Changeset 4173


Ignore:
Timestamp:
Dec 15, 2007, 4:26:31 AM (14 years ago)
Author:
charles
Message:

lessons learned from 0.82:

  • if we can't bind a socket to a peer, take that peer out of the retry pool.
  • also, try to connect with more peers up-front.
Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-io.c

    r4036 r4173  
    175175                      const uint8_t         * torrentHash )
    176176{
     177    int socket;
     178
    177179    assert( handle != NULL );
    178180    assert( in_addr != NULL );
     
    180182    assert( torrentHash != NULL );
    181183
    182     return tr_peerIoNew( handle, in_addr, port,
    183                          torrentHash, 0,
    184                          tr_netOpenTCP( in_addr, port, 0 ) );
     184    socket = tr_netOpenTCP( in_addr, port, 0 );
     185
     186    return socket < 0
     187        ? NULL
     188        : tr_peerIoNew( handle, in_addr, port, torrentHash, 0, socket );
    185189}
    186190
  • trunk/libtransmission/peer-mgr.c

    r4010 r4173  
    111111    /* number of bad pieces a peer is allowed to send before we ban them */
    112112    MAX_BAD_PIECES_PER_PEER = 3,
     113
    113114    /* use for bitwise operations w/peer_atom.myflags */
    114     MYFLAG_BANNED = 1
     115    MYFLAG_BANNED = 1,
     116
     117    /* unreachable for now... but not banned.  if they try to connect to us it's okay */
     118    MYFLAG_UNREACHABLE = 2
    115119};
    116120
     
    17361740        /* peer fed us too much bad data ... we only keep it around
    17371741         * now to weed it out in case someone sends it to us via pex */
    1738         if( atom->myflags & MYFLAG_BANNED ) {
    1739 #if 0
    1740             tordbg( t, "RECONNECT peer %d (%s) is banned...",
    1741                     i, tr_peerIoAddrStr(&atom->addr,atom->port) );
    1742 #endif
     1742        if( atom->myflags & MYFLAG_BANNED )
    17431743            continue;
    1744         }
     1744
     1745        /* peer was unconnectable before, so we're not going to keep trying.
     1746         * this is needs a separate flag from `banned', since if they try
     1747         * to connect to us later, we'll let them in */
     1748        if( atom->myflags & MYFLAG_UNREACHABLE )
     1749            continue;
    17451750
    17461751        /* we don't need two connections to the same peer... */
    1747         if( peerIsInUse( t, &atom->addr ) ) {
    1748 #if 0
    1749             tordbg( t, "RECONNECT peer %d (%s) is in use..",
    1750                     i, tr_peerIoAddrStr(&atom->addr,atom->port) );
    1751 #endif
     1752        if( peerIsInUse( t, &atom->addr ) )
    17521753            continue;
    1753         }
    17541754
    17551755        /* no need to connect if we're both seeds... */
    1756         if( seed && (atom->flags & ADDED_F_SEED_FLAG) ) {
    1757 #if 0
    1758             tordbg( t, "RECONNECT peer %d (%s) is a seed and so are we..",
    1759                     i, tr_peerIoAddrStr(&atom->addr,atom->port) );
    1760 #endif
     1756        if( seed && (atom->flags & ADDED_F_SEED_FLAG) )
    17611757            continue;
    1762         }
    17631758
    17641759        /* we're wasting our time trying to connect to this bozo. */
    1765         if( atom->numFails > 10 ) {
    1766 #if 0
    1767             tordbg( t, "RECONNECT peer %d (%s) gives us nothing but failure.",
    1768                     i, tr_peerIoAddrStr(&atom->addr,atom->port) );
    1769 #endif
     1760        if( atom->numFails > 10 )
    17701761            continue;
    1771         }
    17721762
    17731763        /* if we used this peer recently, give someone else a turn */
     
    18041794    else
    18051795    {
    1806         int i, nCandidates, nBad;
     1796        int i, nCandidates, nBad, addMax;
    18071797        struct peer_atom ** candidates = getPeerCandidates( t, &nCandidates );
    18081798        struct tr_peer ** connections = getPeersToClose( t, &nBad );
     
    18301820
    18311821        /* add some new ones */
     1822        addMax = tr_ptrArraySize(t->pool)
     1823            ? MAX_RECONNECTIONS_PER_PULSE
     1824            : MAX_CONNECTED_PEERS_PER_TORRENT;
     1825         
    18321826        for( i=0; i<nCandidates && i<MAX_RECONNECTIONS_PER_PULSE; ++i )
    18331827        {
     
    18351829            struct peer_atom * atom = candidates[i];
    18361830            tr_peerIo * io;
    1837             tr_handshake * handshake;
    18381831
    18391832            tordbg( t, "Starting an OUTGOING connection with %s",
     
    18411834
    18421835            io = tr_peerIoNewOutgoing( mgr->handle, &atom->addr, atom->port, t->hash );
    1843 
    1844             handshake = tr_handshakeNew( io,
    1845                                          mgr->handle->encryptionMode,
    1846                                          myHandshakeDoneCB,
    1847                                          mgr );
    1848 
    1849             assert( tr_peerIoGetTorrentHash( io ) != NULL );
    1850 
    1851             tr_ptrArrayInsertSorted( t->outgoingHandshakes, handshake, handshakeCompare );
     1836            if( io == NULL )
     1837            {
     1838                atom->myflags |= MYFLAG_UNREACHABLE;
     1839            }
     1840            else
     1841            {
     1842                tr_handshake * handshake = tr_handshakeNew( io,
     1843                                                            mgr->handle->encryptionMode,
     1844                                                            myHandshakeDoneCB,
     1845                                                            mgr );
     1846
     1847                assert( tr_peerIoGetTorrentHash( io ) != NULL );
     1848
     1849                tr_ptrArrayInsertSorted( t->outgoingHandshakes, handshake, handshakeCompare );
     1850            }
    18521851
    18531852            atom->time = time( NULL );
Note: See TracChangeset for help on using the changeset viewer.