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/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/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; } 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 8f01567e038..90721acfdd8 100644 --- a/src/main/java/org/tron/common/overlay/server/SyncPool.java +++ b/src/main/java/org/tron/common/overlay/server/SyncPool.java @@ -199,9 +199,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; }