-
Notifications
You must be signed in to change notification settings - Fork 279
Description
TIP: 592
Title: Supplement Disconnect Reasons in Java-tron
Author: 317787106@qq.com
Status: Draft
Type: Standards Track
Category: Networking
Created: 2023-09-13
Simple Summary
This TIP describes why and how we supplement disconnect reasons in java-tron.
Abstract
We supplement two disconnect reasons in java-tron, including NOT_WITNESS used inRelayService and NO_SUCH_MESSAGE in P2pEventHandlerImpl, so other peers can acquire the reason why we disconnect with it better.
Motivation
Java-tron nodes send DisconnectMessage to peers before stopping the connection. When stopping, the nodes use relatedReasonCode if it exists as DisconnectMessage, otherwise, no message would be sent. Most java-tron logs record the ReasonCode of peer disconnection, but some do not. For example, the reason for disconnection with non-witness nodes in RelayService is not given.
Specification
Unused ReasonCode
We summarize the use of ReasonCode, many of which have been abandoned and some are moved to libp2p, they may get deleted in the future:
enum ReasonCode {
REQUESTED = 0x00; //Not used
BAD_PROTOCOL = 0x02;
TOO_MANY_PEERS = 0x04; //Not used
DUPLICATE_PEER = 0x05;
INCOMPATIBLE_PROTOCOL = 0x06; //Not used
RANDOM_ELIMINATION = 0x07; //Not used
PEER_QUITING = 0x08;
UNEXPECTED_IDENTITY = 0x09;
LOCAL_IDENTITY = 0x0A; //Not used
PING_TIMEOUT = 0x0B; //Not used
USER_REASON = 0x10; //Not used
RESET = 0x11; //Not used
SYNC_FAIL = 0x12;
FETCH_FAIL = 0x13;
BAD_TX = 0x14;
BAD_BLOCK = 0x15;
FORKED = 0x16;
UNLINKABLE = 0x17;
INCOMPATIBLE_VERSION = 0x18;
INCOMPATIBLE_CHAIN = 0x19;
TIME_OUT = 0x20;
CONNECT_FAIL = 0x21; //Not used
TOO_MANY_PEERS_WITH_SAME_IP = 0x22; //Not used
LIGHT_NODE_SYNC_FAIL = 0x23;
BELOW_THAN_ME = 0X24;
UNKNOWN = 0xFF;
}
message DisconnectMessage {
ReasonCode reason = 1;
}
Add new types to Java-tron ReasonCode
Add the following enumeration type to protos/core/Tron.proto
enum ReasonCode {
REQUESTED = 0x00;
...
NOT_WITNESS = 0x25; //Added
NO_SUCH_MESSAGE = 0x26; //Added
...
UNKNOWN = 0xFF;
}
So, we can use this ReasonCode here, such as in RelayService.java :

Send ReasonCode to peer before node quits
Any node should notify peers of the reason when it quits, so others can understand the network better:
public static void close() {
...
for (PeerConnection p : new ArrayList<>(peers)) {
if (!p.isDisconnect()) {
p.disconnect(ReasonCode.PEER_QUITING); //added
p.getChannel().close();
}
}
...
}
Compatibility
All of the newly added unrecognized ReasonCode will be converted to UNKNOWN, and no exception will be thrown.