Changeset 8271


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

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

Location:
trunk/libtransmission
Files:
3 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;
  • trunk/libtransmission/upnp.c

    r7837 r8271  
    8181tr_upnpPulse( tr_upnp * handle,
    8282              int       port,
    83               int       isEnabled )
     83              int       isEnabled,
     84              int       doPortCheck )
    8485{
    8586    int ret;
     
    126127        if( handle->isMapped && ( !isEnabled || ( handle->port != port ) ) )
    127128            handle->state = TR_UPNP_UNMAP;
     129    }
     130
     131    if( isEnabled && handle->isMapped && doPortCheck )
     132    {
     133        char portStr[8];
     134        char intPort[8];
     135        char intClient[16];
     136        int i;
     137
     138        tr_snprintf( portStr, sizeof( portStr ), "%d", handle->port );
     139        i = UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL,
     140                                              handle->data.servicetype, portStr,
     141                                              "TCP", intClient, intPort );
     142        if( i != UPNPCOMMAND_SUCCESS )
     143        {
     144            tr_ninf( getKey( ), _( "Port %d isn't forwarded" ), handle->port );
     145            handle->isMapped = FALSE;
     146        }
    128147    }
    129148
  • trunk/libtransmission/upnp.h

    r7658 r8271  
    2626int       tr_upnpPulse(         tr_upnp *,
    2727                            int port,
    28                             int isEnabled );
    29 
     28                            int isEnabled,
     29                            int doPortCheck );
    3030#endif
Note: See TracChangeset for help on using the changeset viewer.