From c8c26b7ac03d99481ebcc183319f8e6ea80d6fbb Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Thu, 7 Nov 2019 04:51:47 -0800 Subject: [PATCH] [operational-dataset] only generate active dataset once (#4304) Add check to see if Active Timestamp already exists in the Active Operational Dataset. If Active Timestamp exists, do not generate Active Operational Dataset again. --- src/core/meshcop/dataset_local.hpp | 9 +++++++++ src/core/meshcop/dataset_manager.hpp | 3 ++- src/core/meshcop/dataset_manager_ftd.cpp | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/meshcop/dataset_local.hpp b/src/core/meshcop/dataset_local.hpp index cdffe9703..efc87cf69 100644 --- a/src/core/meshcop/dataset_local.hpp +++ b/src/core/meshcop/dataset_local.hpp @@ -80,6 +80,15 @@ public: */ bool IsSaved(void) const { return mSaved; } + /** + * This method indicates whether an Active (Pending) Timestamp is present in the Active (Pending) Dataset. + * + * @retval TRUE if an Active/Pending Timestamp is present. + * @retval FALSE if an Active/Pending Timestamp is not present. + * + */ + bool IsTimestampPresent(void) const { return mTimestampPresent; } + /** * This method restores and retrieves the dataset from non-volatile memory. * diff --git a/src/core/meshcop/dataset_manager.hpp b/src/core/meshcop/dataset_manager.hpp index a991b74fe..cc0967a96 100644 --- a/src/core/meshcop/dataset_manager.hpp +++ b/src/core/meshcop/dataset_manager.hpp @@ -391,7 +391,8 @@ public: /** * This method generate a default Active Operational Dataset. * - * @retval OT_ERROR_NONE Successfully generated an Active Operational Dataset. + * @retval OT_ERROR_NONE Successfully generated an Active Operational Dataset. + * @retval OT_ERROR_ALREADY A valid Active Operational Dataset already exists. * @retval OT_ERROR_INVALID_STATE Device is not currently attached to a network. * */ diff --git a/src/core/meshcop/dataset_manager_ftd.cpp b/src/core/meshcop/dataset_manager_ftd.cpp index 8dc2bb6c4..e4f5d7b3f 100644 --- a/src/core/meshcop/dataset_manager_ftd.cpp +++ b/src/core/meshcop/dataset_manager_ftd.cpp @@ -370,6 +370,7 @@ otError ActiveDataset::GenerateLocal(void) Dataset dataset(mLocal.GetType()); VerifyOrExit(Get().IsAttached(), error = OT_ERROR_INVALID_STATE); + VerifyOrExit(!mLocal.IsTimestampPresent(), error = OT_ERROR_ALREADY); mLocal.Read(dataset);