Changeset 05516f3


Ignore:
Timestamp:
Aug 20, 2012 12:09:20 PM (7 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
6c2eb31
Parents:
264df83
Message:
  • i2psnark: Add minimum tracker and DHT announce intervals
Location:
apps/i2psnark/java/src/org/klomp/snark
Files:
2 edited

Legend:

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

    r264df83 r05516f3  
    4040import net.i2p.data.DataHelper;
    4141import net.i2p.data.Hash;
    42 import net.i2p.util.Clock;
    4342import net.i2p.util.I2PAppThread;
    4443import net.i2p.util.Log;
     
    8079  private final static int MAX_CONSEC_FAILS = 5;    // slow down after this
    8180  private final static int LONG_SLEEP = 30*60*1000; // sleep a while after lots of fails
     81  private final static long MIN_TRACKER_ANNOUNCE_INTERVAL = 10*60*1000;
     82  private final static long MIN_DHT_ANNOUNCE_INTERVAL = 10*60*1000;
    8283
    8384  private final I2PSnarkUtil _util;
     
    104105  private boolean completed;
    105106  private volatile boolean _fastUnannounce;
    106 
     107  private long lastDHTAnnounce;
    107108  private final List<Tracker> trackers;
    108109
     
    215216   */
    216217  public void run() {
    217       long begin = Clock.getInstance().now();
     218      long begin = _util.getContext().clock().now();
    218219      if (_log.shouldLog(Log.DEBUG))
    219220          _log.debug("Start " + Thread.currentThread().getName());
     
    244245          if (_log.shouldLog(Log.DEBUG))
    245246              _log.debug("Finish " + Thread.currentThread().getName() +
    246                          " after " + DataHelper.formatDuration(Clock.getInstance().now() - begin));
     247                         " after " + DataHelper.formatDuration(_util.getContext().clock().now() - begin));
    247248      }
    248249  }
     
    460461            // FIXME this needs to be in its own thread
    461462            dht = _util.getDHT();
    462             if (dht != null && (meta == null || !meta.isPrivate()) && !stop) {
     463            if (dht != null && (meta == null || !meta.isPrivate()) && (!stop) &&
     464                _util.getContext().clock().now() >  lastDHTAnnounce + MIN_DHT_ANNOUNCE_INTERVAL) {
    463465                int numwant;
    464466                if (event.equals(STOPPED_EVENT) || !coordinator.needOutboundPeers())
     
    467469                    numwant = _util.getMaxConnections();
    468470                Collection<Hash> hashes = dht.getPeers(snark.getInfoHash(), numwant, 2*60*1000);
    469                 if (!hashes.isEmpty())
     471                if (!hashes.isEmpty()) {
    470472                    runStarted = true;
     473                    lastDHTAnnounce = _util.getContext().clock().now();
     474                }
    471475                if (_log.shouldLog(Log.INFO))
    472476                    _log.info("Got " + hashes + " from DHT");
     
    656660          throw new IOException(failure);
    657661
    658         tr.interval = info.getInterval() * 1000;
     662        tr.interval = Math.max(MIN_TRACKER_ANNOUNCE_INTERVAL, info.getInterval() * 1000l);
    659663        return info;
    660664    } finally {
  • apps/i2psnark/java/src/org/klomp/snark/TrackerInfo.java

    r264df83 r05516f3  
    3939 *  Compact format 2 - One big string of concatenated hashes - official format
    4040 */
    41 public class TrackerInfo
     41class TrackerInfo
    4242{
    4343  private final String failure_reason;
     
    196196  }
    197197
     198  /** in seconds */
    198199  public int getInterval()
    199200  {
Note: See TracChangeset for help on using the changeset viewer.