From 00d39653037aa9cd9dbd7841dbb400fae0a34de4 Mon Sep 17 00:00:00 2001 From: zzz <zzz@i2pmail.org> Date: Sat, 3 Apr 2021 17:12:49 -0400 Subject: [PATCH] SSU: Log enhancement, fix possible log NPE --- .../router/transport/udp/PacketBuilder.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java b/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java index 991f832bb0..e98036f8c7 100644 --- a/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java +++ b/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java @@ -1214,15 +1214,31 @@ class PacketBuilder { long tag = addr.getIntroducerTag(i); long exp = addr.getIntroducerExpiration(i); // let's not use an introducer on a privileged port, sounds like trouble - if (ikey == null || - iaddr == null || tag <= 0 || - // we must use the same isValid() as EstablishmentManager.receiveRelayResponse(). - // If an introducer isn't valid, we shouldn't send to it - !emgr.isValid(iaddr.getAddress(), iport) || - (exp > 0 && exp < cutoff) || + if (iaddr == null) { + if (_log.shouldWarn()) + _log.warn("Cannot build a relay request for " + state.getRemoteIdentity().calculateHash() + + " slot " + i + " no address"); + continue; + } + if (ikey == null || tag <= 0) { + if (_log.shouldWarn()) + _log.warn("Cannot build a relay request for " + state.getRemoteIdentity().calculateHash() + + " slot " + i + " no key/tag"); + continue; + } + if (exp > 0 && exp < cutoff) { + if (_log.shouldWarn()) + _log.warn("Cannot build a relay request for " + state.getRemoteIdentity().calculateHash() + + ", expired " + DataHelper.formatTime(exp) + + " : " + Addresses.toString(iaddr.getAddress(), iport)); + continue; + } + // we must use the same isValid() as EstablishmentManager.receiveRelayResponse(). + // If an introducer isn't valid, we shouldn't send to it + if (!emgr.isValid(iaddr.getAddress(), iport) || // FIXME this will have already failed in isValid() above, right? (Arrays.equals(iaddr.getAddress(), _transport.getExternalIP()) && !_transport.allowLocal())) { - if (_log.shouldLog(Log.WARN)) + if (_log.shouldWarn()) _log.warn("Cannot build a relay request for " + state.getRemoteIdentity().calculateHash() + ", introducer address is invalid or blocklisted: " + Addresses.toString(iaddr.getAddress(), iport)); // TODO implement some sort of introducer banlist -- GitLab