Exemplo n.º 1
0
	def _recv_sack1 (self, port):
		if self.state != STATE_C_SYN1:
			cnetcom.plog('state error2')
			return -1
		self.dport = port
		self.head.dport = port
		self.state = STATE_C_SYN2
		self.timeout_reset()
		return 0
Exemplo n.º 2
0
 def _recv_sack1(self, port):
     if self.state != STATE_C_SYN1:
         cnetcom.plog('state error2')
         return -1
     self.dport = port
     self.head.dport = port
     self.state = STATE_C_SYN2
     self.timeout_reset()
     return 0
Exemplo n.º 3
0
 def _recv_syn1(self, dport, addr1, mode1, addr2, mode2):
     if self.state != STATE_L_SYN1:
         cnetcom.plog('state error1')
         return -1
     self.dport = dport
     self.head.dport = self.dport
     self.route = (0.2, addr1, mode1, addr2, mode2)
     self.dstaddr = self.route[1]
     self.dstmode = self.route[2]
     self.state = STATE_L_SYN2
     return 0
Exemplo n.º 4
0
	def _recv_syn1 (self, dport, addr1, mode1, addr2, mode2):
		if self.state != STATE_L_SYN1:
			cnetcom.plog('state error1')
			return -1
		self.dport = dport
		self.head.dport = self.dport
		self.route = (0.2, addr1, mode1, addr2, mode2)
		self.dstaddr = self.route[1]
		self.dstmode = self.route[2]
		self.state = STATE_L_SYN2
		return 0
Exemplo n.º 5
0
 def _recv_syn1(self, head, data, remote, forward):
     deny_it = self.deny(head.suid, head.skey)
     if deny_it:
         newhead = cnetcom.msghead(self.uid, self.key, head.suid, \
          head.skey, 0, head.sport, CMD_DENY)
         self.sendudp(newhead, '', remote, forward)
         return -1
     record = data.split(',')
     if len(record) != 4:
         return -2
     try:
         addr1 = cnetudp.text2ep(record[0])
         mode1 = int(record[1])
         addr2 = cnetudp.text2ep(record[2])
         mode2 = int(record[3])
     except:
         cnetcom.plog('error syn1')
         return -3
     ident = head.suid, head.skey, head.sport
     conn = None
     if ident in self.listen:
         port = self.listen[ident]
         if not port in self.ports:
             del self.listen[ident]
         else:
             conn = self.ports[port]
     if not conn:
         sport = self._port_open(TYPE_LISTENER, head.suid, head.skey, \
          head.conv, '')
         conn = self.ports[sport]
         conn._recv_syn1(head.sport, addr1, mode1, \
          addr2, mode2)
         self.ports[sport] = conn
         self.listen[ident] = conn.sport
     text = '%d' % conn.sport
     conn.send(CMD_SACK1, text)
     self.log('recv_syn1 from uid=%d key=%d' % (head.suid, head.skey))
     return 0
Exemplo n.º 6
0
	def _recv_syn1(self, head, data, remote, forward):
		deny_it = self.deny(head.suid, head.skey)
		if deny_it:
			newhead = cnetcom.msghead(self.uid, self.key, head.suid, \
				head.skey, 0, head.sport, CMD_DENY)
			self.sendudp(newhead, '', remote, forward)
			return -1
		record = data.split(',')
		if len(record) != 4:
			return -2
		try:
			addr1 = cnetudp.text2ep(record[0])
			mode1 = int(record[1])
			addr2 = cnetudp.text2ep(record[2])
			mode2 = int(record[3])
		except:
			cnetcom.plog('error syn1')
			return -3
		ident = head.suid, head.skey, head.sport
		conn = None
		if ident in self.listen:
			port = self.listen[ident]
			if not port in self.ports:
				del self.listen[ident]
			else:
				conn = self.ports[port]
		if not conn:
			sport = self._port_open(TYPE_LISTENER, head.suid, head.skey, \
				head.conv, '')
			conn = self.ports[sport]
			conn._recv_syn1(head.sport, addr1, mode1, \
				addr2, mode2)
			self.ports[sport] = conn
			self.listen[ident] = conn.sport
		text = '%d'%conn.sport
		conn.send(CMD_SACK1, text)	
		self.log('recv_syn1 from uid=%d key=%d'%(head.suid, head.skey))
		return 0
Exemplo n.º 7
0
 def _recv_sack1(self, head, data, remote, forward):
     try:
         port = int(data)
     except:
         cnetcom.plog('error sack1')
         return -1
     sport = head.dport
     dport = head.sport
     if not sport in self.ports:
         cnetcom.plog('no such port %d' % sport)
         msghead = cnetcom.msghead(head.duid, head.dkey, \
          head.suid, head.skey, CMD_NOPORT, head.conv)
         self.sendudp(msghead, '', remote, forward)
         return -2
     conn = self.ports[sport]
     if conn.conv != head.conv:
         cnetcom.plog('conv error %d' % sport)
         msghead = cnetcom.msghead(head.duid, head.dkey, \
          head.suid, head.skey, CMD_NOCONV, head.conv)
         self.sendudp(msghead, '', remote, forward)
         return -3
     conn._recv_sack1(port)
     return 0
Exemplo n.º 8
0
	def _recv_sack1(self, head, data, remote, forward):
		try:
			port = int(data)
		except:
			cnetcom.plog('error sack1')
			return -1
		sport = head.dport
		dport = head.sport
		if not sport in self.ports:
			cnetcom.plog('no such port %d'%sport)
			msghead = cnetcom.msghead(head.duid, head.dkey, \
				head.suid, head.skey, CMD_NOPORT, head.conv)
			self.sendudp(msghead, '', remote, forward)
			return -2
		conn = self.ports[sport]
		if conn.conv != head.conv:
			cnetcom.plog('conv error %d'%sport)
			msghead = cnetcom.msghead(head.duid, head.dkey, \
				head.suid, head.skey, CMD_NOCONV, head.conv)
			self.sendudp(msghead, '', remote, forward)
			return -3
		conn._recv_sack1(port)
		return 0
Exemplo n.º 9
0
 def log(self, *args):
     if not self.canlog:
         return -1
     cnetcom.plog('[%d]' % (self.uid), *args)
     return 0
Exemplo n.º 10
0
	def log (self, *args):
		if not self.canlog:
			return -1
		cnetcom.plog('[%d]'%(self.uid), *args)
		return 0