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:
zzz
2015-04-22 11:59:40 +00:00
parent 212f6b472a
commit e1d9e05b8d
7 changed files with 124 additions and 25 deletions

View File

@ -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
*/

View File

@ -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);
}
}

View File

@ -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
*/