def datagramReceived(self, datagram, addr): global _ReceiveControlFunc try: from transport_control import black_IPs_dict if addr[0] in black_IPs_dict().keys() or '.'.join(addr[0].split('.')[:-1]) in black_IPs_dict().keys(): # dhnio.Dprint(12, 'transport_udp_server.datagramReceived %d bytes from BLACK IP: %s, %s' % (len(datagram), str(addr[0]), str(black_IPs_dict()[addr[0]])) ) return except: pass if len(datagram) < 2: return io = cStringIO.StringIO(datagram) code = io.read(2) if code.strip() == '': return cmd = CODES.get(code, None) if cmd is None: # dhnio.Dprint(8, ' [UDP] WARNING wrong code from %s' % (addr,)) return # dhnio.Dprint(10, ' [UDP] %d bytes from %s (%s)' % (len(datagram), addr, cmd)) if _ReceiveControlFunc: seconds_pause = _ReceiveControlFunc(len(datagram)) if seconds_pause > 0: # print 'paused for', seconds_pause, 'seconds' self.client.transport.pauseProducing() reactor.callLater(seconds_pause, self.client.transport.resumeProducing) if not self.peers.has_key(addr): self.peers[addr] = UDPPeer(self, addr) self.peers[addr].datagram_received(cmd, io) io.close() del io
def data_received(datagram, address): try: from transport_control import black_IPs_dict if address[0] in black_IPs_dict().keys() or '.'.join(address[0].split('.')[:-1]) in black_IPs_dict().keys(): # dhnio.Dprint(12, 'transport_udp_session.data_received %d bytes from BLACK IP: %s, %s' % (len(datagram), str(address[0]), str(black_IPs_dict()[address[0]])) ) return except: pass if dhn_stun_servers_enabled(): if address in DHN_STUN_SERVERS: dhn_stun_server_response(datagram, address) return if not is_session_opened(address): s = open_session(address) idurl = identitycache.GetIDURLByIPPort(address[0], address[1]) if idurl: dhnio.Dprint(6, 'transport_udp_session.data_received from KNOWN user, made a new session %s for [%s]' % (s.name, nameurl.GetName(idurl))) s.event('init', idurl) else: dhnio.Dprint(6, 'transport_udp_session.data_received from UNKNOWN user, made a new session %s' % s.name) s.event('init', None) A(address, 'datagram-received', (datagram, address))