Skip to content

Commit b9ab07a

Browse files
authored
feat(net):supplement disconnect reasons (#5392)
* feat(net):supplement disconnect reasons * add ReasonCode NO_SUCH_MESSAGE
1 parent d6ff733 commit b9ab07a

File tree

5 files changed

+10
-1
lines changed

5 files changed

+10
-1
lines changed

framework/src/main/java/org/tron/core/net/P2pEventHandlerImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.tron.p2p.P2pEventHandler;
3939
import org.tron.p2p.connection.Channel;
4040
import org.tron.protos.Protocol;
41+
import org.tron.protos.Protocol.ReasonCode;
4142

4243
@Slf4j(topic = "net")
4344
@Component
@@ -232,7 +233,8 @@ private void processException(PeerConnection peer, TronMessage msg, Exception ex
232233
code = Protocol.ReasonCode.BAD_BLOCK;
233234
break;
234235
case NO_SUCH_MESSAGE:
235-
case MESSAGE_WITH_WRONG_LENGTH:
236+
code = Protocol.ReasonCode.NO_SUCH_MESSAGE;
237+
break;
236238
case BAD_MESSAGE:
237239
code = Protocol.ReasonCode.BAD_PROTOCOL;
238240
break;

framework/src/main/java/org/tron/core/net/message/sync/ChainInventoryMessage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public String toString() {
7373
sb.append(", end blockId: ").append(blockIdWeGet.peekLast().getString());
7474
}
7575
}
76+
sb.append(", remain_num: ").append(chainInventory.getRemainNum());
7677
return sb.toString();
7778
}
7879
}

framework/src/main/java/org/tron/core/net/peer/PeerManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.tron.common.prometheus.MetricLabels;
1717
import org.tron.common.prometheus.Metrics;
1818
import org.tron.p2p.connection.Channel;
19+
import org.tron.protos.Protocol.ReasonCode;
1920

2021
@Slf4j(topic = "net")
2122
public class PeerManager {
@@ -48,6 +49,7 @@ public static void close() {
4849
try {
4950
for (PeerConnection p : new ArrayList<>(peers)) {
5051
if (!p.isDisconnect()) {
52+
p.disconnect(ReasonCode.PEER_QUITING);
5153
p.getChannel().close();
5254
}
5355
}

framework/src/main/java/org/tron/core/net/service/relay/RelayService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.tron.core.store.WitnessScheduleStore;
3535
import org.tron.p2p.connection.Channel;
3636
import org.tron.protos.Protocol;
37+
import org.tron.protos.Protocol.ReasonCode;
3738

3839
@Slf4j(topic = "net")
3940
@Component
@@ -184,6 +185,7 @@ private void disconnect() {
184185
TronNetService.getP2pConfig().getActiveNodes().remove(address);
185186
TronNetService.getPeers().forEach(peer -> {
186187
if (peer.getInetAddress().equals(address.getAddress())) {
188+
peer.disconnect(ReasonCode.NOT_WITNESS);
187189
peer.getChannel().close();
188190
}
189191
});

protocol/src/main/protos/core/Tron.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,8 @@ enum ReasonCode {
601601
TOO_MANY_PEERS_WITH_SAME_IP = 0x22;
602602
LIGHT_NODE_SYNC_FAIL = 0x23;
603603
BELOW_THAN_ME = 0X24;
604+
NOT_WITNESS = 0x25;
605+
NO_SUCH_MESSAGE = 0x26;
604606
UNKNOWN = 0xFF;
605607
}
606608

0 commit comments

Comments
 (0)