def on_service_data(self, peer_id, message): """demand to establish connection from peer that failed to connect through TCP""" if self.peers.assert_id(peer_id): try: message = Message.create_message(message) if message.command != MESSAGE_HELLO: SecurityAlert(peer_id, "unvalid message '%s' from %s"\ % (str(message), peer_id)) else: self.peers.set_peer(peer_id, message) except ValueError, err: SecurityAlert(peer_id, str(err))
def wrap_message(self, command, data=None): message = Message(command) message.ip = self.ip message.port = self.port message.data = data return message