1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-31 03:12:44 +00:00

(libT) remove pointless tr_session.peer_id variable

This commit is contained in:
Jordan Lee 2013-02-02 05:31:43 +00:00
parent f8cae213db
commit aa8ddcb218
3 changed files with 7 additions and 18 deletions

View 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

View 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 */

View 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);