diff --git a/src/main/java/org/qortal/network/Peer.java b/src/main/java/org/qortal/network/Peer.java index 7e51dc36..f99a94b1 100644 --- a/src/main/java/org/qortal/network/Peer.java +++ b/src/main/java/org/qortal/network/Peer.java @@ -12,6 +12,7 @@ import org.qortal.data.network.PeerData; import org.qortal.network.message.ChallengeMessage; import org.qortal.network.message.Message; import org.qortal.network.message.MessageException; +import org.qortal.network.message.MessageType; import org.qortal.network.task.MessageTask; import org.qortal.network.task.PingTask; import org.qortal.settings.Settings; @@ -546,6 +547,10 @@ public class Peer { // adjusting position accordingly, reset limit to capacity this.byteBuffer.compact(); + // Unsupported message type? Discard with no further processing + if (message.getType() == MessageType.UNSUPPORTED) + continue; + BlockingQueue queue = this.replyQueues.get(message.getId()); if (queue != null) { // Adding message to queue will unblock thread waiting for response diff --git a/src/main/java/org/qortal/network/message/Message.java b/src/main/java/org/qortal/network/message/Message.java index e92aca89..f752b5b9 100644 --- a/src/main/java/org/qortal/network/message/Message.java +++ b/src/main/java/org/qortal/network/message/Message.java @@ -103,8 +103,7 @@ public abstract class Message { int typeValue = readOnlyBuffer.getInt(); MessageType messageType = MessageType.valueOf(typeValue); if (messageType == null) - // Unrecognised message type - throw new MessageException(String.format("Received unknown message type [%d]", typeValue)); + messageType = MessageType.UNSUPPORTED; // Optional message ID byte hasId = readOnlyBuffer.get(); diff --git a/src/main/java/org/qortal/network/message/MessageType.java b/src/main/java/org/qortal/network/message/MessageType.java index 8ad7a0da..a2637dfd 100644 --- a/src/main/java/org/qortal/network/message/MessageType.java +++ b/src/main/java/org/qortal/network/message/MessageType.java @@ -8,6 +8,9 @@ import static java.util.Arrays.stream; import static java.util.stream.Collectors.toMap; public enum MessageType { + // Pseudo-message, not sent over the wire + UNSUPPORTED(-1, UnsupportedMessage::fromByteBuffer), + // Handshaking HELLO(0, HelloMessage::fromByteBuffer), GOODBYE(1, GoodbyeMessage::fromByteBuffer), diff --git a/src/main/java/org/qortal/network/message/UnsupportedMessage.java b/src/main/java/org/qortal/network/message/UnsupportedMessage.java new file mode 100644 index 00000000..649092f6 --- /dev/null +++ b/src/main/java/org/qortal/network/message/UnsupportedMessage.java @@ -0,0 +1,20 @@ +package org.qortal.network.message; + +import java.nio.ByteBuffer; + +public class UnsupportedMessage extends Message { + + public UnsupportedMessage() { + super(MessageType.UNSUPPORTED); + throw new UnsupportedOperationException("Unsupported message is unsupported!"); + } + + private UnsupportedMessage(int id) { + super(id, MessageType.UNSUPPORTED); + } + + public static Message fromByteBuffer(int id, ByteBuffer byteBuffer) throws MessageException { + return new UnsupportedMessage(id); + } + +}