forked from bloomberg/blazingmq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmqbnet_initialconnectioncontext.cpp
More file actions
787 lines (661 loc) · 25.1 KB
/
Copy pathmqbnet_initialconnectioncontext.cpp
File metadata and controls
787 lines (661 loc) · 25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
// Copyright 2025 Bloomberg Finance L.P.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <mqbnet_initialconnectioncontext.h>
#include <mqbscm_version.h>
// MQB
#include <mqbcfg_messages.h>
#include <mqbnet_authenticationcontext.h>
#include <mqbnet_negotiationcontext.h>
// BMQ
#include <bmqio_channel.h>
#include <bmqio_channelutil.h>
#include <bmqp_ctrlmsg_messages.h>
#include <bmqp_event.h>
#include <bmqu_blob.h>
#include <bmqu_memoutstream.h>
// BDE
#include <ball_log.h>
#include <bdlb_print.h>
#include <bdlb_string.h>
#include <bdlma_localsequentialallocator.h>
#include <bsl_memory.h>
#include <bsl_ostream.h>
#include <bsl_vector.h>
namespace BloombergLP {
namespace mqbnet {
namespace {
const int k_INITIALCONNECTION_READTIMEOUT = 3 * 60; // 3 minutes
}
// -----------------------------
// struct InitialConnectionState
// -----------------------------
bsl::ostream& InitialConnectionState::print(bsl::ostream& stream,
InitialConnectionState::Enum value,
int level,
int spacesPerLevel)
{
if (stream.bad()) {
return stream; // RETURN
}
bdlb::Print::indent(stream, level, spacesPerLevel);
stream << InitialConnectionState::toAscii(value);
if (spacesPerLevel >= 0) {
stream << '\n';
}
return stream;
}
const char* InitialConnectionState::toAscii(InitialConnectionState::Enum value)
{
#define CASE(X) \
case e_##X: return #X;
switch (value) {
CASE(INITIAL)
CASE(AUTHENTICATING)
CASE(AUTHENTICATED)
CASE(ANON_AUTHENTICATING)
CASE(NEGOTIATING_OUTBOUND)
CASE(NEGOTIATED)
CASE(FAILED)
default: return "(* UNKNOWN *)";
}
#undef CASE
}
bool InitialConnectionState::fromAscii(InitialConnectionState::Enum* out,
const bslstl::StringRef& str)
{
#define CHECKVALUE(M) \
if (bdlb::String::areEqualCaseless( \
toAscii(InitialConnectionState::e_##M), \
str.data(), \
static_cast<int>(str.length()))) { \
*out = InitialConnectionState::e_##M; \
return true; \
}
CHECKVALUE(INITIAL)
CHECKVALUE(AUTHENTICATING)
CHECKVALUE(AUTHENTICATED)
CHECKVALUE(ANON_AUTHENTICATING)
CHECKVALUE(NEGOTIATING_OUTBOUND)
CHECKVALUE(NEGOTIATED)
CHECKVALUE(FAILED)
// Invalid string
return false;
#undef CHECKVALUE
}
// -----------------------------
// struct InitialConnectionEvent
// -----------------------------
bsl::ostream& InitialConnectionEvent::print(bsl::ostream& stream,
InitialConnectionEvent::Enum value,
int level,
int spacesPerLevel)
{
if (stream.bad()) {
return stream; // RETURN
}
bdlb::Print::indent(stream, level, spacesPerLevel);
stream << InitialConnectionEvent::toAscii(value);
if (spacesPerLevel >= 0) {
stream << '\n';
}
return stream;
}
const char* InitialConnectionEvent::toAscii(InitialConnectionEvent::Enum value)
{
#define CASE(X) \
case e_##X: return #X;
switch (value) {
CASE(NONE)
CASE(OUTBOUND_NEGOTIATION)
CASE(INCOMING)
CASE(AUTHN_REQUEST)
CASE(NEGOTIATION_MESSAGE)
CASE(AUTHN_SUCCESS)
CASE(ERROR)
default: return "(* UNKNOWN *)";
}
#undef CASE
}
bool InitialConnectionEvent::fromAscii(InitialConnectionEvent::Enum* out,
const bslstl::StringRef& str)
{
#define CHECKVALUE(M) \
if (bdlb::String::areEqualCaseless( \
toAscii(InitialConnectionEvent::e_##M), \
str.data(), \
static_cast<int>(str.length()))) { \
*out = InitialConnectionEvent::e_##M; \
return true; \
}
CHECKVALUE(NONE)
CHECKVALUE(OUTBOUND_NEGOTIATION)
CHECKVALUE(INCOMING)
CHECKVALUE(AUTHN_REQUEST)
CHECKVALUE(NEGOTIATION_MESSAGE)
CHECKVALUE(AUTHN_SUCCESS)
CHECKVALUE(ERROR)
// Invalid string
return false;
#undef CHECKVALUE
}
// -------------------------
// class NegotiationUserData
// -------------------------
NegotiationUserData::~NegotiationUserData()
{
// NOTHING: Pure interface
}
// ------------------------------
// class InitialConnectionContext
// ------------------------------
// CREATORS
InitialConnectionContext::InitialConnectionContext(
bool isIncoming,
mqbnet::Authenticator* authenticator,
mqbnet::Negotiator* negotiator,
const bsl::shared_ptr<NegotiationUserData>& userData,
void* resultState,
const bsl::shared_ptr<bmqio::Channel>& channel,
const InitialConnectionCompleteCb& initialConnectionCompleteCb,
bslma::Allocator* allocator)
: d_allocator_p(allocator)
, d_mutex()
, d_authenticator_p(authenticator)
, d_negotiator_p(negotiator)
, d_resultState_p(resultState)
, d_userData_sp(userData)
, d_channel_sp(channel)
, d_authenticationCtx_sp()
, d_negotiationCtx_sp()
, d_initialConnectionCompleteCb(initialConnectionCompleteCb)
, d_authenticationEncodingType(bmqp::EncodingType::e_BER)
, d_state(InitialConnectionState::e_INITIAL)
, d_isIncoming(isIncoming)
, d_isClosed(false)
{
// NOTHING
}
InitialConnectionContext::~InitialConnectionContext()
{
// NOTHING
}
// PRIVATE MANIPULATORS
void InitialConnectionContext::setState(InitialConnectionState::Enum value,
InitialConnectionEvent::Enum event)
{
BALL_LOG_DEBUG << "State transition: " << d_state << " -> (" << event
<< ") -> " << value << " [peer: " << d_channel_sp.get()
<< "]";
d_state = value;
}
int InitialConnectionContext::scheduleRead(bsl::ostream& errorDescription)
{
// Schedule a TimedRead
bmqio::Status status;
channel()->read(
&status,
bmqp::Protocol::k_PACKET_MIN_SIZE,
bdlf::BindUtil::bind(&InitialConnectionContext::readCallback,
this,
bdlf::PlaceHolders::_1, // status
bdlf::PlaceHolders::_2, // numNeeded
bdlf::PlaceHolders::_3), // blob
bsls::TimeInterval(k_INITIALCONNECTION_READTIMEOUT));
if (!status) {
errorDescription << "Read failed while negotiating: " << status;
return -1; // RETURN
}
return 0;
}
int InitialConnectionContext::readBlob(bsl::ostream& errorDescription,
bdlbb::Blob* outPacket,
bool* isFullBlob,
int* numNeeded,
bdlbb::Blob* blob)
{
int rc = bmqio::ChannelUtil::handleRead(outPacket, numNeeded, blob);
if (rc != 0) {
// This indicates a non recoverable error...
errorDescription << "Unrecoverable read error:\n"
<< bmqu::BlobStartHexDumper(blob);
return -1; // RETURN
}
if (outPacket->length() == 0) {
// Don't yet have a full blob
*isFullBlob = false;
return 0; // RETURN
}
// Have a full blob, indicate no more bytes needed (we have to do this
// because 'handleRead' above set it back to 4 at the end).
*isFullBlob = true;
*numNeeded = 0;
return 0;
}
int InitialConnectionContext::processBlob(bsl::ostream& errorDescription,
const bdlbb::Blob& blob)
{
// executed by one of the *IO* threads
bsl::variant<bsl::monostate,
bmqp_ctrlmsg::AuthenticationMessage,
bmqp_ctrlmsg::NegotiationMessage>
message;
int rc = decodeInitialConnectionMessage(errorDescription, &message, blob);
if (rc != 0) {
errorDescription << "Failed to decode initial connection message";
return -1; // RETURN
}
if (bsl::holds_alternative<bsl::monostate>(message)) {
errorDescription << "Decode AuthenticationMessage or "
"NegotiationMessage succeeds but nothing gets "
"loaded in.";
return -1;
}
else if (bsl::holds_alternative<bmqp_ctrlmsg::AuthenticationMessage>(
message)) {
handleEvent(bsl::string(),
InitialConnectionEvent::e_AUTHN_REQUEST,
message);
}
else {
handleEvent(bsl::string(),
InitialConnectionEvent::e_NEGOTIATION_MESSAGE,
message);
}
return 0;
}
int InitialConnectionContext::decodeInitialConnectionMessage(
bsl::ostream& errorDescription,
bsl::variant<bsl::monostate,
bmqp_ctrlmsg::AuthenticationMessage,
bmqp_ctrlmsg::NegotiationMessage>* message,
const bdlbb::Blob& blob)
{
BSLS_ASSERT(message);
enum RcEnum {
// Value for the various RC error categories
rc_SUCCESS = 0,
rc_INVALID_MESSAGE = -1,
rc_INVALID_EVENT = -2,
rc_INVALID_AUTHENTICATION_EVENT = -3,
rc_INVALID_CONTROL_EVENT = -4
};
bdlma::LocalSequentialAllocator<2048> localAllocator(d_allocator_p);
bmqp::Event event(&blob, &localAllocator);
if (!event.isValid()) {
errorDescription << "Invalid negotiation message received "
<< "(packet is not a valid BlazingMQ event):\n"
<< bmqu::BlobStartHexDumper(&blob);
return rc_INVALID_MESSAGE; // RETURN
}
bmqp_ctrlmsg::AuthenticationMessage authenticationMessage;
bmqp_ctrlmsg::NegotiationMessage negotiationMessage;
if (event.isAuthenticationEvent()) {
BALL_LOG_DEBUG << "Received AuthenticationEvent: "
<< bmqu::BlobStartHexDumper(&blob);
const int rc = event.loadAuthenticationEvent(&authenticationMessage);
if (rc != 0) {
errorDescription
<< "Invalid message received [reason: 'authentication "
"event is not an AuthenticationMessage', rc: "
<< rc << "]:" << bmqu::BlobStartHexDumper(&blob);
return rc_INVALID_AUTHENTICATION_EVENT; // RETURN
}
d_authenticationEncodingType = event.authenticationEventEncodingType();
*message = authenticationMessage;
}
else if (event.isControlEvent()) {
BALL_LOG_DEBUG << "Received ControlEvent: "
<< bmqu::BlobStartHexDumper(&blob);
const int rc = event.loadControlEvent(&negotiationMessage);
if (rc != 0) {
errorDescription << "Invalid message received [reason: 'control "
"event is not a NegotiationMessage', rc: "
<< rc << "]:" << bmqu::BlobStartHexDumper(&blob);
return rc_INVALID_CONTROL_EVENT; // RETURN
}
*message = negotiationMessage;
}
else {
errorDescription
<< "Invalid initial connection message received "
<< "(packet is not an AuthenticationEvent or ControlEvent):\n"
<< bmqu::BlobStartHexDumper(&blob);
return rc_INVALID_EVENT; // RETURN
}
return rc_SUCCESS;
}
void InitialConnectionContext::createNegotiationContext()
{
if (d_negotiationCtx_sp) {
return; // RETURN
}
d_negotiationCtx_sp = bsl::allocate_shared<mqbnet::NegotiationContext>(
d_allocator_p,
this // initialConnectionContext
);
}
int InitialConnectionContext::handleAnonAuthentication(
bsl::ostream& errorDescription)
{
// executed by one of the *IO* threads
// PRECONDITIONS
BSLS_ASSERT_SAFE(!authenticationContext());
if (!d_authenticator_p->anonymousCredential()) {
errorDescription << "Anonymous credential is disallowed, "
<< "cannot negotiate without authentication.";
return -1; // RETURN
}
bmqp_ctrlmsg::AuthenticationMessage authenticationMessage;
bmqp_ctrlmsg::AuthenticationRequest& authenticationRequest =
authenticationMessage.makeAuthenticationRequest();
const mqbcfg::Credential& anonymousCredential =
d_authenticator_p->anonymousCredential().value();
authenticationRequest.mechanism() = anonymousCredential.mechanism();
authenticationRequest.data() = bsl::vector<char>(
anonymousCredential.identity().begin(),
anonymousCredential.identity().end());
const int rc = d_authenticator_p->handleAuthentication(
errorDescription,
this,
authenticationMessage);
return rc;
}
// MANIPULATORS
void InitialConnectionContext::setResultState(void* value)
{
d_resultState_p = value;
}
void InitialConnectionContext::setAuthenticationContext(
const bsl::shared_ptr<AuthenticationContext>& value)
{
// PRECONDITIONS
BSLS_ASSERT_SAFE(!d_authenticationCtx_sp);
d_authenticationCtx_sp = value;
}
void InitialConnectionContext::onClose()
{
d_isClosed = true;
// Propagate close
if (d_authenticationCtx_sp) {
d_authenticationCtx_sp->onClose();
}
}
void InitialConnectionContext::readCallback(const bmqio::Status& status,
int* numNeeded,
bdlbb::Blob* blob)
{
// executed by one of the *IO* threads
// PRECONDITIONS
BALL_LOG_TRACE << "InitialConnectionContext readCb: [status: " << status
<< ", peer: '" << channel().get() << "']";
bmqu::MemOutStream errStream;
if (!status) {
errStream << "Read error: " << status;
handleEvent(errStream.str(), InitialConnectionEvent::e_ERROR);
return; // RETURN
}
bdlbb::Blob outPacket;
bool isFullBlob = true;
int rc = readBlob(errStream, &outPacket, &isFullBlob, numNeeded, blob);
if (rc != 0) {
handleEvent(errStream.str(), InitialConnectionEvent::e_ERROR);
return; // RETURN
}
if (!isFullBlob) {
return; // RETURN
}
rc = processBlob(errStream, outPacket);
if (rc != 0) {
handleEvent(errStream.str(), InitialConnectionEvent::e_ERROR);
return; // RETURN
}
}
void InitialConnectionContext::handleInitialConnection()
{
if (!isIncoming()) {
// TODO: When we are ready to move on to the next step, we should
// call `authenticationOutbound` here instead before calling
// `negotiateOutbound`.
handleEvent(bsl::string(),
mqbnet::InitialConnectionEvent::e_OUTBOUND_NEGOTIATION);
}
else {
handleEvent(bsl::string(), mqbnet::InitialConnectionEvent::e_INCOMING);
}
}
void InitialConnectionContext::handleEvent(
const bsl::string& errorDescription,
InitialConnectionEvent::Enum event,
const bsl::variant<bsl::monostate,
bmqp_ctrlmsg::AuthenticationMessage,
bmqp_ctrlmsg::NegotiationMessage>& message)
{
// executed by an *AUTHENTICATION* or one of the *IO* threads
enum RcEnum {
// Value for the various RC error categories
rc_SUCCESS = 0,
rc_ERROR = -1
};
bmqu::MemOutStream errStream(d_allocator_p);
int rc = rc_ERROR;
bslmt::LockGuard<bslmt::Mutex> guard(&d_mutex); // LOCKED
BALL_LOG_DEBUG << "Enter InitialConnectionContext::handleEvent: "
<< "state = " << d_state << ", event = " << event
<< " [peer: " << d_channel_sp.get() << "]";
InitialConnectionState::Enum oldState = d_state;
switch (event) {
case InitialConnectionEvent::e_OUTBOUND_NEGOTIATION: {
if (oldState == InitialConnectionState::e_INITIAL) {
setState(InitialConnectionState::e_NEGOTIATING_OUTBOUND, event);
createNegotiationContext();
rc = d_negotiator_p->negotiateOutbound(errStream, this);
if (rc == rc_SUCCESS) {
rc = scheduleRead(errStream);
}
}
else {
errStream << "Unexpected event received: " << oldState << " -> "
<< event;
BALL_LOG_ERROR << "#UNEXPECTED_STATE " << errStream.str()
<< " [peer: " << channel().get() << "]";
}
break;
}
case InitialConnectionEvent::e_INCOMING: {
if (oldState == InitialConnectionState::e_INITIAL) {
// For incoming connections, start reading the first message
rc = scheduleRead(errStream);
}
else {
errStream << "Unexpected event received: " << oldState << " -> "
<< event;
BALL_LOG_ERROR << "#UNEXPECTED_STATE " << errStream.str()
<< " [peer: " << channel().get() << "]";
}
break;
}
case InitialConnectionEvent::e_AUTHN_REQUEST: {
BSLS_ASSERT_SAFE(
bsl::holds_alternative<bmqp_ctrlmsg::AuthenticationMessage>(
message));
const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg =
bsl::get<bmqp_ctrlmsg::AuthenticationMessage>(message);
if (oldState == InitialConnectionState::e_INITIAL) {
BALL_LOG_INFO << "Received authentication request"
<< " [peer: " << channel().get() << "]";
setState(InitialConnectionState::e_AUTHENTICATING, event);
rc = d_authenticator_p->handleAuthentication(errStream,
this,
authenticationMsg);
}
else {
errStream << "Unexpected event received: " << oldState << " -> "
<< event;
BALL_LOG_ERROR << "#UNEXPECTED_STATE " << errStream.str()
<< " [peer: " << channel().get() << "]";
}
break;
}
case InitialConnectionEvent::e_NEGOTIATION_MESSAGE: {
BSLS_ASSERT_SAFE(
bsl::holds_alternative<bmqp_ctrlmsg::NegotiationMessage>(message));
const bmqp_ctrlmsg::NegotiationMessage& negotiationMsg =
bsl::get<bmqp_ctrlmsg::NegotiationMessage>(message);
if (oldState == InitialConnectionState::e_INITIAL &&
negotiationMsg.isClientIdentityValue()) {
BALL_LOG_INFO
<< "Received negotiation message without authentication, "
<< "performing anonymous authentication for '"
<< channel().get() << "'";
setState(InitialConnectionState::e_ANON_AUTHENTICATING, event);
createNegotiationContext();
negotiationContext()->setNegotiationMessage(negotiationMsg);
rc = handleAnonAuthentication(errStream);
}
else if (oldState == InitialConnectionState::e_AUTHENTICATED &&
negotiationMsg.isClientIdentityValue()) {
setState(InitialConnectionState::e_NEGOTIATED, event);
createNegotiationContext();
negotiationContext()->setNegotiationMessage(negotiationMsg);
rc = rc_SUCCESS;
}
else if (oldState == InitialConnectionState::e_NEGOTIATING_OUTBOUND &&
negotiationMsg.isBrokerResponseValue()) {
setState(InitialConnectionState::e_NEGOTIATED, event);
BSLS_ASSERT_SAFE(negotiationContext());
negotiationContext()->setNegotiationMessage(negotiationMsg);
rc = rc_SUCCESS;
}
else {
errStream << "Unexpected event received: " << oldState << " -> "
<< event << " [ negotiationMsg: " << negotiationMsg
<< " ]";
BALL_LOG_ERROR << "#UNEXPECTED_STATE " << errStream.str()
<< " [peer: " << channel().get() << "]";
}
break;
}
case InitialConnectionEvent::e_AUTHN_SUCCESS: {
if (oldState == InitialConnectionState::e_AUTHENTICATING) {
setState(InitialConnectionState::e_AUTHENTICATED, event);
// Now read Negotiation message
rc = scheduleRead(errStream);
}
else if (oldState == InitialConnectionState::e_ANON_AUTHENTICATING) {
setState(InitialConnectionState::e_NEGOTIATED, event);
BSLS_ASSERT_SAFE(negotiationContext());
BSLS_ASSERT_SAFE(negotiationContext()
->negotiationMessage()
.isClientIdentityValue());
rc = rc_SUCCESS;
}
else {
errStream << "Unexpected event received: " << oldState << " -> "
<< event;
BALL_LOG_ERROR << "#UNEXPECTED_STATE " << errStream.str()
<< " [peer: " << channel().get() << "]";
}
break;
}
case InitialConnectionEvent::e_ERROR: {
errStream << errorDescription;
} break;
case InitialConnectionEvent::e_NONE: {
errStream << "InitialConnectionContext: received e_NONE event";
BALL_LOG_ERROR << "#UNEXPECTED_STATE " << errStream.str()
<< " [peer: " << channel().get() << "]";
break;
}
default:
errStream << "InitialConnectionContext: "
<< "unexpected event received: " << event;
BALL_LOG_ERROR << "#UNEXPECTED_STATE " << errStream.str()
<< " [peer: " << channel().get() << "]";
}
bsl::shared_ptr<mqbnet::Session> session;
if (rc == rc_SUCCESS && d_state == InitialConnectionState::e_NEGOTIATED) {
rc = d_negotiator_p->createSessionOnMsgType(errStream, &session, this);
BALL_LOG_INFO << "Created a session with '" << channel().get() << "'";
}
if (rc != rc_SUCCESS) {
setState(InitialConnectionState::e_FAILED, event);
}
if (hasFinalState()) {
if (rc != rc_SUCCESS) {
BALL_LOG_INFO << "Finished initial connection with rc = " << rc
<< ", error = '" << errStream.str() << "'"
<< " [peer: " << channel().get() << "]";
}
guard.release()->unlock();
complete(rc, errStream.str(), session);
}
}
// ACCESSORS
bool InitialConnectionContext::isIncoming() const
{
return d_isIncoming;
}
const bsl::shared_ptr<NegotiationUserData>&
InitialConnectionContext::userData() const
{
return d_userData_sp;
}
void* InitialConnectionContext::resultState() const
{
return d_resultState_p;
}
const bsl::shared_ptr<bmqio::Channel>&
InitialConnectionContext::channel() const
{
return d_channel_sp;
}
bmqp::EncodingType::Enum
InitialConnectionContext::authenticationEncodingType() const
{
return d_authenticationEncodingType;
}
const bsl::shared_ptr<AuthenticationContext>&
InitialConnectionContext::authenticationContext() const
{
return d_authenticationCtx_sp;
}
const bsl::shared_ptr<NegotiationContext>&
InitialConnectionContext::negotiationContext() const
{
return d_negotiationCtx_sp;
}
InitialConnectionState::Enum InitialConnectionContext::state() const
{
return d_state;
}
bool InitialConnectionContext::hasFinalState() const
{
return d_state == InitialConnectionState::e_FAILED ||
d_state == InitialConnectionState::e_NEGOTIATED;
}
void InitialConnectionContext::complete(
int rc,
const bsl::string& error,
const bsl::shared_ptr<mqbnet::Session>& session) const
{
BSLS_ASSERT_SAFE(d_initialConnectionCompleteCb);
d_initialConnectionCompleteCb(rc, error, session, channel());
}
bool InitialConnectionContext::isClosed() const
{
return d_isClosed;
}
} // close package namespace
} // close enterprise namespace