2005-12-16 jrandom
* Moved I2PSnark from using Threads to I2PThreads, so we handle OOMs properly (thanks Complication!) * More guards in I2PSnark for zany behavior (I2PSession recon w/ skew, b0rking in the DirMonitor, etc)
This commit is contained in:
@ -26,6 +26,7 @@ import java.net.*;
|
|||||||
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;
|
||||||
|
import net.i2p.util.I2PThread;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accepts connections on a TCP port and routes them to sub-acceptors.
|
* Accepts connections on a TCP port and routes them to sub-acceptors.
|
||||||
@ -47,7 +48,7 @@ public class ConnectionAcceptor implements Runnable
|
|||||||
|
|
||||||
socketChanged = false;
|
socketChanged = false;
|
||||||
stop = false;
|
stop = false;
|
||||||
thread = new Thread(this, "I2PSnark acceptor");
|
thread = new I2PThread(this, "I2PSnark acceptor");
|
||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
@ -105,7 +106,7 @@ public class ConnectionAcceptor implements Runnable
|
|||||||
Snark.debug("Null socket accepted, but socket wasn't changed?", Snark.ERROR);
|
Snark.debug("Null socket accepted, but socket wasn't changed?", Snark.ERROR);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Thread t = new Thread(new Handler(socket), "Connection-" + socket);
|
Thread t = new I2PThread(new Handler(socket), "Connection-" + socket);
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,8 @@ package org.klomp.snark;
|
|||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.I2PException;
|
import net.i2p.I2PException;
|
||||||
import net.i2p.util.EepGet;
|
import net.i2p.util.EepGet;
|
||||||
import net.i2p.data.Base64;
|
import net.i2p.client.I2PSession;
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.*;
|
||||||
import net.i2p.data.Destination;
|
|
||||||
import net.i2p.client.streaming.I2PServerSocket;
|
import net.i2p.client.streaming.I2PServerSocket;
|
||||||
import net.i2p.client.streaming.I2PSocket;
|
import net.i2p.client.streaming.I2PSocket;
|
||||||
import net.i2p.client.streaming.I2PSocketManager;
|
import net.i2p.client.streaming.I2PSocketManager;
|
||||||
@ -149,7 +148,13 @@ public class I2PSnarkUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String getOurIPString() {
|
String getOurIPString() {
|
||||||
return _manager.getSession().getMyDestination().toBase64();
|
I2PSession sess = _manager.getSession();
|
||||||
|
if (sess != null) {
|
||||||
|
Destination dest = sess.getMyDestination();
|
||||||
|
if (dest != null)
|
||||||
|
return dest.toBase64();
|
||||||
|
}
|
||||||
|
return "unknown";
|
||||||
}
|
}
|
||||||
Destination getDestination(String ip) {
|
Destination getDestination(String ip) {
|
||||||
if (ip == null) return null;
|
if (ip == null) return null;
|
||||||
|
@ -24,6 +24,7 @@ import java.io.*;
|
|||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import net.i2p.util.I2PThread;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
class PeerConnectionOut implements Runnable
|
class PeerConnectionOut implements Runnable
|
||||||
@ -48,7 +49,7 @@ class PeerConnectionOut implements Runnable
|
|||||||
_id = ++__id;
|
_id = ++__id;
|
||||||
|
|
||||||
quit = false;
|
quit = false;
|
||||||
thread = new Thread(this, "Snark sender " + _id);
|
thread = new I2PThread(this, "Snark sender " + _id);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ package org.klomp.snark;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import net.i2p.util.I2PThread;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -249,7 +250,7 @@ public class PeerCoordinator implements PeerListener
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
String threadName = peer.toString();
|
String threadName = peer.toString();
|
||||||
new Thread(r, threadName).start();
|
new I2PThread(r, threadName).start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (Snark.debug >= Snark.INFO)
|
if (Snark.debug >= Snark.INFO)
|
||||||
|
@ -372,7 +372,11 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
while (true) {
|
while (true) {
|
||||||
File dir = getDataDir();
|
File dir = getDataDir();
|
||||||
_log.debug("Directory Monitor loop over " + dir.getAbsolutePath());
|
_log.debug("Directory Monitor loop over " + dir.getAbsolutePath());
|
||||||
|
try {
|
||||||
monitorTorrents(dir);
|
monitorTorrents(dir);
|
||||||
|
} catch (Exception e) {
|
||||||
|
_log.error("Error in the DirectoryMonitor", e);
|
||||||
|
}
|
||||||
try { Thread.sleep(60*1000); } catch (InterruptedException ie) {}
|
try { Thread.sleep(60*1000); } catch (InterruptedException ie) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,12 @@ package org.klomp.snark;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import net.i2p.util.I2PThread;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes sure everything ends correctly when shutting down.
|
* Makes sure everything ends correctly when shutting down.
|
||||||
*/
|
*/
|
||||||
public class SnarkShutdown extends Thread
|
public class SnarkShutdown extends I2PThread
|
||||||
{
|
{
|
||||||
private final Storage storage;
|
private final Storage storage;
|
||||||
private final PeerCoordinator coordinator;
|
private final PeerCoordinator coordinator;
|
||||||
|
@ -25,6 +25,7 @@ import java.net.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.klomp.snark.bencode.*;
|
import org.klomp.snark.bencode.*;
|
||||||
|
import net.i2p.util.I2PThread;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +34,7 @@ import net.i2p.util.Log;
|
|||||||
*
|
*
|
||||||
* @author Mark Wielaard (mark@klomp.org)
|
* @author Mark Wielaard (mark@klomp.org)
|
||||||
*/
|
*/
|
||||||
public class TrackerClient extends Thread
|
public class TrackerClient extends I2PThread
|
||||||
{
|
{
|
||||||
private static final Log _log = new Log(TrackerClient.class);
|
private static final Log _log = new Log(TrackerClient.class);
|
||||||
private static final String NO_EVENT = "";
|
private static final String NO_EVENT = "";
|
||||||
@ -84,6 +85,16 @@ public class TrackerClient extends Thread
|
|||||||
this.interrupt();
|
this.interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean verifyConnected() {
|
||||||
|
while (!stop && !I2PSnarkUtil.instance().connected()) {
|
||||||
|
boolean ok = I2PSnarkUtil.instance().connect();
|
||||||
|
if (!ok) {
|
||||||
|
try { Thread.sleep(30*1000); } catch (InterruptedException ie) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !stop && I2PSnarkUtil.instance().connected();
|
||||||
|
}
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
// XXX - Support other IPs
|
// XXX - Support other IPs
|
||||||
@ -102,6 +113,7 @@ public class TrackerClient extends Thread
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (!verifyConnected()) return;
|
||||||
boolean started = false;
|
boolean started = false;
|
||||||
while (!started)
|
while (!started)
|
||||||
{
|
{
|
||||||
@ -165,6 +177,8 @@ public class TrackerClient extends Thread
|
|||||||
if (stop)
|
if (stop)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (!verifyConnected()) return;
|
||||||
|
|
||||||
uploaded = coordinator.getUploaded();
|
uploaded = coordinator.getUploaded();
|
||||||
downloaded = coordinator.getDownloaded();
|
downloaded = coordinator.getDownloaded();
|
||||||
left = coordinator.getLeft();
|
left = coordinator.getLeft();
|
||||||
@ -224,6 +238,7 @@ public class TrackerClient extends Thread
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (!verifyConnected()) return;
|
||||||
TrackerInfo info = doRequest(announce, infoHash, peerID, uploaded,
|
TrackerInfo info = doRequest(announce, infoHash, peerID, uploaded,
|
||||||
downloaded, left, STOPPED_EVENT);
|
downloaded, left, STOPPED_EVENT);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
$Id: history.txt,v 1.358 2005/12/16 03:24:22 jrandom Exp $
|
$Id: history.txt,v 1.359 2005/12/16 06:01:20 jrandom Exp $
|
||||||
|
|
||||||
|
2005-12-16 jrandom
|
||||||
|
* Moved I2PSnark from using Threads to I2PThreads, so we handle OOMs
|
||||||
|
properly (thanks Complication!)
|
||||||
|
* More guards in I2PSnark for zany behavior (I2PSession recon w/ skew,
|
||||||
|
b0rking in the DirMonitor, etc)
|
||||||
|
|
||||||
2005-12-16 jrandom
|
2005-12-16 jrandom
|
||||||
* Try to run a torrent in readonly mode if we can't write to the file, and
|
* Try to run a torrent in readonly mode if we can't write to the file, and
|
||||||
|
Reference in New Issue
Block a user