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:
parent
6479ecbcf6
commit
4d15bbdc2a
4 changed files with 12 additions and 23 deletions
|
@ -60,7 +60,7 @@ void tr_torrentSetHasPiece( tr_torrent * tor, int pieceIndex, int has );
|
||||||
void tr_torrentLock ( const tr_torrent * );
|
void tr_torrentLock ( const tr_torrent * );
|
||||||
void tr_torrentUnlock ( 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 * );
|
int tr_torrentExists( tr_handle *, const uint8_t * );
|
||||||
tr_torrent* tr_torrentFindFromHash( 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 obfuscatedHash[SHA_DIGEST_LENGTH];
|
||||||
|
|
||||||
uint8_t * azId;
|
uint8_t * azId;
|
||||||
int publicPort;
|
|
||||||
|
|
||||||
/* Where to download */
|
/* Where to download */
|
||||||
char * destination;
|
char * destination;
|
||||||
|
|
|
@ -145,12 +145,14 @@ void tr_sharedSetPort( tr_shared * s, int port )
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the new one */
|
/* Create the new one */
|
||||||
/* XXX should handle failure here in a better way */
|
|
||||||
s->bindSocket = tr_netBindTCP( port );
|
s->bindSocket = tr_netBindTCP( port );
|
||||||
if( 0 > s->bindSocket )
|
|
||||||
{
|
|
||||||
/* Notify the trackers */
|
/* Notify the trackers */
|
||||||
SetPublicPort( s, 0 );
|
SetPublicPort( s, port );
|
||||||
|
|
||||||
|
/* XXX should handle failure here in a better way */
|
||||||
|
if( s->bindSocket < 0 )
|
||||||
|
{
|
||||||
/* Remove the forwarding for the old port */
|
/* Remove the forwarding for the old port */
|
||||||
tr_natpmpRemoveForwarding( s->natpmp );
|
tr_natpmpRemoveForwarding( s->natpmp );
|
||||||
tr_upnpRemoveForwarding( s->upnp );
|
tr_upnpRemoveForwarding( s->upnp );
|
||||||
|
@ -159,11 +161,6 @@ void tr_sharedSetPort( tr_shared * s, int port )
|
||||||
{
|
{
|
||||||
tr_inf( "Bound listening port %d", port );
|
tr_inf( "Bound listening port %d", port );
|
||||||
listen( s->bindSocket, 5 );
|
listen( s->bindSocket, 5 );
|
||||||
if( port != s->publicPort )
|
|
||||||
{
|
|
||||||
/* Notify the trackers */
|
|
||||||
SetPublicPort( s, port );
|
|
||||||
}
|
|
||||||
/* Forward the new port */
|
/* Forward the new port */
|
||||||
tr_natpmpForwardPort( s->natpmp, port );
|
tr_natpmpForwardPort( s->natpmp, port );
|
||||||
tr_upnpForwardPort( s->upnp, port );
|
tr_upnpForwardPort( s->upnp, port );
|
||||||
|
@ -174,6 +171,7 @@ void tr_sharedSetPort( tr_shared * s, int port )
|
||||||
|
|
||||||
int tr_sharedGetPublicPort( tr_shared * s )
|
int tr_sharedGetPublicPort( tr_shared * s )
|
||||||
{
|
{
|
||||||
|
fprintf( stderr, "%s:%d tr_sharedGetPublicPort returning %d\n", __FILE__, __LINE__, (int)s->publicPort );
|
||||||
return s->publicPort;
|
return s->publicPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +266,7 @@ static void SetPublicPort( tr_shared * s, int port )
|
||||||
s->publicPort = port;
|
s->publicPort = port;
|
||||||
|
|
||||||
for( tor = h->torrentList; tor; tor = tor->next )
|
for( tor = h->torrentList; tor; tor = tor->next )
|
||||||
tr_torrentChangeMyPort( tor, port );
|
tr_torrentChangeMyPort( tor );
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
|
@ -359,9 +359,6 @@ torrentRealInit( tr_handle * h,
|
||||||
info->hash, SHA_DIGEST_LENGTH,
|
info->hash, SHA_DIGEST_LENGTH,
|
||||||
NULL );
|
NULL );
|
||||||
|
|
||||||
/* We have a new torrent */
|
|
||||||
tor->publicPort = tr_sharedGetPublicPort( h->shared );
|
|
||||||
|
|
||||||
tr_sharedUnlock( h->shared );
|
tr_sharedUnlock( h->shared );
|
||||||
|
|
||||||
tr_peerMgrAddTorrent( h->peerMgr, tor );
|
tr_peerMgrAddTorrent( h->peerMgr, tor );
|
||||||
|
@ -667,16 +664,10 @@ tr_torrentGetFolder( const tr_torrent * tor )
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tr_torrentChangeMyPort( tr_torrent * tor, int port )
|
tr_torrentChangeMyPort( tr_torrent * tor )
|
||||||
{
|
{
|
||||||
tr_torrentLock( tor );
|
|
||||||
|
|
||||||
tor->publicPort = port;
|
|
||||||
|
|
||||||
if( tor->tracker )
|
if( tor->tracker )
|
||||||
tr_trackerChangeMyPort( tor->tracker );
|
tr_trackerChangeMyPort( tor->tracker );
|
||||||
|
|
||||||
tr_torrentUnlock( tor );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "ptrarray.h"
|
#include "ptrarray.h"
|
||||||
#include "publish.h"
|
#include "publish.h"
|
||||||
|
#include "shared.h"
|
||||||
#include "tracker.h"
|
#include "tracker.h"
|
||||||
#include "trevent.h"
|
#include "trevent.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
@ -771,7 +772,7 @@ buildTrackerRequestURI( const Torrent * tor, const char * eventName )
|
||||||
getCurrentAddress(tor->tracker)->announce,
|
getCurrentAddress(tor->tracker)->announce,
|
||||||
tor->escaped,
|
tor->escaped,
|
||||||
tor->peer_id,
|
tor->peer_id,
|
||||||
torrent->publicPort,
|
tr_sharedGetPublicPort( torrent->handle->shared ),
|
||||||
torrent->uploadedCur,
|
torrent->uploadedCur,
|
||||||
torrent->downloadedCur,
|
torrent->downloadedCur,
|
||||||
torrent->corruptCur,
|
torrent->corruptCur,
|
||||||
|
|
Loading…
Add table
Reference in a new issue