I2CP Multisession - Work in progress:

Stub out hardcoded list of DSA-only destinations
Tweak client name length in summary bar
Force initial leaseset request for subsession
Send SessionStatus msg before LS request for subsession
This commit is contained in:
zzz
2015-04-19 03:11:37 +00:00
parent be8f7f9676
commit d8baf62966
6 changed files with 48 additions and 8 deletions

View File

@ -435,10 +435,10 @@ public class SummaryHelper extends HelperBase {
buf.append("client.png\" alt=\"Client\" title=\"").append(_("Client")).append("\">"); buf.append("client.png\" alt=\"Client\" title=\"").append(_("Client")).append("\">");
buf.append("</td><td align=\"left\"><b><a href=\"tunnels#").append(h.toBase64().substring(0,4)); buf.append("</td><td align=\"left\"><b><a href=\"tunnels#").append(h.toBase64().substring(0,4));
buf.append("\" target=\"_top\" title=\"").append(_("Show tunnels")).append("\">"); buf.append("\" target=\"_top\" title=\"").append(_("Show tunnels")).append("\">");
if (name.length() < 18) if (name.length() <= 20)
buf.append(DataHelper.escapeHTML(name)); buf.append(DataHelper.escapeHTML(name));
else else
buf.append(DataHelper.escapeHTML(name.substring(0,15))).append("&hellip;"); buf.append(DataHelper.escapeHTML(name.substring(0,18))).append("&hellip;");
buf.append("</a></b></td>\n"); buf.append("</a></b></td>\n");
LeaseSet ls = _context.netDb().lookupLeaseSetLocally(h); LeaseSet ls = _context.netDb().lookupLeaseSetLocally(h);
if (ls != null && _context.tunnelManager().getOutboundClientTunnelCount(h) > 0) { if (ls != null && _context.tunnelManager().getOutboundClientTunnelCount(h) > 0) {

View File

@ -11,6 +11,7 @@ import java.net.Socket;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -29,9 +30,11 @@ import net.i2p.client.streaming.I2PSocketOptions;
import net.i2p.crypto.SigType; import net.i2p.crypto.SigType;
import net.i2p.data.Certificate; import net.i2p.data.Certificate;
import net.i2p.data.Destination; import net.i2p.data.Destination;
import net.i2p.data.Hash;
import net.i2p.data.PrivateKey; import net.i2p.data.PrivateKey;
import net.i2p.data.PublicKey; import net.i2p.data.PublicKey;
import net.i2p.data.SimpleDataStructure; import net.i2p.data.SimpleDataStructure;
import net.i2p.util.ConvertToHash;
import net.i2p.util.Log; import net.i2p.util.Log;
/** /**
@ -57,7 +60,23 @@ public class I2PSocketManagerFull implements I2PSocketManager {
private static final AtomicInteger __managerId = new AtomicInteger(); private static final AtomicInteger __managerId = new AtomicInteger();
private final ConnectionManager _connectionManager; private final ConnectionManager _connectionManager;
private final AtomicBoolean _isDestroyed = new AtomicBoolean(); private final AtomicBoolean _isDestroyed = new AtomicBoolean();
private static final Set<Hash> _dsaOnly = new HashSet<Hash>(16);
private static final String[] DSA_ONLY_HASHES = {
"3t5Ar2NCTIOId70uzX2bZyJljR0aBogxMEzNyHirB7A=" // forum.i2p
};
static {
for (int i = 0; i < DSA_ONLY_HASHES.length; i++) {
String s = DSA_ONLY_HASHES[i];
Hash h = ConvertToHash.getHash(s);
if (h != null)
_dsaOnly.add(h);
else
System.out.println("Bad hash " + s);
}
}
/** /**
* How long to wait for the client app to accept() before sending back CLOSE? * How long to wait for the client app to accept() before sending back CLOSE?
* This includes the time waiting in the queue. Currently set to 5 seconds. * This includes the time waiting in the queue. Currently set to 5 seconds.
@ -401,9 +420,22 @@ public class I2PSocketManagerFull implements I2PSocketManager {
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("Connecting to " + peer.calculateHash().toBase64().substring(0,6) _log.info("Connecting to " + peer.calculateHash().toBase64().substring(0,6)
+ " with options: " + opts); + " with options: " + opts);
// fixme pick the subsession here // pick the subsession here
ConnectionManager cm = _connectionManager;
if (!_subsessions.isEmpty()) {
Hash h = peer.calculateHash();
if (_dsaOnly.contains(h)) {
// FIXME just taking the first one for now
for (Map.Entry<I2PSession, ConnectionManager> e : _subsessions.entrySet()) {
if (e.getKey().getMyDestination().getSigType() == SigType.DSA_SHA1) {
cm = e.getValue();
break;
}
}
}
}
// the following blocks unless connect delay > 0 // the following blocks unless connect delay > 0
Connection con = _connectionManager.connect(peer, opts); Connection con = cm.connect(peer, opts);
if (con == null) if (con == null)
throw new TooManyStreamsException("Too many streams, max " + _defaultOptions.getMaxConns()); throw new TooManyStreamsException("Too many streams, max " + _defaultOptions.getMaxConns());
I2PSocketFull socket = new I2PSocketFull(con,_context); I2PSocketFull socket = new I2PSocketFull(con,_context);

View File

@ -401,7 +401,7 @@ class ClientManager {
public void requestLeaseSet(Destination dest, LeaseSet set, long timeout, Job onCreateJob, Job onFailedJob) { public void requestLeaseSet(Destination dest, LeaseSet set, long timeout, Job onCreateJob, Job onFailedJob) {
ClientConnectionRunner runner = getRunner(dest); ClientConnectionRunner runner = getRunner(dest);
if (runner == null) { if (runner == null) {
if (_log.shouldLog(Log.ERROR)) if (_log.shouldLog(Log.WARN))
_log.warn("Cannot request the lease set, as we can't find a client runner for " _log.warn("Cannot request the lease set, as we can't find a client runner for "
+ dest.calculateHash().toBase64() + ". disconnected?"); + dest.calculateHash().toBase64() + ". disconnected?");
_ctx.jobQueue().addJob(onFailedJob); _ctx.jobQueue().addJob(onFailedJob);
@ -424,6 +424,10 @@ class ClientManager {
if (runner != null) { if (runner != null) {
// no need to fire off any jobs... // no need to fire off any jobs...
runner.requestLeaseSet(dest, ls, REQUEST_LEASESET_TIMEOUT, null, null); runner.requestLeaseSet(dest, ls, REQUEST_LEASESET_TIMEOUT, null, null);
} else {
if (_log.shouldLog(Log.WARN))
_log.warn("Cannot request the lease set, as we can't find a client runner for "
+ dest + ". disconnected?");
} }
} }

View File

@ -289,16 +289,19 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
if (pcfg != null) { if (pcfg != null) {
ClientTunnelSettings settings = new ClientTunnelSettings(dest.calculateHash()); ClientTunnelSettings settings = new ClientTunnelSettings(dest.calculateHash());
settings.readFromProperties(props); settings.readFromProperties(props);
// addAlias() sends the create lease set msg, so we have to send the SMS first
sendStatusMessage(id, status);
boolean ok = _context.tunnelManager().addAlias(dest, settings, pcfg.getDestination()); boolean ok = _context.tunnelManager().addAlias(dest, settings, pcfg.getDestination());
if (!ok) { if (!ok) {
_log.error("Add alias failed"); _log.error("Add alias failed");
status = SessionStatusMessage.STATUS_REFUSED; // FIXME cleanup
} }
} else { } else {
_log.error("no primary config?"); _log.error("no primary config?");
status = SessionStatusMessage.STATUS_INVALID; status = SessionStatusMessage.STATUS_INVALID;
sendStatusMessage(id, status);
// FIXME cleanup
} }
sendStatusMessage(id, status);
} }
} }

View File

@ -34,6 +34,7 @@ public class AliasedTunnelPool extends TunnelPool {
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info(toString() + ": Startup() called, was already alive? " + _alive, new Exception()); _log.info(toString() + ": Startup() called, was already alive? " + _alive, new Exception());
_alive = true; _alive = true;
super.refreshLeaseSet();
} }
@Override @Override

View File

@ -607,7 +607,7 @@ public class TunnelPool {
if (_settings.isInbound() && !_settings.isExploratory()) { if (_settings.isInbound() && !_settings.isExploratory()) {
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug(toString() + ": refreshing leaseSet on tunnel expiration (but prior to grace timeout)"); _log.debug(toString() + ": refreshing leaseSet on tunnel expiration (but prior to grace timeout)");
LeaseSet ls = null; LeaseSet ls;
synchronized (_tunnels) { synchronized (_tunnels) {
ls = locked_buildNewLeaseSet(); ls = locked_buildNewLeaseSet();
} }