Skip to content

Commit

Permalink
Merge pull request #334 from tronprotocol/terminateInactivePeer
Browse files Browse the repository at this point in the history
add try catch modify disconnect parameter
  • Loading branch information
zhaohong authored Mar 30, 2018
2 parents 30c48f1 + 7d31a7d commit bd698b6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/java/org/tron/core/net/node/NodeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,17 @@ private void activeTronPump() {

//terminate inactive loop
disconnectInactiveExecutor.scheduleWithFixedDelay(() -> {
disconnectInactive();
try {
disconnectInactive();
} catch (Throwable t) {
logger.error("Unhandled exception", t);
}
}, 30000, BlockConstant.BLOCK_INTERVAL / 2, TimeUnit.MILLISECONDS);

}

private void disconnectInactive() {
getActivePeer().forEach(peer -> {

final boolean[] isDisconnected = {false};

peer.getAdvObjWeRequested().values().stream()
Expand All @@ -409,15 +412,16 @@ private void disconnectInactive() {

//TODO:optimize here
if (!isDisconnected[0]) {
if (del.getHeadBlockId().getNum() - peer.getHeadBlockWeBothHave().getNum() > NetConstants.HEAD_NUM_MAX_DELTA
if (del.getHeadBlockId().getNum() - peer.getHeadBlockWeBothHave().getNum()
> 2 * NetConstants.HEAD_NUM_CHECK_TIME / BlockConstant.BLOCK_INTERVAL
&& peer.getConnectTime() < Time.getCurrentMillis() - NetConstants.HEAD_NUM_CHECK_TIME) {
isDisconnected[0] = true;
}
}


if (isDisconnected[0]) {
disconnectPeer(peer, ReasonCode.RESET);
//TODO use new reason
disconnectPeer(peer, ReasonCode.USER_REASON);
}
});
}
Expand Down Expand Up @@ -921,6 +925,7 @@ public void onDisconnectPeer(PeerConnection peer) {
}

private void disconnectPeer(PeerConnection peer, ReasonCode reason) {
logger.info("disconnect with " + peer.getNode().getHost());
peer.disconnect(reason);
}
}
Expand Down

0 comments on commit bd698b6

Please sign in to comment.