2009-04-11 sponge

* i2ptunnel janitorial work and fixes on most locks.
      Some locks still need work, and are marked with LINT in the comment.
      Just grep for "LINT" to see where the remaining places are.
This commit is contained in:
sponge
2009-04-11 13:55:38 +00:00
parent 56c6f41131
commit 879404f7e0
31 changed files with 73 additions and 89 deletions

View File

@ -14,7 +14,7 @@ import net.i2p.util.Log;
*/
class BufferLogger implements Logging {
private final static Log _log = new Log(BufferLogger.class);
private ByteArrayOutputStream _baos;
private ByteArrayOutputStream _baos; // should be final and use a factory. LINT
private boolean _ignore;
/**

View File

@ -59,13 +59,16 @@ class HTTPResponseOutputStream extends FilterOutputStream {
_buf1 = new byte[1];
}
@Override
public void write(int c) throws IOException {
_buf1[0] = (byte)c;
write(_buf1, 0, 1);
}
@Override
public void write(byte buf[]) throws IOException {
write(buf, 0, buf.length);
}
@Override
public void write(byte buf[], int off, int len) throws IOException {
if (_headerWritten) {
out.write(buf, off, len);
@ -207,6 +210,7 @@ class HTTPResponseOutputStream extends FilterOutputStream {
out.write("\r\n".getBytes()); // end of the headers
}
@Override
public void close() throws IOException {
out.close();
}
@ -303,11 +307,13 @@ class HTTPResponseOutputStream extends FilterOutputStream {
return true;
}
}
@Override
public String toString() {
return "Read: " + getTotalRead() + " expanded: " + getTotalExpanded() + " remaining: " + getRemaining() + " finished: " + getFinished();
}
}
@Override
public String toString() {
return super.toString() + ": " + _in;
}

View File

@ -75,7 +75,7 @@ public class I2PTunnel implements Logging, EventDispatcher {
private static long __tunnelId = 0;
private long _tunnelId;
private Properties _clientOptions;
private List _sessions;
private final List _sessions;
public static final int PACKET_DELAY = 100;
@ -89,7 +89,7 @@ public class I2PTunnel implements Logging, EventDispatcher {
private static final String nocli_args[] = { "-nocli", "-die"};
private List tasks = new ArrayList();
private final List tasks = new ArrayList();
private int next_task_id = 1;
private Set listeners = new HashSet();
@ -606,9 +606,9 @@ public class I2PTunnel implements Logging, EventDispatcher {
*/
public void runHttpClient(String args[], Logging l) {
if (args.length >= 1 && args.length <= 3) {
int port = -1;
int clientPort = -1;
try {
port = Integer.parseInt(args[0]);
clientPort = Integer.parseInt(args[0]);
} catch (NumberFormatException nfe) {
l.log("invalid port");
_log.error(getPrefix() + "Port specified is not valid: " + args[0], nfe);
@ -642,12 +642,12 @@ public class I2PTunnel implements Logging, EventDispatcher {
I2PTunnelTask task;
ownDest = !isShared;
try {
task = new I2PTunnelHTTPClient(port, l, ownDest, proxy, (EventDispatcher) this, this);
task = new I2PTunnelHTTPClient(clientPort, l, ownDest, proxy, (EventDispatcher) this, this);
addtask(task);
notifyEvent("httpclientTaskId", Integer.valueOf(task.getId()));
} catch (IllegalArgumentException iae) {
_log.error(getPrefix() + "Invalid I2PTunnel config to create an httpclient [" + host + ":"+ port + "]", iae);
l.log("Invalid I2PTunnel configuration [" + host + ":" + port + "]");
_log.error(getPrefix() + "Invalid I2PTunnel config to create an httpclient [" + host + ":"+ clientPort + "]", iae);
l.log("Invalid I2PTunnel configuration [" + host + ":" + clientPort + "]");
notifyEvent("httpclientTaskId", Integer.valueOf(-1));
}
} else {

View File

@ -44,11 +44,11 @@ public class I2PTunnelClient extends I2PTunnelClientBase {
while (tok.hasMoreTokens()) {
String destination = tok.nextToken();
try {
Destination dest = I2PTunnel.destFromName(destination);
if (dest == null)
Destination destN = I2PTunnel.destFromName(destination);
if (destN == null)
l.log("Could not resolve " + destination);
else
dests.add(dest);
dests.add(destN);
} catch (DataFormatException dfe) {
l.log("Bad format parsing \"" + destination + "\"");
}
@ -71,10 +71,10 @@ public class I2PTunnelClient extends I2PTunnelClientBase {
public long getReadTimeout() { return readTimeout; }
protected void clientConnectionRun(Socket s) {
Destination dest = pickDestination();
Destination destN = pickDestination();
I2PSocket i2ps = null;
try {
i2ps = createI2PSocket(dest);
i2ps = createI2PSocket(destN);
i2ps.setReadTimeout(readTimeout);
new I2PTunnelRunner(s, i2ps, sockLock, null, mySockets);
} catch (Exception ex) {

View File

@ -41,8 +41,8 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
private static volatile long __clientId = 0;
protected long _clientId;
protected Object sockLock = new Object(); // Guards sockMgr and mySockets
protected I2PSocketManager sockMgr;
protected final Object sockLock = new Object(); // Guards sockMgr and mySockets
protected I2PSocketManager sockMgr; // should be final and use a factory. LINT
protected List mySockets = new ArrayList();
protected Destination dest = null;
@ -52,20 +52,20 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
private ServerSocket ss;
private Object startLock = new Object();
private final Object startLock = new Object();
private boolean startRunning = false;
private Object closeLock = new Object();
// private Object closeLock = new Object();
private byte[] pubkey;
// private byte[] pubkey;
private String handlerName;
private String privKeyFile;
private Object conLock = new Object();
// private Object conLock = new Object();
/** List of Socket for those accept()ed but not yet started up */
private List _waitingSockets = new ArrayList();
private List _waitingSockets = new ArrayList(); // should be final and use a factory. LINT
/** How many connections will we allow to be in the process of being built at once? */
private int _numConnectionBuilders;
/** How long will we allow sockets to sit in the _waitingSockets map before killing them? */

View File

@ -17,7 +17,6 @@ import net.i2p.I2PAppContext;
import net.i2p.I2PException;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.client.streaming.I2PSocketOptions;
import net.i2p.data.DataFormatException;
import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
import net.i2p.util.EventDispatcher;
@ -55,7 +54,7 @@ import net.i2p.util.Log;
public class I2PTunnelConnectClient extends I2PTunnelClientBase implements Runnable {
private static final Log _log = new Log(I2PTunnelConnectClient.class);
private List<String> _proxyList;
private final List<String> _proxyList;
private final static byte[] ERR_DESTINATION_UNKNOWN =
("HTTP/1.1 503 Service Unavailable\r\n"+
@ -116,12 +115,12 @@ public class I2PTunnelConnectClient extends I2PTunnelClientBase implements Runna
I2PTunnel tunnel) throws IllegalArgumentException {
super(localPort, ownDest, l, notifyThis, "HTTPHandler " + (++__clientId), tunnel);
_proxyList = new ArrayList();
if (waitEventValue("openBaseClientResult").equals("error")) {
notifyEvent("openConnectClientResult", "error");
return;
}
_proxyList = new ArrayList();
if (wwwProxy != null) {
StringTokenizer tok = new StringTokenizer(wwwProxy, ",");
while (tok.hasMoreTokens())

View File

@ -50,7 +50,7 @@ import net.i2p.util.Log;
public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable {
private static final Log _log = new Log(I2PTunnelHTTPClient.class);
private List proxyList;
private final List proxyList;
private HashMap addressHelpers = new HashMap();
@ -145,12 +145,12 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable
I2PTunnel tunnel) throws IllegalArgumentException {
super(localPort, ownDest, l, notifyThis, "HTTPHandler " + (++__clientId), tunnel);
proxyList = new ArrayList();
if (waitEventValue("openBaseClientResult").equals("error")) {
notifyEvent("openHTTPClientResult", "error");
return;
}
proxyList = new ArrayList();
if (wwwProxy != null) {
StringTokenizer tok = new StringTokenizer(wwwProxy, ",");
while (tok.hasMoreTokens())

View File

@ -30,11 +30,13 @@ public class I2PTunnelHTTPClientRunner extends I2PTunnelRunner {
_log = I2PAppContext.getGlobalContext().logManager().getLog(I2PTunnelHTTPClientRunner.class);
}
@Override
protected OutputStream getSocketOut() throws IOException {
OutputStream raw = super.getSocketOut();
return new HTTPResponseOutputStream(raw);
}
@Override
protected void close(OutputStream out, InputStream in, OutputStream i2pout, InputStream i2pin, Socket s, I2PSocket i2ps, Thread t1, Thread t2) throws InterruptedException, IOException {
try {
i2pin.close();

View File

@ -59,6 +59,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
* Called by the thread pool of I2PSocket handlers
*
*/
@Override
protected void blockingHandle(I2PSocket socket) {
long afterAccept = getTunnel().getContext().clock().now();
long afterSocket = -1;
@ -247,7 +248,9 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
super(o);
}
@Override
protected boolean shouldCompress() { return true; }
@Override
protected void finishHeaders() throws IOException {
if (_log.shouldLog(Log.INFO))
_log.info("Including x-i2p-gzip as the content encoding in the response");
@ -255,6 +258,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
super.finishHeaders();
}
@Override
protected void beginProcessing() throws IOException {
if (_log.shouldLog(Log.INFO))
_log.info("Beginning compression processing");

View File

@ -51,11 +51,11 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable
while (tok.hasMoreTokens()) {
String destination = tok.nextToken();
try {
Destination dest = I2PTunnel.destFromName(destination);
if (dest == null)
Destination destN = I2PTunnel.destFromName(destination);
if (destN == null)
l.log("Could not resolve " + destination);
else
dests.add(dest);
dests.add(destN);
} catch (DataFormatException dfe) {
l.log("Bad format parsing \"" + destination + "\"");
}

View File

@ -3,22 +3,18 @@ package net.i2p.i2ptunnel;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.util.Properties;
import net.i2p.I2PAppContext;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.crypto.SHA256Generator;
import net.i2p.data.DataFormatException;
import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
import net.i2p.data.Hash;
import net.i2p.data.Base32;
import net.i2p.util.EventDispatcher;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
/**
@ -83,6 +79,7 @@ public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable {
this.hostname = opts.getProperty(PROP_HOSTNAME, PROP_HOSTNAME_DEFAULT);
}
@Override
protected void blockingHandle(I2PSocket socket) {
try {
// give them 15 seconds to send in the request

View File

@ -36,7 +36,7 @@ public class I2PTunnelRunner extends I2PThread implements I2PSocket.SocketErrorL
private Socket s;
private I2PSocket i2ps;
Object slock, finishLock = new Object();
final Object slock, finishLock = new Object();
boolean finished = false;
HashMap ostreams, sockets;
byte[] initialI2PData;
@ -114,6 +114,7 @@ public class I2PTunnelRunner extends I2PThread implements I2PSocket.SocketErrorL
protected InputStream getSocketIn() throws IOException { return s.getInputStream(); }
protected OutputStream getSocketOut() throws IOException { return s.getOutputStream(); }
@Override
public void run() {
try {
InputStream in = getSocketIn();
@ -239,6 +240,7 @@ public class I2PTunnelRunner extends I2PThread implements I2PSocket.SocketErrorL
start();
}
@Override
public void run() {
String from = i2ps.getThisDestination().calculateHash().toBase64().substring(0,6);
String to = i2ps.getPeerDestination().calculateHash().toBase64().substring(0,6);

View File

@ -18,8 +18,6 @@ import java.util.Properties;
import net.i2p.I2PAppContext;
import net.i2p.I2PException;
import net.i2p.client.I2PClient;
import net.i2p.client.I2PClientFactory;
import net.i2p.client.streaming.I2PServerSocket;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.client.streaming.I2PSocketManager;
@ -36,8 +34,8 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable {
protected I2PSocketManager sockMgr;
protected I2PServerSocket i2pss;
private Object lock = new Object();
protected Object slock = new Object();
private final Object lock = new Object();
protected final Object slock = new Object();
protected InetAddress remoteHost;
protected int remotePort;
@ -203,17 +201,17 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable {
public void run() {
if (shouldUsePool()) {
I2PServerSocket i2pss = sockMgr.getServerSocket();
I2PServerSocket i2pS_S = sockMgr.getServerSocket();
int handlers = getHandlerCount();
for (int i = 0; i < handlers; i++) {
I2PThread handler = new I2PThread(new Handler(i2pss), "Handle Server " + i);
I2PThread handler = new I2PThread(new Handler(i2pS_S), "Handle Server " + i);
handler.start();
}
} else {
I2PServerSocket i2pss = sockMgr.getServerSocket();
I2PServerSocket i2pS_S = sockMgr.getServerSocket();
while (true) {
try {
final I2PSocket i2ps = i2pss.accept();
final I2PSocket i2ps = i2pS_S.accept();
if (i2ps == null) throw new I2PException("I2PServerSocket closed");
new I2PThread(new Runnable() { public void run() { blockingHandle(i2ps); } }).start();
} catch (I2PException ipe) {

View File

@ -73,6 +73,7 @@ public abstract class I2PTunnelTask implements EventDispatcher {
public void reportAbuse(I2PSession session, int severity) {
}
@Override
public String toString() {
return name;
}

View File

@ -37,11 +37,11 @@ public class I2Ping extends I2PTunnelTask implements Runnable {
private String command;
private long timeout = PING_TIMEOUT;
private Object simulLock = new Object();
private final Object simulLock = new Object();
private int simulPings = 0;
private long lastPingTime = 0;
private Object lock = new Object(), slock = new Object();
private final Object lock = new Object(), slock = new Object();
//public I2Ping(String cmd, Logging l,
// boolean ownDest) {
@ -197,6 +197,7 @@ public class I2Ping extends I2PTunnelTask implements Runnable {
start();
}
@Override
public void run() {
try {
Destination dest = I2PTunnel.destFromName(destination);

View File

@ -40,7 +40,7 @@ public class TunnelControllerGroup {
* no more tunnels are using it)
*
*/
private Map _sessions;
private final Map _sessions;
public static TunnelControllerGroup getInstance() {
synchronized (TunnelControllerGroup.class) {

View File

@ -1,6 +1,5 @@
package net.i2p.i2ptunnel.socks;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
import net.i2p.data.Destination;

View File

@ -379,7 +379,7 @@ public class SOCKS5Server extends SOCKSServer {
// This isn't really the right place for this, we can't stop the tunnel once it starts.
static SOCKSUDPTunnel _tunnel;
static Object _startLock = new Object();
static final Object _startLock = new Object();
static byte[] dummyIP = new byte[4];
/**
* We got a UDP associate command.

View File

@ -9,7 +9,6 @@ package net.i2p.i2ptunnel.socks;
import java.net.Socket;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.i2ptunnel.I2PTunnel;
import net.i2p.util.Log;
/**

View File

@ -7,10 +7,7 @@ import java.util.Map;
import net.i2p.data.Destination;
import net.i2p.i2ptunnel.I2PTunnel;
import net.i2p.i2ptunnel.Logging;
import net.i2p.i2ptunnel.udp.*;
import net.i2p.i2ptunnel.udpTunnel.I2PTunnelUDPClientBase;
import net.i2p.util.EventDispatcher;
/**
* A Datagram Tunnel that can have multiple bidirectional ports on the UDP side.
@ -63,12 +60,14 @@ public class SOCKSUDPTunnel extends I2PTunnelUDPClientBase {
}
}
@Override
public final void startRunning() {
super.startRunning();
// demuxer start() doesn't do anything
startall();
}
@Override
public boolean close(boolean forced) {
stopall();
return super.close(forced);

View File

@ -54,6 +54,6 @@ public class Pinger implements Source, Runnable {
protected Sink sink;
protected Thread thread;
protected Object waitlock;
protected Object waitlock; // should be final and use a factory. LINT
protected boolean running;
}

View File

@ -7,7 +7,6 @@ package net.i2p.i2ptunnel.streamr;
import java.net.InetAddress;
import net.i2p.data.Destination;
import net.i2p.i2ptunnel.I2PTunnel;
import net.i2p.i2ptunnel.Logging;
import net.i2p.i2ptunnel.udp.*;
@ -38,6 +37,7 @@ public class StreamrConsumer extends I2PTunnelUDPClientBase {
this.pinger.setSink(this);
}
@Override
public final void startRunning() {
super.startRunning();
// send subscribe-message
@ -45,6 +45,7 @@ public class StreamrConsumer extends I2PTunnelUDPClientBase {
l.log("Streamr client ready");
}
@Override
public boolean close(boolean forced) {
// send unsubscribe-message
this.pinger.stop();

View File

@ -9,7 +9,6 @@ package net.i2p.i2ptunnel.streamr;
import java.io.File;
// i2p
import net.i2p.client.I2PSession;
import net.i2p.i2ptunnel.I2PTunnel;
import net.i2p.i2ptunnel.Logging;
import net.i2p.i2ptunnel.udp.*;
@ -45,12 +44,14 @@ public class StreamrProducer extends I2PTunnelUDPServerBase {
this.server.setSink(this.multi);
}
@Override
public final void startRunning() {
super.startRunning();
this.server.start();
l.log("Streamr server ready");
}
@Override
public boolean close(boolean forced) {
this.server.stop();
this.multi.stop();

View File

@ -6,17 +6,12 @@
package net.i2p.i2ptunnel.streamr;
// system
import java.io.File;
import java.util.Set;
// i2p
import net.i2p.client.I2PSession;
import net.i2p.data.Destination;
import net.i2p.i2ptunnel.I2PTunnel;
import net.i2p.i2ptunnel.Logging;
import net.i2p.i2ptunnel.udp.*;
import net.i2p.i2ptunnel.udpTunnel.I2PTunnelUDPServerBase;
import net.i2p.util.EventDispatcher;
import net.i2p.util.ConcurrentHashSet;
/**

View File

@ -69,5 +69,5 @@ public class I2PSink implements Sink {
protected boolean raw;
protected I2PSession sess;
protected Destination dest;
protected I2PDatagramMaker maker;
protected I2PDatagramMaker maker; // should be final and use a factory. LINT
}

View File

@ -67,5 +67,5 @@ public class I2PSinkAnywhere implements Sink {
protected boolean raw;
protected I2PSession sess;
protected Destination dest;
protected I2PDatagramMaker maker;
protected I2PDatagramMaker maker; // should be final and use a factory. LINT
}

View File

@ -5,21 +5,9 @@ package net.i2p.i2ptunnel.udpTunnel;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.NoRouteToHostException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import net.i2p.I2PAppContext;
import net.i2p.I2PException;
import net.i2p.client.I2PClient;
import net.i2p.client.I2PClientFactory;
import net.i2p.client.I2PSession;
@ -31,7 +19,6 @@ import net.i2p.i2ptunnel.I2PTunnelTask;
import net.i2p.i2ptunnel.Logging;
import net.i2p.i2ptunnel.udp.*;
import net.i2p.util.EventDispatcher;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
/**
@ -107,11 +94,11 @@ import net.i2p.util.Log;
// create i2pclient and destination
I2PClient client = I2PClientFactory.createClient();
Destination dest;
Destination destN;
byte[] key;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream(512);
dest = client.createDestination(out);
destN = client.createDestination(out);
key = out.toByteArray();
} catch(Exception exc) {
throw new RuntimeException("failed to create i2p-destination", exc);

View File

@ -3,33 +3,22 @@
*/
package net.i2p.i2ptunnel.udpTunnel;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.Iterator;
import java.util.Properties;
import net.i2p.I2PAppContext;
import net.i2p.I2PException;
import net.i2p.client.I2PClient;
import net.i2p.client.I2PClientFactory;
import net.i2p.client.I2PSession;
import net.i2p.client.I2PSessionException;
import net.i2p.data.Base64;
import net.i2p.data.Destination;
import net.i2p.i2ptunnel.I2PTunnel;
import net.i2p.i2ptunnel.I2PTunnelTask;
import net.i2p.i2ptunnel.Logging;
import net.i2p.i2ptunnel.udp.*;
import net.i2p.util.EventDispatcher;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
/**
@ -59,7 +48,7 @@ public class I2PTunnelUDPServerBase extends I2PTunnelTask implements Source, Sin
private final static Log _log = new Log(I2PTunnelUDPServerBase.class);
private Object lock = new Object();
private final Object lock = new Object();
protected Object slock = new Object();
private static volatile long __serverId = 0;

View File

@ -8,7 +8,6 @@ package net.i2p.i2ptunnel.web;
*
*/
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;

View File

@ -1,3 +1,8 @@
2009-04-11 sponge
* i2ptunnel janitorial work and fixes on most locks.
Some locks still need work, and are marked with LINT in the comment.
Just grep for "LINT" to see where the remaining places are.
2009-04-10 sponge
* More BOB threadgroup fixes, plus debug dump when things go wrong.
* Fixes to streaminglib, I2CP, which are related to the TG problem.

View File

@ -17,7 +17,7 @@ import net.i2p.CoreVersion;
public class RouterVersion {
public final static String ID = "$Revision: 1.548 $ $Date: 2008-06-07 23:00:00 $";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 15;
public final static long BUILD = 16;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);