I2CP: Remove client-side-only options from those sent to router

This commit is contained in:
zzz
2019-01-10 17:08:35 +00:00
parent 5ca98022ab
commit 17228def91

View File

@ -15,6 +15,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import net.i2p.I2PAppContext;
import net.i2p.client.I2PClient;
import net.i2p.client.I2PSessionException;
import net.i2p.client.SendMessageOptions;
import net.i2p.data.DatabaseEntry;
@ -58,6 +59,16 @@ class I2CPMessageProducer {
private static final int TYP_SIZE = 1730 + 28 + 23;
private static final int MIN_RATE = 2 * TYP_SIZE;
// http://i2p-projekt.i2p/en/docs/protocol/i2cp
// Note that some are listed for both client and server side, don't include those below.
private static final String[] CLIENT_SIDE_OPTIONS = new String[] {
"i2cp.closeIdleTime", "i2cp.closeOnIdle", "i2cp.encryptLeaseSet",
"i2cp.gzip", "i2cp.leaseSetKey", "i2cp.leaseSetPrivateKey",
"i2cp.leaseSetSigningPrivateKey", "i2cp.reduceIdleTime", "i2cp.reduceOnIdle",
I2PSessionImpl.PROP_ENABLE_SSL, I2PClient.PROP_TCP_HOST, I2PClient.PROP_TCP_PORT
};
public I2CPMessageProducer(I2PAppContext context) {
_context = context;
_log = context.logManager().getLog(I2CPMessageProducer.class);
@ -86,6 +97,20 @@ class I2CPMessageProducer {
_log.debug("Setting " + _maxBytesPerSecond + " BPS max");
}
/**
* Strip out the client-side options from the session options.
* @return a new copy, may be modified
* @since 0.9.38
*/
private static Properties getRouterOptions(I2PSessionImpl session) {
Properties props = new Properties();
props.putAll(session.getOptions());
for (int i = 0; i < CLIENT_SIDE_OPTIONS.length; i++) {
props.remove(CLIENT_SIDE_OPTIONS[i]);
}
return props;
}
/**
* Send all the messages that a client needs to send to a router to establish
* a new session.
@ -94,7 +119,7 @@ class I2CPMessageProducer {
updateBandwidth(session);
CreateSessionMessage msg = new CreateSessionMessage();
SessionConfig cfg = new SessionConfig(session.getMyDestination());
cfg.setOptions(session.getOptions());
cfg.setOptions(getRouterOptions(session));
if (session.isOffline()) {
cfg.setOfflineSignature(session.getOfflineExpiration(),
session.getTransientSigningPublicKey(),
@ -365,11 +390,8 @@ class I2CPMessageProducer {
public void updateTunnels(I2PSessionImpl session, int tunnels) throws I2PSessionException {
ReconfigureSessionMessage msg = new ReconfigureSessionMessage();
SessionConfig cfg = new SessionConfig(session.getMyDestination());
Properties props = session.getOptions();
Properties props = getRouterOptions(session);
if (tunnels > 0) {
Properties newprops = new Properties();
newprops.putAll(props);
props = newprops;
String stunnels = Integer.toString(tunnels);
props.setProperty("inbound.quantity", stunnels);
props.setProperty("outbound.quantity", stunnels);