@@ -38,17 +38,17 @@ void ChannelContext::Start(const ChannelBuilder & builder)
38
38
ExchangeContext * ChannelContext::NewExchange (ExchangeDelegate * delegate)
39
39
{
40
40
assert (GetState () == ChannelState::kReady );
41
- return mExchangeManager ->NewContext (mStateVars . mReady .mSession , delegate);
41
+ return mExchangeManager ->NewContext (GetReadyVars () .mSession , delegate);
42
42
}
43
43
44
44
bool ChannelContext::MatchNodeId (NodeId nodeId)
45
45
{
46
46
switch (mState )
47
47
{
48
48
case ChannelState::kPreparing :
49
- return nodeId == mStateVars . mPreparing .mBuilder .GetPeerNodeId ();
49
+ return nodeId == GetPrepareVars () .mBuilder .GetPeerNodeId ();
50
50
case ChannelState::kReady : {
51
- auto state = mExchangeManager ->GetSessionMgr ()->GetPeerConnectionState (mStateVars . mReady .mSession );
51
+ auto state = mExchangeManager ->GetSessionMgr ()->GetPeerConnectionState (GetReadyVars () .mSession );
52
52
if (state == nullptr )
53
53
return false ;
54
54
return nodeId == state->GetPeerNodeId ();
@@ -63,7 +63,7 @@ bool ChannelContext::MatchTransport(Transport::Type transport)
63
63
switch (mState )
64
64
{
65
65
case ChannelState::kPreparing :
66
- switch (mStateVars . mPreparing .mBuilder .GetTransportPreference ())
66
+ switch (GetPrepareVars () .mBuilder .GetTransportPreference ())
67
67
{
68
68
case ChannelBuilder::TransportPreference::kPreferConnectionOriented :
69
69
case ChannelBuilder::TransportPreference::kConnectionOriented :
@@ -73,7 +73,7 @@ bool ChannelContext::MatchTransport(Transport::Type transport)
73
73
}
74
74
return false ;
75
75
case ChannelState::kReady : {
76
- auto state = mExchangeManager ->GetSessionMgr ()->GetPeerConnectionState (mStateVars . mReady .mSession );
76
+ auto state = mExchangeManager ->GetSessionMgr ()->GetPeerConnectionState (GetReadyVars () .mSession );
77
77
if (state == nullptr )
78
78
return false ;
79
79
return transport == state->GetPeerAddress ().GetTransportType ();
@@ -118,36 +118,38 @@ bool ChannelContext::MatchesBuilder(const ChannelBuilder & builder)
118
118
119
119
bool ChannelContext::IsCasePairing ()
120
120
{
121
- return mState == ChannelState::kPreparing && mStateVars . mPreparing .mState == PrepareState::kCasePairing ;
121
+ return mState == ChannelState::kPreparing && GetPrepareVars () .mState == PrepareState::kCasePairing ;
122
122
}
123
123
124
124
bool ChannelContext::MatchesSession (SecureSessionHandle session, SecureSessionMgr * ssm)
125
125
{
126
126
switch (mState )
127
127
{
128
128
case ChannelState::kPreparing : {
129
- switch (mStateVars . mPreparing .mState )
129
+ switch (GetPrepareVars () .mState )
130
130
{
131
131
case PrepareState::kCasePairing : {
132
132
auto state = ssm->GetPeerConnectionState (session);
133
- return (state->GetPeerNodeId () == mStateVars . mPreparing .mBuilder .GetPeerNodeId () &&
134
- state->GetPeerKeyID () == mStateVars . mPreparing .mBuilder .GetPeerKeyID ());
133
+ return (state->GetPeerNodeId () == GetPrepareVars () .mBuilder .GetPeerNodeId () &&
134
+ state->GetPeerKeyID () == GetPrepareVars () .mBuilder .GetPeerKeyID ());
135
135
}
136
136
default :
137
137
return false ;
138
138
}
139
139
}
140
140
case ChannelState::kReady :
141
- return mStateVars . mReady .mSession == session;
141
+ return GetReadyVars () .mSession == session;
142
142
default :
143
143
return false ;
144
144
}
145
145
}
146
146
147
147
void ChannelContext::EnterPreparingState (const ChannelBuilder & builder)
148
148
{
149
- mState = ChannelState::kPreparing ;
150
- mStateVars .mPreparing .mBuilder = builder;
149
+ mState = ChannelState::kPreparing ;
150
+
151
+ mStateVars .Set <PrepareVars>();
152
+ GetPrepareVars ().mBuilder = builder;
151
153
152
154
EnterAddressResolve ();
153
155
}
@@ -157,14 +159,14 @@ void ChannelContext::ExitPreparingState() {}
157
159
// Address resolve
158
160
void ChannelContext::EnterAddressResolve ()
159
161
{
160
- mStateVars . mPreparing .mState = PrepareState::kAddressResolving ;
162
+ GetPrepareVars () .mState = PrepareState::kAddressResolving ;
161
163
162
164
// Skip address resolve if the address is provided
163
165
{
164
- auto addr = mStateVars . mPreparing .mBuilder .GetForcePeerAddress ();
166
+ auto addr = GetPrepareVars () .mBuilder .GetForcePeerAddress ();
165
167
if (addr.HasValue ())
166
168
{
167
- mStateVars . mPreparing .mAddress = addr.Value ();
169
+ GetPrepareVars () .mAddress = addr.Value ();
168
170
ExitAddressResolve ();
169
171
// Only CASE session is supported
170
172
EnterCasePairingState ();
@@ -174,10 +176,10 @@ void ChannelContext::EnterAddressResolve()
174
176
175
177
// TODO: call mDNS Scanner::SubscribeNode after PR #4459 is ready
176
178
// Scanner::RegisterScannerDelegate(this)
177
- // Scanner::SubscribeNode(mStateVars.mPreparing .mBuilder.GetPeerNodeId())
179
+ // Scanner::SubscribeNode(GetPrepareVars() .mBuilder.GetPeerNodeId())
178
180
179
181
// The HandleNodeIdResolve may already have been called, recheck the state here before set up the timer
180
- if (mState == ChannelState::kPreparing && mStateVars . mPreparing .mState == PrepareState::kAddressResolving )
182
+ if (mState == ChannelState::kPreparing && GetPrepareVars () .mState == PrepareState::kAddressResolving )
181
183
{
182
184
System::Layer * layer = mExchangeManager ->GetSessionMgr ()->SystemLayer ();
183
185
layer->StartTimer (CHIP_CONFIG_NODE_ADDRESS_RESOLVE_TIMEOUT_MSECS, AddressResolveTimeout, this );
@@ -196,7 +198,7 @@ void ChannelContext::AddressResolveTimeout()
196
198
{
197
199
if (mState != ChannelState::kPreparing )
198
200
return ;
199
- if (mStateVars . mPreparing .mState != PrepareState::kAddressResolving )
201
+ if (GetPrepareVars () .mState != PrepareState::kAddressResolving )
200
202
return ;
201
203
202
204
ExitAddressResolve ();
@@ -219,7 +221,7 @@ void ChannelContext::HandleNodeIdResolve(CHIP_ERROR error, uint64_t nodeId, cons
219
221
return ;
220
222
}
221
223
case ChannelState::kPreparing : {
222
- switch (mStateVars . mPreparing .mState )
224
+ switch (GetPrepareVars () .mState )
223
225
{
224
226
case PrepareState::kAddressResolving : {
225
227
if (error != CHIP_NO_ERROR)
@@ -232,8 +234,8 @@ void ChannelContext::HandleNodeIdResolve(CHIP_ERROR error, uint64_t nodeId, cons
232
234
233
235
if (!address.mAddress .HasValue ())
234
236
return ;
235
- mStateVars . mPreparing .mAddressType = address.mAddressType ;
236
- mStateVars . mPreparing .mAddress = address.mAddress .Value ();
237
+ GetPrepareVars () .mAddressType = address.mAddressType ;
238
+ GetPrepareVars () .mAddress = address.mAddress .Value ();
237
239
ExitAddressResolve ();
238
240
EnterCasePairingState ();
239
241
return ;
@@ -253,18 +255,18 @@ void ChannelContext::HandleNodeIdResolve(CHIP_ERROR error, uint64_t nodeId, cons
253
255
254
256
void ChannelContext::EnterCasePairingState ()
255
257
{
256
- mStateVars . mPreparing . mState = PrepareState:: kCasePairing ;
257
- mStateVars . mPreparing .mCasePairingSession = Platform::New<CASESession>();
258
+ auto & prepare = GetPrepareVars () ;
259
+ prepare .mCasePairingSession = Platform::New<CASESession>();
258
260
259
- ExchangeContext * ctxt = mExchangeManager ->NewContext (SecureSessionHandle (), mStateVars . mPreparing .mCasePairingSession );
261
+ ExchangeContext * ctxt = mExchangeManager ->NewContext (SecureSessionHandle (), prepare .mCasePairingSession );
260
262
VerifyOrReturn (ctxt != nullptr );
261
263
262
264
// TODO: currently only supports IP/UDP paring
263
265
Transport::PeerAddress addr;
264
- addr.SetTransportType (Transport::Type::kUdp ).SetIPAddress (mStateVars . mPreparing .mAddress );
265
- CHIP_ERROR err = mStateVars . mPreparing . mCasePairingSession ->EstablishSession (
266
- addr, & mStateVars . mPreparing . mBuilder . GetOperationalCredentialSet (), mStateVars . mPreparing .mBuilder .GetPeerNodeId (),
267
- mExchangeManager ->GetNextKeyId (), ctxt, this );
266
+ addr.SetTransportType (Transport::Type::kUdp ).SetIPAddress (prepare .mAddress );
267
+ CHIP_ERROR err = prepare. mCasePairingSession ->EstablishSession (addr, &prepare. mBuilder . GetOperationalCredentialSet (),
268
+ prepare .mBuilder .GetPeerNodeId (),
269
+ mExchangeManager ->GetNextKeyId (), ctxt, this );
268
270
if (err != CHIP_NO_ERROR)
269
271
{
270
272
ExitCasePairingState ();
@@ -275,14 +277,14 @@ void ChannelContext::EnterCasePairingState()
275
277
276
278
void ChannelContext::ExitCasePairingState ()
277
279
{
278
- Platform::Delete (mStateVars . mPreparing .mCasePairingSession );
280
+ Platform::Delete (GetPrepareVars () .mCasePairingSession );
279
281
}
280
282
281
283
void ChannelContext::OnSessionEstablishmentError (CHIP_ERROR error)
282
284
{
283
285
if (mState != ChannelState::kPreparing )
284
286
return ;
285
- switch (mStateVars . mPreparing .mState )
287
+ switch (GetPrepareVars () .mState )
286
288
{
287
289
case PrepareState::kCasePairing :
288
290
ExitCasePairingState ();
@@ -298,11 +300,11 @@ void ChannelContext::OnSessionEstablished()
298
300
{
299
301
if (mState != ChannelState::kPreparing )
300
302
return ;
301
- switch (mStateVars . mPreparing .mState )
303
+ switch (GetPrepareVars () .mState )
302
304
{
303
305
case PrepareState::kCasePairing :
304
306
ExitCasePairingState ();
305
- mStateVars . mPreparing .mState = PrepareState::kCasePairingDone ;
307
+ GetPrepareVars () .mState = PrepareState::kCasePairingDone ;
306
308
// TODO: current CASE paring session API doesn't show how to derive a secure session
307
309
return ;
308
310
default :
@@ -314,7 +316,7 @@ void ChannelContext::OnNewConnection(SecureSessionHandle session)
314
316
{
315
317
if (mState != ChannelState::kPreparing )
316
318
return ;
317
- if (mStateVars . mPreparing .mState != PrepareState::kCasePairingDone )
319
+ if (GetPrepareVars () .mState != PrepareState::kCasePairingDone )
318
320
return ;
319
321
320
322
ExitPreparingState ();
@@ -324,8 +326,7 @@ void ChannelContext::OnNewConnection(SecureSessionHandle session)
324
326
void ChannelContext::EnterReadyState (SecureSessionHandle session)
325
327
{
326
328
mState = ChannelState::kReady ;
327
-
328
- mStateVars .mReady .mSession = session;
329
+ mStateVars .Set <ReadyVars>(session);
329
330
mChannelManager ->NotifyChannelEvent (this , [](ChannelDelegate * delegate) { delegate->OnEstablished (); });
330
331
}
331
332
@@ -344,7 +345,7 @@ void ChannelContext::ExitReadyState()
344
345
// Currently SecureSessionManager doesn't provide an interface to close a session
345
346
346
347
// TODO: call mDNS Scanner::UnubscribeNode after PR #4459 is ready
347
- // Scanner::UnsubscribeNode(mStateVars.mPreparing .mBuilder.GetPeerNodeId())
348
+ // Scanner::UnsubscribeNode(GetPrepareVars() .mBuilder.GetPeerNodeId())
348
349
}
349
350
350
351
void ChannelContext::EnterFailedState (CHIP_ERROR error)
0 commit comments