Ticket #776: bind.r9230.patch

File bind.r9230.patch, 4.3 KB (added by tiennou, 12 years ago)

Patch against r9320 + settings.json

  • libtransmission/net.c

    diff --git a/libtransmission/net.c b/libtransmission/net.c
    index d37c4e9..3b8d1bd 100644
    a b tr_netOpenTCP( tr_session * session, 
    297297    const tr_address      * source_addr;
    298298    socklen_t               sourcelen;
    299299    struct sockaddr_storage source_sock;
     300    tr_port                 source_port = 0;
    300301
    301302    assert( tr_isAddress( addr ) );
    302303
    tr_netOpenTCP( tr_session * session, 
    312313        return -1;
    313314    }
    314315
     316    if( tr_sessionShouldBindLocalPort( session ) )
     317    {
     318        int optval = 1;
     319        setsockopt( s, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval) );
     320        source_port = htons( tr_sessionGetPeerPort( session ) );
     321    }
     322   
    315323    addrlen = setup_sockaddr( addr, port, &sock );
    316324
    317325    /* set source address */
    318326    source_addr = tr_sessionGetPublicAddress( session, addr->type );
    319327    assert( source_addr );
    320     sourcelen = setup_sockaddr( source_addr, 0, &source_sock );
     328    sourcelen = setup_sockaddr( source_addr, source_port, &source_sock );
    321329    if( bind( s, ( struct sockaddr * ) &source_sock, sourcelen ) )
    322330    {
    323331        tr_err( _( "Couldn't set source address %s on %d: %s" ),
  • libtransmission/session.c

    diff --git a/libtransmission/session.c b/libtransmission/session.c
    index 190e5f4..9564662 100644
    a b tr_sessionGetPublicAddress( const tr_session * session, int tr_af_type ) 
    221221    }
    222222}
    223223
     224tr_bool
     225tr_sessionShouldBindLocalPort( const tr_session * session )
     226{
     227    assert( tr_isSession( session ) );
     228   
     229    return session->bindLocalPort;
     230}
     231
    224232/***
    225233****
    226234***/
    tr_sessionGetDefaultSettings( tr_benc * d ) 
    351359{
    352360    assert( tr_bencIsDict( d ) );
    353361
    354     tr_bencDictReserve( d, 35 );
     362    tr_bencDictReserve( d, 49 );
    355363    tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED,        FALSE );
    356364    tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED,              TRUE );
    357365    tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR,             tr_getDefaultDownloadDir( ) );
    tr_sessionGetDefaultSettings( tr_benc * d ) 
    401409    tr_bencDictAddInt ( d, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, 14 );
    402410    tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV4,        TR_DEFAULT_BIND_ADDRESS_IPV4 );
    403411    tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV6,        TR_DEFAULT_BIND_ADDRESS_IPV6 );
     412    tr_bencDictAddBool( d, TR_PREFS_KEY_BIND_LOCAL_PORT,                FALSE );
    404413}
    405414
    406415void
    tr_sessionGetSettings( tr_session * s, struct tr_benc * d ) 
    458467    tr_bencDictAddInt ( d, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, s->uploadSlotsPerTorrent );
    459468    tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV4,        tr_ntop_non_ts( &s->public_ipv4->addr ) );
    460469    tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV6,        tr_ntop_non_ts( &s->public_ipv6->addr ) );
     470    tr_bencDictAddBool( d, TR_PREFS_KEY_BIND_LOCAL_PORT,                s->bindLocalPort );
    461471}
    462472
    463473void
  • libtransmission/session.h

    diff --git a/libtransmission/session.h b/libtransmission/session.h
    index 379dcfd..ce27375 100644
    a b struct tr_session 
    141141
    142142    struct tr_bindinfo         * public_ipv4;
    143143    struct tr_bindinfo         * public_ipv6;
     144   
     145    tr_bool                      bindLocalPort;
    144146};
    145147
    146148tr_bool      tr_sessionAllowsDHT( const tr_session * session );
    const struct tr_address* tr_sessionGetPublicAddress( const tr_session *, int tr 
    165167
    166168struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * );
    167169
     170tr_bool tr_sessionShouldBindLocalPort( const tr_session * session );
     171
    168172enum
    169173{
    170174    SESSION_MAGIC_NUMBER = 3845
  • libtransmission/transmission.h

    diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h
    index f7fd458..caa7248 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"
    167168#define TR_PREFS_KEY_BLOCKLIST_ENABLED          "blocklist-enabled"
    168169#define TR_PREFS_KEY_DHT_ENABLED                "dht-enabled"
    169170#define TR_PREFS_KEY_DOWNLOAD_DIR               "download-dir"