forked from I2P_Developers/i2p.i2p
* i2psnark: - Concurrent, limit, display, log tweaks
This commit is contained in:
@ -25,6 +25,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.I2PException;
|
import net.i2p.I2PException;
|
||||||
import net.i2p.client.streaming.I2PServerSocket;
|
import net.i2p.client.streaming.I2PServerSocket;
|
||||||
import net.i2p.client.streaming.I2PSocket;
|
import net.i2p.client.streaming.I2PSocket;
|
||||||
@ -36,7 +37,7 @@ import net.i2p.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class ConnectionAcceptor implements Runnable
|
public class ConnectionAcceptor implements Runnable
|
||||||
{
|
{
|
||||||
private Log _log = new Log(ConnectionAcceptor.class);
|
private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(ConnectionAcceptor.class);
|
||||||
private I2PServerSocket serverSocket;
|
private I2PServerSocket serverSocket;
|
||||||
private PeerAcceptor peeracceptor;
|
private PeerAcceptor peeracceptor;
|
||||||
private Thread thread;
|
private Thread thread;
|
||||||
|
@ -4,7 +4,6 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -23,6 +22,7 @@ import net.i2p.client.streaming.I2PSocketManagerFactory;
|
|||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
import net.i2p.data.Hash;
|
import net.i2p.data.Hash;
|
||||||
|
import net.i2p.util.ConcurrentHashSet;
|
||||||
import net.i2p.util.EepGet;
|
import net.i2p.util.EepGet;
|
||||||
import net.i2p.util.FileUtil;
|
import net.i2p.util.FileUtil;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
@ -48,7 +48,7 @@ public class I2PSnarkUtil {
|
|||||||
private Map _opts;
|
private Map _opts;
|
||||||
private I2PSocketManager _manager;
|
private I2PSocketManager _manager;
|
||||||
private boolean _configured;
|
private boolean _configured;
|
||||||
private final Set _shitlist;
|
private final Set<Hash> _shitlist;
|
||||||
private int _maxUploaders;
|
private int _maxUploaders;
|
||||||
private int _maxUpBW;
|
private int _maxUpBW;
|
||||||
private int _maxConnections;
|
private int _maxConnections;
|
||||||
@ -67,7 +67,7 @@ public class I2PSnarkUtil {
|
|||||||
_opts = new HashMap();
|
_opts = new HashMap();
|
||||||
setProxy("127.0.0.1", 4444);
|
setProxy("127.0.0.1", 4444);
|
||||||
setI2CPConfig("127.0.0.1", 7654, null);
|
setI2CPConfig("127.0.0.1", 7654, null);
|
||||||
_shitlist = new HashSet(64);
|
_shitlist = new ConcurrentHashSet();
|
||||||
_configured = false;
|
_configured = false;
|
||||||
_maxUploaders = Snark.MAX_TOTAL_UPLOADERS;
|
_maxUploaders = Snark.MAX_TOTAL_UPLOADERS;
|
||||||
_maxUpBW = DEFAULT_MAX_UP_BW;
|
_maxUpBW = DEFAULT_MAX_UP_BW;
|
||||||
@ -187,18 +187,15 @@ public class I2PSnarkUtil {
|
|||||||
/** connect to the given destination */
|
/** connect to the given destination */
|
||||||
I2PSocket connect(PeerID peer) throws IOException {
|
I2PSocket connect(PeerID peer) throws IOException {
|
||||||
Hash dest = peer.getAddress().calculateHash();
|
Hash dest = peer.getAddress().calculateHash();
|
||||||
synchronized (_shitlist) {
|
|
||||||
if (_shitlist.contains(dest))
|
if (_shitlist.contains(dest))
|
||||||
throw new IOException("Not trying to contact " + dest.toBase64() + ", as they are shitlisted");
|
throw new IOException("Not trying to contact " + dest.toBase64() + ", as they are shitlisted");
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
I2PSocket rv = _manager.connect(peer.getAddress());
|
I2PSocket rv = _manager.connect(peer.getAddress());
|
||||||
if (rv != null) synchronized (_shitlist) { _shitlist.remove(dest); }
|
if (rv != null)
|
||||||
|
_shitlist.remove(dest);
|
||||||
return rv;
|
return rv;
|
||||||
} catch (I2PException ie) {
|
} catch (I2PException ie) {
|
||||||
synchronized (_shitlist) {
|
|
||||||
_shitlist.add(dest);
|
_shitlist.add(dest);
|
||||||
}
|
|
||||||
SimpleScheduler.getInstance().addEvent(new Unshitlist(dest), 10*60*1000);
|
SimpleScheduler.getInstance().addEvent(new Unshitlist(dest), 10*60*1000);
|
||||||
throw new IOException("Unable to reach the peer " + peer + ": " + ie.getMessage());
|
throw new IOException("Unable to reach the peer " + peer + ": " + ie.getMessage());
|
||||||
}
|
}
|
||||||
@ -207,7 +204,7 @@ public class I2PSnarkUtil {
|
|||||||
private class Unshitlist implements SimpleTimer.TimedEvent {
|
private class Unshitlist implements SimpleTimer.TimedEvent {
|
||||||
private Hash _dest;
|
private Hash _dest;
|
||||||
public Unshitlist(Hash dest) { _dest = dest; }
|
public Unshitlist(Hash dest) { _dest = dest; }
|
||||||
public void timeReached() { synchronized (_shitlist) { _shitlist.remove(_dest); } }
|
public void timeReached() { _shitlist.remove(_dest); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +30,7 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.crypto.SHA1;
|
import net.i2p.crypto.SHA1;
|
||||||
import net.i2p.data.Base64;
|
import net.i2p.data.Base64;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
@ -47,7 +48,7 @@ import org.klomp.snark.bencode.InvalidBEncodingException;
|
|||||||
*/
|
*/
|
||||||
public class MetaInfo
|
public class MetaInfo
|
||||||
{
|
{
|
||||||
private static final Log _log = new Log(MetaInfo.class);
|
private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(MetaInfo.class);
|
||||||
private final String announce;
|
private final String announce;
|
||||||
private final byte[] info_hash;
|
private final byte[] info_hash;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
@ -28,6 +28,7 @@ import java.io.OutputStream;
|
|||||||
import java.io.SequenceInputStream;
|
import java.io.SequenceInputStream;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.client.streaming.I2PSocket;
|
import net.i2p.client.streaming.I2PSocket;
|
||||||
import net.i2p.data.Base64;
|
import net.i2p.data.Base64;
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
@ -41,7 +42,7 @@ import net.i2p.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class PeerAcceptor
|
public class PeerAcceptor
|
||||||
{
|
{
|
||||||
private static final Log _log = new Log(PeerAcceptor.class);
|
private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(PeerAcceptor.class);
|
||||||
private final PeerCoordinator coordinator;
|
private final PeerCoordinator coordinator;
|
||||||
final PeerCoordinatorSet coordinators;
|
final PeerCoordinatorSet coordinators;
|
||||||
|
|
||||||
|
@ -23,11 +23,12 @@ package org.klomp.snark;
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
class PeerConnectionIn implements Runnable
|
class PeerConnectionIn implements Runnable
|
||||||
{
|
{
|
||||||
private Log _log = new Log(PeerConnectionIn.class);
|
private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(PeerConnectionIn.class);
|
||||||
private final Peer peer;
|
private final Peer peer;
|
||||||
private final DataInputStream din;
|
private final DataInputStream din;
|
||||||
|
|
||||||
@ -129,7 +130,7 @@ class PeerConnectionIn implements Runnable
|
|||||||
din.readFully(bitmap);
|
din.readFully(bitmap);
|
||||||
ps.bitfieldMessage(bitmap);
|
ps.bitfieldMessage(bitmap);
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Received bitmap from " + peer + " on " + peer.metainfo.getName() + ": size=" + (i-1) + ": " + ps.bitfield);
|
_log.debug("Received bitmap from " + peer + " on " + peer.metainfo.getName() + ": size=" + (i-1) /* + ": " + ps.bitfield */ );
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
piece = din.readInt();
|
piece = din.readInt();
|
||||||
|
@ -26,6 +26,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.util.I2PAppThread;
|
import net.i2p.util.I2PAppThread;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.SimpleScheduler;
|
import net.i2p.util.SimpleScheduler;
|
||||||
@ -33,7 +34,7 @@ import net.i2p.util.SimpleTimer;
|
|||||||
|
|
||||||
class PeerConnectionOut implements Runnable
|
class PeerConnectionOut implements Runnable
|
||||||
{
|
{
|
||||||
private Log _log = new Log(PeerConnectionOut.class);
|
private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(PeerConnectionOut.class);
|
||||||
private final Peer peer;
|
private final Peer peer;
|
||||||
private final DataOutputStream dout;
|
private final DataOutputStream dout;
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.util.I2PAppThread;
|
import net.i2p.util.I2PAppThread;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ import net.i2p.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class PeerCoordinator implements PeerListener
|
public class PeerCoordinator implements PeerListener
|
||||||
{
|
{
|
||||||
private final Log _log = new Log(PeerCoordinator.class);
|
private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(PeerCoordinator.class);
|
||||||
final MetaInfo metainfo;
|
final MetaInfo metainfo;
|
||||||
final Storage storage;
|
final Storage storage;
|
||||||
final Snark snark;
|
final Snark snark;
|
||||||
@ -241,18 +242,17 @@ public class PeerCoordinator implements PeerListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reduce max if huge pieces to keep from ooming
|
* Reduce max if huge pieces to keep from ooming when leeching
|
||||||
* Todo: should we only reduce when leeching?
|
* @return 512K: 16; 1M: 11; 2M: 6
|
||||||
* @return 512K: 16; 1M: 11; 2M: 8
|
|
||||||
*/
|
*/
|
||||||
private int getMaxConnections() {
|
private int getMaxConnections() {
|
||||||
int size = metainfo.getPieceLength(0);
|
int size = metainfo.getPieceLength(0);
|
||||||
int max = _util.getMaxConnections();
|
int max = _util.getMaxConnections();
|
||||||
if (size <= 512*1024)
|
if (size <= 512*1024 || completed())
|
||||||
return max;
|
return max;
|
||||||
if (size <= 1024*1024)
|
if (size <= 1024*1024)
|
||||||
return (max + max + 2) / 3;
|
return (max + max + 2) / 3;
|
||||||
return (max + 1) / 2;
|
return (max + 2) / 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean halted() { return halted; }
|
public boolean halted() { return halted; }
|
||||||
|
@ -24,11 +24,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
class PeerState
|
class PeerState
|
||||||
{
|
{
|
||||||
private Log _log = new Log(PeerState.class);
|
private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(PeerState.class);
|
||||||
final Peer peer;
|
final Peer peer;
|
||||||
final PeerListener listener;
|
final PeerListener listener;
|
||||||
final MetaInfo metainfo;
|
final MetaInfo metainfo;
|
||||||
@ -159,7 +160,7 @@ class PeerState
|
|||||||
// why did they contact us? (robert)
|
// why did they contact us? (robert)
|
||||||
// Dump them quick before we send our whole bitmap
|
// Dump them quick before we send our whole bitmap
|
||||||
if (_log.shouldLog(Log.WARN))
|
if (_log.shouldLog(Log.WARN))
|
||||||
_log.warn("Disconnecting seed that connects to seeds" + peer);
|
_log.warn("Disconnecting seed that connects to seeds: " + peer);
|
||||||
peer.disconnect(true);
|
peer.disconnect(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,6 +196,7 @@ class PeerState
|
|||||||
|
|
||||||
// Limit total pipelined requests to MAX_PIPELINE bytes
|
// Limit total pipelined requests to MAX_PIPELINE bytes
|
||||||
// to conserve memory and prevent DOS
|
// to conserve memory and prevent DOS
|
||||||
|
// Todo: limit number of requests also? (robert 64 x 4KB)
|
||||||
if (out.queuedBytes() + length > MAX_PIPELINE_BYTES)
|
if (out.queuedBytes() + length > MAX_PIPELINE_BYTES)
|
||||||
{
|
{
|
||||||
if (_log.shouldLog(Log.WARN))
|
if (_log.shouldLog(Log.WARN))
|
||||||
|
@ -33,6 +33,7 @@ import java.util.List;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.util.I2PAppThread;
|
import net.i2p.util.I2PAppThread;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ import net.i2p.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class TrackerClient extends I2PAppThread
|
public class TrackerClient extends I2PAppThread
|
||||||
{
|
{
|
||||||
private static final Log _log = new Log(TrackerClient.class);
|
private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(TrackerClient.class);
|
||||||
private static final String NO_EVENT = "";
|
private static final String NO_EVENT = "";
|
||||||
private static final String STARTED_EVENT = "started";
|
private static final String STARTED_EVENT = "started";
|
||||||
private static final String COMPLETED_EVENT = "completed";
|
private static final String COMPLETED_EVENT = "completed";
|
||||||
|
@ -505,7 +505,7 @@ public class I2PSnarkServlet extends HttpServlet {
|
|||||||
err = snark.coordinator.trackerProblems;
|
err = snark.coordinator.trackerProblems;
|
||||||
curPeers = snark.coordinator.getPeerCount();
|
curPeers = snark.coordinator.getPeerCount();
|
||||||
stats[4] += curPeers;
|
stats[4] += curPeers;
|
||||||
knownPeers = snark.coordinator.trackerSeenPeers;
|
knownPeers = Math.max(curPeers, snark.coordinator.trackerSeenPeers);
|
||||||
}
|
}
|
||||||
|
|
||||||
String statusString = _("Unknown");
|
String statusString = _("Unknown");
|
||||||
|
Reference in New Issue
Block a user