forked from I2P_Developers/i2p.i2p
- Fix changing 'use open trackers' config setting (old bug) - More TrackerClient fixes for no primary announce - More BEValue.toString() improvements for debugging
This commit is contained in:
@ -60,6 +60,7 @@ public class I2PSnarkUtil {
|
|||||||
private int _maxConnections;
|
private int _maxConnections;
|
||||||
private File _tmpDir;
|
private File _tmpDir;
|
||||||
private int _startupDelay;
|
private int _startupDelay;
|
||||||
|
private boolean _shouldUseOT;
|
||||||
private KRPC _krpc;
|
private KRPC _krpc;
|
||||||
|
|
||||||
public static final int DEFAULT_STARTUP_DELAY = 3;
|
public static final int DEFAULT_STARTUP_DELAY = 3;
|
||||||
@ -83,6 +84,7 @@ public class I2PSnarkUtil {
|
|||||||
_maxUpBW = DEFAULT_MAX_UP_BW;
|
_maxUpBW = DEFAULT_MAX_UP_BW;
|
||||||
_maxConnections = MAX_CONNECTIONS;
|
_maxConnections = MAX_CONNECTIONS;
|
||||||
_startupDelay = DEFAULT_STARTUP_DELAY;
|
_startupDelay = DEFAULT_STARTUP_DELAY;
|
||||||
|
_shouldUseOT = DEFAULT_USE_OPENTRACKERS;
|
||||||
// This is used for both announce replies and .torrent file downloads,
|
// This is used for both announce replies and .torrent file downloads,
|
||||||
// so it must be available even if not connected to I2CP.
|
// so it must be available even if not connected to I2CP.
|
||||||
// so much for multiple instances
|
// so much for multiple instances
|
||||||
@ -425,10 +427,10 @@ public class I2PSnarkUtil {
|
|||||||
|
|
||||||
/** comma delimited list open trackers to use as backups */
|
/** comma delimited list open trackers to use as backups */
|
||||||
/** sorted map of name to announceURL=baseURL */
|
/** sorted map of name to announceURL=baseURL */
|
||||||
public List getOpenTrackers() {
|
public List<String> getOpenTrackers() {
|
||||||
if (!shouldUseOpenTrackers())
|
if (!shouldUseOpenTrackers())
|
||||||
return null;
|
return null;
|
||||||
List rv = new ArrayList(1);
|
List<String> rv = new ArrayList(1);
|
||||||
String trackers = getOpenTrackerString();
|
String trackers = getOpenTrackerString();
|
||||||
StringTokenizer tok = new StringTokenizer(trackers, ", ");
|
StringTokenizer tok = new StringTokenizer(trackers, ", ");
|
||||||
while (tok.hasMoreTokens())
|
while (tok.hasMoreTokens())
|
||||||
@ -439,11 +441,12 @@ public class I2PSnarkUtil {
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUseOpenTrackers(boolean yes) {
|
||||||
|
_shouldUseOT = yes;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean shouldUseOpenTrackers() {
|
public boolean shouldUseOpenTrackers() {
|
||||||
String rv = (String) _opts.get(PROP_USE_OPENTRACKERS);
|
return _shouldUseOT;
|
||||||
if (rv == null)
|
|
||||||
return DEFAULT_USE_OPENTRACKERS;
|
|
||||||
return Boolean.valueOf(rv).booleanValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -394,6 +394,8 @@ public class Snark
|
|||||||
*/
|
*/
|
||||||
else
|
else
|
||||||
fatal("Cannot open '" + torrent + "'", ioe);
|
fatal("Cannot open '" + torrent + "'", ioe);
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
fatal("ERROR - Out of memory, cannot create torrent " + torrent + ": " + oom.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
if (in != null)
|
if (in != null)
|
||||||
try { in.close(); } catch (IOException ioe) {}
|
try { in.close(); } catch (IOException ioe) {}
|
||||||
|
@ -263,7 +263,9 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
String ot = _config.getProperty(I2PSnarkUtil.PROP_OPENTRACKERS);
|
String ot = _config.getProperty(I2PSnarkUtil.PROP_OPENTRACKERS);
|
||||||
if (ot != null)
|
if (ot != null)
|
||||||
_util.setOpenTrackerString(ot);
|
_util.setOpenTrackerString(ot);
|
||||||
// FIXME set util use open trackers property somehow
|
String useOT = _config.getProperty(I2PSnarkUtil.PROP_USE_OPENTRACKERS);
|
||||||
|
boolean bOT = useOT == null || Boolean.valueOf(useOT).booleanValue();
|
||||||
|
_util.setUseOpenTrackers(bOT);
|
||||||
getDataDir().mkdirs();
|
getDataDir().mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,6 +436,7 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
addMessage(_("Enabled open trackers - torrent restart required to take effect."));
|
addMessage(_("Enabled open trackers - torrent restart required to take effect."));
|
||||||
else
|
else
|
||||||
addMessage(_("Disabled open trackers - torrent restart required to take effect."));
|
addMessage(_("Disabled open trackers - torrent restart required to take effect."));
|
||||||
|
_util.setUseOpenTrackers(useOpenTrackers);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
if (openTrackers != null) {
|
if (openTrackers != null) {
|
||||||
@ -605,6 +608,8 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
if (sfile.exists())
|
if (sfile.exists())
|
||||||
sfile.delete();
|
sfile.delete();
|
||||||
return;
|
return;
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
addMessage(_("ERROR - Out of memory, cannot create torrent from {0}", sfile.getName()) + ": " + oom.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
if (fis != null) try { fis.close(); } catch (IOException ioe) {}
|
if (fis != null) try { fis.close(); } catch (IOException ioe) {}
|
||||||
}
|
}
|
||||||
|
@ -137,18 +137,18 @@ public class TrackerClient extends I2PAppThread
|
|||||||
// the primary tracker, that we don't add it twice.
|
// the primary tracker, that we don't add it twice.
|
||||||
// todo: check for b32 matches as well
|
// todo: check for b32 matches as well
|
||||||
trackers = new ArrayList(2);
|
trackers = new ArrayList(2);
|
||||||
String primary;
|
String primary = null;
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
primary = meta.getAnnounce();
|
primary = meta.getAnnounce();
|
||||||
if (isValidAnnounce(primary)) {
|
if (isValidAnnounce(primary)) {
|
||||||
trackers.add(new Tracker(meta.getAnnounce(), true));
|
trackers.add(new Tracker(meta.getAnnounce(), true));
|
||||||
|
_log.debug("Announce: [" + primary + "] infoHash: " + infoHash);
|
||||||
} else {
|
} else {
|
||||||
_log.warn("Skipping invalid or non-i2p announce: " + primary);
|
_log.warn("Skipping invalid or non-i2p announce: " + primary);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
primary = "";
|
|
||||||
}
|
}
|
||||||
_log.debug("Announce: [" + primary + "] infoHash: " + infoHash);
|
if (primary == null)
|
||||||
|
primary = "";
|
||||||
List tlist = _util.getOpenTrackers();
|
List tlist = _util.getOpenTrackers();
|
||||||
if (tlist != null) {
|
if (tlist != null) {
|
||||||
for (int i = 0; i < tlist.size(); i++) {
|
for (int i = 0; i < tlist.size(); i++) {
|
||||||
@ -179,7 +179,7 @@ public class TrackerClient extends I2PAppThread
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tlist.isEmpty()) {
|
if (trackers.isEmpty()) {
|
||||||
// FIXME really need to get this message to the gui
|
// FIXME really need to get this message to the gui
|
||||||
stop = true;
|
stop = true;
|
||||||
_log.error("No valid trackers for infoHash: " + infoHash);
|
_log.error("No valid trackers for infoHash: " + infoHash);
|
||||||
|
@ -180,15 +180,36 @@ public class BEValue
|
|||||||
String valueString;
|
String valueString;
|
||||||
if (value instanceof byte[])
|
if (value instanceof byte[])
|
||||||
{
|
{
|
||||||
|
// try to do a nice job for debugging
|
||||||
byte[] bs = (byte[])value;
|
byte[] bs = (byte[])value;
|
||||||
// XXX - Stupid heuristic... and not UTF-8
|
if (bs.length == 0)
|
||||||
//if (bs.length <= 12)
|
valueString = "0 bytes";
|
||||||
// valueString = new String(bs);
|
else if (bs.length <= 32) {
|
||||||
//else
|
StringBuilder buf = new StringBuilder(32);
|
||||||
// valueString = "bytes:" + bs.length;
|
boolean bin = false;
|
||||||
if (bs.length <= 32)
|
for (int i = 0; i < bs.length; i++) {
|
||||||
valueString = bs.length + " bytes: " + Base64.encode(bs);
|
int b = bs[i] & 0xff;
|
||||||
else
|
// no UTF-8
|
||||||
|
if (b < ' ' || b > 0x7e) {
|
||||||
|
bin = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bin && bs.length <= 8) {
|
||||||
|
buf.append(bs.length).append(" bytes: 0x");
|
||||||
|
for (int i = 0; i < bs.length; i++) {
|
||||||
|
int b = bs[i] & 0xff;
|
||||||
|
if (b < 16)
|
||||||
|
buf.append('0');
|
||||||
|
buf.append(Integer.toHexString(b));
|
||||||
|
}
|
||||||
|
} else if (bin) {
|
||||||
|
buf.append(bs.length).append(" bytes: ").append(Base64.encode(bs));
|
||||||
|
} else {
|
||||||
|
buf.append('"').append(new String(bs)).append('"');
|
||||||
|
}
|
||||||
|
valueString = buf.toString();
|
||||||
|
} else
|
||||||
valueString = bs.length + " bytes";
|
valueString = bs.length + " bytes";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1902,6 +1902,8 @@ private static class FetchAndAdd implements Runnable {
|
|||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
_manager.addMessage(_("Torrent at {0} was not valid", urlify(_url)) + ": " + ioe.getMessage());
|
_manager.addMessage(_("Torrent at {0} was not valid", urlify(_url)) + ": " + ioe.getMessage());
|
||||||
|
} catch (OutOfMemoryError oom) {
|
||||||
|
_manager.addMessage(_("ERROR - Out of memory, cannot create torrent from {0}", urlify(_url)) + ": " + oom.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
try { if (in != null) in.close(); } catch (IOException ioe) {}
|
try { if (in != null) in.close(); } catch (IOException ioe) {}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user