From aa8ddcb21865bc6d343d071980197d486dbb5fe0 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Sat, 2 Feb 2013 05:31:43 +0000 Subject: [PATCH] (libT) remove pointless tr_session.peer_id variable --- libtransmission/handshake.c | 16 +++++++--------- libtransmission/session.c | 1 - libtransmission/session.h | 8 -------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index 3a525c15a..6ada2127e 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -194,7 +194,7 @@ buildHandshakeMessage (tr_handshake * handshake, uint8_t * buf) uint8_t * walk = buf; const uint8_t * torrentHash = tr_cryptoGetTorrentHash (handshake->crypto); const tr_torrent * tor = tr_torrentFindFromHash (handshake->session, torrentHash); - const uint8_t * peer_id = tor && *tor->peer_id ? tor->peer_id : tr_getPeerId (handshake->session); + const uint8_t * peer_id = tor->peer_id; memcpy (walk, HANDSHAKE_NAME, HANDSHAKE_NAME_LEN); walk += HANDSHAKE_NAME_LEN; @@ -272,7 +272,7 @@ parseHandshake (tr_handshake * handshake, dbgmsg (handshake, "peer-id is [%*.*s]", PEER_ID_LEN, PEER_ID_LEN, peer_id); tor = tr_torrentFindFromHash (handshake->session, hash); - tor_peer_id = tor ? tor->peer_id : tr_getPeerId (handshake->session); + tor_peer_id = tor->peer_id; if (!memcmp (peer_id, tor_peer_id, PEER_ID_LEN)) { dbgmsg (handshake, "streuth! we've connected to ourselves."); @@ -685,11 +685,10 @@ static int readPeerId (tr_handshake * handshake, struct evbuffer * inbuf) { - bool peerIsGood; + bool connected_to_self; char client[128]; - tr_torrent * tor; - const uint8_t * tor_peer_id; uint8_t peer_id[PEER_ID_LEN]; + tr_torrent * tor; if (evbuffer_get_length (inbuf) < PEER_ID_LEN) return READ_LATER; @@ -704,10 +703,9 @@ readPeerId (tr_handshake * handshake, /* if we've somehow connected to ourselves, don't keep the connection */ tor = tr_torrentFindFromHash (handshake->session, tr_peerIoGetTorrentHash (handshake->io)); - tor_peer_id = tor ? tor->peer_id : tr_getPeerId (handshake->session); - peerIsGood = memcmp (peer_id, tor_peer_id, PEER_ID_LEN) != 0; - dbgmsg (handshake, "isPeerGood == %d", (int)peerIsGood); - return tr_handshakeDone (handshake, peerIsGood); + connected_to_self = (tor != NULL) && !memcmp (peer_id, tor->peer_id, PEER_ID_LEN); + + return tr_handshakeDone (handshake, !connected_to_self); } static int diff --git a/libtransmission/session.c b/libtransmission/session.c index eac04e0ee..9caaba96e 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -592,7 +592,6 @@ tr_sessionInit (const char * tag, session->tag = tr_strdup (tag); session->magicNumber = SESSION_MAGIC_NUMBER; tr_bandwidthConstruct (&session->bandwidth, session, NULL); - tr_peerIdInit (session->peer_id); tr_variantInitList (&session->removedTorrents, 0); /* nice to start logging at the very beginning */ diff --git a/libtransmission/session.h b/libtransmission/session.h index d4eb8e3ef..6ea3a334f 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -223,8 +223,6 @@ struct tr_session struct tr_bindinfo * public_ipv4; struct tr_bindinfo * public_ipv6; - - uint8_t peer_id[PEER_ID_LEN+1]; }; static inline tr_port @@ -233,12 +231,6 @@ tr_sessionGetPublicPeerPort (const tr_session * session) return session->public_peer_port; } -static inline const uint8_t* -tr_getPeerId (tr_session * session) -{ - return session->peer_id; -} - bool tr_sessionAllowsDHT (const tr_session * session); bool tr_sessionAllowsLPD (const tr_session * session); -- 2.40.0