Skip to content

Commit 71f8e49

Browse files
committed
address feedback
Signed-off-by: Emelia Lei <[email protected]>
1 parent 524583f commit 71f8e49

File tree

4 files changed

+17
-33
lines changed

4 files changed

+17
-33
lines changed

src/groups/mqb/mqba/mqba_authenticator.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ int Authenticator::onAuthenticationRequest(
9595
authenticationMsg, // authenticationMessage
9696
context
9797
->authenticationEncodingType(), // authenticationEncodingType
98-
State::e_AUTHENTICATING, // state
99-
mqbnet::ConnectionType::e_UNKNOWN // connectionType
98+
State::e_AUTHENTICATING // state
10099
);
101100

102101
context->setAuthenticationContext(authenticationContext);
@@ -214,7 +213,8 @@ void Authenticator::authenticate(
214213

215214
int rc = rc_SUCCESS;
216215
bsl::string error;
217-
mqbnet::InitialConnectionEvent::Enum input;
216+
mqbnet::InitialConnectionEvent::Enum input =
217+
InitialConnectionEvent::e_ERROR;
218218

219219
bdlb::ScopeExitAny handleEventOnReturn(
220220
bdlf::BindUtil::bind(&mqbnet::InitialConnectionContext::handleEvent,
@@ -242,7 +242,6 @@ void Authenticator::authenticate(
242242
if (processRc != rc_SUCCESS) {
243243
rc = (processRc * 10) + rc_PROCESS_AUTHENTICATION_FAILED;
244244
error = processErrStream.str();
245-
input = InitialConnectionEvent::e_ERROR;
246245
return; // RETURN
247246
}
248247

@@ -253,7 +252,6 @@ void Authenticator::authenticate(
253252
if (status.category() != bmqp_ctrlmsg::StatusCategory::E_SUCCESS) {
254253
rc = (status.code() * 10) + rc_AUTHENTICATION_FAILED;
255254
error = status.message();
256-
input = InitialConnectionEvent::e_ERROR;
257255
}
258256
else {
259257
input = InitialConnectionEvent::e_AUTHN_SUCCESS;
@@ -272,14 +270,12 @@ void Authenticator::authenticate(
272270
if (status.category() != bmqp_ctrlmsg::StatusCategory::E_SUCCESS) {
273271
rc = (status.code() * 10) + rc_AUTHENTICATION_FAILED;
274272
error = status.message();
275-
input = InitialConnectionEvent::e_ERROR;
276273
return; // RETURN
277274
}
278275

279276
if (sendRc != rc_SUCCESS) {
280277
rc = (sendRc * 10) + rc_SEND_AUTHENTICATION_RESPONSE_FAILED;
281278
error = sendResponseErrStream.str();
282-
input = InitialConnectionEvent::e_ERROR;
283279
return; // RETURN
284280
}
285281

src/groups/mqb/mqbnet/mqbnet_authenticationcontext.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ AuthenticationContext::AuthenticationContext(
102102
const bmqp_ctrlmsg::AuthenticationMessage& authenticationMessage,
103103
bmqp::EncodingType::Enum authenticationEncodingType,
104104
State state,
105-
ConnectionType::Enum connectionType,
106105
bslma::Allocator* allocator)
107106
: d_self(this) // use default allocator
108107
, d_mutex()
@@ -112,7 +111,6 @@ AuthenticationContext::AuthenticationContext(
112111
, d_initialConnectionContext_p(initialConnectionContext)
113112
, d_authenticationMessage(authenticationMessage)
114113
, d_authenticationEncodingType(authenticationEncodingType)
115-
, d_connectionType(connectionType)
116114
, d_allocator_p(allocator)
117115
{
118116
// NOTHING
@@ -142,11 +140,6 @@ void AuthenticationContext::setAuthenticationEncodingType(
142140
d_authenticationEncodingType = value;
143141
}
144142

145-
void AuthenticationContext::setConnectionType(ConnectionType::Enum value)
146-
{
147-
d_connectionType = value;
148-
}
149-
150143
int AuthenticationContext::scheduleReauthn(
151144
bsl::ostream& errorDescription,
152145
bdlmt::EventScheduler* scheduler_p,
@@ -211,7 +204,7 @@ void AuthenticationContext::onReauthenticateErrorOrTimeout(
211204
<< channel->peerUri() << "' [error: " << errorName
212205
<< ", code: " << errorCode << "]";
213206

214-
bmqio::Status status(bmqio::StatusCategory::e_GENERIC_ERROR,
207+
bmqio::Status status(bmqio::StatusCategory::e_CANCELED,
215208
errorName,
216209
errorCode,
217210
d_allocator_p);
@@ -270,10 +263,5 @@ AuthenticationContext::authenticationEncodingType() const
270263
return d_authenticationEncodingType;
271264
}
272265

273-
ConnectionType::Enum AuthenticationContext::connectionType() const
274-
{
275-
return d_connectionType;
276-
}
277-
278266
} // namespace mqbnet
279267
} // namespace BloombergLP

src/groups/mqb/mqbnet/mqbnet_authenticationcontext.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ class AuthenticationContext {
154154
/// encoding type of the received message.
155155
bmqp::EncodingType::Enum d_authenticationEncodingType;
156156

157-
ConnectionType::Enum d_connectionType;
158-
159157
/// Allocator to use.
160158
bslma::Allocator* d_allocator_p;
161159

@@ -177,7 +175,6 @@ class AuthenticationContext {
177175
const bmqp_ctrlmsg::AuthenticationMessage& authenticationMessage,
178176
bmqp::EncodingType::Enum authenticationEncodingType,
179177
State state,
180-
ConnectionType::Enum connectionType,
181178
bslma::Allocator* allocator = 0);
182179

183180
// MANIPULATORS

src/groups/mqb/mqbnet/mqbnet_initialconnectioncontext.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ void InitialConnectionContext::readCallback(const bmqio::Status& status,
445445
int* numNeeded,
446446
bdlbb::Blob* blob)
447447
{
448+
// executed by one of the *IO* threads
449+
448450
enum RcEnum {
449451
// Value for the various RC error categories
450452
rc_SUCCESS = 0,
@@ -518,6 +520,8 @@ void InitialConnectionContext::handleEvent(
518520
bmqp_ctrlmsg::AuthenticationMessage,
519521
bmqp_ctrlmsg::NegotiationMessage>& message)
520522
{
523+
// executed by an *AUTHENTICATION* or one of the *IO* threads
524+
521525
enum RcEnum {
522526
// Value for the various RC error categories
523527
rc_SUCCESS = 0,
@@ -527,7 +531,7 @@ void InitialConnectionContext::handleEvent(
527531
bsl::shared_ptr<InitialConnectionContext> self = shared_from_this();
528532

529533
bmqu::MemOutStream errStream(d_allocator_p);
530-
int rc = rc_SUCCESS;
534+
int rc = rc_ERROR;
531535

532536
bslmt::LockGuard<bslmt::Mutex> guard(&d_mutex); // LOCKED
533537

@@ -551,7 +555,6 @@ void InitialConnectionContext::handleEvent(
551555
}
552556
}
553557
else {
554-
rc = rc_ERROR;
555558
errStream << "Unexpected event received: " << oldState << " -> "
556559
<< input;
557560
}
@@ -560,7 +563,6 @@ void InitialConnectionContext::handleEvent(
560563
case Event::e_AUTH_REQUEST: {
561564
if (!bsl::holds_alternative<bmqp_ctrlmsg::AuthenticationMessage>(
562565
message)) {
563-
rc = rc_ERROR;
564566
errStream
565567
<< "Expecting AuthenticationMessage for event AUTH_REQUEST.";
566568
break;
@@ -576,7 +578,6 @@ void InitialConnectionContext::handleEvent(
576578
authenticationMsg);
577579
}
578580
else {
579-
rc = rc_ERROR;
580581
errStream << "Unexpected event received: " << oldState << " -> "
581582
<< input;
582583
}
@@ -585,7 +586,6 @@ void InitialConnectionContext::handleEvent(
585586
case Event::e_NEGOTIATION_MESSAGE: {
586587
if (!bsl::holds_alternative<bmqp_ctrlmsg::NegotiationMessage>(
587588
message)) {
588-
rc = rc_ERROR;
589589
errStream << "Expecting NegotiationMessage for event "
590590
"e_NEGOTIATION_MESSAGE.";
591591
break;
@@ -608,6 +608,8 @@ void InitialConnectionContext::handleEvent(
608608

609609
createNegotiationContext();
610610
negotiationContext()->setNegotiationMessage(negotiationMsg);
611+
612+
rc = rc_SUCCESS;
611613
}
612614
else if (oldState == State::e_NEGOTIATING_OUTBOUND &&
613615
negotiationMsg.isBrokerResponseValue()) {
@@ -616,9 +618,10 @@ void InitialConnectionContext::handleEvent(
616618

617619
BSLS_ASSERT_SAFE(negotiationContext());
618620
negotiationContext()->setNegotiationMessage(negotiationMsg);
621+
622+
rc = rc_SUCCESS;
619623
}
620624
else {
621-
rc = rc_ERROR;
622625
errStream << "Unexpected event received: " << oldState << " -> "
623626
<< input << " [ negotiationMsg: " << negotiationMsg
624627
<< " ]";
@@ -639,9 +642,10 @@ void InitialConnectionContext::handleEvent(
639642
BSLS_ASSERT_SAFE(negotiationContext()
640643
->negotiationMessage()
641644
.isClientIdentityValue());
645+
646+
rc = rc_SUCCESS;
642647
}
643648
else {
644-
rc = rc_ERROR;
645649
errStream << "Unexpected event received: " << oldState << " -> "
646650
<< input;
647651
}
@@ -657,7 +661,6 @@ void InitialConnectionContext::handleEvent(
657661
break;
658662
}
659663
default:
660-
rc = rc_ERROR;
661664
errStream << "InitialConnectionContext: "
662665
<< "unexpected event received: " << input;
663666
}
@@ -667,12 +670,12 @@ void InitialConnectionContext::handleEvent(
667670

668671
bsl::shared_ptr<mqbnet::Session> session;
669672

670-
if (rc == 0 && d_state == State::e_NEGOTIATED) {
673+
if (rc == rc_SUCCESS && d_state == State::e_NEGOTIATED) {
671674
rc = d_negotiator_p->createSessionOnMsgType(errStream, &session, this);
672675
BALL_LOG_INFO << "Created a session with " << channel()->peerUri();
673676
}
674677

675-
if (rc != 0 || d_state == State::e_NEGOTIATED) {
678+
if (rc != rc_SUCCESS || d_state == State::e_NEGOTIATED) {
676679
BALL_LOG_INFO << "Finished initial connection with rc = " << rc
677680
<< ", error = '" << errStream.str() << "'";
678681
guard.release()->unlock();

0 commit comments

Comments
 (0)