forked from I2P_Developers/i2p.i2p
i2psnark: Add web seeds in TrackerClient
list web seeds in UI
This commit is contained in:
@ -227,6 +227,10 @@ public class PeerID implements Comparable<PeerID>
|
||||
{
|
||||
if (_toStringCache != null)
|
||||
return _toStringCache;
|
||||
if (id != null && DataHelper.eq(id, 0, WebPeer.IDBytes, 0, WebPeer.IDBytes.length)) {
|
||||
_toStringCache = "WebSeed@" + Base32.encode(destHash) + ".b32.i2p";
|
||||
return _toStringCache;
|
||||
}
|
||||
if (id == null || address == null)
|
||||
return "unkn@" + Base64.encode(destHash).substring(0, 6);
|
||||
int nonZero = 0;
|
||||
|
@ -407,6 +407,8 @@ public class TrackerClient implements Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
int webPeers = getWebPeers();
|
||||
|
||||
// Local DHT tracker announce
|
||||
DHT dht = _util.getDHT();
|
||||
if (dht != null && (meta == null || !meta.isPrivate()))
|
||||
@ -438,7 +440,7 @@ public class TrackerClient implements Runnable {
|
||||
}
|
||||
|
||||
// we could try and total the unique peers but that's too hard for now
|
||||
snark.setTrackerSeenPeers(maxSeenPeers);
|
||||
snark.setTrackerSeenPeers(maxSeenPeers + webPeers);
|
||||
|
||||
if (stop)
|
||||
return;
|
||||
@ -720,6 +722,62 @@ public class TrackerClient implements Runnable {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return valid web peers from metainfo
|
||||
* @since 0.9.49
|
||||
*/
|
||||
private int getWebPeers() {
|
||||
if (meta == null)
|
||||
return 0;
|
||||
// prevent connecting out to a webseed for comments only
|
||||
if (coordinator.getNeededLength() <= 0)
|
||||
return 0;
|
||||
List<String> urls = meta.getWebSeedURLs();
|
||||
if (urls == null || urls.isEmpty())
|
||||
return 0;
|
||||
// Uncomment to skip multifile torrents
|
||||
//if (meta.getLengths() != null)
|
||||
// return 0;
|
||||
List<Peer> peers = new ArrayList<Peer>(urls.size());
|
||||
for (String url : urls) {
|
||||
Hash h = getHostHash(url);
|
||||
if (h == null)
|
||||
continue;
|
||||
try {
|
||||
PeerID pID = new PeerID(h.getData(), _util);
|
||||
byte[] id = new byte[20];
|
||||
System.arraycopy(WebPeer.IDBytes, 0, id, 0, 12);
|
||||
System.arraycopy(h.getData(), 0, id, 12, 8);
|
||||
pID.setID(id);
|
||||
URI uri = new URI(url);
|
||||
String host = uri.getHost();
|
||||
if (host == null)
|
||||
continue;
|
||||
if (coordinator.isWebPeerBanned(host)) {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Skipping banned webseed " + url);
|
||||
continue;
|
||||
}
|
||||
peers.add(new WebPeer(coordinator, uri, pID, snark.getMetaInfo()));
|
||||
} catch (InvalidBEncodingException ibe) {
|
||||
} catch (URISyntaxException use) {
|
||||
}
|
||||
}
|
||||
if (peers.isEmpty())
|
||||
return 0;
|
||||
Random r = _util.getContext().random();
|
||||
if (peers.size() > 1)
|
||||
Collections.shuffle(peers, r);
|
||||
Iterator<Peer> it = peers.iterator();
|
||||
while ((!stop) && it.hasNext() && coordinator.needOutboundPeers()) {
|
||||
Peer cur = it.next();
|
||||
if (coordinator.addPeer(cur) && it.hasNext()) {
|
||||
int delay = r.nextInt(DELAY_RAND) + DELAY_MIN;
|
||||
try { Thread.sleep(delay); } catch (InterruptedException ie) {}
|
||||
}
|
||||
}
|
||||
return peers.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a thread for each tracker in parallel if tunnel is still open
|
||||
|
@ -1993,33 +1993,38 @@ public class I2PSnarkServlet extends BasicServlet {
|
||||
out.write(_t("Peer attached to swarm"));
|
||||
out.write("\"></td><td colspan=\"5\">");
|
||||
PeerID pid = peer.getPeerID();
|
||||
String ch = pid != null ? pid.toString().substring(0, 4) : "????";
|
||||
String client;
|
||||
if ("AwMD".equals(ch))
|
||||
client = _t("I2PSnark");
|
||||
else if ("LUJJ".equals(ch))
|
||||
client = "BiglyBT" + getAzVersion(pid.getID());
|
||||
else if ("LUFa".equals(ch))
|
||||
client = "Vuze" + getAzVersion(pid.getID());
|
||||
else if ("LVhE".equals(ch))
|
||||
client = "XD" + getAzVersion(pid.getID());
|
||||
else if ("ZV".equals(ch.substring(2,4)) || "VUZP".equals(ch))
|
||||
client = "Robert" + getRobtVersion(pid.getID());
|
||||
else if (ch.startsWith("LV")) // LVCS 1.0.2?; LVRS 1.0.4
|
||||
client = "Transmission" + getAzVersion(pid.getID());
|
||||
else if ("LUtU".equals(ch))
|
||||
client = "KTorrent" + getAzVersion(pid.getID());
|
||||
else if ("CwsL".equals(ch))
|
||||
client = "I2PSnarkXL";
|
||||
else if ("BFJT".equals(ch))
|
||||
client = "I2PRufus";
|
||||
else if ("TTMt".equals(ch))
|
||||
client = "I2P-BT";
|
||||
else
|
||||
client = _t("Unknown") + " (" + ch + ')';
|
||||
out.write(client + " <tt title=\"");
|
||||
out.write(_t("Destination (identity) of peer"));
|
||||
out.write("\">" + peer.toString().substring(5, 9)+ "</tt>");
|
||||
String ch = pid != null ? pid.toString() : "????";
|
||||
if (ch.startsWith("WebSeed@")) {
|
||||
out.write(ch);
|
||||
} else {
|
||||
ch = ch.substring(0, 4);
|
||||
String client;
|
||||
if ("AwMD".equals(ch))
|
||||
client = _t("I2PSnark");
|
||||
else if ("LUJJ".equals(ch))
|
||||
client = "BiglyBT" + getAzVersion(pid.getID());
|
||||
else if ("LUFa".equals(ch))
|
||||
client = "Vuze" + getAzVersion(pid.getID());
|
||||
else if ("LVhE".equals(ch))
|
||||
client = "XD" + getAzVersion(pid.getID());
|
||||
else if ("ZV".equals(ch.substring(2,4)) || "VUZP".equals(ch))
|
||||
client = "Robert" + getRobtVersion(pid.getID());
|
||||
else if (ch.startsWith("LV")) // LVCS 1.0.2?; LVRS 1.0.4
|
||||
client = "Transmission" + getAzVersion(pid.getID());
|
||||
else if ("LUtU".equals(ch))
|
||||
client = "KTorrent" + getAzVersion(pid.getID());
|
||||
else if ("CwsL".equals(ch))
|
||||
client = "I2PSnarkXL";
|
||||
else if ("BFJT".equals(ch))
|
||||
client = "I2PRufus";
|
||||
else if ("TTMt".equals(ch))
|
||||
client = "I2P-BT";
|
||||
else
|
||||
client = _t("Unknown") + " (" + ch + ')';
|
||||
out.write(client + " <tt title=\"");
|
||||
out.write(_t("Destination (identity) of peer"));
|
||||
out.write("\">" + peer.toString().substring(5, 9)+ "</tt>");
|
||||
}
|
||||
if (showDebug) {
|
||||
long t = peer.getInactiveTime();
|
||||
if (t >= 5000)
|
||||
@ -3177,9 +3182,34 @@ public class I2PSnarkServlet extends BasicServlet {
|
||||
}
|
||||
buf.append("</td></tr>\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (meta != null) {
|
||||
List<String> weblist = meta.getWebSeedURLs();
|
||||
if (weblist != null) {
|
||||
List<String> wlist = new ArrayList<String>(weblist.size());
|
||||
// strip non-i2p web seeds
|
||||
for (String s : weblist) {
|
||||
if (isI2PTracker(s))
|
||||
wlist.add(s);
|
||||
}
|
||||
if (!wlist.isEmpty()) {
|
||||
buf.append("<tr><td>");
|
||||
toThemeImg(buf, "details");
|
||||
buf.append("</td><td><b>")
|
||||
.append(_t("Web Seeds")).append("</b></td><td>");
|
||||
boolean more = false;
|
||||
for (String s : wlist) {
|
||||
buf.append("<span class=\"info_tracker\">");
|
||||
if (more)
|
||||
buf.append(' ');
|
||||
else
|
||||
more = true;
|
||||
buf.append(getShortTrackerLink(DataHelper.stripHTML(s), snark.getInfoHash()));
|
||||
buf.append("</span> ");
|
||||
}
|
||||
buf.append("</td></tr>\n");
|
||||
}
|
||||
}
|
||||
|
||||
String com = meta.getComment();
|
||||
if (com != null && com.length() > 0) {
|
||||
if (com.length() > 1024)
|
||||
|
Reference in New Issue
Block a user