From 26c5d0ecb8fe198d379326a34d8489cb5eb2bcd1 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Wed, 23 Jan 2019 08:11:07 +0800 Subject: [PATCH] [border-agent] reuse Dtls restart (#3489) `MeshCoP::Dtls` session will restart listening by itself. It's not necessary for border agent to restart `MeshCoP::Dtls`. --- src/core/meshcop/border_agent.cpp | 45 +++++++------------------------ src/core/meshcop/border_agent.hpp | 3 +-- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/src/core/meshcop/border_agent.cpp b/src/core/meshcop/border_agent.cpp index 367664e63..817fa2ed6 100644 --- a/src/core/meshcop/border_agent.cpp +++ b/src/core/meshcop/border_agent.cpp @@ -641,32 +641,12 @@ void BorderAgent::HandleConnected(bool aConnected) } else { - ThreadNetif & netif = GetNetif(); - Coap::CoapSecure &coaps = netif.GetCoapSecure(); - otLogInfoMeshCoP("Commissioner disconnected"); - netif.GetIp6().GetUdp().RemoveReceiver(mUdpReceiver); - netif.RemoveUnicastAddress(mCommissionerAloc); - coaps.Stop(); + GetNetif().RemoveUnicastAddress(mCommissionerAloc); SetState(OT_BORDER_AGENT_STATE_STARTED); - mTimer.Start(kRestartDelay); } } -otError BorderAgent::StartCoaps(void) -{ - ThreadNetif & netif = GetNetif(); - Coap::CoapSecure &coaps = netif.GetCoapSecure(); - otError error; - - SuccessOrExit(error = coaps.Start(kBorderAgentUdpPort)); - SuccessOrExit(error = coaps.SetPsk(netif.GetKeyManager().GetPSKc(), OT_PSKC_MAX_SIZE)); - coaps.SetConnectedCallback(HandleConnected, this); - -exit: - return error; -} - otError BorderAgent::Start(void) { otError error; @@ -676,7 +656,9 @@ otError BorderAgent::Start(void) VerifyOrExit(mState == OT_BORDER_AGENT_STATE_STOPPED, error = OT_ERROR_ALREADY); - SuccessOrExit(error = StartCoaps()); + SuccessOrExit(error = coaps.Start(kBorderAgentUdpPort)); + SuccessOrExit(error = coaps.SetPsk(netif.GetKeyManager().GetPSKc(), OT_PSKC_MAX_SIZE)); + coaps.SetConnectedCallback(HandleConnected, this); coaps.AddResource(mActiveGet); coaps.AddResource(mActiveSet); @@ -706,24 +688,15 @@ void BorderAgent::HandleTimeout(void) { ThreadNetif & netif = GetNetif(); Coap::CoapSecure &coaps = netif.GetCoapSecure(); - otError error; if (coaps.IsConnected()) { - error = coaps.Stop(); - otLogWarnMeshCoP("Reset commissioner session: %s", otThreadErrorToString(error)); - } - else if (!coaps.IsConnectionActive()) - { - error = StartCoaps(); - otLogWarnMeshCoP("Restart border agent secure CoAP service: %s", otThreadErrorToString(error)); - } - else - { - assert(false); - } + otError error; - OT_UNUSED_VARIABLE(error); + error = coaps.Disconnect(); + otLogWarnMeshCoP("Reset commissioner session: %s", otThreadErrorToString(error)); + OT_UNUSED_VARIABLE(error); + } } otError BorderAgent::Stop(void) diff --git a/src/core/meshcop/border_agent.hpp b/src/core/meshcop/border_agent.hpp index 5ed81c23e..3af0855a7 100644 --- a/src/core/meshcop/border_agent.hpp +++ b/src/core/meshcop/border_agent.hpp @@ -88,8 +88,7 @@ private: { static_cast(aContext)->HandleConnected(aConnected); } - void HandleConnected(bool aConnected); - otError StartCoaps(void); + void HandleConnected(bool aConnected); template static void HandleRequest(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)