* I2PTunnel & I2CP:

- Fix tunnel reduction/restore, hook in the GUI
      - Hook leaseset encryption into the GUI
      - Implement saves for all the new stuff
      - Add cancel button
      - Add b32 display for non-http servers
      - Prep for CONNECT
      - Fix error msg when connection goes away
This commit is contained in:
zzz
2009-02-06 04:22:44 +00:00
parent a82de3d1cf
commit a7d4b3d6ba
10 changed files with 182 additions and 78 deletions

View File

@ -8,12 +8,10 @@ package net.i2p.i2ptunnel.web;
* *
*/ */
import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import net.i2p.i2ptunnel.TunnelController; import net.i2p.i2ptunnel.TunnelController;
@ -107,15 +105,15 @@ public class EditBean extends IndexBean {
} }
public boolean getReduce(int tunnel) { public boolean getReduce(int tunnel) {
return false; return getBooleanProperty(tunnel, "i2cp.reduceOnIdle");
} }
public int getReduceCount(int tunnel) { public int getReduceCount(int tunnel) {
return getProperty(tunnel, "inbound.reduceQuantity", 1); return getProperty(tunnel, "i2cp.reduceQuantity", 1);
} }
public int getReduceTime(int tunnel) { public int getReduceTime(int tunnel) {
return getProperty(tunnel, "reduceIdleTime", 20); return getProperty(tunnel, "i2cp.reduceIdleTime", 20*60*1000) / (60*1000);
} }
public int getCert(int tunnel) { public int getCert(int tunnel) {
@ -131,31 +129,31 @@ public class EditBean extends IndexBean {
} }
public boolean getEncrypt(int tunnel) { public boolean getEncrypt(int tunnel) {
return false; return getBooleanProperty(tunnel, "i2cp.encryptLeaseSet");
} }
public String getEncryptKey(int tunnel) { public String getEncryptKey(int tunnel) {
return getProperty(tunnel, "encryptKey", ""); return getProperty(tunnel, "i2cp.leaseSetKey", "");
} }
public boolean getAccess(int tunnel) { public boolean getAccess(int tunnel) {
return false; return getBooleanProperty(tunnel, "i2cp.enableAccessList");
} }
public String getAccessList(int tunnel) { public String getAccessList(int tunnel) {
return getProperty(tunnel, "accessList", ""); return getProperty(tunnel, "i2cp.accessList", "").replaceAll(",", "\n");
} }
public boolean getClose(int tunnel) { public boolean getClose(int tunnel) {
return false; return getBooleanProperty(tunnel, "i2cp.closeOnIdle");
} }
public int getCloseTime(int tunnel) { public int getCloseTime(int tunnel) {
return getProperty(tunnel, "closeIdleTime", 30); return getProperty(tunnel, "i2cp.closeIdleTime", 30*60*1000) / (60*1000);
} }
public boolean getNewDest(int tunnel) { public boolean getNewDest(int tunnel) {
return false; return getBooleanProperty(tunnel, "i2cp.newDestOnResume");
} }
private int getProperty(int tunnel, String prop, int def) { private int getProperty(int tunnel, String prop, int def) {
@ -183,6 +181,17 @@ public class EditBean extends IndexBean {
return def; return def;
} }
/** default is false */
private boolean getBooleanProperty(int tunnel, String prop) {
TunnelController tun = getController(tunnel);
if (tun != null) {
Properties opts = getOptions(tun);
if (opts != null)
return Boolean.valueOf(opts.getProperty(prop)).booleanValue();
}
return false;
}
public String getI2CPHost(int tunnel) { public String getI2CPHost(int tunnel) {
TunnelController tun = getController(tunnel); TunnelController tun = getController(tunnel);
if (tun != null) if (tun != null)
@ -199,14 +208,6 @@ public class EditBean extends IndexBean {
return "7654"; return "7654";
} }
private static final String noShowProps[] = {
"inbound.length", "outbound.length", "inbound.lengthVariance", "outbound.lengthVariance",
"inbound.backupQuantity", "outbound.backupQuantity", "inbound.quantity", "outbound.quantity",
"inbound.nickname", "outbound.nickname", "i2p.streaming.connectDelay", "i2p.streaming.maxWindowSize"
};
private static final Set noShowSet = new HashSet(noShowProps.length);
static { noShowSet.addAll(Arrays.asList(noShowProps)); }
public String getCustomOptions(int tunnel) { public String getCustomOptions(int tunnel) {
TunnelController tun = getController(tunnel); TunnelController tun = getController(tunnel);
if (tun != null) { if (tun != null) {
@ -216,7 +217,7 @@ public class EditBean extends IndexBean {
int i = 0; int i = 0;
for (Iterator iter = opts.keySet().iterator(); iter.hasNext(); ) { for (Iterator iter = opts.keySet().iterator(); iter.hasNext(); ) {
String key = (String)iter.next(); String key = (String)iter.next();
if (noShowSet.contains(key)) if (_noShowSet.contains(key))
continue; continue;
String val = opts.getProperty(key); String val = opts.getProperty(key);
if (i != 0) buf.append(' '); if (i != 0) buf.append(' ');

View File

@ -8,13 +8,19 @@ package net.i2p.i2ptunnel.web;
* *
*/ */
import java.util.concurrent.ConcurrentHashMap;
import java.util.Arrays;
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.StringTokenizer; import java.util.StringTokenizer;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.i2ptunnel.TunnelController; import net.i2p.i2ptunnel.TunnelController;
import net.i2p.i2ptunnel.TunnelControllerGroup; import net.i2p.i2ptunnel.TunnelControllerGroup;
import net.i2p.util.ConcurrentHashSet;
import net.i2p.util.Log; import net.i2p.util.Log;
/** /**
@ -57,6 +63,8 @@ public class IndexBean {
private boolean _sharedClient; private boolean _sharedClient;
private boolean _privKeyGenerate; private boolean _privKeyGenerate;
private boolean _removeConfirmed; private boolean _removeConfirmed;
private Set<String> _booleanOptions;
private Map<String, String> _otherOptions;
public static final int RUNNING = 1; public static final int RUNNING = 1;
public static final int STARTING = 2; public static final int STARTING = 2;
@ -85,6 +93,8 @@ public class IndexBean {
} catch (NumberFormatException nfe) {} } catch (NumberFormatException nfe) {}
_nextNonce = _context.random().nextLong(); _nextNonce = _context.random().nextLong();
System.setProperty(PROP_NONCE, Long.toString(_nextNonce)); System.setProperty(PROP_NONCE, Long.toString(_nextNonce));
_booleanOptions = new ConcurrentHashSet(4);
_otherOptions = new ConcurrentHashMap(4);
} }
public long getNextNonce() { return _nextNonce; } public long getNextNonce() { return _nextNonce; }
@ -326,6 +336,7 @@ public class IndexBean {
return ( ("client".equals(type)) || return ( ("client".equals(type)) ||
("httpclient".equals(type)) || ("httpclient".equals(type)) ||
("sockstunnel".equals(type)) || ("sockstunnel".equals(type)) ||
("connectclient".equals(type)) ||
("ircclient".equals(type))); ("ircclient".equals(type)));
} }
@ -360,6 +371,7 @@ public class IndexBean {
else if ("server".equals(internalType)) return "Standard server"; else if ("server".equals(internalType)) return "Standard server";
else if ("httpserver".equals(internalType)) return "HTTP server"; else if ("httpserver".equals(internalType)) return "HTTP server";
else if ("sockstunnel".equals(internalType)) return "SOCKS proxy"; else if ("sockstunnel".equals(internalType)) return "SOCKS proxy";
else if ("connectclient".equals(internalType)) return "CONNECT/SSL/HTTPS proxy";
else return internalType; else return internalType;
} }
@ -406,13 +418,12 @@ public class IndexBean {
public String getClientDestination(int tunnel) { public String getClientDestination(int tunnel) {
TunnelController tun = getController(tunnel); TunnelController tun = getController(tunnel);
if (tun == null) return ""; if (tun == null) return "";
if ("client".equals(tun.getType())||"ircclient".equals(tun.getType())) { String rv;
if (tun.getTargetDestination() != null) if ("client".equals(tun.getType())||"ircclient".equals(tun.getType()))
return tun.getTargetDestination(); rv = tun.getTargetDestination();
else else
return ""; rv = tun.getProxyList();
} return rv != null ? rv : "";
else return tun.getProxyList();
} }
public String getServerTarget(int tunnel) { public String getServerTarget(int tunnel) {
@ -429,11 +440,8 @@ public class IndexBean {
String rv = tun.getMyDestination(); String rv = tun.getMyDestination();
if (rv != null) if (rv != null)
return rv; return rv;
else
return "";
} else {
return "";
} }
return "";
} }
public String getDestHashBase32(int tunnel) { public String getDestHashBase32(int tunnel) {
@ -442,11 +450,8 @@ public class IndexBean {
String rv = tun.getMyDestHashBase32(); String rv = tun.getMyDestHashBase32();
if (rv != null) if (rv != null)
return rv; return rv;
else
return "";
} else {
return "";
} }
return "";
} }
/// ///
@ -568,6 +573,49 @@ public class IndexBean {
_profile = profile; _profile = profile;
} }
public void setReduce(String moo) {
_booleanOptions.add("i2cp.reduceOnIdle");
}
public void setClose(String moo) {
_booleanOptions.add("i2cp.closeOnIdle");
}
public void setEncrypt(String moo) {
_booleanOptions.add("i2cp.encryptLeaseSet");
}
public void setAccess(String moo) {
_booleanOptions.add("i2cp.enableAccessList");
}
public void setNewDest(String moo) {
_booleanOptions.add("i2cp.newDestOnResume");
}
public void setReduceTime(String val) {
if (val != null) {
try {
_otherOptions.put("i2cp.reduceIdleTime", "" + (Integer.parseInt(val.trim()) * 60*1000));
} catch (NumberFormatException nfe) {}
}
}
public void setReduceCount(String val) {
if (val != null)
_otherOptions.put("i2cp.reduceQuantity", val.trim());
}
public void setEncryptKey(String val) {
if (val != null)
_otherOptions.put("i2cp.leaseSetKey", val.trim());
}
public void setAccessList(String val) {
if (val != null)
_otherOptions.put("i2cp.accessList", val.trim().replaceAll("\r\n", ",").replaceAll("\n", ",").replaceAll(" ", ","));
}
public void setCloseTime(String val) {
if (val != null) {
try {
_otherOptions.put("i2cp.closeIdleTime", "" + (Integer.parseInt(val.trim()) * 60*1000));
} catch (NumberFormatException nfe) {}
}
}
/** /**
* Based on all provided data, create a set of configuration parameters * Based on all provided data, create a set of configuration parameters
* suitable for use in a TunnelController. This will replace (not add to) * suitable for use in a TunnelController. This will replace (not add to)
@ -593,6 +641,11 @@ public class IndexBean {
config.setProperty("option.outbound.nickname", _name); config.setProperty("option.outbound.nickname", _name);
} }
config.setProperty("sharedClient", _sharedClient + ""); config.setProperty("sharedClient", _sharedClient + "");
for (String p : _booleanClientOpts)
config.setProperty("option." + p, "" + _booleanOptions.contains(p));
for (String p : _otherClientOpts)
if (_otherOptions.containsKey(p))
config.setProperty("option." + p, _otherOptions.get(p));
} else { } else {
// generic server stuff // generic server stuff
if (_targetHost != null) if (_targetHost != null)
@ -601,9 +654,14 @@ public class IndexBean {
config.setProperty("targetPort", _targetPort); config.setProperty("targetPort", _targetPort);
if (_privKeyFile != null) if (_privKeyFile != null)
config.setProperty("privKeyFile", _privKeyFile); config.setProperty("privKeyFile", _privKeyFile);
for (String p : _booleanServerOpts)
config.setProperty("option." + p, "" + _booleanOptions.contains(p));
for (String p : _otherServerOpts)
if (_otherOptions.containsKey(p))
config.setProperty("option." + p, _otherOptions.get(p));
} }
if ("httpclient".equals(_type)) { if ("httpclient".equals(_type) || "connectclient".equals(_type)) {
if (_proxyList != null) if (_proxyList != null)
config.setProperty("proxyList", _proxyList); config.setProperty("proxyList", _proxyList);
} else if ("ircclient".equals(_type) || "client".equals(_type)) { } else if ("ircclient".equals(_type) || "client".equals(_type)) {
@ -617,6 +675,32 @@ public class IndexBean {
return config; return config;
} }
private static final String _noShowOpts[] = {
"inbound.length", "outbound.length", "inbound.lengthVariance", "outbound.lengthVariance",
"inbound.backupQuantity", "outbound.backupQuantity", "inbound.quantity", "outbound.quantity",
"inbound.nickname", "outbound.nickname", "i2p.streaming.connectDelay", "i2p.streaming.maxWindowSize"
};
private static final String _booleanClientOpts[] = {
"i2cp.reduceOnIdle", "i2cp.closeOnIdle", "i2cp.newDestOnResume"
};
private static final String _booleanServerOpts[] = {
"i2cp.reduceOnIdle", "i2cp.encryptLeaseSet", "i2cp.enableAccessList"
};
private static final String _otherClientOpts[] = {
"i2cp.reduceIdleTime", "i2cp.reduceQuantity", "i2cp.closeIdleTime"
};
private static final String _otherServerOpts[] = {
"i2cp.reduceIdleTime", "i2cp.reduceQuantity", "i2cp.leaseSetKey", "i2cp.accessList"
};
protected static final Set _noShowSet = new HashSet();
static {
_noShowSet.addAll(Arrays.asList(_noShowOpts));
_noShowSet.addAll(Arrays.asList(_booleanClientOpts));
_noShowSet.addAll(Arrays.asList(_booleanServerOpts));
_noShowSet.addAll(Arrays.asList(_otherClientOpts));
_noShowSet.addAll(Arrays.asList(_otherServerOpts));
}
private void updateConfigGeneric(Properties config) { private void updateConfigGeneric(Properties config) {
config.setProperty("type", _type); config.setProperty("type", _type);
if (_name != null) if (_name != null)
@ -639,19 +723,9 @@ public class IndexBean {
if ( (eq <= 0) || (eq >= pair.length()) ) if ( (eq <= 0) || (eq >= pair.length()) )
continue; continue;
String key = pair.substring(0, eq); String key = pair.substring(0, eq);
if (_noShowSet.contains(key))
continue;
String val = pair.substring(eq+1); String val = pair.substring(eq+1);
if ("inbound.length".equals(key)) continue;
if ("outbound.length".equals(key)) continue;
if ("inbound.quantity".equals(key)) continue;
if ("outbound.quantity".equals(key)) continue;
if ("inbound.lengthVariance".equals(key)) continue;
if ("outbound.lengthVariance".equals(key)) continue;
if ("inbound.backupQuantity".equals(key)) continue;
if ("outbound.backupQuantity".equals(key)) continue;
if ("inbound.nickname".equals(key)) continue;
if ("outbound.nickname".equals(key)) continue;
if ("i2p.streaming.connectDelay".equals(key)) continue;
if ("i2p.streaming.maxWindowSize".equals(key)) continue;
config.setProperty("option." + key, val); config.setProperty("option." + key, val);
} }
} }
@ -679,7 +753,7 @@ public class IndexBean {
else else
config.setProperty("option.i2p.streaming.connectDelay", "0"); config.setProperty("option.i2p.streaming.connectDelay", "0");
if (_name != null) { if (_name != null) {
if ( ((!"client".equals(_type)) && (!"httpclient".equals(_type))&& (!"ircclient".equals(_type))) || (!_sharedClient) ) { if ( (!isClient(_type)) || (!_sharedClient) ) {
config.setProperty("option.inbound.nickname", _name); config.setProperty("option.inbound.nickname", _name);
config.setProperty("option.outbound.nickname", _name); config.setProperty("option.outbound.nickname", _name);
} else { } else {

View File

@ -116,7 +116,7 @@
<hr /> <hr />
</div> </div>
<% if ("httpclient".equals(tunnelType)) { <% if ("httpclient".equals(tunnelType) || "connectclient".equals(tunnelType)) {
%><div id="destinationField" class="rowItem"> %><div id="destinationField" class="rowItem">
<label for="proxyList" accesskey="x"> <label for="proxyList" accesskey="x">
Outpro<span class="accessKey">x</span>ies: Outpro<span class="accessKey">x</span>ies:
@ -344,6 +344,7 @@
<input type="hidden" value="true" name="removeConfirm" /> <input type="hidden" value="true" name="removeConfirm" />
<button id="controlSave" accesskey="S" class="control" type="submit" name="action" value="Save changes" title="Save Changes"><span class="accessKey">S</span>ave</button> <button id="controlSave" accesskey="S" class="control" type="submit" name="action" value="Save changes" title="Save Changes"><span class="accessKey">S</span>ave</button>
<button id="controlDelete" <%=(editBean.allowJS() ? "onclick=\"if (!confirm('Are you sure you want to delete?')) { return false; }\" " : "")%>accesskey="D" class="control" type="submit" name="action" value="Delete this proxy" title="Delete this Proxy"><span class="accessKey">D</span>elete</button> <button id="controlDelete" <%=(editBean.allowJS() ? "onclick=\"if (!confirm('Are you sure you want to delete?')) { return false; }\" " : "")%>accesskey="D" class="control" type="submit" name="action" value="Delete this proxy" title="Delete this Proxy"><span class="accessKey">D</span>elete</button>
<button id="controlCancel" class="control" type="submit" name="action" value="" title="Cancel">Cancel</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -281,7 +281,7 @@
<label for="accessList" accesskey="s"> <label for="accessList" accesskey="s">
Access List: Access List:
</label> </label>
<textarea rows="2" cols="60" id="hostField" title="Access List" wrap="off"><%=editBean.getAccessList(curTunnel)%></textarea> <textarea rows="2" cols="60" id="hostField" name="accessList" title="Access List" wrap="off"><%=editBean.getAccessList(curTunnel)%></textarea>
<span class="comment">(Restrict to these clients only)</span> <span class="comment">(Restrict to these clients only)</span>
</div> </div>
@ -385,6 +385,7 @@
<input type="hidden" value="true" name="removeConfirm" /> <input type="hidden" value="true" name="removeConfirm" />
<button id="controlSave" accesskey="S" class="control" type="submit" name="action" value="Save changes" title="Save Changes"><span class="accessKey">S</span>ave</button> <button id="controlSave" accesskey="S" class="control" type="submit" name="action" value="Save changes" title="Save Changes"><span class="accessKey">S</span>ave</button>
<button id="controlDelete" <%=(editBean.allowJS() ? "onclick=\"if (!confirm('Are you sure you want to delete?')) { return false; }\" " : "")%>accesskey="D" class="control" type="submit" name="action" value="Delete this proxy" title="Delete this Proxy"><span class="accessKey">D</span>elete</button> <button id="controlDelete" <%=(editBean.allowJS() ? "onclick=\"if (!confirm('Are you sure you want to delete?')) { return false; }\" " : "")%>accesskey="D" class="control" type="submit" name="action" value="Delete this proxy" title="Delete this Proxy"><span class="accessKey">D</span>elete</button>
<button id="controlCancel" class="control" type="submit" name="action" value="" title="Cancel">Cancel</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -114,7 +114,13 @@
<% if (!"sockstunnel".equals(indexBean.getInternalType(curClient))) { %> <% if (!"sockstunnel".equals(indexBean.getInternalType(curClient))) { %>
<div class="destinationField rowItem"> <div class="destinationField rowItem">
<label>Destination:</label> <label>
<% if ("httpclient".equals(indexBean.getInternalType(curClient)) || "connectclient".equals(indexBean.getInternalType(curClient))) { %>
Outproxy:
<% } else { %>
Destination:
<% } %>
</label>
<input class="freetext" size="40" readonly="readonly" value="<%=indexBean.getClientDestination(curClient)%>" /> <input class="freetext" size="40" readonly="readonly" value="<%=indexBean.getClientDestination(curClient)%>" />
</div> </div>
<% } %> <% } %>
@ -143,6 +149,7 @@
<option value="httpclient">HTTP</option> <option value="httpclient">HTTP</option>
<option value="ircclient">IRC</option> <option value="ircclient">IRC</option>
<option value="sockstunnel">SOCKS</option> <option value="sockstunnel">SOCKS</option>
<option value="connectclient">CONNECT</option>
</select> </select>
<input class="control" type="submit" value="Create" /> <input class="control" type="submit" value="Create" />
</div> </div>
@ -162,10 +169,10 @@
<div class="nameHeaderField rowItem"> <div class="nameHeaderField rowItem">
<label>Name:</label> <label>Name:</label>
</div> </div>
<div class="targetHeaderField rowItem"> <div class="previewHeaderField rowItem">
<label>Points at:</label> <label>Points at:</label>
</div> </div>
<div class="previewHeaderField rowItem"> <div class="targetHeaderField rowItem">
<label>Preview:</label> <label>Preview:</label>
</div> </div>
<div class="statusHeaderField rowItem"> <div class="statusHeaderField rowItem">
@ -181,7 +188,7 @@
<label>Name:</label> <label>Name:</label>
<span class="text"><a href="edit.jsp?tunnel=<%=curServer%>" title="Edit Server Tunnel Settings for <%=indexBean.getTunnelName(curServer)%>"><%=indexBean.getTunnelName(curServer)%></a></span> <span class="text"><a href="edit.jsp?tunnel=<%=curServer%>" title="Edit Server Tunnel Settings for <%=indexBean.getTunnelName(curServer)%>"><%=indexBean.getTunnelName(curServer)%></a></span>
</div> </div>
<div class="targetField rowItem"> <div class="previewField rowItem">
<label>Points at:</label> <label>Points at:</label>
<span class="text"> <span class="text">
<% <%
@ -195,11 +202,14 @@
} }
%></span> %></span>
</div> </div>
<div class="previewField rowItem"> <div class="targetField rowItem">
<% <%
if ("httpserver".equals(indexBean.getInternalType(curServer)) && indexBean.getTunnelStatus(curServer) == IndexBean.RUNNING) { if ("httpserver".equals(indexBean.getInternalType(curServer)) && indexBean.getTunnelStatus(curServer) == IndexBean.RUNNING) {
%><label>Preview:</label> %><label>Preview:</label>
<a class="control" title="Test HTTP server through I2P" href="http://<%=indexBean.getDestHashBase32(curServer)%>.b32.i2p">Preview</a> <a class="control" title="Test HTTP server through I2P" href="http://<%=indexBean.getDestHashBase32(curServer)%>.b32.i2p">Preview</a>
<%
} else if (indexBean.getTunnelStatus(curServer) == IndexBean.RUNNING) {
%><span class="text">Base32 Address:<br><%=indexBean.getDestHashBase32(curServer)%>.b32.i2p</span>
<% <%
} else { } else {
%><span class="comment">No Preview</span> %><span class="comment">No Preview</span>

View File

@ -442,8 +442,8 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
long before = System.currentTimeMillis(); long before = System.currentTimeMillis();
_sessionListener.messageAvailable(I2PSessionImpl.this, msgId.intValue(), size.intValue()); _sessionListener.messageAvailable(I2PSessionImpl.this, msgId.intValue(), size.intValue());
long duration = System.currentTimeMillis() - before; long duration = System.currentTimeMillis() - before;
if ((duration > 100) && _log.shouldLog(Log.WARN)) if ((duration > 100) && _log.shouldLog(Log.INFO))
_log.warn("Message availability notification for " + msgId.intValue() + " took " _log.info("Message availability notification for " + msgId.intValue() + " took "
+ duration + " to " + _sessionListener); + duration + " to " + _sessionListener);
} catch (Exception e) { } catch (Exception e) {
_log.log(Log.CRIT, "Error notifying app of message availability", e); _log.log(Log.CRIT, "Error notifying app of message availability", e);
@ -678,6 +678,8 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
_lastActivity = _context.clock().now(); _lastActivity = _context.clock().now();
if (_isReduced) { if (_isReduced) {
_isReduced = false; _isReduced = false;
if (_log.shouldLog(Log.WARN))
_log.warn(getPrefix() + "Restoring original tunnel quantity");
try { try {
_producer.updateTunnels(this, 0); _producer.updateTunnels(this, 0);
} catch (I2PSessionException ise) { } catch (I2PSessionException ise) {

View File

@ -79,15 +79,16 @@ class RequestLeaseSetMessageHandler extends HandlerImpl {
leaseSet.setEncryptionKey(li.getPublicKey()); leaseSet.setEncryptionKey(li.getPublicKey());
leaseSet.setSigningKey(li.getSigningPublicKey()); leaseSet.setSigningKey(li.getSigningPublicKey());
String sk = session.getOptions().getProperty("i2cp.sessionKey"); boolean encrypt = Boolean.valueOf(session.getOptions().getProperty("i2cp.encryptLeaseset")).booleanValue();
if (sk != null) { String sk = session.getOptions().getProperty("i2cp.leaseSetKey");
if (encrypt && sk != null) {
SessionKey key = new SessionKey(); SessionKey key = new SessionKey();
try { try {
key.fromBase64(sk); key.fromBase64(sk);
leaseSet.encrypt(key); leaseSet.encrypt(key);
_context.keyRing().put(session.getMyDestination().calculateHash(), key); _context.keyRing().put(session.getMyDestination().calculateHash(), key);
} catch (DataFormatException dfe) { } catch (DataFormatException dfe) {
_log.error("Bad session key: " + sk); _log.error("Bad leaseset key: " + sk);
} }
} }
try { try {

View File

@ -31,6 +31,7 @@ public class SessionIdleTimer implements SimpleTimer.TimedEvent {
private boolean _shutdownEnabled; private boolean _shutdownEnabled;
private long _shutdownTime; private long _shutdownTime;
private long _minimumTime; private long _minimumTime;
private long _lastActive;
/** /**
* reduce, shutdown, or both must be true * reduce, shutdown, or both must be true
@ -44,6 +45,7 @@ public class SessionIdleTimer implements SimpleTimer.TimedEvent {
throw new IllegalArgumentException("At least one must be enabled"); throw new IllegalArgumentException("At least one must be enabled");
Properties props = session.getOptions(); Properties props = session.getOptions();
_minimumTime = Long.MAX_VALUE; _minimumTime = Long.MAX_VALUE;
_lastActive = 0;
if (reduce) { if (reduce) {
_reduceQuantity = 1; _reduceQuantity = 1;
String p = props.getProperty("i2cp.reduceQuantity"); String p = props.getProperty("i2cp.reduceQuantity");
@ -83,10 +85,16 @@ public class SessionIdleTimer implements SimpleTimer.TimedEvent {
long lastActivity = _session.lastActivity(); long lastActivity = _session.lastActivity();
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("Fire idle timer, last activity: " + DataHelper.formatDuration(now - lastActivity) + " ago "); _log.info("Fire idle timer, last activity: " + DataHelper.formatDuration(now - lastActivity) + " ago ");
long nextDelay = 0;
if (_shutdownEnabled && now - lastActivity >= _shutdownTime) { if (_shutdownEnabled && now - lastActivity >= _shutdownTime) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn("Closing on idle " + _session); _log.warn("Closing on idle " + _session);
_session.destroySession(); _session.destroySession();
return;
} else if (lastActivity <= _lastActive && !_shutdownEnabled) {
if (_log.shouldLog(Log.WARN))
_log.warn("Still idle, sleeping again " + _session);
nextDelay = _reduceTime;
} else if (_reduceEnabled && now - lastActivity >= _reduceTime) { } else if (_reduceEnabled && now - lastActivity >= _reduceTime) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn("Reducing quantity on idle " + _session); _log.warn("Reducing quantity on idle " + _session);
@ -96,11 +104,14 @@ public class SessionIdleTimer implements SimpleTimer.TimedEvent {
_log.error("bork idle reduction " + ise); _log.error("bork idle reduction " + ise);
} }
_session.setReduced(); _session.setReduced();
_lastActive = lastActivity;
if (_shutdownEnabled) if (_shutdownEnabled)
SimpleScheduler.getInstance().addEvent(this, _shutdownTime - (now - lastActivity)); nextDelay = _shutdownTime - (now - lastActivity);
// else sessionimpl must reschedule?? else
nextDelay = _reduceTime;
} else { } else {
SimpleScheduler.getInstance().addEvent(this, _minimumTime - (now - lastActivity)); nextDelay = _minimumTime - (now - lastActivity);
} }
SimpleScheduler.getInstance().addEvent(this, nextDelay);
} }
} }

View File

@ -34,8 +34,13 @@ public class I2CPMessageHandler {
* message - if it is an unknown type or has improper formatting, etc. * message - if it is an unknown type or has improper formatting, etc.
*/ */
public static I2CPMessage readMessage(InputStream in) throws IOException, I2CPMessageException { public static I2CPMessage readMessage(InputStream in) throws IOException, I2CPMessageException {
int length = -1;
try {
length = (int) DataHelper.readLong(in, 4);
} catch (DataFormatException dfe) {
throw new IOException("Connection closed");
}
try { try {
int length = (int) DataHelper.readLong(in, 4);
if (length < 0) throw new I2CPMessageException("Invalid message length specified"); if (length < 0) throw new I2CPMessageException("Invalid message length specified");
int type = (int) DataHelper.readLong(in, 1); int type = (int) DataHelper.readLong(in, 1);
I2CPMessage msg = createMessage(in, length, type); I2CPMessage msg = createMessage(in, length, type);

View File

@ -237,22 +237,20 @@ public class TunnelPoolManager implements TunnelManagerFacade {
return null; return null;
} }
public void setInboundSettings(Hash client, TunnelPoolSettings settings) { public void setInboundSettings(Hash client, TunnelPoolSettings settings) {
setSettings(_clientInboundPools, client, settings);
TunnelPool pool = null;
synchronized (_clientInboundPools) {
pool = (TunnelPool)_clientInboundPools.get(client);
}
if (pool != null)
pool.setSettings(settings);
} }
public void setOutboundSettings(Hash client, TunnelPoolSettings settings) { public void setOutboundSettings(Hash client, TunnelPoolSettings settings) {
setSettings(_clientOutboundPools, client, settings);
}
private void setSettings(Map pools, Hash client, TunnelPoolSettings settings) {
TunnelPool pool = null; TunnelPool pool = null;
synchronized (_clientOutboundPools) { synchronized (pools) {
pool = (TunnelPool)_clientOutboundPools.get(client); pool = (TunnelPool)pools.get(client);
} }
if (pool != null) if (pool != null) {
settings.setDestination(client); // prevent spoofing or unset dest
pool.setSettings(settings); pool.setSettings(settings);
}
} }
public void restart() { public void restart() {