Changeset 1720


Ignore:
Timestamp:
Apr 15, 2007, 7:36:24 AM (15 years ago)
Author:
joshe
Message:

Don't try port mapping if binding the port fails.

Location:
trunk/libtransmission
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/natpmp.c

    r1529 r1720  
    9898tr_natpmp_parse_t;
    9999
     100static void
     101unmap( tr_natpmp_t * pmp );
    100102static int
    101103checktime( tr_natpmp_uptime_t * uptime, uint32_t seen );
     
    174176        pmp->active = 0;
    175177        killsock( &pmp->mcastfd );
    176         switch( pmp->state )
    177         {
    178             case PMP_STATE_IDLE:
    179                 break;
    180             case PMP_STATE_ADDING:
    181                 pmp->state = PMP_STATE_IDLE;
    182                 tr_dbg( "nat-pmp state add -> idle" );
    183                 if( NULL != pmp->req )
    184                 {
    185                     pmp->mappedport = pmp->req->gotport;
    186                     killreq( &pmp->req );
    187                     pmp->state = PMP_STATE_DELETING;
    188                     tr_dbg( "nat-pmp state idle -> del" );
    189                 }
    190                 break;
    191             case PMP_STATE_DELETING:
    192                 break;
    193             case PMP_STATE_MAPPED:
    194                 pmp->state = PMP_STATE_DELETING;
    195                 tr_dbg( "nat-pmp state mapped -> del" );
    196                 break;
    197             case PMP_STATE_FAILED:
    198             case PMP_STATE_NOBODYHOME:
    199             case PMP_STATE_TMPFAIL:
    200                 break;
    201             default:
    202                 assert( 0 );
    203                 break;
    204         }
     178        unmap( pmp );
    205179    }
    206180}
     
    254228    tr_inf( "nat-pmp set port %i", port );
    255229    pmp->newport = port;
     230}
     231
     232void
     233tr_natpmpRemoveForwarding( tr_natpmp_t * pmp )
     234{
     235    tr_inf( "nat-pmp unset port" );
     236    pmp->newport = -1;
     237    unmap( pmp );
    256238}
    257239
     
    441423}
    442424
     425void
     426unmap( tr_natpmp_t * pmp )
     427{
     428    switch( pmp->state )
     429    {
     430        case PMP_STATE_IDLE:
     431            break;
     432        case PMP_STATE_ADDING:
     433            if( NULL == pmp->req )
     434            {
     435                pmp->state = PMP_STATE_IDLE;
     436                tr_dbg( "nat-pmp state add -> idle" );
     437            }
     438            else
     439            {
     440                pmp->mappedport = pmp->req->gotport;
     441                killreq( &pmp->req );
     442                pmp->state = PMP_STATE_DELETING;
     443                tr_dbg( "nat-pmp state add -> del" );
     444            }
     445            break;
     446        case PMP_STATE_DELETING:
     447            break;
     448        case PMP_STATE_MAPPED:
     449            pmp->state = PMP_STATE_DELETING;
     450            tr_dbg( "nat-pmp state mapped -> del" );
     451            break;
     452        case PMP_STATE_FAILED:
     453        case PMP_STATE_NOBODYHOME:
     454        case PMP_STATE_TMPFAIL:
     455            break;
     456        default:
     457            assert( 0 );
     458            break;
     459    }
     460}
     461
    443462static int
    444463checktime( tr_natpmp_uptime_t * uptime, uint32_t cursecs )
  • trunk/libtransmission/natpmp.h

    r1460 r1720  
    3333int         tr_natpmpStatus( tr_natpmp_t * );
    3434void        tr_natpmpForwardPort( tr_natpmp_t *, int );
     35void        tr_natpmpRemoveForwarding( tr_natpmp_t * );
    3536void        tr_natpmpPulse( tr_natpmp_t *, int * );
    3637void        tr_natpmpClose( tr_natpmp_t * );
  • trunk/libtransmission/peeraz.h

    r1650 r1720  
    135135    tr_bencInitStr( tr_bencDictAdd( &val, "client" ),   TR_NAME, 0, 1 );
    136136    tr_bencInitStr( tr_bencDictAdd( &val, "version" ),  VERSION_STRING, 0, 1 );
    137     tr_bencInitInt( tr_bencDictAdd( &val, "tcp_port" ), tor->publicPort );
     137    if( 0 < tor->publicPort )
     138    {
     139        tr_bencInitInt( tr_bencDictAdd( &val, "tcp_port" ), tor->publicPort );
     140    }
    138141
    139142    /* initialize supported message list */
  • trunk/libtransmission/peerext.h

    r1650 r1720  
    149149    if( 0 < tor->publicPort )
    150150    {
     151        /* XXX should inform peer when we no longer have a valid port */
    151152        tr_bencInitInt( tr_bencDictAdd( &val, "p" ), tor->publicPort );
    152153    }
  • trunk/libtransmission/shared.c

    r1579 r1720  
    161161    /* XXX should handle failure here in a better way */
    162162    s->bindSocket = tr_netBindTCP( port );
    163     if( s->bindSocket >= 0 )
     163    if( 0 > s->bindSocket )
     164    {
     165        /* Notify the trackers */
     166        SetPublicPort( s, 0 );
     167        /* Remove the forwarding for the old port */
     168        tr_natpmpRemoveForwarding( s->natpmp );
     169        tr_upnpRemoveForwarding( s->upnp );
     170    }
     171    else
    164172    {
    165173        tr_inf( "Bound listening port %d", port );
    166174        listen( s->bindSocket, 5 );
    167     }
    168 
    169     /* Notify the trackers */
    170     if( port != s->publicPort )
    171     {
    172         SetPublicPort( s, port );
    173     }
    174 
    175     /* Forward the new port */
    176     tr_natpmpForwardPort( s->natpmp, port );
    177     tr_upnpForwardPort( s->upnp, port );
     175        if( port != s->publicPort )
     176        {
     177            /* Notify the trackers */
     178            SetPublicPort( s, port );
     179            /* Forward the new port */
     180            tr_natpmpForwardPort( s->natpmp, port );
     181            tr_upnpForwardPort( s->upnp, port );
     182        }
     183    }
    178184
    179185    tr_sharedUnlock( s );
  • trunk/libtransmission/upnp.c

    r1693 r1720  
    237237    tr_dbg( "upnp port changed from %i to %i", upnp->port, port );
    238238    upnp->port = port;
     239}
     240
     241void
     242tr_upnpRemoveForwarding( tr_upnp_t * upnp )
     243{
     244    tr_dbg( "upnp port unset" );
     245    upnp->port = 0;
    239246}
    240247
  • trunk/libtransmission/upnp.h

    r1420 r1720  
    3333int         tr_upnpStatus( tr_upnp_t * );
    3434void        tr_upnpForwardPort( tr_upnp_t *, int );
     35void        tr_upnpRemoveForwarding( tr_upnp_t * );
    3536void        tr_upnpPulse( tr_upnp_t * );
    3637void        tr_upnpClose( tr_upnp_t * );
Note: See TracChangeset for help on using the changeset viewer.