def SendDeleteFile(SupplierID, pathID): if _Debug: lg.out(_DebugLevel, "p2p_service.SendDeleteFile SupplierID=%s PathID=%s" % (SupplierID, pathID)) MyID = my_id.getLocalID() PacketID = pathID RemoteID = SupplierID result = signed.Packet(commands.DeleteFile(), MyID, MyID, PacketID, "", RemoteID) gateway.outbox(result) return result
def SendDeleteListPaths(SupplierID, ListPathIDs): if _Debug: lg.out(_DebugLevel, "p2p_service.SendDeleteListPaths SupplierID=%s PathIDs: %s" % (SupplierID, ListPathIDs)) MyID = my_id.getLocalID() PacketID = packetid.UniqueID() RemoteID = SupplierID Payload = '\n'.join(ListPathIDs) result = signed.Packet(commands.DeleteFile(), MyID, MyID, PacketID, Payload, RemoteID) gateway.outbox(result) return result
def _on_inbox_packet_received(self, newpacket, info, status, error_message): from p2p import commands if newpacket.Command == commands.DeleteFile(): return self._on_delete_file(newpacket) elif newpacket.Command == commands.Retrieve(): return self._on_retreive(newpacket) elif newpacket.Command == commands.Data(): return self._on_data(newpacket) elif newpacket.Command == commands.ListFiles(): return self._on_list_files(newpacket) return False
def _on_inbox_packet_received(self, newpacket, info, status, error_message): from p2p import commands from supplier import customer_space if newpacket.Command == commands.DeleteFile(): return customer_space.on_delete_file(newpacket) elif newpacket.Command == commands.DeleteBackup(): return customer_space.on_delete_backup(newpacket) elif newpacket.Command == commands.Retrieve(): return customer_space.on_retrieve(newpacket) elif newpacket.Command == commands.Data(): return customer_space.on_data(newpacket) elif newpacket.Command == commands.ListFiles(): return customer_space.on_list_files(newpacket) return False
def SendDeleteFile(SupplierID, pathID): if _Debug: lg.out( _DebugLevel, "p2p_service.SendDeleteFile SupplierID=%s PathID=%s" % (SupplierID, pathID)) MyID = my_id.getIDURL() PacketID = pathID RemoteID = SupplierID result = signed.Packet( Command=commands.DeleteFile(), OwnerID=MyID, CreatorID=MyID, PacketID=PacketID, Payload="", RemoteID=RemoteID, ) gateway.outbox(result) return result
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 verify_packet_ownership(newpacket, raise_exception=False): """ At that point packet creator is already verified via signature, but creator could be not authorized to store data on that node. So based on owner ID decision must be made what to do with the packet. Returns IDURL of the user who should receive and Ack() or None if not authorized. """ # SECURITY owner_idurl = newpacket.OwnerID creator_idurl = newpacket.CreatorID owner_id = owner_idurl.to_id() creator_id = creator_idurl.to_id() packet_key_alias, packet_owner_id, _ = packetid.SplitKeyOwnerData( newpacket.PacketID) packet_key_id = my_keys.latest_key_id( my_keys.make_key_id(packet_key_alias, creator_idurl, creator_glob_id=packet_owner_id)) if _Debug: lg.args(_DebugLevel, owner_id=owner_id, creator_id=creator_id, packet_id=newpacket.PacketID, key_id_registered=my_keys.is_key_registered(packet_key_id)) if newpacket.Command == commands.Data(): if owner_idurl.to_bin() == creator_idurl.to_bin(): if contactsdb.is_customer(creator_idurl): if _Debug: lg.dbg( _DebugLevel, 'OK, scenario 1: customer is sending own data to own supplier' ) return owner_idurl lg.err( 'FAIL, scenario 6: user is not my customer but trying to store data' ) if raise_exception: raise Exception( 'non-authorized user is trying to store data on the supplier' ) return None if contactsdb.is_customer(creator_idurl): if _Debug: lg.dbg( _DebugLevel, 'OK, scenario 2: customer wants to store data for someone else on own supplier' ) # TODO: check that, why do we need that? return creator_idurl if packet_owner_id == owner_id: if contactsdb.is_customer(owner_idurl): if my_keys.is_key_registered(packet_key_id): if _Debug: lg.dbg( _DebugLevel, 'OK, scenario 3: another authorized user is sending data to customer to be stored on the supplier' ) return creator_idurl lg.err('non-authorized user is trying to store data on the supplier') return None if newpacket.Command in [ commands.DeleteFile(), commands.DeleteBackup(), ]: if owner_idurl == creator_idurl: if contactsdb.is_customer(creator_idurl): if _Debug: lg.dbg( _DebugLevel, 'OK, scenario 4: customer wants to remove already stored data on own supplier' ) return owner_idurl lg.err( 'FAIL, scenario 7: non-authorized user is trying to erase data owned by customer from the supplier' ) if raise_exception: raise Exception( 'non-authorized user is trying to erase data owned by customer from the supplier' ) return None if contactsdb.is_customer(creator_idurl): # TODO: check that, why do we need that? if _Debug: lg.dbg( _DebugLevel, 'OK, scenario 8: customer wants to erase existing data that belongs to someone else but stored on the supplier' ) return creator_idurl if packet_owner_id == owner_id: if contactsdb.is_customer(owner_idurl): if my_keys.is_key_registered(packet_key_id): if _Debug: lg.dbg( _DebugLevel, 'OK, scenario 5: another authorized user wants to remove already stored data from the supplier' ) return creator_idurl lg.err('non-authorized user is trying to erase data on the supplier') return None if driver.is_enabled('service_proxy_server'): if _Debug: lg.dbg( _DebugLevel, 'IGNORE, scenario 9: received Data() not authorized, but proxy router service was enabled' ) return None # TODO: # scenario 9: make possible to set "active" flag True/False for any key # this way customer can make virtual location available for other user but in read-only mode raise Exception('scenario not implemented yet, received %r' % newpacket)
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 Retrieve(newpacket) commandhandled = True elif newpacket.Command == commands.RequestService(): # other node send us a request to get some service RequestService(newpacket, info) commandhandled = True elif newpacket.Command == commands.CancelService(): # other node wants to stop the service we gave him CancelService(newpacket, info) commandhandled = True elif newpacket.Command == commands.Data(): # new packet to store for customer commandhandled = Data(newpacket) elif newpacket.Command == commands.ListFiles(): # customer wants list of their files ListFiles(newpacket) commandhandled = True elif newpacket.Command == commands.Files(): # supplier sent us list of files Files(newpacket, info) commandhandled = True elif newpacket.Command == commands.DeleteFile(): # will Delete a customer file for them DeleteFile(newpacket) commandhandled = True elif newpacket.Command == commands.DeleteBackup(): # will Delete all files starting in a backup DeleteBackup(newpacket) commandhandled = True elif newpacket.Command == commands.Message(): # will be handled in message.py commandhandled = False elif newpacket.Command == commands.Correspondent(): # contact asking for our current identity Correspondent(newpacket) commandhandled = True 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 return commandhandled