Commit d826c53b authored by Pieter Hintjens's avatar Pieter Hintjens

Bumped ZMTP revision to 2

* Starting draft ZMTP/2.1 protocol (revision 2)
* Basis for adding security to the wire protocol
* Maintains backward compatibility
parent 785ef41f
...@@ -363,7 +363,6 @@ bool zmq::stream_engine_t::handshake () ...@@ -363,7 +363,6 @@ bool zmq::stream_engine_t::handshake ()
error (); error ();
return false; return false;
} }
if (n == 0) if (n == 0)
return false; return false;
...@@ -390,7 +389,7 @@ bool zmq::stream_engine_t::handshake () ...@@ -390,7 +389,7 @@ bool zmq::stream_engine_t::handshake ()
if (outpos + outsize != greeting_output_buffer + greeting_size) { if (outpos + outsize != greeting_output_buffer + greeting_size) {
if (outsize == 0) if (outsize == 0)
set_pollout (handle); set_pollout (handle);
outpos [outsize++] = 1; // Protocol revision outpos [outsize++] = ZMTP_2_1; // Protocol revision
outpos [outsize++] = options.type; // Socket type outpos [outsize++] = options.type; // Socket type
} }
} }
...@@ -432,25 +431,26 @@ bool zmq::stream_engine_t::handshake () ...@@ -432,25 +431,26 @@ bool zmq::stream_engine_t::handshake ()
decoder->set_msg_sink (this); decoder->set_msg_sink (this);
} }
else else
if (greeting [revision_pos] == 0) { if (greeting [revision_pos] == ZMTP_1_0) {
// ZMTP/1.0 framing (revision 0) encoder = new (std::nothrow) v1_encoder_t (
encoder = new (std::nothrow) v1_encoder_t (out_batch_size); out_batch_size);
alloc_assert (encoder); alloc_assert (encoder);
encoder->set_msg_source (session); encoder->set_msg_source (session);
decoder = new (std::nothrow) v1_decoder_t (in_batch_size, options.maxmsgsize); decoder = new (std::nothrow) v1_decoder_t (
in_batch_size, options.maxmsgsize);
alloc_assert (decoder); alloc_assert (decoder);
decoder->set_msg_sink (session); decoder->set_msg_sink (session);
} }
else else
if (greeting [revision_pos] == 1 if (greeting [revision_pos] == ZMTP_2_0
|| greeting [revision_pos] == 2) { || greeting [revision_pos] == ZMTP_2_1) {
// ZMTP/2.0 framing (revision 1) encoder = new (std::nothrow) v2_encoder_t (
encoder = new (std::nothrow) v2_encoder_t (out_batch_size, session); out_batch_size, session);
alloc_assert (encoder); alloc_assert (encoder);
decoder = new (std::nothrow) decoder = new (std::nothrow) v2_decoder_t (
v2_decoder_t (in_batch_size, options.maxmsgsize, session); in_batch_size, options.maxmsgsize, session);
alloc_assert (decoder); alloc_assert (decoder);
} }
......
...@@ -34,6 +34,13 @@ ...@@ -34,6 +34,13 @@
namespace zmq namespace zmq
{ {
// Protocol revisions
enum
{
ZMTP_1_0 = 0,
ZMTP_2_0 = 1,
ZMTP_2_1 = 2
};
class io_thread_t; class io_thread_t;
class session_base_t; class session_base_t;
......
...@@ -36,4 +36,3 @@ namespace zmq ...@@ -36,4 +36,3 @@ namespace zmq
} }
#endif #endif
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
typedef unsigned char byte; typedef unsigned char byte;
typedef struct { typedef struct {
byte signature [10]; // 0xFF 8*0x00 0x7F byte signature [10]; // 0xFF 8*0x00 0x7F
byte revision; // 0x01 = ZMTP/2.0 byte revision; // 2 = ZMTP/2.1
byte socktype; // Defined in ZMTP spec byte socktype; // Defined in ZMTP spec
byte identity [2]; // Empty message byte identity [2]; // Empty message
} zmtp_greeting_t; } zmtp_greeting_t;
...@@ -41,7 +41,7 @@ typedef struct { ...@@ -41,7 +41,7 @@ typedef struct {
// 8-byte size is set to 1 for backwards compatibility // 8-byte size is set to 1 for backwards compatibility
static zmtp_greeting_t greeting static zmtp_greeting_t greeting
= { { 0xFF, 0, 0, 0, 0, 0, 0, 0, 1, 0x7F }, 1, 0, { 0, 0 } }; = { { 0xFF, 0, 0, 0, 0, 0, 0, 0, 1, 0x7F }, 2, 0, { 0, 0 } };
int main (void) int main (void)
{ {
...@@ -107,7 +107,7 @@ int main (void) ...@@ -107,7 +107,7 @@ int main (void)
assert (rc == 11); assert (rc == 11);
// First four bytes are [revision][socktype][identity] // First four bytes are [revision][socktype][identity]
assert (buffer [0] == 1); assert (buffer [0] == 2); // ZMTP/2.1
assert (buffer [1] == ZMTP_DEALER); assert (buffer [1] == ZMTP_DEALER);
// Identity is 2 byte message // Identity is 2 byte message
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment