mirror of
https://github.com/i2p/i2p.i2p.git
synced 2024-12-06 19:27:00 +01:00
Merge branch 'ssu1-8' into 'master'
Transports: SSU1 removal part 8/n See merge request i2p-hackers/i2p.i2p!202
This commit is contained in:
@@ -83,16 +83,6 @@ 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
|
||||
*/
|
||||
public final static String PROP_ENABLE_SSU2 = "i2np.ssu2.enable";
|
||||
/** default true */
|
||||
public final static String PROP_ENABLE_NTCP = "i2np.ntcp.enable";
|
||||
/** default true */
|
||||
@@ -268,11 +258,7 @@ public class TransportManager implements TransportEventListener {
|
||||
private void configTransports() {
|
||||
Transport udp = null;
|
||||
if (_enableUDP) {
|
||||
boolean enableSSU1 = false; //_context.getBooleanProperty(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, dh, xdh);
|
||||
udp = new UDPTransport(_context, _xdhThread);
|
||||
addTransport(udp);
|
||||
initializeAddress(udp);
|
||||
}
|
||||
|
||||
@@ -1687,39 +1687,6 @@ public class PeerState {
|
||||
return _transport;
|
||||
}
|
||||
|
||||
/**
|
||||
* A message ID and a timestamp. Used for the resend ACKS.
|
||||
*
|
||||
* SSU 1 only.
|
||||
*
|
||||
* @since 0.9.17
|
||||
*/
|
||||
private static class ResendACK {
|
||||
public final Long id;
|
||||
public final long time;
|
||||
|
||||
public ResendACK(Long id, long time) {
|
||||
this.id = id;
|
||||
this.time = time;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Message ID to sequence number.
|
||||
* Insertion order. Caller must synch.
|
||||
*
|
||||
* SSU 1 only.
|
||||
*
|
||||
* @since 0.9.49
|
||||
*/
|
||||
private static class AckedMessages extends LinkedHashMap<Integer, Long> {
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<Integer, Long> eldest) {
|
||||
return size() > MAX_SEND_MSGS_PENDING;
|
||||
}
|
||||
}
|
||||
|
||||
// why removed? Some risk of dups in OutboundMessageFragments._activePeers ???
|
||||
|
||||
/*
|
||||
|
||||
@@ -51,7 +51,6 @@ import net.i2p.router.transport.TransportBid;
|
||||
import net.i2p.router.transport.TransportImpl;
|
||||
import net.i2p.router.transport.TransportUtil;
|
||||
import static net.i2p.router.transport.TransportUtil.IPv6Config.*;
|
||||
import net.i2p.router.transport.crypto.DHSessionKeyBuilder;
|
||||
import net.i2p.router.transport.crypto.X25519KeyFactory;
|
||||
import static net.i2p.router.transport.udp.PeerTestState.Role.*;
|
||||
import net.i2p.router.util.EventLog;
|
||||
@@ -100,7 +99,6 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
private long _v4IntroducersSelectedOn;
|
||||
private long _v6IntroducersSelectedOn;
|
||||
private long _lastInboundReceivedOn;
|
||||
private final DHSessionKeyBuilder.Factory _dhFactory;
|
||||
private int _mtu = PeerState.MIN_MTU;
|
||||
private int _mtu_ipv6 = PeerState.MIN_IPV6_MTU;
|
||||
private int _mtu_ssu2;
|
||||
@@ -150,8 +148,6 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
static final String SSU2_VERSION = Integer.toString(SSU2_INT_VERSION);
|
||||
/** "2," */
|
||||
static final String SSU2_VERSION_ALT = SSU2_VERSION + ',';
|
||||
private final boolean _enableSSU1;
|
||||
private final boolean _enableSSU2;
|
||||
private final PacketBuilder2 _packetBuilder2;
|
||||
private final X25519KeyFactory _xdhFactory;
|
||||
private final byte[] _ssu2StaticPubKey;
|
||||
@@ -366,25 +362,19 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
|
||||
|
||||
/**
|
||||
* @param dh non-null to enable SSU1
|
||||
* @param xdh non-null to enable SSU2
|
||||
* @param xdh non-null
|
||||
*/
|
||||
public UDPTransport(RouterContext ctx, DHSessionKeyBuilder.Factory dh, X25519KeyFactory xdh) {
|
||||
public UDPTransport(RouterContext ctx, X25519KeyFactory xdh) {
|
||||
super(ctx);
|
||||
_networkID = ctx.router().getNetworkID();
|
||||
_dhFactory = dh;
|
||||
_xdhFactory = xdh;
|
||||
_log = ctx.logManager().getLog(UDPTransport.class);
|
||||
_peersByIdent = new ConcurrentHashMap<Hash, PeerState>(128);
|
||||
_peersByRemoteHost = new ConcurrentHashMap<RemoteHostId, PeerState>(128);
|
||||
_peersByConnID = (xdh != null) ? new ConcurrentHashMap<Long, PeerState2>(32) : null;
|
||||
if (xdh != null) {
|
||||
// roughly scale based on expected traffic
|
||||
int sz = Math.max(16, Math.min(128, getMaxConnections() / 16));
|
||||
_recentlyClosedConnIDs = new DestroyedCache(sz);
|
||||
} else {
|
||||
_recentlyClosedConnIDs = null;
|
||||
}
|
||||
// roughly scale based on expected traffic
|
||||
int sz = Math.max(16, Math.min(128, getMaxConnections() / 16));
|
||||
_recentlyClosedConnIDs = new DestroyedCache(sz);
|
||||
_dropList = new ConcurrentHashSet<RemoteHostId>(2);
|
||||
_endpoints = new CopyOnWriteArrayList<UDPEndpoint>();
|
||||
|
||||
@@ -447,32 +437,25 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
_context.simpleTimer2().addPeriodicEvent(new PingIntroducers(), MIN_EXPIRE_TIMEOUT * 3 / 4);
|
||||
|
||||
// SSU2 key and IV generation if required
|
||||
_enableSSU1 = dh != null;
|
||||
_defaultMTU = _enableSSU1 ? PeerState.LARGE_MTU : PeerState2.DEFAULT_MTU;
|
||||
_mtu_ssu2 = _enableSSU1 ? PeerState2.MIN_SSU_IPV4_MTU : PeerState2.MIN_MTU;
|
||||
_mtu_ssu2_ipv6 = _enableSSU1 ? PeerState2.MIN_SSU_IPV6_MTU : PeerState2.MIN_MTU;
|
||||
boolean enableSSU2 = xdh != null;
|
||||
if (enableSSU2) {
|
||||
_defaultMTU = PeerState2.DEFAULT_MTU;
|
||||
_mtu_ssu2 = PeerState2.MIN_MTU;
|
||||
_mtu_ssu2_ipv6 = PeerState2.MIN_MTU;
|
||||
|
||||
// if any ipv4 address is lower than 1280 MTU, disable
|
||||
Set<String> ipset = Addresses.getAddresses(true, false, false);
|
||||
for (String ips : ipset) {
|
||||
try {
|
||||
InetAddress addr = InetAddress.getByName(ips);
|
||||
int mtu = MTU.getMTU(addr, true);
|
||||
if (mtu > 0 && mtu < PeerState2.MIN_MTU && _enableSSU1) {
|
||||
_log.logAlways(Log.WARN, "Disabling SSU2, MTU is " + mtu + ", minimum is " + PeerState2.MIN_MTU);
|
||||
enableSSU2 = false;
|
||||
break;
|
||||
if (mtu > 0 && mtu < PeerState2.MIN_MTU) {
|
||||
_log.error("MTU too small on address " + ips + "!!!, MTU is " + mtu + ", minimum is " + PeerState2.MIN_MTU);
|
||||
}
|
||||
} catch (UnknownHostException e) {}
|
||||
}
|
||||
}
|
||||
_enableSSU2 = enableSSU2;
|
||||
if (!_enableSSU1 && !_enableSSU2)
|
||||
throw new IllegalArgumentException("Must enable SSU 1 or 2");
|
||||
|
||||
byte[] ikey = null;
|
||||
String b64Ikey = null;
|
||||
if (_enableSSU2) {
|
||||
|
||||
byte[] priv = null;
|
||||
boolean shouldSave = false;
|
||||
String s = null;
|
||||
@@ -516,10 +499,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
changes.put(PROP_SSU2_IKEY, b64Ikey);
|
||||
ctx.router().saveConfig(changes, null);
|
||||
}
|
||||
} else {
|
||||
_ssu2StaticPrivKey = null;
|
||||
_ssu2StaticPubKey = null;
|
||||
}
|
||||
|
||||
_ssu2StaticIntroKey = ikey;
|
||||
_ssu2B64StaticIntroKey = b64Ikey;
|
||||
_ssu2B64StaticPubKey = (_ssu2StaticPubKey != null) ? Base64.encode(_ssu2StaticPubKey) : null;
|
||||
@@ -577,26 +557,6 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
|
||||
if (_log.shouldLog(Log.WARN)) _log.warn("Starting SSU transport listening");
|
||||
|
||||
if (_enableSSU1) {
|
||||
// set up random intro key, as of 0.9.48
|
||||
byte[] ikey = new byte[SessionKey.KEYSIZE_BYTES];
|
||||
_introKey = new SessionKey(ikey);
|
||||
String sikey = _context.getProperty(PROP_INTRO_KEY);
|
||||
if (sikey != null &&
|
||||
_context.getEstimatedDowntime() < MIN_DOWNTIME_TO_REKEY) {
|
||||
byte[] saved = Base64.decode(sikey);
|
||||
if (saved != null && saved.length == SessionKey.KEYSIZE_BYTES) {
|
||||
System.arraycopy(saved, 0, ikey, 0, SessionKey.KEYSIZE_BYTES);
|
||||
} else {
|
||||
_context.random().nextBytes(ikey);
|
||||
_context.router().saveConfig(PROP_INTRO_KEY, Base64.encode(ikey));
|
||||
}
|
||||
} else {
|
||||
_context.random().nextBytes(ikey);
|
||||
_context.router().saveConfig(PROP_INTRO_KEY, Base64.encode(ikey));
|
||||
}
|
||||
}
|
||||
|
||||
// bind host
|
||||
// This is not exposed in the UI and in practice is always null.
|
||||
// We use PROP_EXTERNAL_HOST instead. See below.
|
||||
@@ -731,7 +691,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
_establisher = new EstablishmentManager(_context, this);
|
||||
|
||||
if (_handler == null)
|
||||
_handler = new PacketHandler(_context, this, _enableSSU1, _enableSSU2, _establisher,
|
||||
_handler = new PacketHandler(_context, this, false, true, _establisher,
|
||||
_inboundFragments, _testManager, _introManager);
|
||||
|
||||
// See comments in DummyThrottle.java
|
||||
@@ -1007,12 +967,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
int rv;
|
||||
String style = addr.getTransportStyle();
|
||||
if (style.equals(STYLE)) {
|
||||
if (!_enableSSU2)
|
||||
return 1;
|
||||
rv = 1;
|
||||
} else if (style.equals(STYLE2)) {
|
||||
if (!_enableSSU2)
|
||||
return 0;
|
||||
rv = SSU2_INT_VERSION;
|
||||
} else {
|
||||
return 0;
|
||||
@@ -1026,7 +982,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
addr.getOption("s") == null ||
|
||||
(!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 0;
|
||||
}
|
||||
// his address is SSU2
|
||||
// do not validate the s/i b64, we will just catch it later
|
||||
@@ -1173,7 +1129,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
mtu = PeerState.LARGE_MTU;
|
||||
_mtu = mtu;
|
||||
}
|
||||
if (_enableSSU2 && addr != null) {
|
||||
if (addr != null) {
|
||||
int mtussu2 = MTU.getMTU(addr, true);
|
||||
if (mtussu2 > 0 && mtussu2 < PeerState2.MIN_MTU) {
|
||||
_log.logAlways(Log.WARN, "Low MTU " + mtussu2 + " for interface " + addr + ", consider disabling SSU2");
|
||||
@@ -1196,9 +1152,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
*/
|
||||
public int getMTU(boolean ipv6) {
|
||||
// TODO multiple interfaces of each type
|
||||
if (!_enableSSU1)
|
||||
return getSSU2MTU(ipv6);
|
||||
return ipv6 ? _mtu_ipv6 : _mtu;
|
||||
return getSSU2MTU(ipv6);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1557,14 +1511,13 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
(isIPv6 ? '6' : '4') +
|
||||
" port " + ourPort);
|
||||
}
|
||||
if (_enableSSU2) {
|
||||
|
||||
// flush SSU2 tokens
|
||||
if (ourPort != externalListenPort) {
|
||||
_establisher.portChanged();
|
||||
} else if (externalListenHost != null && !Arrays.equals(ourIP, externalListenHost)) {
|
||||
_establisher.ipChanged(isIPv6);
|
||||
}
|
||||
}
|
||||
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Trying to change our external address to " +
|
||||
@@ -2587,7 +2540,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
List<RouterAddress> addrs = getTargetAddresses(target);
|
||||
for (int i = 0; i < addrs.size(); i++) {
|
||||
RouterAddress addr = addrs.get(i);
|
||||
if (!_enableSSU1 && addr.getTransportStyle().equals("SSU") && !"2".equals(addr.getOption("v")))
|
||||
if (addr.getTransportStyle().equals("SSU") && !"2".equals(addr.getOption("v")))
|
||||
continue;
|
||||
if (addr.getOption("itag0") == null) {
|
||||
// No introducers
|
||||
@@ -2638,7 +2591,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
*/
|
||||
@Override
|
||||
public String getAltStyle() {
|
||||
return _enableSSU2 ? STYLE2 : null;
|
||||
return STYLE2;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2646,7 +2599,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
* @since 0.9.57
|
||||
*/
|
||||
private String getPublishStyle() {
|
||||
return _enableSSU1 ? STYLE : STYLE2;
|
||||
return STYLE2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -3000,7 +2953,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
options.setProperty(UDPAddress.PROP_CAPACITY, caps);
|
||||
if (mtu != _defaultMTU && mtu > 0)
|
||||
options.setProperty(UDPAddress.PROP_MTU, Integer.toString(mtu));
|
||||
if (_enableSSU2 && (mtu >= PeerState2.MIN_MTU || mtu == 0))
|
||||
if (mtu >= PeerState2.MIN_MTU || mtu == 0)
|
||||
addSSU2Options(options);
|
||||
RouterAddress current = getCurrentAddress(false);
|
||||
RouterAddress addr = new RouterAddress(getPublishStyle(), options, SSU_OUTBOUND_COST);
|
||||
@@ -3075,11 +3028,6 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
options.setProperty(UDPAddress.PROP_MTU, Integer.toString(mtu));
|
||||
|
||||
if (directIncluded || introducersIncluded) {
|
||||
// This is called via TransportManager.configTransports() before startup(), prevent NPE
|
||||
// Note that peers won't connect to us without this - see EstablishmentManager
|
||||
if (_enableSSU1 && _introKey != null)
|
||||
options.setProperty(UDPAddress.PROP_INTRO_KEY, _introKey.toBase64());
|
||||
|
||||
// SSU seems to regulate at about 85%, so make it a little higher.
|
||||
// If this is too low, both NTCP and SSU always have incremented cost and
|
||||
// the whole mechanism is not helpful.
|
||||
@@ -3095,7 +3043,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
else if (config == IPV6_NOT_PREFERRED)
|
||||
cost++;
|
||||
}
|
||||
if (_enableSSU2 && (mtu >= PeerState2.MIN_MTU || mtu == 0))
|
||||
if (mtu >= PeerState2.MIN_MTU || mtu == 0)
|
||||
addSSU2Options(options);
|
||||
RouterAddress addr = new RouterAddress(getPublishStyle(), options, cost);
|
||||
|
||||
@@ -3130,8 +3078,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
mtu = getMTU(true);
|
||||
if (mtu != _defaultMTU && mtu > 0)
|
||||
opts.setProperty(UDPAddress.PROP_MTU, Integer.toString(mtu));
|
||||
if (_enableSSU2)
|
||||
addSSU2Options(opts);
|
||||
addSSU2Options(opts);
|
||||
RouterAddress addr6 = new RouterAddress(getPublishStyle(), opts, SSU_OUTBOUND_COST);
|
||||
replaceAddress(addr6);
|
||||
}
|
||||
@@ -3164,7 +3111,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
opts.setProperty(UDPAddress.PROP_CAPACITY, isIPv6 ? CAP_IPV6 : CAP_IPV4);
|
||||
if (mtu != _defaultMTU && mtu > 0)
|
||||
opts.setProperty(UDPAddress.PROP_MTU, Integer.toString(mtu));
|
||||
if (_enableSSU2 && (mtu >= PeerState2.MIN_MTU || mtu == 0))
|
||||
if (mtu >= PeerState2.MIN_MTU || mtu == 0)
|
||||
addSSU2Options(opts);
|
||||
RouterAddress addr = new RouterAddress(getPublishStyle(), opts, SSU_OUTBOUND_COST);
|
||||
RouterAddress current = getCurrentAddress(isIPv6);
|
||||
@@ -4025,10 +3972,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
// which will start up NTCP inbound when we transition to OK.
|
||||
if (isIPv6) {
|
||||
if (STATUS_IPV6_FW_2.contains(status)) {
|
||||
if (_enableSSU2)
|
||||
rebuildExternalAddress(true); // we must publish i/s/v
|
||||
else
|
||||
removeExternalAddress(true, true);
|
||||
rebuildExternalAddress(true); // we must publish i/s/v
|
||||
} else if (STATUS_IPV6_FW_2.contains(old) &&
|
||||
STATUS_IPV6_OK.contains(status) &&
|
||||
!explicitAddressSpecified()){
|
||||
@@ -4134,7 +4078,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
if (peerRole == ALICE)
|
||||
throw new IllegalArgumentException();
|
||||
// if we are or may be symmetric natted, require SSU2 so we don't let an SSU1 test change the state
|
||||
boolean requireV2 = peerRole == BOB && !isIPv6 && _enableSSU2 &&
|
||||
boolean requireV2 = peerRole == BOB && !isIPv6 &&
|
||||
(isSymNatted() || STATUS_IPV4_SYMNAT.contains(_reachabilityStatusPending));
|
||||
List<PeerState> peers = new ArrayList<PeerState>(_peersByIdent.values());
|
||||
for (Iterator<PeerState> iter = new RandomIterator<PeerState>(peers); iter.hasNext(); ) {
|
||||
@@ -4178,7 +4122,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
ip = null;
|
||||
List<RouterAddress> addrs = getTargetAddresses(peerInfo);
|
||||
for (RouterAddress addr : addrs) {
|
||||
if (_enableSSU2) {
|
||||
|
||||
// get the right address
|
||||
String style = addr.getTransportStyle();
|
||||
if (version == 1) {
|
||||
@@ -4188,7 +4132,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
if (style.equals("SSU") && !"2".equals(addr.getOption("v")))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
byte[] rip = addr.getIP();
|
||||
if (rip != null) {
|
||||
if (isIPv6) {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ConnectChecker {
|
||||
* @since 0.9.56
|
||||
*/
|
||||
private boolean isSSU2Enabled() {
|
||||
return ctx.getBooleanPropertyDefaultTrue(TransportManager.PROP_ENABLE_SSU2);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user