From dc0a91fd2e1254160f32520e926b8f563171bd29 Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Wed, 2 Aug 2023 16:03:47 +0800 Subject: [PATCH 1/2] feat(net):supplement disconnect reasons --- .../org/tron/core/net/message/sync/ChainInventoryMessage.java | 1 + framework/src/main/java/org/tron/core/net/peer/PeerManager.java | 2 ++ .../main/java/org/tron/core/net/service/relay/RelayService.java | 2 ++ protocol/src/main/protos/core/Tron.proto | 1 + 4 files changed, 6 insertions(+) diff --git a/framework/src/main/java/org/tron/core/net/message/sync/ChainInventoryMessage.java b/framework/src/main/java/org/tron/core/net/message/sync/ChainInventoryMessage.java index 4179544ebf7..610a5ff2f11 100644 --- a/framework/src/main/java/org/tron/core/net/message/sync/ChainInventoryMessage.java +++ b/framework/src/main/java/org/tron/core/net/message/sync/ChainInventoryMessage.java @@ -73,6 +73,7 @@ public String toString() { sb.append(", end blockId: ").append(blockIdWeGet.peekLast().getString()); } } + sb.append(", remain_num: ").append(chainInventory.getRemainNum()); return sb.toString(); } } diff --git a/framework/src/main/java/org/tron/core/net/peer/PeerManager.java b/framework/src/main/java/org/tron/core/net/peer/PeerManager.java index 6817720dff5..4b5921683ad 100644 --- a/framework/src/main/java/org/tron/core/net/peer/PeerManager.java +++ b/framework/src/main/java/org/tron/core/net/peer/PeerManager.java @@ -16,6 +16,7 @@ import org.tron.common.prometheus.MetricLabels; import org.tron.common.prometheus.Metrics; import org.tron.p2p.connection.Channel; +import org.tron.protos.Protocol.ReasonCode; @Slf4j(topic = "net") public class PeerManager { @@ -45,6 +46,7 @@ public static void close() { try { for (PeerConnection p : new ArrayList<>(peers)) { if (!p.isDisconnect()) { + p.disconnect(ReasonCode.PEER_QUITING); p.getChannel().close(); } } diff --git a/framework/src/main/java/org/tron/core/net/service/relay/RelayService.java b/framework/src/main/java/org/tron/core/net/service/relay/RelayService.java index 665255a6594..7ac870bd054 100644 --- a/framework/src/main/java/org/tron/core/net/service/relay/RelayService.java +++ b/framework/src/main/java/org/tron/core/net/service/relay/RelayService.java @@ -34,6 +34,7 @@ import org.tron.core.store.WitnessScheduleStore; import org.tron.p2p.connection.Channel; import org.tron.protos.Protocol; +import org.tron.protos.Protocol.ReasonCode; @Slf4j(topic = "net") @Component @@ -182,6 +183,7 @@ private void disconnect() { TronNetService.getP2pConfig().getActiveNodes().remove(address); TronNetService.getPeers().forEach(peer -> { if (peer.getInetAddress().equals(address.getAddress())) { + peer.disconnect(ReasonCode.NOT_WITNESS); peer.getChannel().close(); } }); diff --git a/protocol/src/main/protos/core/Tron.proto b/protocol/src/main/protos/core/Tron.proto index aa6a96ba1b3..730d51a45d5 100644 --- a/protocol/src/main/protos/core/Tron.proto +++ b/protocol/src/main/protos/core/Tron.proto @@ -601,6 +601,7 @@ enum ReasonCode { TOO_MANY_PEERS_WITH_SAME_IP = 0x22; LIGHT_NODE_SYNC_FAIL = 0x23; BELOW_THAN_ME = 0X24; + NOT_WITNESS = 0x25; UNKNOWN = 0xFF; } From 9ce2b834d6ae2df39cc7828c1efb0e9f2f6bb9b4 Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Wed, 30 Aug 2023 15:41:42 +0800 Subject: [PATCH 2/2] add ReasonCode NO_SUCH_MESSAGE --- .../src/main/java/org/tron/core/net/P2pEventHandlerImpl.java | 4 +++- protocol/src/main/protos/core/Tron.proto | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/src/main/java/org/tron/core/net/P2pEventHandlerImpl.java b/framework/src/main/java/org/tron/core/net/P2pEventHandlerImpl.java index 10615b70ce3..7518b1347a7 100644 --- a/framework/src/main/java/org/tron/core/net/P2pEventHandlerImpl.java +++ b/framework/src/main/java/org/tron/core/net/P2pEventHandlerImpl.java @@ -38,6 +38,7 @@ import org.tron.p2p.P2pEventHandler; import org.tron.p2p.connection.Channel; import org.tron.protos.Protocol; +import org.tron.protos.Protocol.ReasonCode; @Slf4j(topic = "net") @Component @@ -232,7 +233,8 @@ private void processException(PeerConnection peer, TronMessage msg, Exception ex code = Protocol.ReasonCode.BAD_BLOCK; break; case NO_SUCH_MESSAGE: - case MESSAGE_WITH_WRONG_LENGTH: + code = Protocol.ReasonCode.NO_SUCH_MESSAGE; + break; case BAD_MESSAGE: code = Protocol.ReasonCode.BAD_PROTOCOL; break; diff --git a/protocol/src/main/protos/core/Tron.proto b/protocol/src/main/protos/core/Tron.proto index 730d51a45d5..2fc08901e93 100644 --- a/protocol/src/main/protos/core/Tron.proto +++ b/protocol/src/main/protos/core/Tron.proto @@ -602,6 +602,7 @@ enum ReasonCode { LIGHT_NODE_SYNC_FAIL = 0x23; BELOW_THAN_ME = 0X24; NOT_WITNESS = 0x25; + NO_SUCH_MESSAGE = 0x26; UNKNOWN = 0xFF; }