diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 3766f74dc..c68af636e 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -275,7 +275,7 @@ peerCompare( const void * va, const void * vb ) const tr_peer * a = va; const tr_peer * b = vb; - return tr_compareAddresses( &a->atom->addr, &b->atom->addr ); + return tr_compareAddresses( &a->addr, &b->addr ); } static int @@ -283,7 +283,7 @@ peerCompareToAddr( const void * va, const void * vb ) { const tr_peer * a = va; - return tr_compareAddresses( &a->atom->addr, vb ); + return tr_compareAddresses( &a->addr, vb ); } static tr_peer* @@ -319,9 +319,12 @@ peerIsInUse( const Torrent * ct, } static tr_peer* -peerConstructor( void ) +peerConstructor( const tr_address * addr ) { - return tr_new0( tr_peer, 1 ); + tr_peer * p; + p = tr_new0( tr_peer, 1 ); + p->addr = *addr; + return p; } static tr_peer* @@ -336,7 +339,7 @@ getPeer( Torrent * torrent, if( peer == NULL ) { - peer = peerConstructor( ); + peer = peerConstructor( addr ); tr_ptrArrayInsertSorted( &torrent->peers, peer, peerCompare ); } @@ -921,14 +924,15 @@ static void addStrike( Torrent * t, tr_peer * peer ) { tordbg( t, "increasing peer %s strike count to %d", - tr_atomAddrStr( peer->atom ), peer->strikes + 1 ); + tr_peerIoAddrStr( &peer->addr, + peer->port ), 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_atomAddrStr( atom ) ); + tordbg( t, "banning peer %s", tr_peerIoAddrStr( &atom->addr, atom->port ) ); } } @@ -1100,7 +1104,7 @@ 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_atomAddrStr( atom ) ); + tordbg( t, "marking peer %s as a seed", tr_peerIoAddrStr( &atom->addr, atom->port ) ); atom->flags |= ADDED_F_SEED_FLAG; } } @@ -1167,7 +1171,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_atomAddrStr( peer->atom ) ); + tr_peerIoAddrStr( &peer->addr, peer->port ) ); } else { @@ -1200,7 +1204,7 @@ ensureAtomExists( Torrent * t, a->port = port; a->flags = flags; a->from = from; - tordbg( t, "got a new atom: %s", tr_atomAddrStr( a ) ); + tordbg( t, "got a new atom: %s", tr_peerIoAddrStr( &a->addr, a->port ) ); tr_ptrArrayInsertSorted( &t->pool, a, comparePeerAtoms ); } } @@ -1276,7 +1280,8 @@ myHandshakeDoneCB( tr_handshake * handshake, if( atom->myflags & MYFLAG_BANNED ) { - tordbg( t, "banned peer %s tried to reconnect", tr_atomAddrStr( atom ) ); + tordbg( t, "banned peer %s tried to reconnect", + tr_peerIoAddrStr( &atom->addr, atom->port ) ); } else if( tr_peerIoIsIncoming( io ) && ( getPeerCount( t ) >= getMaxPeerCount( t->tor ) ) ) @@ -1303,6 +1308,7 @@ 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() */ @@ -1478,7 +1484,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_atomAddrStr( peer->atom ), + tr_peerIoAddrStr( &peer->addr, peer->port ), pieceIndex, (int)peer->strikes + 1 ); addStrike( t, peer ); } @@ -1876,10 +1882,10 @@ tr_peerMgrPeerStats( const tr_torrent * tor, const struct peer_atom * atom = peer->atom; tr_peer_stat * stat = ret + i; - tr_ntop( &atom->addr, stat->addr, sizeof( stat->addr ) ); + tr_ntop( &peer->addr, stat->addr, sizeof( stat->addr ) ); tr_strlcpy( stat->client, ( peer->client ? peer->client : "" ), sizeof( stat->client ) ); - stat->port = ntohs( atom->port ); + stat->port = ntohs( peer->port ); stat->from = atom->from; stat->progress = peer->progress; stat->isEncrypted = tr_peerIoIsEncrypted( peer->io ) ? 1 : 0; @@ -2386,14 +2392,15 @@ reconnectTorrent( Torrent * t ) struct peer_atom * atom = candidates[i]; tr_peerIo * io; - tordbg( t, "Starting an OUTGOING connection with %s", tr_atomAddrStr( atom ) ); + tordbg( t, "Starting an OUTGOING connection with %s", + tr_peerIoAddrStr( &atom->addr, atom->port ) ); 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_atomAddrStr( atom ) ); + tr_peerIoAddrStr( &atom->addr, atom->port ) ); atom->myflags |= MYFLAG_UNREACHABLE; } else @@ -2636,39 +2643,3 @@ bandwidthPulse( void * vmgr ) managerUnlock( mgr ); return TRUE; } - -/*** -**** -***/ - -tr_port -tr_atomGetPort( const struct peer_atom * atom ) -{ - assert( tr_isAtom( atom ) ); - - return atom->port; -} - -void -tr_atomSetPort( struct peer_atom * atom, tr_port port ) -{ - assert( tr_isAtom( atom ) ); - - atom->port = port; -} - -const char * -tr_atomAddrStr( const struct peer_atom * atom ) -{ - assert( tr_isAtom( atom ) ); - - return tr_peerIoAddrStr( &atom->addr, atom->port ); -} - -const tr_address * -tr_atomGetAddr( const struct peer_atom * atom ) -{ - assert( tr_isAtom( atom ) ); - - return &atom->addr; -} diff --git a/libtransmission/peer-mgr.h b/libtransmission/peer-mgr.h index cc1678048..da5e48ae0 100644 --- a/libtransmission/peer-mgr.h +++ b/libtransmission/peer-mgr.h @@ -59,25 +59,6 @@ struct tr_bandwidth; struct tr_peerIo; struct tr_peermsgs; -/** -*** -**/ - -/* opaque forward declaration */ -struct peer_atom; - -const tr_address* tr_atomGetAddr( const struct peer_atom * ); - -tr_port tr_atomGetPort( const struct peer_atom * atom ); - -void tr_atomSetPort( struct peer_atom * atom, tr_port port ); - -const char* tr_atomAddrStr( const struct peer_atom * ); - -/** -*** -**/ - enum { ENCRYPTION_PREFERENCE_UNKNOWN, @@ -85,6 +66,9 @@ enum ENCRYPTION_PREFERENCE_NO }; +/* opaque forward declaration */ +struct peer_atom; + /** * State information about a connected peer. * @@ -103,7 +87,9 @@ 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; @@ -123,9 +109,6 @@ typedef struct tr_peer } tr_peer; -/** -*** -**/ int tr_pexCompare( const void * a, const void * b ); diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index c62d105c7..b2fa2cf5c 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -1059,8 +1059,8 @@ parseLtepHandshake( tr_peermsgs * msgs, /* get peer's listening port */ if( tr_bencDictFindInt( &val, "p", &i ) ) { - tr_atomSetPort( msgs->peer->atom, htons( (uint16_t)i ) ); - dbgmsg( msgs, "msgs->port is now %hu", tr_atomGetPort( msgs->peer->atom ) ); + msgs->peer->port = htons( (uint16_t)i ); + dbgmsg( msgs, "msgs->port is now %hu", msgs->peer->port ); } /* get peer's maximum request queue size */ @@ -1455,7 +1455,7 @@ 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), tr_atomGetAddr( msgs->peer->atom ), msgs->peer->dht_port, 0 ); + tr_dhtAddNode( getSession(msgs), &msgs->peer->addr, msgs->peer->dht_port, 0 ); break; case BT_FEXT_SUGGEST: diff --git a/libtransmission/tr-dht.c b/libtransmission/tr-dht.c index 5594db541..31492c7b3 100644 --- a/libtransmission/tr-dht.c +++ b/libtransmission/tr-dht.c @@ -60,10 +60,10 @@ THE SOFTWARE. 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, - const tr_address * addr UNUSED, - tr_port port UNUSED, - tr_bool bootstrap UNUSED ) { return 0; } + int tr_dhtAddNode( tr_session * session UNUSED, + 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,10 +319,8 @@ tr_dhtPort( const tr_session *ss ) } int -tr_dhtAddNode(tr_session * ss, - const tr_address * address, - tr_port port, - tr_bool bootstrap) +tr_dhtAddNode(tr_session *ss, tr_address *address, tr_port port, + tr_bool bootstrap) { struct sockaddr_in sin; diff --git a/libtransmission/tr-dht.h b/libtransmission/tr-dht.h index 51c6ca959..d0be03df6 100644 --- a/libtransmission/tr-dht.h +++ b/libtransmission/tr-dht.h @@ -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 *, const tr_address *, tr_port, tr_bool bootstrap ); +int tr_dhtAddNode( tr_session *, tr_address *, tr_port, tr_bool bootstrap ); int tr_dhtAnnounce( tr_torrent *, tr_bool announce ); diff --git a/libtransmission/web.h b/libtransmission/web.h index e6a21414f..12e98e923 100644 --- a/libtransmission/web.h +++ b/libtransmission/web.h @@ -13,8 +13,6 @@ #ifndef TR_HTTP_H #define TR_HTTP_H -struct tr_address; - typedef struct tr_web tr_web; tr_web* tr_webInit( tr_session * session,