Changeset 12181


Ignore:
Timestamp:
Mar 17, 2011, 12:34:43 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) move tr_dhtUpkeep() out of the announcer module

During shutdown, we can stop DHT almost immediately, but need to leave the announcer running for the DHT tracker event=stopped messages. So it doesn't make sense to keep them on the same periodic timer.

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r12177 r12181  
    2929#include "ptrarray.h"
    3030#include "session.h"
    31 #include "tr-dht.h"
    3231#include "tr-lpd.h"
    3332#include "torrent.h"
     
    14951494
    14961495static void
    1497 dht_upkeep( tr_session * session )
    1498 {
    1499     tr_torrent * tor = NULL;
    1500     const time_t now = tr_time( );
    1501 
    1502     while(( tor = tr_torrentNext( session, tor )))
    1503     {
    1504         if( tor->dhtAnnounceAt <= now )
    1505         {
    1506             if( tor->isRunning && tr_torrentAllowsDHT(tor) ) {
    1507                 const int rc = tr_dhtAnnounce(tor, AF_INET, 1);
    1508                 if(rc == 0)
    1509                     /* The DHT is not ready yet. Try again soon. */
    1510                     tor->dhtAnnounceAt = now + 5 + tr_cryptoWeakRandInt( 5 );
    1511                 else
    1512                     /* We should announce at least once every 30 minutes. */
    1513                     tor->dhtAnnounceAt =
    1514                         now + 25 * 60 + tr_cryptoWeakRandInt( 3 * 60 );
    1515             }
    1516         }
    1517 
    1518         if( tor->dhtAnnounce6At <= now )
    1519         {
    1520             if( tor->isRunning && tr_torrentAllowsDHT(tor) ) {
    1521                 const int rc = tr_dhtAnnounce(tor, AF_INET6, 1);
    1522                 if(rc == 0)
    1523                     tor->dhtAnnounce6At = now + 5 + tr_cryptoWeakRandInt( 5 );
    1524                 else
    1525                     tor->dhtAnnounce6At =
    1526                         now + 25 * 60 + tr_cryptoWeakRandInt( 3 * 60 );
    1527             }
    1528         }
    1529     }
    1530 }
    1531 
    1532 static void
    15331496onUpkeepTimer( int foo UNUSED, short bar UNUSED, void * vannouncer )
    15341497{
     
    15421505    /* maybe send out some announcements to trackers */
    15431506    announceMore( announcer );
    1544 
    1545     dht_upkeep( announcer->session );
    15461507
    15471508    /* LPD upkeep */
  • trunk/libtransmission/session.c

    r12148 r12181  
    4444#include "stats.h"
    4545#include "torrent.h"
     46#include "tr-dht.h" /* tr_dhtUpkeep() */
    4647#include "tr-udp.h"
    4748#include "tr-utp.h"
     
    619620    tr_timeUpdate( time( NULL ) );
    620621
     622    tr_dhtUpkeep( session );
     623
    621624    if( session->turtle.isClockEnabled )
    622625        turtleCheckClock( session, &session->turtle );
  • trunk/libtransmission/tr-dht.c

    r12177 r12181  
    547547}
    548548
    549 int
     549static int
    550550tr_dhtAnnounce(tr_torrent *tor, int af, tr_bool announce)
    551551{
     
    591591
    592592void
     593tr_dhtUpkeep( tr_session * session )
     594{
     595    tr_torrent * tor = NULL;
     596    const time_t now = tr_time( );
     597
     598    while(( tor = tr_torrentNext( session, tor )))
     599    {
     600        if( !tor->isRunning || !tr_torrentAllowsDHT( tor ) )
     601            continue;
     602
     603        if( tor->dhtAnnounceAt <= now )
     604        {
     605            const int rc = tr_dhtAnnounce(tor, AF_INET, 1);
     606
     607            tor->dhtAnnounceAt = now + (rc == 0)
     608                                     ? 5 + tr_cryptoWeakRandInt( 5 )
     609                                     : 25 * 60 + tr_cryptoWeakRandInt( 3*60 );
     610        }
     611
     612        if( tor->dhtAnnounce6At <= now )
     613        {
     614            const int rc = tr_dhtAnnounce(tor, AF_INET6, 1);
     615
     616            tor->dhtAnnounce6At = now + (rc == 0)
     617                                      ? 5 + tr_cryptoWeakRandInt( 5 )
     618                                      : 25 * 60 + tr_cryptoWeakRandInt( 3*60 );
     619        }
     620    }
     621}
     622
     623void
    593624tr_dhtCallback(unsigned char *buf, int buflen,
    594625               struct sockaddr *from, socklen_t fromlen,
  • trunk/libtransmission/tr-dht.h

    r12096 r12181  
    4444const char *tr_dhtPrintableStatus(int status);
    4545int tr_dhtAddNode( tr_session *, const tr_address *, tr_port, tr_bool bootstrap );
    46 int tr_dhtAnnounce( tr_torrent *, int af, tr_bool announce );
     46void tr_dhtUpkeep( tr_session * );
    4747void tr_dhtCallback(unsigned char *buf, int buflen,
    4848                    struct sockaddr *from, socklen_t fromlen,
Note: See TracChangeset for help on using the changeset viewer.