Skip to content

Commit ea2450d

Browse files
committed
change state and event enum
Signed-off-by: Emelia Lei <wlei29@bloomberg.net>
1 parent b8f4f7e commit ea2450d

7 files changed

Lines changed: 64 additions & 60 deletions

src/groups/mqb/mqba/mqba_authenticator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int Authenticator::onAuthenticationRequest(
9696
authenticationMsg, // authenticationMessage
9797
context
9898
->authenticationEncodingType(), // authenticationEncodingType
99-
State::e_AUTHENTICATING // state
99+
mqbnet::AuthenticationState::e_AUTHENTICATING // state
100100
);
101101

102102
context->setAuthenticationContext(authenticationContext);
@@ -106,8 +106,7 @@ int Authenticator::onAuthenticationRequest(
106106
errorDescription,
107107
authenticationContext,
108108
context->channel(),
109-
context->state() ==
110-
mqbnet::InitialConnectionState::e_ANON_AUTHENTICATING,
109+
context->state() == InitialConnectionState::e_ANON_AUTHENTICATING,
111110
false);
112111

113112
return rc;
@@ -483,6 +482,7 @@ int Authenticator::handleAuthentication(
483482
}
484483

485484
int Authenticator::authenticationOutbound(
485+
BSLA_UNUSED bsl::ostream& errorDescription,
486486
BSLA_UNUSED const AuthenticationContextSp& context)
487487
{
488488
BALL_LOG_ERROR << "Not Implemented";

src/groups/mqb/mqba/mqba_authenticator.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ class Authenticator : public mqbnet::Authenticator {
8787
bdlcc::ObjectPoolFunctors::RemoveAll<bdlbb::Blob> >
8888
BlobSpPool;
8989

90-
typedef mqbnet::AuthenticationContext::State State;
91-
9290
private:
9391
typedef bsl::shared_ptr<mqbnet::AuthenticationContext>
9492
AuthenticationContextSp;
@@ -111,6 +109,7 @@ class Authenticator : public mqbnet::Authenticator {
111109
/// Thread pool to run authentication and reauthentication tasks.
112110
bdlmt::ThreadPool d_threadPool;
113111

112+
/// Pool of shared pointers to blobs. Held, not owned.
114113
BlobSpPool* d_blobSpPool_p;
115114

116115
/// Used to track the duration of a valid authenticated connection.
@@ -199,7 +198,8 @@ class Authenticator : public mqbnet::Authenticator {
199198
// CREATORS
200199

201200
/// Create a new `Authenticator` using the specified `authnController` and
202-
/// `blobSpPool`. Use the specified `allocator` for all memory allocations.
201+
/// `blobSpPool`. Use the specified `allocator` for all memory
202+
/// allocations.
203203
Authenticator(mqbauthn::AuthenticationController* authnController,
204204
BlobSpPool* blobSpPool,
205205
bdlmt::EventScheduler* scheduler,
@@ -235,7 +235,8 @@ class Authenticator : public mqbnet::Authenticator {
235235
/// `context`. Return 0 on success, or a non-zero error code and populate
236236
/// the specified `errorDescription` with a description of the error
237237
/// otherwise.
238-
int authenticationOutbound(const AuthenticationContextSp& context)
238+
int authenticationOutbound(bsl::ostream& errorDescription,
239+
const AuthenticationContextSp& context)
239240
BSLS_KEYWORD_OVERRIDE;
240241

241242
/// Schedule an authentication job in the thread pool using the

src/groups/mqb/mqbnet/mqbnet_authenticationcontext.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ AuthenticationContext::AuthenticationContext(
102102
InitialConnectionContext* initialConnectionContext,
103103
const bmqp_ctrlmsg::AuthenticationMessage& authenticationMessage,
104104
bmqp::EncodingType::Enum authenticationEncodingType,
105-
State state,
105+
AuthenticationState::Enum state,
106106
bslma::Allocator* allocator)
107107
: d_allocator_p(allocator)
108108
, d_self(this) // use default allocator
@@ -136,12 +136,12 @@ int AuthenticationContext::setAuthenticatedAndScheduleReauthn(
136136

137137
bslmt::LockGuard<bslmt::Mutex> guard(&d_mutex); // LOCKED
138138

139-
if (d_state != State::e_AUTHENTICATING) {
139+
if (d_state != AuthenticationState::e_AUTHENTICATING) {
140140
errorDescription << "State not AUTHENTICATING (was " << d_state << ")";
141141
return -1;
142142
}
143143

144-
d_state = State::e_AUTHENTICATED;
144+
d_state = AuthenticationState::e_AUTHENTICATED;
145145

146146
if (d_timeoutHandle) {
147147
scheduler_p->cancelEventAndWait(&d_timeoutHandle);
@@ -191,7 +191,7 @@ void AuthenticationContext::onReauthenticateErrorOrTimeout(
191191
{
192192
bslmt::LockGuard<bslmt::Mutex> guard(&d_mutex); // LOCKED
193193

194-
if (d_state == State::e_CLOSED) {
194+
if (d_state == AuthenticationState::e_CLOSED) {
195195
return;
196196
}
197197
} // UNLOCK
@@ -213,10 +213,10 @@ void AuthenticationContext::onClose(bdlmt::EventScheduler* scheduler_p)
213213

214214
bslmt::LockGuard<bslmt::Mutex> guard(&d_mutex); // LOCKED
215215

216-
if (d_state == State::e_CLOSED) {
216+
if (d_state == AuthenticationState::e_CLOSED) {
217217
return; // idempotent
218218
}
219-
d_state = State::e_CLOSED;
219+
d_state = AuthenticationState::e_CLOSED;
220220

221221
if (d_timeoutHandle) {
222222
scheduler_p->cancelEventAndWait(&d_timeoutHandle);
@@ -227,8 +227,8 @@ bool AuthenticationContext::tryStartReauthentication()
227227
{
228228
bslmt::LockGuard<bslmt::Mutex> guard(&d_mutex); // LOCKED
229229

230-
if (d_state == State::e_AUTHENTICATED) {
231-
d_state = State::e_AUTHENTICATING;
230+
if (d_state == AuthenticationState::e_AUTHENTICATED) {
231+
d_state = AuthenticationState::e_AUTHENTICATING;
232232
return true;
233233
}
234234

src/groups/mqb/mqbnet/mqbnet_authenticationcontext.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ class AuthenticationContext {
120120

121121
public:
122122
// TYPES
123-
typedef AuthenticationState::Enum State;
124123
typedef bdlmt::EventScheduler::EventHandle EventHandle;
125124

126125
private:
@@ -144,7 +143,7 @@ class AuthenticationContext {
144143
EventHandle d_timeoutHandle;
145144

146145
/// Authentication State.
147-
State d_state;
146+
AuthenticationState::Enum d_state;
148147

149148
/// The initial connection context associated with this authentication
150149
/// context. It is set during the initial authentication, and is null for
@@ -175,7 +174,7 @@ class AuthenticationContext {
175174
InitialConnectionContext* initialConnectionContext,
176175
const bmqp_ctrlmsg::AuthenticationMessage& authenticationMessage,
177176
bmqp::EncodingType::Enum authenticationEncodingType,
178-
State state,
177+
AuthenticationState::Enum state,
179178
bslma::Allocator* allocator = 0);
180179

181180
// MANIPULATORS

src/groups/mqb/mqbnet/mqbnet_authenticator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class Authenticator {
7979
/// the specified `errorDescription` with a description of the error
8080
/// otherwise.
8181
virtual int authenticationOutbound(
82+
bsl::ostream& errorDescription,
8283
const bsl::shared_ptr<AuthenticationContext>& context) = 0;
8384

8485
/// Schedule an authentication job in the thread pool using the

src/groups/mqb/mqbnet/mqbnet_initialconnectioncontext.cpp

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,16 @@ int InitialConnectionContext::processBlob(bsl::ostream& errorDescription,
291291
}
292292
else if (bsl::holds_alternative<bmqp_ctrlmsg::AuthenticationMessage>(
293293
message)) {
294-
handleEvent(rc, bsl::string(), Event::e_AUTHN_REQUEST, message);
294+
handleEvent(rc,
295+
bsl::string(),
296+
InitialConnectionEvent::e_AUTHN_REQUEST,
297+
message);
295298
}
296299
else {
297-
handleEvent(rc, bsl::string(), Event::e_NEGOTIATION_MESSAGE, message);
300+
handleEvent(rc,
301+
bsl::string(),
302+
InitialConnectionEvent::e_NEGOTIATION_MESSAGE,
303+
message);
298304
}
299305

300306
return rc_SUCCESS;
@@ -468,15 +474,17 @@ void InitialConnectionContext::readCallback(const bmqio::Status& status,
468474

469475
if (!status) {
470476
errStream << "Read error: " << status;
471-
handleEvent(rc_READ_BLOB_ERROR, errStream.str(), Event::e_ERROR);
477+
handleEvent(rc_READ_BLOB_ERROR,
478+
errStream.str(),
479+
InitialConnectionEvent::e_ERROR);
472480
return; // RETURN
473481
}
474482

475483
rc = readBlob(errStream, &outPacket, &isFullBlob, numNeeded, blob);
476484
if (rc != rc_SUCCESS) {
477485
handleEvent((rc * 10) + rc_READ_BLOB_ERROR,
478486
errStream.str(),
479-
Event::e_ERROR);
487+
InitialConnectionEvent::e_ERROR);
480488
return; // RETURN
481489
}
482490

@@ -488,7 +496,7 @@ void InitialConnectionContext::readCallback(const bmqio::Status& status,
488496
if (rc != rc_SUCCESS) {
489497
handleEvent((rc * 10) + rc_PROCESS_BLOB_ERROR,
490498
errStream.str(),
491-
Event::e_ERROR);
499+
InitialConnectionEvent::e_ERROR);
492500
return; // RETURN
493501
}
494502
}
@@ -530,23 +538,21 @@ void InitialConnectionContext::handleInitialConnection()
530538
// `negotiateOutbound`.
531539
handleEvent(0,
532540
bsl::string(),
533-
mqbnet::InitialConnectionEvent::e_OUTBOUND_NEGOTATION);
541+
InitialConnectionEvent::e_OUTBOUND_NEGOTATION);
534542
}
535543
else {
536544
bmqu::MemOutStream errStream;
537545
const int rc = scheduleRead(errStream);
538546
if (rc != 0) {
539-
handleEvent(rc,
540-
errStream.str(),
541-
mqbnet::InitialConnectionEvent::e_ERROR);
547+
handleEvent(rc, errStream.str(), InitialConnectionEvent::e_ERROR);
542548
}
543549
}
544550
}
545551

546552
void InitialConnectionContext::handleEvent(
547553
int statusCode,
548554
const bsl::string& errorDescription,
549-
Event input,
555+
InitialConnectionEvent::Enum input,
550556
const bsl::variant<bsl::monostate,
551557
bmqp_ctrlmsg::AuthenticationMessage,
552558
bmqp_ctrlmsg::NegotiationMessage>& message)
@@ -571,12 +577,12 @@ void InitialConnectionContext::handleEvent(
571577
<< "; peerUri = " << d_channelSp->peerUri()
572578
<< "; context address = " << this;
573579

574-
State oldState = d_state;
580+
InitialConnectionState::Enum oldState = d_state;
575581

576582
switch (input) {
577-
case Event::e_OUTBOUND_NEGOTATION: {
578-
if (oldState == State::e_INITIAL) {
579-
setState(State::e_NEGOTIATING_OUTBOUND);
583+
case InitialConnectionEvent::e_OUTBOUND_NEGOTATION: {
584+
if (oldState == InitialConnectionState::e_INITIAL) {
585+
setState(InitialConnectionState::e_NEGOTIATING_OUTBOUND);
580586

581587
createNegotiationContext();
582588

@@ -591,7 +597,7 @@ void InitialConnectionContext::handleEvent(
591597
}
592598
break;
593599
}
594-
case Event::e_AUTHN_REQUEST: {
600+
case InitialConnectionEvent::e_AUTHN_REQUEST: {
595601
if (!bsl::holds_alternative<bmqp_ctrlmsg::AuthenticationMessage>(
596602
message)) {
597603
errStream << "Expecting AuthenticationMessage for event " << input
@@ -601,8 +607,8 @@ void InitialConnectionContext::handleEvent(
601607
const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg =
602608
bsl::get<bmqp_ctrlmsg::AuthenticationMessage>(message);
603609

604-
if (oldState == State::e_INITIAL) {
605-
setState(State::e_AUTHENTICATING);
610+
if (oldState == InitialConnectionState::e_INITIAL) {
611+
setState(InitialConnectionState::e_AUTHENTICATING);
606612

607613
rc = d_authenticator_p->handleAuthentication(errStream,
608614
self,
@@ -614,7 +620,7 @@ void InitialConnectionContext::handleEvent(
614620
}
615621
break;
616622
}
617-
case Event::e_NEGOTIATION_MESSAGE: {
623+
case InitialConnectionEvent::e_NEGOTIATION_MESSAGE: {
618624
if (!bsl::holds_alternative<bmqp_ctrlmsg::NegotiationMessage>(
619625
message)) {
620626
errStream << "Expecting NegotiationMessage for event " << input
@@ -624,27 +630,27 @@ void InitialConnectionContext::handleEvent(
624630
const bmqp_ctrlmsg::NegotiationMessage& negotiationMsg =
625631
bsl::get<bmqp_ctrlmsg::NegotiationMessage>(message);
626632

627-
if (oldState == State::e_INITIAL &&
633+
if (oldState == InitialConnectionState::e_INITIAL &&
628634
negotiationMsg.isClientIdentityValue()) {
629-
setState(State::e_ANON_AUTHENTICATING);
635+
setState(InitialConnectionState::e_ANON_AUTHENTICATING);
630636

631637
createNegotiationContext();
632638
negotiationContext()->setNegotiationMessage(negotiationMsg);
633639

634640
rc = handleAnonAuthentication(errStream);
635641
}
636-
else if (oldState == State::e_AUTHENTICATED &&
642+
else if (oldState == InitialConnectionState::e_AUTHENTICATED &&
637643
negotiationMsg.isClientIdentityValue()) {
638-
setState(State::e_NEGOTIATED);
644+
setState(InitialConnectionState::e_NEGOTIATED);
639645

640646
createNegotiationContext();
641647
negotiationContext()->setNegotiationMessage(negotiationMsg);
642648

643649
rc = rc_SUCCESS;
644650
}
645-
else if (oldState == State::e_NEGOTIATING_OUTBOUND &&
651+
else if (oldState == InitialConnectionState::e_NEGOTIATING_OUTBOUND &&
646652
negotiationMsg.isBrokerResponseValue()) {
647-
setState(State::e_NEGOTIATED);
653+
setState(InitialConnectionState::e_NEGOTIATED);
648654

649655
BSLS_ASSERT_SAFE(negotiationContext());
650656
negotiationContext()->setNegotiationMessage(negotiationMsg);
@@ -658,15 +664,15 @@ void InitialConnectionContext::handleEvent(
658664
}
659665
break;
660666
}
661-
case Event::e_AUTHN_SUCCESS: {
662-
if (oldState == State::e_AUTHENTICATING) {
663-
setState(State::e_AUTHENTICATED);
667+
case InitialConnectionEvent::e_AUTHN_SUCCESS: {
668+
if (oldState == InitialConnectionState::e_AUTHENTICATING) {
669+
setState(InitialConnectionState::e_AUTHENTICATED);
664670

665671
// Now read Negotiation message
666672
rc = scheduleRead(errStream);
667673
}
668-
else if (oldState == State::e_ANON_AUTHENTICATING) {
669-
setState(State::e_NEGOTIATED);
674+
else if (oldState == InitialConnectionState::e_ANON_AUTHENTICATING) {
675+
setState(InitialConnectionState::e_NEGOTIATED);
670676

671677
BSLS_ASSERT_SAFE(negotiationContext());
672678
BSLS_ASSERT_SAFE(negotiationContext()
@@ -681,11 +687,11 @@ void InitialConnectionContext::handleEvent(
681687
}
682688
break;
683689
}
684-
case Event::e_ERROR: {
690+
case InitialConnectionEvent::e_ERROR: {
685691
rc = statusCode;
686692
errStream << errorDescription;
687693
} break;
688-
case Event::e_NONE: {
694+
case InitialConnectionEvent::e_NONE: {
689695
// NOT IMPLEMENTED
690696
BSLS_ASSERT_SAFE(!"Unexpected event received: " + input);
691697
break;
@@ -700,12 +706,12 @@ void InitialConnectionContext::handleEvent(
700706

701707
bsl::shared_ptr<mqbnet::Session> session;
702708

703-
if (rc == rc_SUCCESS && d_state == State::e_NEGOTIATED) {
709+
if (rc == rc_SUCCESS && d_state == InitialConnectionState::e_NEGOTIATED) {
704710
rc = d_negotiator_p->createSessionOnMsgType(errStream, &session, this);
705711
BALL_LOG_INFO << "Created a session with " << channel()->peerUri();
706712
}
707713

708-
if (rc != rc_SUCCESS || d_state == State::e_NEGOTIATED) {
714+
if (rc != rc_SUCCESS || d_state == InitialConnectionState::e_NEGOTIATED) {
709715
BALL_LOG_INFO << "Finished initial connection with rc = " << rc
710716
<< ", error = '" << errStream.str() << "'";
711717
guard.release()->unlock();

0 commit comments

Comments
 (0)