diff --git a/libtransmission/internal.h b/libtransmission/internal.h index c254daa63..4ba11c121 100644 --- a/libtransmission/internal.h +++ b/libtransmission/internal.h @@ -60,7 +60,7 @@ void tr_torrentSetHasPiece( tr_torrent * tor, int pieceIndex, int has ); void tr_torrentLock ( const tr_torrent * ); void tr_torrentUnlock ( const tr_torrent * ); -void tr_torrentChangeMyPort ( tr_torrent *, int port ); +void tr_torrentChangeMyPort ( tr_torrent * ); int tr_torrentExists( tr_handle *, const uint8_t * ); tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * ); @@ -120,7 +120,6 @@ struct tr_torrent uint8_t obfuscatedHash[SHA_DIGEST_LENGTH]; uint8_t * azId; - int publicPort; /* Where to download */ char * destination; diff --git a/libtransmission/shared.c b/libtransmission/shared.c index 4a7b89321..8a84231b2 100644 --- a/libtransmission/shared.c +++ b/libtransmission/shared.c @@ -145,12 +145,14 @@ void tr_sharedSetPort( tr_shared * s, int port ) } /* Create the new one */ - /* XXX should handle failure here in a better way */ s->bindSocket = tr_netBindTCP( port ); - if( 0 > s->bindSocket ) + + /* Notify the trackers */ + SetPublicPort( s, port ); + + /* XXX should handle failure here in a better way */ + if( s->bindSocket < 0 ) { - /* Notify the trackers */ - SetPublicPort( s, 0 ); /* Remove the forwarding for the old port */ tr_natpmpRemoveForwarding( s->natpmp ); tr_upnpRemoveForwarding( s->upnp ); @@ -159,11 +161,6 @@ void tr_sharedSetPort( tr_shared * s, int port ) { tr_inf( "Bound listening port %d", port ); listen( s->bindSocket, 5 ); - if( port != s->publicPort ) - { - /* Notify the trackers */ - SetPublicPort( s, port ); - } /* Forward the new port */ tr_natpmpForwardPort( s->natpmp, port ); tr_upnpForwardPort( s->upnp, port ); @@ -174,6 +171,7 @@ void tr_sharedSetPort( tr_shared * s, int port ) int tr_sharedGetPublicPort( tr_shared * s ) { +fprintf( stderr, "%s:%d tr_sharedGetPublicPort returning %d\n", __FILE__, __LINE__, (int)s->publicPort ); return s->publicPort; } @@ -268,7 +266,7 @@ static void SetPublicPort( tr_shared * s, int port ) s->publicPort = port; for( tor = h->torrentList; tor; tor = tor->next ) - tr_torrentChangeMyPort( tor, port ); + tr_torrentChangeMyPort( tor ); } /*********************************************************************** diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index d56898ca0..534112fcc 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -359,9 +359,6 @@ torrentRealInit( tr_handle * h, info->hash, SHA_DIGEST_LENGTH, NULL ); - /* We have a new torrent */ - tor->publicPort = tr_sharedGetPublicPort( h->shared ); - tr_sharedUnlock( h->shared ); tr_peerMgrAddTorrent( h->peerMgr, tor ); @@ -667,16 +664,10 @@ tr_torrentGetFolder( const tr_torrent * tor ) } void -tr_torrentChangeMyPort( tr_torrent * tor, int port ) +tr_torrentChangeMyPort( tr_torrent * tor ) { - tr_torrentLock( tor ); - - tor->publicPort = port; - if( tor->tracker ) tr_trackerChangeMyPort( tor->tracker ); - - tr_torrentUnlock( tor ); } diff --git a/libtransmission/tracker.c b/libtransmission/tracker.c index 81be2f36c..0e28446ec 100644 --- a/libtransmission/tracker.c +++ b/libtransmission/tracker.c @@ -28,6 +28,7 @@ #include "net.h" #include "ptrarray.h" #include "publish.h" +#include "shared.h" #include "tracker.h" #include "trevent.h" #include "utils.h" @@ -771,7 +772,7 @@ buildTrackerRequestURI( const Torrent * tor, const char * eventName ) getCurrentAddress(tor->tracker)->announce, tor->escaped, tor->peer_id, - torrent->publicPort, + tr_sharedGetPublicPort( torrent->handle->shared ), torrent->uploadedCur, torrent->downloadedCur, torrent->corruptCur,