Skip to content

Commit

Permalink
Merge pull request #369 from gdamore/websock-pr
Browse files Browse the repository at this point in the history
New websocket mapping details
  • Loading branch information
djc committed Feb 19, 2015
2 parents 3a5fff0 + 4db7cdf commit 7cc9b9f
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 83 deletions.
103 changes: 51 additions & 52 deletions rfc/sp-websocket-mapping-01.txt
Expand Up @@ -4,8 +4,9 @@

Internet Engineering Task Force M. Sustrik, Ed.
Internet-Draft
Intended status: Informational November 15, 2014
Expires: May 19, 2015
Intended status: Informational G. D'Amore
Expires: August 7, 2015
February 3, 2015


WebSocket Mapping for Scalability Protocols
Expand All @@ -31,11 +32,11 @@ Status of This Memo
time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress."

This Internet-Draft will expire on May 19, 2015.
This Internet-Draft will expire on August 7, 2015.

Copyright Notice

Copyright (c) 2014 IETF Trust and the persons identified as the
Copyright (c) 2015 IETF Trust and the persons identified as the
document authors. All rights reserved.

This document is subject to BCP 78 and the IETF Trust's Legal
Expand All @@ -52,10 +53,9 @@ Copyright Notice




Sustrik Expires May 19, 2015 [Page 1]
Sustrik & D'Amore Expires August 7, 2015 [Page 1]

Internet-Draft WebSocket mapping for SPs November 2014
Internet-Draft WebSocket mapping for SPs February 2015


1. Underlying protocol
Expand All @@ -65,85 +65,84 @@ Internet-Draft WebSocket mapping for SPs November 2014

2. Connection initiation

Standard WebSocket handshake is done. Sec-WebSocket-Protocol field
MUST be set according to the following table:
Standard WebSocket handshake is done following RFC 6455.

x-nanomsg-pair for NN_PAIR sockets
The Sec-WebSocket-Protocol field MUST be set in the client's HTTP
request to match the protocol used by the WebSocket server.
Accordingly, the following values should be used.

x-nanomsg-req for NN_REQ sockets
pair.sp.nanomsg.org (NN_PAIR client and server)

x-nanomsg-rep for NN_REP sockets
req.sp.nanomsg.org (NN_REQ server, NN_REP client)

x-nanomsg-pub for NN_PUB sockets
rep.sp.nanomsg.org (NN_REP server, NN_REQ client)

x-nanomsg-sub for NN_SUB sockets
pub.sp.nanomsg.org (NN_PUB server, NN_SUB client)

x-nanomsg-surveyor for NN_SURVEYOR sockets
sub.sp.nanomsg.org (NN_SUB server, NN_PUB client)

x-nanomsg-respondent for NN_RESPONDENT sockets
surveyor.sp.nanomsg.org (NN_SURVEYOR server, NN_RESPONDENT client)

x-nanomsg-push for NN_PUSH sockets
respondent.sp.nanomsg.org (NN_RESPONDENT server, NN_SURVEYOR client)

x-nanomsg-pull for NN_PULL sockets
push.sp.nanomsg.org (NN_PUSH server, NN_PULL client)

x-nanomsg-bus for NN_BUS sockets
pull.sp.nanomsg.org (NN_PULL server, NN_PUSH client)

3. Message
bus.sp.nanomsg.org (NN_BUS client and server)

SP message maps directly to WebSocket message. The message can be
fragmented as needed. Frame boundaries are ignored by the SP layer.
If the server supports the requested SP protocol as indicated by the
Sec-WebSocket-Protocol header, then it MUST respond with the same
Sec-WebSocket-Protocol value sent by the client.

4. IANA Considerations
If the server does support the requested SP protocol, then it MUST
fail the WebSocket connection using the Close code of 1002, as
specified in RFC 6455.

This memo includes no request to IANA.
For example, an NN_REQ client socket, connecting to an NN_REP server,
will send the value rep.sp.nanomsg.org in the Sec-WebSocket-Protocol
field. The NN_REP socket on the server would then include the same
rep.sp.nanomsg.org in its response.

5. Security Considerations

The mapping isn't intended to provide any additional security in
addition to what WebSocket does. DoS concerns are addressed within
the specification.







Sustrik Expires May 19, 2015 [Page 2]
Sustrik & D'Amore Expires August 7, 2015 [Page 2]

Internet-Draft WebSocket mapping for SPs November 2014


Author's Address

Martin Sustrik (editor)

