]> granicus.if.org Git - transmission/commitdiff
(libT) remove pointless tr_session.peer_id variable
authorJordan Lee <jordan@transmissionbt.com>
Sat, 2 Feb 2013 05:31:43 +0000 (05:31 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sat, 2 Feb 2013 05:31:43 +0000 (05:31 +0000)
libtransmission/handshake.c
libtransmission/session.c
libtransmission/session.h

index 3a525c15a9302c3a6bb5c55986e32b296e6c786e..6ada2127e6ec6cece1d7c8b95c4ad37899923d09 100644 (file)
@@ -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
index eac04e0ee3f93ef33bbf5437e301c1b1ff4174b0..9caaba96eff8733e53893cd4faab4e80239f3779 100644 (file)
@@ -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 */
index d4eb8e3ef0a335b9b6f3cdad1f5989d061ab9162..6ea3a334f5c90b178ecbb4ead4536f755694d5b1 100644 (file)
@@ -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);