Exemplo n.º 1
0
def on_chunk_entities_timeout(interest):
    # NOTE: Bad design, if timeout -> do nothing, will be fetch next time
    # TODO: Check if remote peer is alive, if not remove from store and maybe
    # broadcast leave interest
    x, y = mngt.get_x_y_tuple(interest)

    chunk_uid = entities.MapChunk.gen_uid(mngt.context.game_id, x, y)
    mngt.pending_fetch.remove(chunk_uid)
    utils.on_timeout(interest)
    mngt.execute_callback(chunk_uid)
Exemplo n.º 2
0
def on_enter_chunk_interest(prefix, interest, face, interest_filter_id):
    uid = int(interest.getName().get(-1).toEscapedString())
    x, y = mngt.get_x_y_tuple(interest.getName().getPrefix(-1))
    logger.debug(
        'Received EnterChunkInterest for entity %d '
        'and chunk (%d, %d)', uid, x, y)
    mngt.load_entity(
        uid, (functools.partial(mngt.emit_enter_chunk_update, x, y, uid),
              functools.partial(mngt.send_entity_update_interest, uid)))
    mngt.load_chunk(x, y)
Exemplo n.º 3
0
def on_chunk_update_data(interest, data):
    x, y = mngt.get_x_y_tuple(data.getName().getPrefix(-1))
    uid = entities.MapChunk.gen_uid(mngt.context.game_id, x, y)

    _, update = entities.Result.deserialize(data.getContent().toBytes())
    logger.debug('Update received for chunk (%d, %d): %s', x, y, update)
    if update.status == const.status_code.ENTER_CHUNK:
        mngt.context.object_store.add(update.value)
        mngt.send_entity_update_interest(update.value.uid)

    mngt.send_chunk_update_interest(x, y, uid)
Exemplo n.º 4
0
def on_chunk_update_interest(prefix, interest, face, interest_filter_id):
    touch = False
    name = interest.getName()
    if interest.getName().get(-1).toEscapedString() == 'touch':
        touch = True
        name = name.getPrefix(-1)

    x, y = mngt.get_x_y_tuple(name)
    logger.debug('Received ChunkUpdateInterest for chunk (%d, %d)', x, y)
    chunk = mngt.context.object_store.get_chunk(x, y)

    if chunk is not None and touch:
        logger.debug('Chunk touched')
        chunk.touch()
    elif not chunk:
        mngt.load_chunk(x, y)
Exemplo n.º 5
0
def on_chunk_entities_interest(prefix, interest, face, interest_filter_id):
    """
    Try to get the requested chunk from the local store and send it back if
    found.
    Else initiate the recorvery procedure with the chunk id before creating
    the chunk if it did not managed to find it in remote peers store.
    """
    x, y = mngt.get_x_y_tuple(interest)

    chunk_uid = entities.MapChunk.gen_uid(mngt.context.game_id, x, y)
    chunk = mngt.context.object_store.get(chunk_uid)

    logger.debug('Received ChunkEntitiesInterest for chunk %d (%d, %d)',
                 chunk_uid, x, y)
    if chunk is not None:
        mngt.context.object_store.set_local_coordinator(chunk_uid, True)
        return mngt.send_chunk_entities_data(
            interest, face, chunk)

    cb = functools.partial(mngt.send_chunk_or_create, interest, face, x, y)
    mngt.start_recorvery(
        chunk_uid,
        failed_cb=cb,  # Failure : create then send
        success_cb=cb)  # Success : fetch in store then send