From 12e2dabaa875be3e2e1cc5e576f11f14bff56c14 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Sat, 11 Jul 2020 14:19:01 +0000
Subject: [PATCH] Router: Consistent logging for network ID check Log level
 change for peer test IP

---
 .../networkdb/kademlia/KademliaNetworkDatabaseFacade.java     | 2 +-
 .../net/i2p/router/transport/ntcp/InboundEstablishState.java  | 2 +-
 .../java/src/net/i2p/router/transport/ntcp/NTCPTransport.java | 2 ++
 .../net/i2p/router/transport/udp/EstablishmentManager.java    | 4 +++-
 .../src/net/i2p/router/transport/udp/PeerTestManager.java     | 4 ++--
 .../java/src/net/i2p/router/transport/udp/UDPTransport.java   | 4 ++--
 6 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java
index 5d0494510e..d248494e2b 100644
--- a/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java
+++ b/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java
@@ -1062,7 +1062,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
         if (routerInfo.getNetworkId() != _networkID){
             _context.banlist().banlistRouterForever(key, "Not in our network: " + routerInfo.getNetworkId());
             if (_log.shouldLog(Log.WARN))
-                _log.warn("Bad network: " + routerInfo);
+                _log.warn("Not in our network: " + routerInfo, new Exception());
             return "Not in our network";
         }
         FamilyKeyCrypto fkc = _context.router().getFamilyKeyCrypto();
diff --git a/router/java/src/net/i2p/router/transport/ntcp/InboundEstablishState.java b/router/java/src/net/i2p/router/transport/ntcp/InboundEstablishState.java
index 067ecad53e..b7d0d6f990 100644
--- a/router/java/src/net/i2p/router/transport/ntcp/InboundEstablishState.java
+++ b/router/java/src/net/i2p/router/transport/ntcp/InboundEstablishState.java
@@ -591,7 +591,7 @@ class InboundEstablishState extends EstablishBase implements NTCP2Payload.Payloa
         if (!rv) {
             Hash aliceHash = alice.getHash();
             if (_log.shouldLog(Log.WARN))
-                _log.warn("Dropping inbound connection from wrong network: " + aliceID + ' ' + aliceHash);
+                _log.warn("Not in our network: " + alice, new Exception());
             // So next time we will not accept the con from this IP,
             // rather than doing the whole handshake
             InetAddress addr = _con.getChannel().socket().getInetAddress();
diff --git a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java
index d56c59c7e1..b8bc674fd8 100644
--- a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java
+++ b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java
@@ -531,6 +531,8 @@ public class NTCPTransport extends TransportImpl {
         }
         if (toAddress.getNetworkId() != _networkID) {
             _context.banlist().banlistRouterForever(peer, "Not in our network: " + toAddress.getNetworkId());
+            if (_log.shouldWarn())
+                _log.warn("Not in our network: " + toAddress, new Exception());
             markUnreachable(peer);
             return null;    
         }
diff --git a/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java b/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java
index 59f410df95..1393eb7f4a 100644
--- a/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java
+++ b/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java
@@ -253,8 +253,10 @@ class EstablishmentManager {
         Hash toHash = toIdentity.calculateHash();
         if (toRouterInfo.getNetworkId() != _networkID) {
             _context.banlist().banlistRouterForever(toHash, "Not in our network: " + toRouterInfo.getNetworkId());
+            if (_log.shouldWarn())
+                _log.warn("Not in our network: " + toRouterInfo, new Exception());
             _transport.markUnreachable(toHash);
-            _transport.failed(msg, "Remote peer is on the wrong network, cannot establish");
+            _transport.failed(msg, "Not in our network");
             return;
         }
         UDPAddress addr = new UDPAddress(ra);
diff --git a/router/java/src/net/i2p/router/transport/udp/PeerTestManager.java b/router/java/src/net/i2p/router/transport/udp/PeerTestManager.java
index fd6f04ceeb..3f5a619d92 100644
--- a/router/java/src/net/i2p/router/transport/udp/PeerTestManager.java
+++ b/router/java/src/net/i2p/router/transport/udp/PeerTestManager.java
@@ -393,8 +393,8 @@ class PeerTestManager {
                     if (test.getReceiveBobTime() > 0)
                         testComplete(true);
                 } catch (UnknownHostException uhe) {
-                    if (_log.shouldLog(Log.ERROR))
-                        _log.error("Charlie @ " + from + " said we were an invalid IP address: " + uhe.getMessage(), uhe);
+                    if (_log.shouldWarn())
+                        _log.warn("Charlie @ " + from + " said we were an invalid IP address: " + uhe.getMessage(), uhe);
                     _context.statManager().addRateData("udp.testBadIP", 1);
                 }
             } else {
diff --git a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
index b8e8496fef..abc40021bf 100644
--- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
+++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
@@ -1542,9 +1542,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
                 //_context.banlist().banlistRouter(peerHash, "Part of the wrong network", STYLE);
                 if (peer != null)
                     sendDestroy(peer);
-                dropPeer(peerHash, false, "wrong network");
+                dropPeer(peerHash, false, "Not in our network");
                 if (_log.shouldLog(Log.WARN))
-                    _log.warn("Dropping the peer " + peerHash + " because they are in the wrong net: " + entry);
+                    _log.warn("Not in our network: " + entry, new Exception());
                 return;
             } else {
                 if (entry.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
-- 
GitLab