Ticket #776: ticket-776-bind-local-port-2.patch

File ticket-776-bind-local-port-2.patch, 4.8 KB (added by elsdoerfer, 11 years ago)
  • libtransmission/net.c

    diff --git a/libtransmission/net.c b/libtransmission/net.c
    index ac2e615..c7ae2d6 100644
    a b tr_netOpenPeerSocket( tr_session * session, 
    291291    const tr_address      * source_addr;
    292292    socklen_t               sourcelen;
    293293    struct sockaddr_storage source_sock;
    294     tr_port                 source_port = 0, source_port_max;
    295294
    296295    assert( tr_isAddress( addr ) );
    297296
    tr_netOpenPeerSocket( tr_session * session, 
    314313        return -1;
    315314    }
    316315
    317     if( tr_sessionShouldBindLocalPort( session ) )
    318     {
    319         int optval = 1;
    320         setsockopt( s, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval) );
    321         source_port = tr_sessionGetPeerPort( session );
    322         source_port_max = MIN( (int)source_port + 50, UINT16_MAX );
    323     }
    324    
    325316    addrlen = setup_sockaddr( addr, port, &sock );
    326317
    327318    /* set source address */
    328319    source_addr = tr_sessionGetPublicAddress( session, addr->type );
    329320    assert( source_addr );
    330 
    331 try_again:
    332     sourcelen = setup_sockaddr( source_addr, htons( source_port ), &source_sock );
     321    sourcelen = setup_sockaddr( source_addr, 0, &source_sock );
    333322    if( bind( s, ( struct sockaddr * ) &source_sock, sourcelen ) )
    334323    {
    335         if( tr_sessionShouldBindLocalPort( session ) && errno == EADDRINUSE )
    336         {
    337             if( source_port++ < source_port_max )
    338                 goto try_again;
    339         }
    340 
    341324        tr_err( _( "Couldn't set source address %s on %d: %s" ),
    342325                tr_ntop_non_ts( source_addr ), s, tr_strerror( errno ) );
    343326        return -errno;
  • libtransmission/session.c

    diff --git a/libtransmission/session.c b/libtransmission/session.c
    index 649b774..bb530a3 100644
    a b tr_sessionGetPublicAddress( const tr_session * session, int tr_af_type ) 
    231231    return bindinfo ? &bindinfo->addr : NULL;
    232232}
    233233
    234 tr_bool
    235 tr_sessionShouldBindLocalPort( const tr_session * session )
    236 {
    237     assert( tr_isSession( session ) );
    238 
    239     return session->bindLocalPort;
    240 }
    241 
    242234/***
    243235****
    244236***/
    tr_sessionGetDefaultSettings( const char * configDir UNUSED, tr_benc * d ) 
    315307    tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV6,        TR_DEFAULT_BIND_ADDRESS_IPV6 );
    316308    tr_bencDictAddBool( d, TR_PREFS_KEY_START,                    TRUE );
    317309    tr_bencDictAddBool( d, TR_PREFS_KEY_TRASH_ORIGINAL,           FALSE );
    318     tr_bencDictAddBool( d, TR_PREFS_KEY_BIND_LOCAL_PORT,          FALSE );
    319310}
    320311
    321312void
    tr_sessionGetSettings( tr_session * s, struct tr_benc * d ) 
    386377    tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV6,        tr_ntop_non_ts( &s->public_ipv6->addr ) );
    387378    tr_bencDictAddBool( d, TR_PREFS_KEY_START,                    !tr_sessionGetPaused( s ) );
    388379    tr_bencDictAddBool( d, TR_PREFS_KEY_TRASH_ORIGINAL,           tr_sessionGetDeleteSource( s ) );
    389     tr_bencDictAddBool( d, TR_PREFS_KEY_BIND_LOCAL_PORT,          s->bindLocalPort );
    390380}
    391381
    392382tr_bool
    sessionSetImpl( void * vdata ) 
    778768    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_PORT_FORWARDING, &boolVal ) )
    779769        tr_sessionSetPortForwardingEnabled( session, boolVal );
    780770
    781     if( tr_bencDictFindBool( settings, TR_PREFS_KEY_BIND_LOCAL_PORT, &boolVal ) )
    782         session->bindLocalPort = boolVal;
    783 
    784771    /* file and peer socket limits */
    785772    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &i ) )
    786773        tr_fdSetPeerLimit( session, i );
  • libtransmission/session.h

    diff --git a/libtransmission/session.h b/libtransmission/session.h
    index 20f3012..b8a218a 100644
    a b struct tr_session 
    194194    /* a page-aligned buffer for use by the libtransmission thread.
    195195     * @see SESSION_BUFFER_SIZE */
    196196    void * buffer;
     197
    197198    tr_bool bufferInUse;
    198    
    199     tr_bool                      bindLocalPort;
    200199};
    201200
    202201static inline tr_port
    struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * ); 
    231230
    232231int tr_sessionCountTorrents( const tr_session * session );
    233232
    234 tr_bool tr_sessionShouldBindLocalPort( const tr_session * session );
    235 
    236233enum
    237234{
    238235    SESSION_MAGIC_NUMBER = 3845,
  • libtransmission/transmission.h

    diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h
    index c816023..b218c33 100644
    a b const char* tr_getDefaultDownloadDir( void ); 
    164164#define TR_PREFS_KEY_ALT_SPEED_TIME_DAY            "alt-speed-time-day"
    165165#define TR_PREFS_KEY_BIND_ADDRESS_IPV4             "bind-address-ipv4"
    166166#define TR_PREFS_KEY_BIND_ADDRESS_IPV6             "bind-address-ipv6"
    167 #define TR_PREFS_KEY_BIND_LOCAL_PORT               "bind-local-port"
    168167#define TR_PREFS_KEY_BLOCKLIST_ENABLED             "blocklist-enabled"
    169168#define TR_PREFS_KEY_MAX_CACHE_SIZE_MB             "cache-size-mb"
    170169#define TR_PREFS_KEY_DHT_ENABLED                   "dht-enabled"