Ignore:
Timestamp:
Apr 22, 2009, 4:00:45 PM (13 years ago)
Author:
charles
Message:

(trunk libT) #1993: Check if UPNP port is still open. Patch from KyleK

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/port-forwarding.c

    r8242 r8271  
    4545
    4646    tr_timer            * pulseTimer;
     47    tr_timer            * recheckTimer;
    4748
    4849    tr_upnp             * upnp;
     
    8485
    8586static void
    86 natPulse( tr_shared * s )
     87natPulse( tr_shared * s, tr_bool doPortCheck )
    8788{
    8889    const tr_port port = s->publicPort;
     
    9394    oldStatus = tr_sharedTraversalStatus( s );
    9495    s->natpmpStatus = tr_natpmpPulse( s->natpmp, port, isEnabled );
    95     s->upnpStatus = tr_upnpPulse( s->upnp, port, isEnabled );
     96    s->upnpStatus = tr_upnpPulse( s->upnp, port, isEnabled, doPortCheck );
    9697    newStatus = tr_sharedTraversalStatus( s );
    9798
     
    187188sharedPulse( void * vshared )
    188189{
    189     tr_bool keepPulsing = 1;
     190    tr_bool keepPulsing = TRUE;
    190191    tr_shared * shared = vshared;
    191192
    192     natPulse( shared );
     193    natPulse( shared, FALSE );
    193194
    194195    if( !shared->isShuttingDown )
     
    200201        tr_ninf( getKey( ), _( "Stopped" ) );
    201202        tr_timerFree( &shared->pulseTimer );
     203        tr_timerFree( &shared->recheckTimer );
    202204        tr_socketListForEach( shared->bindSockets, &closeCb, shared );
    203205        tr_socketListFree( shared->bindSockets );
     
    206208        shared->session->shared = NULL;
    207209        tr_free( shared );
    208         keepPulsing = 0;
    209     }
     210        keepPulsing = FALSE;
     211    }
     212
     213    return keepPulsing;
     214}
     215
     216static int
     217recheckPulse( void * vshared )
     218{
     219    tr_bool keepPulsing = TRUE;
     220    tr_shared * shared = vshared;
     221
     222    tr_ninf( getKey( ), _( "Checking to see if port %d is still open" ), shared->publicPort );
     223    natPulse( shared, TRUE );
     224
     225    if( shared->isShuttingDown )
     226        keepPulsing = FALSE;
    210227
    211228    return keepPulsing;
     
    226243    s->session      = session;
    227244    s->publicPort   = publicPort;
    228     s->shouldChange = TRUE;
    229245    s->bindSockets  = socks;
    230246    s->shouldChange = TRUE;
     
    232248    s->upnp         = tr_upnpInit( );
    233249    s->pulseTimer   = tr_timerNew( session, sharedPulse, s, 1000 );
     250    s->recheckTimer = tr_timerNew( session, recheckPulse, s, 1000*60*20 ); /* 20 minutes */
    234251    s->isEnabled    = isEnabled;
    235252    s->upnpStatus   = TR_PORT_UNMAPPED;
Note: See TracChangeset for help on using the changeset viewer.