Changeset 7287


Ignore:
Timestamp:
Dec 5, 2008, 5:31:39 PM (12 years ago)
Author:
charles
Message:

(1.3x libT) backport #1389: protocol error - bitcomet handshake with TransmissionBT failed

File:
1 edited

Legend:

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

    r7282 r7287  
    122122    AWAITING_PAD_C,
    123123    AWAITING_IA,
     124    AWAITING_PAYLOAD_STREAM,
    124125
    125126    /* outgoing */
     
    147148        case AWAITING_PAD_C:          str = "awaiting pad c"; break;
    148149        case AWAITING_IA:             str = "awaiting ia"; break;
     150        case AWAITING_PAYLOAD_STREAM: str = "awaiting payload stream"; break;
    149151        case AWAITING_YB:             str = "awaiting yb"; break;
    150152        case AWAITING_VC:             str = "awaiting vc"; break;
     
    846848readIA( tr_handshake * handshake, struct evbuffer * inbuf )
    847849{
    848     int i;
    849850    const size_t needlen = handshake->ia_len;
    850851    struct evbuffer * outbuf;
     
    854855    if( EVBUFFER_LENGTH(inbuf) < needlen )
    855856        return READ_MORE;
    856 
    857 dbgmsg( handshake, "reading IA..." );
    858     /* parse the handshake ... */
    859     i = parseHandshake( handshake, inbuf );
    860 dbgmsg( handshake, "parseHandshake returned %d", i );
    861     if( i != HANDSHAKE_OK ) {
    862         tr_handshakeDone( handshake, FALSE );
    863         return READ_DONE;
    864     }
    865857
    866858    /**
     
    923915}
    924916
     917static int
     918readPayloadStream( tr_handshake    * handshake,
     919                   struct evbuffer * inbuf )
     920{
     921    int i;
     922    const size_t needlen = HANDSHAKE_SIZE;
     923
     924    dbgmsg( handshake, "reading payload stream... have %zu, need %zu",
     925            EVBUFFER_LENGTH( inbuf ), needlen );
     926    if( EVBUFFER_LENGTH( inbuf ) < needlen )
     927        return READ_MORE;
     928
     929    /* parse the handshake ... */
     930    i = parseHandshake( handshake, inbuf );
     931    dbgmsg( handshake, "parseHandshake returned %d", i );
     932    tr_handshakeDone( handshake, i == HANDSHAKE_OK );
     933    return READ_DONE;
     934}
     935
    925936/***
    926937****
     
    935946    struct evbuffer * inbuf = EVBUFFER_INPUT ( evin );
    936947    ReadState ret;
     948    int readyForMore = TRUE;
    937949    dbgmsg( handshake, "handling canRead; state is [%s]", getStateName(handshake->state) );
    938950
    939     switch( handshake->state )
    940     {
    941         case AWAITING_HANDSHAKE:       ret = readHandshake    ( handshake, inbuf ); break;
    942         case AWAITING_PEER_ID:         ret = readPeerId       ( handshake, inbuf ); break;
    943         case AWAITING_YA:              ret = readYa           ( handshake, inbuf ); break;
    944         case AWAITING_PAD_A:           ret = readPadA         ( handshake, inbuf ); break;
    945         case AWAITING_CRYPTO_PROVIDE:  ret = readCryptoProvide( handshake, inbuf ); break;
    946         case AWAITING_PAD_C:           ret = readPadC         ( handshake, inbuf ); break;
    947         case AWAITING_IA:              ret = readIA           ( handshake, inbuf ); break;
    948 
    949         case AWAITING_YB:              ret = readYb           ( handshake, inbuf ); break;
    950         case AWAITING_VC:              ret = readVC           ( handshake, inbuf ); break;
    951         case AWAITING_CRYPTO_SELECT:   ret = readCryptoSelect ( handshake, inbuf ); break;
    952         case AWAITING_PAD_D:           ret = readPadD         ( handshake, inbuf ); break;
    953 
    954         default: assert( 0 );
     951    while( readyForMore )
     952    {
     953        switch( handshake->state )
     954        {
     955            case AWAITING_HANDSHAKE:       ret = readHandshake    ( handshake, inbuf ); break;
     956            case AWAITING_PEER_ID:         ret = readPeerId       ( handshake, inbuf ); break;
     957            case AWAITING_YA:              ret = readYa           ( handshake, inbuf ); break;
     958            case AWAITING_PAD_A:           ret = readPadA         ( handshake, inbuf ); break;
     959            case AWAITING_CRYPTO_PROVIDE:  ret = readCryptoProvide( handshake, inbuf ); break;
     960            case AWAITING_PAD_C:           ret = readPadC         ( handshake, inbuf ); break;
     961            case AWAITING_IA:              ret = readIA           ( handshake, inbuf ); break;
     962            case AWAITING_PAYLOAD_STREAM:  ret = readPayloadStream( handshake, inbuf ); break;
     963
     964            case AWAITING_YB:              ret = readYb           ( handshake, inbuf ); break;
     965            case AWAITING_VC:              ret = readVC           ( handshake, inbuf ); break;
     966            case AWAITING_CRYPTO_SELECT:   ret = readCryptoSelect ( handshake, inbuf ); break;
     967            case AWAITING_PAD_D:           ret = readPadD         ( handshake, inbuf ); break;
     968
     969            default: assert( 0 );
     970        }
     971
     972        if( ret != READ_AGAIN )
     973            readyForMore = FALSE;
     974        else if( handshake->state == AWAITING_PAD_C )
     975            readyForMore = EVBUFFER_LENGTH( inbuf ) >= handshake->pad_c_len;
     976        else if( handshake->state == AWAITING_PAD_D )
     977            readyForMore = EVBUFFER_LENGTH( inbuf ) >= handshake->pad_d_len;
     978        else if( handshake->state == AWAITING_IA )
     979            readyForMore = EVBUFFER_LENGTH( inbuf ) >= handshake->ia_len;
    955980    }
    956981
Note: See TracChangeset for help on using the changeset viewer.