Skip to content

Commit

Permalink
Stop storing the extended discovery timeout in NVM. (project-chip#17270)
Browse files Browse the repository at this point in the history
It's set at startup by all the examples that care to set it.  There's
no obvious reason this value should be in persistent storage.
  • Loading branch information
bzbarsky-apple authored and andrei-menzopol committed Apr 14, 2022
1 parent 67880ec commit b4877ee
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
19 changes: 2 additions & 17 deletions src/app/server/Dnssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <platform/CHIPDeviceLayer.h>
#include <platform/CommissionableDataProvider.h>
#include <platform/ConfigurationManager.h>
#include <platform/KeyValueStoreManager.h>
#include <protocols/secure_channel/PASESession.h>
#if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID)
#include <setup_payload/AdditionalDataPayloadGenerator.h>
Expand Down Expand Up @@ -87,26 +86,12 @@ bool DnssdServer::HaveOperationalCredentials()
void DnssdServer::SetExtendedDiscoveryTimeoutSecs(int32_t secs)
{
ChipLogDetail(Discovery, "Setting extended discovery timeout to %" PRId32 "s", secs);
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgr().Put(DefaultStorageKeyAllocator::DNSExtendedDiscoveryTimeout(), secs);
mExtendedDiscoveryTimeoutSecs = MakeOptional(secs);
}

int32_t DnssdServer::GetExtendedDiscoveryTimeoutSecs()
{
int32_t secs;
CHIP_ERROR err = chip::DeviceLayer::PersistedStorage::KeyValueStoreMgr().Get(
DefaultStorageKeyAllocator::DNSExtendedDiscoveryTimeout(), &secs);

if (err == CHIP_NO_ERROR)
{
return secs;
}

if (err != CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
{
ChipLogError(Discovery, "Failed to load extended discovery timeout: %" CHIP_ERROR_FORMAT, err.Format());
}

return CHIP_DEVICE_CONFIG_EXTENDED_DISCOVERY_TIMEOUT_SECS;
return mExtendedDiscoveryTimeoutSecs.ValueOr(CHIP_DEVICE_CONFIG_EXTENDED_DISCOVERY_TIMEOUT_SECS);
}

/// Callback from Extended Discovery Expiration timer
Expand Down
5 changes: 4 additions & 1 deletion src/app/server/Dnssd.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,14 @@ class DLL_EXPORT DnssdServer
int16_t mDiscoveryTimeoutSecs = CHIP_DEVICE_CONFIG_DISCOVERY_TIMEOUT_SECS;
System::Clock::Timestamp mDiscoveryExpiration = kTimeoutCleared;

Optional<int32_t> mExtendedDiscoveryTimeoutSecs = NullOptional;

/// return true if expirationMs is valid (not cleared and not in the future)
bool OnExpiration(System::Clock::Timestamp expiration);

#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
/// get the current extended discovery timeout (from persistent storage)
/// Get the current extended discovery timeout (set by
/// SetExtendedDiscoveryTimeoutSecs, or the configuration default if not set).
int32_t GetExtendedDiscoveryTimeoutSecs();

/// schedule next extended discovery expiration
Expand Down
3 changes: 0 additions & 3 deletions src/lib/support/DefaultStorageKeyAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ class DefaultStorageKeyAllocator
static const char * OTACurrentUpdateState() { return "g/o/us"; }
static const char * OTATargetVersion() { return "g/o/tv"; }

// [G]lobal [D]NS-related keys
static const char * DNSExtendedDiscoveryTimeout() { return "g/d/edt"; }

private:
// The ENFORCE_FORMAT args are "off by one" because this is a class method,
// with an implicit "this" as first arg.
Expand Down

0 comments on commit b4877ee

Please sign in to comment.