Ignore:
Timestamp:
Nov 9, 2006, 4:45:14 AM (16 years ago)
Author:
titer
Message:

Saves a list of peers when you pause a torrent, and tries to reconnect to them next time you resume it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer.c

    r931 r1060  
    152152
    153153/***********************************************************************
     154 * tr_peerAddCompactMany
     155 ***********************************************************************
     156 * Adds several peers in compact form
     157 **********************************************************************/
     158void tr_peerAddCompactMany( tr_torrent_t * tor, uint8_t * buf, int len )
     159{
     160    struct in_addr addr;
     161    in_port_t port;
     162    int i;
     163
     164    len /= 6;
     165    for( i = 0; i < len; i++ )
     166    {
     167        memcpy( &addr, buf, 4 ); buf += 4;
     168        memcpy( &port, buf, 2 ); buf += 2;
     169        tr_peerAddCompact( tor, addr, port );
     170    }
     171}
     172
     173/***********************************************************************
    154174 * tr_peerInit
    155175 ***********************************************************************
     
    617637    tr_bitfieldRem( peer->blamefield, piece );
    618638}
     639
     640int tr_peerGetConnectable( tr_torrent_t * tor, uint8_t ** _buf )
     641{
     642    int count = 0;
     643    uint8_t * buf = malloc( 6 * tor->peerCount );
     644    tr_peer_t * peer;
     645    int i;
     646
     647    for( i = 0; i < tor->peerCount; i++ )
     648    {
     649        peer = tor->peers[i];
     650
     651        /* Skip peers for which the connection isn't established,
     652         * and peers that came from incoming connections */
     653        if( peer->status < PEER_STATUS_CONNECTED )
     654            continue;
     655        if( peer->incoming )
     656            continue;
     657
     658        memcpy( &buf[count*6], &peer->addr, 4 );
     659        memcpy( &buf[count*6+4], &peer->port, 2 );
     660        count++;
     661    }
     662
     663    if( count < 1 )
     664    {
     665        free( buf );
     666        *_buf = NULL;
     667    }
     668    else
     669    {
     670        *_buf = buf;
     671    }
     672
     673    return count * 6;
     674}
Note: See TracChangeset for help on using the changeset viewer.