Changeset 3185


Ignore:
Timestamp:
Sep 26, 2007, 3:14:37 PM (14 years ago)
Author:
charles
Message:

for every connected peer, send a keepalive message every 90 seconds

File:
1 edited

Legend:

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

    r3184 r3185  
    3939**/
    4040
    41 #define PEX_INTERVAL (60 * 1000)
    42 
    43 #define PEER_PULSE_INTERVAL (100)
    44 
    4541enum
    4642{
    47     BT_CHOKE                  = 0,
    48     BT_UNCHOKE                = 1,
    49     BT_INTERESTED             = 2,
    50     BT_NOT_INTERESTED         = 3,
    51     BT_HAVE                   = 4,
    52     BT_BITFIELD               = 5,
    53     BT_REQUEST                = 6,
    54     BT_PIECE                  = 7,
    55     BT_CANCEL                 = 8,
    56     BT_PORT                   = 9,
    57     BT_SUGGEST                = 13,
    58     BT_HAVE_ALL               = 14,
    59     BT_HAVE_NONE              = 15,
    60     BT_REJECT                 = 16,
    61     BT_ALLOWED_FAST           = 17,
    62     BT_LTEP                   = 20,
    63 
    64     LTEP_HANDSHAKE            = 0,
    65 
    66     OUR_LTEP_PEX              = 1,
    67 
    68     /* disregard requests that want more than this many bytes.
    69        it's common practice in for BT clients to use a 16K threshold */
    70     MAX_REQUEST_BYTE_COUNT    = (16 * 1024)
     43    BT_CHOKE                = 0,
     44    BT_UNCHOKE              = 1,
     45    BT_INTERESTED           = 2,
     46    BT_NOT_INTERESTED       = 3,
     47    BT_HAVE                 = 4,
     48    BT_BITFIELD             = 5,
     49    BT_REQUEST              = 6,
     50    BT_PIECE                = 7,
     51    BT_CANCEL               = 8,
     52    BT_PORT                 = 9,
     53    BT_SUGGEST              = 13,
     54    BT_HAVE_ALL             = 14,
     55    BT_HAVE_NONE            = 15,
     56    BT_REJECT               = 16,
     57    BT_ALLOWED_FAST         = 17,
     58    BT_LTEP                 = 20,
     59
     60    LTEP_HANDSHAKE          = 0,
     61
     62    OUR_LTEP_PEX            = 1,
     63
     64    MAX_REQUEST_BYTE_COUNT  = (16 * 1024), /* drop requests who want too much */
     65
     66    KEEPALIVE_INTERVAL      = (90 * 1000), /* msec between calls to sendKeepalive() */
     67    PEX_INTERVAL            = (60 * 1000), /* msec between calls to sendPex() */
     68    PEER_PULSE_INTERVAL     = (100),       /* msec between calls to pulse() */
    7169};
    7270
     
    115113    tr_timer * pulseTimer;
    116114    tr_timer * pexTimer;
     115    tr_timer * keepaliveTimer;
    117116
    118117    struct peer_request blockToUs; /* the block currntly being sent to us */
     
    10931092    const tr_bitfield * bitfield = tr_cpPieceBitfield( msgs->torrent->completion );
    10941093
    1095     dbgmsg( msgs, "sending peer a bitfield message\n", msgs );
     1094    dbgmsg( msgs, "sending peer a bitfield message" );
    10961095    tr_peerIoWriteUint32( msgs->io, msgs->outMessages, sizeof(uint8_t) + bitfield->len );
    10971096    tr_peerIoWriteUint8 ( msgs->io, msgs->outMessages, BT_BITFIELD );
    10981097    tr_peerIoWriteBytes ( msgs->io, msgs->outMessages, bitfield->bits, bitfield->len );
     1098}
     1099
     1100static void
     1101sendKeepalive( tr_peermsgs * msgs )
     1102{
     1103    dbgmsg( msgs, "sending a keepalive message" );
     1104    tr_peerIoWriteUint32( msgs->io, msgs->outMessages, 0 );
    10991105}
    11001106
     
    12461252}
    12471253
     1254static int
     1255keepalivePulse( void * vpeer )
     1256{
     1257    sendKeepalive( vpeer );
     1258    return TRUE;
     1259}
     1260
    12481261/**
    12491262***
     
    12711284    msgs->pulseTimer = tr_timerNew( msgs->handle, pulse, msgs, PEER_PULSE_INTERVAL );
    12721285    msgs->pexTimer = tr_timerNew( msgs->handle, pexPulse, msgs, PEX_INTERVAL );
     1286    msgs->keepaliveTimer = tr_timerNew( msgs->handle, keepalivePulse, msgs, KEEPALIVE_INTERVAL );
    12731287    msgs->outMessages = evbuffer_new( );
    12741288    msgs->outBlock = evbuffer_new( );
     
    13051319    if( msgs != NULL )
    13061320    {
     1321        tr_timerFree( &msgs->keepaliveTimer );
    13071322        tr_timerFree( &msgs->pulseTimer );
    13081323        tr_timerFree( &msgs->pexTimer );
Note: See TracChangeset for help on using the changeset viewer.