Ticket #1398: paused-handshake.diff

File paused-handshake.diff, 3.3 KB (added by charles, 12 years ago)

patch to shun incoming handshakes iff there are no non-paused torrents

  • libtransmission/port-forwarding.c

    struct tr_shared 
    4242    int                   bindSocket;
    4343    int                   publicPort;
    4444
    45     tr_handle *           h;
     45    tr_session *          session;
    4646    tr_timer *            pulseTimer;
    4747
    4848    tr_upnp *             upnp;
    natPulse( tr_shared * s ) 
    103103static void
    104104incomingPeersPulse( tr_shared * s )
    105105{
     106    int allPaused;
     107    tr_torrent * tor;
     108
    106109    if( s->bindSocket >= 0 && ( s->bindPort != s->publicPort ) )
    107110    {
    108111        tr_ninf( getKey( ), _( "Closing port %d" ), s->bindPort );
    incomingPeersPulse( tr_shared * s ) 
    136139        }
    137140    }
    138141
    139     for( ; ; ) /* check for new incoming peer connections */
     142    /* see if any torrents aren't paused */
     143    allPaused = 1;
     144    tor = NULL;
     145    while(( tor = tr_torrentNext( s->session, tor ))) {
     146        if( TR_STATUS_IS_ACTIVE( tr_torrentGetActivity( tor ))) {
     147            allPaused = 0;
     148            break;
     149        }
     150    }
     151
     152    /* if we have any running torrents, check for new incoming peer connections */
     153    while( !allPaused )
    140154    {
    141         int            socket;
    142         uint16_t       port;
     155        int socket;
     156        uint16_t port;
    143157        struct in_addr addr;
    144158
    145159        if( s->bindSocket < 0 )
    incomingPeersPulse( tr_shared * s ) 
    151165
    152166        tr_deepLog( __FILE__, __LINE__, NULL,
    153167                   "New INCOMING connection %d (%s)",
    154                    socket, tr_peerIoAddrStr( &addr,
    155                                              port ) );
     168                   socket, tr_peerIoAddrStr( &addr, port ) );
    156169
    157         tr_peerMgrAddIncoming( s->h->peerMgr, &addr, port, socket );
     170        tr_peerMgrAddIncoming( s->session->peerMgr, &addr, port, socket );
    158171    }
    159172}
    160173
    sharedPulse( void * vshared ) 
    177190        tr_netClose( shared->bindSocket );
    178191        tr_natpmpClose( shared->natpmp );
    179192        tr_upnpClose( shared->upnp );
    180         shared->h->shared = NULL;
     193        shared->session->shared = NULL;
    181194        tr_free( shared );
    182195        keepPulsing = 0;
    183196    }
    sharedPulse( void * vshared ) 
    190203***/
    191204
    192205tr_shared *
    193 tr_sharedInit( tr_handle * h,
    194                int         isEnabled,
    195                int         publicPort )
     206tr_sharedInit( tr_session * session,
     207               int          isEnabled,
     208               int          publicPort )
    196209{
    197210    tr_shared * s = tr_new0( tr_shared, 1 );
    198211
    199     s->h            = h;
     212    s->session      = session;
    200213    s->publicPort   = publicPort;
    201214    s->bindPort     = -1;
    202215    s->bindSocket   = -1;
    203216    s->natpmp       = tr_natpmpInit( );
    204217    s->upnp         = tr_upnpInit( );
    205     s->pulseTimer   = tr_timerNew( h, sharedPulse, s, 1000 );
     218    s->pulseTimer   = tr_timerNew( session, sharedPulse, s, 1000 );
    206219    s->isEnabled    = isEnabled ? 1 : 0;
    207220    s->upnpStatus   = TR_PORT_UNMAPPED;
    208221    s->natpmpStatus = TR_PORT_UNMAPPED;
    tr_sharedSetPort( tr_shared * s, 
    224237
    225238    s->publicPort = port;
    226239
    227     while( ( tor = tr_torrentNext( s->h, tor ) ) )
     240    while( ( tor = tr_torrentNext( s->session, tor ) ) )
    228241        tr_torrentChangeMyPort( tor );
    229242}
    230243