Changeset 5600


Ignore:
Timestamp:
Apr 12, 2008, 9:47:10 PM (14 years ago)
Author:
charles
Message:

#848: UPnP users always have to wait for NAT-PMP to fail first

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/natpmp.c

    r5592 r5600  
    7070        tr_ninf( getKey(), _( "%s succeeded (%d)" ), func, ret );
    7171    else
    72         tr_ninf( getKey(), _( "%s failed (%d): %s (%d)" ), func, ret, tr_strerror(errno), errno );
     72        tr_ndbg( getKey(), "%s failed (%d): %s (%d)", func, ret, tr_strerror(errno), errno );
    7373}
    7474
     
    103103{
    104104    nat->commandTime = time(NULL) + COMMAND_WAIT_SECS;
    105 }
    106 
    107 static void
    108 setErrorState( struct tr_natpmp * nat )
    109 {
    110     tr_ninf( getKey(), _( "If your router supports NAT-PMP, please make sure NAT-PMP is enabled!" ) );
    111     tr_ninf( getKey(), _( "NAT-PMP port forwarding unsuccessful, trying UPnP next" ) );
    112     nat->state = TR_NATPMP_ERR;
    113105}
    114106
     
    138130            nat->state = TR_NATPMP_IDLE;
    139131        } else if( val != NATPMP_TRYAGAIN ) {
    140             setErrorState( nat );
     132            nat->state = TR_NATPMP_ERR;
    141133        }
    142134    }
     
    167159            nat->isMapped = 0;
    168160        } else if( val != NATPMP_TRYAGAIN ) {
    169             setErrorState( nat );
     161            nat->state = TR_NATPMP_ERR;
    170162        }
    171163    }
     
    198190            nat->renewTime = time( NULL ) + LIFETIME_SECS;
    199191            nat->port = resp.newportmapping.privateport;
    200             tr_ninf( getKey(), _( "port %d forwarded successfully" ), nat->port );
     192            tr_ninf( getKey(), _( "Port %d forwarded successfully" ), nat->port );
    201193        } else if( val != NATPMP_TRYAGAIN ) {
    202             setErrorState( nat );
     194            nat->state = TR_NATPMP_ERR;
    203195        }
    204196    }
  • trunk/libtransmission/port-forwarding.c

    r5585 r5600  
    11/******************************************************************************
    2  * $Id:$
     2 * $Id$
    33 *
    44 * Copyright (c) 2005-2008 Transmission authors and contributors
     
    4343struct tr_shared
    4444{
     45    unsigned int isEnabled      : 1;
     46    unsigned int isShuttingDown : 1;
     47
     48    tr_nat_traversal_status natpmpStatus;
     49    tr_nat_traversal_status upnpStatus;
     50
     51    int bindPort;
     52    int bindSocket;
     53    int publicPort;
     54
    4555    tr_handle * h;
    4656    tr_timer  * pulseTimer;
    4757
    48     /* Incoming connections */
    49     int bindPort;
    50     int bindSocket;
    51 
    52     /* port forwarding */
    53     int isEnabled;
    54     int publicPort;
    55     tr_nat_traversal_status natStatus;
    56     tr_upnp * upnp;
     58    tr_upnp    * upnp;
    5759    tr_natpmp  * natpmp;
    5860
    59     int isShuttingDown;
    6061};
    6162
     
    8687natPulse( tr_shared * s )
    8788{
    88     tr_nat_traversal_status status;
    8989    const int port = s->publicPort;
    9090    const int isEnabled = s->isEnabled && !s->isShuttingDown;
    91 
    92     status = tr_natpmpPulse( s->natpmp, port, isEnabled );
    93     if( status == TR_NAT_TRAVERSAL_ERROR )
    94         status = tr_upnpPulse( s->upnp, port, isEnabled );
    95     if( status != s->natStatus ) {
    96         tr_ninf( getKey(), _( "State changed from \"%s\" to \"%s\"" ), getNatStateStr(s->natStatus), getNatStateStr(status) );
    97         s->natStatus = status;
    98         if( status == TR_NAT_TRAVERSAL_ERROR )
    99             tr_nerr( getKey(), _( "Port forwarding failed." ) );
    100     }
     91    int oldStatus;
     92    int newStatus;
     93   
     94    oldStatus = tr_sharedTraversalStatus( s );
     95    s->natpmpStatus = tr_natpmpPulse( s->natpmp, port, isEnabled );
     96    s->upnpStatus = tr_upnpPulse( s->upnp, port, isEnabled );
     97    newStatus = tr_sharedTraversalStatus( s );
     98
     99    if( newStatus != oldStatus )
     100        tr_ninf( getKey(), _( "State changed from \"%s\" to \"%s\"" ),
     101                 getNatStateStr(oldStatus),
     102                 getNatStateStr(newStatus) );
    101103}
    102104
     
    190192    s->pulseTimer   = tr_timerNew( h, sharedPulse, s, 500 );
    191193    s->isEnabled    = isEnabled ? 1 : 0;
    192     s->natStatus    = TR_NAT_TRAVERSAL_UNMAPPED;
     194    s->upnpStatus   = TR_NAT_TRAVERSAL_UNMAPPED;
     195    s->natpmpStatus = TR_NAT_TRAVERSAL_UNMAPPED;
    193196
    194197    return s;
     
    227230tr_sharedTraversalStatus( const tr_shared * s )
    228231{
    229     return s->natStatus;
    230 }
     232    return MAX( s->natpmpStatus, s->upnpStatus );
     233}
  • trunk/libtransmission/transmission.h

    r5597 r5600  
    220220typedef enum
    221221{
     222    TR_NAT_TRAVERSAL_ERROR,
     223    TR_NAT_TRAVERSAL_UNMAPPED,
     224    TR_NAT_TRAVERSAL_UNMAPPING,
    222225    TR_NAT_TRAVERSAL_MAPPING,
    223     TR_NAT_TRAVERSAL_MAPPED,
    224     TR_NAT_TRAVERSAL_UNMAPPING,
    225     TR_NAT_TRAVERSAL_UNMAPPED,
    226     TR_NAT_TRAVERSAL_ERROR,
     226    TR_NAT_TRAVERSAL_MAPPED
    227227}
    228228tr_nat_traversal_status;
  • trunk/libtransmission/upnp.c

    r5585 r5600  
    8989        devlist = upnpDiscover( 2000, NULL, NULL );
    9090        if( devlist == NULL ) {
    91             tr_ninf( getKey(), _( "upnpDiscover failed (errno %d - %s)" ), errno, tr_strerror(errno) );
     91            tr_ndbg( getKey(), "upnpDiscover failed (errno %d - %s)", errno, tr_strerror(errno) );
    9292        }
    9393        errno = 0;
     
    9999        } else {
    100100            handle->state = TR_UPNP_ERR;
    101             tr_ninf( getKey(), _( "UPNP_GetValidIGD failed (errno %d - %s)" ), errno, tr_strerror(errno) );
    102             tr_ninf( getKey(), _( "If your router supports UPnP, please make sure UPnP is enabled!" ) );
     101            tr_ndbg( getKey(), "UPNP_GetValidIGD failed (errno %d - %s)", errno, tr_strerror(errno) );
     102            tr_ndbg( getKey(), "If your router supports UPnP, please make sure UPnP is enabled!" );
    103103        }
    104104        freeUPNPDevlist( devlist );
     
    154154            handle->state = TR_UPNP_IDLE;
    155155        } else {
    156             tr_ninf( getKey(), _( "Port forwarding failed with error %d (errno %d - %s)" ), err, errno, tr_strerror(errno) );
    157             tr_ninf( getKey(), _( "If your router supports UPnP, please make sure UPnP is enabled!" ) );
     156            tr_ndbg( getKey(), "Port forwarding failed with error %d (errno %d - %s)", err, errno, tr_strerror(errno) );
     157            tr_ndbg( getKey(), "If your router supports UPnP, please make sure UPnP is enabled!" );
    158158            handle->port = -1;
    159159            handle->state = TR_UPNP_ERR;
Note: See TracChangeset for help on using the changeset viewer.