Changeset 5631


Ignore:
Timestamp:
Apr 17, 2008, 2:11:29 AM (14 years ago)
Author:
charles
Message:

#881: follow the transmission spec wrt extension handshake message timing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-msgs.c

    r5602 r5631  
    565565    }
    566566}
    567 #endif
    568567static void
    569568sendFastHave( tr_peermsgs * msgs, int all )
     
    579578    }
    580579}
     580#endif
    581581
    582582static void
     
    853853    int len;
    854854    int pex;
    855     const char * v = TR_NAME " " USERAGENT_PREFIX;
    856     const int port = tr_getPublicPort( msgs->handle );
    857855    struct evbuffer * outbuf;
    858856
     
    873871
    874872    tr_bencInitDict( &val, 4 );
    875     tr_bencInitInt( tr_bencDictAdd( &val, "e" ), 1 );
    876     m  = tr_bencDictAdd( &val, "m" );
    877     tr_bencInit( m, TYPE_DICT );
    878     if( pex ) {
    879         tr_bencDictReserve( m, 1 );
    880         tr_bencInitInt( tr_bencDictAdd( m, "ut_pex" ), TR_LTEP_PEX );
    881     }
    882     if( port > 0 )
    883         tr_bencInitInt( tr_bencDictAdd( &val, "p" ), port );
    884     tr_bencInitStr( tr_bencDictAdd( &val, "v" ), v, 0, 1 );
     873    tr_bencDictAddInt( &val, "e", msgs->handle->encryptionMode != TR_PLAINTEXT_PREFERRED );
     874    tr_bencDictAddInt( &val, "p", tr_getPublicPort( msgs->handle ) );
     875    tr_bencDictAddStr( &val, "v", TR_NAME " " USERAGENT_PREFIX );
     876    m  = tr_bencDictAddDict( &val, "m", 1 );
     877    if( pex )
     878        tr_bencDictAddInt( m, "ut_pex", TR_LTEP_PEX );
    885879    buf = tr_bencSave( &val, &len );
    886880
     
    892886    tr_peerIoWriteBuf( msgs->io, outbuf );
    893887
    894 #if 0
    895     dbgmsg( msgs, "here is the ltep handshake we sent:" );
    896     tr_bencPrint( &val );
    897     dbgmsg( msgs, "here is the ltep handshake we read [%s]:", tr_bencSave( &val, NULL ) );
    898 #endif
     888    dbgmsg( msgs, "here is the ltep handshake we sent [%*.*s]", len, len, buf );
    899889
    900890    /* cleanup */
     
    919909    }
    920910
    921 #if 0
    922     dbgmsg( msgs, "here is the ltep handshake we read:" );
    923     tr_bencPrint( &val );
    924     dbgmsg( msgs, "here is the ltep handshake we read [%s]:", tr_bencSave( &val, NULL ) );
    925 #endif
     911    dbgmsg( msgs, "here is the ltep handshake we got [%*.*s]", len, len, tmp );
    926912
    927913    /* does the peer prefer encrypted connections? */
     
    19301916    *setme = tr_publisherSubscribe( m->publisher, func, userData );
    19311917
     1918    sendBitfield( m );
     1919
    19321920    if ( tr_peerIoSupportsLTEP( m->io ) )
    19331921        sendLtepHandshake( m );
    1934 
    1935     /* bitfield/have-all/have-none must preceed other non-handshake messages... */
    1936     if ( !tr_peerIoSupportsFEXT( m->io ) )
    1937         sendBitfield( m );
    1938     else {
    1939         /* This peer is fastpeer-enabled, send it have-all or have-none if appropriate */
    1940         float completion = tr_cpPercentComplete( m->torrent->completion );
    1941         if ( completion == 0.0f ) {
    1942             sendFastHave( m, 0 );
    1943         } else if ( completion == 1.0f ) {
    1944             sendFastHave( m, 1 );
    1945         } else {
    1946             sendBitfield( m );
    1947         }
    1948     }
    19491922   
    19501923    tr_peerIoSetTimeoutSecs( m->io, 150 ); /* timeout after N seconds of inactivity */
Note: See TracChangeset for help on using the changeset viewer.