Changeset 3188


Ignore:
Timestamp:
Sep 26, 2007, 5:34:33 PM (14 years ago)
Author:
charles
Message:

only send a peer keepalive messages when we're not sending them anything else

File:
1 edited

Legend:

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

    r3185 r3188  
    6464    MAX_REQUEST_BYTE_COUNT  = (16 * 1024), /* drop requests who want too much */
    6565
    66     KEEPALIVE_INTERVAL      = (90 * 1000), /* msec between calls to sendKeepalive() */
     66    KEEPALIVE_INTERVAL_SECS = 90,          /* idle seconds before we send a keepalive */
    6767    PEX_INTERVAL            = (60 * 1000), /* msec between calls to sendPex() */
    6868    PEER_PULSE_INTERVAL     = (100),       /* msec between calls to pulse() */
     
    113113    tr_timer * pulseTimer;
    114114    tr_timer * pexTimer;
    115     tr_timer * keepaliveTimer;
    116115
    117116    struct peer_request blockToUs; /* the block currntly being sent to us */
     
    119118    time_t lastReqAddedAt;
    120119    time_t clientSentPexAt;
     120    time_t clientSentAnythingAt;
    121121
    122122    unsigned int notListening          : 1;
     
    990990}
    991991
     992static void
     993sendKeepalive( tr_peermsgs * msgs )
     994{
     995    dbgmsg( msgs, "sending a keepalive message" );
     996    tr_peerIoWriteUint32( msgs->io, msgs->outMessages, 0 );
     997}
     998
    992999/**
    9931000***
     
    10241031pulse( void * vmsgs )
    10251032{
     1033    const time_t now = time( NULL );
    10261034    tr_peermsgs * msgs = (tr_peermsgs *) vmsgs;
    10271035    size_t len;
     
    10481056            peerGotBytes( msgs, outlen );
    10491057            len -= outlen;
    1050             msgs->info->clientSentPieceDataAt = time( NULL );
     1058            msgs->info->clientSentPieceDataAt = now;
     1059            msgs->clientSentAnythingAt = now;
    10511060            dbgmsg( msgs, "wrote %d bytes; %d left in block", (int)outlen, (int)len );
    10521061        }
     
    10551064    {
    10561065        tr_peerIoWriteBuf( msgs->io, msgs->outMessages );
     1066        msgs->clientSentAnythingAt = now;
    10571067    }
    10581068    else if(( msgs->peerAskedFor ))
     
    10711081        tr_free( req );
    10721082    }
     1083    else if( ( now - msgs->clientSentAnythingAt ) > KEEPALIVE_INTERVAL_SECS )
     1084    {
     1085        sendKeepalive( msgs );
     1086    }
    10731087
    10741088    return TRUE; /* loop forever */
     
    10961110    tr_peerIoWriteUint8 ( msgs->io, msgs->outMessages, BT_BITFIELD );
    10971111    tr_peerIoWriteBytes ( msgs->io, msgs->outMessages, bitfield->bits, bitfield->len );
    1098 }
    1099 
    1100 static void
    1101 sendKeepalive( tr_peermsgs * msgs )
    1102 {
    1103     dbgmsg( msgs, "sending a keepalive message" );
    1104     tr_peerIoWriteUint32( msgs->io, msgs->outMessages, 0 );
    11051112}
    11061113
     
    12521259}
    12531260
    1254 static int
    1255 keepalivePulse( void * vpeer )
    1256 {
    1257     sendKeepalive( vpeer );
    1258     return TRUE;
    1259 }
    1260 
    12611261/**
    12621262***
     
    12841284    msgs->pulseTimer = tr_timerNew( msgs->handle, pulse, msgs, PEER_PULSE_INTERVAL );
    12851285    msgs->pexTimer = tr_timerNew( msgs->handle, pexPulse, msgs, PEX_INTERVAL );
    1286     msgs->keepaliveTimer = tr_timerNew( msgs->handle, keepalivePulse, msgs, KEEPALIVE_INTERVAL );
    12871286    msgs->outMessages = evbuffer_new( );
    12881287    msgs->outBlock = evbuffer_new( );
     
    13191318    if( msgs != NULL )
    13201319    {
    1321         tr_timerFree( &msgs->keepaliveTimer );
    13221320        tr_timerFree( &msgs->pulseTimer );
    13231321        tr_timerFree( &msgs->pexTimer );
Note: See TracChangeset for help on using the changeset viewer.