Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public enum MessageTypes {

P2P_DISCONNECT(0x21),

P2P_PING(0x22),

P2P_PONG(0x23),

DISCOVER_PING(0x30),

DISCOVER_PONG(0x31),
Expand Down Expand Up @@ -73,26 +69,10 @@ public static MessageTypes fromByte(byte i) {
return intToTypeMap.get((int) i);
}

public static boolean inRange(byte code) {
return code < LAST.asByte();
}

public static boolean inP2pRange(byte code) {
return code <= P2P_PONG.asByte() && code >= P2P_HELLO.asByte();
}

public static boolean inTronRange(byte code) {
return code <= PBFT_COMMIT_MSG.asByte() && code >= FIRST.asByte();
}

public byte asByte() {
return (byte) (type);
}

public static boolean inPbftRange(byte code) {
return code == PBFT_MSG.asByte();
}

@Override
public String toString() {
switch (type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public static class Histogram {
public static final String GRPC_SERVICE_LATENCY = "tron:grpc_service_latency_seconds";
public static final String JSONRPC_SERVICE_LATENCY = "tron:jsonrpc_service_latency_seconds";
public static final String MINER_LATENCY = "tron:miner_latency_seconds";
public static final String PING_PONG_LATENCY = "tron:ping_pong_latency_seconds";
public static final String VERIFY_SIGN_LATENCY = "tron:verify_sign_latency_seconds";
public static final String LOCK_ACQUIRE_LATENCY = "tron:lock_acquire_latency_seconds";
public static final String BLOCK_PROCESS_LATENCY = "tron:block_process_latency_seconds";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class MetricsHistogram {
"method");
init(MetricKeys.Histogram.MINER_LATENCY, "miner latency.",
MetricLabels.Histogram.MINER);
init(MetricKeys.Histogram.PING_PONG_LATENCY, "node ping pong latency.");
init(MetricKeys.Histogram.VERIFY_SIGN_LATENCY, "verify sign latency for trx , block.",
"type");
init(MetricKeys.Histogram.LOCK_ACQUIRE_LATENCY, "lock acquire latency.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.tron.core.net.peer.PeerManager;
import org.tron.core.net.service.effective.EffectiveCheckService;
import org.tron.core.net.service.handshake.HandshakeService;
import org.tron.core.net.service.keepalive.KeepAliveService;
import org.tron.core.net.service.statistics.MessageStatistics;
import org.tron.p2p.P2pEventHandler;
import org.tron.p2p.connection.Channel;
Expand Down Expand Up @@ -83,9 +82,6 @@ public class P2pEventHandlerImpl extends P2pEventHandler {
@Autowired
private PbftMsgHandler pbftMsgHandler;

@Autowired
private KeepAliveService keepAliveService;

@Autowired
private EffectiveCheckService effectiveCheckService;

Expand Down Expand Up @@ -171,10 +167,6 @@ private void processMessage(PeerConnection peer, byte[] data) {
}

switch (type) {
case P2P_PING:
case P2P_PONG:
keepAliveService.processMessage(peer, msg);
break;
case P2P_HELLO:
handshakeService.processHelloMessage(peer, (HelloMessage) msg);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import org.tron.core.net.message.adv.TransactionsMessage;
import org.tron.core.net.message.base.DisconnectMessage;
import org.tron.core.net.message.handshake.HelloMessage;
import org.tron.core.net.message.keepalive.PingMessage;
import org.tron.core.net.message.keepalive.PongMessage;
import org.tron.core.net.message.pbft.PbftCommitMessage;
import org.tron.core.net.message.sync.ChainInventoryMessage;
import org.tron.core.net.message.sync.SyncBlockChainMessage;
Expand Down Expand Up @@ -51,10 +49,6 @@ private static TronMessage create(byte type, byte[] packed) throws Exception {
return new HelloMessage(packed);
case P2P_DISCONNECT:
return new DisconnectMessage(packed);
case P2P_PING:
return new PingMessage(packed);
case P2P_PONG:
return new PongMessage(packed);
case BLOCK:
return new BlockMessage(packed);
case TRXS:
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
import org.tron.core.net.message.adv.TransactionsMessage;
import org.tron.core.net.message.base.DisconnectMessage;
import org.tron.core.net.message.handshake.HelloMessage;
import org.tron.core.net.message.keepalive.PingMessage;
import org.tron.core.net.message.keepalive.PongMessage;
import org.tron.core.net.service.adv.AdvService;
import org.tron.core.net.service.statistics.NodeStatistics;
import org.tron.core.net.service.statistics.PeerStatistics;
Expand Down Expand Up @@ -429,9 +427,7 @@ private void processDisconnect(Protocol.ReasonCode reason) {
}

public static boolean needToLog(Message msg) {
if (msg instanceof PingMessage
|| msg instanceof PongMessage
|| msg instanceof TransactionsMessage
if (msg instanceof TransactionsMessage
|| msg instanceof PbftBaseMessage) {
return false;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ public class MessageStatistics {

public final MessageCount p2pInHello = new MessageCount();
public final MessageCount p2pOutHello = new MessageCount();
public final MessageCount p2pInPing = new MessageCount();
public final MessageCount p2pOutPing = new MessageCount();
public final MessageCount p2pInPong = new MessageCount();
public final MessageCount p2pOutPong = new MessageCount();
public final MessageCount p2pInDisconnect = new MessageCount();
public final MessageCount p2pOutDisconnect = new MessageCount();

Expand Down Expand Up @@ -78,20 +74,6 @@ private void addTcpMessage(Message msg, boolean flag) {
p2pOutHello.add();
}
break;
case P2P_PING:
if (flag) {
p2pInPing.add();
} else {
p2pOutPing.add();
}
break;
case P2P_PONG:
if (flag) {
p2pInPong.add();
} else {
p2pOutPong.add();
}
break;
case P2P_DISCONNECT:
if (flag) {
p2pInDisconnect.add();
Expand Down
21 changes: 2 additions & 19 deletions framework/src/test/java/org/tron/core/net/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.tron.core.net.message.base.DisconnectMessage;
import org.tron.core.net.service.statistics.MessageStatistics;
import org.tron.protos.Protocol.Inventory.InventoryType;
import org.tron.protos.Protocol.ReasonCode;

public class MessageTest {

Expand All @@ -37,18 +36,6 @@ public Class<?> getAnswerMessage() {
return null;
}
};
Message message2 = new Message(MessageTypes.P2P_PING.asByte(), null) {
@Override
public Class<?> getAnswerMessage() {
return null;
}
};
Message message3 = new Message(MessageTypes.P2P_PONG.asByte(), null) {
@Override
public Class<?> getAnswerMessage() {
return null;
}
};
Message message4 = new Message(MessageTypes.P2P_DISCONNECT.asByte(), null) {
@Override
public Class<?> getAnswerMessage() {
Expand Down Expand Up @@ -85,10 +72,6 @@ public Class<?> getAnswerMessage() {

messageStatistics.addTcpInMessage(message1);
messageStatistics.addTcpOutMessage(message1);
messageStatistics.addTcpInMessage(message2);
messageStatistics.addTcpOutMessage(message2);
messageStatistics.addTcpInMessage(message3);
messageStatistics.addTcpOutMessage(message3);
messageStatistics.addTcpInMessage(message4);
messageStatistics.addTcpOutMessage(message4);
messageStatistics.addTcpInMessage(message5);
Expand All @@ -111,8 +94,8 @@ public Class<?> getAnswerMessage() {
messageStatistics.addTcpInMessage(message11);
messageStatistics.addTcpOutMessage(message11);

Assert.assertEquals(11, messageStatistics.tronInMessage.getTotalCount());
Assert.assertEquals(11, messageStatistics.tronOutMessage.getTotalCount());
Assert.assertEquals(9, messageStatistics.tronInMessage.getTotalCount());
Assert.assertEquals(9, messageStatistics.tronOutMessage.getTotalCount());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.tron.core.net.P2pEventHandlerImpl;
import org.tron.core.net.message.adv.TransactionMessage;
import org.tron.core.net.message.adv.TransactionsMessage;
import org.tron.core.net.message.base.DisconnectMessage;
import org.tron.core.net.message.handshake.HelloMessage;
import org.tron.core.net.peer.PeerConnection;
import org.tron.core.net.peer.PeerManager;
Expand All @@ -32,6 +33,36 @@

public class TronMessageFactoryTest {

@Test
public void legacyKeepAliveIsRejectedRegardlessOfPayloadContents() {
byte[][] payloads = {new byte[0], {(byte) 0xc0}, {0x0a, 0x7f},
new byte[Parameter.MAX_MESSAGE_LENGTH - 2]};
for (byte type : new byte[] {0x22, 0x23}) {
for (byte[] payload : payloads) {
P2pException exception = assertThrows(P2pException.class,
() -> TronMessageFactory.create(withType(type, payload)));
assertEquals(TypeEnum.NO_SUCH_MESSAGE, exception.getType());
}
}
}

@Test
public void legacyKeepAliveIsRejectedAtP2pEntryWithoutReply() {
for (byte type : new byte[] {0x22, 0x23}) {
Channel channel = mock(Channel.class);
PeerConnection peer = mock(PeerConnection.class);
when(peer.getHelloMessageReceive()).thenReturn(mock(HelloMessage.class));
when(peer.getInetSocketAddress()).thenReturn(new InetSocketAddress("127.0.0.1", 10001));
try (MockedStatic<PeerManager> peers = mockStatic(PeerManager.class)) {
peers.when(() -> PeerManager.getPeerConnection(channel)).thenReturn(peer);
new P2pEventHandlerImpl().onMessage(channel, withType(type, new byte[] {(byte) 0xc0}));
verify(peer).disconnect(ReasonCode.NO_SUCH_MESSAGE);
verify(peer, never()).getPeerStatistics();
verify(peer, never()).sendMessage(any());
}
}
}

@Test
public void trxIsRejectedBeforeParsingRegardlessOfPayloadContents() {
byte[][] payloads = {new byte[0], {0x0c}, {0x0a, 0x7f},
Expand Down Expand Up @@ -94,8 +125,9 @@ public void supportedMessageTypesStillDecode() throws Exception {
TransactionsMessage batch = (TransactionsMessage) TronMessageFactory.create(
withType(MessageTypes.TRXS, new byte[0]));
assertEquals(0, batch.getTransactions().getTransactionsCount());
assertEquals(MessageTypes.P2P_PING, TronMessageFactory.create(
withType(MessageTypes.P2P_PING, new byte[] {(byte) 0xc0})).getType());
DisconnectMessage disconnect = (DisconnectMessage) TronMessageFactory.create(
new DisconnectMessage(ReasonCode.REQUESTED).getSendBytes());
assertEquals(ReasonCode.REQUESTED, disconnect.getReason());
}
}

Expand All @@ -105,8 +137,12 @@ private static Transaction sampleTransaction() {
}

private static byte[] withType(MessageTypes type, byte[] payload) {
return withType(type.asByte(), payload);
}

private static byte[] withType(byte type, byte[] payload) {
byte[] data = new byte[payload.length + 1];
data[0] = type.asByte();
data[0] = type;
System.arraycopy(payload, 0, data, 1, payload.length);
return data;
}
Expand Down
Loading
Loading