Changeset 3508


Ignore:
Timestamp:
Oct 23, 2007, 8:42:00 PM (15 years ago)
Author:
charles
Message:

rewind this morning's changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/handshake.c

    r3507 r3508  
    117117    /* incoming */
    118118    AWAITING_HANDSHAKE,
    119     AWAITING_PEER_ID,
    120119    AWAITING_YA,
    121120    AWAITING_PAD_A,
     
    167166    switch( state ) {
    168167        case AWAITING_HANDSHAKE:      str = "awaiting handshake"; break;
    169         case AWAITING_PEER_ID:        str = "awaiting peer_id"; break;
    170168        case AWAITING_YA:             str = "awaiting ya"; break;
    171169        case AWAITING_PAD_A:          str = "awaiting pad a"; break;
     
    532530    uint8_t reserved[HANDSHAKE_FLAGS_LEN];
    533531    uint8_t hash[SHA_DIGEST_LENGTH];
    534     const size_t sizeNeeded = HANDSHAKE_SIZE - PEER_ID_LEN;
     532    char * client;
    535533
    536534/* FIXME: use  readHandshake here */
    537535
    538     dbgmsg( handshake, "payload: need %d, got %d", (int)sizeNeeded, (int)EVBUFFER_LENGTH(inbuf) );
    539 
    540     if( EVBUFFER_LENGTH(inbuf) < sizeNeeded )
     536    dbgmsg( handshake, "payload: need %d, got %d", (int)HANDSHAKE_SIZE, (int)EVBUFFER_LENGTH(inbuf) );
     537
     538    if( EVBUFFER_LENGTH(inbuf) < HANDSHAKE_SIZE )
    541539        return READ_MORE;
    542540
     
    618616    }
    619617
    620     /**
    621     *** Extension negotiation
    622     **/
    623 
    624     if( HANDSHAKE_HAS_LTEP( reserved ) )
    625     {
    626         tr_peerIoEnableLTEP( handshake->io, 1 );
    627         dbgmsg( handshake,"using ltep" );
    628     }
    629     if( HANDSHAKE_HAS_FASTEXT( reserved ) )
    630     {
    631         tr_peerIoEnableFEXT( handshake->io, 1 );
    632         dbgmsg( handshake,"using fext" );
    633     }
    634    
    635     /**
    636     ***  If this is an incoming message, then we need to send a response handshake
    637     **/
    638 
    639     if( !handshake->haveSentBitTorrentHandshake )
    640     {
    641         int msgSize;
    642         uint8_t * msg = buildHandshakeMessage( handshake, &msgSize );
    643         tr_peerIoWrite( handshake->io, msg, msgSize );
    644         tr_free( msg );
    645         handshake->haveSentBitTorrentHandshake = 1;
    646     }
    647 
    648     setReadState( handshake, AWAITING_PEER_ID );
    649     return READ_AGAIN;
    650 }
    651 
    652 static int
    653 readPeerId( tr_handshake * handshake, struct evbuffer * inbuf )
    654 {
    655     int connectedToSelf;
    656     char * client;
    657     const size_t sizeNeeded = PEER_ID_LEN;
    658     if( EVBUFFER_LENGTH(inbuf) < sizeNeeded )
    659         return READ_MORE;
    660 
    661618    /* peer id */
    662619    tr_peerIoReadBytes( handshake->io, inbuf, handshake->peer_id, sizeof(handshake->peer_id) );
     
    666623    dbgmsg( handshake, "peer-id is [%s]", client );
    667624    tr_free( client );
     625    if( !memcmp( handshake->peer_id, getPeerId(), PEER_ID_LEN ) ) {
     626        dbgmsg( handshake, "streuth!  we've connected to ourselves." );
     627        tr_handshakeDone( handshake, FALSE );
     628        return READ_DONE;
     629    }
     630
     631    /**
     632    *** Extension negotiation
     633    **/
     634
     635    if( HANDSHAKE_HAS_LTEP( reserved ) )
     636    {
     637        tr_peerIoEnableLTEP( handshake->io, 1 );
     638        dbgmsg( handshake,"using ltep" );
     639    }
     640    if( HANDSHAKE_HAS_FASTEXT( reserved ) )
     641    {
     642        tr_peerIoEnableFEXT( handshake->io, 1 );
     643        dbgmsg( handshake,"using fext" );
     644    }
     645   
     646    /**
     647    ***  If this is an incoming message, then we need to send a response handshake
     648    **/
     649
     650    if( !handshake->haveSentBitTorrentHandshake )
     651    {
     652        int msgSize;
     653        uint8_t * msg = buildHandshakeMessage( handshake, &msgSize );
     654        tr_peerIoWrite( handshake->io, msg, msgSize );
     655        tr_free( msg );
     656        handshake->haveSentBitTorrentHandshake = 1;
     657    }
    668658
    669659    /* we've completed the BT handshake... pass the work on to peer-msgs */
    670     connectedToSelf = memcmp( handshake->peer_id, getPeerId(), PEER_ID_LEN ) != 0;
    671     tr_handshakeDone( handshake, !connectedToSelf );
     660    tr_handshakeDone( handshake, TRUE );
    672661    return READ_DONE;
    673662}
    674663
    675664static int
    676 readYa( tr_handshake * handshake, struct evbuffer * inbuf )
     665readYa( tr_handshake * handshake, struct evbuffer  * inbuf )
    677666{
    678667    uint8_t ya[KEY_LEN];
     
    913902canRead( struct bufferevent * evin, void * arg )
    914903{
    915     tr_handshake * h = arg;
     904    tr_handshake * handshake = (tr_handshake *) arg;
    916905    struct evbuffer * inbuf = EVBUFFER_INPUT ( evin );
    917906    ReadState ret;
    918     dbgmsg( h, "handling canRead; state is [%s]", getStateName(h->state) );
    919 
    920     switch( h->state )
    921     {
    922         case AWAITING_HANDSHAKE:       ret = readHandshake    ( h, inbuf ); break;
    923         case AWAITING_PEER_ID:         ret = readPeerId       ( h, inbuf ); break;
    924         case AWAITING_YA:              ret = readYa           ( h, inbuf ); break;
    925         case AWAITING_PAD_A:           ret = readPadA         ( h, inbuf ); break;
    926         case AWAITING_CRYPTO_PROVIDE:  ret = readCryptoProvide( h, inbuf ); break;
    927         case AWAITING_PAD_C:           ret = readPadC         ( h, inbuf ); break;
    928         case AWAITING_IA:              ret = readIA           ( h, inbuf ); break;
    929 
    930         case AWAITING_YB:              ret = readYb           ( h, inbuf ); break;
    931         case AWAITING_VC:              ret = readVC           ( h, inbuf ); break;
    932         case AWAITING_CRYPTO_SELECT:   ret = readCryptoSelect ( h, inbuf ); break;
    933         case AWAITING_PAD_D:           ret = readPadD         ( h, inbuf ); break;
     907    dbgmsg( handshake, "handling canRead; state is [%s]", getStateName(handshake->state) );
     908
     909    switch( handshake->state )
     910    {
     911        case AWAITING_HANDSHAKE:       ret = readHandshake    ( handshake, inbuf ); break;
     912        case AWAITING_YA:              ret = readYa           ( handshake, inbuf ); break;
     913        case AWAITING_PAD_A:           ret = readPadA         ( handshake, inbuf ); break;
     914        case AWAITING_CRYPTO_PROVIDE:  ret = readCryptoProvide( handshake, inbuf ); break;
     915        case AWAITING_PAD_C:           ret = readPadC         ( handshake, inbuf ); break;
     916        case AWAITING_IA:              ret = readIA           ( handshake, inbuf ); break;
     917
     918        case AWAITING_YB:              ret = readYb           ( handshake, inbuf ); break;
     919        case AWAITING_VC:              ret = readVC           ( handshake, inbuf ); break;
     920        case AWAITING_CRYPTO_SELECT:   ret = readCryptoSelect ( handshake, inbuf ); break;
     921        case AWAITING_PAD_D:           ret = readPadD         ( handshake, inbuf ); break;
    934922
    935923        default: assert( 0 );
Note: See TracChangeset for help on using the changeset viewer.