Пример #1
0
 def doSendMyListFiles(self, *args, **kwargs):
     """
     Action method.
     """
     json_list_files = backup_fs.Serialize(
         to_json=True,
         filter_cb=lambda path_id, path, info: True if strng.to_text(info.key_id) == strng.to_text(self.key_id) else False,
     )
     # raw_list_files = json.dumps(json_list_files, indent=2, encoding='utf-8')
     raw_list_files = serialization.DictToBytes(json_list_files, keys_to_text=True, values_to_text=True)
     if _Debug:
         lg.out(_DebugLevel, 'shared_access_donor.doSendMyListFiles prepared list of files for %s :\n%s' % (
             self.remote_idurl, raw_list_files))
     block = encrypted.Block(
         CreatorID=my_id.getLocalID(),
         BackupID=self.key_id,
         Data=raw_list_files,
         SessionKey=key.NewSessionKey(),
         EncryptKey=self.key_id,
     )
     encrypted_list_files = block.Serialize()
     packet_id = "%s:%s" % (self.key_id, packetid.UniqueID(), )
     p2p_service.SendFiles(
         idurl=self.remote_idurl,
         raw_list_files_info=encrypted_list_files,
         packet_id=packet_id,
         callbacks={
             commands.Ack(): lambda response, _: self.automat('list-files-ok', response),
             commands.Fail(): lambda response, _: self.automat('fail', Exception(str(response))),
             None: lambda pkt_out: self.automat('fail', Exception('timeout')),
         },
     )
Пример #2
0
def WriteIndex(filepath=None, encoding='utf-8'):
    """
    Write index data base to the local file .bitdust/metadata/index.
    """
    global _LoadingFlag
    if _LoadingFlag:
        return
    if filepath is None:
        filepath = settings.BackupIndexFilePath()
    json_data = {}
    # json_data = backup_fs.Serialize(to_json=True, encoding=encoding)
    for customer_idurl in backup_fs.known_customers():
        customer_id = global_id.UrlToGlobalID(customer_idurl)
        json_data[customer_id] = backup_fs.Serialize(
            iterID=backup_fs.fsID(customer_idurl),
            to_json=True,
            encoding=encoding,
        )
    src = '%d\n' % revision()
    src += json.dumps(json_data,
                      indent=1,
                      separators=(',', ':'),
                      encoding=encoding)
    if _Debug:
        import pprint
        lg.out(_DebugLevel, pprint.pformat(json_data))
    return bpio.WriteTextFile(filepath, src)
Пример #3
0
def WriteIndex(filepath=None, encoding='utf-8'):
    """
    Write index data base to the local file .bitdust/metadata/index.
    """
    global _LoadingFlag
    if _LoadingFlag:
        return
    if filepath is None:
        filepath = settings.BackupIndexFilePath()
    json_data = {}
    for customer_idurl in backup_fs.known_customers():
        customer_id = customer_idurl.to_id()
        json_data[customer_id] = backup_fs.Serialize(
            iterID=backup_fs.fsID(customer_idurl),
            to_json=True,
            encoding=encoding,
        )
    src = '%d\n' % revision()
    src += jsn.dumps(
        json_data,
        indent=1,
        separators=(',', ':'),
        encoding=encoding,
    )
    if _Debug:
        lg.args(_DebugLevel, size=len(src), filepath=filepath)
    return bpio.WriteTextFile(filepath, src)
Пример #4
0
def WriteIndex(filepath=None):
    """
    Write index data base to the local file .bitdust/metadata/index.
    """
    global _LoadingFlag
    if _LoadingFlag:
        return
    if filepath is None:
        filepath = settings.BackupIndexFilePath()
    src = '%d\n' % revision()
    src += backup_fs.Serialize(to_json=True)
    return bpio.AtomicWriteFile(filepath, src)
Пример #5
0
 def doSendMyListFiles(self, arg):
     """
     Action method.
     """
     json_list_files = backup_fs.Serialize(
         to_json=True,
         filter_cb=lambda path_id, path, info: True
         if info.key_id == self.key_id else False,
     )
     raw_list_files = json.dumps(json_list_files,
                                 indent=2,
                                 encoding='utf-8')
     block = encrypted.Block(
         CreatorID=my_id.getLocalID(),
         BackupID=self.key_id,
         Data=raw_list_files,
         SessionKey=key.NewSessionKey(),
         # encrypt data using public key of recipient
         EncryptKey=lambda inp: self.remote_identity.encrypt(inp),
     )
     encrypted_list_files = block.Serialize()
     packet_id = "%s:%s" % (self.key_id, packetid.UniqueID())
     p2p_service.SendFiles(
         idurl=self.remote_idurl,
         raw_list_files_info=encrypted_list_files,
         packet_id=packet_id,
         callbacks={
             commands.Ack():
             lambda response, _: self.automat('list-files-ok', response),
             commands.Fail():
             lambda response, _: self.automat('fail',
                                              Exception(str(response))),
             None:
             lambda pkt_out: self.automat('fail', Exception('timeout')),
         },
     )