Changeset 8985


Ignore:
Timestamp:
Aug 22, 2009, 4:21:13 PM (13 years ago)
Author:
charles
Message:

(trunk third-party) #2302: revert from dht 0.8 to 0.6 for Transmission 1.74. 0.8 reportedly adds a new crasher <http://forum.transmissionbt.com/viewtopic.php?p=39773#p39773>

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r8979 r8985  
    33==== All Platforms ====
    44  * Better data recovery in the case of an OS or Transmission crash
    5   * Upgrade DHT to version 0.8
    65  * If a data file is moved, stop the torrent instead of redownloading it
    76  * Fix bug that didn't list some peers in the resume file and in PEX
  • trunk/third-party/dht/CHANGES

    r8884 r8985  
    1 dht-0.9 (unreleased):
    2 
    3   * Fixed a typo in dht_nodes.
    4 
    5 28 July 2009: dht-0.8
    6 
    7   * Fixed a crash when expiring the first search on the list.
    8   * Fixed freeing of the search list when uniniting with dofree = 1.
    9 
    10 24 June 2009: dht-0.7
    11 
    12   * Removed the fixed limit on the number of concurrent searches, we now
    13     use a linked list.
    14   * Fixed build on FreeBSD (thanks to Humihara and Charles Kerr).
    15 
    16122 May 2009: dht-0.6
    172
  • trunk/third-party/dht/README

    r8860 r8985  
    9494This schedules a search for information about the info-hash specified in
    9595id.  If port is not 0, it specifies the TCP port on which the current peer
    96 is listening; in that case, when the search is complete it will be announced
     96is litening; in that case, when the search is complete it will be announced
    9797to the network.  The port is in host order, beware if you got it from
    9898a struct sockaddr_in.
     
    102102additionally be called when the search is complete.
    103103
    104 Up to DHT_MAX_SEARCHES (1024) searches can be in progress at a given time;
     104Up to DHT_MAX_SEARCHES (20) searches can be in progress at a given time;
    105105any more, and dht_search will return -1.  If you specify a new search for
    106106the same info hash as a search still in progress, the previous search is
     
    124124firewalled.
    125125
    126 If you want to display a single figure to the user, you should display
    127 good + doubtful, which is the total number of nodes in your routing table.
    128 Some clients try to estimate the total number of nodes, but this doesn't
    129 make much sense -- since the result is exponential in the number of nodes
    130 in the routing table, small variations in the latter cause huge jumps in
    131 the former.
     126If you want to display a single figure to the user, you should display good
     127+ doubtful, which is the total number of nodes in your routing table.  Some
     128clients try to estimate the total number of nodes, but this doesn't make
     129much sense -- since the result is exponential in the number of nodes in the
     130routing table, small variations in the latter cause huge jumps in the
     131former.
    132132
    133133* dht_get_nodes
     
    187187keep both pieces.
    188188
     189There is currently no good way to save and restore your routing table.
     190
    189191IPv6 support is deliberately not included: designing a double-stack
    190192distributed hash table raises some tricky issues, and doing it naively may
  • trunk/third-party/dht/dht.c

    r8884 r8985  
    123123    struct search_node nodes[SEARCH_NODES];
    124124    int numnodes;
    125     struct search *next;
    126125};
    127126
     
    135134#ifndef DHT_MAX_PEERS
    136135#define DHT_MAX_PEERS 2048
    137 #endif
    138 
    139 /* The maximum number of searches we keep data about. */
    140 #ifndef DHT_MAX_SEARCHES
    141 #define DHT_MAX_SEARCHES 1024
    142 #endif
    143 
    144 /* The time after which we consider a search to be expirable. */
    145 #ifndef DHT_SEARCH_EXPIRE_TIME
    146 #define DHT_SEARCH_EXPIRE_TIME (62 * 60)
    147136#endif
    148137
     
    219208static struct storage *storage;
    220209
    221 static struct search *searches = NULL;
     210/* The maximum number of concurrent searches. */
     211#ifndef DHT_MAX_SEARCHES
     212#define DHT_MAX_SEARCHES 20
     213#endif
     214
     215static struct search searches[DHT_MAX_SEARCHES];
    222216static int numsearches;
    223217static unsigned short search_id;
     
    731725find_search(unsigned short tid)
    732726{
    733     struct search *sr = searches;
    734     while(sr) {
    735         if(sr->tid == tid)
    736             return sr;
    737         sr = sr->next;
     727    int i;
     728    for(i = 0; i < numsearches; i++) {
     729        if(searches[i].tid == tid)
     730            return &searches[i];
    738731    }
    739732    return NULL;
     
    804797        sr->nodes[j] = sr->nodes[j + 1];
    805798    sr->numnodes--;
    806 }
    807 
    808 static void
    809 expire_searches(void)
    810 {
    811     struct search *sr = searches, *previous = NULL;
    812 
    813     while(sr) {
    814         struct search *next = sr->next;
    815         if(sr->step_time < now.tv_sec - DHT_SEARCH_EXPIRE_TIME) {
    816             if(previous)
    817                 previous->next = next;
    818             else
    819                 searches = next;
    820             free(sr);
    821             numsearches--;
    822         } else {
    823             previous = sr;
    824         }
    825         sr = next;
    826     }
    827799}
    828800
     
    938910
    939911static struct search *
    940 new_search(void)
    941 {
    942     struct search *sr, *oldest = NULL;
    943 
    944     /* Find the oldest done search */
    945     sr = searches;
    946     while(sr) {
    947         if(sr->done &&
    948            (oldest == NULL || oldest->step_time > sr->step_time))
    949             oldest = sr;
    950         sr = sr->next;
    951     }
    952 
    953     /* The oldest slot is expired. */
    954     if(oldest && oldest->step_time < now.tv_sec - DHT_SEARCH_EXPIRE_TIME)
    955         return oldest;
    956 
    957     /* Allocate a new slot. */
    958     if(numsearches < DHT_MAX_SEARCHES) {
    959         sr = calloc(1, sizeof(struct search));
    960         if(sr != NULL) {
    961             sr->next = searches;
    962             searches = sr;
    963             numsearches++;
    964             return sr;
    965         }
    966     }
    967 
    968     /* Oh, well, never mind.  Reuse the oldest slot. */
    969     return oldest;
     912find_free_search_slot(void)
     913{
     914    int i;
     915    struct search *sr = NULL;
     916
     917    if(numsearches < DHT_MAX_SEARCHES)
     918        return &searches[numsearches++];
     919
     920    for(i = 0; i < numsearches; i++) {
     921        if(searches[i].done &&
     922           (sr == NULL || searches[i].step_time < sr->step_time))
     923            sr = &searches[i];
     924    }
     925    return sr;
    970926}
    971927
     
    990946    struct search *sr;
    991947    struct bucket *b;
    992 
    993     sr = searches;
    994     while(sr) {
    995         if(id_cmp(sr->id, id) == 0)
     948    int i;
     949
     950    for(i = 0; i < numsearches; i++) {
     951        if(id_cmp(searches[i].id, id) == 0)
    996952            break;
    997         sr = sr->next;
    998     }
    999 
    1000     if(sr) {
     953    }
     954
     955    if(i < numsearches) {
    1001956        /* We're reusing data from an old search.  Reusing the same tid
    1002957           means that we can merge replies for both searches. */
    1003         int i;
     958        int j;
     959        sr = searches + i;
    1004960        sr->done = 0;
    1005961    again:
    1006         for(i = 0; i < sr->numnodes; i++) {
     962        for(j = 0; j < sr->numnodes; j++) {
    1007963            struct search_node *n;
    1008             n = &sr->nodes[i];
     964            n = &sr->nodes[j];
    1009965            /* Discard any doubtful nodes. */
    1010966            if(n->pinged >= 3 || n->reply_time < now.tv_sec - 7200) {
     
    1018974        }
    1019975    } else {
    1020         sr = new_search();
     976        sr = find_free_search_slot();
    1021977        if(sr == NULL) {
    1022978            errno = ENOSPC;
    1023979            return -1;
    1024980        }
     981        memset(sr, 0, sizeof(struct search));
    1025982        sr->tid = search_id++;
    1026         sr->step_time = 0;
    1027983        memcpy(sr->id, id, 20);
    1028         sr->done = 0;
    1029984        sr->numnodes = 0;
    1030985    }
     
    11531108broken_node(int s, const unsigned char *id, struct sockaddr_in *sin)
    11541109{
    1155     int i;
     1110    int i, j;
    11561111
    11571112    debugf("Blacklisting broken node.\n");
    11581113
    11591114    if(id) {
     1115        /* Make the node easy to discard. */
    11601116        struct node *n;
    1161         struct search *sr;
    1162         /* Make the node easy to discard. */
    11631117        n = find_node(id);
    11641118        if(n) {
     
    11671121        }
    11681122        /* Discard it from any searches in progress. */
    1169         sr = searches;
    1170         while(sr) {
    1171             for(i = 0; i < sr->numnodes; i++)
    1172                 if(id_cmp(sr->nodes[i].id, id) == 0)
    1173                     flush_search_node(&sr->nodes[i], sr);
    1174             sr = sr->next;
     1123        for(i = 0; i < numsearches; i++) {
     1124            for(j = 0; j < searches[i].numnodes; j++)
     1125                if(id_cmp(searches[i].nodes[j].id, id) == 0)
     1126                    flush_search_node(&searches[i].nodes[j],
     1127                                      &searches[i]);
    11751128        }
    11761129    }
     
    12541207        *cached_return = cached;
    12551208    if(incoming_return)
    1256         *incoming_return = incoming;
     1209        *incoming_return = cached;
    12571210    return good + dubious;
    12581211}
     
    12621215dht_dump_tables(FILE *f)
    12631216{
    1264     int i;
     1217    int i, j;
    12651218    struct bucket *b = buckets;
    12661219    struct storage *st = storage;
    1267     struct search *sr = searches;
    12681220
    12691221    fprintf(f, "My id ");
     
    12991251        b = b->next;
    13001252    }
    1301     while(sr) {
    1302         fprintf(f, "\nSearch id ");
     1253    for(i = 0; i < numsearches; i++) {
     1254        struct search *sr = &searches[i];
     1255        fprintf(f, "\nSearch %d id ", i);
    13031256        print_hex(f, sr->id, 20);
    13041257        fprintf(f, " age %d%s\n", (int)(now.tv_sec - sr->step_time),
    13051258               sr->done ? " (done)" : "");
    1306         for(i = 0; i < sr->numnodes; i++) {
    1307             struct search_node *n = &sr->nodes[i];
    1308             fprintf(f, "Node %d id ", i);
     1259        for(j = 0; j < sr->numnodes; j++) {
     1260            struct search_node *n = &sr->nodes[j];
     1261            fprintf(f, "Node %d id ", j);
    13091262            print_hex(f, n->id, 20);
    13101263            fprintf(f, " bits %d age ", common_bits(sr->id, n->id));
     
    13181271                   n->replied ? " (replied)" : "");
    13191272        }
    1320         sr = sr->next;
    13211273    }
    13221274
     
    13541306        return -1;
    13551307
    1356     searches = NULL;
    13571308    numsearches = 0;
    13581309
     
    14271378        free(st);
    14281379    }
    1429 
    1430     while(searches) {
    1431         struct search *sr = searches;
    1432         searches = searches->next;
    1433         free(sr);
    1434     }
    1435 
     1380   
    14361381    return 1;
    14371382}
     
    17101655        expire_buckets(s);
    17111656        expire_storage();
    1712         expire_searches();
    17131657    }
    17141658
    17151659    if(search_time > 0 && now.tv_sec >= search_time) {
    1716         struct search *sr;
    1717         sr = searches;
    1718         while(sr) {
     1660        int i;
     1661        for(i = 0; i < numsearches; i++) {
     1662            struct search *sr = &searches[i];
    17191663            if(!sr->done && sr->step_time + 5 <= now.tv_sec) {
    17201664                search_step(s, sr, callback, closure);
    17211665            }
    1722             sr = sr->next;
    17231666        }
    17241667                   
    17251668        search_time = 0;
    1726 
    1727         sr = searches;
    1728         while(sr) {
     1669       
     1670        for(i = 0; i < numsearches; i++) {
     1671            struct search *sr = &searches[i];
    17291672            if(!sr->done) {
    17301673                time_t tm = sr->step_time + 15 + random() % 10;
     
    17321675                    search_time = tm;
    17331676            }
    1734             sr = sr->next;
    17351677        }
    17361678    }
Note: See TracChangeset for help on using the changeset viewer.