forked from I2P_Developers/i2p.i2p
i2psnark: Don't mark torrent BAD on I2CP errors (ticket #2725)
Logging: - Log to wrapper log after log manager shutdown (ticket #2725) - sync methods Router: - Allow clients more time to get disconnect messages at shutdown (ticket #2725) - Don't delete router context at shutdown, to prevent a late creation of a new app context (ticket #2725) - Don't try to delete ping file on Android javadocs
This commit is contained in:
@@ -304,6 +304,7 @@ public class Snark
|
||||
* Will not start itself. Caller must call startTorrent() if desired.
|
||||
*
|
||||
* @throws RuntimeException via fatal()
|
||||
* @throws RouterException via fatalRouter()
|
||||
*/
|
||||
public Snark(I2PSnarkUtil util, String torrent, String ip, int user_port,
|
||||
StorageListener slistener, CoordinatorListener clistener,
|
||||
@@ -321,6 +322,7 @@ public class Snark
|
||||
*
|
||||
* @param baseFile if null, use rootDir/torrentName; if non-null, use it instead
|
||||
* @throws RuntimeException via fatal()
|
||||
* @throws RouterException via fatalRouter()
|
||||
* @since 0.9.11
|
||||
*/
|
||||
public Snark(I2PSnarkUtil util, String torrent, String ip, int user_port,
|
||||
@@ -399,7 +401,7 @@ public class Snark
|
||||
fatal("'" + torrent + "' exists,"
|
||||
+ " but is not a valid torrent metainfo file."
|
||||
+ System.getProperty("line.separator"), ioe);
|
||||
else
|
||||
else
|
||||
fatal("I2PSnark does not support creating and tracking a torrent at the moment");
|
||||
/*
|
||||
{
|
||||
@@ -424,7 +426,7 @@ public class Snark
|
||||
else
|
||||
fatal("Cannot open '" + torrent + "'", ioe);
|
||||
} catch (OutOfMemoryError oom) {
|
||||
fatal("ERROR - Out of memory, cannot create torrent " + torrent + ": " + oom.getMessage());
|
||||
fatalRouter("ERROR - Out of memory, cannot create torrent " + torrent + ": " + oom.getMessage(), oom);
|
||||
} finally {
|
||||
if (in != null)
|
||||
try { in.close(); } catch (IOException ioe) {}
|
||||
@@ -496,6 +498,7 @@ public class Snark
|
||||
*
|
||||
* @param ignored used to be autostart
|
||||
* @throws RuntimeException via fatal()
|
||||
* @throws RouterException via fatalRouter()
|
||||
* @since 0.8.4, removed in 0.9.36, restored in 0.9.45 with boolean param now ignored
|
||||
*/
|
||||
protected Snark(I2PSnarkUtil util, String torrent, byte[] ih, String trackerURL,
|
||||
@@ -513,6 +516,7 @@ public class Snark
|
||||
* @param ih 20-byte info hash
|
||||
* @param trackerURL may be null
|
||||
* @throws RuntimeException via fatal()
|
||||
* @throws RouterException via fatalRouter()
|
||||
* @since 0.8.4
|
||||
*/
|
||||
public Snark(I2PSnarkUtil util, String torrent, byte[] ih, String trackerURL,
|
||||
@@ -556,7 +560,12 @@ public class Snark
|
||||
rv[9] = snark;
|
||||
rv[10] = snark;
|
||||
rv[11] = snark;
|
||||
I2PAppContext.getGlobalContext().random().nextBytes(rv, 12, 8);
|
||||
try {
|
||||
I2PAppContext.getGlobalContext().random().nextBytes(rv, 12, 8);
|
||||
} catch (IllegalStateException ise) {
|
||||
// random is shut down
|
||||
throw new RouterException("Router shutdown", ise);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -565,6 +574,7 @@ public class Snark
|
||||
* Blocks if tunnel is not yet open.
|
||||
*
|
||||
* @throws RuntimeException via fatal()
|
||||
* @throws RouterException via fatalRouter()
|
||||
*/
|
||||
public synchronized void startTorrent() {
|
||||
if (!stopped)
|
||||
@@ -580,11 +590,12 @@ public class Snark
|
||||
|
||||
private void x_startTorrent() {
|
||||
boolean ok = _util.connect();
|
||||
if (!ok) fatal("Unable to connect to I2P");
|
||||
if (!ok)
|
||||
fatalRouter("Unable to connect to I2P", null);
|
||||
if (coordinator == null) {
|
||||
I2PServerSocket serversocket = _util.getServerSocket();
|
||||
if (serversocket == null)
|
||||
fatal("Unable to listen for I2P connections");
|
||||
fatalRouter("Unable to listen for I2P connections", null);
|
||||
else {
|
||||
Destination d = serversocket.getManager().getSession().getMyDestination();
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
@@ -1217,21 +1228,18 @@ public class Snark
|
||||
|
||||
/**
|
||||
* Aborts program abnormally.
|
||||
* @throws RuntimeException always
|
||||
*/
|
||||
private void fatal(String s)
|
||||
{
|
||||
private void fatal(String s) throws RuntimeException {
|
||||
fatal(s, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aborts program abnormally.
|
||||
* @throws RuntimeException always
|
||||
*/
|
||||
private void fatal(String s, Throwable t)
|
||||
{
|
||||
private void fatal(String s, Throwable t) throws RuntimeException {
|
||||
_log.error(s, t);
|
||||
//System.err.println("snark: " + s + ((t == null) ? "" : (": " + t)));
|
||||
//if (debug >= INFO && t != null)
|
||||
// t.printStackTrace();
|
||||
stopTorrent();
|
||||
if (t != null)
|
||||
s += ": " + t;
|
||||
@@ -1240,6 +1248,29 @@ public class Snark
|
||||
throw new RuntimeException(s, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws a unique exception class to blame the router that can be caught by SnarkManager
|
||||
* @throws RouterException always
|
||||
* @since 0.9.46
|
||||
*/
|
||||
private void fatalRouter(String s, Throwable t) throws RouterException {
|
||||
_log.error(s, t);
|
||||
stopTorrent();
|
||||
if (completeListener != null)
|
||||
completeListener.fatal(this, s);
|
||||
throw new RouterException(s, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* A unique exception class to blame the router that can be caught by SnarkManager
|
||||
* @since 0.9.46
|
||||
*/
|
||||
static class RouterException extends RuntimeException {
|
||||
public RouterException(String s) { super(s); }
|
||||
public RouterException(String s, Throwable t) { super(s, t); }
|
||||
}
|
||||
|
||||
|
||||
/** CoordinatorListener - this does nothing */
|
||||
public void peerChange(PeerCoordinator coordinator, Peer peer)
|
||||
{
|
||||
@@ -1421,6 +1452,9 @@ public class Snark
|
||||
return totalUploaders > limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is i2psnark as a whole over its limit?
|
||||
*/
|
||||
public boolean overUpBWLimit() {
|
||||
if (_peerCoordinatorSet == null)
|
||||
return false;
|
||||
@@ -1435,6 +1469,9 @@ public class Snark
|
||||
return total > limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a particular peer who has this recent download rate (in Bps) over our upstream bandwidth limit?
|
||||
*/
|
||||
public boolean overUpBWLimit(long total) {
|
||||
long limit = 1024l * _util.getMaxUpBW();
|
||||
return total > limit;
|
||||
|
||||
@@ -1659,8 +1659,9 @@ public class SnarkManager implements CompleteListener, ClientApp {
|
||||
disableTorrentFile(filename);
|
||||
return false;
|
||||
} catch (OutOfMemoryError oom) {
|
||||
addMessage(_t("ERROR - Out of memory, cannot create torrent from {0}", sfile.getName()) + ": " + oom.getLocalizedMessage());
|
||||
return false;
|
||||
String s = _t("ERROR - Out of memory, cannot create torrent from {0}", sfile.getName()) + ": " + oom.getLocalizedMessage();
|
||||
addMessage(s);
|
||||
throw new Snark.RouterException(s, oom);
|
||||
} finally {
|
||||
if (fis != null) try { fis.close(); } catch (IOException ioe) {}
|
||||
}
|
||||
@@ -2734,6 +2735,10 @@ public class SnarkManager implements CompleteListener, ClientApp {
|
||||
disableTorrentFile(name);
|
||||
rv = false;
|
||||
}
|
||||
} catch (Snark.RouterException e) {
|
||||
addMessage(_t("Error: Could not add the torrent {0}", name) + ": " + e);
|
||||
_log.error("Unable to add the torrent " + name, e);
|
||||
return false;
|
||||
} catch (RuntimeException e) {
|
||||
addMessage(_t("Error: Could not add the torrent {0}", name) + ": " + e);
|
||||
_log.error("Unable to add the torrent " + name, e);
|
||||
|
||||
Reference in New Issue
Block a user