Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- transmission-1.76_orig/libtransmission/peer-mgr.c 2009-10-25 02:47:21.000000000 +0100
- +++ transmission-1.76/libtransmission/peer-mgr.c 2009-11-22 02:45:51.393980440 +0100
- @@ -2276,10 +2276,6 @@
- if( atom->myflags & MYFLAG_UNREACHABLE )
- continue;
- - /* we don't need two connections to the same peer... */
- - if( peerIsInUse( t, &atom->addr ) )
- - continue;
- -
- /* no need to connect if we're both seeds... */
- if( seed && ( ( atom->flags & ADDED_F_SEED_FLAG ) ||
- ( atom->uploadOnly == UPLOAD_ONLY_YES ) ) )
- @@ -2298,10 +2294,15 @@
- if( tr_sessionIsAddressBlocked( t->manager->session, &atom->addr ) )
- continue;
- + /* we don't need two connections to the same peer... */
- + if( peerIsInUse( t, &atom->addr ) )
- + continue;
- +
- ret[retCount++] = atom;
- }
- - qsort( ret, retCount, sizeof( struct peer_atom* ), compareCandidates );
- + if( retCount != 0 )
- + qsort( ret, retCount, sizeof( struct peer_atom* ), compareCandidates );
- *setmeSize = retCount;
- return ret;
- }
- @@ -2333,9 +2334,8 @@
- {
- static time_t prevTime = 0;
- static int newConnectionsThisSecond = 0;
- - time_t now;
- + time_t now = time( NULL );
- - now = time( NULL );
- if( prevTime != now )
- {
- prevTime = now;
- @@ -2349,92 +2349,119 @@
- else
- {
- int i;
- - int canCloseCount;
- int mustCloseCount;
- - int candidateCount;
- int maxCandidates;
- - struct tr_peer ** canClose = getPeersToClose( t, TR_CAN_CLOSE, &canCloseCount );
- struct tr_peer ** mustClose = getPeersToClose( t, TR_MUST_CLOSE, &mustCloseCount );
- - struct peer_atom ** candidates = getPeerCandidates( t, &candidateCount );
- -
- - tordbg( t, "reconnect pulse for [%s]: "
- - "%d must-close connections, "
- - "%d can-close connections, "
- - "%d connection candidates, "
- - "%d atoms, "
- - "max per pulse is %d",
- - t->tor->info.name,
- - mustCloseCount,
- - canCloseCount,
- - candidateCount,
- - tr_ptrArraySize( &t->pool ),
- - MAX_RECONNECTIONS_PER_PULSE );
- /* disconnect the really bad peers */
- for( i=0; i<mustCloseCount; ++i )
- closePeer( t, mustClose[i] );
- /* decide how many peers can we try to add in this pass */
- - maxCandidates = candidateCount;
- - maxCandidates = MIN( maxCandidates, MAX_RECONNECTIONS_PER_PULSE );
- + maxCandidates = MAX_RECONNECTIONS_PER_PULSE;
- maxCandidates = MIN( maxCandidates, getMaxPeerCount( t->tor ) - getPeerCount( t ) );
- maxCandidates = MIN( maxCandidates, MAX_CONNECTIONS_PER_SECOND - newConnectionsThisSecond );
- - /* maybe disconnect some lesser peers, if we have candidates to replace them with */
- - for( i=0; ( i<canCloseCount ) && ( i<maxCandidates ); ++i )
- - closePeer( t, canClose[i] );
- -
- - tordbg( t, "candidateCount is %d, MAX_RECONNECTIONS_PER_PULSE is %d,"
- - " getPeerCount(t) is %d, getMaxPeerCount(t) is %d, "
- - "newConnectionsThisSecond is %d, MAX_CONNECTIONS_PER_SECOND is %d",
- - candidateCount,
- - MAX_RECONNECTIONS_PER_PULSE,
- - getPeerCount( t ),
- - getMaxPeerCount( t->tor ),
- - newConnectionsThisSecond, MAX_CONNECTIONS_PER_SECOND );
- -
- - /* add some new ones */
- - for( i=0; i<maxCandidates; ++i )
- + if( maxCandidates == 0 )
- {
- - tr_peerMgr * mgr = t->manager;
- - struct peer_atom * atom = candidates[i];
- - tr_peerIo * io;
- -
- - tordbg( t, "Starting an OUTGOING connection with %s",
- - tr_peerIoAddrStr( &atom->addr, atom->port ) );
- -
- - io = tr_peerIoNewOutgoing( mgr->session, mgr->session->bandwidth, &atom->addr, atom->port, t->tor->info.hash );
- -
- - if( io == NULL )
- - {
- - tordbg( t, "peerIo not created; marking peer %s as unreachable",
- - tr_peerIoAddrStr( &atom->addr, atom->port ) );
- - atom->myflags |= MYFLAG_UNREACHABLE;
- - }
- - else
- - {
- - tr_handshake * handshake = tr_handshakeNew( io,
- - mgr->session->encryptionMode,
- - myHandshakeDoneCB,
- - mgr );
- -
- - assert( tr_peerIoGetTorrentHash( io ) );
- -
- - tr_peerIoUnref( io ); /* balanced by the implicit ref in tr_peerIoNewOutgoing() */
- -
- - ++newConnectionsThisSecond;
- -
- - tr_ptrArrayInsertSorted( &t->outgoingHandshakes, handshake,
- - handshakeCompare );
- - }
- -
- - atom->time = time( NULL );
- + tordbg( t, "reconnect pulse for [%s]: "
- + "%d must-close connections, "
- + "%d connection candidates _needed_, "
- + "%d atoms, "
- + "max per pulse is %d",
- + t->tor->info.name,
- + mustCloseCount,
- + maxCandidates,
- + tr_ptrArraySize( &t->pool ),
- + MAX_RECONNECTIONS_PER_PULSE );
- +
- + tordbg( t, "maxCandidates is %d, MAX_RECONNECTIONS_PER_PULSE is %d,"
- + " getPeerCount(t) is %d, getMaxPeerCount(t) is %d, "
- + "newConnectionsThisSecond is %d, MAX_CONNECTIONS_PER_SECOND is %d",
- + maxCandidates,
- + MAX_RECONNECTIONS_PER_PULSE,
- + getPeerCount( t ),
- + getMaxPeerCount( t->tor ),
- + newConnectionsThisSecond, MAX_CONNECTIONS_PER_SECOND );
- }
- -
- - /* cleanup */
- - tr_free( candidates );
- - tr_free( mustClose );
- - tr_free( canClose );
- + else
- + {
- + int canCloseCount;
- + int candidateCount;
- + struct tr_peer ** canClose = getPeersToClose( t, TR_CAN_CLOSE, &canCloseCount );
- + struct peer_atom ** candidates;
- +
- + candidates = getPeerCandidates( t, &candidateCount );
- + maxCandidates = MIN( maxCandidates, candidateCount );
- +
- + tordbg( t, "reconnect pulse for [%s]: "
- + "%d must-close connections, "
- + "%d can-close connections, "
- + "%d connection candidates, "
- + "%d atoms, "
- + "max per pulse is %d",
- + t->tor->info.name,
- + mustCloseCount,
- + canCloseCount,
- + candidateCount,
- + tr_ptrArraySize( &t->pool ),
- + MAX_RECONNECTIONS_PER_PULSE );
- +
- + /* maybe disconnect some lesser peers, if we have candidates to replace them with */
- + for( i=0; ( i<canCloseCount ) && ( i<maxCandidates ); ++i )
- + closePeer( t, canClose[i] );
- +
- + tordbg( t, "candidateCount is %d, MAX_RECONNECTIONS_PER_PULSE is %d,"
- + " getPeerCount(t) is %d, getMaxPeerCount(t) is %d, "
- + "newConnectionsThisSecond is %d, MAX_CONNECTIONS_PER_SECOND is %d",
- + candidateCount,
- + MAX_RECONNECTIONS_PER_PULSE,
- + getPeerCount( t ),
- + getMaxPeerCount( t->tor ),
- + newConnectionsThisSecond, MAX_CONNECTIONS_PER_SECOND );
- +
- + /* add some new ones */
- + for( i=0; i<maxCandidates; ++i )
- + {
- + tr_peerMgr * mgr = t->manager;
- + struct peer_atom * atom = candidates[i];
- + tr_peerIo * io;
- +
- + tordbg( t, "Starting an OUTGOING connection with %s",
- + tr_peerIoAddrStr( &atom->addr, atom->port ) );
- +
- + io = tr_peerIoNewOutgoing( mgr->session, mgr->session->bandwidth, &atom->addr, atom->port, t->tor->info.hash );
- +
- + if( io == NULL )
- + {
- + tordbg( t, "peerIo not created; marking peer %s as unreachable",
- + tr_peerIoAddrStr( &atom->addr, atom->port ) );
- + atom->myflags |= MYFLAG_UNREACHABLE;
- + }
- + else
- + {
- + tr_handshake * handshake = tr_handshakeNew( io,
- + mgr->session->encryptionMode,
- + myHandshakeDoneCB,
- + mgr );
- +
- + assert( tr_peerIoGetTorrentHash( io ) );
- +
- + tr_peerIoUnref( io ); /* balanced by the implicit ref in tr_peerIoNewOutgoing() */
- +
- + ++newConnectionsThisSecond;
- +
- + tr_ptrArrayInsertSorted( &t->outgoingHandshakes, handshake,
- + handshakeCompare );
- + }
- +
- + atom->time = time( NULL );
- + }
- + /* cleanup */
- + tr_free( candidates );
- + tr_free( canClose );
- + }
- + tr_free( mustClose );
- }
- }
Add Comment
Please, Sign In to add comment