Changeset 4155


Ignore:
Timestamp:
Dec 13, 2007, 7:28:51 PM (14 years ago)
Author:
charles
Message:

follow Chinstrap's suggestion of waiting a small interval between sending nat commands as per the nat spec

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/natpmp.c

    r4154 r4155  
    2929
    3030#define LIFETIME_SECS 3600
     31#define COMMAND_WAIT_SECS 8
    3132
    3233#define KEY "Port Mapping (NAT-PMP): "
     
    5152    unsigned int hasDiscovered : 1;
    5253    time_t renewTime;
     54    time_t commandTime;
    5355    tr_natpmp_state state;
    5456    natpmp_t natpmp;
     
    9092}
    9193
     94static int
     95canSendCommand( const struct tr_natpmp * nat )
     96{
     97    return time(NULL) >= nat->commandTime;
     98}
     99
     100static void
     101setCommandTime( struct tr_natpmp * nat )
     102{
     103    nat->commandTime = time(NULL) + COMMAND_WAIT_SECS;
     104}
     105
    92106int
    93107tr_natpmpPulse( struct tr_natpmp * nat, int port, int isEnabled )
     
    103117        nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_PUB;
    104118        nat->hasDiscovered = 1;
    105     }
    106 
    107     if( nat->state == TR_NATPMP_RECV_PUB )
     119        setCommandTime( nat );
     120    }
     121
     122    if( ( nat->state == TR_NATPMP_RECV_PUB ) && canSendCommand( nat ) )
    108123    {
    109124        natpmpresp_t response;
     
    124139    }
    125140
    126     if( nat->state == TR_NATPMP_SEND_UNMAP )
     141    if( ( nat->state == TR_NATPMP_SEND_UNMAP ) && canSendCommand( nat ) )
    127142    {
    128143        const int val = sendnewportmappingrequest( &nat->natpmp, NATPMP_PROTOCOL_TCP, nat->port, nat->port, 0 );
    129144        logVal( "sendnewportmappingrequest", val );
    130145        nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_UNMAP;
     146        setCommandTime( nat );
    131147    }
    132148
     
    155171    }
    156172
    157     if( nat->state == TR_NATPMP_SEND_MAP )
     173    if( ( nat->state == TR_NATPMP_SEND_MAP ) && canSendCommand( nat ) )
    158174    {
    159175        const int val = sendnewportmappingrequest( &nat->natpmp, NATPMP_PROTOCOL_TCP, port, port, LIFETIME_SECS );
    160176        logVal( "sendnewportmappingrequest", val );
    161177        nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_MAP;
     178        setCommandTime( nat );
    162179    }
    163180
Note: See TracChangeset for help on using the changeset viewer.