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

refactor(security): add join point to start negotiation #626

Merged
merged 16 commits into from
Sep 17, 2020

Conversation

levy5307
Copy link
Contributor

Previously, the network module is coupled from security, because we should start negotiation when rpc session is connected. To make network decoupled from security, in this pr, I use joint point for starting negotiation. And if you enable authentiation, a joint point, which is implemented in security module, is put_back to on_rpc_session_connected.

And to make network module simply, I removed the SS_NEGOTIATING. Because I think the authentication code should not invade network modules

include/dsn/tool-api/network.h Outdated Show resolved Hide resolved
src/runtime/security/negotiation_service.cpp Outdated Show resolved Hide resolved
Comment on lines +83 to +86
rpc_session::on_rpc_session_connected.put_back(negotiation_service::on_rpc_connected,
"security");
rpc_session::on_rpc_session_disconnected.put_back(negotiation_service::on_rpc_disconnected,
"security");
Copy link
Member

Choose a reason for hiding this comment

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

👍

src/runtime/security/negotiation_service.cpp Show resolved Hide resolved
src/runtime/rpc/network.cpp Outdated Show resolved Hide resolved
Comment on lines +470 to +471
if (negotiation_succeed) {
return negotiation_succeed;
Copy link
Member

Choose a reason for hiding this comment

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

Why these sentense out of lock?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is kind of double check. the first one didn't lock the _lock.
Because negotiation_succeed only transfered from false to true. So if it is true now, it will not change in the later. but if it is false now, maybe it will change soon. So we should use lock to protect it.
Why I use double check here is to be efficient

Copy link
Member

Choose a reason for hiding this comment

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

OK, better to add some comments here

Copy link
Member

Choose a reason for hiding this comment

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

Is on_recv_message in the same lock?

Copy link
Contributor Author

@levy5307 levy5307 Sep 16, 2020

Choose a reason for hiding this comment

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

on_recv_message will not lock any locks. It only calls is_negotiation_succeed to judge whether the negotiation is succeed. if negotiation is not succeed, the received message will be ignored.

acelyc111
acelyc111 previously approved these changes Sep 16, 2020

static zrwlock_nr _lock; // [
static negotiation_map _negotiations;
//]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why add '//]' here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

//[ and //] indicates that the _lock is used for protecting the members locates between [ and ]

hycdong
hycdong previously approved these changes Sep 16, 2020
This reverts commit 8128c53.
acelyc111
acelyc111 previously approved these changes Sep 17, 2020
@levy5307 levy5307 changed the title refactor(security): add joint point to start negotiation refactor(security): add join point to start negotiation Sep 17, 2020
Comment on lines 388 to +390
bool rpc_session::is_auth_success(message_ex *msg)
{
if (security::FLAGS_enable_auth && !_negotiation->negotiation_succeed()) {
if (security::FLAGS_enable_auth && !is_negotiation_succeed()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

From my point, if you want to decouple the negotiation entirely with rpc_session, you should remove this function and modify rpc_session::on_recv_message, where a session rejects the incoming requests when the negotiation is unfinished.

Nevertheless, there's no joint point for recv_message as far as I see. (There's one joint point at task_spec::on_rpc_call, but not suitable since it targets at customization of tasks, rather than general rpc control).

Maybe you can add such joint point later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will do it in the next pull request. I split the refactor of network into 3 pull requests.

@levy5307 levy5307 merged commit e794dec into XiaoMi:master Sep 17, 2020
@levy5307 levy5307 deleted the on-rpc-connected branch September 17, 2020 10:00
levy5307 added a commit to levy5307/rdsn that referenced this pull request Dec 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants