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;
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.");
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;
/* 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
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 */
struct tr_bindinfo * public_ipv4;
struct tr_bindinfo * public_ipv6;
-
- uint8_t peer_id[PEER_ID_LEN+1];
};
static inline tr_port
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);