From e31b9d8fc5b85802f7aec43b80b43848a718fcbd Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 14 Feb 2010 19:35:09 +0000 Subject: [PATCH] (trunk libT) #2903 "Don't send DHT port messages to peers if we didn't advertise support for DHT in the handshake" -- fixed in trunk for 1.90 --- libtransmission/handshake.c | 18 ++++++------------ libtransmission/peer-msgs.c | 3 ++- libtransmission/tr-dht.c | 2 +- libtransmission/tr-dht.h | 2 +- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index d16e2ee31..075eeb20c 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -225,10 +225,10 @@ buildHandshakeMessage( tr_handshake * handshake, uint8_t * buf ) HANDSHAKE_SET_LTEP( walk ); HANDSHAKE_SET_FASTEXT( walk ); - /* Note that this doesn't depend on whether the torrent is private. We - don't accept DHT peers for a private torrent, but we participate in - the DHT regardless. */ - if(tr_dhtEnabled(handshake->session)) + /* Note that this doesn't depend on whether the torrent is private. + * We don't accept DHT peers for a private torrent, + * but we participate in the DHT regardless. */ + if( tr_dhtEnabled( handshake->session ) ) HANDSHAKE_SET_DHT( walk ); walk += HANDSHAKE_FLAGS_LEN; @@ -312,10 +312,7 @@ parseHandshake( tr_handshake * handshake, tr_peerIoEnableFEXT( handshake->io, HANDSHAKE_HAS_FASTEXT( reserved ) ); - /* This is independent of whether or not DHT is actually used. - * it's okay to set this flag even for private torrents */ - if( tor && tr_sessionAllowsDHT( tor->session ) ) - tr_peerIoEnableDHT( handshake->io, HANDSHAKE_HAS_DHT( reserved ) ); + tr_peerIoEnableDHT( handshake->io, HANDSHAKE_HAS_DHT( reserved ) ); return HANDSHAKE_OK; } @@ -675,10 +672,7 @@ readHandshake( tr_handshake * handshake, tr_peerIoEnableFEXT( handshake->io, HANDSHAKE_HAS_FASTEXT( reserved ) ); - /* This is independent of whether or not DHT is actually used. - * it's okay to set this flag even for private torrents */ - if( tr_sessionAllowsDHT( handshake->session ) ) - tr_peerIoEnableDHT( handshake->io, HANDSHAKE_HAS_DHT( reserved ) ); + tr_peerIoEnableDHT( handshake->io, HANDSHAKE_HAS_DHT( reserved ) ); /* torrent hash */ tr_peerIoReadBytes( handshake->io, inbuf, hash, sizeof( hash ) ); diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 596064301..7867a1050 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -2358,7 +2358,8 @@ tr_peerMsgsNew( struct tr_torrent * torrent, if( tr_peerIoSupportsLTEP( peer->io ) ) sendLtepHandshake( m ); - if(tr_peerIoSupportsDHT(peer->io)) { + if( tr_dhtEnabled( torrent->session ) && tr_peerIoSupportsDHT( peer->io )) + { /* Only send PORT over IPv6 when the IPv6 DHT is running (BEP-32). */ const struct tr_address *addr = tr_peerIoGetAddress( peer->io, NULL ); if( addr->type == TR_AF_INET || tr_globalIPv6() ) { diff --git a/libtransmission/tr-dht.c b/libtransmission/tr-dht.c index 5f18477d9..19a794bef 100644 --- a/libtransmission/tr-dht.c +++ b/libtransmission/tr-dht.c @@ -482,7 +482,7 @@ tr_dhtUninit(tr_session *ss) } tr_bool -tr_dhtEnabled( tr_session * ss ) +tr_dhtEnabled( const tr_session * ss ) { return ss && ( ss == session ); } diff --git a/libtransmission/tr-dht.h b/libtransmission/tr-dht.h index fce2ac0d1..bbf52d999 100644 --- a/libtransmission/tr-dht.h +++ b/libtransmission/tr-dht.h @@ -35,7 +35,7 @@ enum int tr_dhtInit( tr_session *, const tr_address * ); void tr_dhtUninit( tr_session * ); -tr_bool tr_dhtEnabled( tr_session * ); +tr_bool tr_dhtEnabled( const tr_session * ); tr_port tr_dhtPort ( tr_session * ); int tr_dhtStatus( tr_session *, int af, int * setme_nodeCount ); const char *tr_dhtPrintableStatus(int status);