(1 . 7)(1 . 9)
285 import socket
286 from infosec import Infosec
287 from commands import IGNORE
288 import sys
289 import binascii
290 import traceback
291
292 class Peer(object):
293 def __init__(self, server, peer_entry):
(22 . 14)(24 . 14)
295
296 def send(self, msg):
297 try:
298 full_message = str.encode(msg["body"])
299
300 signed_packet_bytes = self.infosec.pack(self, msg)
301 self.server.print_debug("packing message: %s" % full_message)
302 if msg.command != IGNORE:
303 self.server.print_debug("packing message: %s" % msg.body)
304 self.socket.sendto(signed_packet_bytes, (self.address, self.port))
305 self.server.print_debug("[%s:%d] <- %s" % (self.address,
306 self.port,
307 binascii.hexlify(signed_packet_bytes)[0:16]))
308
309 except Exception as ex:
310 print("Exception while attempting to encode message: %s" % ex)
311 stack = traceback.format_exc()
312 print(stack)