Skip to content

LengthPrefixedProtocol: Handle non protocol-compliant messages #173

@TiWi79

Description

@TiWi79

I have been using "LengthPrefixedProtocol" in "MyCustomProtocol".

This works "well" (well meaning according to what I would expect) as long as

1.) the incoming message from the client is length-prefixed
2.) the message's length is precisely as long as the prefix indicates

As soon as the reader receives a single message, which does not comply with both conditions, it won't be able to recognize length-prefixed messages after that, even if ithe incoming message does comply with both conditions again.
You would have to do a disconnect/connect, in order to "reset" that.

While this may be intended behaviour(?), I found it confusing.
In my opinion, the reader should be able to recognize protocol-compliant messages, even after it receives by one or more non-compliant messages.

Adding
consumed = input.End;

in the if-statement of "TryParseMessage" has worked for me so far to work around this issue:

if (!reader.TryReadBigEndian(out int length) || reader.Remaining < length)
{
message = default;
consumed = input.End;
return false
}

While adding this line of code has worked so far for me, I cannot guarantee that doing so might not go along with implications not yet recognized or that it might be against the author's original intention.

I would appreciate feedback on this.

And thank you for Bedrock anyway. This framework is really valuable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions