Esempio n. 1
0
def ListResult(packet):
    dhnio.Dprint(7, "supplierpatrol.ListResult got result from " + packet.OwnerID)
    supnum=contacts.numberForSupplier(packet.OwnerID)
    filename= os.path.join(settings.FileListDir(), str(supnum))
    dhnio.WriteFile(filename, packet.Data)
    global NumRequestsOutstanding
    NumRequestsOutstanding -= 1
    dhnio.Dprint(7, "supplierpatrol.ListResult  NumRequestsOutstanding = " + str(NumRequestsOutstanding))
    CheckCallback()
Esempio n. 2
0
def ReadLatestRawListFiles():
    """
    Call `ReadRawListFiles()` for every local file we have on hands and build whole "remote" matrix.
    """
    dhnio.Dprint(4, 'backup_matrix.ReadLatestRawListFiles')
    for idurl in contacts.getSupplierIDs():
        if idurl:
            filename = os.path.join(settings.SupplierPath(idurl, 'listfiles'))
            if os.path.isfile(filename):
                listFileText = dhnio.ReadTextFile(filename)
                if listFileText.strip() != '':
                    ReadRawListFiles(contacts.numberForSupplier(idurl), listFileText)
Esempio n. 3
0
def SendReplaceSupplier(numORidurl, doAck=False):
    """
    Send "FireContact" packet to Central server, 
    this will replace given supplier with a random guy.
    """
    if isinstance(numORidurl, str):
        idurl = numORidurl
    else:
        idurl = contacts.getSupplierID(numORidurl)
    if not idurl:
        dhnio.Dprint(2, "central_service.SendReplaceSupplier ERROR supplier not found")
        return None
    dhnio.Dprint(4, "central_service.SendReplaceSupplier [%s]" % nameurl.GetName(idurl))
    data = 'S\n'+idurl+'\n'+str(contacts.numberForSupplier(idurl))
    ret = send2central(commands.FireContact(), data, doAck)
    events.notify('central_service', 'sent request to dismiss supplier %s' % nameurl.GetName(idurl))
    return ret
Esempio n. 4
0
def IncomingSupplierListFiles(packet):
    """
    Called by `p2p.p2p_service` when command "Files" were received from one of our suppliers.
    This is an answer from given supplier (after our request) to get a list of our files stored on his machine.
    """
    supplier_idurl = packet.OwnerID
    num = contacts.numberForSupplier(supplier_idurl)
    if num < -1:
        dhnio.Dprint(2, 'backup_control.IncomingSupplierListFiles ERROR unknown supplier: %s' % supplier_idurl)
        return
    src = p2p_service.UnpackListFiles(packet.Payload, settings.ListFilesFormat())
    backups2remove, paths2remove = backup_matrix.ReadRawListFiles(num, src)
    list_files_orator.IncomingListFiles(packet)
    backup_matrix.SaveLatestRawListFiles(supplier_idurl, src)
    if len(backups2remove) > 0:
        p2p_service.RequestDeleteListBackups(backups2remove)
    if len(paths2remove) > 0:
        p2p_service.RequestDeleteListPaths(paths2remove)
    del backups2remove
    del paths2remove
    dhnio.Dprint(8, 'backup_control.IncomingSupplierListFiles from [%s] %s bytes long' % (
        nameurl.GetName(supplier_idurl), len(packet.Payload)))
Esempio n. 5
0
def HandleSuppliersAck(ackpacket):
    Num = contacts.numberForSupplier(ackpacket.OwnerID)
    dhnio.Dprint(8, "identitypropagate.HandleSupplierAck ")
Esempio n. 6
0
def HandleSingleSupplier(ackpacket):
    Num = contacts.numberForSupplier(ackpacket.OwnerID)