Ignore:
Timestamp:
Dec 13, 2007, 6:56:22 PM (14 years ago)
Author:
charles
Message:

take pea_'s suggestion of not sending out natpmp/upnp discover messages until port forwarding is enabled

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/natpmp.c

    r4140 r4154  
    3636    TR_NATPMP_IDLE,
    3737    TR_NATPMP_ERR,
     38    TR_NATPMP_DISCOVER,
    3839    TR_NATPMP_RECV_PUB,
    3940    TR_NATPMP_SEND_MAP,
     
    4748{
    4849    int port;
    49     int isMapped;
     50    unsigned int isMapped      : 1;
     51    unsigned int hasDiscovered : 1;
    5052    time_t renewTime;
    5153    tr_natpmp_state state;
     
    7173tr_natpmpInit( void )
    7274{
    73     struct tr_natpmp * nat = tr_new0( struct tr_natpmp, 1 );
    74     int val;
    75 
    76     val = initnatpmp( &nat->natpmp );
    77     logVal( "initnatpmp", val );
    78     val = sendpublicaddressrequest( &nat->natpmp );
    79     logVal( "sendpublicaddressrequest", val );
    80 
    81     nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_PUB;
     75    struct tr_natpmp * nat;
     76    nat = tr_new0( struct tr_natpmp, 1 );
     77    nat->state = TR_NATPMP_DISCOVER;
    8278    nat->port = -1;
    8379    return nat;
     
    9894{
    9995    int ret;
     96
     97    if( isEnabled && ( nat->state == TR_NATPMP_DISCOVER ) )
     98    {
     99        int val = initnatpmp( &nat->natpmp );
     100        logVal( "initnatpmp", val );
     101        val = sendpublicaddressrequest( &nat->natpmp );
     102        logVal( "sendpublicaddressrequest", val );
     103        nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_PUB;
     104        nat->hasDiscovered = 1;
     105    }
    100106
    101107    if( nat->state == TR_NATPMP_RECV_PUB )
     
    142148    if( nat->state == TR_NATPMP_IDLE )
    143149    {
    144         if( isEnabled && !nat->isMapped )
     150        if( isEnabled && !nat->isMapped && nat->hasDiscovered )
    145151            nat->state = TR_NATPMP_SEND_MAP;
    146152
     
    172178    }
    173179
    174     if( nat->state == TR_NATPMP_ERR )
    175         ret = TR_NAT_TRAVERSAL_ERROR;
    176     else if( ( nat->state == TR_NATPMP_IDLE ) &&  ( nat->isMapped ) )
    177         ret = TR_NAT_TRAVERSAL_MAPPED;
    178     else if( ( nat->state == TR_NATPMP_IDLE ) &&  ( !nat->isMapped ) )
    179         ret = TR_NAT_TRAVERSAL_UNMAPPED;
    180     else if( ( nat->state == TR_NATPMP_SEND_MAP ) || ( nat->state == TR_NATPMP_RECV_MAP ) )
    181         ret = TR_NAT_TRAVERSAL_MAPPING;
    182     else if( ( nat->state == TR_NATPMP_SEND_UNMAP ) || ( nat->state == TR_NATPMP_RECV_UNMAP ) )
    183         ret = TR_NAT_TRAVERSAL_UNMAPPING;
     180    switch( nat->state ) {
     181        case TR_NATPMP_IDLE:        ret = nat->isMapped ? TR_NAT_TRAVERSAL_MAPPED : TR_NAT_TRAVERSAL_UNMAPPED; break;
     182        case TR_NATPMP_DISCOVER:    ret = TR_NAT_TRAVERSAL_UNMAPPED; break;
     183        case TR_NATPMP_RECV_PUB:
     184        case TR_NATPMP_SEND_MAP:
     185        case TR_NATPMP_RECV_MAP:    ret = TR_NAT_TRAVERSAL_MAPPING; break;
     186        case TR_NATPMP_SEND_UNMAP:
     187        case TR_NATPMP_RECV_UNMAP:  ret = TR_NAT_TRAVERSAL_UNMAPPING; break;
     188        default:                    ret = TR_NAT_TRAVERSAL_ERROR; break;
     189    }
    184190    return ret;
    185191}
Note: See TracChangeset for help on using the changeset viewer.