- E763BB836EBA69AEDEBD4D4ADFDD8820E1A173F16E1FD493DDD16BF6D41718155C20EE38073570D2AEB0144EA281B6FBCC5DDDE48D5CA60CB01A0B08103DD1F5
+ C96DA174AE6CEB0489ED2B50872C02E481FA7D14D09A747B387BCF7EC45F1EC1DAC5326A3370951F20C8995C85FCC7A8B91BC333CEDAF78B11345A3897C8F95D
blatta/lib/peer.py
(1 . 20)(1 . 21)
686 import socket
687 from infosec import Infosec
688 from commands import IGNORE
689 from commands import DIRECT
690 from commands import BROADCAST
691
692 import sys
693 import binascii
694 import traceback
695 import logging
696
697 class Peer(object):
698 def __init__(self, server, peer_entry):
699 def __init__(self, socket, peer_entry):
700 self.handles = peer_entry["handles"]
701 self.keys = peer_entry["keys"]
702 self.peer_id = peer_entry["peer_id"]
703 self.server = server
704 self.address = peer_entry["address"]
705 self.port = peer_entry["port"]
706 self.socket = self.server.udp_server_socket
707 self.infosec = Infosec(server)
708 self.socket = socket
709
710 def get_key(self):
711 if len(self.keys) > 0:
(22 . 16)(23 . 16)
713 else:
714 return None
715
716 def send(self, msg):
717 try:
718 if msg.command != IGNORE:
719 self.server.print_debug("packing message: %s" % msg.body)
720 signed_packet_bytes = self.infosec.pack(self, msg)
721 self.socket.sendto(signed_packet_bytes, (self.address, self.port))
722 self.server.print_debug("[%s:%d] <- %s" % (self.address,
723 self.port,
724 binascii.hexlify(signed_packet_bytes)[0:16]))
725 def send(self, signed_packet_bytes):
726 if self.get_key() != None:
727 try:
728 self.socket.sendto(signed_packet_bytes, (self.address, self.port))
729 logging.debug("[%s:%d] <- %s" % (self.address,
730 self.port,
731 binascii.hexlify(signed_packet_bytes)[0:16]))
732
733 except Exception as ex:
734 stack = traceback.format_exc()
735 print(stack)
736 except Exception as ex:
737 stack = traceback.format_exc()
738 logging.debug(stack)
739 else:
740 logging.debug("Discarding message to unknown handle or handle with no key: %s" % message.handle)