1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-04 02:28:03 +00:00

slightly less broken handling of cases where we can't bind to our listening port.

This commit is contained in:
Charles Kerr 2007-09-21 05:31:29 +00:00
parent 6479ecbcf6
commit 4d15bbdc2a
4 changed files with 12 additions and 23 deletions

View file

@ -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;

View file

@ -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 );
}
/***********************************************************************

View file

@ -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 );
}

View file

@ -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,