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:
jrandom
2005-12-16 23:18:56 +00:00
committed by zzz
parent 6f424fa751
commit 7d234b1978
8 changed files with 47 additions and 12 deletions

View File

@ -26,6 +26,7 @@ import java.net.*;
import net.i2p.I2PException;
import net.i2p.client.streaming.I2PServerSocket;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.util.I2PThread;
/**
* Accepts connections on a TCP port and routes them to sub-acceptors.
@ -47,7 +48,7 @@ public class ConnectionAcceptor implements Runnable
socketChanged = false;
stop = false;
thread = new Thread(this, "I2PSnark acceptor");
thread = new I2PThread(this, "I2PSnark acceptor");
thread.setDaemon(true);
thread.start();
}
@ -105,7 +106,7 @@ public class ConnectionAcceptor implements Runnable
Snark.debug("Null socket accepted, but socket wasn't changed?", Snark.ERROR);
}
} else {
Thread t = new Thread(new Handler(socket), "Connection-" + socket);
Thread t = new I2PThread(new Handler(socket), "Connection-" + socket);
t.start();
}
}

View File

@ -3,9 +3,8 @@ package org.klomp.snark;
import net.i2p.I2PAppContext;
import net.i2p.I2PException;
import net.i2p.util.EepGet;
import net.i2p.data.Base64;
import net.i2p.data.DataFormatException;
import net.i2p.data.Destination;
import net.i2p.client.I2PSession;
import net.i2p.data.*;
import net.i2p.client.streaming.I2PServerSocket;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.client.streaming.I2PSocketManager;
@ -149,7 +148,13 @@ public class I2PSnarkUtil {
}
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) {
if (ip == null) return null;

View File

@ -24,6 +24,7 @@ import java.io.*;
import java.net.*;
import java.util.*;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
class PeerConnectionOut implements Runnable
@ -48,7 +49,7 @@ class PeerConnectionOut implements Runnable
_id = ++__id;
quit = false;
thread = new Thread(this, "Snark sender " + _id);
thread = new I2PThread(this, "Snark sender " + _id);
thread.start();
}

View File

@ -23,6 +23,7 @@ package org.klomp.snark;
import java.util.*;
import java.io.IOException;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
/**
@ -249,7 +250,7 @@ public class PeerCoordinator implements PeerListener
}
};
String threadName = peer.toString();
new Thread(r, threadName).start();
new I2PThread(r, threadName).start();
}
else
if (Snark.debug >= Snark.INFO)

View File

@ -372,7 +372,11 @@ public class SnarkManager implements Snark.CompleteListener {
while (true) {
File dir = getDataDir();
_log.debug("Directory Monitor loop over " + dir.getAbsolutePath());
monitorTorrents(dir);
try {
monitorTorrents(dir);
} catch (Exception e) {
_log.error("Error in the DirectoryMonitor", e);
}
try { Thread.sleep(60*1000); } catch (InterruptedException ie) {}
}
}

View File

@ -22,10 +22,12 @@ package org.klomp.snark;
import java.io.IOException;
import net.i2p.util.I2PThread;
/**
* Makes sure everything ends correctly when shutting down.
*/
public class SnarkShutdown extends Thread
public class SnarkShutdown extends I2PThread
{
private final Storage storage;
private final PeerCoordinator coordinator;

View File

@ -25,6 +25,7 @@ import java.net.*;
import java.util.*;
import org.klomp.snark.bencode.*;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
/**
@ -33,7 +34,7 @@ import net.i2p.util.Log;
*
* @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 String NO_EVENT = "";
@ -84,6 +85,16 @@ public class TrackerClient extends Thread
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()
{
// XXX - Support other IPs
@ -102,6 +113,7 @@ public class TrackerClient extends Thread
try
{
if (!verifyConnected()) return;
boolean started = false;
while (!started)
{
@ -165,6 +177,8 @@ public class TrackerClient extends Thread
if (stop)
break;
if (!verifyConnected()) return;
uploaded = coordinator.getUploaded();
downloaded = coordinator.getDownloaded();
left = coordinator.getLeft();
@ -224,6 +238,7 @@ public class TrackerClient extends Thread
{
try
{
if (!verifyConnected()) return;
TrackerInfo info = doRequest(announce, infoHash, peerID, uploaded,
downloaded, left, STOPPED_EVENT);
}

View File

@ -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
* Try to run a torrent in readonly mode if we can't write to the file, and