示例#1
0
 def OnFileSendingFinished(self, pkt_out, item, status, size, error_message):
     if self.shutdown:
         lg.warn('skip, supplier queue is shutting down')
         return
     if not pkt_out.outpacket:
         lg.warn('skip, outpacket is already None')
         return
     packetID = global_id.CanonicalID(pkt_out.outpacket.PacketID)
     if status == 'finished':
         if pkt_out.outpacket.Command == commands.Retrieve():
             if packetID in self.fileRequestQueue:
                 f_down = self.fileRequestDict[packetID]
                 if _Debug:
                     lg.args(_DebugLevel, obj=f_down, status=status, packetID=packetID, event='retrieve-sent')
                 f_down.event('retrieve-sent', pkt_out.outpacket)
         elif pkt_out.outpacket.Command == commands.Data():
             if packetID in self.fileSendQueue:
                 f_up = self.fileSendDict[packetID]
                 if _Debug:
                     lg.args(_DebugLevel, obj=f_up, status=status, packetID=packetID, event='data-sent')
                 f_up.event('data-sent', pkt_out.outpacket)
     else:
         if pkt_out.outpacket.Command == commands.Retrieve():
             if packetID in self.fileRequestQueue:
                 if _Debug:
                     lg.dbg(_DebugLevel, 'packet %r is %r during downloading from %s' % (packetID, status, self.remoteID))
                 f_down = self.fileRequestDict[packetID]
                 f_down.event('request-failed')
         elif pkt_out.outpacket.Command == commands.Data():
             if packetID in self.fileSendQueue:
                 if _Debug:
                     lg.dbg(_DebugLevel, 'packet %r is %r during uploading to %s' % (packetID, status, self.remoteID))
                 f_up = self.fileSendDict[packetID]
                 f_up.event('sending-failed')
示例#2
0
 def DeleteBackupRequests(self, backupName):
     if self.shutdown:
         # if we're closing down this queue
         # (supplier replaced, don't any anything new)
         return
     packetsToRemove = set()
     for packetID in self.fileRequestQueue:
         if packetID.count(backupName):
             packetsToRemove.add(packetID)
             if _Debug:
                 lg.out(_DebugLevel, 'io_throttle.DeleteBackupRequests %s from request queue' % packetID)
     for packetID in packetsToRemove:
         self.fileRequestQueue.remove(packetID)
         del self.fileRequestDict[packetID]
         if _Debug:
             lg.out(_DebugLevel, "io_throttle.DeleteBackupRequests removed %s from %s receiving queue, %d more items" % (
                 packetID, self.remoteName, len(self.fileRequestQueue)))
     packetsToCancel = packet_out.search_by_backup_id(backupName)
     for pkt_out in packetsToCancel:
         if pkt_out.outpacket.Command == commands.Retrieve():
             if pkt_out.outpacket.PacketID in packetsToRemove:
                 lg.warn('sending "cancel" to %s addressed to %s   from io_throttle' % (
                     pkt_out, pkt_out.remote_idurl, ))
                 pkt_out.automat('cancel')
     if len(self.fileRequestQueue) > 0:
         reactor.callLater(0, self.DoRequest)
示例#3
0
def SendRetreive(ownerID,
                 creatorID,
                 packetID,
                 remoteID,
                 payload='',
                 response_timeout=None,
                 callbacks={}):
    """
    """
    newpacket = signed.Packet(
        Command=commands.Retrieve(),
        OwnerID=ownerID,
        CreatorID=creatorID,
        PacketID=packetID,
        Payload=payload,
        RemoteID=remoteID,
    )
    result = gateway.outbox(newpacket,
                            callbacks=callbacks,
                            response_timeout=response_timeout)
    if _Debug:
        lg.out(_DebugLevel, 'p2p_service.SendRetreive packetID=%s' % packetID)
        lg.out(
            _DebugLevel, '  remoteID=%s  ownerID=%s  creatorID=%s' %
            (remoteID, ownerID, creatorID))
    return result
示例#4
0
 def doCancelPackets(self, *args, **kwargs):
     """
     Action method.
     """
     packetsToCancel = packet_out.search_by_backup_id(self.packetID)
     for pkt_out in packetsToCancel:
         if pkt_out.outpacket.Command == commands.Retrieve():
             lg.warn('sending "cancel" to %s addressed to %s because downloading cancelled' % (
                 pkt_out, pkt_out.remote_idurl, ))
             pkt_out.automat('cancel')
示例#5
0
 def doCancelRequests(self, arg):
     """
     Action method.
     """
     packetID = global_id.MakeGlobalID(idurl=my_id.getLocalID(),
                                       path=settings.BackupIndexFileName())
     packetsToCancel = packet_out.search_by_backup_id(packetID)
     for pkt_out in packetsToCancel:
         if pkt_out.outpacket.Command == commands.Retrieve():
             lg.warn('sending "cancel" to %s' % pkt_out)
             pkt_out.automat('cancel')
示例#6
0
 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 isAllTimedOut(self, *args, **kwargs):
     """
     Condition method.
     """
     for packetID, supplierIDURL in self.requests_packets_sent:
         pkts_out = packet_out.search_many(
             command=commands.Retrieve(),
             remote_idurl=supplierIDURL,
             packet_id=packetID,
         )
         if pkts_out:
             return False
     return True
示例#8
0
 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
示例#9
0
def SendRetreive(ownerID, creatorID, packetID, remoteID, payload='', callbacks={}):
    """
    """
    newpacket = signed.Packet(
        commands.Retrieve(),
        ownerID,
        creatorID,
        packetID,
        payload,
        remoteID,
    )
    result = gateway.outbox(newpacket, callbacks=callbacks)
    if _Debug:
        lg.out(_DebugLevel, 'p2p_service.SendRetreive packetID=%s' % packetID)
        lg.out(_DebugLevel, '  remoteID=%s  ownerID=%s  creatorID=%s' % (remoteID, ownerID, creatorID))
    return result
示例#10
0
 def DeleteBackupRequests(self, backupName):
     if self.shutdown:
         # if we're closing down this queue
         # (supplier replaced, don't any anything new)
         return
     packetsToRemove = set()
     for packetID in self.fileRequestQueue:
         if packetID.count(backupName):
             packetsToRemove.add(packetID)
             lg.out(
                 12,
                 'io_throttle.DeleteBackupRequests %s from request queue' %
                 packetID)
     for packetID in packetsToRemove:
         self.fileRequestQueue.remove(packetID)
         del self.fileRequestDict[packetID]
     packetsToCancel = packet_out.search_by_backup_id(backupName)
     for pkt_out in packetsToCancel:
         if pkt_out.outpacket.Command == commands.Retrieve():
             if pkt_out.outpacket.PacketID in packetsToRemove:
                 lg.warn('sending "cancel" to %s' % pkt_out)
                 pkt_out.automat('cancel')
     if len(self.fileRequestQueue) > 0:
         reactor.callLater(0, self.DoRequest)
示例#11
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
        # 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
示例#12
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