diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index ced5d1634..b77ddf8b6 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -203,11 +203,11 @@ static uint8_t * buildHandshakeMessage( tr_handshake * handshake, int * setme_len ) { - uint8_t * buf = tr_new0( uint8_t, HANDSHAKE_SIZE ); - uint8_t * walk = buf; - const uint8_t * torrentHash = tr_cryptoGetTorrentHash( - handshake->crypto ); - const uint8_t * peerId = tr_getPeerId( ); + uint8_t * buf = tr_new0( uint8_t, HANDSHAKE_SIZE ); + uint8_t * walk = buf; + const uint8_t * torrentHash = tr_cryptoGetTorrentHash( handshake->crypto ); + const tr_torrent * tor = tr_torrentFindFromHash( handshake->handle, torrentHash ); + const uint8_t * peerId = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( ); memcpy( walk, HANDSHAKE_NAME, HANDSHAKE_NAME_LEN ); walk += HANDSHAKE_NAME_LEN; @@ -665,9 +665,7 @@ readHandshake( tr_handshake * handshake, { if( !tr_torrentExists( handshake->handle, hash ) ) { - dbgmsg( - handshake, - "peer is trying to connect to us for a torrent we don't have." ); + dbgmsg( handshake, "peer is trying to connect to us for a torrent we don't have." ); return tr_handshakeDone( handshake, FALSE ); } else @@ -688,8 +686,7 @@ readHandshake( tr_handshake * handshake, } /** - *** If this is an incoming message, then we need to send a response - ***handshake + *** If it's an incoming message, we need to send a response handshake **/ if( !handshake->haveSentBitTorrentHandshake ) diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index 47927e295..07176bc41 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -181,8 +181,17 @@ struct tr_torrent uint8_t obfuscatedHash[SHA_DIGEST_LENGTH]; + /* If the initiator of the connection receives a handshake in which the + * peer_id does not match the expected peerid, then the initiator is + * expected to drop the connection. Note that the initiator presumably + * received the peer information from the tracker, which includes the + * peer_id that was registered by the peer. The peer_id from the tracker + * and in the handshake are expected to match. + */ + uint8_t * peer_id; + /* Where to download */ - char * downloadDir; + char * downloadDir; /* How many bytes we ask for per request */ uint32_t blockSize; diff --git a/libtransmission/tracker.c b/libtransmission/tracker.c index b93edcaa3..832b3a3a4 100644 --- a/libtransmission/tracker.c +++ b/libtransmission/tracker.c @@ -1091,8 +1091,15 @@ tr_trackerStart( tr_tracker * t ) { if( t && !t->isRunning ) { + tr_torrent * tor; + + /* change the peer-id */ tr_free( t->peer_id ); t->peer_id = tr_peerIdNew( ); + if(( tor = tr_torrentFindFromHash( t->session, t->hash ))) { + tr_free( tor->peer_id ); + tor->peer_id = (uint8_t*) tr_strdup( t->peer_id ); + } t->isRunning = 1; enqueueRequest( t->session, t, TR_REQ_STARTED );