genesis 1 import socket
genesis 2 from infosec import Infosec
9990-keep-ephemer... 3 from commands import IGNORE
genesis 4 import sys
genesis 5 import binascii
9990-keep-ephemer... 6 import traceback
genesis 7
genesis 8 class Peer(object):
genesis 9 def __init__(self, server, peer_entry):
genesis 10 self.handles = peer_entry["handles"]
genesis 11 self.keys = peer_entry["keys"]
genesis 12 self.peer_id = peer_entry["peer_id"]
genesis 13 self.server = server
genesis 14 self.address = peer_entry["address"]
genesis 15 self.port = peer_entry["port"]
genesis 16 self.socket = self.server.udp_server_socket
genesis 17 self.infosec = Infosec(server)
genesis 18
genesis 19 def get_key(self):
9992-handle-edge-... 20 if len(self.keys) > 0:
9992-handle-edge-... 21 return self.keys[0]
9992-handle-edge-... 22 else:
9992-handle-edge-... 23 return None
genesis 24
genesis 25 def send(self, msg):
genesis 26 try:
9990-keep-ephemer... 27 if msg.command != IGNORE:
9990-keep-ephemer... 28 self.server.print_debug("packing message: %s" % msg.body)
9988-hash-dedup 29 signed_packet_bytes = self.infosec.pack(self, msg)
genesis 30 self.socket.sendto(signed_packet_bytes, (self.address, self.port))
9991-improved-log... 31 self.server.print_debug("[%s:%d] <- %s" % (self.address,
9991-improved-log... 32 self.port,
9991-improved-log... 33 binascii.hexlify(signed_packet_bytes)[0:16]))
genesis 34
genesis 35 except Exception as ex: