Subject: [hybi] Implementing masked framing. was: call for feedback on Masking alternatives

From: Greg Wilkins <[email-masked]>
Date: Wed, 6 Apr 2011 09:36:15 +1000

On 6 April 2011 09:26, Brian McKelvey <[email-masked]> wrote:
> From my experience implementing this masking (I presume you're talking about #1, masking everything including the framing) I don't see any change in difficulty whatsoever relating to handling multiple messages in a single packet.  I wrote my code to handle that from the beginning.  And handling multiple messages per packet or handling single messages that span multiple packets isn't related to the masking in the first place.  Have I misunderstood you?

The main difference for me is that with option #1, the unmasking has
to be done in the framing layer and thus has to be concerned with
frames fragmented into multiple packets.  Thus you have to handle
pathological cases of a WS frame arriving asynchronously 1 byte at a
time and maintain extra state and buffers accordingly.   This is made
slightly more complex by the fact that the parser/generators are
asymmetric, so masking has to be optional in this code.    OK, it is
not rocket science and it not even that difficult to get right - but
it does represent a blending of concerns and makes the code harder to
understand and maintain - and test harnesses are also more complicated
as a result.

With option #2, masking can be treated like an extension.  The parser
can work symmetrically to obtain the entire frame and only once all
the bytes have been received and parsed do we need to a) move the
bytes to user-space b) unmask them.

But my support for #2 is not determined by code complexity - rather
having a known framing mechanism that is invariant so that we can
encourage the development of a rich eco system of 3rd party tools and
value add intermediaries.

cheers

---

From: Brian <[email-masked]>
Date: Tue, 5 Apr 2011 16:55:25 -0700

Yes, that's true.  My state-based parser checks for the availability
of the appropriate number of bytes on the stream buffer at each stage
and returns, awaiting another socketData event with more bytes if
there is insufficient data.

I agree about the extra complexity with regard to having to integrate
the masking into the framing parser, I just don't see how that relates
to receiving multiple messages in a single packet.

Brian