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 ()
error ();
return false;
}
if (n == 0)
return false;
......@@ -390,7 +389,7 @@ bool zmq::stream_engine_t::handshake ()
if (outpos + outsize != greeting_output_buffer + greeting_size) {
if (outsize == 0)
set_pollout (handle);
outpos [outsize++] = 1; // Protocol revision
outpos [outsize++] = ZMTP_2_1; // Protocol revision
outpos [outsize++] = options.type; // Socket type
}
}
......@@ -432,25 +431,26 @@ bool zmq::stream_engine_t::handshake ()
decoder->set_msg_sink (this);
}
else
if (greeting [revision_pos] == 0) {
// ZMTP/1.0 framing (revision 0)
encoder = new (std::nothrow) v1_encoder_t (out_batch_size);
if (greeting [revision_pos] == ZMTP_1_0) {
encoder = new (std::nothrow) v1_encoder_t (
out_batch_size);
alloc_assert (encoder);
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);
decoder->set_msg_sink (session);
}
else
if (greeting [revision_pos] == 1
|| greeting [revision_pos] == 2) {
// ZMTP/2.0 framing (revision 1)
encoder = new (std::nothrow) v2_encoder_t (out_batch_size, session);
if (greeting [revision_pos] == ZMTP_2_0
|| greeting [revision_pos] == ZMTP_2_1) {
encoder = new (std::nothrow) v2_encoder_t (
out_batch_size, session);
alloc_assert (encoder);
decoder = new (std::nothrow)
v2_decoder_t (in_batch_size, options.maxmsgsize, session);
decoder = new (std::nothrow) v2_decoder_t (
in_batch_size, options.maxmsgsize, session);
alloc_assert (decoder);
}
......
......@@ -34,6 +34,13 @@
namespace zmq
{
// Protocol revisions
enum
{
ZMTP_1_0 = 0,
ZMTP_2_0 = 1,
ZMTP_2_1 = 2
};
class io_thread_t;
class session_base_t;
......
......@@ -36,4 +36,3 @@ namespace zmq
}
#endif
......@@ -29,7 +29,7 @@
typedef unsigned char byte;
typedef struct {
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 identity [2]; // Empty message
} zmtp_greeting_t;
......@@ -41,7 +41,7 @@ typedef struct {
// 8-byte size is set to 1 for backwards compatibility
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)
{
......@@ -107,7 +107,7 @@ int main (void)
assert (rc == 11);
// First four bytes are [revision][socktype][identity]
assert (buffer [0] == 1);
assert (buffer [0] == 2); // ZMTP/2.1
assert (buffer [1] == ZMTP_DEALER);
// 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