From 78295838ecbc9a26ace05c6207ae3b23d9f6ab37 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Thu, 29 Mar 2018 21:39:41 +0800 Subject: [PATCH 1/2] mdf pong msg --- src/main/java/org/tron/common/overlay/discover/NodeHandler.java | 2 +- .../java/org/tron/common/overlay/server/HandshakeHandler.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/tron/common/overlay/discover/NodeHandler.java b/src/main/java/org/tron/common/overlay/discover/NodeHandler.java index e48d59e2e83..39c60d6d1ed 100644 --- a/src/main/java/org/tron/common/overlay/discover/NodeHandler.java +++ b/src/main/java/org/tron/common/overlay/discover/NodeHandler.java @@ -281,7 +281,7 @@ void sendPing() { } void sendPong() { - Message pong = new PongMessage(node); + Message pong = new PongMessage(nodeManager.getPublicHomeNode()); logMessage(pong, false); sendMessage(pong); getNodeStatistics().discoverOutPong.add(); diff --git a/src/main/java/org/tron/common/overlay/server/HandshakeHandler.java b/src/main/java/org/tron/common/overlay/server/HandshakeHandler.java index a16b553e13e..6e0e0ccf935 100644 --- a/src/main/java/org/tron/common/overlay/server/HandshakeHandler.java +++ b/src/main/java/org/tron/common/overlay/server/HandshakeHandler.java @@ -83,6 +83,8 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List ou final HelloMessage helloMessage = (HelloMessage) msg; if (helloMessage.getVersion() != Args.getInstance().getNodeP2pVersion()) { + logger.info("version not support, you[{}] version[{}], my version[{}]", + ctx.channel().remoteAddress(), helloMessage.getVersion(), Args.getInstance().getNodeP2pVersion()); ctx.close(); return; } From 86d120fc6e3917b987e9b4a1e32d9501bc8fcb04 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Fri, 30 Mar 2018 12:42:14 +0800 Subject: [PATCH 2/2] mdf nodemanager change active peer init time --- .../common/overlay/discover/NodeManager.java | 16 ++++++++++++---- .../org/tron/common/overlay/server/SyncPool.java | 4 +--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/tron/common/overlay/discover/NodeManager.java b/src/main/java/org/tron/common/overlay/discover/NodeManager.java index 3d906851c61..d8d992a3ca3 100644 --- a/src/main/java/org/tron/common/overlay/discover/NodeManager.java +++ b/src/main/java/org/tron/common/overlay/discover/NodeManager.java @@ -94,9 +94,7 @@ public void run() { this.pongTimer = Executors.newSingleThreadScheduledExecutor(); - for (Node node : args.getNodeActive()) { - getNodeHandler(node).getNodeStatistics().setPredefined(true); - } + } public ScheduledExecutorService getPongTimer() { @@ -132,9 +130,19 @@ public void run() { for (Node node : bootNodes) { getNodeHandler(node); } + + for (Node node : args.getNodeActive()) { + getNodeHandler(node).getNodeStatistics().setPredefined(true); + } } } + public boolean isNodeAlive(NodeHandler nodeHandler){ + return nodeHandler.state.equals(State.Alive) || + nodeHandler.state.equals(State.Active) || + nodeHandler.state.equals(State.EvictCandidate); + } + private void dbRead() { Set Nodes = this.dbManager.readNeighbours(); logger.info("Reading Node statistics from PeersStore: " + Nodes.size() + " nodes."); @@ -145,7 +153,7 @@ private void dbWrite() { Set batch = new HashSet<>(); synchronized (this) { for (NodeHandler nodeHandler: nodeHandlerMap.values()){ - if (!nodeHandler.state.equals(NodeHandler.State.Dead)) { + if (isNodeAlive(nodeHandler)) { batch.add(nodeHandler.getNode()); } } diff --git a/src/main/java/org/tron/common/overlay/server/SyncPool.java b/src/main/java/org/tron/common/overlay/server/SyncPool.java index 329f2c1fb89..bd0d594c919 100644 --- a/src/main/java/org/tron/common/overlay/server/SyncPool.java +++ b/src/main/java/org/tron/common/overlay/server/SyncPool.java @@ -195,9 +195,7 @@ public boolean test(NodeHandler handler) { //TODO: use reputation sysytem - if (handler.getState().equals(NodeHandler.State.Discovered) || - handler.getState().equals(NodeHandler.State.Dead) || - handler.getState().equals(NodeHandler.State.NonActive)){ + if (!nodeManager.isNodeAlive(handler)){ return false; }