I2PSnark: Limit cases when we display tracker errors;

include host name of tracker when we do
This commit is contained in:
zzz
2016-05-09 11:32:56 +00:00
parent 6b578dfd8c
commit ab3dbd5880

View File

@ -585,12 +585,12 @@ public class TrackerClient implements Runnable {
{ {
// Probably not fatal (if it doesn't last to long...) // Probably not fatal (if it doesn't last to long...)
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn _log.warn("Could not contact tracker at '" + tr.announce + "': " + ioe);
("WARNING: Could not contact tracker at '"
+ tr.announce + "': " + ioe);
tr.trackerProblems = ioe.getMessage(); tr.trackerProblems = ioe.getMessage();
// don't show secondary tracker problems to the user // don't show secondary tracker problems to the user
if (tr.isPrimary) // ... and only if we don't have any peers at all. Otherwise, PEX/DHT will save us.
if (tr.isPrimary && coordinator.getPeers() <= 0 &&
(!completed || _util.getDHT() == null || _util.getDHT().size() <= 0))
snark.setTrackerProblems(tr.trackerProblems); snark.setTrackerProblems(tr.trackerProblems);
String tplc = tr.trackerProblems.toLowerCase(Locale.US); String tplc = tr.trackerProblems.toLowerCase(Locale.US);
if (tplc.startsWith(NOT_REGISTERED) || tplc.startsWith(NOT_REGISTERED_2) || if (tplc.startsWith(NOT_REGISTERED) || tplc.startsWith(NOT_REGISTERED_2) ||
@ -780,6 +780,11 @@ public class TrackerClient implements Runnable {
} }
} }
/**
*
* Note: IOException message text gets displayed in the UI
*
*/
private TrackerInfo doRequest(TCTracker tr, String infoHash, private TrackerInfo doRequest(TCTracker tr, String infoHash,
String peerID, long uploaded, String peerID, long uploaded,
long downloaded, long left, String event) long downloaded, long left, String event)
@ -821,24 +826,24 @@ public class TrackerClient implements Runnable {
boolean fast = _fastUnannounce && event.equals(STOPPED_EVENT); boolean fast = _fastUnannounce && event.equals(STOPPED_EVENT);
byte[] fetched = _util.get(s, true, fast ? -1 : 0, small ? 128 : 1024, small ? 1024 : 32*1024); byte[] fetched = _util.get(s, true, fast ? -1 : 0, small ? 128 : 1024, small ? 1024 : 32*1024);
if (fetched == null) if (fetched == null)
throw new IOException("Error fetching"); throw new IOException("No response from " + tr.host);
if (fetched.length == 0) if (fetched.length == 0)
throw new IOException("No data"); throw new IOException("No data from " + tr.host);
// The HTML check only works if we didn't exceed the maxium fetch size specified in get(), // The HTML check only works if we didn't exceed the maxium fetch size specified in get(),
// otherwise we already threw an IOE. // otherwise we already threw an IOE.
if (fetched[0] == '<') if (fetched[0] == '<')
throw new IOException(ERROR_GOT_HTML); throw new IOException(ERROR_GOT_HTML + " from " + tr.host);
InputStream in = new ByteArrayInputStream(fetched); InputStream in = new ByteArrayInputStream(fetched);
TrackerInfo info = new TrackerInfo(in, snark.getID(), TrackerInfo info = new TrackerInfo(in, snark.getID(),
snark.getInfoHash(), snark.getMetaInfo(), _util); snark.getInfoHash(), snark.getMetaInfo(), _util);
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("TrackerClient response: " + info); _log.info("TrackerClient " + tr.host + " response: " + info);
String failure = info.getFailureReason(); String failure = info.getFailureReason();
if (failure != null) if (failure != null)
throw new IOException(failure); throw new IOException("Tracker " + tr.host + " responded with: " + failure);
tr.interval = Math.max(MIN_TRACKER_ANNOUNCE_INTERVAL, info.getInterval() * 1000l); tr.interval = Math.max(MIN_TRACKER_ANNOUNCE_INTERVAL, info.getInterval() * 1000l);
return info; return info;
@ -925,6 +930,7 @@ public class TrackerClient implements Runnable {
private static class TCTracker private static class TCTracker
{ {
final String announce; final String announce;
final String host;
final boolean isPrimary; final boolean isPrimary;
long interval; long interval;
long lastRequestTime; long lastRequestTime;
@ -938,6 +944,8 @@ public class TrackerClient implements Runnable {
public TCTracker(String a, boolean p) public TCTracker(String a, boolean p)
{ {
announce = a; announce = a;
String s = a.substring(7);
host = s.substring(0, s.indexOf("/"));
isPrimary = p; isPrimary = p;
interval = INITIAL_SLEEP; interval = INITIAL_SLEEP;
} }