-
+ B2BFEE16A02F0AD104FBE59958BE80D27FC59C50695D25B4C008C28ABA4438C00706C3181C473C7A74BD85F21A681059B694B3B792F7C234D3478B346307EB7Cblatta/lib/direct.py(0 . 0)(1 . 58)
981 import logging
982 import hashlib
983 import time
984 import binascii
985 from message import Message
986 from message import DIRECT
987
988
989 class Direct(Message):
990 def __init__(self, message, state):
991 message['command'] = DIRECT
992 message['bounces'] = 0
993 super(Direct, self).__init__(message, state)
994
995 def send(self):
996 if not self.speaker:
997 logging.error("aborting message send due speaker not being set")
998 return
999
1000 self.timestamp = int(time.time())
1001 target_peer = self.state.get_peer_by_handle(self.handle)
1002 if target_peer and not target_peer.get_key():
1003 logging.debug("No key for peer associated with %s" % self.handle)
1004 return
1005
1006 if target_peer == None:
1007 logging.debug("Aborting message: unknown handle: %s" % self.handle)
1008 return
1009
1010 self.message_bytes = self.get_message_bytes(target_peer)
1011 self.message_hash = hashlib.sha256(self.message_bytes).digest()
1012
1013 logging.debug("generated message_hash: %s" % binascii.hexlify(self.message_hash))
1014
1015 self.peer = target_peer
1016 self.long_buffer.intern(self)
1017
1018 signed_packet_bytes = self.pack(target_peer, self.command, self.bounces, self.message_bytes)
1019 self.state.update_handle_self_chain(target_peer.handles[0], self.message_hash)
1020 target_peer.send(signed_packet_bytes)
1021 self.log_outgoing(target_peer)
1022
1023 def retry(self, requesting_peer):
1024 target_peer = self.state.get_peer_by_handle(self.handle)
1025
1026 if target_peer == None:
1027 logging.debug("Aborting message: unknown handle: %s" % self.handle)
1028 return
1029
1030 if not target_peer.get_key():
1031 logging.debug("No key for peer associated with %s" % self.handle)
1032 return
1033
1034 # TODO: Figure out how to verify that the requester was the original intended recipient
1035 signed_packet_bytes = self.pack(target_peer, self.command, self.bounces, self.message_bytes)
1036 target_peer.send(signed_packet_bytes)
1037 self.log_outgoing(target_peer)
1038