forked from I2P_Developers/i2p.i2p
i2ptunnel: Fixes and cleanups for command line testing;
catch IAE from getInstance() if i2ptunnel.config isn't found in app context; log tweaks; config command tweaks Unit tests: Fix several NPEs in LocalClientManager, implement HostLookup
This commit is contained in:
@@ -165,7 +165,9 @@ class ClientConnectionRunner {
|
||||
*/
|
||||
public synchronized void stopRunning() {
|
||||
if (_dead) return;
|
||||
if (_context.router().isAlive() && _log.shouldLog(Log.WARN))
|
||||
// router may be null in unit tests
|
||||
if ((_context.router() == null || _context.router().isAlive()) &&
|
||||
_log.shouldWarn())
|
||||
_log.warn("Stop the I2CP connection! current leaseSet: "
|
||||
+ _currentLeaseSet, new Exception("Stop client connection"));
|
||||
_dead = true;
|
||||
|
@@ -15,6 +15,7 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
import net.i2p.client.I2PClient;
|
||||
import net.i2p.router.Router;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
@@ -101,17 +102,17 @@ class ClientListenerRunner implements Runnable {
|
||||
} catch (IOException ioe) {}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
if (_context.router().isAlive())
|
||||
if (isAlive())
|
||||
_log.error("Server error accepting", ioe);
|
||||
} catch (Throwable t) {
|
||||
if (_context.router().isAlive())
|
||||
if (isAlive())
|
||||
_log.error("Fatal error running client listener - killing the thread!", t);
|
||||
_listening = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
if (_context.router().isAlive())
|
||||
if (isAlive())
|
||||
_log.error("Error listening on port " + _port, ioe);
|
||||
}
|
||||
|
||||
@@ -121,7 +122,7 @@ class ClientListenerRunner implements Runnable {
|
||||
_socket = null;
|
||||
}
|
||||
|
||||
if (!_context.router().isAlive()) break;
|
||||
if (!isAlive()) break;
|
||||
|
||||
if (curDelay < 60*1000)
|
||||
_log.error("Error listening, waiting " + (curDelay/1000) + "s before we try again");
|
||||
@@ -131,11 +132,20 @@ class ClientListenerRunner implements Runnable {
|
||||
curDelay = Math.min(curDelay*3, 60*1000);
|
||||
}
|
||||
|
||||
if (_context.router().isAlive())
|
||||
if (isAlive())
|
||||
_log.error("CANCELING I2CP LISTEN", new Exception("I2CP Listen cancelled!!!"));
|
||||
_running = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Just so unit tests don't NPE, where router could be null.
|
||||
* @since 0.9.20
|
||||
*/
|
||||
private boolean isAlive() {
|
||||
Router r = _context.router();
|
||||
return r == null || r.isAlive();
|
||||
}
|
||||
|
||||
/** give the i2cp client 5 seconds to show that they're really i2cp clients */
|
||||
protected final static int CONNECT_TIMEOUT = 5*1000;
|
||||
private final static int LOOP_DELAY = 250;
|
||||
|
@@ -8,6 +8,8 @@ import net.i2p.data.Lease;
|
||||
import net.i2p.data.LeaseSet;
|
||||
import net.i2p.data.i2cp.I2CPMessageException;
|
||||
import net.i2p.data.i2cp.I2CPMessageReader;
|
||||
import net.i2p.data.i2cp.MessageId;
|
||||
import net.i2p.data.i2cp.MessageStatusMessage;
|
||||
import net.i2p.data.i2cp.RequestVariableLeaseSetMessage;
|
||||
import net.i2p.router.Job;
|
||||
import net.i2p.router.RouterContext;
|
||||
@@ -54,6 +56,27 @@ class LocalClientConnectionRunner extends ClientConnectionRunner {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* No job queue, so super NPEs
|
||||
*/
|
||||
@Override
|
||||
void updateMessageDeliveryStatus(MessageId id, long messageNonce, int status) {
|
||||
if (messageNonce <= 0)
|
||||
return;
|
||||
MessageStatusMessage msg = new MessageStatusMessage();
|
||||
msg.setMessageId(id.getMessageId());
|
||||
msg.setSessionId(getSessionId().getSessionId());
|
||||
// has to be >= 0, it is initialized to -1
|
||||
msg.setNonce(messageNonce);
|
||||
msg.setSize(0);
|
||||
msg.setStatus(status);
|
||||
try {
|
||||
doSend(msg);
|
||||
} catch (I2CPMessageException ime) {
|
||||
_log.warn("Error updating the status for " + id, ime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* So LocalClientMessageEventListener can lookup other local dests
|
||||
*/
|
||||
|
@@ -73,7 +73,7 @@ class LocalClientManager extends ClientManager {
|
||||
ClientManager mgr = new LocalClientManager(ctx, port);
|
||||
mgr.start();
|
||||
System.out.println("Listening on port " + port);
|
||||
try { Thread.sleep(5*60*1000); } catch (InterruptedException ie) {}
|
||||
try { Thread.sleep(60*60*1000); } catch (InterruptedException ie) {}
|
||||
System.out.println("Done listening on port " + port);
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,9 @@ package net.i2p.router.client;
|
||||
*/
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.i2p.data.Base32;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.Lease;
|
||||
@@ -20,7 +22,10 @@ import net.i2p.data.i2cp.CreateLeaseSetMessage;
|
||||
import net.i2p.data.i2cp.DestLookupMessage;
|
||||
import net.i2p.data.i2cp.DestReplyMessage;
|
||||
import net.i2p.data.i2cp.GetBandwidthLimitsMessage;
|
||||
import net.i2p.data.i2cp.HostLookupMessage;
|
||||
import net.i2p.data.i2cp.HostReplyMessage;
|
||||
import net.i2p.data.i2cp.I2CPMessageException;
|
||||
import net.i2p.data.i2cp.SessionId;
|
||||
import net.i2p.router.RouterContext;
|
||||
|
||||
/**
|
||||
@@ -78,6 +83,40 @@ class LocalClientMessageEventListener extends ClientMessageEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Look only in current local dests
|
||||
*/
|
||||
@Override
|
||||
protected void handleHostLookup(HostLookupMessage message) {
|
||||
Hash h = message.getHash();
|
||||
String name = message.getHostname();
|
||||
long reqID = message.getReqID();
|
||||
SessionId sessID = message.getSessionId();
|
||||
if (h == null && name != null && name.length() == 60) {
|
||||
// convert a b32 lookup to a hash lookup
|
||||
String nlc = name.toLowerCase(Locale.US);
|
||||
if (nlc.endsWith(".b32.i2p")) {
|
||||
byte[] b = Base32.decode(nlc.substring(0, 52));
|
||||
if (b != null && b.length == Hash.HASH_LENGTH) {
|
||||
h = Hash.create(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
Destination d = null;
|
||||
if (h != null)
|
||||
d = ((LocalClientConnectionRunner)_runner).localLookup(h);
|
||||
HostReplyMessage msg;
|
||||
if (d != null)
|
||||
msg = new HostReplyMessage(sessID, d, reqID);
|
||||
else
|
||||
msg = new HostReplyMessage(sessID, HostReplyMessage.RESULT_FAILURE, reqID);
|
||||
try {
|
||||
_runner.doSend(msg);
|
||||
} catch (I2CPMessageException ime) {
|
||||
ime.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send dummy limits
|
||||
*/
|
||||
|
Reference in New Issue
Block a user