Changeset 8563


Ignore:
Timestamp:
May 30, 2009, 9:45:40 PM (14 years ago)
Author:
charles
Message:

(trunk libT) dead code removal

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/handshake.c

    r8483 r8563  
    108108    tr_crypto *           crypto;
    109109    tr_session *          session;
    110     uint8_t               myPublicKey[KEY_LEN];
    111110    uint8_t               mySecret[KEY_LEN];
    112111    uint8_t               state;
     
    118117    uint32_t              crypto_provide;
    119118    uint8_t               myReq1[SHA_DIGEST_LENGTH];
    120     uint8_t               peer_id[PEER_ID_LEN];
    121119    handshakeDoneCB       doneCB;
    122120    void *                doneUserData;
     
    215213}
    216214
    217 static uint8_t *
    218 buildHandshakeMessage( tr_handshake * handshake,
    219                        int *          setme_len )
    220 {
    221     uint8_t          * buf = tr_new0( uint8_t, HANDSHAKE_SIZE );
     215static void
     216buildHandshakeMessage( tr_handshake * handshake, uint8_t * buf )
     217{
    222218    uint8_t          * walk = buf;
    223219    const uint8_t    * torrentHash = tr_cryptoGetTorrentHash( handshake->crypto );
     
    245241    assert( strlen( ( const char* )peer_id ) == PEER_ID_LEN );
    246242    assert( walk - buf == HANDSHAKE_SIZE );
    247     *setme_len = walk - buf;
    248     return buf;
    249243}
    250244
     
    268262    uint8_t hash[SHA_DIGEST_LENGTH];
    269263    const tr_torrent * tor;
    270     const uint8_t * peer_id;
     264    const uint8_t * tor_peer_id;
     265    uint8_t peer_id[PEER_ID_LEN];
    271266
    272267    dbgmsg( handshake, "payload: need %d, got %zu",
     
    296291
    297292    /* peer_id */
    298     tr_peerIoReadBytes( handshake->io, inbuf, handshake->peer_id,
    299                        sizeof( handshake->peer_id ) );
    300     tr_peerIoSetPeersId( handshake->io, handshake->peer_id );
     293    tr_peerIoReadBytes( handshake->io, inbuf, peer_id, sizeof( peer_id ) );
     294    tr_peerIoSetPeersId( handshake->io, peer_id );
    301295
    302296    /* peer id */
    303297    handshake->havePeerID = TRUE;
    304     dbgmsg( handshake, "peer-id is [%*.*s]", PEER_ID_LEN, PEER_ID_LEN,
    305             handshake->peer_id );
     298    dbgmsg( handshake, "peer-id is [%*.*s]", PEER_ID_LEN, PEER_ID_LEN, peer_id );
    306299
    307300    tor = tr_torrentFindFromHash( handshake->session, hash );
    308     peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
    309     if( !memcmp( handshake->peer_id, peer_id, PEER_ID_LEN ) )
     301    tor_peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
     302    if( !memcmp( peer_id, tor_peer_id, PEER_ID_LEN ) )
    310303    {
    311304        dbgmsg( handshake, "streuth!  we've connected to ourselves." );
     
    494487    /* ENCRYPT len(IA)), ENCRYPT(IA) */
    495488    {
    496         int       msglen;
    497         uint8_t * msg = buildHandshakeMessage( handshake, &msglen );
    498 
    499         tr_peerIoWriteUint16( handshake->io, outbuf, msglen );
    500         tr_peerIoWriteBytes( handshake->io, outbuf, msg, msglen );
     489        uint8_t msg[HANDSHAKE_SIZE];
     490        buildHandshakeMessage( handshake, msg );
     491
     492        tr_peerIoWriteUint16( handshake->io, outbuf, sizeof( msg ) );
     493        tr_peerIoWriteBytes( handshake->io, outbuf, msg, sizeof( msg ) );
    501494
    502495        handshake->haveSentBitTorrentHandshake = 1;
    503         tr_free( msg );
    504496    }
    505497
     
    719711    if( !handshake->haveSentBitTorrentHandshake )
    720712    {
    721         int       msgSize;
    722         uint8_t * msg = buildHandshakeMessage( handshake, &msgSize );
    723         tr_peerIoWrite( handshake->io, msg, msgSize, FALSE );
    724         tr_free( msg );
     713        uint8_t msg[HANDSHAKE_SIZE];
     714        buildHandshakeMessage( handshake, msg );
     715        tr_peerIoWrite( handshake->io, msg, sizeof( msg ), FALSE );
    725716        handshake->haveSentBitTorrentHandshake = 1;
    726717    }
     
    737728    char client[128];
    738729    tr_torrent * tor;
    739     const uint8_t * peer_id;
     730    const uint8_t * tor_peer_id;
     731    uint8_t peer_id[PEER_ID_LEN];
    740732
    741733    if( EVBUFFER_LENGTH( inbuf ) < PEER_ID_LEN )
     
    743735
    744736    /* peer id */
    745     tr_peerIoReadBytes( handshake->io, inbuf, handshake->peer_id, PEER_ID_LEN );
    746     tr_peerIoSetPeersId( handshake->io, handshake->peer_id );
     737    tr_peerIoReadBytes( handshake->io, inbuf, peer_id, PEER_ID_LEN );
     738    tr_peerIoSetPeersId( handshake->io, peer_id );
    747739    handshake->havePeerID = TRUE;
    748     tr_clientForId( client, sizeof( client ), handshake->peer_id );
     740    tr_clientForId( client, sizeof( client ), peer_id );
    749741    dbgmsg( handshake, "peer-id is [%s] ... isIncoming is %d", client,
    750742            tr_peerIoIsIncoming( handshake->io ) );
     
    752744    /* if we've somehow connected to ourselves, don't keep the connection */
    753745    tor = tr_torrentFindFromHash( handshake->session, tr_peerIoGetTorrentHash( handshake->io ) );
    754     peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
    755     peerIsGood = memcmp( handshake->peer_id, peer_id, PEER_ID_LEN ) != 0;
     746    tor_peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
     747    peerIsGood = memcmp( peer_id, tor->peer_id, PEER_ID_LEN ) != 0;
    756748    dbgmsg( handshake, "isPeerGood == %d", peerIsGood );
    757749    return tr_handshakeDone( handshake, peerIsGood );
     
    987979    /* send our handshake */
    988980    {
    989         int       msgSize;
    990         uint8_t * msg = buildHandshakeMessage( handshake, &msgSize );
    991         tr_peerIoWriteBytes( handshake->io, outbuf, msg, msgSize );
     981        uint8_t msg[HANDSHAKE_SIZE];
     982        buildHandshakeMessage( handshake, msg );
     983
     984        tr_peerIoWriteBytes( handshake->io, outbuf, msg, sizeof( msg ) );
    992985        handshake->haveSentBitTorrentHandshake = 1;
    993         tr_free( msg );
    994986    }
    995987
     
    11071099{
    11081100    const uint8_t * peer_id = isConnected && handshake->havePeerID
    1109                               ? handshake->peer_id
    1110                               : NULL;
    1111     const int       success = ( *handshake->doneCB )( handshake,
    1112                                                       handshake->io,
    1113                                                       isConnected,
    1114                                                       peer_id,
    1115                                                       handshake->
    1116                                                       doneUserData );
     1101                            ? tr_peerIoGetPeersId( handshake->io )
     1102                            : NULL;
     1103    const int success = ( *handshake->doneCB )( handshake,
     1104                                                handshake->io,
     1105                                                isConnected,
     1106                                                peer_id,
     1107                                                handshake->doneUserData );
    11171108
    11181109    return success;
     
    11671158      && ( !tr_peerIoReconnect( handshake->io ) ) )
    11681159    {
    1169         int       msgSize;
    1170         uint8_t * msg;
     1160        uint8_t msg[HANDSHAKE_SIZE];
     1161
    11711162        dbgmsg( handshake, "handshake failed, trying plaintext..." );
    1172         msg = buildHandshakeMessage( handshake, &msgSize );
     1163        buildHandshakeMessage( handshake, msg );
    11731164        handshake->haveSentBitTorrentHandshake = 1;
    11741165        setReadState( handshake, AWAITING_HANDSHAKE );
    1175         tr_peerIoWrite( handshake->io, msg, msgSize, FALSE );
    1176         tr_free( msg );
     1166        tr_peerIoWrite( handshake->io, msg, sizeof( msg ), FALSE );
    11771167    }
    11781168    else
     
    12221212    else
    12231213    {
    1224         int       msgSize;
    1225         uint8_t * msg = buildHandshakeMessage( handshake, &msgSize );
     1214        uint8_t msg[HANDSHAKE_SIZE];
     1215        buildHandshakeMessage( handshake, msg );
     1216
    12261217        handshake->haveSentBitTorrentHandshake = 1;
    12271218        setReadState( handshake, AWAITING_HANDSHAKE );
    1228         tr_peerIoWrite( handshake->io, msg, msgSize, FALSE );
    1229         tr_free( msg );
     1219        tr_peerIoWrite( handshake->io, msg, sizeof( msg ), FALSE );
    12301220    }
    12311221
Note: See TracChangeset for help on using the changeset viewer.