Changeset 8435


Ignore:
Timestamp:
May 19, 2009, 7:05:34 PM (12 years ago)
Author:
charles
Message:

(trunk libT) add Juliusz' provide-node-count.patch patch

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tr-dht.c

    r8433 r8435  
    8585        /* There's no race here -- if we uninit between the test and the
    8686           AddNode, the AddNode will be ignored. */
    87         status = tr_dhtStatus(cl->session);
     87        status = tr_dhtStatus(cl->session, NULL);
    8888        if(status == TR_DHT_STOPPED || status >= TR_DHT_FIREWALLED)
    8989            break;
     
    208208    /* Since we only save known good nodes, avoid erasing older data if we
    209209       don't know enough nodes. */
    210     if(tr_dhtStatus(ss) >= TR_DHT_FIREWALLED) {
     210    if(tr_dhtStatus(ss, NULL) >= TR_DHT_FIREWALLED) {
    211211        tr_benc benc;
    212212        struct sockaddr_in sins[300];
     
    237237tr_dhtEnabled(tr_session *ss)
    238238{
    239     return (ss && session == ss);
    240 }
     239    return ss && ss == session;
     240}
     241
     242struct getstatus_closure
     243{
     244    sig_atomic_t status;
     245    sig_atomic_t count;
     246};
    241247
    242248static void
    243249getstatus(void *closure)
    244250{
    245     sig_atomic_t *ret = (sig_atomic_t*)closure;
     251    struct getstatus_closure *ret = (struct getstatus_closure*)closure;
    246252    int good, dubious, incoming;
    247253
    248254    dht_nodes(&good, &dubious, NULL, &incoming);
    249     if(good < 4 || good + dubious <= 8)
    250         *ret = TR_DHT_BROKEN;
    251     else if(good < 40)
    252         *ret = TR_DHT_POOR;
    253     else if(incoming < 8)
    254         *ret = TR_DHT_FIREWALLED;
     255
     256    if( good < 4 || good + dubious <= 8 )
     257        ret->status = TR_DHT_BROKEN;
     258    else if( good < 40 )
     259        ret->status = TR_DHT_POOR;
     260    else if( incoming < 8 )
     261        ret->status = TR_DHT_FIREWALLED;
    255262    else
    256         *ret = TR_DHT_GOOD;
     263        ret->status = TR_DHT_GOOD;
     264
     265    ret->count = good + dubious;
    257266}
    258267
    259268int
    260 tr_dhtStatus(tr_session *ss)
    261 {
    262     sig_atomic_t ret = -1;
    263 
    264     if(!tr_dhtEnabled(ss))
     269tr_dhtStatus(tr_session *ss, int *nodes_return )
     270{
     271    struct getstatus_closure ret = { -1, - 1 };
     272
     273    if( !tr_dhtEnabled( ss ) )
    265274        return TR_DHT_STOPPED;
    266275
    267     tr_runInEventThread(ss, getstatus, &ret);
    268     while( ret < 0 )
    269         tr_wait( 1 /* msec */ );
    270 
    271     return ret;
     276    tr_runInEventThread( ss, getstatus, &ret );
     277    while( ret.status < 0 )
     278        tr_wait( 10 /*msec*/ );
     279
     280    if( nodes_return )
     281        *nodes_return = ret.count;
     282
     283    return ret.status;
    272284}
    273285
     
    283295    struct sockaddr_in sin;
    284296
    285     if(!tr_dhtEnabled(ss))
     297    if( !tr_dhtEnabled( ss ) )
    286298        return 0;
    287299
    288     if(address->type != TR_AF_INET)
     300    if( address->type != TR_AF_INET )
    289301        return 0;
    290302
     
    292304       if the DHT is in a good state. */
    293305    if(bootstrap) {
    294         if(tr_dhtStatus(ss) >= TR_DHT_FIREWALLED)
     306        if(tr_dhtStatus(ss, NULL) >= TR_DHT_FIREWALLED)
    295307            return 0;
    296308    }
     
    329341        tr_free(pex);
    330342    } else if(event == DHT_EVENT_SEARCH_DONE) {
    331         tr_torrent *tor;
    332         tor = tr_torrentFindFromHash(session, info_hash);
     343        tr_torrent * tor = tr_torrentFindFromHash( session, info_hash );
    333344        if(tor)
    334345            tor->dhtAnnounceInProgress = 0;
     
    339350tr_dhtAnnounce(tr_torrent *tor, tr_bool announce)
    340351{
    341     if(!tr_torrentAllowsDHT(tor))
     352    if( !tr_torrentAllowsDHT( tor ) )
    342353        return -1;
    343354
    344     if(tr_dhtStatus(tor->session) < TR_DHT_POOR)
     355    if( tr_dhtStatus( tor->session, NULL ) < TR_DHT_POOR )
    345356        return 0;
    346357
    347     dht_search(dht_socket, tor->info.hash,
    348                announce ? tr_sessionGetPeerPort(session) : 0,
    349                callback, NULL);
    350 
    351     tor->dhtAnnounceInProgress = 1;
    352 
     358    dht_search( dht_socket, tor->info.hash,
     359                announce ? tr_sessionGetPeerPort(session) : 0,
     360                callback, NULL);
     361
     362    tor->dhtAnnounceInProgress = TRUE;
    353363    return 1;
    354364}
  • trunk/libtransmission/tr-dht.h

    r8433 r8435  
    3030void tr_dhtUninit(tr_session *ss);
    3131tr_bool tr_dhtEnabled(tr_session *ss);
    32 int tr_dhtStatus(tr_session *ss);
     32int tr_dhtStatus(tr_session *ss, int * setme_nodeCount );
    3333tr_port tr_dhtPort(tr_session *ss);
    3434int tr_dhtAddNode(tr_session *ss, tr_address *address, tr_port port, tr_bool bootstrap);
Note: See TracChangeset for help on using the changeset viewer.