Changeset 7340


Ignore:
Timestamp:
Dec 10, 2008, 5:20:28 AM (12 years ago)
Author:
charles
Message:

(trunk libT) fix minor r7266 oops that could keep us from disconnecting if we made a peer connection to ourself

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/handshake.c

    r7289 r7340  
    208208    const uint8_t    * torrentHash = tr_cryptoGetTorrentHash( handshake->crypto );
    209209    const tr_torrent * tor = tr_torrentFindFromHash( handshake->handle, torrentHash );
    210     const uint8_t    * peerId = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
     210    const uint8_t    * peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
    211211
    212212    memcpy( walk, HANDSHAKE_NAME, HANDSHAKE_NAME_LEN );
     
    219219    memcpy( walk, torrentHash, SHA_DIGEST_LENGTH );
    220220    walk += SHA_DIGEST_LENGTH;
    221     memcpy( walk, peerId, PEER_ID_LEN );
     221    memcpy( walk, peer_id, PEER_ID_LEN );
    222222    walk += PEER_ID_LEN;
    223223
    224     assert( strlen( ( const char* )peerId ) == PEER_ID_LEN );
     224    assert( strlen( ( const char* )peer_id ) == PEER_ID_LEN );
    225225    assert( walk - buf == HANDSHAKE_SIZE );
    226226    *setme_len = walk - buf;
     
    246246    uint8_t reserved[HANDSHAKE_FLAGS_LEN];
    247247    uint8_t hash[SHA_DIGEST_LENGTH];
     248    const tr_torrent * tor;
     249    const uint8_t * peer_id;
    248250
    249251    dbgmsg( handshake, "payload: need %d, got %zu",
     
    281283    dbgmsg( handshake, "peer-id is [%*.*s]", PEER_ID_LEN, PEER_ID_LEN,
    282284            handshake->peer_id );
    283     if( !memcmp( handshake->peer_id, tr_getPeerId( ), PEER_ID_LEN ) )
     285
     286    tor = tr_torrentFindFromHash( handshake->handle, hash );
     287    peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
     288    if( !memcmp( handshake->peer_id, peer_id, PEER_ID_LEN ) )
    284289    {
    285290        dbgmsg( handshake, "streuth!  we've connected to ourselves." );
     
    700705
    701706static int
    702 readPeerId( tr_handshake *    handshake,
     707readPeerId( tr_handshake    * handshake,
    703708            struct evbuffer * inbuf )
    704709{
    705710    int  peerIsGood;
    706711    char client[128];
     712    tr_torrent * tor;
     713    const uint8_t * peer_id;
    707714
    708715    if( EVBUFFER_LENGTH( inbuf ) < PEER_ID_LEN )
     
    718725
    719726    /* if we've somehow connected to ourselves, don't keep the connection */
    720     peerIsGood =
    721         memcmp( handshake->peer_id, tr_getPeerId( ), PEER_ID_LEN ) ? 1 : 0;
     727    tor = tr_torrentFindFromHash( handshake->handle, tr_peerIoGetTorrentHash( handshake->io ) );
     728    peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
     729    peerIsGood = memcmp( handshake->peer_id, peer_id, PEER_ID_LEN ) != 0;
    722730    dbgmsg( handshake, "isPeerGood == %d", peerIsGood );
    723731    return tr_handshakeDone( handshake, peerIsGood );
Note: See TracChangeset for help on using the changeset viewer.