SSU2: Fixes part 10

Avoid relaying until it's implemented:
Don't use SSU2 for an SSU address with introducers (fixes NPE)
Don't connect to SSU2 address without host/port
Don't ask for relay tag
Log tweaks
This commit is contained in:
zzz
2022-03-15 07:12:25 -04:00
parent 049456493f
commit 46bba0fe71
2 changed files with 21 additions and 12 deletions

View File

@@ -407,19 +407,21 @@ class EstablishmentManager {
_transport.failed(msg, "Peer has bad key, cannot establish");
return;
}
boolean allowExtendedOptions = VersionComparator.comp(toRouterInfo.getVersion(),
VERSION_ALLOW_EXTENDED_OPTIONS) >= 0
&& !_context.getBooleanProperty(PROP_DISABLE_EXT_OPTS);
// w/o ext options, it's always 'requested', no need to set
// don't ask if they are indirect
boolean requestIntroduction = allowExtendedOptions && !isIndirect &&
_transport.introducersMaybeRequired(TransportUtil.isIPv6(ra));
if (version == 1) {
boolean allowExtendedOptions = VersionComparator.comp(toRouterInfo.getVersion(),
VERSION_ALLOW_EXTENDED_OPTIONS) >= 0
&& !_context.getBooleanProperty(PROP_DISABLE_EXT_OPTS);
// w/o ext options, it's always 'requested', no need to set
// don't ask if they are indirect
boolean requestIntroduction = allowExtendedOptions && !isIndirect &&
_transport.introducersMaybeRequired(TransportUtil.isIPv6(ra));
state = new OutboundEstablishState(_context, maybeTo, to,
toIdentity, allowExtendedOptions,
requestIntroduction,
sessionKey, addr, _transport.getDHFactory());
} else if (version == 2) {
boolean requestIntroduction = SSU2Util.ENABLE_RELAY && !isIndirect &&
_transport.introducersMaybeRequired(TransportUtil.isIPv6(ra));
state = new OutboundEstablishState2(_context, _transport, maybeTo, to,
toIdentity, requestIntroduction, sessionKey, ra, addr);
} else {
@@ -1152,8 +1154,8 @@ class EstablishmentManager {
InboundEstablishState2 state2 = (InboundEstablishState2) state;
InboundEstablishState.InboundState istate = state2.getState();
if (istate == IB_STATE_CREATED_SENT) {
if (_log.shouldDebug())
_log.debug("Send created to: " + state);
if (_log.shouldInfo())
_log.info("Retransmit created to: " + state);
// if already sent, get from the state to retx
pkt = state2.getRetransmitSessionCreatedPacket();
} else if (istate == IB_STATE_REQUEST_RECEIVED) {
@@ -1204,8 +1206,8 @@ class EstablishmentManager {
OutboundEstablishState.OutboundState ostate = state2.getState();
if (ostate == OB_STATE_REQUEST_SENT ||
ostate == OB_STATE_REQUEST_SENT_NEW_TOKEN) {
if (_log.shouldDebug())
_log.debug("Send Session Request to: " + state);
if (_log.shouldInfo())
_log.info("Retransmit Session Request to: " + state);
// if already sent, get from the state to retx
packet = state2.getRetransmitSessionRequestPacket();
} else if (ostate == OB_STATE_NEEDS_TOKEN ||

View File

@@ -922,10 +922,12 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
}
// check version == "2" || version starts with "2,"
// and static key and intro key
// and, until we support relay, host and port.
String v = addr.getOption("v");
if (v == null ||
addr.getOption("i") == null ||
addr.getOption("s") == null ||
(!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;
@@ -2315,6 +2317,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
//if (getSSUVersion(addr) == 0)
// continue;
if (addr.getOption("ihost0") == null) {
// No introducers
// Skip outbound-only or invalid address/port
byte[] ip = addr.getIP();
int port = addr.getPort();
if (ip == null || !TransportUtil.isValidPort(port) ||
@@ -2327,6 +2331,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
String caps = addr.getOption(UDPAddress.PROP_CAPACITY);
if (caps != null && caps.contains(CAP_IPV6) && !_haveIPv6Address)
continue;
// Skip SSU2 with introducers until we support relay
if (_enableSSU2 && !SSU2Util.ENABLE_RELAY && addr.getTransportStyle().equals(STYLE2))
continue;
}
return addr;
}
@@ -3782,7 +3789,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
for (Iterator<PeerState> iter = new RandomIterator<PeerState>(peers); iter.hasNext(); ) {
PeerState peer = iter.next();
// Skip SSU2 until we have support for peer test
if (peer.getVersion() != 1)
if (peer.getVersion() != 1 && !SSU2Util.ENABLE_PEER_TEST)
continue;
if ( (dontInclude != null) && (dontInclude.equals(peer.getRemoteHostId())) )
continue;