Changeset 7341


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.4x/libtransmission/handshake.c

    r7267 r7341  
    209209    const uint8_t    * torrentHash = tr_cryptoGetTorrentHash( handshake->crypto );
    210210    const tr_torrent * tor = tr_torrentFindFromHash( handshake->handle, torrentHash );
    211     const uint8_t    * peerId = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
     211    const uint8_t    * peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
    212212
    213213    memcpy( walk, HANDSHAKE_NAME, HANDSHAKE_NAME_LEN );
     
    220220    memcpy( walk, torrentHash, SHA_DIGEST_LENGTH );
    221221    walk += SHA_DIGEST_LENGTH;
    222     memcpy( walk, peerId, PEER_ID_LEN );
     222    memcpy( walk, peer_id, PEER_ID_LEN );
    223223    walk += PEER_ID_LEN;
    224224
    225     assert( strlen( ( const char* )peerId ) == PEER_ID_LEN );
     225    assert( strlen( ( const char* )peer_id ) == PEER_ID_LEN );
    226226    assert( walk - buf == HANDSHAKE_SIZE );
    227227    *setme_len = walk - buf;
     
    247247    uint8_t reserved[HANDSHAKE_FLAGS_LEN];
    248248    uint8_t hash[SHA_DIGEST_LENGTH];
     249    const tr_torrent * tor;
     250    const uint8_t * peer_id;
    249251
    250252    dbgmsg( handshake, "payload: need %d, got %d", (int)HANDSHAKE_SIZE,
     
    282284    dbgmsg( handshake, "peer-id is [%*.*s]", PEER_ID_LEN, PEER_ID_LEN,
    283285            handshake->peer_id );
    284     if( !memcmp( handshake->peer_id, tr_getPeerId( ), PEER_ID_LEN ) )
     286
     287    tor = tr_torrentFindFromHash( handshake->handle, hash );
     288    peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
     289    if( !memcmp( handshake->peer_id, peer_id, PEER_ID_LEN ) )
    285290    {
    286291        dbgmsg( handshake, "streuth!  we've connected to ourselves." );
     
    720725
    721726static int
    722 readPeerId( tr_handshake *    handshake,
     727readPeerId( tr_handshake    * handshake,
    723728            struct evbuffer * inbuf )
    724729{
    725730    int  peerIsGood;
    726731    char client[128];
     732    tr_torrent * tor;
     733    const uint8_t * peer_id;
    727734
    728735    if( EVBUFFER_LENGTH( inbuf ) < PEER_ID_LEN )
     
    740747
    741748    /* if we've somehow connected to ourselves, don't keep the connection */
    742     peerIsGood =
    743         memcmp( handshake->peer_id, tr_getPeerId( ), PEER_ID_LEN ) ? 1 : 0;
     749    tor = tr_torrentFindFromHash( handshake->handle, tr_peerIoGetTorrentHash( handshake->io ) );
     750    peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
     751    peerIsGood = memcmp( handshake->peer_id, peer_id, PEER_ID_LEN ) != 0;
    744752    dbgmsg( handshake, "isPeerGood == %d", peerIsGood );
    745753    return tr_handshakeDone( handshake, peerIsGood );
Note: See TracChangeset for help on using the changeset viewer.