Commit ebba815a authored by sigiesec's avatar sigiesec

Problem: duplicate but equivalent state enums in curve_server_t and plain_server_t

Solution: pull state enum up to zap_client_t and unify names of enum values
parent 414c6f45
...@@ -43,7 +43,7 @@ zmq::curve_server_t::curve_server_t (session_base_t *session_, ...@@ -43,7 +43,7 @@ zmq::curve_server_t::curve_server_t (session_base_t *session_,
const options_t &options_) : const options_t &options_) :
mechanism_t (options_), mechanism_t (options_),
zap_client_t (session_, peer_address_, options_), zap_client_t (session_, peer_address_, options_),
state (expect_hello), state (waiting_for_hello),
current_error_detail (no_detail), current_error_detail (no_detail),
cn_nonce (1), cn_nonce (1),
cn_peer_nonce (1) cn_peer_nonce (1)
...@@ -66,17 +66,17 @@ int zmq::curve_server_t::next_handshake_command (msg_t *msg_) ...@@ -66,17 +66,17 @@ int zmq::curve_server_t::next_handshake_command (msg_t *msg_)
int rc = 0; int rc = 0;
switch (state) { switch (state) {
case send_welcome: case sending_welcome:
rc = produce_welcome (msg_); rc = produce_welcome (msg_);
if (rc == 0) if (rc == 0)
state = expect_initiate; state = waiting_for_initiate;
break; break;
case send_ready: case sending_ready:
rc = produce_ready (msg_); rc = produce_ready (msg_);
if (rc == 0) if (rc == 0)
state = connected; state = ready;
break; break;
case send_error: case sending_error:
rc = produce_error (msg_); rc = produce_error (msg_);
if (rc == 0) if (rc == 0)
state = error_sent; state = error_sent;
...@@ -94,10 +94,10 @@ int zmq::curve_server_t::process_handshake_command (msg_t *msg_) ...@@ -94,10 +94,10 @@ int zmq::curve_server_t::process_handshake_command (msg_t *msg_)
int rc = 0; int rc = 0;
switch (state) { switch (state) {
case expect_hello: case waiting_for_hello:
rc = process_hello (msg_); rc = process_hello (msg_);
break; break;
case expect_initiate: case waiting_for_initiate:
rc = process_initiate (msg_); rc = process_initiate (msg_);
break; break;
default: default:
...@@ -124,7 +124,7 @@ int zmq::curve_server_t::process_handshake_command (msg_t *msg_) ...@@ -124,7 +124,7 @@ int zmq::curve_server_t::process_handshake_command (msg_t *msg_)
int zmq::curve_server_t::encode (msg_t *msg_) int zmq::curve_server_t::encode (msg_t *msg_)
{ {
zmq_assert (state == connected); zmq_assert (state == ready);
const size_t mlen = crypto_box_ZEROBYTES + 1 + msg_->size (); const size_t mlen = crypto_box_ZEROBYTES + 1 + msg_->size ();
...@@ -176,7 +176,7 @@ int zmq::curve_server_t::encode (msg_t *msg_) ...@@ -176,7 +176,7 @@ int zmq::curve_server_t::encode (msg_t *msg_)
int zmq::curve_server_t::decode (msg_t *msg_) int zmq::curve_server_t::decode (msg_t *msg_)
{ {
zmq_assert (state == connected); zmq_assert (state == ready);
if (msg_->size () < 33) { if (msg_->size () < 33) {
// CURVE I : invalid CURVE client, sent malformed command // CURVE I : invalid CURVE client, sent malformed command
...@@ -250,7 +250,7 @@ int zmq::curve_server_t::zap_msg_available () ...@@ -250,7 +250,7 @@ int zmq::curve_server_t::zap_msg_available ()
// TODO I don't think that it is possible that this is called in any // TODO I don't think that it is possible that this is called in any
// state other than expect_zap_reply. It should be changed to // state other than expect_zap_reply. It should be changed to
// zmq_assert (state == expect_zap_reply); // zmq_assert (state == expect_zap_reply);
if (state != expect_zap_reply) { if (state != waiting_for_zap_reply) {
errno = EFSM; errno = EFSM;
return -1; return -1;
} }
...@@ -262,7 +262,7 @@ int zmq::curve_server_t::zap_msg_available () ...@@ -262,7 +262,7 @@ int zmq::curve_server_t::zap_msg_available ()
zmq::mechanism_t::status_t zmq::curve_server_t::status () const zmq::mechanism_t::status_t zmq::curve_server_t::status () const
{ {
if (state == connected) if (state == ready)
return mechanism_t::ready; return mechanism_t::ready;
else else
if (state == error_sent) if (state == error_sent)
...@@ -328,7 +328,7 @@ int zmq::curve_server_t::process_hello (msg_t *msg_) ...@@ -328,7 +328,7 @@ int zmq::curve_server_t::process_hello (msg_t *msg_)
return -1; return -1;
} }
state = send_welcome; state = sending_welcome;
return rc; return rc;
} }
...@@ -528,12 +528,12 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_) ...@@ -528,12 +528,12 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
handle_zap_status_code (); handle_zap_status_code ();
else else
if (errno == EAGAIN) if (errno == EAGAIN)
state = expect_zap_reply; state = waiting_for_zap_reply;
else else
return -1; return -1;
} }
else else
state = send_ready; state = sending_ready;
return parse_metadata (initiate_plaintext + crypto_box_ZEROBYTES + 128, return parse_metadata (initiate_plaintext + crypto_box_ZEROBYTES + 128,
clen - crypto_box_ZEROBYTES - 128); clen - crypto_box_ZEROBYTES - 128);
...@@ -618,9 +618,9 @@ void zmq::curve_server_t::handle_zap_status_code () ...@@ -618,9 +618,9 @@ void zmq::curve_server_t::handle_zap_status_code ()
// we can assume here that status_code is a valid ZAP status code, // we can assume here that status_code is a valid ZAP status code,
// i.e. 200, 300, 400 or 500 // i.e. 200, 300, 400 or 500
if (status_code [0] == '2') { if (status_code [0] == '2') {
state = send_ready; state = sending_ready;
} else { } else {
state = send_error; state = sending_error;
int err = 0; int err = 0;
switch (status_code [0]) { switch (status_code [0]) {
......
...@@ -79,17 +79,6 @@ namespace zmq ...@@ -79,17 +79,6 @@ namespace zmq
private: private:
enum state_t {
expect_hello,
send_welcome,
expect_initiate,
expect_zap_reply,
send_ready,
send_error,
error_sent,
connected
};
// Current FSM state // Current FSM state
state_t state; state_t state;
......
...@@ -181,7 +181,7 @@ zmq::mechanism_t::status_t zmq::null_mechanism_t::status () const ...@@ -181,7 +181,7 @@ zmq::mechanism_t::status_t zmq::null_mechanism_t::status () const
ready_command_received || error_command_received; ready_command_received || error_command_received;
if (ready_command_sent && ready_command_received) if (ready_command_sent && ready_command_received)
return ready; return mechanism_t::ready;
else else
if (command_sent && command_received) if (command_sent && command_received)
return error; return error;
......
...@@ -68,7 +68,7 @@ int zmq::plain_server_t::next_handshake_command (msg_t *msg_) ...@@ -68,7 +68,7 @@ int zmq::plain_server_t::next_handshake_command (msg_t *msg_)
case sending_error: case sending_error:
rc = produce_error (msg_); rc = produce_error (msg_);
if (rc == 0) if (rc == 0)
state = error_command_sent; state = error_sent;
break; break;
default: default:
errno = EAGAIN; errno = EAGAIN;
...@@ -109,7 +109,7 @@ zmq::mechanism_t::status_t zmq::plain_server_t::status () const ...@@ -109,7 +109,7 @@ zmq::mechanism_t::status_t zmq::plain_server_t::status () const
if (state == ready) if (state == ready)
return mechanism_t::ready; return mechanism_t::ready;
else else
if (state == error_command_sent) if (state == error_sent)
return mechanism_t::error; return mechanism_t::error;
else else
return mechanism_t::handshaking; return mechanism_t::handshaking;
......
...@@ -57,17 +57,6 @@ namespace zmq ...@@ -57,17 +57,6 @@ namespace zmq
private: private:
enum state_t {
waiting_for_hello,
sending_welcome,
waiting_for_initiate,
sending_ready,
waiting_for_zap_reply,
sending_error,
error_command_sent,
ready
};
state_t state; state_t state;
int produce_welcome (msg_t *msg_) const; int produce_welcome (msg_t *msg_) const;
......
...@@ -63,6 +63,18 @@ class zap_client_t : public virtual mechanism_t ...@@ -63,6 +63,18 @@ class zap_client_t : public virtual mechanism_t
// Status code as received from ZAP handler // Status code as received from ZAP handler
std::string status_code; std::string status_code;
enum state_t
{
waiting_for_hello,
sending_welcome,
waiting_for_initiate,
waiting_for_zap_reply,
sending_ready,
sending_error,
error_sent,
ready
};
}; };
} }
......
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