Esempio n. 1
0
def send_chunk_to(client: hash.Hash, chk):
    chk = check_for_string(chk)

    from_cli = chunk.get_chunk_owner(chk)
    if from_cli is None:
        logger.warn('could not find any user hosting {}'.format(chk.pretty()))
        return

    logger.debug('{} is being sent from {} to {}'.format(
        chk.pretty(), from_cli.username, client.username))
    protocol.send_CSND(from_cli, client, 1, chk)
    protocol.send_CSND(client, from_cli, 0, chk)
    chunk.register_chunk(chk, client)
Esempio n. 2
0
def send_chunk_to(client: hash.Hash, chk):
    chk = check_for_string(chk)

    from_cli = chunk.get_chunk_owner(chk)
    if from_cli is None:
        logger.warn('could not find any user hosting {}'.format(chk.pretty()))
        return

    logger.debug('{} is being sent from {} to {}'
                 .format(chk.pretty(), from_cli.username, client.username))
    protocol.send_CSND(from_cli, client, 1, chk)
    protocol.send_CSND(client, from_cli, 0, chk)
    chunk.register_chunk(chk, client)
Esempio n. 3
0
def FADD(directory, from_who, filename, tree, client):
    logger.debug('user {} adding {} from {}'.format(client.username,
                                                    tree['path'], from_who))

    if from_who == 'server':
        protocol.send_FADD(tree, client)
    elif tree['kind'] != 0:
        hsh = chunk.register_chunk(hash.Hash(tree['unique_hash']), client)
        chunk.keep_chunk_alive(client, hsh)

        for instance in shared.climanager.clients[client.username]:
            if instance is not client:
                FADD(directory, 'server', filename, tree, instance)
    else:
        pass  # TODO: handle adding a directory with some content

    directory[filename] = tree
Esempio n. 4
0
def FADD(directory, from_who, filename, tree, client):
    logger.debug('user {} adding {} from {}'
                 .format(client.username, tree['path'], from_who))

    if from_who == 'server':
        protocol.send_FADD(tree, client)
    elif tree['kind'] != 0:
        hsh = chunk.register_chunk(hash.Hash(tree['unique_hash']), client)
        chunk.keep_chunk_alive(client, hsh)

        for instance in shared.climanager.clients[client.username]:
            if instance is not client:
                FADD(directory, 'server', filename, tree, instance)
    else:
        pass  # TODO: handle adding a directory with some content

    directory[filename] = tree
Esempio n. 5
0
def all():
    chunk.add_user('sevauk', ['a', 'b', 'c'])
    chunk.register_chunk('d', 'sevauk')
    chunk.register_chunk('a', 'matt')
    chunk.register_chunk('z', 'paul')
    chunk.remove_user('matt')
    chunk.register_chunk('a', 'joe')
    chunk.register_chunk('d', 'matt')
    chunk.register_chunk('chunk', 'sevauk')
    chunk.register_chunk('chunk', 'matt')
    chunk.register_chunk('chunk', 'marc')
    chunk.remove_chunk('chunk')
    chunk.remove_chunk('b')
    chunk.remove_chunk('c')
    assert chunk.has_user_chunk('d', 'sevauk')
    assert chunk.chunks == {'a': ['sevauk', 'joe'], 'z': ['paul'], 'd': ['sevauk', 'matt']}
    assert chunk.users == {'paul': ['z'], 'marc': [], 'sevauk': ['a', 'd'], 'joe': ['a'], 'matt': ['d']}