UDP: Add option to disable SSU 1 - Part 1 - WIP

More todo, do not attempt until feature is completed
This commit is contained in:
zzz
2022-11-30 16:05:38 -05:00
parent f8e0ee65f2
commit d0cd620364
3 changed files with 37 additions and 17 deletions

View File

@ -83,6 +83,11 @@ public class TransportManager implements TransportEventListener {
/** default true */
public final static String PROP_ENABLE_UDP = "i2np.udp.enable";
/**
* Default true for now
* @since 0.9.57
*/
public final static String PROP_ENABLE_SSU1 = "i2np.ssu1.enable";
/**
* Default true as of 0.9.56
* @since 0.9.54
@ -260,9 +265,11 @@ public class TransportManager implements TransportEventListener {
private void configTransports() {
Transport udp = null;
if (_enableUDP) {
boolean enableSSU1 = _context.getBooleanPropertyDefaultTrue(PROP_ENABLE_SSU1);
boolean enableSSU2 = _context.getBooleanPropertyDefaultTrue(PROP_ENABLE_SSU2);
DHSessionKeyBuilder.PrecalcRunner dh = enableSSU1 ? _dhThread : null;
X25519KeyFactory xdh = enableSSU2 ? _xdhThread : null;
udp = new UDPTransport(_context, _dhThread, xdh);
udp = new UDPTransport(_context, dh, xdh);
addTransport(udp);
initializeAddress(udp);
}

View File

@ -40,7 +40,7 @@ class PacketHandler {
private final Map<RemoteHostId, Object> _failCache;
private final BlockingQueue<UDPPacket> _inboundQueue;
private static final Object DUMMY = new Object();
private final boolean _enableSSU2;
private final boolean _enableSSU1, _enableSSU2;
private final int _networkID;
private static final int TYPE_POISON = -99999;
@ -58,11 +58,12 @@ class PacketHandler {
private enum AuthType { NONE, INTRO, BOBINTRO, SESSION }
PacketHandler(RouterContext ctx, UDPTransport transport, boolean enableSSU2, EstablishmentManager establisher,
PacketHandler(RouterContext ctx, UDPTransport transport, boolean enableSSU1, boolean enableSSU2, EstablishmentManager establisher,
InboundMessageFragments inbound, PeerTestManager testManager, IntroductionManager introManager) {
_context = ctx;
_log = ctx.logManager().getLog(PacketHandler.class);
_transport = transport;
_enableSSU1 = enableSSU1;
_enableSSU2 = enableSSU2;
_establisher = establisher;
_inbound = inbound;
@ -264,7 +265,10 @@ class PacketHandler {
_log.debug("Packet received is not for an inbound or outbound establishment");
// ok, not already known establishment, try as a new one
// Last chance for success, using our intro key
receivePacket(reader, packet, PeerType.NEW_PEER);
if (_enableSSU1)
receivePacket(reader, packet, PeerType.NEW_PEER);
else
receiveSSU2Packet(rem, packet, (InboundEstablishState2) null);
}
}
} else {

View File

@ -424,6 +424,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
}
}
_enableSSU2 = enableSSU2;
if (!_enableSSU1 && !_enableSSU2)
throw new IllegalArgumentException("Must enable SSU 1 or 2");
byte[] ikey = null;
String b64Ikey = null;
if (_enableSSU2) {
@ -682,7 +684,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
_establisher = new EstablishmentManager(_context, this);
if (_handler == null)
_handler = new PacketHandler(_context, this, _enableSSU2, _establisher, _inboundFragments, _testManager, _introManager);
_handler = new PacketHandler(_context, this, _enableSSU1, _enableSSU2, _establisher,
_inboundFragments, _testManager, _introManager);
// See comments in DummyThrottle.java
if (USE_PRIORITY && _refiller == null)
@ -765,7 +768,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
OrderedProperties localOpts = new OrderedProperties();
localOpts.setProperty(UDPAddress.PROP_PORT, String.valueOf(newPort));
localOpts.setProperty(UDPAddress.PROP_HOST, newIP);
RouterAddress local = new RouterAddress(STYLE, localOpts, DEFAULT_COST);
RouterAddress local = new RouterAddress(getPublishStyle(), localOpts, DEFAULT_COST);
replaceCurrentExternalAddress(local, true);
if (isIPv6Firewalled() || _context.getBooleanProperty(PROP_IPV6_FIREWALLED)) {
setReachabilityStatus(Status.IPV4_UNKNOWN_IPV6_FIREWALLED, true);
@ -780,7 +783,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
OrderedProperties localOpts = new OrderedProperties();
localOpts.setProperty(UDPAddress.PROP_PORT, String.valueOf(newPort));
localOpts.setProperty(UDPAddress.PROP_HOST, newIP);
RouterAddress local = new RouterAddress(STYLE, localOpts, DEFAULT_COST);
RouterAddress local = new RouterAddress(getPublishStyle(), localOpts, DEFAULT_COST);
replaceCurrentExternalAddress(local, false);
if (isIPv4Firewalled()) {
setReachabilityStatus(Status.IPV4_FIREWALLED_IPV6_UNKNOWN);
@ -962,8 +965,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
(!SSU2Util.ENABLE_RELAY && (addr.getHost() == null || addr.getPort() <= 0)) ||
(!v.equals(SSU2_VERSION) && !v.startsWith(SSU2_VERSION_ALT))) {
// his address is SSU1 or is outbound SSU2 only
//return (rv == 1 && _enableSSU1) ? 1 : 0;
return (rv == 1) ? 1 : 0;
return (rv == 1 && _enableSSU1) ? 1 : 0;
}
// his address is SSU2
// do not validate the s/i b64, we will just catch it later
@ -1460,7 +1462,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
OrderedProperties localOpts = new OrderedProperties();
localOpts.setProperty(UDPAddress.PROP_PORT, String.valueOf(ourPort));
localOpts.setProperty(UDPAddress.PROP_HOST, newIP);
RouterAddress local = new RouterAddress(STYLE, localOpts, DEFAULT_COST);
RouterAddress local = new RouterAddress(getPublishStyle(), localOpts, DEFAULT_COST);
replaceCurrentExternalAddress(local, true);
if (_log.shouldWarn())
_log.warn("New IPv6 address, assuming still firewalled [" +
@ -2469,6 +2471,13 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
return _enableSSU2 ? STYLE2 : null;
}
/**
* @return "SSU" unless SSU1 disabled, then "SSU2"
* @since 0.9.57
*/
private String getPublishStyle() {
return _enableSSU1 ? STYLE : STYLE2;
}
@Override
public void send(OutNetMessage msg) {
@ -2799,7 +2808,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
if (old == null || !host.equals(old.getHost()) || port != old.getPort()) {
options.setProperty(UDPAddress.PROP_PORT, String.valueOf(port));
options.setProperty(UDPAddress.PROP_HOST, host);
RouterAddress local = new RouterAddress(STYLE, options, SSU_OUTBOUND_COST);
RouterAddress local = new RouterAddress(getPublishStyle(), options, SSU_OUTBOUND_COST);
replaceCurrentExternalAddress(local, isIPv6);
options = new OrderedProperties();
}
@ -2824,7 +2833,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
if (_enableSSU2 && (mtu >= PeerState2.MIN_MTU || mtu == 0))
addSSU2Options(options);
RouterAddress current = getCurrentAddress(false);
RouterAddress addr = new RouterAddress(STYLE, options, SSU_OUTBOUND_COST);
RouterAddress addr = new RouterAddress(getPublishStyle(), options, SSU_OUTBOUND_COST);
if (!addr.deepEquals(current)) {
if (_log.shouldInfo())
_log.info("Address rebuilt: " + addr, new Exception());
@ -2915,7 +2924,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
}
if (_enableSSU2 && (mtu >= PeerState2.MIN_MTU || mtu == 0))
addSSU2Options(options);
RouterAddress addr = new RouterAddress(STYLE, options, cost);
RouterAddress addr = new RouterAddress(getPublishStyle(), options, cost);
RouterAddress current = getCurrentAddress(isIPv6);
boolean wantsRebuild = !addr.deepEquals(current);
@ -2929,7 +2938,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
OrderedProperties localOpts = new OrderedProperties();
localOpts.setProperty(UDPAddress.PROP_PORT, String.valueOf(port));
localOpts.setProperty(UDPAddress.PROP_HOST, host);
local = new RouterAddress(STYLE, localOpts, cost);
local = new RouterAddress(getPublishStyle(), localOpts, cost);
}
replaceCurrentExternalAddress(local, isIPv6);
}
@ -2950,7 +2959,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
opts.setProperty(UDPAddress.PROP_MTU, Integer.toString(mtu));
if (_enableSSU2)
addSSU2Options(opts);
RouterAddress addr6 = new RouterAddress(STYLE, opts, SSU_OUTBOUND_COST);
RouterAddress addr6 = new RouterAddress(getPublishStyle(), opts, SSU_OUTBOUND_COST);
replaceAddress(addr6);
}
// warning, this calls back into us with allowRebuildRouterInfo = false,
@ -2975,7 +2984,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
OrderedProperties localOpts = new OrderedProperties();
localOpts.setProperty(UDPAddress.PROP_PORT, String.valueOf(port));
localOpts.setProperty(UDPAddress.PROP_HOST, host);
RouterAddress local = new RouterAddress(STYLE, localOpts, DEFAULT_COST);
RouterAddress local = new RouterAddress(getPublishStyle(), localOpts, DEFAULT_COST);
replaceCurrentExternalAddress(local, isIPv6);
}
// Make an empty "4" or "6" address
@ -2985,7 +2994,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
opts.setProperty(UDPAddress.PROP_MTU, Integer.toString(mtu));
if (_enableSSU2 && (mtu >= PeerState2.MIN_MTU || mtu == 0))
addSSU2Options(opts);
RouterAddress addr = new RouterAddress(STYLE, opts, SSU_OUTBOUND_COST);
RouterAddress addr = new RouterAddress(getPublishStyle(), opts, SSU_OUTBOUND_COST);
RouterAddress current = getCurrentAddress(isIPv6);
boolean wantsRebuild = !addr.deepEquals(current);
if (!wantsRebuild)