Changeset 2772


Ignore:
Timestamp:
Aug 15, 2007, 9:26:24 PM (15 years ago)
Author:
joshe
Message:

Implement proposed extension to indicate which of azrueus or extended messaging are preferred.
This is disabled for now.

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer.c

    r2769 r2772  
    112112/* #define DISABLE_AZPROTO */
    113113
     114/* uncomment this to use the new reserved bits proposed here:
     115   http://www.azureuswiki.com/index.php/Extension_negotiation_protocol */
     116/* #define NEW_AZ_BITS */
     117
    114118#define HANDSHAKE_NAME          "\023BitTorrent protocol"
    115119#define HANDSHAKE_NAME_LEN      20
     
    120124#define HANDSHAKE_SIZE          ( HANDSHAKE_PEERID_OFF + TR_ID_LEN )
    121125
     126/* these macros test and set the bit indicating extended messaging support */
    122127#ifdef DISABLE_EXTMSGS
    123128#define HANDSHAKE_HAS_EXTMSGS( bits ) ( 0 )
     
    128133#endif
    129134
     135/* these macros test and set the bit indicating azureus protocol support */
    130136#ifdef DISABLE_AZPROTO
    131137#define HANDSHAKE_HAS_AZPROTO( bits ) ( 0 )
     
    135141#define HANDSHAKE_SET_AZPROTO( bits ) ( (bits)[0] |= 0x80 )
    136142#endif
     143
     144/* these macros are to be used if both extended messaging and the
     145   azureus protocol is supported, they indicate which protocol is preferred */
     146#ifdef NEW_AZ_BITS
     147#define HANDSHAKE_GET_EXTPREF( bits )      ( (bits)[5] & 0x03 )
     148#define HANDSHAKE_SET_EXTPREF( bits, val ) ( (bits)[5] |= 0x03 & (val) )
     149#else
     150#define HANDSHAKE_GET_EXTPREF( bits )      ( 0 )
     151#define HANDSHAKE_SET_EXTPREF( bits, val ) ( (void)0 )
     152#endif
     153#define HANDSHAKE_EXTPREF_FORCE_EXT        ( 0x00 )
     154#define HANDSHAKE_EXTPREF_WANT_EXT         ( 0x01 )
     155#define HANDSHAKE_EXTPREF_WANT_AZ          ( 0x10 )
     156#define HANDSHAKE_EXTPREF_FORCE_AZ         ( 0x11 )
    137157
    138158#define PEER_MSG_CHOKE          0
     
    559579        HANDSHAKE_SET_EXTMSGS( buf + HANDSHAKE_FLAGS_OFF );
    560580        HANDSHAKE_SET_AZPROTO( buf + HANDSHAKE_FLAGS_OFF );
     581        HANDSHAKE_SET_EXTPREF( buf + HANDSHAKE_FLAGS_OFF,
     582                               HANDSHAKE_EXTPREF_WANT_EXT );
    561583        memcpy( buf + HANDSHAKE_HASH_OFF, inf->hash, SHA_DIGEST_LENGTH );
    562584        memcpy( buf + HANDSHAKE_PEERID_OFF, tor->peer_id, TR_ID_LEN );
  • trunk/libtransmission/peerparse.h

    r2769 r2772  
    604604{
    605605    tr_info_t * inf = &tor->info;
    606     int         ii;
     606    int         ii, extmsgs, azproto;
     607    char      * dbgsup, * dbgwant;
    607608
    608609    if( 0 != memcmp( peer->buf + HANDSHAKE_HASH_OFF, inf->hash,
     
    636637    }
    637638
     639    extmsgs = 0;
     640    azproto = 0;
     641    dbgsup  = "";
     642    dbgwant = "";
     643
    638644    if( HANDSHAKE_HAS_EXTMSGS( peer->buf + HANDSHAKE_FLAGS_OFF ) )
     645    {
     646        dbgsup = " extended messaging supported";
     647        extmsgs = 1;
     648    }
     649    if( HANDSHAKE_HAS_AZPROTO( peer->buf + HANDSHAKE_FLAGS_OFF ) )
     650    {
     651        dbgsup = " will use azureus protocol";
     652        azproto = 1;
     653    }
     654    if( extmsgs && azproto )
     655    {
     656        dbgsup = " both extended and azureus messaging supported";
     657        switch( HANDSHAKE_GET_EXTPREF( peer->buf + HANDSHAKE_FLAGS_OFF ) )
     658        {
     659            case HANDSHAKE_EXTPREF_FORCE_EXT:
     660                dbgwant = ", peer forces extended";
     661                azproto = 0;
     662                break;
     663            case HANDSHAKE_EXTPREF_WANT_EXT:
     664                dbgwant = ", peer prefers extended";
     665                azproto = 0;
     666                break;
     667            case HANDSHAKE_EXTPREF_WANT_AZ:
     668                dbgwant = ", peer prefers azureus";
     669                extmsgs = 0;
     670                break;
     671            case HANDSHAKE_EXTPREF_FORCE_AZ:
     672                dbgwant = ", peer forces azureus";
     673                extmsgs = 0;
     674                break;
     675        }
     676    }
     677    assert( !extmsgs || !azproto );
     678
     679    if( extmsgs )
    639680    {
    640681        peer->status = PEER_STATUS_CONNECTED;
    641682        peer->extStatus = EXTENDED_SUPPORTED;
    642         peer_dbg( "GET  handshake, ok (%s) extended messaging supported",
    643                   tr_peerClient( peer ) );
    644     }
    645     else if( HANDSHAKE_HAS_AZPROTO( peer->buf + HANDSHAKE_FLAGS_OFF ) )
     683    }
     684    else if( azproto )
    646685    {
    647686        peer->status  = PEER_STATUS_AZ_GIVER;
    648687        peer->azproto = 1;
    649688        peer->date    = tr_date();
    650         peer_dbg( "GET  handshake, ok (%s) will use azureus protocol",
    651                   tr_peerClient( peer ) );
    652689    }
    653690    else
    654691    {
    655692        peer->status = PEER_STATUS_CONNECTED;
    656         peer_dbg( "GET  handshake, ok (%s)", tr_peerClient( peer ) );
    657     }
     693    }
     694    peer_dbg( "GET  handshake, ok (%s)%s%s",
     695              tr_peerClient( peer ), dbgsup, dbgwant );
    658696
    659697    return TR_OK;
Note: See TracChangeset for help on using the changeset viewer.