Email: sustrik@250bpm.com











Internet-Draft WebSocket mapping for SPs February 2015


3. Message

SP message maps directly to WebSocket message. The message can be
fragmented as needed. Frame boundaries are ignored by the SP layer.

When possible, binary frames SHOULD be used in preference to text
frames. If text frames are in use, then SP message payloads MUST be
comprised of legal UTF-8 text only.

4. IANA Considerations

This memo includes no request to IANA.

5. Security Considerations

The mapping isn't intended to provide any additional security in
addition to what WebSocket does. DoS concerns are addressed within
the specification.

Authors' Addresses

Martin Sustrik (editor)

Email: sustrik@250bpm.com


Garrett D'Amore

Email: garrett@damore.org



Expand All @@ -165,5 +164,5 @@ Author's Address



Sustrik Expires May 19, 2015 [Page 3]

Sustrik & D'Amore Expires August 7, 2015 [Page 3]
59 changes: 43 additions & 16 deletions rfc/sp-websocket-mapping-01.xml
Expand Up @@ -15,8 +15,14 @@
<email>sustrik@250bpm.com</email>
</address>
</author>
<author fullname="Garrett D'Amore" initials="G."
surname="D'Amore">
<address>
<email>garrett@damore.org</email>
</address>
</author>

<date month="November" year="2014" />
<date month="February" year="2015" />

<area>Applications</area>
<workgroup>Internet Engineering Task Force</workgroup>
Expand All @@ -42,20 +48,38 @@

<section title = "Connection initiation">

<t>Standard WebSocket handshake is done. Sec-WebSocket-Protocol field
MUST be set according to the following table:</t>

<t>x-nanomsg-pair for NN_PAIR sockets</t>
<t>x-nanomsg-req for NN_REQ sockets</t>
<t>x-nanomsg-rep for NN_REP sockets</t>
<t>x-nanomsg-pub for NN_PUB sockets</t>
<t>x-nanomsg-sub for NN_SUB sockets</t>
<t>x-nanomsg-surveyor for NN_SURVEYOR sockets</t>
<t>x-nanomsg-respondent for NN_RESPONDENT sockets</t>
<t>x-nanomsg-push for NN_PUSH sockets</t>
<t>x-nanomsg-pull for NN_PULL sockets</t>
<t>x-nanomsg-bus for NN_BUS sockets</t>

<t>Standard WebSocket handshake is done following RFC 6455.</t>

<t>The Sec-WebSocket-Protocol field
MUST be set in the client's HTTP request to match the protocol used
by the WebSocket server. Accordingly, the following values should
be used.</t>

<t>pair.sp.nanomsg.org (NN_PAIR client and server)</t>
<t>req.sp.nanomsg.org (NN_REQ server, NN_REP client)</t>
<t>rep.sp.nanomsg.org (NN_REP server, NN_REQ client)</t>
<t>pub.sp.nanomsg.org (NN_PUB server, NN_SUB client)</t>
<t>sub.sp.nanomsg.org (NN_SUB server, NN_PUB client)</t>
<t>surveyor.sp.nanomsg.org (NN_SURVEYOR server, NN_RESPONDENT client)</t>
<t>respondent.sp.nanomsg.org (NN_RESPONDENT server, NN_SURVEYOR client)</t>
<t>push.sp.nanomsg.org (NN_PUSH server, NN_PULL client)</t>
<t>pull.sp.nanomsg.org (NN_PULL server, NN_PUSH client)</t>
<t>bus.sp.nanomsg.org (NN_BUS client and server)</t>

<t>If the server supports the requested SP protocol as indicated
by the Sec-WebSocket-Protocol header, then it MUST respond with
the same Sec-WebSocket-Protocol value sent by the client.</t>

<t>If the server does support the requested SP protocol, then it MUST
fail the WebSocket connection using the Close code of 1002, as
specified in RFC 6455.</t>

<t>For example, an NN_REQ client socket, connecting to
an NN_REP server, will send the value rep.sp.nanomsg.org in
the Sec-WebSocket-Protocol field. The NN_REP socket on the
server would then include the same rep.sp.nanomsg.org in its
response.</t>

</section>

<section title = "Message">
Expand All @@ -64,6 +88,10 @@
fragmented as needed. Frame boundaries are ignored by the SP
layer.</t>

<t>When possible, binary frames SHOULD be used in preference to
text frames. If text frames are in use, then SP message payloads
MUST be comprised of legal UTF-8 text only.</t>

