def send_relayed_ping(self): self.log.debug('Sending Relay Ping to: %s', self) for active_peer in self.transport.dht.active_peers: if active_peer.hostname == 'seed2.openbazaar.org' or active_peer.hostname == '205.186.156.31': self.sock.sendto('send_relay_ping %s' % self.guid, (active_peer.hostname, active_peer.port)) count_outgoing_packet('send_relay_ping %s' % self.guid) return True
def send_relayed_ping(self): self.log.debug('Sending Relay Ping to: %s', self) for x in self.transport.dht.active_peers: if x.hostname == 'seed2.openbazaar.org' or x.hostname == '205.186.156.31': self.sock.sendto('send_relay_ping %s' % self.guid, (x.hostname, x.port)) count_outgoing_packet('send_relay_ping %s' % self.guid) return True
def start_listening(): while self.is_listening: try: data, addr = self.socket.recvfrom(2048) self.log.debug('Got data from %s:%d: %s', addr[0], addr[1], data[:50]) count_incoming_packet(data) if data[:4] == 'ping': self.socket.sendto('pong', (addr[0], addr[1])) count_outgoing_packet('pong') elif data[:4] == 'pong': self.ee.emit('on_pong_message', (data, addr)) elif data[:15] == 'send_relay_ping': self.ee.emit('on_send_relay_ping', (data, addr)) elif data[:10] == 'relay_ping': data = data.split(' ') sender = self.guid recipient = data[1] self.socket.sendto( 'send_relay_pong %s %s' % (sender, recipient), (addr[0], addr[1])) count_outgoing_packet('send_relay_pong %s %s' % (sender, recipient)) elif data[:15] == 'send_relay_pong': self.ee.emit('on_send_relay_pong', (data, addr)) elif data[:9] == 'heartbeat': self.log.debug('We just received a heartbeat.') elif data[:7] == 'relayto': self.log.debug('Relay To Packet') self.ee.emit('on_relayto', data) elif data[:6] == 'relay ': self.log.debug('Relay Packet') self.ee.emit('on_message', (data, addr)) else: self.ee.emit('on_message', (data, addr)) except socket.timeout as e: err = e.args[0] if err == 'timed out': time.sleep(0.5) continue else: sys.exit(1) except socket.error: # No data. This is normal. pass
def start_listening(): while self.is_listening: try: data, addr = self.socket.recvfrom(PEERLISTENER_RECV_FROM_BUFFER_SIZE) self.log.debug('Got data from %s:%d: %s', addr[0], addr[1], data[:50]) count_incoming_packet(data) if data[:MSG_PING_ID_SIZE] == MSG_PING_ID: self.socket.sendto('pong', (addr[0], addr[1])) count_outgoing_packet('pong') elif data[:MSG_PONG_ID_SIZE] == MSG_PONG_ID: self.event_emitter.emit('on_pong_message', (data, addr)) elif data[:MSG_SEND_RELAY_PING_ID_SIZE] == MSG_SEND_RELAY_PING_ID: self.event_emitter.emit('on_send_relay_ping', (data, addr)) elif data[:MSG_RELAY_PING_ID_SIZE] == MSG_RELAY_PING_ID: data = data.split(' ') sender = self.guid recipient = data[1] self.socket.sendto('send_relay_pong %s %s' % (sender, recipient), (addr[0], addr[1])) count_outgoing_packet('send_relay_pong %s %s' % (sender, recipient)) elif data[:MSG_SEND_RELAY_PONG_ID_SIZE] == MSG_SEND_RELAY_PONG_ID: self.event_emitter.emit('on_send_relay_pong', (data, addr)) elif data[:MSG_HEARTBEAT_ID_SIZE] == MSG_HEARTBEAT_ID: self.log.debug('We just received a heartbeat.') elif data[:MSG_RELAYTO_ID_SIZE] == MSG_RELAYTO_ID: self.log.debug('Relay To Packet') self.event_emitter.emit('on_relayto', data) elif data[:MSG_RELAY_ID_SIZE] == MSG_RELAY_ID: self.log.debug('Relay Packet') self.event_emitter.emit('on_message', (data, addr)) else: self.event_emitter.emit('on_message', (data, addr)) except socket.timeout as exc: err = exc.args[0] if err == 'timed out': time.sleep(0.5) continue else: sys.exit(1) except socket.error: # No data. This is normal. pass
def start_listening(): while self.is_listening: try: data, addr = self.socket.recvfrom(2048) self.log.debug('Got data from %s:%d: %s', addr[0], addr[1], data[:50]) count_incoming_packet(data) if data[:4] == 'ping': self.socket.sendto('pong', (addr[0], addr[1])) count_outgoing_packet('pong') elif data[:4] == 'pong': self.ee.emit('on_pong_message', (data, addr)) elif data[:15] == 'send_relay_ping': self.ee.emit('on_send_relay_ping', (data, addr)) elif data[:10] == 'relay_ping': data = data.split(' ') sender = self.guid recipient = data[1] self.socket.sendto('send_relay_pong %s %s' % (sender, recipient), (addr[0], addr[1])) count_outgoing_packet('send_relay_pong %s %s' % (sender, recipient)) elif data[:15] == 'send_relay_pong': self.ee.emit('on_send_relay_pong', (data, addr)) elif data[:9] == 'heartbeat': self.log.debug('We just received a heartbeat.') elif data[:7] == 'relayto': self.log.debug('Relay To Packet') self.ee.emit('on_relayto', data) elif data[:6] == 'relay ': self.log.debug('Relay Packet') self.ee.emit('on_message', (data, addr)) else: self.ee.emit('on_message', (data, addr)) except socket.timeout as e: err = e.args[0] if err == 'timed out': time.sleep(0.5) continue else: sys.exit(1) except socket.error: # No data. This is normal. pass
def send_to_sock(self, data): self.sock.sendto(data, (self.hostname, self.port)) count_outgoing_packet(data)
def send_ping(self): self.sock.sendto(MSG_PING_ID, (self.hostname, self.port)) count_outgoing_packet(MSG_PING_ID) return True
def send(self, data): self._sender.send(data) count_outgoing_packet(data)
def send_ping(self): self.sock.sendto('ping', (self.hostname, self.port)) count_outgoing_packet('ping') return True
def start_listening(): while self.is_listening: try: data, addr = self.socket.recvfrom( PEERLISTENER_RECV_FROM_BUFFER_SIZE) self.log.debug('Got data from %s:%d: %s', addr[0], addr[1], data[:50]) count_incoming_packet(data) if data[:MSG_PING_ID_SIZE] == MSG_PING_ID: self.socket.sendto('pong', (addr[0], addr[1])) count_outgoing_packet('pong') elif data[:MSG_PONG_ID_SIZE] == MSG_PONG_ID: self.event_emitter.emit('on_pong_message', (data, addr)) elif data[: MSG_SEND_RELAY_PING_ID_SIZE] == MSG_SEND_RELAY_PING_ID: self.event_emitter.emit('on_send_relay_ping', (data, addr)) elif data[:MSG_RELAY_PING_ID_SIZE] == MSG_RELAY_PING_ID: data = data.split(' ') sender = self.guid recipient = data[1] self.socket.sendto( 'send_relay_pong %s %s' % (sender, recipient), (addr[0], addr[1])) count_outgoing_packet('send_relay_pong %s %s' % (sender, recipient)) elif data[: MSG_SEND_RELAY_PONG_ID_SIZE] == MSG_SEND_RELAY_PONG_ID: self.event_emitter.emit('on_send_relay_pong', (data, addr)) elif data[:MSG_HEARTBEAT_ID_SIZE] == MSG_HEARTBEAT_ID: self.log.debug('We just received a heartbeat.') elif data[:MSG_RELAYTO_ID_SIZE] == MSG_RELAYTO_ID: self.log.debug('Relay To Packet') self.event_emitter.emit('on_relayto', data) elif data[:MSG_RELAY_ID_SIZE] == MSG_RELAY_ID: self.log.debug('Relay Packet') self.event_emitter.emit('on_message', (data, addr)) else: self.event_emitter.emit('on_message', (data, addr)) except socket.timeout as exc: err = exc.args[0] if err == 'timed out': time.sleep(0.5) continue else: sys.exit(1) except socket.error: # No data. This is normal. pass