I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit c8f97d9c authored by zzz's avatar zzz
Browse files

* i2psnark:

      - Send numwant=0 if we don't need peers
      - Report returned complete and incomplete counts
        if higher than peer count
      - Allow missing peer list
      - Log tweaks
parent d3f1fe1c
No related branches found
No related tags found
No related merge requests found
......@@ -150,7 +150,7 @@ public class TrackerClient extends I2PAppThread
continue;
String dest = _util.lookup(url.substring(7, slash));
if (dest == null) {
_log.error("Announce host unknown: [" + url + "]");
_log.error("Announce host unknown: [" + url.substring(7, slash) + "]");
continue;
}
if (primary.startsWith("http://" + dest))
......@@ -258,7 +258,7 @@ public class TrackerClient extends I2PAppThread
tr.started = true;
Set peers = info.getPeers();
tr.seenPeers = peers.size();
tr.seenPeers = info.getPeerCount();
if (coordinator.trackerSeenPeers < tr.seenPeers) // update rising number quickly
coordinator.trackerSeenPeers = tr.seenPeers;
if ( (left > 0) && (!completed) ) {
......@@ -269,6 +269,7 @@ public class TrackerClient extends I2PAppThread
Iterator it = ordered.iterator();
while (it.hasNext()) {
Peer cur = (Peer)it.next();
// FIXME if id == us || dest == us continue;
// only delay if we actually make an attempt to add peer
if(coordinator.addPeer(cur)) {
int delay = DELAY_MUL;
......@@ -356,6 +357,10 @@ public class TrackerClient extends I2PAppThread
+ "&downloaded=" + downloaded
+ "&left=" + left
+ ((! event.equals(NO_EVENT)) ? ("&event=" + event) : "");
if (left <= 0 || event.equals(STOPPED_EVENT) || !coordinator.needPeers())
s += "&numwant=0";
else
s += "&numwant=" + _util.getMaxConnections();
_util.debug("Sending TrackerClient request: " + s, Snark.INFO);
tr.lastRequestTime = System.currentTimeMillis();
......@@ -430,7 +435,7 @@ public class TrackerClient extends I2PAppThread
url.getPort() < 0;
}
private class Tracker
private static class Tracker
{
String announce;
boolean isPrimary;
......
......@@ -23,6 +23,7 @@ package org.klomp.snark;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
......@@ -37,6 +38,8 @@ public class TrackerInfo
private final String failure_reason;
private final int interval;
private final Set peers;
private int complete;
private int incomplete;
public TrackerInfo(InputStream in, byte[] my_id, MetaInfo metainfo)
throws IOException
......@@ -68,11 +71,26 @@ public class TrackerInfo
throw new InvalidBEncodingException("No interval given");
else
interval = beInterval.getInt();
BEValue bePeers = (BEValue)m.get("peers");
if (bePeers == null)
throw new InvalidBEncodingException("No peer list");
peers = Collections.EMPTY_SET;
else
peers = getPeers(bePeers.getList(), my_id, metainfo);
BEValue bev = (BEValue)m.get("complete");
if (bev != null) try {
complete = bev.getInt();
if (complete < 0)
complete = 0;
} catch (InvalidBEncodingException ibe) {}
bev = (BEValue)m.get("incomplete");
if (bev != null) try {
incomplete = bev.getInt();
if (incomplete < 0)
incomplete = 0;
} catch (InvalidBEncodingException ibe) {}
}
}
......@@ -115,6 +133,12 @@ public class TrackerInfo
return peers;
}
public int getPeerCount()
{
int pc = peers == null ? 0 : peers.size();
return Math.max(pc, complete + incomplete - 1);
}
public String getFailureReason()
{
return failure_reason;
......@@ -132,6 +156,8 @@ public class TrackerInfo
return "TrackerInfo[FAILED: " + failure_reason + "]";
else
return "TrackerInfo[interval=" + interval
+ (complete > 0 ? (", complete=" + complete) : "" )
+ (incomplete > 0 ? (", incomplete=" + incomplete) : "" )
+ ", peers=" + peers + "]";
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment