Re: [hybi] Framing take IV

Jamie Lokier <jamie@shareable.org> Thu, 05 August 2010 02:02 UTC

Return-Path: <jamie@shareable.org>
X-Original-To: hybi@core3.amsl.com
Delivered-To: hybi@core3.amsl.com
Received: from localhost (localhost [127.0.0.1]) by core3.amsl.com (Postfix) with ESMTP id D22AE3A67E5 for <hybi@core3.amsl.com>; Wed, 4 Aug 2010 19:02:38 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.517
X-Spam-Level:
X-Spam-Status: No, score=-2.517 tagged_above=-999 required=5 tests=[AWL=0.082, BAYES_00=-2.599]
Received: from mail.ietf.org ([64.170.98.32]) by localhost (core3.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vsoTWy8PW2JX for <hybi@core3.amsl.com>; Wed, 4 Aug 2010 19:02:36 -0700 (PDT)
Received: from mail2.shareable.org (mail2.shareable.org [80.68.89.115]) by core3.amsl.com (Postfix) with ESMTP id B5AE73A635F for <hybi@ietf.org>; Wed, 4 Aug 2010 19:02:35 -0700 (PDT)
Received: from jamie by mail2.shareable.org with local (Exim 4.63) (envelope-from <jamie@shareable.org>) id 1OgpnU-0006RA-2S; Thu, 05 Aug 2010 03:03:04 +0100
Date: Thu, 05 Aug 2010 03:03:04 +0100
From: Jamie Lokier <jamie@shareable.org>
To: Greg Wilkins <gregw@webtide.com>
Message-ID: <20100805020304.GY27827@shareable.org>
References: <AANLkTinyrDoG5d_Ur6HVRy=SgMPjLzJtpJ++Ye=1DQdj@mail.gmail.com> <20100804022719.GT27827@shareable.org> <AANLkTi=MENta8H4A_ota=R==EJ3j0zAkPc7ai2qmsZiT@mail.gmail.com> <AANLkTinZE8-HSi-BJD8Oq3z3+9BXY8eMnZ4DAnOaiuT=@mail.gmail.com> <20100804031917.GV27827@shareable.org> <AANLkTikMuVDwUyKYetCvj2GWv8dW+sWa5RLOVVOVPcBF@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: inline
In-Reply-To: <AANLkTikMuVDwUyKYetCvj2GWv8dW+sWa5RLOVVOVPcBF@mail.gmail.com>
User-Agent: Mutt/1.5.13 (2006-08-11)
Cc: hybi@ietf.org
Subject: Re: [hybi] Framing take IV
X-BeenThere: hybi@ietf.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: Server-Initiated HTTP <hybi.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/hybi>
List-Post: <mailto:hybi@ietf.org>
List-Help: <mailto:hybi-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=subscribe>
X-List-Received-Date: Thu, 05 Aug 2010 02:02:39 -0000

Greg Wilkins wrote:
> 
>    Jamie,
>    so to make your proposal a little more concrete, I think that you are
>    advocating something like:

Sorry, I'm not able to decode the diagrams you are sending.  They come
out as mangled text in my editor.

But yes, the basic idea: length, opcode, data.

The length must include the opcodes as well as the data, although the
first opcode byte doesn't have to be included if we don't want to.

The order should probably be length, opcode, data, so a "wrapper"
style opcode would end up looking like these made up examples.
First the simple one:

    length, any-opcode, data  (basic simple frames, including text, binary etc.)

Extensions, to be defined by whomever wants to, no standard necessary:

    length, multiplex, flow-id, final-bit, forward-bit, any-opcode, data
    length, crc32-opcode, any-opcode, data, crc32
    length, md5-opcode, any-opcode, data, md5

Putting length after the first opcode suggests length is part of the
opcode's parameters, which it isn't, as you can see in the last three
examples, where any-opcode isn't associated with a length of it's own,
but it's the same set of opcodes.

>           frame-opcode              = %x00 ; text data frame
>                                     | %x01 ; final frame
>                                     | %x02-ff; extension

I'd rename "final frame" as "basic data frame", but it's a nit.

>           frame-length               = %x0000-FFFF

I'm not sure if this limit penalises implementations shifting large
amounts of data over jumbo frames, which are about 64kB per packet, or
over TCP segmentation accelerators, which take large packets and split
them in hardware on the way out.  I.e. a larger limit such as 24 bits
might be better, for implementations which can use "sendfile" or
"splice" style transmission methods to share memory among sockets and
avoid copying the data.  I haven't investigated or tested in
sufficient detail.

However I'm leaning towards the BER-style that Ian Hixie suggests,
with an explicit note in the specification saying what the maximum
permitted BER value is (or equivalently what the maximum number of
bytes encoding the value are), with the implication that all
implementations should count properly up to that (although they may
still reject a message on the grounds of being too large for local
policy of course).

The first byte in BER does not have to use all the bits, so we could
reserve a few bits in the first byte for universal flags _if_ we think
there are any, and the remainder of bits would be sufficient for small
lengths.  I'm not sure if this is needed - do you think there are any
universal bits needed?

>    A client would indicate the extensions that it wants to support with a
>    handshake header like:
>         Websocket-Ext: fragment;mandatory=true, ping;mandatory=true, multiplex, compression

>    The server could then respond with the extensions that it will be
>    used, plus allocations of bits/codes:
>         Wesocket-Ext: fragment;bit=7, ping;code=02-03, multiplex;code=10-1F

>    Is that about right?

Not quite.

The *client* decides opcode values for features it proposes.  The
server must ignore frames with opcodes for features it doesn't
support; this is why the length is universal (and also for
intermediaries).

If we ever use any mechanism to bypass the negotation round-trip (such
as TLS extensions, encoding initial messages in the handshake, etc.),
it is only effective if the client sets the opcodes.

Although we might not use that mechanism with the HTTP handshake, it
is a valuable and simple trap door in case we decided to avoid startup
latency in future, or with a different handshake, and it is also a
good pattern for latency avoidance in general.

-- Jamie