Skip to content

Commit

Permalink
Merge pull request #328 from tronprotocol/p2p
Browse files Browse the repository at this point in the history
mdf send pong msg && change active node init time
  • Loading branch information
olenheim authored Mar 30, 2018
2 parents 1e3200c + 86d120f commit dd7a4e9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/tron/common/overlay/discover/NodeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ public void run() {

this.pongTimer = Executors.newSingleThreadScheduledExecutor();

for (Node node : args.getNodeActive()) {
getNodeHandler(node).getNodeStatistics().setPredefined(true);
}

}

public ScheduledExecutorService getPongTimer() {
Expand Down Expand Up @@ -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<Node> Nodes = this.dbManager.readNeighbours();
logger.info("Reading Node statistics from PeersStore: " + Nodes.size() + " nodes.");
Expand All @@ -145,7 +153,7 @@ private void dbWrite() {
Set<Node> batch = new HashSet<>();
synchronized (this) {
for (NodeHandler nodeHandler: nodeHandlerMap.values()){
if (!nodeHandler.state.equals(NodeHandler.State.Dead)) {
if (isNodeAlive(nodeHandler)) {
batch.add(nodeHandler.getNode());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> 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;
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/tron/common/overlay/server/SyncPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit dd7a4e9

Please sign in to comment.