Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

refactor(security): refactor the send func of client_negotiation #620

Merged
merged 4 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions src/runtime/security/client_negotiation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ void client_negotiation::start()

void client_negotiation::list_mechanisms()
{
auto request = dsn::make_unique<negotiation_request>();
_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)
Expand Down Expand Up @@ -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<negotiation_request>();
_status = req->status = negotiation_status::type::SASL_INITIATE;
req->msg = start_output;
send(std::move(req));
_status = negotiation_status::type::SASL_INITIATE;
send(_status, std::move(start_output));
} else {
dwarn_f("{}: start sasl client failed, error = {}, reason = {}",
_name,
Expand All @@ -153,10 +150,8 @@ void client_negotiation::on_challenge(const negotiation_response &challenge)
return;
}

auto req = dsn::make_unique<negotiation_request>();
_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, std::move(response_msg));
return;
}

Expand All @@ -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<negotiation_request>();
_status = req->status = negotiation_status::type::SASL_SELECT_MECHANISMS;
req->msg = mechanism;
send(std::move(req));
send(_status, std::move(mechanism));
Copy link
Member

@acelyc111 acelyc111 Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mechanism is a 'const &', is it movable? Is there any compile complains?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see any compile complains. And I write a test program like this:

    std::string test = "123123";
    const std::string &ref_test = test;
    const std::string &&r_test = std::move(ref_test);
    std::cout << r_test << std::endl;

It works well.

}

void client_negotiation::send(std::unique_ptr<negotiation_request> 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<negotiation_request>();
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()));
});
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/security/client_negotiation.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class client_negotiation : public negotiation

void list_mechanisms();
void select_mechanism(const std::string &mechanism);
void send(std::unique_ptr<negotiation_request> request);
void send(negotiation_status::type status, const std::string &&msg = "");
void succ_negotiation();

friend class client_negotiation_test;
Expand Down