forked from Qortal/qortal
Better forwards compatibility with newer message types so we don't disconnect newer peers
This commit is contained in:
parent
33cffe45fd
commit
ca8f8a59f4
@ -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<Message> queue = this.replyQueues.get(message.getId());
|
||||
if (queue != null) {
|
||||
// Adding message to queue will unblock thread waiting for response
|
||||
|
@ -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();
|
||||
|
@ -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),
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user