forked from Qortal/qortal
Discard unsupported messages instead of disconnecting the peer.
This commit is contained in:
parent
64d4c458ec
commit
d086ade91f
@ -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.UnsupportedMessageException;
|
||||
import org.qortal.network.task.MessageTask;
|
||||
import org.qortal.network.task.PingTask;
|
||||
import org.qortal.settings.Settings;
|
||||
@ -510,8 +511,13 @@ public class Peer {
|
||||
ByteBuffer readOnlyBuffer = this.byteBuffer.asReadOnlyBuffer().flip();
|
||||
try {
|
||||
message = Message.fromByteBuffer(readOnlyBuffer);
|
||||
} catch (UnsupportedMessageException e) {
|
||||
// Unsupported message - discard it without disconnecting
|
||||
LOGGER.debug("[{}] {}, from peer {} - discarding...", this.peerConnectionId, e.getMessage(), this);
|
||||
return;
|
||||
} catch (MessageException e) {
|
||||
LOGGER.debug("[{}] {}, from peer {}", this.peerConnectionId, e.getMessage(), this);
|
||||
// Any other message exception - disconnect the peer
|
||||
LOGGER.debug("[{}] {}, from peer {} - forcing disconnection...", this.peerConnectionId, e.getMessage(), this);
|
||||
this.disconnect(e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ public abstract class Message {
|
||||
MessageType messageType = MessageType.valueOf(typeValue);
|
||||
if (messageType == null)
|
||||
// Unrecognised message type
|
||||
throw new MessageException(String.format("Received unknown message type [%d]", typeValue));
|
||||
throw new UnsupportedMessageException(String.format("Received unknown message type [%d]", typeValue));
|
||||
|
||||
// Optional message ID
|
||||
byte hasId = readOnlyBuffer.get();
|
||||
|
@ -0,0 +1,19 @@
|
||||
package org.qortal.network.message;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class UnsupportedMessageException extends MessageException {
|
||||
public UnsupportedMessageException() {
|
||||
}
|
||||
|
||||
public UnsupportedMessageException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public UnsupportedMessageException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public UnsupportedMessageException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user