</section>

<section anchor="IANA" title="IANA Considerations">
Expand All @@ -79,4 +107,3 @@
</middle>

</rfc>

28 changes: 15 additions & 13 deletions src/transports/ws/ws_handshake.c
@@ -1,6 +1,7 @@
/*
Copyright (c) 2013 250bpm s.r.o. All rights reserved.
Copyright (c) 2014 Wirebird Labs LLC. All rights reserved.
Copyright 2015 Garrett D'Amore <garrett@damore.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -57,16 +58,16 @@
#include "../../bus.h"

static const struct nn_ws_sp_map NN_WS_HANDSHAKE_SP_MAP[] = {
{ NN_PAIR, "x-nanomsg-pair" },
{ NN_REQ, "x-nanomsg-req" },
{ NN_REP, "x-nanomsg-rep" },
{ NN_PUB, "x-nanomsg-pub" },
{ NN_SUB, "x-nanomsg-sub" },
{ NN_SURVEYOR, "x-nanomsg-surveyor" },
{ NN_RESPONDENT, "x-nanomsg-respondent" },
{ NN_PUSH, "x-nanomsg-push" },
{ NN_PULL, "x-nanomsg-pull" },
{ NN_BUS, "x-nanomsg-bus" }
{ NN_PAIR, NN_PAIR, "pair.sp.nanomsg.org" },
{ NN_REQ, NN_REP, "req.sp.nanomsg.org" },
{ NN_REP, NN_REQ, "rep.sp.nanomsg.org" },
{ NN_PUB, NN_SUB, "pub.sp.nanomsg.org" },
{ NN_SUB, NN_PUB, "sub.sp.nanomsg.org" },
{ NN_SURVEYOR, NN_RESPONDENT, "surveyor.sp.nanomsg.org" },
{ NN_RESPONDENT, NN_SURVEYOR, "respondent.sp.nanomsg.org" },
{ NN_PUSH, NN_PULL, "push.sp.nanomsg.org" },
{ NN_PULL, NN_PUSH, "pull.sp.nanomsg.org" },
{ NN_BUS, NN_BUS, "bus.sp.nanomsg.org" }
};

const size_t NN_WS_HANDSHAKE_SP_MAP_LEN = sizeof (NN_WS_HANDSHAKE_SP_MAP) /
Expand Down Expand Up @@ -1003,8 +1004,9 @@ static int nn_ws_handshake_parse_client_opening (struct nn_ws_handshake *self)
for (i = 0; i < NN_WS_HANDSHAKE_SP_MAP_LEN; i++) {
if (nn_ws_validate_value (NN_WS_HANDSHAKE_SP_MAP [i].ws_sp,
self->protocol, self->protocol_len, 1)) {
if (nn_pipebase_ispeer (self->pipebase,
NN_WS_HANDSHAKE_SP_MAP [i].sp)) {

if (self->pipebase->sock->socktype->protocol ==
NN_WS_HANDSHAKE_SP_MAP [i].server) {
self->response_code = NN_WS_HANDSHAKE_RESPONSE_OK;
return NN_WS_HANDSHAKE_VALID;
}
Expand Down Expand Up @@ -1222,7 +1224,7 @@ static void nn_ws_handshake_client_request (struct nn_ws_handshake *self)

/* Lookup SP header value. */
for (i = 0; i < NN_WS_HANDSHAKE_SP_MAP_LEN; i++) {
if (NN_WS_HANDSHAKE_SP_MAP [i].sp ==
if (NN_WS_HANDSHAKE_SP_MAP [i].client ==
self->pipebase->sock->socktype->protocol) {
break;
}
Expand Down
8 changes: 6 additions & 2 deletions src/transports/ws/ws_handshake.h
@@ -1,6 +1,7 @@
/*
Copyright (c) 2013 250bpm s.r.o. All rights reserved.
Copyright (c) 2014 Wirebird Labs LLC. All rights reserved.
Copyright 2015 Garrett D'Amore <garrett@damore.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -154,8 +155,11 @@ struct nn_ws_handshake {
WebSocket header values. */
struct nn_ws_sp_map {

/* Scalability Protocol ID... */
int sp;
/* Scalability Protocol ID for server... */
int server;

/* ... and corresponding client Protocol ID */
int client;

/* ... and corresponding WebSocket header field value. */
const char* ws_sp;
Expand Down

0 comments on commit 7cc9b9f

Please sign in to comment.