Changeset 523d39b


Ignore:
Timestamp:
Aug 15, 2012 12:44:46 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
442af03
Parents:
44edf70
Message:
  • i2psnark:
    • Fix bug preventing completion announcement, broken in 0.9.1
    • Fix setting short retry time after initial announce failure
    • Fix DHT announce and getPeers
    • Fix DHT warning message
    • log tweaks
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java

    r44edf70 r523d39b  
    829829                            addMessage(_("Warning - No I2P trackers in \"{0}\", will announce to I2P open trackers and DHT only.", info.getName()));
    830830                            //addMessage(_("Warning - No I2P trackers in \"{0}\", will announce to I2P open trackers only.", info.getName()));
    831                         } else if (_util.getDHT() != null) {
     831                        } else if (_util.shouldUseDHT()) {
    832832                            addMessage(_("Warning - No I2P trackers in \"{0}\", and open trackers are disabled, will announce to DHT only.", info.getName()));
    833833                        } else {
  • apps/i2psnark/java/src/org/klomp/snark/TrackerClient.java

    r44edf70 r523d39b  
    2828import java.net.URL;
    2929import java.util.ArrayList;
     30import java.util.Collection;
    3031import java.util.Collections;
    3132import java.util.Date;
     
    101102  private volatile boolean runStarted;
    102103  private volatile  int consecutiveFails;
     104  private boolean completed;
    103105  private volatile boolean _fastUnannounce;
    104106
     
    219221          if (!_initialized) {
    220222              setup();
    221               // FIXME dht
    222               if (trackers.isEmpty()) {
    223                   stop = true;
    224                   return;
    225               }
     223          }
     224          if (trackers.isEmpty() && _util.getDHT() == null) {
     225              stop = true;
     226              this.snark.addMessage(_util.getString("No valid trackers for {0} - enable opentrackers or DHT?",
     227                                              this.snark.getBaseName()));
     228              _log.error("No valid trackers for " + this.snark.getBaseName());
     229              this.snark.stopTorrent();
     230              return;
     231          }
     232          if (!_initialized) {
    226233              _initialized = true;
    227234              // FIXME only when starting everybody at once, not for a single torrent
     
    297304        }
    298305    }
    299 
    300     if (trackers.isEmpty() && _util.getDHT() == null) {
    301         stop = true;
    302         this.snark.addMessage(_util.getString("No valid trackers for {0} - enable opentrackers or DHT?",
    303                                               this.snark.getBaseName()));
    304         _log.error("No valid trackers for " + this.snark.getBaseName());
    305         this.snark.stopTorrent();
    306         return;
    307     }
     306    this.completed = coordinator.getLeft() == 0;
    308307  }
    309308
     
    332331            long downloaded = coordinator.getDownloaded();
    333332            long left = coordinator.getLeft();   // -1 in magnet mode
    334             boolean completed = (left == 0);
    335333           
    336334            // First time we got a complete download?
     
    346344            // *** loop once for each tracker
    347345            int maxSeenPeers = 0;
    348             for (Iterator iter = trackers.iterator(); iter.hasNext(); ) {
    349               Tracker tr = (Tracker)iter.next();
     346            for (Tracker tr : trackers) {
    350347              if ((!stop) && (!tr.stop) &&
    351348                  (completed || coordinator.needOutboundPeers() || !tr.started) &&
     
    469466                else
    470467                    numwant = _util.getMaxConnections();
    471                 List<Hash> hashes = dht.getPeers(snark.getInfoHash(), numwant, 2*60*1000);
     468                Collection<Hash> hashes = dht.getPeers(snark.getInfoHash(), numwant, 2*60*1000);
     469                if (!hashes.isEmpty())
     470                    runStarted = true;
    472471                if (_log.shouldLog(Log.INFO))
    473472                    _log.info("Got " + hashes + " from DHT");
     
    510509                return;
    511510
    512             if (!runStarted)
    513                 if (_log.shouldLog(Log.DEBUG))
    514                     _log.debug("         Retrying in one minute...");
    515 
    516511            try {
    517512                // Sleep some minutes...
     
    522517                  delay = 3*SLEEP*60*1000 + random;
    523518                else if (snark.getTrackerProblems() != null && ++consecutiveFails < MAX_CONSEC_FAILS)
     519                  delay = INITIAL_SLEEP;
     520                else if ((!runStarted) && _runCount < MAX_CONSEC_FAILS)
    524521                  delay = INITIAL_SLEEP;
    525522                else
  • apps/i2psnark/java/src/org/klomp/snark/dht/DHT.java

    r44edf70 r523d39b  
    55 */
    66
    7 import java.util.List;
     7import java.util.Collection;
    88
    99import net.i2p.data.Destination;
     
    4343     *  @param max maximum number of peers to return
    4444     *  @param maxWait the maximum time to wait (ms) must be > 0
    45      *  @return list or empty list (never null)
     45     *  @return possibly empty (never null)
    4646     */
    47     public List<Hash> getPeers(byte[] ih, int max, long maxWait);
     47    public Collection<Hash> getPeers(byte[] ih, int max, long maxWait);
    4848
    4949    /**
  • apps/i2psnark/java/src/org/klomp/snark/dht/KRPC.java

    r44edf70 r523d39b  
    300300     *  @param max maximum number of peers to return
    301301     *  @param maxWait the maximum time to wait (ms) must be > 0
    302      *  @return list or empty list (never null)
    303      */
    304     public List<Hash> getPeers(byte[] ih, int max, long maxWait) {
     302     *  @return possibly empty (never null)
     303     */
     304    public Collection<Hash> getPeers(byte[] ih, int max, long maxWait) {
    305305        // check local tracker first
    306306        InfoHash iHash = new InfoHash(ih);
    307         List<Hash> rv = _tracker.getPeers(iHash, max);
     307        Collection<Hash> rv = _tracker.getPeers(iHash, max);
    308308        rv.remove(_myNodeInfo.getHash());
    309         if (!rv.isEmpty())
    310             return rv;  // TODO get DHT too?
     309        if (rv.size() >= max)
     310            return rv;
     311        rv = new HashSet(rv);
     312        long endTime = _context.clock().now() + maxWait;
    311313
    312314        // Initial set to try, will get added to as we go
    313         List<NodeInfo> nodes = _knownNodes.findClosest(iHash, max);
     315        int maxNodes = 12;
     316        List<NodeInfo> nodes = _knownNodes.findClosest(iHash, maxNodes);
    314317        SortedSet<NodeInfo> toTry = new TreeSet(new NodeInfoComparator(iHash));
    315318        toTry.addAll(nodes);
     
    317320
    318321        if (_log.shouldLog(Log.INFO))
    319             _log.info("Starting getPeers with " + nodes.size() + " to try");
    320         for (int i = 0; i < max; i++) {
     322            _log.info("Starting getPeers for " + iHash + " with " + nodes.size() + " to try");
     323        for (int i = 0; i < maxNodes; i++) {
    321324            if (!_isRunning)
    322325                break;
     
    335338            synchronized(waiter) {
    336339                try {
    337                     waiter.wait(maxWait);
     340                    waiter.wait(Math.max(20*1000, (Math.min(40*1000, endTime - _context.clock().now()))));
    338341                } catch (InterruptedException ie) {}
    339342            }
     
    351354                 List<Hash> reply = (List<Hash>) waiter.getReplyObject();
    352355                 if (!reply.isEmpty()) {
     356                     for (int j = 0; j < reply.size() && rv.size() < max; j++) {
     357                          rv.add(reply.get(j));
     358                     }
    353359                     if (_log.shouldLog(Log.INFO))
    354                          _log.info("Finished get Peers, returning " + reply.size());
    355                      return reply;
     360                         _log.info("Finished get Peers, got " + rv.size() + " from DHT, returning " + reply.size());
     361                     return rv;
    356362                 }
    357363            } else if (replyType == REPLY_NODES) {
     
    367373                     _log.info("Got unexpected reply " + replyType + ": " + waiter.getReplyObject());
    368374            }
    369         }
    370         if (_log.shouldLog(Log.INFO))
    371             _log.info("Finished get Peers, fail");
    372         return Collections.EMPTY_LIST;
     375            if (_context.clock().now() > endTime)
     376                break;
     377        }
     378        if (_log.shouldLog(Log.INFO))
     379            _log.info("Finished get Peers, " + rv.size() + " from local and none from DHT");
     380        return rv;
    373381    }
    374382
     
    466474                return false;
    467475            if (_log.shouldLog(Log.INFO))
    468                 _log.info("No token for announce to " + nInfo + " sending get_peers first");
     476                _log.info("No token for announce to " + nInfo + ", sending get_peers first");
    469477            ReplyWaiter waiter = sendGetPeers(nInfo, iHash);
    470478            if (waiter == null)
     
    479487            if (!(replyType == REPLY_PEERS || replyType == REPLY_NODES)) {
    480488                if (_log.shouldLog(Log.INFO))
    481                     _log.info("Get_peers failed to " + nInfo);
     489                    _log.info("Get_peers in announce() failed to " + nInfo);
    482490                return false;
    483491            }
     
    486494            if (token == null) {
    487495                if (_log.shouldLog(Log.INFO))
    488                     _log.info("Huh? no token after get_peers succeeded to " + nInfo);
     496                    _log.info("Huh? no token after get_peers in announce() succeeded to " + nInfo);
    489497                return false;
    490498            }
     
    492500            if (maxWait < 1000) {
    493501                if (_log.shouldLog(Log.INFO))
    494                     _log.info("Ran out of time after get_peers succeeded to " + nInfo);
     502                    _log.info("Ran out of time after get_peers in announce() succeeded to " + nInfo);
    495503                return false;
    496504            }
  • history.txt

    r44edf70 r523d39b  
     12012-08-15 zzz
     2 * i2psnark:
     3   - Fix bug preventing completion announcement, broken in 0.9.1
     4   - Fix setting short retry time after initial announce failure
     5   - Fix DHT announce and getPeers
     6   - Fix DHT warning message
     7
    182012-08-13 zzz
    29 * SSU EstablishmentManager:
  • router/java/src/net/i2p/router/RouterVersion.java

    r44edf70 r523d39b  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 9;
     21    public final static long BUILD = 10;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.