Exemple #1
0
 def _on_inbox_packet(self, newpacket, info, status, error_message):
     if status != 'finished':
         return False
     if newpacket.Command == commands.Coin():
         coins_list = coins_io.read_coins_from_packet(newpacket)
         if not coins_list:
             p2p_service.SendFail(newpacket, 'failed to read coins from packet')
             return True
         if len(coins_list) != 1:
             p2p_service.SendFail(newpacket, 'expected only one coin to be mined')
             return True
         coin_json = coins_list[0]
         if not coins_io.validate_coin(coin_json):
             lg.warn('coin not valid: %s' % coin_json)
             p2p_service.SendFail(newpacket, 'coin not valid')
             return True
         if not coins_io.verify_signature(coin_json, 'creator'):
             lg.warn('creator signature is not valid: %s' % coin_json)
             p2p_service.SendFail(newpacket, 'creator signature is not valid')
             return True
         new_coins.append(coin_json)
         if not new_coins:
             # p2p_service.SendFail(newpacket, 'did not received any coins to mine')
             return False
         for coin in new_coins:
             self.automat('new-data-received', coin)
         return True
     return False
Exemple #2
0
 def _on_inbox_packet(self, newpacket, info, status, error_message):
     if _Debug:
         lg.out(_DebugLevel, 'accountant_node._on_inbox_packet %r' % newpacket)
     if newpacket.Command == commands.RetrieveCoin():
         return self._on_command_retrieve_coin(newpacket, info)
     if newpacket.Command == commands.Coin():
         return self._on_command_coin(newpacket, info)
     return False
Exemple #3
0
def SendCoin(remote_idurl, coins, packet_id=None, wide=False, callbacks={}):
    if _Debug:
        lg.out(_DebugLevel, "p2p_service.SendCoin to %s with %d records" % (remote_idurl, len(coins)))
    if packet_id is None:
        packet_id = packetid.UniqueID()
    outpacket = signed.Packet(
        commands.Coin(), my_id.getLocalID(),
        my_id.getLocalID(), packet_id,
        serialization.DictToBytes(coins), remote_idurl)
    gateway.outbox(outpacket, wide=wide, callbacks=callbacks)
    return outpacket
Exemple #4
0
def SendCoin(remote_idurl, coins, packet_id=None, wide=False, callbacks={}):
    if _Debug:
        lg.out(_DebugLevel, "p2p_service.SendCoin to %s with %d records" % (remote_idurl, len(coins)))
    if packet_id is None:
        packet_id = packetid.UniqueID()
    outpacket = signed.Packet(
        Command=commands.Coin(),
        OwnerID=my_id.getLocalID(),
        CreatorID=my_id.getLocalID(),
        PacketID=packet_id,
        Payload=serialization.DictToBytes(coins, keys_to_text=True),
        RemoteID=remote_idurl,
    )
    gateway.outbox(outpacket, wide=wide, callbacks=callbacks)
    return outpacket
 def __init__(self, query_dict):
     """
     """
     self.result = Deferred()
     self.out_packets = {}
     for idurl in contract_chain_consumer.A().connected_accountants:
         single_accountant = Deferred()
         outpacket = p2p_service.SendRetrieveCoin(idurl, query_dict, callbacks={
             commands.Coin(): self._on_coin_received,
             commands.Fail(): self._on_coin_failed,
         })
         assert outpacket.PacketID not in self.out_packets
         self.out_packets[outpacket.PacketID] = single_accountant
     DeferredList(list(self.out_packets.values())).addBoth(self._on_results_collected)
     if _Debug:
         lg.out(_DebugLevel, 'contract_chain_node.Query created to request from %d accountants' % len(self.out_packets))
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
Exemple #7
0
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