forked from I2P_Developers/i2p.i2p
i2psnark:
- Update session options when max bandwidth changes - BufferedStream cleanup and comments - torrent name display tweak - findbugs
This commit is contained in:
@ -179,11 +179,8 @@ public class ConnectionAcceptor implements Runnable
|
|||||||
try {
|
try {
|
||||||
InputStream in = _socket.getInputStream();
|
InputStream in = _socket.getInputStream();
|
||||||
OutputStream out = _socket.getOutputStream();
|
OutputStream out = _socket.getOutputStream();
|
||||||
|
// this is for the readahead in PeerAcceptor.connection()
|
||||||
if (true) {
|
in = new BufferedInputStream(in);
|
||||||
in = new BufferedInputStream(in);
|
|
||||||
//out = new BufferedOutputStream(out);
|
|
||||||
}
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Handling socket from " + _socket.getPeerDestination().calculateHash().toBase64());
|
_log.debug("Handling socket from " + _socket.getPeerDestination().calculateHash().toBase64());
|
||||||
peeracceptor.connection(_socket, in, out);
|
peeracceptor.connection(_socket, in, out);
|
||||||
|
@ -71,6 +71,7 @@ public class I2PSnarkUtil {
|
|||||||
public static final String DEFAULT_OPENTRACKERS = "http://tracker.welterde.i2p/a";
|
public static final String DEFAULT_OPENTRACKERS = "http://tracker.welterde.i2p/a";
|
||||||
public static final int DEFAULT_MAX_UP_BW = 8; //KBps
|
public static final int DEFAULT_MAX_UP_BW = 8; //KBps
|
||||||
public static final int MAX_CONNECTIONS = 16; // per torrent
|
public static final int MAX_CONNECTIONS = 16; // per torrent
|
||||||
|
private static final String PROP_MAX_BW = "i2cp.outboundBytesPerSecond";
|
||||||
private static final boolean ENABLE_DHT = true;
|
private static final boolean ENABLE_DHT = true;
|
||||||
|
|
||||||
public I2PSnarkUtil(I2PAppContext ctx) {
|
public I2PSnarkUtil(I2PAppContext ctx) {
|
||||||
@ -132,9 +133,21 @@ public class I2PSnarkUtil {
|
|||||||
_configured = true;
|
_configured = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param KBps
|
||||||
|
*/
|
||||||
public void setMaxUpBW(int limit) {
|
public void setMaxUpBW(int limit) {
|
||||||
_maxUpBW = limit;
|
_maxUpBW = limit;
|
||||||
|
_opts.put(PROP_MAX_BW, Integer.toString(limit * (1024 * 6 / 5))); // add a little for overhead
|
||||||
_configured = true;
|
_configured = true;
|
||||||
|
if (_manager != null) {
|
||||||
|
I2PSession sess = _manager.getSession();
|
||||||
|
if (sess != null) {
|
||||||
|
Properties newProps = new Properties();
|
||||||
|
newProps.putAll(_opts);
|
||||||
|
sess.updateOptions(newProps);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxConnections(int limit) {
|
public void setMaxConnections(int limit) {
|
||||||
@ -154,6 +167,10 @@ public class I2PSnarkUtil {
|
|||||||
public int getEepProxyPort() { return _proxyPort; }
|
public int getEepProxyPort() { return _proxyPort; }
|
||||||
public boolean getEepProxySet() { return _shouldProxy; }
|
public boolean getEepProxySet() { return _shouldProxy; }
|
||||||
public int getMaxUploaders() { return _maxUploaders; }
|
public int getMaxUploaders() { return _maxUploaders; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return KBps
|
||||||
|
*/
|
||||||
public int getMaxUpBW() { return _maxUpBW; }
|
public int getMaxUpBW() { return _maxUpBW; }
|
||||||
public int getMaxConnections() { return _maxConnections; }
|
public int getMaxConnections() { return _maxConnections; }
|
||||||
public int getStartupDelay() { return _startupDelay; }
|
public int getStartupDelay() { return _startupDelay; }
|
||||||
@ -166,7 +183,7 @@ public class I2PSnarkUtil {
|
|||||||
// try to find why reconnecting after stop
|
// try to find why reconnecting after stop
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Connecting to I2P", new Exception("I did it"));
|
_log.debug("Connecting to I2P", new Exception("I did it"));
|
||||||
Properties opts = new Properties();
|
Properties opts = _context.getProperties();
|
||||||
if (_opts != null) {
|
if (_opts != null) {
|
||||||
for (Iterator iter = _opts.keySet().iterator(); iter.hasNext(); ) {
|
for (Iterator iter = _opts.keySet().iterator(); iter.hasNext(); ) {
|
||||||
String key = (String)iter.next();
|
String key = (String)iter.next();
|
||||||
|
@ -189,7 +189,7 @@ public class MetaInfo
|
|||||||
if (val == null)
|
if (val == null)
|
||||||
throw new InvalidBEncodingException("Missing length number");
|
throw new InvalidBEncodingException("Missing length number");
|
||||||
long len = val.getLong();
|
long len = val.getLong();
|
||||||
m_lengths.add(new Long(len));
|
m_lengths.add(Long.valueOf(len));
|
||||||
l += len;
|
l += len;
|
||||||
|
|
||||||
val = (BEValue)desc.get("path");
|
val = (BEValue)desc.get("path");
|
||||||
@ -438,7 +438,7 @@ public class MetaInfo
|
|||||||
info.put("piece length", Integer.valueOf(piece_length));
|
info.put("piece length", Integer.valueOf(piece_length));
|
||||||
info.put("pieces", piece_hashes);
|
info.put("pieces", piece_hashes);
|
||||||
if (files == null)
|
if (files == null)
|
||||||
info.put("length", new Long(length));
|
info.put("length", Long.valueOf(length));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List l = new ArrayList();
|
List l = new ArrayList();
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
package org.klomp.snark;
|
package org.klomp.snark;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -231,19 +230,8 @@ public class Peer implements Comparable
|
|||||||
throw new IOException("Unable to reach " + peerID);
|
throw new IOException("Unable to reach " + peerID);
|
||||||
}
|
}
|
||||||
InputStream in = sock.getInputStream();
|
InputStream in = sock.getInputStream();
|
||||||
OutputStream out = sock.getOutputStream(); //new BufferedOutputStream(sock.getOutputStream());
|
OutputStream out = sock.getOutputStream();
|
||||||
if (true) {
|
byte [] id = handshake(in, out);
|
||||||
// buffered output streams are internally synchronized, so we can't get through to the underlying
|
|
||||||
// I2PSocket's MessageOutputStream to close() it if we are blocking on a write(...). Oh, and the
|
|
||||||
// buffer is unnecessary anyway, as unbuffered access lets the streaming lib do the 'right thing'.
|
|
||||||
//out = new BufferedOutputStream(out);
|
|
||||||
in = new BufferedInputStream(sock.getInputStream());
|
|
||||||
}
|
|
||||||
//BufferedInputStream bis
|
|
||||||
// = new BufferedInputStream(sock.getInputStream());
|
|
||||||
//BufferedOutputStream bos
|
|
||||||
// = new BufferedOutputStream(sock.getOutputStream());
|
|
||||||
byte [] id = handshake(in, out); //handshake(bis, bos);
|
|
||||||
byte [] expected_id = peerID.getID();
|
byte [] expected_id = peerID.getID();
|
||||||
if (expected_id == null) {
|
if (expected_id == null) {
|
||||||
peerID.setID(id);
|
peerID.setID(id);
|
||||||
@ -328,7 +316,7 @@ public class Peer implements Comparable
|
|||||||
* Sets DataIn/OutputStreams, does the handshake and returns the id
|
* Sets DataIn/OutputStreams, does the handshake and returns the id
|
||||||
* reported by the other side.
|
* reported by the other side.
|
||||||
*/
|
*/
|
||||||
private byte[] handshake(InputStream in, OutputStream out) //BufferedInputStream bis, BufferedOutputStream bos)
|
private byte[] handshake(InputStream in, OutputStream out)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
din = new DataInputStream(in);
|
din = new DataInputStream(in);
|
||||||
|
@ -210,6 +210,7 @@ class PeerCheckerTask extends TimerTask
|
|||||||
if (_util.getDHT() != null && (_runCount % 5) == 0) {
|
if (_util.getDHT() != null && (_runCount % 5) == 0) {
|
||||||
_util.getDHT().announce(coordinator.getInfoHash(), peer.getPeerID().getDestHash());
|
_util.getDHT().announce(coordinator.getInfoHash(), peer.getPeerID().getDestHash());
|
||||||
}
|
}
|
||||||
|
// send PEX
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resync actual uploaders value
|
// Resync actual uploaders value
|
||||||
|
@ -1185,7 +1185,7 @@ public class PeerCoordinator implements PeerListener
|
|||||||
* @since 0.8.4
|
* @since 0.8.4
|
||||||
*/
|
*/
|
||||||
public void gotPeers(Peer peer, List<PeerID> peers) {
|
public void gotPeers(Peer peer, List<PeerID> peers) {
|
||||||
|
// spin off thread or timer task to do a new Peer() and an addPeer() for each one
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return number of allowed uploaders for this torrent.
|
/** Return number of allowed uploaders for this torrent.
|
||||||
|
@ -35,8 +35,8 @@ class Piece implements Comparable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
if (o == null) return false;
|
||||||
if (o instanceof Piece) {
|
if (o instanceof Piece) {
|
||||||
if (o == null) return false;
|
|
||||||
return this.id == ((Piece)o).id;
|
return this.id == ((Piece)o).id;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -108,7 +108,7 @@ public class Snark
|
|||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
System.out.println("OOM in the OOM");
|
System.out.println("OOM in the OOM");
|
||||||
}
|
}
|
||||||
System.exit(0);
|
//System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -980,7 +980,6 @@ public class Snark
|
|||||||
(" <file> \tEither a local .torrent metainfo file to download");
|
(" <file> \tEither a local .torrent metainfo file to download");
|
||||||
System.out.println
|
System.out.println
|
||||||
(" \tor (with --share) a file to share.");
|
(" \tor (with --share) a file to share.");
|
||||||
System.exit(-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1117,11 +1116,12 @@ public class Snark
|
|||||||
coordinator.setWantedPieces();
|
coordinator.setWantedPieces();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** SnarkSnutdown callback unused */
|
||||||
public void shutdown()
|
public void shutdown()
|
||||||
{
|
{
|
||||||
// Should not be necessary since all non-deamon threads should
|
// Should not be necessary since all non-deamon threads should
|
||||||
// have died. But in reality this does not always happen.
|
// have died. But in reality this does not always happen.
|
||||||
System.exit(0);
|
//System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface CompleteListener {
|
public interface CompleteListener {
|
||||||
|
@ -247,11 +247,9 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
i2cpOpts.put(pair.substring(0, split), pair.substring(split+1));
|
i2cpOpts.put(pair.substring(0, split), pair.substring(split+1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i2cpHost != null) {
|
_util.setI2CPConfig(i2cpHost, i2cpPort, i2cpOpts);
|
||||||
_util.setI2CPConfig(i2cpHost, i2cpPort, i2cpOpts);
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
_log.debug("Configuring with I2CP options " + i2cpOpts);
|
||||||
_log.debug("Configuring with I2CP options " + i2cpOpts);
|
|
||||||
}
|
|
||||||
//I2PSnarkUtil.instance().setI2CPConfig("66.111.51.110", 7654, new Properties());
|
//I2PSnarkUtil.instance().setI2CPConfig("66.111.51.110", 7654, new Properties());
|
||||||
//String eepHost = _config.getProperty(PROP_EEP_HOST);
|
//String eepHost = _config.getProperty(PROP_EEP_HOST);
|
||||||
//int eepPort = getInt(PROP_EEP_PORT, 4444);
|
//int eepPort = getInt(PROP_EEP_PORT, 4444);
|
||||||
@ -338,6 +336,7 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// FIXME do this even if == null
|
||||||
if (i2cpHost != null) {
|
if (i2cpHost != null) {
|
||||||
int oldI2CPPort = _util.getI2CPPort();
|
int oldI2CPPort = _util.getI2CPPort();
|
||||||
String oldI2CPHost = _util.getI2CPHost();
|
String oldI2CPHost = _util.getI2CPHost();
|
||||||
@ -383,6 +382,7 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
p.putAll(opts);
|
p.putAll(opts);
|
||||||
_util.setI2CPConfig(i2cpHost, port, p);
|
_util.setI2CPConfig(i2cpHost, port, p);
|
||||||
|
_util.setMaxUpBW(getInt(PROP_UPBW_MAX, DEFAULT_MAX_UP_BW));
|
||||||
addMessage(_("I2CP and tunnel changes will take effect after stopping all torrents"));
|
addMessage(_("I2CP and tunnel changes will take effect after stopping all torrents"));
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("i2cp host [" + i2cpHost + "] i2cp port " + port + " opts [" + opts
|
_log.debug("i2cp host [" + i2cpHost + "] i2cp port " + port + " opts [" + opts
|
||||||
@ -396,6 +396,7 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
p.putAll(opts);
|
p.putAll(opts);
|
||||||
addMessage(_("I2CP settings changed to {0}", i2cpHost + ":" + port + " (" + i2cpOpts.trim() + ")"));
|
addMessage(_("I2CP settings changed to {0}", i2cpHost + ":" + port + " (" + i2cpOpts.trim() + ")"));
|
||||||
_util.setI2CPConfig(i2cpHost, port, p);
|
_util.setI2CPConfig(i2cpHost, port, p);
|
||||||
|
_util.setMaxUpBW(getInt(PROP_UPBW_MAX, DEFAULT_MAX_UP_BW));
|
||||||
boolean ok = _util.connect();
|
boolean ok = _util.connect();
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
addMessage(_("Unable to connect with the new settings, reverting to the old I2CP settings"));
|
addMessage(_("Unable to connect with the new settings, reverting to the old I2CP settings"));
|
||||||
|
@ -105,7 +105,7 @@ public class Storage
|
|||||||
{
|
{
|
||||||
long length = lengths[i];
|
long length = lengths[i];
|
||||||
total += length;
|
total += length;
|
||||||
lengthsList.add(new Long(length));
|
lengthsList.add(Long.valueOf(length));
|
||||||
}
|
}
|
||||||
|
|
||||||
piece_size = MIN_PIECE_SIZE;
|
piece_size = MIN_PIECE_SIZE;
|
||||||
@ -753,7 +753,8 @@ public class Storage
|
|||||||
openRAF(nr, false); // RW
|
openRAF(nr, false); // RW
|
||||||
// XXX - Is this the best way to make sure we have enough space for
|
// XXX - Is this the best way to make sure we have enough space for
|
||||||
// the whole file?
|
// the whole file?
|
||||||
listener.storageCreateFile(this, names[nr], lengths[nr]);
|
if (listener != null)
|
||||||
|
listener.storageCreateFile(this, names[nr], lengths[nr]);
|
||||||
final int ZEROBLOCKSIZE = metainfo.getPieceLength(0);
|
final int ZEROBLOCKSIZE = metainfo.getPieceLength(0);
|
||||||
byte[] zeros;
|
byte[] zeros;
|
||||||
try {
|
try {
|
||||||
|
@ -755,8 +755,12 @@ public class I2PSnarkServlet extends Default {
|
|||||||
filename = filename.substring(0, i);
|
filename = filename.substring(0, i);
|
||||||
String fullFilename = filename;
|
String fullFilename = filename;
|
||||||
if (filename.length() > MAX_DISPLAYED_FILENAME_LENGTH) {
|
if (filename.length() > MAX_DISPLAYED_FILENAME_LENGTH) {
|
||||||
fullFilename = new String(filename);
|
String start = filename.substring(0, MAX_DISPLAYED_FILENAME_LENGTH);
|
||||||
filename = filename.substring(0, MAX_DISPLAYED_FILENAME_LENGTH) + "…";
|
if (start.indexOf(" ") < 0 && start.indexOf("-") < 0) {
|
||||||
|
// browser has nowhere to break it
|
||||||
|
fullFilename = filename;
|
||||||
|
filename = start + "…";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
long total = snark.getTotalLength();
|
long total = snark.getTotalLength();
|
||||||
// Early typecast, avoid possibly overflowing a temp integer
|
// Early typecast, avoid possibly overflowing a temp integer
|
||||||
@ -1035,7 +1039,7 @@ public class I2PSnarkServlet extends Default {
|
|||||||
} else {
|
} else {
|
||||||
pct = (float) 101.0;
|
pct = (float) 101.0;
|
||||||
// until we get the metainfo we don't know how many pieces there are
|
// until we get the metainfo we don't know how many pieces there are
|
||||||
out.write("??");
|
//out.write("??");
|
||||||
}
|
}
|
||||||
out.write("</td>\n\t");
|
out.write("</td>\n\t");
|
||||||
out.write("<td class=\"snarkTorrentStatus " + rowClass + "\">");
|
out.write("<td class=\"snarkTorrentStatus " + rowClass + "\">");
|
||||||
@ -1134,7 +1138,6 @@ public class I2PSnarkServlet extends Default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void writeAddForm(PrintWriter out, HttpServletRequest req) throws IOException {
|
private void writeAddForm(PrintWriter out, HttpServletRequest req) throws IOException {
|
||||||
String uri = req.getRequestURI();
|
|
||||||
String newURL = req.getParameter("newURL");
|
String newURL = req.getParameter("newURL");
|
||||||
if ( (newURL == null) || (newURL.trim().length() <= 0) )
|
if ( (newURL == null) || (newURL.trim().length() <= 0) )
|
||||||
newURL = "";
|
newURL = "";
|
||||||
@ -1175,7 +1178,6 @@ public class I2PSnarkServlet extends Default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void writeSeedForm(PrintWriter out, HttpServletRequest req) throws IOException {
|
private void writeSeedForm(PrintWriter out, HttpServletRequest req) throws IOException {
|
||||||
String uri = req.getRequestURI();
|
|
||||||
String baseFile = req.getParameter("baseFile");
|
String baseFile = req.getParameter("baseFile");
|
||||||
if (baseFile == null || baseFile.trim().length() <= 0)
|
if (baseFile == null || baseFile.trim().length() <= 0)
|
||||||
baseFile = "";
|
baseFile = "";
|
||||||
@ -1235,7 +1237,6 @@ public class I2PSnarkServlet extends Default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void writeConfigForm(PrintWriter out, HttpServletRequest req) throws IOException {
|
private void writeConfigForm(PrintWriter out, HttpServletRequest req) throws IOException {
|
||||||
String uri = req.getRequestURI();
|
|
||||||
String dataDir = _manager.getDataDir().getAbsolutePath();
|
String dataDir = _manager.getDataDir().getAbsolutePath();
|
||||||
boolean autoStart = _manager.shouldAutoStart();
|
boolean autoStart = _manager.shouldAutoStart();
|
||||||
boolean useOpenTrackers = _manager.util().shouldUseOpenTrackers();
|
boolean useOpenTrackers = _manager.util().shouldUseOpenTrackers();
|
||||||
@ -1914,8 +1915,7 @@ private static class FetchAndAdd implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't hold object from this MetaInfo
|
String name = info.getName();
|
||||||
String name = new String(info.getName());
|
|
||||||
name = Storage.filterName(name);
|
name = Storage.filterName(name);
|
||||||
name = name + ".torrent";
|
name = name + ".torrent";
|
||||||
File torrentFile = new File(_manager.getDataDir(), name);
|
File torrentFile = new File(_manager.getDataDir(), name);
|
||||||
|
Reference in New Issue
Block a user