mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[meshcop] consolidate Open() and Bind() in SecureTransport (#12826)
This commit simplifies the `SecureTransport` API by consolidating the previous `Open()` and `Bind()` methods into two specialized `Open()` flavors. The first flavor, `Open(uint16_t aPort, ...)`, creates and binds a UDP socket to a specific port and network interface. If the port is zero, an ephemeral port is automatically selected. The second flavor, `Open(TransportCallback aCallback, ...)`, enables callback-based transmission, where outgoing messages are sent via the provided callback and received messages are passed in through `HandleReceive()`. This consolidation ensures that the transport is fully initialized and ready for traffic in a single method call. It also prevents the creation of unused UDP sockets when a `TransportCallback` is employed, avoiding unnecessary overhead in the `Udp` class. All core components (`BorderAgent`, `Commissioner`, `Joiner`, and `BleSecure`) and related tests are updated to utilize the new patterns.
This commit is contained in:
committed by
GitHub
parent
9c6ddb75c9
commit
641e84aed4
@@ -41,13 +41,7 @@ using namespace ot;
|
||||
|
||||
otError otCoapSecureStart(otInstance *aInstance, uint16_t aPort)
|
||||
{
|
||||
otError error;
|
||||
|
||||
SuccessOrExit(error = AsCoreType(aInstance).Get<Coap::ApplicationCoapSecure>().Open());
|
||||
error = AsCoreType(aInstance).Get<Coap::ApplicationCoapSecure>().Bind(aPort);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
return AsCoreType(aInstance).Get<Coap::ApplicationCoapSecure>().Open(aPort);
|
||||
}
|
||||
|
||||
otError otCoapSecureStartWithMaxConnAttempts(otInstance *aInstance,
|
||||
|
||||
@@ -171,8 +171,7 @@ void Manager::Start(void)
|
||||
mDtlsTransport.SetAcceptCallback(Manager::HandleAcceptSession, this);
|
||||
mDtlsTransport.SetRemoveSessionCallback(Manager::HandleRemoveSession, this);
|
||||
|
||||
SuccessOrExit(error = mDtlsTransport.Open());
|
||||
SuccessOrExit(error = mDtlsTransport.Bind(kUdpPort));
|
||||
SuccessOrExit(error = mDtlsTransport.Open(kUdpPort));
|
||||
|
||||
Get<KeyManager>().GetPskc(pskc);
|
||||
SuccessOrExit(error = mDtlsTransport.SetPsk(pskc.m8, Pskc::kSize));
|
||||
|
||||
@@ -103,8 +103,7 @@ Error EphemeralKeyManager::Start(const char *aKeyString, uint32_t aTimeout, uint
|
||||
mDtlsTransport.SetAcceptCallback(EphemeralKeyManager::HandleAcceptSession, this);
|
||||
mDtlsTransport.SetRemoveSessionCallback(EphemeralKeyManager::HandleRemoveSession, this);
|
||||
|
||||
SuccessOrExit(error = mDtlsTransport.Open());
|
||||
SuccessOrExit(error = mDtlsTransport.Bind(aUdpPort));
|
||||
SuccessOrExit(error = mDtlsTransport.Open(aUdpPort));
|
||||
|
||||
SuccessOrExit(
|
||||
error = mDtlsTransport.SetPsk(reinterpret_cast<const uint8_t *>(aKeyString), static_cast<uint8_t>(length)));
|
||||
|
||||
@@ -265,8 +265,7 @@ Error Commissioner::Start(StateCallback aStateCallback, JoinerCallback aJoinerCa
|
||||
VerifyOrExit(Get<Mle::Mle>().IsAttached(), error = kErrorInvalidState);
|
||||
VerifyOrExit(mState == kStateDisabled, error = kErrorAlready);
|
||||
|
||||
SuccessOrExit(error = Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrExit(error = Get<Tmf::SecureAgent>().Bind(SendRelayTransmit, this));
|
||||
SuccessOrExit(error = Get<Tmf::SecureAgent>().Open(SendRelayTransmit, this));
|
||||
|
||||
Get<Tmf::SecureAgent>().SetConnectCallback(HandleSecureAgentConnectEvent, this);
|
||||
|
||||
|
||||
@@ -126,7 +126,8 @@ Error Joiner::Start(const char *aPskd,
|
||||
VerifyOrExit(mState == kStateIdle, error = kErrorBusy);
|
||||
VerifyOrExit(!Get<Seeker>().IsRunning(), error = kErrorBusy);
|
||||
|
||||
SuccessOrExit(error = Get<Tmf::SecureAgent>().Open(Ip6::NetifIdentifier::kNetifThreadInternal));
|
||||
SuccessOrExit(
|
||||
error = Get<Tmf::SecureAgent>().Open(Get<Seeker>().GetUdpPort(), Ip6::NetifIdentifier::kNetifThreadInternal));
|
||||
|
||||
if (mDiscerner.IsEmpty())
|
||||
{
|
||||
@@ -137,7 +138,6 @@ Error Joiner::Start(const char *aPskd,
|
||||
// (free allocated message, stop seeker, close agent, etc).
|
||||
shouldCleanup = true;
|
||||
|
||||
SuccessOrExit(error = Get<Tmf::SecureAgent>().Bind(Get<Seeker>().GetUdpPort()));
|
||||
Get<Tmf::SecureAgent>().SetConnectCallback(HandleSecureCoapClientConnect, this);
|
||||
Get<Tmf::SecureAgent>().SetPsk(joinerPskd);
|
||||
|
||||
|
||||
@@ -680,14 +680,41 @@ SecureTransport::SecureTransport(Instance &aInstance, LinkSecurityMode aLayerTwo
|
||||
OT_UNUSED_VARIABLE(mVerifyPeerCertificate);
|
||||
}
|
||||
|
||||
Error SecureTransport::Open(Ip6::NetifIdentifier aNetifIdentifier)
|
||||
Error SecureTransport::Open(uint16_t aPort, Ip6::NetifIdentifier aNetifIdentifier)
|
||||
{
|
||||
Error error;
|
||||
|
||||
VerifyOrExit(!mIsOpen, error = kErrorAlready);
|
||||
|
||||
SuccessOrExit(error = mSocket.Open(aNetifIdentifier));
|
||||
mIsOpen = true;
|
||||
|
||||
error = mSocket.Bind(aPort);
|
||||
|
||||
if (error != kErrorNone)
|
||||
{
|
||||
IgnoreError(mSocket.Close());
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
mIsOpen = true;
|
||||
mTransportCallback.Clear();
|
||||
|
||||
mRemainingConnectionAttempts = mMaxConnectionAttempts;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error SecureTransport::Open(TransportCallback aCallback, void *aContext)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
VerifyOrExit(!mIsOpen, error = kErrorAlready);
|
||||
VerifyOrExit(aCallback != nullptr, error = kErrorInvalidArgs);
|
||||
|
||||
mIsOpen = true;
|
||||
mTransportCallback.Set(aCallback, aContext);
|
||||
|
||||
mRemainingConnectionAttempts = mMaxConnectionAttempts;
|
||||
|
||||
exit:
|
||||
@@ -737,37 +764,6 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
Error SecureTransport::Bind(uint16_t aPort)
|
||||
{
|
||||
Error error;
|
||||
|
||||
VerifyOrExit(mIsOpen, error = kErrorInvalidState);
|
||||
VerifyOrExit(!mTransportCallback.IsSet(), error = kErrorAlready);
|
||||
|
||||
VerifyOrExit(mSessions.IsEmpty(), error = kErrorInvalidState);
|
||||
|
||||
error = mSocket.Bind(aPort);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error SecureTransport::Bind(TransportCallback aCallback, void *aContext)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
VerifyOrExit(mIsOpen, error = kErrorInvalidState);
|
||||
VerifyOrExit(!mSocket.IsBound(), error = kErrorAlready);
|
||||
VerifyOrExit(!mTransportCallback.IsSet(), error = kErrorAlready);
|
||||
|
||||
VerifyOrExit(mSessions.IsEmpty(), error = kErrorInvalidState);
|
||||
|
||||
mTransportCallback.Set(aCallback, aContext);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void SecureTransport::Close(void)
|
||||
{
|
||||
VerifyOrExit(mIsOpen);
|
||||
@@ -789,10 +785,15 @@ void SecureTransport::Close(void)
|
||||
|
||||
RemoveDisconnectedSessions();
|
||||
|
||||
if (UsesSocket())
|
||||
{
|
||||
IgnoreError(mSocket.Close());
|
||||
}
|
||||
|
||||
mTransportCallback.Clear();
|
||||
|
||||
mIsOpen = false;
|
||||
mIsClosing = false;
|
||||
mTransportCallback.Clear();
|
||||
IgnoreError(mSocket.Close());
|
||||
mTimer.Stop();
|
||||
|
||||
exit:
|
||||
@@ -864,13 +865,13 @@ int SecureTransport::Transmit(const unsigned char *aBuf,
|
||||
|
||||
SuccessOrExit(error = message->AppendBytes(aBuf, static_cast<uint16_t>(aLength)));
|
||||
|
||||
if (mTransportCallback.IsSet())
|
||||
if (UsesSocket())
|
||||
{
|
||||
error = mTransportCallback.Invoke(*message, aMessageInfo);
|
||||
error = mSocket.SendTo(*message, aMessageInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = mSocket.SendTo(*message, aMessageInfo);
|
||||
error = mTransportCallback.Invoke(*message, aMessageInfo);
|
||||
}
|
||||
|
||||
exit:
|
||||
@@ -1044,7 +1045,7 @@ void SecureTransport::HandleMbedtlsDebug(int aLevel, const char *aFile, int aLin
|
||||
break;
|
||||
}
|
||||
|
||||
LogAt(logLevel, "[%u] %s", mSocket.GetSockName().mPort, aStr);
|
||||
LogAt(logLevel, "[%u] %s", UsesSocket() ? mSocket.GetSockName().mPort : 0, aStr);
|
||||
|
||||
OT_UNUSED_VARIABLE(aStr);
|
||||
OT_UNUSED_VARIABLE(aFile);
|
||||
|
||||
@@ -343,7 +343,7 @@ public:
|
||||
typedef Error (*TransportCallback)(void *aContext, ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
/**
|
||||
* Callback to notify when the socket is automatically closed due to reaching the maximum number of connection
|
||||
* Callback to notify when the transport is automatically closed due to reaching the maximum number of connection
|
||||
* attempts (set from `SetMaxConnectionAttempts()`).
|
||||
*
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
@@ -617,26 +617,46 @@ public:
|
||||
#endif // OPENTHREAD_CONFIG_TLS_API_ENABLE
|
||||
|
||||
/**
|
||||
* Opens the transport.
|
||||
* Opens the secure transport and binds it to a UDP socket.
|
||||
*
|
||||
* @param[in] aNetifIdentifier A network interface identifier. If not explicitly provided, kNetifUnspecified will
|
||||
* be used by default.
|
||||
* This flavor of `Open` creates and binds a UDP socket to the specified @p aPort and @p aNetifIdentifier. The
|
||||
* transport will then use this socket for all its traffic.
|
||||
*
|
||||
* @retval kErrorNone Successfully opened the socket.
|
||||
* @retval kErrorAlready The connection is already open.
|
||||
* If @p aPort is zero, an ephemeral port number is picked by the socket. The chosen port can be retrieved using
|
||||
* `GetUdpPort()`.
|
||||
*
|
||||
* @param[in] aPort The port to bind to. If zero, an ephemeral port is used.
|
||||
* @param[in] aNetifIdentifier A network interface identifier. `kNetifUnspecified` will be used by default.
|
||||
*
|
||||
* @retval kErrorNone Successfully opened the socket and bound it to @p aPort.
|
||||
* @retval kErrorAlready The secure transport is already open.
|
||||
*/
|
||||
Error Open(Ip6::NetifIdentifier aNetifIdentifier = Ip6::NetifIdentifier::kNetifUnspecified);
|
||||
Error Open(uint16_t aPort, Ip6::NetifIdentifier aNetifIdentifier = Ip6::NetifIdentifier::kNetifUnspecified);
|
||||
|
||||
/**
|
||||
* Sets the maximum number of allowed connection requests before socket is automatically closed.
|
||||
* Opens the secure transport using a callback for transmission.
|
||||
*
|
||||
* This method can be called when socket is closed. Otherwise `kErrorInvalidSatet` is returned.
|
||||
* This flavor of `Open` does not use a UDP socket. Instead, it relies on the provided @p aCallback for all outgoing
|
||||
* message transmissions. It also expects received messages to be passed in through `HandleReceive()`.
|
||||
*
|
||||
* If @p aMaxAttempts is zero, no limit is applied and connections are allowed until the socket is closed. This is
|
||||
* the default behavior if `SetMaxConnectionAttempts()` is not called.
|
||||
* @param[in] aCallback A pointer to a function for sending messages.
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
*
|
||||
* @retval kErrorNone Successfully opened the transport.
|
||||
* @retval kErrorAlready The secure transport is already open.
|
||||
*/
|
||||
Error Open(TransportCallback aCallback, void *aContext);
|
||||
|
||||
/**
|
||||
* Sets the maximum number of allowed connection requests before transport is automatically closed.
|
||||
*
|
||||
* This method can be called when transport is closed. Otherwise `kErrorInvalidState` is returned.
|
||||
*
|
||||
* If @p aMaxAttempts is zero, no limit is applied and connections are allowed until the transport is closed. This
|
||||
* is the default behavior if `SetMaxConnectionAttempts()` is not called.
|
||||
*
|
||||
* @param[in] aMaxAttempts Maximum number of allowed connection attempts.
|
||||
* @param[in] aCallback Callback to notify when max number of attempts has reached and socket is closed.
|
||||
* @param[in] aCallback Callback to notify when max number of attempts has reached and transport is closed.
|
||||
* @param[in] aContext A pointer to arbitrary context to use with `AutoCloseCallback`.
|
||||
*
|
||||
* @retval kErrorNone Successfully set the maximum allowed connection attempts and callback.
|
||||
@@ -664,45 +684,32 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds this DTLS to a UDP port.
|
||||
* Indicates whether or not the secure transport uses a UDP socket.
|
||||
*
|
||||
* @param[in] aPort The port to bind.
|
||||
*
|
||||
* @retval kErrorNone Successfully bound the socket.
|
||||
* @retval kErrorInvalidState The socket is not open.
|
||||
* @retval kErrorAlready Already bound.
|
||||
* @retval TRUE The secure transport is open and uses a UDP socket.
|
||||
* @retval FALSE The secure transport is either closed or does not use a UDP socket.
|
||||
*/
|
||||
Error Bind(uint16_t aPort);
|
||||
bool UsesSocket(void) const { return mIsOpen && !mTransportCallback.IsSet(); }
|
||||
|
||||
/**
|
||||
* Gets the UDP port of this session.
|
||||
* Gets the UDP port of the secure transport.
|
||||
*
|
||||
* @returns UDP port number.
|
||||
* This method can only be used if the secure transport is open and uses a UDP socket. Otherwise, it returns 0.
|
||||
*
|
||||
* @returns The UDP port number if the transport uses a socket, 0 otherwise.
|
||||
*/
|
||||
uint16_t GetUdpPort(void) const { return mSocket.GetSockName().GetPort(); }
|
||||
uint16_t GetUdpPort(void) const { return UsesSocket() ? mSocket.GetSockName().GetPort() : 0; }
|
||||
|
||||
/**
|
||||
* Binds with a transport callback.
|
||||
* Indicates whether or not the secure transport is closed.
|
||||
*
|
||||
* @param[in] aCallback A pointer to a function for sending messages.
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
*
|
||||
* @retval kErrorNone Successfully bound the socket.
|
||||
* @retval kErrorInvalidState The socket is not open.
|
||||
* @retval kErrorAlready Already bound.
|
||||
*/
|
||||
Error Bind(TransportCallback aCallback, void *aContext);
|
||||
|
||||
/**
|
||||
* Indicates whether or not the secure transpose socket is closed.
|
||||
*
|
||||
* @retval TRUE The secure transport socket closed.
|
||||
* @retval FALSE The secure transport socket is not closed.
|
||||
* @retval TRUE The secure transport closed.
|
||||
* @retval FALSE The secure transport is not closed.
|
||||
*/
|
||||
bool IsClosed(void) const { return !mIsOpen; }
|
||||
|
||||
/**
|
||||
* Closes the socket.
|
||||
* Closes the transport.
|
||||
*/
|
||||
void Close(void);
|
||||
|
||||
@@ -724,11 +731,13 @@ public:
|
||||
void SetPsk(const JoinerPskd &aPskd);
|
||||
|
||||
/**
|
||||
* Checks and handles a received message provided to the SecureTransport object. If checks based on
|
||||
* the message info and current connection state pass, the message is processed.
|
||||
* Checks and handles a received message provided to the `SecureTransport`.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message to receive.
|
||||
* @param[in] aMessageInfo A reference to the message info associated with @p aMessage.
|
||||
* This method is intended to be used with the flavor of `Open()` that uses a `TransportCallback`. It is used to
|
||||
* pass in a received message for the transport to process.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message to receive.
|
||||
* @param[in] aMessageInfo A reference to the message info associated with @p aMessage.
|
||||
*/
|
||||
void HandleReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
|
||||
@@ -81,10 +81,9 @@ Error BleSecure::Start(ConnectCallback aConnectHandler, ReceiveCallback aReceive
|
||||
VerifyOrExit(advertisementData != nullptr, error = kErrorFailed);
|
||||
SuccessOrExit(error = otPlatBleGapAdvSetData(&GetInstance(), advertisementData, advertisementLen));
|
||||
|
||||
SuccessOrExit(error = mTls.Open());
|
||||
SuccessOrExit(error = mTls.Open(HandleTransport, this));
|
||||
mTls.SetReceiveCallback(HandleTlsReceive, this);
|
||||
mTls.SetConnectCallback(HandleTlsConnectEvent, this);
|
||||
SuccessOrExit(error = mTls.Bind(HandleTransport, this));
|
||||
|
||||
// attempt to start BLE advertising only if everything else succeeded.
|
||||
mBleState = kNotAdvertising;
|
||||
|
||||
@@ -449,7 +449,7 @@ void TestBorderAdmitterEnrollerInteraction(void)
|
||||
|
||||
enroller.Get<Tmf::SecureAgent>().RegisterResourceHandler(HandleResource, &recvContext);
|
||||
|
||||
SuccessOrQuit(enroller.Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(enroller.Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(enroller.Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(Time::kOneSecondInMsec);
|
||||
@@ -1135,7 +1135,7 @@ void TestBorderAdmitterCommissionerConflictAndPetitionerRetry(void)
|
||||
|
||||
enroller.Get<Tmf::SecureAgent>().RegisterResourceHandler(HandleResource, &recvContext);
|
||||
|
||||
SuccessOrQuit(enroller.Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(enroller.Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(enroller.Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(Time::kOneSecondInMsec);
|
||||
@@ -1423,7 +1423,7 @@ void TestBorderAdmitterMultipleEnrollers(void)
|
||||
recvContext[i].Clear();
|
||||
enroller->Get<Tmf::SecureAgent>().RegisterResourceHandler(HandleResource, &recvContext[i]);
|
||||
|
||||
SuccessOrQuit(enroller->Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(enroller->Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(enroller->Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(Time::kOneSecondInMsec);
|
||||
@@ -1761,7 +1761,7 @@ void TestBorderAdmitterJoinerEnrollerInteraction(void)
|
||||
recvContext[i].Clear();
|
||||
enroller->Get<Tmf::SecureAgent>().RegisterResourceHandler(HandleResource, &recvContext[i]);
|
||||
|
||||
SuccessOrQuit(enroller->Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(enroller->Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(enroller->Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(Time::kOneSecondInMsec);
|
||||
@@ -3259,7 +3259,7 @@ void TestBorderAdmitterForwardingUdpProxy(void)
|
||||
recvContext[i].Clear();
|
||||
enroller->Get<Tmf::SecureAgent>().RegisterResourceHandler(HandleResource, &recvContext[i]);
|
||||
|
||||
SuccessOrQuit(enroller->Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(enroller->Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(enroller->Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(Time::kOneSecondInMsec);
|
||||
|
||||
@@ -113,7 +113,7 @@ void TestBorderAgent(void)
|
||||
node0.Get<KeyManager>().GetPskc(pskc);
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().SetPsk(pskc.m8, Pskc::kSize));
|
||||
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
@@ -145,7 +145,7 @@ void TestBorderAgent(void)
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Log("Establish a secure connection again");
|
||||
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
@@ -245,11 +245,11 @@ void TestBorderAgent(void)
|
||||
Log("Establish two more secure sessions while the first session is still active");
|
||||
|
||||
SuccessOrQuit(node2.Get<Tmf::SecureAgent>().SetPsk(pskc.m8, Pskc::kSize));
|
||||
SuccessOrQuit(node2.Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(node2.Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(node2.Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
SuccessOrQuit(node3.Get<Tmf::SecureAgent>().SetPsk(pskc.m8, Pskc::kSize));
|
||||
SuccessOrQuit(node3.Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(node3.Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(node3.Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
@@ -313,7 +313,7 @@ void TestBorderAgent(void)
|
||||
|
||||
nexus.AdvanceTime(25 * Time::kOneSecondInMsec);
|
||||
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
@@ -481,7 +481,7 @@ void TestBorderAgentEphemeralKey(void)
|
||||
SuccessOrQuit(
|
||||
node1.Get<Tmf::SecureAgent>().SetPsk(reinterpret_cast<const uint8_t *>(kEphemeralKey), kEphemeralKeySize));
|
||||
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
@@ -521,7 +521,7 @@ void TestBorderAgentEphemeralKey(void)
|
||||
VerifyOrQuit(node0.Get<EphemeralKeyManager>().GetState() == EphemeralKeyManager::kStateStarted);
|
||||
VerifyOrQuit(node0.Get<EphemeralKeyManager>().GetUdpPort() == kUdpPort);
|
||||
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(2 * Time::kOneSecondInMsec);
|
||||
@@ -619,7 +619,7 @@ void TestBorderAgentEphemeralKey(void)
|
||||
SuccessOrQuit(
|
||||
node1.Get<Tmf::SecureAgent>().SetPsk(reinterpret_cast<const uint8_t *>(kEphemeralKey), kEphemeralKeySize));
|
||||
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
@@ -670,7 +670,7 @@ void TestBorderAgentEphemeralKey(void)
|
||||
|
||||
node0.Get<KeyManager>().GetPskc(pskc);
|
||||
SuccessOrQuit(node2.Get<Tmf::SecureAgent>().SetPsk(pskc.m8, Pskc::kSize));
|
||||
SuccessOrQuit(node2.Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(node2.Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(node2.Get<Tmf::SecureAgent>().Connect(baSockAddr));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
@@ -690,7 +690,7 @@ void TestBorderAgentEphemeralKey(void)
|
||||
SuccessOrQuit(
|
||||
node1.Get<Tmf::SecureAgent>().SetPsk(reinterpret_cast<const uint8_t *>(kEphemeralKey), kEphemeralKeySize));
|
||||
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
@@ -902,7 +902,7 @@ void TestHistoryTrackerBorderAgentEpskcEvent(void)
|
||||
|
||||
nexus.AdvanceTime(0);
|
||||
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open());
|
||||
SuccessOrQuit(node1.Get<Tmf::SecureAgent>().Open(0));
|
||||
SuccessOrQuit(
|
||||
node1.Get<Tmf::SecureAgent>().SetPsk(reinterpret_cast<const uint8_t *>(kEphemeralKey), kEphemeralKeySize - 2));
|
||||
|
||||
|
||||
@@ -274,8 +274,7 @@ void TestDtlsSingleSession(void)
|
||||
SuccessOrQuit(dtls0.SetPsk(kPsk, sizeof(kPsk)));
|
||||
dtls0.SetReceiveCallback(HandleReceive, &node0);
|
||||
dtls0.SetConnectCallback(HandleConnectEvent, &node0);
|
||||
SuccessOrQuit(dtls0.Open());
|
||||
SuccessOrQuit(dtls0.Bind(kUdpPort));
|
||||
SuccessOrQuit(dtls0.Open(kUdpPort));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
|
||||
@@ -291,7 +290,7 @@ void TestDtlsSingleSession(void)
|
||||
SuccessOrQuit(dtls1.SetPsk(kPsk, sizeof(kPsk) - 1));
|
||||
dtls1.SetReceiveCallback(HandleReceive, &node1);
|
||||
dtls1.SetConnectCallback(HandleConnectEvent, &node1);
|
||||
SuccessOrQuit(dtls1.Open());
|
||||
SuccessOrQuit(dtls1.Open(0));
|
||||
|
||||
for (uint16_t iter = 0; iter <= kMaxAttempts + 1; iter++)
|
||||
{
|
||||
@@ -315,7 +314,7 @@ void TestDtlsSingleSession(void)
|
||||
SuccessOrQuit(dtls1.SetPsk(kPsk, sizeof(kPsk)));
|
||||
dtls1.SetReceiveCallback(HandleReceive, &node1);
|
||||
dtls1.SetConnectCallback(HandleConnectEvent, &node1);
|
||||
SuccessOrQuit(dtls1.Open());
|
||||
SuccessOrQuit(dtls1.Open(0));
|
||||
SuccessOrQuit(dtls1.Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
@@ -386,7 +385,7 @@ void TestDtlsSingleSession(void)
|
||||
SuccessOrQuit(dtls2.SetPsk(kPsk, sizeof(kPsk)));
|
||||
dtls2.SetReceiveCallback(HandleReceive, &node2);
|
||||
dtls2.SetReceiveCallback(HandleReceive, &node2);
|
||||
SuccessOrQuit(dtls2.Open());
|
||||
SuccessOrQuit(dtls2.Open(0));
|
||||
SuccessOrQuit(dtls2.Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(20 * Time::kOneSecondInMsec);
|
||||
@@ -425,8 +424,7 @@ void TestDtlsSingleSession(void)
|
||||
SuccessOrQuit(dtls0.SetPsk(kPsk, sizeof(kPsk)));
|
||||
dtls0.SetReceiveCallback(HandleReceive, &node0);
|
||||
dtls0.SetConnectCallback(HandleConnectEvent, &node0);
|
||||
SuccessOrQuit(dtls0.Open());
|
||||
SuccessOrQuit(dtls0.Bind(kUdpPort));
|
||||
SuccessOrQuit(dtls0.Open(kUdpPort));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
|
||||
@@ -439,7 +437,7 @@ void TestDtlsSingleSession(void)
|
||||
SuccessOrQuit(dtls1.SetPsk(kPsk, sizeof(kPsk) - 1));
|
||||
dtls1.SetReceiveCallback(HandleReceive, &node1);
|
||||
dtls1.SetConnectCallback(HandleConnectEvent, &node1);
|
||||
SuccessOrQuit(dtls1.Open());
|
||||
SuccessOrQuit(dtls1.Open(0));
|
||||
|
||||
for (uint16_t iter = 0; iter < kMaxAttempts - 1; iter++)
|
||||
{
|
||||
@@ -513,8 +511,7 @@ void TestDtlsMultiSession(void)
|
||||
Log("Start DTLS (server) on node0 bound to port %u", kUdpPort);
|
||||
|
||||
SuccessOrQuit(dtls0.SetPsk(kPsk, sizeof(kPsk)));
|
||||
SuccessOrQuit(dtls0.Open());
|
||||
SuccessOrQuit(dtls0.Bind(kUdpPort));
|
||||
SuccessOrQuit(dtls0.Open(kUdpPort));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
|
||||
@@ -531,7 +528,7 @@ void TestDtlsMultiSession(void)
|
||||
SuccessOrQuit(dtls1.SetPsk(kPsk, sizeof(kPsk)));
|
||||
dtls1.SetReceiveCallback(HandleReceive, &node1);
|
||||
dtls1.SetConnectCallback(HandleConnectEvent, &node1);
|
||||
SuccessOrQuit(dtls1.Open());
|
||||
SuccessOrQuit(dtls1.Open(0));
|
||||
SuccessOrQuit(dtls1.Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
@@ -560,7 +557,7 @@ void TestDtlsMultiSession(void)
|
||||
SuccessOrQuit(dtls2.SetPsk(kPsk, sizeof(kPsk)));
|
||||
dtls2.SetReceiveCallback(HandleReceive, &node2);
|
||||
dtls2.SetConnectCallback(HandleConnectEvent, &node2);
|
||||
SuccessOrQuit(dtls2.Open());
|
||||
SuccessOrQuit(dtls2.Open(0));
|
||||
SuccessOrQuit(dtls2.Connect(sockAddr));
|
||||
|
||||
nexus.AdvanceTime(1 * Time::kOneSecondInMsec);
|
||||
|
||||
Reference in New Issue
Block a user