@@ -387,14 +387,17 @@ private void activeTronPump() {
387387
388388 //terminate inactive loop
389389 disconnectInactiveExecutor .scheduleWithFixedDelay (() -> {
390- disconnectInactive ();
390+ try {
391+ disconnectInactive ();
392+ } catch (Throwable t ) {
393+ logger .error ("Unhandled exception" , t );
394+ }
391395 }, 30000 , BlockConstant .BLOCK_INTERVAL / 2 , TimeUnit .MILLISECONDS );
392396
393397 }
394398
395399 private void disconnectInactive () {
396400 getActivePeer ().forEach (peer -> {
397-
398401 final boolean [] isDisconnected = {false };
399402
400403 peer .getAdvObjWeRequested ().values ().stream ()
@@ -409,15 +412,16 @@ private void disconnectInactive() {
409412
410413 //TODO:optimize here
411414 if (!isDisconnected [0 ]) {
412- if (del .getHeadBlockId ().getNum () - peer .getHeadBlockWeBothHave ().getNum () > NetConstants .HEAD_NUM_MAX_DELTA
415+ if (del .getHeadBlockId ().getNum () - peer .getHeadBlockWeBothHave ().getNum ()
416+ > 2 * NetConstants .HEAD_NUM_CHECK_TIME / BlockConstant .BLOCK_INTERVAL
413417 && peer .getConnectTime () < Time .getCurrentMillis () - NetConstants .HEAD_NUM_CHECK_TIME ) {
414418 isDisconnected [0 ] = true ;
415419 }
416420 }
417421
418-
419422 if (isDisconnected [0 ]) {
420- disconnectPeer (peer , ReasonCode .RESET );
423+ //TODO use new reason
424+ disconnectPeer (peer , ReasonCode .USER_REASON );
421425 }
422426 });
423427 }
@@ -921,6 +925,7 @@ public void onDisconnectPeer(PeerConnection peer) {
921925 }
922926
923927 private void disconnectPeer (PeerConnection peer , ReasonCode reason ) {
928+ logger .info ("disconnect with " + peer .getNode ().getHost ());
924929 peer .disconnect (reason );
925930 }
926931}
0 commit comments