mirror of
https://github.com/transmission/transmission
synced 2024-12-25 09:13:06 +00:00
(trunk libT) #2508 atom->port never updated
This commit is contained in:
parent
632ccf066a
commit
3680896a19
7 changed files with 83 additions and 52 deletions
|
@ -48,6 +48,7 @@ typedef enum
|
|||
TR_PEER_CLIENT_GOT_DATA,
|
||||
TR_PEER_CLIENT_GOT_ALLOWED_FAST,
|
||||
TR_PEER_CLIENT_GOT_SUGGEST,
|
||||
TR_PEER_CLIENT_GOT_PORT,
|
||||
TR_PEER_PEER_GOT_DATA,
|
||||
TR_PEER_PEER_PROGRESS,
|
||||
TR_PEER_ERROR,
|
||||
|
@ -67,6 +68,7 @@ typedef struct
|
|||
int err; /* errno for GOT_ERROR */
|
||||
tr_bool wasPieceData; /* for GOT_DATA */
|
||||
tr_bool uploadOnly; /* for UPLOAD_ONLY */
|
||||
tr_port port; /* for GOT_PORT */
|
||||
}
|
||||
tr_peer_event;
|
||||
|
||||
|
|
|
@ -130,6 +130,12 @@ tr_isAtom( const struct peer_atom * atom )
|
|||
&& ( tr_isAddress( &atom->addr ) );
|
||||
}
|
||||
|
||||
static const char*
|
||||
tr_atomAddrStr( const struct peer_atom * atom )
|
||||
{
|
||||
return tr_peerIoAddrStr( &atom->addr, atom->port );
|
||||
}
|
||||
|
||||
struct tr_blockIterator
|
||||
{
|
||||
time_t expirationDate;
|
||||
|
@ -260,6 +266,12 @@ comparePeerAtoms( const void * va, const void * vb )
|
|||
***
|
||||
**/
|
||||
|
||||
const tr_address *
|
||||
tr_peerAddress( const tr_peer * peer )
|
||||
{
|
||||
return &peer->atom->addr;
|
||||
}
|
||||
|
||||
static Torrent*
|
||||
getExistingTorrent( tr_peerMgr * manager,
|
||||
const uint8_t * hash )
|
||||
|
@ -270,20 +282,15 @@ getExistingTorrent( tr_peerMgr * manager,
|
|||
}
|
||||
|
||||
static int
|
||||
peerCompare( const void * va, const void * vb )
|
||||
peerCompare( const void * a, const void * b )
|
||||
{
|
||||
const tr_peer * a = va;
|
||||
const tr_peer * b = vb;
|
||||
|
||||
return tr_compareAddresses( &a->addr, &b->addr );
|
||||
return tr_compareAddresses( tr_peerAddress( a ), tr_peerAddress( b ) );
|
||||
}
|
||||
|
||||
static int
|
||||
peerCompareToAddr( const void * va, const void * vb )
|
||||
peerCompareToAddr( const void * a, const void * vb )
|
||||
{
|
||||
const tr_peer * a = va;
|
||||
|
||||
return tr_compareAddresses( &a->addr, vb );
|
||||
return tr_compareAddresses( tr_peerAddress( a ), vb );
|
||||
}
|
||||
|
||||
static tr_peer*
|
||||
|
@ -319,27 +326,25 @@ peerIsInUse( const Torrent * ct,
|
|||
}
|
||||
|
||||
static tr_peer*
|
||||
peerConstructor( const tr_address * addr )
|
||||
peerConstructor( struct peer_atom * atom )
|
||||
{
|
||||
tr_peer * p;
|
||||
p = tr_new0( tr_peer, 1 );
|
||||
p->addr = *addr;
|
||||
return p;
|
||||
tr_peer * peer = tr_new0( tr_peer, 1 );
|
||||
peer->atom = atom;
|
||||
return peer;
|
||||
}
|
||||
|
||||
static tr_peer*
|
||||
getPeer( Torrent * torrent,
|
||||
const tr_address * addr )
|
||||
getPeer( Torrent * torrent, struct peer_atom * atom )
|
||||
{
|
||||
tr_peer * peer;
|
||||
|
||||
assert( torrentIsLocked( torrent ) );
|
||||
|
||||
peer = getExistingPeer( torrent, addr );
|
||||
peer = getExistingPeer( torrent, &atom->addr );
|
||||
|
||||
if( peer == NULL )
|
||||
{
|
||||
peer = peerConstructor( addr );
|
||||
peer = peerConstructor( atom );
|
||||
tr_ptrArrayInsertSorted( &torrent->peers, peer, peerCompare );
|
||||
}
|
||||
|
||||
|
@ -928,15 +933,14 @@ static void
|
|||
addStrike( Torrent * t, tr_peer * peer )
|
||||
{
|
||||
tordbg( t, "increasing peer %s strike count to %d",
|
||||
tr_peerIoAddrStr( &peer->addr,
|
||||
peer->port ), peer->strikes + 1 );
|
||||
tr_atomAddrStr( peer->atom ), peer->strikes + 1 );
|
||||
|
||||
if( ++peer->strikes >= MAX_BAD_PIECES_PER_PEER )
|
||||
{
|
||||
struct peer_atom * atom = peer->atom;
|
||||
atom->myflags |= MYFLAG_BANNED;
|
||||
peer->doPurge = 1;
|
||||
tordbg( t, "banning peer %s", tr_peerIoAddrStr( &atom->addr, atom->port ) );
|
||||
tordbg( t, "banning peer %s", tr_atomAddrStr( atom ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1063,6 +1067,11 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt )
|
|||
break;
|
||||
}
|
||||
|
||||
case TR_PEER_CLIENT_GOT_PORT:
|
||||
if( peer )
|
||||
peer->atom->port = e->port;
|
||||
break;
|
||||
|
||||
case TR_PEER_CLIENT_GOT_SUGGEST:
|
||||
if( peer )
|
||||
peerSuggestedPiece( t, peer, e->pieceIndex, FALSE );
|
||||
|
@ -1108,7 +1117,8 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt )
|
|||
{
|
||||
struct peer_atom * atom = peer->atom;
|
||||
if( e->progress >= 1.0 ) {
|
||||
tordbg( t, "marking peer %s as a seed", tr_peerIoAddrStr( &atom->addr, atom->port ) );
|
||||
tordbg( t, "marking peer %s as a seed",
|
||||
tr_atomAddrStr( atom ) );
|
||||
atom->flags |= ADDED_F_SEED_FLAG;
|
||||
}
|
||||
}
|
||||
|
@ -1175,7 +1185,7 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt )
|
|||
/* some protocol error from the peer */
|
||||
peer->doPurge = 1;
|
||||
tordbg( t, "setting %s doPurge flag because we got an ERANGE, EMSGSIZE, or ENOTCONN error",
|
||||
tr_peerIoAddrStr( &peer->addr, peer->port ) );
|
||||
tr_atomAddrStr( peer->atom ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1208,7 +1218,7 @@ ensureAtomExists( Torrent * t,
|
|||
a->port = port;
|
||||
a->flags = flags;
|
||||
a->from = from;
|
||||
tordbg( t, "got a new atom: %s", tr_peerIoAddrStr( &a->addr, a->port ) );
|
||||
tordbg( t, "got a new atom: %s", tr_atomAddrStr( a ) );
|
||||
tr_ptrArrayInsertSorted( &t->pool, a, comparePeerAtoms );
|
||||
}
|
||||
}
|
||||
|
@ -1285,7 +1295,7 @@ myHandshakeDoneCB( tr_handshake * handshake,
|
|||
if( atom->myflags & MYFLAG_BANNED )
|
||||
{
|
||||
tordbg( t, "banned peer %s tried to reconnect",
|
||||
tr_peerIoAddrStr( &atom->addr, atom->port ) );
|
||||
tr_atomAddrStr( atom ) );
|
||||
}
|
||||
else if( tr_peerIoIsIncoming( io )
|
||||
&& ( getPeerCount( t ) >= getMaxPeerCount( t->tor ) ) )
|
||||
|
@ -1301,7 +1311,7 @@ myHandshakeDoneCB( tr_handshake * handshake,
|
|||
}
|
||||
else
|
||||
{
|
||||
peer = getPeer( t, addr );
|
||||
peer = getPeer( t, atom );
|
||||
tr_free( peer->client );
|
||||
|
||||
if( !peer_id )
|
||||
|
@ -1312,8 +1322,6 @@ myHandshakeDoneCB( tr_handshake * handshake,
|
|||
peer->client = tr_strdup( client );
|
||||
}
|
||||
|
||||
peer->port = port;
|
||||
peer->atom = atom;
|
||||
peer->io = tr_handshakeStealIO( handshake ); /* this steals its refcount too, which is
|
||||
balanced by our unref in peerDestructor() */
|
||||
tr_peerIoSetParent( peer->io, t->tor->bandwidth );
|
||||
|
@ -1493,7 +1501,7 @@ tr_peerMgrSetBlame( tr_torrent * tor,
|
|||
if( tr_bitfieldHas( peer->blame, pieceIndex ) )
|
||||
{
|
||||
tordbg( t, "peer %s contributed to corrupt piece (%d); now has %d strikes",
|
||||
tr_peerIoAddrStr( &peer->addr, peer->port ),
|
||||
tr_atomAddrStr( peer->atom ),
|
||||
pieceIndex, (int)peer->strikes + 1 );
|
||||
addStrike( t, peer );
|
||||
}
|
||||
|
@ -1891,10 +1899,10 @@ tr_peerMgrPeerStats( const tr_torrent * tor,
|
|||
const struct peer_atom * atom = peer->atom;
|
||||
tr_peer_stat * stat = ret + i;
|
||||
|
||||
tr_ntop( &peer->addr, stat->addr, sizeof( stat->addr ) );
|
||||
tr_ntop( &atom->addr, stat->addr, sizeof( stat->addr ) );
|
||||
tr_strlcpy( stat->client, ( peer->client ? peer->client : "" ),
|
||||
sizeof( stat->client ) );
|
||||
stat->port = ntohs( peer->port );
|
||||
stat->port = ntohs( peer->atom->port );
|
||||
stat->from = atom->from;
|
||||
stat->progress = peer->progress;
|
||||
stat->isEncrypted = tr_peerIoIsEncrypted( peer->io ) ? 1 : 0;
|
||||
|
@ -2118,7 +2126,7 @@ shouldPeerBeClosed( const Torrent * t,
|
|||
if( peer->doPurge )
|
||||
{
|
||||
tordbg( t, "purging peer %s because its doPurge flag is set",
|
||||
tr_peerIoAddrStr( &atom->addr, atom->port ) );
|
||||
tr_atomAddrStr( atom ) );
|
||||
return TR_MUST_CLOSE;
|
||||
}
|
||||
|
||||
|
@ -2141,7 +2149,7 @@ shouldPeerBeClosed( const Torrent * t,
|
|||
if( peerHasEverything && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30 )))
|
||||
{
|
||||
tordbg( t, "purging peer %s because we're both seeds",
|
||||
tr_peerIoAddrStr( &atom->addr, atom->port ) );
|
||||
tr_atomAddrStr( atom ) );
|
||||
return TR_MUST_CLOSE;
|
||||
}
|
||||
}
|
||||
|
@ -2162,7 +2170,7 @@ shouldPeerBeClosed( const Torrent * t,
|
|||
/*fprintf( stderr, "strictness is %.3f, limit is %d seconds... time since connect is %d, time since piece is %d ... idleTime is %d, doPurge is %d\n", (double)strictness, limit, (int)(now - atom->time), (int)(now - atom->piece_data_time), idleTime, idleTime > limit );*/
|
||||
if( idleTime > limit ) {
|
||||
tordbg( t, "purging peer %s because it's been %d secs since we shared anything",
|
||||
tr_peerIoAddrStr( &atom->addr, atom->port ), idleTime );
|
||||
tr_atomAddrStr( atom ), idleTime );
|
||||
return TR_CAN_CLOSE;
|
||||
}
|
||||
}
|
||||
|
@ -2295,7 +2303,7 @@ getPeerCandidates( Torrent * t, int * setmeSize )
|
|||
if( ( now - atom->time ) < interval )
|
||||
{
|
||||
tordbg( t, "RECONNECT peer %d (%s) is in its grace period of %d seconds..",
|
||||
i, tr_peerIoAddrStr( &atom->addr, atom->port ), interval );
|
||||
i, tr_atomAddrStr( atom ), interval );
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2406,14 +2414,14 @@ reconnectTorrent( Torrent * t )
|
|||
tr_peerIo * io;
|
||||
|
||||
tordbg( t, "Starting an OUTGOING connection with %s",
|
||||
tr_peerIoAddrStr( &atom->addr, atom->port ) );
|
||||
tr_atomAddrStr( atom ) );
|
||||
|
||||
io = tr_peerIoNewOutgoing( mgr->session, mgr->session->bandwidth, &atom->addr, atom->port, t->tor->info.hash );
|
||||
|
||||
if( io == NULL )
|
||||
{
|
||||
tordbg( t, "peerIo not created; marking peer %s as unreachable",
|
||||
tr_peerIoAddrStr( &atom->addr, atom->port ) );
|
||||
tr_atomAddrStr( atom ) );
|
||||
atom->myflags |= MYFLAG_UNREACHABLE;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -87,9 +87,7 @@ typedef struct tr_peer
|
|||
uint8_t strikes;
|
||||
|
||||
uint8_t encryption_preference;
|
||||
tr_port port;
|
||||
tr_port dht_port;
|
||||
tr_address addr;
|
||||
struct tr_peerIo * io;
|
||||
struct peer_atom * atom;
|
||||
|
||||
|
@ -109,6 +107,7 @@ typedef struct tr_peer
|
|||
}
|
||||
tr_peer;
|
||||
|
||||
const tr_address * tr_peerAddress( const tr_peer * );
|
||||
|
||||
int tr_pexCompare( const void * a, const void * b );
|
||||
|
||||
|
|
|
@ -412,7 +412,7 @@ protocolSendHaveNone( tr_peermsgs * msgs )
|
|||
*** EVENTS
|
||||
**/
|
||||
|
||||
static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0, 0 };
|
||||
static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0, 0, 0 };
|
||||
|
||||
static void
|
||||
publish( tr_peermsgs * msgs, tr_peer_event * e )
|
||||
|
@ -491,6 +491,15 @@ fireClientGotSuggest( tr_peermsgs * msgs, uint32_t pieceIndex )
|
|||
publish( msgs, &e );
|
||||
}
|
||||
|
||||
static void
|
||||
fireClientGotPort( tr_peermsgs * msgs, tr_port port )
|
||||
{
|
||||
tr_peer_event e = blankEvent;
|
||||
e.eventType = TR_PEER_CLIENT_GOT_PORT;
|
||||
e.port = port;
|
||||
publish( msgs, &e );
|
||||
}
|
||||
|
||||
static void
|
||||
fireClientGotAllowedFast( tr_peermsgs * msgs, uint32_t pieceIndex )
|
||||
{
|
||||
|
@ -1059,8 +1068,8 @@ parseLtepHandshake( tr_peermsgs * msgs,
|
|||
|
||||
/* get peer's listening port */
|
||||
if( tr_bencDictFindInt( &val, "p", &i ) ) {
|
||||
msgs->peer->port = htons( (uint16_t)i );
|
||||
dbgmsg( msgs, "msgs->port is now %hu", msgs->peer->port );
|
||||
fireClientGotPort( msgs, (tr_port)i );
|
||||
dbgmsg( msgs, "peer's port is now %d", (int)i );
|
||||
}
|
||||
|
||||
/* get peer's maximum request queue size */
|
||||
|
@ -1455,7 +1464,9 @@ readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen )
|
|||
dbgmsg( msgs, "Got a BT_PORT" );
|
||||
tr_peerIoReadUint16( msgs->peer->io, inbuf, &msgs->peer->dht_port );
|
||||
if( msgs->peer->dht_port > 0 )
|
||||
tr_dhtAddNode( getSession(msgs), &msgs->peer->addr, msgs->peer->dht_port, 0 );
|
||||
tr_dhtAddNode( getSession(msgs),
|
||||
tr_peerAddress( msgs->peer ),
|
||||
msgs->peer->dht_port, 0 );
|
||||
break;
|
||||
|
||||
case BT_FEXT_SUGGEST:
|
||||
|
|
|
@ -52,18 +52,27 @@ THE SOFTWARE.
|
|||
|
||||
#ifdef WITHOUT_DHT
|
||||
|
||||
/* These are the stubs for when we're building without DHT support */
|
||||
/**
|
||||
*** These are the stubs for when we're building without DHT support
|
||||
**/
|
||||
|
||||
int tr_dhtInit( tr_session * session UNUSED,
|
||||
tr_address * address UNUSED ) { return TR_DHT_STOPPED; }
|
||||
|
||||
void tr_dhtUninit( tr_session * session UNUSED ) { }
|
||||
|
||||
tr_bool tr_dhtEnabled( const tr_session * session UNUSED ) { return FALSE; }
|
||||
|
||||
tr_port tr_dhtPort ( const tr_session * sesssion UNUSED ) { return 0; }
|
||||
|
||||
int tr_dhtStatus( tr_session * session UNUSED,
|
||||
int * setmeCount UNUSED ) { return TR_DHT_STOPPED; }
|
||||
int tr_dhtAddNode( tr_session * session UNUSED,
|
||||
tr_address * addr UNUSED,
|
||||
tr_port port UNUSED,
|
||||
tr_bool bootstrap UNUSED ) { return 0; }
|
||||
|
||||
int tr_dhtAddNode( tr_session * session UNUSED,
|
||||
const tr_address * addr UNUSED,
|
||||
tr_port port UNUSED,
|
||||
tr_bool bootstrap UNUSED ) { return 0; }
|
||||
|
||||
int tr_dhtAnnounce( tr_torrent * session UNUSED,
|
||||
tr_bool announce UNUSED ) { return -1; }
|
||||
|
||||
|
@ -319,8 +328,10 @@ tr_dhtPort( const tr_session *ss )
|
|||
}
|
||||
|
||||
int
|
||||
tr_dhtAddNode(tr_session *ss, tr_address *address, tr_port port,
|
||||
tr_bool bootstrap)
|
||||
tr_dhtAddNode( tr_session * ss,
|
||||
const tr_address * address,
|
||||
tr_port port,
|
||||
tr_bool bootstrap )
|
||||
{
|
||||
struct sockaddr_in sin;
|
||||
|
||||
|
|
|
@ -32,5 +32,5 @@ tr_bool tr_dhtEnabled( const tr_session * );
|
|||
tr_port tr_dhtPort ( const tr_session * );
|
||||
int tr_dhtStatus( tr_session *, int * setme_nodeCount );
|
||||
const char *tr_dhtPrintableStatus(int status);
|
||||
int tr_dhtAddNode( tr_session *, tr_address *, tr_port, tr_bool bootstrap );
|
||||
int tr_dhtAddNode( tr_session *, const tr_address *, tr_port, tr_bool bootstrap );
|
||||
int tr_dhtAnnounce( tr_torrent *, tr_bool announce );
|
||||
|
|
|
@ -51,7 +51,7 @@ struct tr_webseed
|
|||
****
|
||||
***/
|
||||
|
||||
static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0, 0 };
|
||||
static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0, 0, 0 };
|
||||
|
||||
static void
|
||||
publish( tr_webseed * w,
|
||||
|
|
Loading…
Reference in a new issue