From 641e84aed4bb349291181240fe3348d2dada85e8 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 6 Apr 2026 23:30:39 -0700 Subject: [PATCH] [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. --- src/core/api/coap_secure_api.cpp | 8 +- src/core/meshcop/border_agent.cpp | 3 +- .../meshcop/border_agent_ephemeral_key.cpp | 3 +- src/core/meshcop/commissioner.cpp | 3 +- src/core/meshcop/joiner.cpp | 4 +- src/core/meshcop/secure_transport.cpp | 79 ++++++++-------- src/core/meshcop/secure_transport.hpp | 93 ++++++++++--------- src/core/radio/ble_secure.cpp | 3 +- tests/nexus/test_border_admitter.cpp | 10 +- tests/nexus/test_border_agent.cpp | 22 ++--- tests/nexus/test_dtls.cpp | 21 ++--- 11 files changed, 123 insertions(+), 126 deletions(-) diff --git a/src/core/api/coap_secure_api.cpp b/src/core/api/coap_secure_api.cpp index 0f0fc6bc3..738a57290 100644 --- a/src/core/api/coap_secure_api.cpp +++ b/src/core/api/coap_secure_api.cpp @@ -41,13 +41,7 @@ using namespace ot; otError otCoapSecureStart(otInstance *aInstance, uint16_t aPort) { - otError error; - - SuccessOrExit(error = AsCoreType(aInstance).Get().Open()); - error = AsCoreType(aInstance).Get().Bind(aPort); - -exit: - return error; + return AsCoreType(aInstance).Get().Open(aPort); } otError otCoapSecureStartWithMaxConnAttempts(otInstance *aInstance, diff --git a/src/core/meshcop/border_agent.cpp b/src/core/meshcop/border_agent.cpp index e0c800323..d07a423a7 100644 --- a/src/core/meshcop/border_agent.cpp +++ b/src/core/meshcop/border_agent.cpp @@ -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().GetPskc(pskc); SuccessOrExit(error = mDtlsTransport.SetPsk(pskc.m8, Pskc::kSize)); diff --git a/src/core/meshcop/border_agent_ephemeral_key.cpp b/src/core/meshcop/border_agent_ephemeral_key.cpp index 9d4995f71..e1565133d 100644 --- a/src/core/meshcop/border_agent_ephemeral_key.cpp +++ b/src/core/meshcop/border_agent_ephemeral_key.cpp @@ -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(aKeyString), static_cast(length))); diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index 687b62ba4..e021a5247 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -265,8 +265,7 @@ Error Commissioner::Start(StateCallback aStateCallback, JoinerCallback aJoinerCa VerifyOrExit(Get().IsAttached(), error = kErrorInvalidState); VerifyOrExit(mState == kStateDisabled, error = kErrorAlready); - SuccessOrExit(error = Get().Open()); - SuccessOrExit(error = Get().Bind(SendRelayTransmit, this)); + SuccessOrExit(error = Get().Open(SendRelayTransmit, this)); Get().SetConnectCallback(HandleSecureAgentConnectEvent, this); diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index 43bf6b39e..20ce3d098 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -126,7 +126,8 @@ Error Joiner::Start(const char *aPskd, VerifyOrExit(mState == kStateIdle, error = kErrorBusy); VerifyOrExit(!Get().IsRunning(), error = kErrorBusy); - SuccessOrExit(error = Get().Open(Ip6::NetifIdentifier::kNetifThreadInternal)); + SuccessOrExit( + error = Get().Open(Get().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().Bind(Get().GetUdpPort())); Get().SetConnectCallback(HandleSecureCoapClientConnect, this); Get().SetPsk(joinerPskd); diff --git a/src/core/meshcop/secure_transport.cpp b/src/core/meshcop/secure_transport.cpp index 268b3746b..d0d90852b 100644 --- a/src/core/meshcop/secure_transport.cpp +++ b/src/core/meshcop/secure_transport.cpp @@ -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(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); diff --git a/src/core/meshcop/secure_transport.hpp b/src/core/meshcop/secure_transport.hpp index fde6f264a..c80f258b2 100644 --- a/src/core/meshcop/secure_transport.hpp +++ b/src/core/meshcop/secure_transport.hpp @@ -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); diff --git a/src/core/radio/ble_secure.cpp b/src/core/radio/ble_secure.cpp index cff1f511a..0116912f9 100644 --- a/src/core/radio/ble_secure.cpp +++ b/src/core/radio/ble_secure.cpp @@ -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; diff --git a/tests/nexus/test_border_admitter.cpp b/tests/nexus/test_border_admitter.cpp index b71db7f2e..45dccfb5f 100644 --- a/tests/nexus/test_border_admitter.cpp +++ b/tests/nexus/test_border_admitter.cpp @@ -449,7 +449,7 @@ void TestBorderAdmitterEnrollerInteraction(void) enroller.Get().RegisterResourceHandler(HandleResource, &recvContext); - SuccessOrQuit(enroller.Get().Open()); + SuccessOrQuit(enroller.Get().Open(0)); SuccessOrQuit(enroller.Get().Connect(sockAddr)); nexus.AdvanceTime(Time::kOneSecondInMsec); @@ -1135,7 +1135,7 @@ void TestBorderAdmitterCommissionerConflictAndPetitionerRetry(void) enroller.Get().RegisterResourceHandler(HandleResource, &recvContext); - SuccessOrQuit(enroller.Get().Open()); + SuccessOrQuit(enroller.Get().Open(0)); SuccessOrQuit(enroller.Get().Connect(sockAddr)); nexus.AdvanceTime(Time::kOneSecondInMsec); @@ -1423,7 +1423,7 @@ void TestBorderAdmitterMultipleEnrollers(void) recvContext[i].Clear(); enroller->Get().RegisterResourceHandler(HandleResource, &recvContext[i]); - SuccessOrQuit(enroller->Get().Open()); + SuccessOrQuit(enroller->Get().Open(0)); SuccessOrQuit(enroller->Get().Connect(sockAddr)); nexus.AdvanceTime(Time::kOneSecondInMsec); @@ -1761,7 +1761,7 @@ void TestBorderAdmitterJoinerEnrollerInteraction(void) recvContext[i].Clear(); enroller->Get().RegisterResourceHandler(HandleResource, &recvContext[i]); - SuccessOrQuit(enroller->Get().Open()); + SuccessOrQuit(enroller->Get().Open(0)); SuccessOrQuit(enroller->Get().Connect(sockAddr)); nexus.AdvanceTime(Time::kOneSecondInMsec); @@ -3259,7 +3259,7 @@ void TestBorderAdmitterForwardingUdpProxy(void) recvContext[i].Clear(); enroller->Get().RegisterResourceHandler(HandleResource, &recvContext[i]); - SuccessOrQuit(enroller->Get().Open()); + SuccessOrQuit(enroller->Get().Open(0)); SuccessOrQuit(enroller->Get().Connect(sockAddr)); nexus.AdvanceTime(Time::kOneSecondInMsec); diff --git a/tests/nexus/test_border_agent.cpp b/tests/nexus/test_border_agent.cpp index 68d91ff36..5aed14dd3 100644 --- a/tests/nexus/test_border_agent.cpp +++ b/tests/nexus/test_border_agent.cpp @@ -113,7 +113,7 @@ void TestBorderAgent(void) node0.Get().GetPskc(pskc); SuccessOrQuit(node1.Get().SetPsk(pskc.m8, Pskc::kSize)); - SuccessOrQuit(node1.Get().Open()); + SuccessOrQuit(node1.Get().Open(0)); SuccessOrQuit(node1.Get().Connect(sockAddr)); nexus.AdvanceTime(1 * Time::kOneSecondInMsec); @@ -145,7 +145,7 @@ void TestBorderAgent(void) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Log("Establish a secure connection again"); - SuccessOrQuit(node1.Get().Open()); + SuccessOrQuit(node1.Get().Open(0)); SuccessOrQuit(node1.Get().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().SetPsk(pskc.m8, Pskc::kSize)); - SuccessOrQuit(node2.Get().Open()); + SuccessOrQuit(node2.Get().Open(0)); SuccessOrQuit(node2.Get().Connect(sockAddr)); SuccessOrQuit(node3.Get().SetPsk(pskc.m8, Pskc::kSize)); - SuccessOrQuit(node3.Get().Open()); + SuccessOrQuit(node3.Get().Open(0)); SuccessOrQuit(node3.Get().Connect(sockAddr)); nexus.AdvanceTime(1 * Time::kOneSecondInMsec); @@ -313,7 +313,7 @@ void TestBorderAgent(void) nexus.AdvanceTime(25 * Time::kOneSecondInMsec); - SuccessOrQuit(node1.Get().Open()); + SuccessOrQuit(node1.Get().Open(0)); SuccessOrQuit(node1.Get().Connect(sockAddr)); nexus.AdvanceTime(1 * Time::kOneSecondInMsec); @@ -481,7 +481,7 @@ void TestBorderAgentEphemeralKey(void) SuccessOrQuit( node1.Get().SetPsk(reinterpret_cast(kEphemeralKey), kEphemeralKeySize)); - SuccessOrQuit(node1.Get().Open()); + SuccessOrQuit(node1.Get().Open(0)); SuccessOrQuit(node1.Get().Connect(sockAddr)); nexus.AdvanceTime(1 * Time::kOneSecondInMsec); @@ -521,7 +521,7 @@ void TestBorderAgentEphemeralKey(void) VerifyOrQuit(node0.Get().GetState() == EphemeralKeyManager::kStateStarted); VerifyOrQuit(node0.Get().GetUdpPort() == kUdpPort); - SuccessOrQuit(node1.Get().Open()); + SuccessOrQuit(node1.Get().Open(0)); SuccessOrQuit(node1.Get().Connect(sockAddr)); nexus.AdvanceTime(2 * Time::kOneSecondInMsec); @@ -619,7 +619,7 @@ void TestBorderAgentEphemeralKey(void) SuccessOrQuit( node1.Get().SetPsk(reinterpret_cast(kEphemeralKey), kEphemeralKeySize)); - SuccessOrQuit(node1.Get().Open()); + SuccessOrQuit(node1.Get().Open(0)); SuccessOrQuit(node1.Get().Connect(sockAddr)); nexus.AdvanceTime(1 * Time::kOneSecondInMsec); @@ -670,7 +670,7 @@ void TestBorderAgentEphemeralKey(void) node0.Get().GetPskc(pskc); SuccessOrQuit(node2.Get().SetPsk(pskc.m8, Pskc::kSize)); - SuccessOrQuit(node2.Get().Open()); + SuccessOrQuit(node2.Get().Open(0)); SuccessOrQuit(node2.Get().Connect(baSockAddr)); nexus.AdvanceTime(1 * Time::kOneSecondInMsec); @@ -690,7 +690,7 @@ void TestBorderAgentEphemeralKey(void) SuccessOrQuit( node1.Get().SetPsk(reinterpret_cast(kEphemeralKey), kEphemeralKeySize)); - SuccessOrQuit(node1.Get().Open()); + SuccessOrQuit(node1.Get().Open(0)); SuccessOrQuit(node1.Get().Connect(sockAddr)); nexus.AdvanceTime(1 * Time::kOneSecondInMsec); @@ -902,7 +902,7 @@ void TestHistoryTrackerBorderAgentEpskcEvent(void) nexus.AdvanceTime(0); - SuccessOrQuit(node1.Get().Open()); + SuccessOrQuit(node1.Get().Open(0)); SuccessOrQuit( node1.Get().SetPsk(reinterpret_cast(kEphemeralKey), kEphemeralKeySize - 2)); diff --git a/tests/nexus/test_dtls.cpp b/tests/nexus/test_dtls.cpp index 2660d2b68..531fcb4ef 100644 --- a/tests/nexus/test_dtls.cpp +++ b/tests/nexus/test_dtls.cpp @@ -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);