Changeset 7931451


Ignore:
Timestamp:
Jun 3, 2009 7:05:55 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
cb488eb
Parents:
39e5ff7
Message:
  • Reseed: Limit to 200 per URL, shuffle selection, add some logging
File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/ReseedHandler.java

    r39e5ff7 r7931451  
    9292        public void run() {
    9393            _isRunning = true;
     94            System.out.println("Reseed start");
    9495            reseed(false);
    95             System.out.println("Reseeding complete");
     96            System.out.println("Reseed complete");
    9697            System.setProperty("net.i2p.router.web.ReseedHandler.reseedInProgress", "false");
    9798            _isRunning = false;
     
    134135
    135136        /**
    136          *  Fetch a directory listing and then all the routerInfo files in the listing.
     137         *  Fetch a directory listing and then up to 200 routerInfo files in the listing.
    137138         *  The listing must contain (exactly) strings that match:
    138139         *           href="routerInfo-{hash}.dat">
     
    148149                System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage","");
    149150                System.setProperty("net.i2p.router.web.ReseedHandler.statusMessage","Reseeding: fetching seed URL.");
     151                System.err.println("Reseed from " + seedURL);
    150152                URL dir = new URL(seedURL);
    151153                byte contentRaw[] = readURL(dir);
     
    161163                Set urls = new HashSet();
    162164                int cur = 0;
    163                 while (true) {
     165                int total = 0;
     166                while (total++ < 1000) {
    164167                    int start = content.indexOf("href=\"routerInfo-", cur);
    165168                    if (start < 0)
     
    171174                    cur = end + 1;
    172175                }
    173                 if (urls.size() <= 0) {
     176                if (total <= 0) {
    174177                    _log.error("Read " + contentRaw.length + " bytes from seed " + seedURL + ", but found no routerInfo URLs.");
    175178                    System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage",
     
    179182                }
    180183
     184                List urlList = new ArrayList(urls);
     185                Collections.shuffle(urlList);
    181186                int fetched = 0;
    182187                int errors = 0;
    183                 for (Iterator iter = urls.iterator(); iter.hasNext(); ) {
     188                // 200 max from one URL
     189                for (Iterator iter = urlList.iterator(); iter.hasNext() && fetched < 200; ) {
    184190                    try {
    185191                        System.setProperty("net.i2p.router.web.ReseedHandler.statusMessage",
    186192                            "Reseeding: fetching router info from seed URL (" +
    187                             fetched + " successful, " + errors + " errors, " + urls.size() + " total).");
     193                            fetched + " successful, " + errors + " errors, " + total + " total).");
    188194
    189195                        fetchSeed(seedURL, (String)iter.next());
     
    198204                    }
    199205                }
    200                 if (echoStatus) System.out.println();
     206                System.err.println("Reseed got " + fetched + " router infos from " + seedURL);
    201207               
    202                 int failPercent = 100 * errors / urls.size();
     208                int failPercent = 100 * errors / total;
    203209               
    204210                // Less than 10% of failures is considered success,
     
    206212                if ((failPercent >= 10) && (failPercent < 90)) {
    207213                    System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage",
    208                         "Last reseed failed partly (" + failPercent + "% of " + urls.size() + "). " +
     214                        "Last reseed failed partly (" + failPercent + "% of " + total + "). " +
    209215                        RESEED_TIPS);
    210216                }
    211217                if (failPercent >= 90) {
    212218                    System.setProperty("net.i2p.router.web.ReseedHandler.errorMessage",
    213                         "Last reseed failed (" + failPercent + "% of " + urls.size() + "). " +
     219                        "Last reseed failed (" + failPercent + "% of " + total + "). " +
    214220                        RESEED_TIPS);
    215221                }
    216222                // Don't go on to the next URL if we have enough
    217                 if (fetched > 25)
     223                if (fetched >= 100)
    218224                    _isRunning = false;
    219225            } catch (Throwable t) {
Note: See TracChangeset for help on using the changeset viewer.