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
This commit is contained in:
sigiesec
2017-08-16 15:25:08 +02:00
parent 414c6f45b8
commit ebba815a4d
6 changed files with 32 additions and 42 deletions

View File

@@ -43,7 +43,7 @@ zmq::curve_server_t::curve_server_t (session_base_t *session_,
const options_t &options_) :
mechanism_t (options_),
zap_client_t (session_, peer_address_, options_),
state (expect_hello),
state (waiting_for_hello),
current_error_detail (no_detail),
cn_nonce (1),
cn_peer_nonce (1)
@@ -66,17 +66,17 @@ int zmq::curve_server_t::next_handshake_command (msg_t *msg_)
int rc = 0;
switch (state) {
case send_welcome:
case sending_welcome:
rc = produce_welcome (msg_);
if (rc == 0)
state = expect_initiate;
state = waiting_for_initiate;
break;
case send_ready:
case sending_ready:
rc = produce_ready (msg_);
if (rc == 0)
state = connected;
state = ready;
break;
case send_error:
case sending_error:
rc = produce_error (msg_);
if (rc == 0)
state = error_sent;
@@ -94,10 +94,10 @@ int zmq::curve_server_t::process_handshake_command (msg_t *msg_)
int rc = 0;
switch (state) {
case expect_hello:
case waiting_for_hello:
rc = process_hello (msg_);
break;
case expect_initiate:
case waiting_for_initiate:
rc = process_initiate (msg_);
break;
default:
@@ -124,7 +124,7 @@ int zmq::curve_server_t::process_handshake_command (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 ();
@@ -176,7 +176,7 @@ int zmq::curve_server_t::encode (msg_t *msg_)
int zmq::curve_server_t::decode (msg_t *msg_)
{
zmq_assert (state == connected);
zmq_assert (state == ready);
if (msg_->size () < 33) {
// CURVE I : invalid CURVE client, sent malformed command
@@ -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
// state other than expect_zap_reply. It should be changed to
// zmq_assert (state == expect_zap_reply);
if (state != expect_zap_reply) {
if (state != waiting_for_zap_reply) {
errno = EFSM;
return -1;
}
@@ -262,7 +262,7 @@ int zmq::curve_server_t::zap_msg_available ()
zmq::mechanism_t::status_t zmq::curve_server_t::status () const
{
if (state == connected)
if (state == ready)
return mechanism_t::ready;
else
if (state == error_sent)
@@ -328,7 +328,7 @@ int zmq::curve_server_t::process_hello (msg_t *msg_)
return -1;
}
state = send_welcome;
state = sending_welcome;
return rc;
}
@@ -528,12 +528,12 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
handle_zap_status_code ();
else
if (errno == EAGAIN)
state = expect_zap_reply;
state = waiting_for_zap_reply;
else
return -1;
}
else
state = send_ready;
state = sending_ready;
return parse_metadata (initiate_plaintext + crypto_box_ZEROBYTES + 128,
clen - crypto_box_ZEROBYTES - 128);
@@ -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,
// i.e. 200, 300, 400 or 500
if (status_code [0] == '2') {
state = send_ready;
state = sending_ready;
} else {
state = send_error;
state = sending_error;
int err = 0;
switch (status_code [0]) {

View File

@@ -79,17 +79,6 @@ namespace zmq
private:
enum state_t {
expect_hello,
send_welcome,
expect_initiate,
expect_zap_reply,
send_ready,
send_error,
error_sent,
connected
};
// Current FSM state
state_t state;

View File

@@ -181,7 +181,7 @@ zmq::mechanism_t::status_t zmq::null_mechanism_t::status () const
ready_command_received || error_command_received;
if (ready_command_sent && ready_command_received)
return ready;
return mechanism_t::ready;
else
if (command_sent && command_received)
return error;

View File

@@ -68,7 +68,7 @@ int zmq::plain_server_t::next_handshake_command (msg_t *msg_)
case sending_error:
rc = produce_error (msg_);
if (rc == 0)
state = error_command_sent;
state = error_sent;
break;
default:
errno = EAGAIN;
@@ -109,7 +109,7 @@ zmq::mechanism_t::status_t zmq::plain_server_t::status () const
if (state == ready)
return mechanism_t::ready;
else
if (state == error_command_sent)
if (state == error_sent)
return mechanism_t::error;
else
return mechanism_t::handshaking;

View File

@@ -57,17 +57,6 @@ namespace zmq
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;
int produce_welcome (msg_t *msg_) const;

View File

@@ -63,6 +63,18 @@ class zap_client_t : public virtual mechanism_t
// Status code as received from ZAP handler
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
};
};
}