コード例 #1
0
 def doSendRejectService(self, arg):
     """
     Action method.
     """
     space_dict, spent_bytes, current_customers, removed_customers = arg
     for customer_idurl in removed_customers:
         p2p_service.SendFailNoRequest(customer_idurl, packetid.UniqueID(), 'service rejected')
         events.send('existing-customer-terminated', dict(idurl=customer_idurl))
     self.automat('packets-sent')
コード例 #2
0
ファイル: list_files.py プロジェクト: StasEvseev/devel
def send(customer_idurl, packet_id, format_type, key_id, remote_idurl):
    if not my_keys.is_key_registered(key_id):
        lg.warn(
            'not able to return Files() for customer %s, key %s not registered'
            % (
                customer_idurl,
                key_id,
            ))
        return p2p_service.SendFailNoRequest(customer_idurl, packet_id)
    if _Debug:
        lg.out(
            _DebugLevel,
            "list_files.send to %s, customer_idurl=%s, key_id=%s" % (
                remote_idurl,
                customer_idurl,
                key_id,
            ))
    ownerdir = settings.getCustomerFilesDir(customer_idurl)
    plaintext = ''
    if os.path.isdir(ownerdir):
        for key_alias in os.listdir(ownerdir):
            if not misc.ValidKeyAlias(str(key_alias)):
                continue
            key_alias_dir = os.path.join(ownerdir, key_alias)
            plaintext += TreeSummary(key_alias_dir, key_alias)
    else:
        lg.warn('did not found customer dir: %s' % ownerdir)
    if _Debug:
        lg.out(_DebugLevel + 8, '\n%s' % plaintext)
    raw_list_files = PackListFiles(plaintext, format_type)
    block = encrypted.Block(
        CreatorID=my_id.getLocalID(),
        BackupID=key_id,
        Data=raw_list_files,
        SessionKey=key.NewSessionKey(),
        EncryptKey=key_id,
    )
    encrypted_list_files = block.Serialize()
    newpacket = p2p_service.SendFiles(
        idurl=remote_idurl,
        raw_list_files_info=encrypted_list_files,
        packet_id=packet_id,
        callbacks={
            commands.Ack(): on_acked,
            commands.Fail(): on_failed,
            None: on_timeout,
        },
    )
    return newpacket
コード例 #3
0
 def doSendRejectService(self, *args, **kwargs):
     """
     Action method.
     """
     space_dict, free_space, spent_bytes, current_customers, removed_customers = args[
         0]
     for customer_idurl in removed_customers:
         p2p_service.SendFailNoRequest(customer_idurl, packetid.UniqueID(),
                                       'service rejected')
         events.send(
             'existing-customer-terminated',
             dict(
                 idurl=customer_idurl,
                 ecc_map=eccmap.Current().name,
             ))
     self.automat('packets-sent')
コード例 #4
0
def send(customer_idurl,
         packet_id,
         format_type,
         key_id,
         remote_idurl,
         query_items=[]):
    if not query_items:
        query_items = [
            '*',
        ]
    key_id = my_keys.latest_key_id(key_id)
    parts = global_id.ParseGlobalID(key_id)
    if parts['key_alias'] == 'master' and parts['idurl'] != my_id.getIDURL():
        # lg.warn('incoming ListFiles() request with customer "master" key: %r' % key_id)
        if not my_keys.is_key_registered(key_id) and identitycache.HasKey(
                parts['idurl']):
            lg.info(
                'customer public key %r to be registered locally for the first time'
                % key_id)
            known_ident = identitycache.FromCache(parts['idurl'])
            if not my_keys.register_key(key_id, known_ident.getPublicKey()):
                lg.err(
                    'failed to register known public key of the customer: %r' %
                    key_id)
    if not my_keys.is_key_registered(key_id):
        lg.warn(
            'not able to return Files() for customer %s, key %s not registered'
            % (
                customer_idurl,
                key_id,
            ))
        return p2p_service.SendFailNoRequest(customer_idurl,
                                             packet_id,
                                             response='key not registered')
    if _Debug:
        lg.out(
            _DebugLevel,
            "list_files.send to %s, customer_idurl=%s, key_id=%s, query_items=%r"
            % (
                remote_idurl,
                customer_idurl,
                key_id,
                query_items,
            ))
    ownerdir = settings.getCustomerFilesDir(customer_idurl)
    plaintext = ''
    if os.path.isdir(ownerdir):
        try:
            for query_path in query_items:
                plaintext += process_query_item(query_path, parts['key_alias'],
                                                ownerdir)
        except:
            lg.exc()
            return p2p_service.SendFailNoRequest(
                customer_idurl,
                packet_id,
                response='list files query processing error')
    else:
        lg.warn('did not found customer folder: %s' % ownerdir)
    if _Debug:
        lg.out(_DebugLevel, '\n%s' % plaintext)
    raw_list_files = PackListFiles(plaintext, format_type)
    block = encrypted.Block(
        CreatorID=my_id.getIDURL(),
        BackupID=key_id,
        Data=raw_list_files,
        SessionKey=key.NewSessionKey(session_key_type=key.SessionKeyType()),
        SessionKeyType=key.SessionKeyType(),
        EncryptKey=key_id,
    )
    encrypted_list_files = block.Serialize()
    newpacket = p2p_service.SendFiles(
        idurl=remote_idurl,
        raw_list_files_info=encrypted_list_files,
        packet_id=packet_id,
        callbacks={
            commands.Ack(): on_acked,
            commands.Fail(): on_failed,
            None: on_timeout,
        },
    )
    return newpacket