Changeset 4154


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

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

    r4142 r4154  
    5757{
    5858    tr_upnp * ret = tr_new0( tr_upnp, 1 );
     59    ret->state = TR_UPNP_DISCOVER;
    5960    ret->port = -1;
    6061    return ret;
     
    8182    int ret;
    8283
    83     if( handle->state == TR_UPNP_IDLE )
    84     {
    85         if( !handle->hasDiscovered )
    86             handle->state = TR_UPNP_DISCOVER;
    87     }
    88 
    89     if( handle->state == TR_UPNP_DISCOVER )
     84    if( isEnabled && ( handle->state == TR_UPNP_DISCOVER ) )
    9085    {
    9186        struct UPNPDev * devlist;
     
    158153    }
    159154
    160     if( handle->state == TR_UPNP_ERR )
    161         ret = TR_NAT_TRAVERSAL_ERROR;
    162     else if( ( handle->state == TR_UPNP_IDLE ) && handle->isMapped )
    163         ret = TR_NAT_TRAVERSAL_MAPPED;
    164     else if( ( handle->state == TR_UPNP_IDLE ) && !handle->isMapped )
    165         ret = TR_NAT_TRAVERSAL_UNMAPPED;
    166     else if( handle->state == TR_UPNP_MAP )
    167         ret = TR_NAT_TRAVERSAL_MAPPING;
    168     else if( handle->state == TR_UPNP_UNMAP )
    169         ret = TR_NAT_TRAVERSAL_UNMAPPING;
     155    switch( handle->state )
     156    {
     157        case TR_UPNP_DISCOVER: ret = TR_NAT_TRAVERSAL_UNMAPPED; break;
     158        case TR_UPNP_MAP:      ret = TR_NAT_TRAVERSAL_MAPPING; break;
     159        case TR_UPNP_UNMAP:    ret = TR_NAT_TRAVERSAL_UNMAPPING; break;
     160        case TR_UPNP_IDLE:     ret = handle->isMapped ? TR_NAT_TRAVERSAL_MAPPED
     161                                                      : TR_NAT_TRAVERSAL_UNMAPPED; break;
     162        default:               ret = TR_NAT_TRAVERSAL_ERROR; break;
     163    }
     164
    170165    return ret;
    171166}
Note: See TracChangeset for help on using the changeset viewer.