def SendKey( remote_idurl, encrypted_key_data, packet_id=None, wide=False, callbacks={}, timeout=10, ): if packet_id is None: packet_id = packetid.UniqueID() if _Debug: lg.out( _DebugLevel, "p2p_service.SendKey [%s] to %s with %d bytes encrypted key data" % (packet_id, remote_idurl, len(encrypted_key_data))) outpacket = signed.Packet( Command=commands.Key(), OwnerID=my_id.getLocalID(), CreatorID=my_id.getLocalID(), PacketID=packet_id, Payload=encrypted_key_data, RemoteID=remote_idurl, ) gateway.outbox(outpacket, wide=wide, callbacks=callbacks, response_timeout=timeout) return outpacket
def _inbox_packet_received(self, newpacket, info, status, error_message): if status != 'finished': return False from p2p import commands from access import key_ring if newpacket.Command != commands.Key(): return False return key_ring.on_private_key_received(newpacket, info, status, error_message)
def _on_inbox_packet_received(self, newpacket, info, status, error_message): from p2p import commands from access import key_ring if newpacket.Command == commands.Key(): return key_ring.on_key_received(newpacket, info, status, error_message) elif newpacket.Command == commands.AuditKey(): return key_ring.on_audit_key_received(newpacket, info, status, error_message) return False
def _on_inbox_packet_received(self, newpacket, info, status, error_message): from p2p import commands from access import key_ring if newpacket.Command == commands.Key(): # TODO: work in progress : need to store history of all keys transfers return key_ring.on_key_received(newpacket, info, status, error_message) elif newpacket.Command == commands.AuditKey(): return key_ring.on_audit_key_received(newpacket, info, status, error_message) return False
def SendKey(remote_idurl, encrypted_key_data, packet_id=None, wide=False, callbacks={}): # full_key_data = json.dumps(key_data) if isinstance(key_data, dict) else key_data if _Debug: lg.out( _DebugLevel, "p2p_service.SendKey to %s with %d bytes encrypted key data" % (remote_idurl, len(encrypted_key_data))) if packet_id is None: packet_id = packetid.UniqueID() outpacket = signed.Packet( Command=commands.Key(), OwnerID=my_id.getLocalID(), CreatorID=my_id.getLocalID(), PacketID=packet_id, Payload=encrypted_key_data, RemoteID=remote_idurl, ) gateway.outbox(outpacket, wide=wide, callbacks=callbacks) return outpacket
def _outbox_packet_sent(self, pkt_out): from p2p import commands if pkt_out.outpacket.Command == commands.Key(): pass
def inbox(newpacket, info, status, error_message): """ """ if newpacket.CreatorID != my_id.getLocalID( ) and newpacket.RemoteID != my_id.getLocalID(): # packet is NOT for us, skip return False commandhandled = False if newpacket.Command == commands.Ack(): # a response from remote node, typically handled in other places Ack(newpacket, info) commandhandled = False elif newpacket.Command == commands.Fail(): # some operation was failed on other side Fail(newpacket) commandhandled = False elif newpacket.Command == commands.Retrieve(): # retrieve some packet customer stored with us # handled by service_supplier() Retrieve(newpacket) commandhandled = False elif newpacket.Command == commands.RequestService(): # other node send us a request to get some service # handled by service_p2p_hookups() RequestService(newpacket, info) commandhandled = False elif newpacket.Command == commands.CancelService(): # other node wants to stop the service we gave him # handled by service_p2p_hookups() CancelService(newpacket, info) commandhandled = False elif newpacket.Command == commands.Data(): # new packet to store for customer, or data coming back from supplier # handled by service_backups() and service_supplier() Data(newpacket) commandhandled = False elif newpacket.Command == commands.ListFiles(): # customer wants list of their files # handled by service_supplier() ListFiles(newpacket, info) commandhandled = False elif newpacket.Command == commands.Files(): # supplier sent us list of files # handled by service_backups() Files(newpacket, info) commandhandled = False elif newpacket.Command == commands.DeleteFile(): # handled by service_supplier() DeleteFile(newpacket) commandhandled = False elif newpacket.Command == commands.DeleteBackup(): # handled by service_supplier() DeleteBackup(newpacket) commandhandled = False elif newpacket.Command == commands.Correspondent(): # TODO: contact asking for our current identity, not implemented yet Correspondent(newpacket) commandhandled = False elif newpacket.Command == commands.Broadcast(): # handled by service_broadcasting() Broadcast(newpacket, info) commandhandled = False elif newpacket.Command == commands.Coin(): # handled by service_accountant() Coin(newpacket, info) commandhandled = False elif newpacket.Command == commands.RetrieveCoin(): # handled by service_accountant() RetrieveCoin(newpacket, info) commandhandled = False elif newpacket.Command == commands.Key(): # handled by service_keys_registry() Key(newpacket, info) commandhandled = False elif newpacket.Command == commands.Event(): # handled by service_p2p_hookups() Event(newpacket, info) commandhandled = False elif newpacket.Command == commands.Message(): # handled by service_private_messages() Message(newpacket, info) commandhandled = False return commandhandled
def _on_outbox_packet_sent(self, pkt_out): # TODO: work in progress from p2p import commands if pkt_out.outpacket.Command == commands.Key(): return True return False
def _on_outbox_packet_sent(self, pkt_out): from p2p import commands if pkt_out.outpacket.Command == commands.Key(): # TODO: work in progress : need to store history of all keys transfers return True return False