forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p' (head bd037c8b542fe0f6125aa16fb3bff5d257b4e955)
to branch 'i2p.i2p.str4d.ui' (head 9bd4080121d8ef662d6a2e4dfe7fae1079b32646)
This commit is contained in:
@ -48,7 +48,7 @@ public class BitField
|
||||
* as set by the given byte array. This will make a copy of the array.
|
||||
* Extra bytes will be ignored.
|
||||
*
|
||||
* @exception ArrayOutOfBoundsException if give byte array is not large
|
||||
* @throws IndexOutOfBoundsException if give byte array is not large
|
||||
* enough.
|
||||
*/
|
||||
public BitField(byte[] bitfield, int size)
|
||||
@ -90,7 +90,7 @@ public class BitField
|
||||
/**
|
||||
* Sets the given bit to true.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException if bit is smaller then zero
|
||||
* @throws IndexOutOfBoundsException if bit is smaller then zero
|
||||
* bigger then size (inclusive).
|
||||
*/
|
||||
public void set(int bit)
|
||||
@ -110,7 +110,7 @@ public class BitField
|
||||
/**
|
||||
* Sets the given bit to false.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException if bit is smaller then zero
|
||||
* @throws IndexOutOfBoundsException if bit is smaller then zero
|
||||
* bigger then size (inclusive).
|
||||
* @since 0.9.22
|
||||
*/
|
||||
@ -141,7 +141,7 @@ public class BitField
|
||||
/**
|
||||
* Return true if the bit is set or false if it is not.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException if bit is smaller then zero
|
||||
* @throws IndexOutOfBoundsException if bit is smaller then zero
|
||||
* bigger then size (inclusive).
|
||||
*/
|
||||
public boolean get(int bit)
|
||||
|
@ -357,12 +357,12 @@ public class I2PSnarkUtil {
|
||||
public File get(String url, boolean rewrite) { return get(url, rewrite, 0); }
|
||||
|
||||
/**
|
||||
* @param retries if < 0, set timeout to a few seconds
|
||||
* @param retries if < 0, set timeout to a few seconds
|
||||
*/
|
||||
public File get(String url, int retries) { return get(url, true, retries); }
|
||||
|
||||
/**
|
||||
* @param retries if < 0, set timeout to a few seconds
|
||||
* @param retries if < 0, set timeout to a few seconds
|
||||
*/
|
||||
public File get(String url, boolean rewrite, int retries) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
@ -413,7 +413,7 @@ public class I2PSnarkUtil {
|
||||
|
||||
/**
|
||||
* Fetch to memory
|
||||
* @param retries if < 0, set timeout to a few seconds
|
||||
* @param retries if < 0, set timeout to a few seconds
|
||||
* @param initialSize buffer size
|
||||
* @param maxSize fails if greater
|
||||
* @return null on error
|
||||
@ -659,7 +659,7 @@ public class I2PSnarkUtil {
|
||||
*
|
||||
* @param s string to be translated containing {0}
|
||||
* The {0} will be replaced by the parameter.
|
||||
* Single quotes must be doubled, i.e. ' -> '' in the string.
|
||||
* Single quotes must be doubled, i.e. ' -> '' in the string.
|
||||
* @param o parameter, not translated.
|
||||
* To translate parameter also, use _t("foo {0} bar", _t("baz"))
|
||||
* Do not double the single quotes in the parameter.
|
||||
|
@ -161,7 +161,7 @@ class MagnetState {
|
||||
|
||||
/**
|
||||
* @return true if this was the last piece
|
||||
* @throws NPE, IllegalArgumentException, IOException, ...
|
||||
* @throws NullPointerException IllegalArgumentException, IOException, ...
|
||||
*/
|
||||
public boolean saveChunk(int chunk, byte[] data, int off, int length) throws Exception {
|
||||
if (!isInitialized)
|
||||
@ -185,7 +185,7 @@ class MagnetState {
|
||||
|
||||
/**
|
||||
* @return true if this was the last piece
|
||||
* @throws NPE, IllegalArgumentException, IOException, ...
|
||||
* @throws NullPointerException IllegalArgumentException, IOException, ...
|
||||
*/
|
||||
private MetaInfo buildMetaInfo() throws Exception {
|
||||
// top map has nothing in it but the info map (no announce)
|
||||
|
@ -464,7 +464,7 @@ public class MetaInfo
|
||||
* Return the length of a piece. All pieces are of equal length
|
||||
* except for the last one (<code>getPieces()-1</code>).
|
||||
*
|
||||
* @exception IndexOutOfBoundsException when piece is equal to or
|
||||
* @throws IndexOutOfBoundsException when piece is equal to or
|
||||
* greater then the number of pieces in the torrent.
|
||||
*/
|
||||
public int getPieceLength(int piece)
|
||||
|
@ -115,7 +115,7 @@ public class Peer implements Comparable<Peer>
|
||||
* the connect() method.
|
||||
*
|
||||
* @param metainfo null if in magnet mode
|
||||
* @exception IOException when an error occurred during the handshake.
|
||||
* @throws IOException when an error occurred during the handshake.
|
||||
*/
|
||||
public Peer(final I2PSocket sock, InputStream in, OutputStream out, byte[] my_id, byte[] infohash, MetaInfo metainfo)
|
||||
throws IOException
|
||||
|
@ -385,7 +385,7 @@ class PeerCoordinator implements PeerListener
|
||||
|
||||
/**
|
||||
* Inbound.
|
||||
* Not halted, peers < max.
|
||||
* Not halted, peers < max.
|
||||
* @since 0.9.1
|
||||
*/
|
||||
public boolean needPeers()
|
||||
@ -395,7 +395,7 @@ class PeerCoordinator implements PeerListener
|
||||
|
||||
/**
|
||||
* Outbound.
|
||||
* Not halted, peers < max, and need pieces.
|
||||
* Not halted, peers < max, and need pieces.
|
||||
* @since 0.9.1
|
||||
*/
|
||||
public boolean needOutboundPeers() {
|
||||
|
@ -212,6 +212,7 @@ public class Snark
|
||||
|
||||
***********/
|
||||
|
||||
/** max connections */
|
||||
public static final String PROP_MAX_CONNECTIONS = "i2psnark.maxConnections";
|
||||
|
||||
/** most of these used to be public, use accessors below instead */
|
||||
|
@ -42,6 +42,7 @@ import net.i2p.util.SecureDirectory;
|
||||
import net.i2p.util.SecureFileOutputStream;
|
||||
import net.i2p.util.SimpleTimer;
|
||||
import net.i2p.util.SimpleTimer2;
|
||||
import net.i2p.util.SystemVersion;
|
||||
import net.i2p.util.Translate;
|
||||
|
||||
import org.klomp.snark.dht.DHT;
|
||||
@ -302,6 +303,8 @@ public class SnarkManager implements CompleteListener {
|
||||
* Runs inline.
|
||||
*/
|
||||
public void stop() {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Snark stop() begin", new Exception("I did it"));
|
||||
if (_umgr != null && _uhandler != null) {
|
||||
//_uhandler.shutdown();
|
||||
_umgr.unregister(_uhandler, UpdateType.ROUTER_SIGNED, UpdateMethod.TORRENT);
|
||||
@ -312,6 +315,8 @@ public class SnarkManager implements CompleteListener {
|
||||
_connectionAcceptor.halt();
|
||||
_idleChecker.cancel();
|
||||
stopAllTorrents(true);
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Snark stop() end");
|
||||
}
|
||||
|
||||
/** @since 0.9.1 */
|
||||
@ -324,7 +329,7 @@ public class SnarkManager implements CompleteListener {
|
||||
|
||||
/**
|
||||
* Use if it does not include a link.
|
||||
* Escapes '<' and '>' before queueing
|
||||
* Escapes '<' and '>' before queueing
|
||||
*/
|
||||
public void addMessage(String message) {
|
||||
addMessageNoEscape(message.replace("<", "<").replace(">", ">"));
|
||||
@ -332,7 +337,7 @@ public class SnarkManager implements CompleteListener {
|
||||
|
||||
/**
|
||||
* Use if it includes a link.
|
||||
* Does not escape '<' and '>' before queueing
|
||||
* Does not escape '<' and '>' before queueing
|
||||
* @since 0.9.14.1
|
||||
*/
|
||||
public void addMessageNoEscape(String message) {
|
||||
@ -2558,7 +2563,7 @@ public class SnarkManager implements CompleteListener {
|
||||
/**
|
||||
* Stop all running torrents, and close the tunnel after a delay
|
||||
* to allow for announces.
|
||||
* If called at router shutdown via Jetty shutdown hook -> webapp destroy() -> stop(),
|
||||
* If called at router shutdown via Jetty shutdown hook -> webapp destroy() -> stop(),
|
||||
* the tunnel won't actually be closed as the SimpleTimer2 is already shutdown
|
||||
* or will be soon, so we delay a few seconds inline.
|
||||
* @param finalShutdown if true, sleep at the end if any torrents were running
|
||||
@ -2580,7 +2585,9 @@ public class SnarkManager implements CompleteListener {
|
||||
stopTorrent(snark, false);
|
||||
// Throttle since every unannounce is now threaded.
|
||||
// How to do this without creating a ton of threads?
|
||||
try { Thread.sleep(20); } catch (InterruptedException ie) {}
|
||||
if (count % 8 == 0) {
|
||||
try { Thread.sleep(20); } catch (InterruptedException ie) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_util.connected()) {
|
||||
@ -2593,8 +2600,12 @@ public class SnarkManager implements CompleteListener {
|
||||
_context.simpleTimer2().addEvent(new Disconnector(), 60*1000);
|
||||
addMessage(_t("Closing I2P tunnel after notifying trackers."));
|
||||
if (finalShutdown) {
|
||||
try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
|
||||
long toWait = 5*1000;
|
||||
if (SystemVersion.isARM())
|
||||
toWait *= 2;
|
||||
try { Thread.sleep(toWait); } catch (InterruptedException ie) {}
|
||||
}
|
||||
_util.disconnect();
|
||||
} else {
|
||||
_util.disconnect();
|
||||
_stopping = false;
|
||||
|
@ -436,7 +436,7 @@ public class Storage implements Closeable
|
||||
* Must call Snark.updatePiecePriorities()
|
||||
* (which calls getPiecePriorities()) after calling this.
|
||||
* @param fileIndex as obtained from indexOf
|
||||
* @param pri default 0; <0 to disable
|
||||
* @param pri default 0; <0 to disable
|
||||
* @since 0.8.1
|
||||
*/
|
||||
public void setPriority(int fileIndex, int pri) {
|
||||
@ -695,7 +695,7 @@ public class Storage implements Closeable
|
||||
* Doesn't really reopen the file descriptors for a restart.
|
||||
* Just does an existence check but no length check or data reverification
|
||||
*
|
||||
* @throws IOE on fail
|
||||
* @throws IOException on fail
|
||||
*/
|
||||
public void reopen() throws IOException
|
||||
{
|
||||
@ -1111,7 +1111,7 @@ public class Storage implements Closeable
|
||||
*
|
||||
* @return true if the piece was correct (sha metainfo hash
|
||||
* matches), otherwise false.
|
||||
* @exception IOException when some storage related error occurs.
|
||||
* @throws IOException when some storage related error occurs.
|
||||
*/
|
||||
public boolean putPiece(PartialPiece pp) throws IOException
|
||||
{
|
||||
|
@ -102,9 +102,9 @@ public class BDecoder
|
||||
* @return The first BEValue on the stream or null when the stream
|
||||
* has ended.
|
||||
*
|
||||
* @exception InvalidBEncoding when the stream doesn't start with a
|
||||
* @throws InvalidBEncodingException when the stream doesn't start with a
|
||||
* bencoded value or the stream isn't a bencoded stream at all.
|
||||
* @exception IOException when somthing bad happens with the stream
|
||||
* @throws IOException when somthing bad happens with the stream
|
||||
* to read from.
|
||||
*/
|
||||
public static BEValue bdecode(InputStream in) throws IOException
|
||||
|
@ -42,7 +42,7 @@ public interface DHT {
|
||||
*
|
||||
* @param ih the Info Hash (torrent)
|
||||
* @param max maximum number of peers to return
|
||||
* @param maxWait the maximum time to wait (ms) must be > 0
|
||||
* @param maxWait the maximum time to wait (ms) must be > 0
|
||||
* @param annMax the number of peers to announce to
|
||||
* @param annMaxWait the maximum total time to wait for announces, may be 0 to return immediately without waiting for acks
|
||||
* @param isSeed true if seed, false if leech
|
||||
@ -81,7 +81,7 @@ public interface DHT {
|
||||
|
||||
/**
|
||||
* Announce to the closest DHT peers.
|
||||
* Blocking unless maxWait <= 0
|
||||
* Blocking unless maxWait <= 0
|
||||
* Caller should run in a thread.
|
||||
* This also automatically announces ourself to our local tracker.
|
||||
* For best results do a getPeers() first so we have tokens.
|
||||
|
@ -245,7 +245,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
||||
*
|
||||
* @param target the key we are searching for
|
||||
* @param maxNodes how many to contact
|
||||
* @param maxWait how long to wait for each to reply (not total) must be > 0
|
||||
* @param maxWait how long to wait for each to reply (not total) must be > 0
|
||||
* @param parallel how many outstanding at once (unimplemented, always 1)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -326,7 +326,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
||||
*
|
||||
* @param ih the Info Hash (torrent)
|
||||
* @param max maximum number of peers to return
|
||||
* @param maxWait the maximum time to wait (ms) must be > 0
|
||||
* @param maxWait the maximum time to wait (ms) must be > 0
|
||||
* @param annMax the number of peers to announce to
|
||||
* @param annMaxWait the maximum total time to wait for announces, may be 0 to return immediately without waiting for acks
|
||||
* @param isSeed true if seed, false if leech
|
||||
@ -510,7 +510,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
||||
* Announce to the closest peers in the local DHT.
|
||||
* This is NOT iterative - call getPeers() first to get the closest
|
||||
* peers into the local DHT.
|
||||
* Blocking unless maxWait <= 0
|
||||
* Blocking unless maxWait <= 0
|
||||
* Caller should run in a thread.
|
||||
* This also automatically announces ourself to our local tracker.
|
||||
* For best results do a getPeersAndAnnounce() instead, as this announces to
|
||||
@ -544,7 +544,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
||||
|
||||
/**
|
||||
* Announce to a single DHT peer.
|
||||
* Blocking unless maxWait <= 0
|
||||
* Blocking unless maxWait <= 0
|
||||
* Caller should run in a thread.
|
||||
* For best results do a getPeers() first so we have a token.
|
||||
*
|
||||
@ -1509,9 +1509,9 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
||||
|
||||
/**
|
||||
* Should contain null if getReplyCode is REPLY_PONG.
|
||||
* Should contain List<Hash> if getReplyCode is REPLY_PEERS.
|
||||
* Should contain List<NodeInfo> if getReplyCode is REPLY_NODES.
|
||||
* Should contain String if getReplyCode is > 200.
|
||||
* Should contain List<Hash> if getReplyCode is REPLY_PEERS.
|
||||
* Should contain List<NodeInfo> if getReplyCode is REPLY_NODES.
|
||||
* Should contain String if getReplyCode is > 200.
|
||||
* @return may be null depending on what happened. Cast to expected type.
|
||||
*/
|
||||
public Object getReplyObject() {
|
||||
|
@ -77,7 +77,7 @@ class NodeInfo extends SimpleDataStructure {
|
||||
* @param compactInfo 20 byte node ID, 32 byte destHash, 2 byte port
|
||||
* @param offset starting at this offset in compactInfo
|
||||
* @throws IllegalArgumentException
|
||||
* @throws AIOOBE
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
*/
|
||||
public NodeInfo(byte[] compactInfo, int offset) {
|
||||
super();
|
||||
|
@ -57,7 +57,7 @@ class URIUtil
|
||||
|
||||
/** Encode a URI path.
|
||||
*
|
||||
* Somewhat oddly, this encodes all chars >= 0x80 if buf is null, (strict RFC 2396)
|
||||
* Somewhat oddly, this encodes all chars >= 0x80 if buf is null, (strict RFC 2396)
|
||||
* but only the control, space, and special chars if buf is non-null.
|
||||
*
|
||||
* @param path The path the encode
|
||||
|
Reference in New Issue
Block a user