From b4a35fcabc7e5584c504c3863e2f9696013a57bd Mon Sep 17 00:00:00 2001 From: levy Date: Wed, 9 Sep 2020 14:24:53 +0800 Subject: [PATCH 1/2] refactor(security): refactor send func of client_negotiation --- src/runtime/security/client_negotiation.cpp | 31 ++++++++++----------- src/runtime/security/client_negotiation.h | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/runtime/security/client_negotiation.cpp b/src/runtime/security/client_negotiation.cpp index 089b277663..b5222190ca 100644 --- a/src/runtime/security/client_negotiation.cpp +++ b/src/runtime/security/client_negotiation.cpp @@ -42,9 +42,8 @@ void client_negotiation::start() void client_negotiation::list_mechanisms() { - auto request = dsn::make_unique(); - _status = request->status = negotiation_status::type::SASL_LIST_MECHANISMS; - send(std::move(request)); + _status = negotiation_status::type::SASL_LIST_MECHANISMS; + send(_status); } void client_negotiation::handle_response(error_code err, const negotiation_response &&response) @@ -129,10 +128,8 @@ void client_negotiation::on_mechanism_selected(const negotiation_response &resp) std::string start_output; err_s = _sasl->start(_selected_mechanism, "", start_output); if (err_s.is_ok() || ERR_SASL_INCOMPLETE == err_s.code()) { - auto req = dsn::make_unique(); - _status = req->status = negotiation_status::type::SASL_INITIATE; - req->msg = start_output; - send(std::move(req)); + _status = negotiation_status::type::SASL_INITIATE; + send(_status, start_output); } else { dwarn_f("{}: start sasl client failed, error = {}, reason = {}", _name, @@ -153,10 +150,8 @@ void client_negotiation::on_challenge(const negotiation_response &challenge) return; } - auto req = dsn::make_unique(); - _status = req->status = negotiation_status::type::SASL_CHALLENGE_RESP; - req->msg = response_msg; - send(std::move(req)); + _status = negotiation_status::type::SASL_CHALLENGE_RESP; + send(_status, response_msg); return; } @@ -172,16 +167,18 @@ void client_negotiation::on_challenge(const negotiation_response &challenge) void client_negotiation::select_mechanism(const std::string &mechanism) { _selected_mechanism = mechanism; + _status = negotiation_status::type::SASL_SELECT_MECHANISMS; - auto req = dsn::make_unique(); - _status = req->status = negotiation_status::type::SASL_SELECT_MECHANISMS; - req->msg = mechanism; - send(std::move(req)); + send(_status, mechanism); } -void client_negotiation::send(std::unique_ptr request) +void client_negotiation::send(negotiation_status::type status, const std::string &msg) { - negotiation_rpc rpc(std::move(request), RPC_NEGOTIATION); + auto req = dsn::make_unique(); + req->status = status; + req->msg = msg; + + negotiation_rpc rpc(std::move(req), RPC_NEGOTIATION); rpc.call(_session->remote_address(), nullptr, [this, rpc](error_code err) mutable { handle_response(err, std::move(rpc.response())); }); diff --git a/src/runtime/security/client_negotiation.h b/src/runtime/security/client_negotiation.h index 0560d885c8..4ed8d75a9c 100644 --- a/src/runtime/security/client_negotiation.h +++ b/src/runtime/security/client_negotiation.h @@ -37,7 +37,7 @@ class client_negotiation : public negotiation void list_mechanisms(); void select_mechanism(const std::string &mechanism); - void send(std::unique_ptr request); + void send(negotiation_status::type status, const std::string &msg = ""); void succ_negotiation(); friend class client_negotiation_test; From fd4c7cda457f7e3b78b97d38da6ce5176628dcc9 Mon Sep 17 00:00:00 2001 From: levy Date: Wed, 9 Sep 2020 15:33:03 +0800 Subject: [PATCH 2/2] refactor --- src/runtime/security/client_negotiation.cpp | 8 ++++---- src/runtime/security/client_negotiation.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/runtime/security/client_negotiation.cpp b/src/runtime/security/client_negotiation.cpp index b5222190ca..08caadbf70 100644 --- a/src/runtime/security/client_negotiation.cpp +++ b/src/runtime/security/client_negotiation.cpp @@ -129,7 +129,7 @@ void client_negotiation::on_mechanism_selected(const negotiation_response &resp) err_s = _sasl->start(_selected_mechanism, "", start_output); if (err_s.is_ok() || ERR_SASL_INCOMPLETE == err_s.code()) { _status = negotiation_status::type::SASL_INITIATE; - send(_status, start_output); + send(_status, std::move(start_output)); } else { dwarn_f("{}: start sasl client failed, error = {}, reason = {}", _name, @@ -151,7 +151,7 @@ void client_negotiation::on_challenge(const negotiation_response &challenge) } _status = negotiation_status::type::SASL_CHALLENGE_RESP; - send(_status, response_msg); + send(_status, std::move(response_msg)); return; } @@ -169,10 +169,10 @@ void client_negotiation::select_mechanism(const std::string &mechanism) _selected_mechanism = mechanism; _status = negotiation_status::type::SASL_SELECT_MECHANISMS; - send(_status, mechanism); + send(_status, std::move(mechanism)); } -void client_negotiation::send(negotiation_status::type status, const std::string &msg) +void client_negotiation::send(negotiation_status::type status, const std::string &&msg) { auto req = dsn::make_unique(); req->status = status; diff --git a/src/runtime/security/client_negotiation.h b/src/runtime/security/client_negotiation.h index 4ed8d75a9c..4d3263c806 100644 --- a/src/runtime/security/client_negotiation.h +++ b/src/runtime/security/client_negotiation.h @@ -37,7 +37,7 @@ class client_negotiation : public negotiation void list_mechanisms(); void select_mechanism(const std::string &mechanism); - void send(negotiation_status::type status, const std::string &msg = ""); + void send(negotiation_status::type status, const std::string &&msg = ""); void succ_negotiation(); friend class client_negotiation_test;