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