Esempio n. 1
0
void
tr_bandwidthSetParent( tr_bandwidth  * b,
                       tr_bandwidth  * parent )
{
    assert( tr_isBandwidth( b ) );
    assert( b != parent );

    if( b->parent )
    {
        void * removed;

        assert( tr_isBandwidth( b->parent ) );

        removed = tr_ptrArrayRemoveSorted( &b->parent->children, b, comparePointers );
        assert( removed == b );
        assert( tr_ptrArrayFindSorted( &b->parent->children, b, comparePointers ) == NULL );

        b->parent = NULL;
    }

    if( parent )
    {
        assert( tr_isBandwidth( parent ) );
        assert( parent->parent != b );

        tr_ptrArrayInsertSorted( &parent->children, b, comparePointers );
        assert( tr_ptrArrayFindSorted( &parent->children, b, comparePointers ) == b );
        b->parent = parent;
    }
}
Esempio n. 2
0
static const char*
dns_cache_set_name( struct tr_web_task * task, const char * host,
                   const char * resolved, int ttl )
{
    char * ret = NULL;

    ttl = MAX( MIN_DNS_CACHE_TIME, ttl );

    if( task->session->web != NULL )
    {
        struct dns_cache_item * item;
        tr_ptrArray * cache = &task->session->web->dns_cache;

        dns_cache_clear_entry( cache, host );

        item = tr_new( struct dns_cache_item, 1 );
        item->host = tr_strdup( host );
        item->resolved_host = tr_strdup( resolved );
        item->expiration = tr_time( ) + ttl;
        item->success = TRUE;
        tr_ptrArrayInsertSorted( cache, item, dns_cache_compare );
        ret = item->resolved_host;
        dbgmsg( "adding dns cache entry for \"%s\": %s", host, resolved );
    }
    return ret;
}
Esempio n. 3
0
void
tr_bandwidthAddPeer( tr_bandwidth   * b,
                     tr_peerIo      * peerIo )
{
    assert( tr_isBandwidth( b ) );
    assert( tr_isPeerIo( peerIo ) );

    tr_ptrArrayInsertSorted( b->peers, peerIo, comparePointers );
}
Esempio n. 4
0
static void
dns_cache_set_fail( struct tr_web_task * task, const char * host )
{
    if( ( task->session->web != NULL ) && ( host != NULL ) )
    {
        struct dns_cache_item * item;
        tr_ptrArray * cache = &task->session->web->dns_cache;

        dns_cache_clear_entry( cache, host );

        item = tr_new( struct dns_cache_item, 1 );
        item->host = tr_strdup( host );
        item->resolved_host = NULL;
        item->expiration = tr_time( ) + MIN_DNS_CACHE_TIME;
        item->success = FALSE;
        tr_ptrArrayInsertSorted( cache, item, dns_cache_compare );
    }
}
Esempio n. 5
0
int
tr_cacheWriteBlock( tr_cache         * cache,
                    tr_torrent       * torrent,
                    tr_piece_index_t   piece,
                    uint32_t           offset,
                    uint32_t           length,
                    struct evbuffer  * writeme )
{
    struct cache_block * cb = findBlock( cache, torrent, piece, offset );

    if( cb == NULL )
    {
        cb = tr_new( struct cache_block, 1 );
        cb->tor = torrent;
        cb->piece = piece;
        cb->offset = offset;
        cb->length = length;
        cb->block = _tr_block( torrent, piece, offset );
        cb->evbuf = evbuffer_new( );
        tr_ptrArrayInsertSorted( &cache->blocks, cb, cache_block_compare );
    }