-
Notifications
You must be signed in to change notification settings - Fork 143
Feat[MQB]: refactor negotiator #670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
e6b2fad
to
0ee460f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 28 out of 30 changed files in this pull request and generated no comments.
Files not reviewed (2)
- src/groups/bmq/bmqp/bmqp_ctrlmsg.xsd: Language not supported
- src/groups/mqb/mqba/package/mqba.mem: Language not supported
Comments suppressed due to low confidence (2)
src/groups/mqb/mqba/mqba_sessionnegotiator.cpp:1041
- The 'initiateOutboundNegotiation' function now returns an int. Please verify that all callers consistently handle non-zero error codes and propagate them appropriately.
int rc = initiateOutboundNegotiation(negotiationContext);
src/groups/mqb/mqba/mqba_authenticator.cpp:46
- [nitpick] The 'readCallback' function is currently empty. Consider providing an implementation or adding tests to validate that read events are handled as expected.
void Authenticator::readCallback(const bmqio::Status& status,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make the authenticator a separate PR if it is not used?
The prefix initialConnect
appears many times, we may want to rethink the names.
The connect
part does not match TCP listen context in which it is used.
We have InitialConnectionHandlerContext
and InitialConnectionContext
Potentially, they can be even merged (the existing design has them split which is fine). We may need better names.
/// specified `context`. | ||
void negotiate(const bsl::shared_ptr<bmqio::Channel>& channel, | ||
const bsl::shared_ptr<OperationContext>& context); | ||
void initialConnect(const bsl::shared_ptr<bmqio::Channel>& channel, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor. initialConnect
seems to apply to both connect and listen results. If so, the name connect
in the context of TCP may imply the connect
part and the listen
part is less obvious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about "handleInitialConnection"?
scheduleRead(initialConnectionContext); | ||
} | ||
else { | ||
if (d_negotiator_mp->negotiateOutboundOrReverse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used to have a comment in SessionNegotiator::negotiate
for this case // If this is a 'connect' negotiation, this could either represent an...
. Is it gone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. It resides in SessionNegotiator::negotiateOutboundOrReverse
now.
scheduleRead(initialConnectionContext); | ||
} | ||
else { | ||
if (d_negotiator_mp->negotiateOutboundOrReverse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the authentication requirements (going to be) in this connect
case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would imagine something similar. We read if it's an incoming request, otherwise maybe have a function like authenticateOutboundOrReverse
.
/// needed, the `initialConnectionCb` may be invoked directly from inside | ||
/// the call to `initialConnect()`. | ||
virtual void | ||
initialConnect(mqbnet::InitialConnectionHandlerContext* context, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comment about initialConnect
name
return; // RETURN | ||
} | ||
|
||
switch (context->d_initialConnectionMessage_p.selectionId()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decodeNegotiationMessage
does not have to cache the decoded message (d_initialConnectionMessage_p
) if it is used in the same stack frame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean in the decodeNegotiationMessage
we shouldn't create an Event
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that decodeNegotiationMessage
does not need to assign to d_negotiationMessage
(unless we need to keep the last received message in which case the name should be different). The assignment can happen when we ready to pass the handling to the negotiator
/// `context`, returning 0. Return a non-zero code on error and | ||
/// populate the specified `errorDescription` with a description of the | ||
/// error. | ||
int decodeNegotiationMessage(bsl::ostream& errorDescription, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we add authentication, will this method read authentication messages? If so, do we still want to call that negotiation
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to decodeInitialConnectionMessage
a01af08
to
c6c893c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 24 out of 25 changed files in this pull request and generated no comments.
Files not reviewed (1)
- src/groups/mqb/mqba/package/mqba.mem: Language not supported
Comments suppressed due to low confidence (1)
src/groups/mqb/mqba/mqba_sessionnegotiator.cpp:296
- The callback is being passed '*session' (i.e. the object pointed by the shared_ptr) instead of passing the shared_ptr itself. This could lead to undefined behavior if 'session' is empty; please change it to 'session'.
context->d_initialConnectionCb(rc_NO_ADMIN_CALLBACK, error, *session);
623737d
to
07e722a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A suggestion. Why don't we keep the name NegotiationContext
. InitialConnectionHandler
creates NegotiationContext
when it is ready to pass the connection handling to the negotiator. After all, this is the context for negotiator use.
That way, we clearly separate context for negotiation from the context for pre-negotiation phase (authentication).
And we have one less ``InitialConnection` prefix.
So, the chain looks like this TCPSessionFactory_OperationContext
-> InitialConnectionHandlerContext
(can be shortened to InitialConnectionContext
) -> NegotiationContext
src/groups/mqb/mqbnet/mqbnet_initialconnectionhandlercontext.t.cpp
Outdated
Show resolved
Hide resolved
return; // RETURN | ||
} | ||
|
||
switch (context->d_initialConnectionMessage_p.selectionId()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that decodeNegotiationMessage
does not need to assign to d_negotiationMessage
(unless we need to keep the last received message in which case the name should be different). The assignment can happen when we ready to pass the handling to the negotiator
…ator Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
… context Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
…otiate() Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
… as mqbnet Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
InitialConnectionContext -> NegotiationContext; InitialConnectionHandlerContext -> InitialConnectionContext Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting there. Few more comments
bdlmt::FixedThreadPool d_threadPool; | ||
|
||
/// Allocator store to spawn new allocators for sub components. | ||
bmqma::CountingAllocatorStore d_allocators; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it used anywhere?
@@ -475,7 +404,8 @@ SessionNegotiator::onClientIdentityMessage(bsl::ostream& errorDescription, | |||
case bmqp_ctrlmsg::ClientType::E_TCPBROKER: | |||
case bmqp_ctrlmsg::ClientType::E_TCPADMIN: { | |||
if (clientIdentity.hostName().empty()) { | |||
clientIdentity.hostName() = context->d_channelSp->peerUri(); | |||
clientIdentity.hostName() = | |||
context->d_initialConnectionContext_p->channel()->peerUri(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ignore. Could have NegotiationContext::channel()
accessor
{ | ||
// Create a NegotiationContext for that connection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BSLS_ASSERT_SAFE(context)
|
||
// Disable some compiler warning for simplified write of the | ||
// 'AbstractSessionTestImp'. | ||
#if defined(BSLS_PLATFORM_CMP_CLANG) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as before, no need for the #pragma
. Just make handleInitialConnection
not inline
if (rc == rc_CONTINUE_READ) { | ||
scheduleRead(context); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to make sure initialConnectionCompleteCb
always gets called. Otherwise, the connection is stuck.
Regarding calling initialConnectionCompleteCb
, there may be an option of calling it from InitialConnectionHandler
only (never from the Negotiator) if the Negotiator is synchronous. Could make the logic easier to follow.
No description provided.