Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility to get user default values for configurable parameters fo… #33056

Merged
merged 13 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/platform/Darwin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ static_library("Darwin") {
"PosixConfig.h",
"SystemPlatformConfig.h",
"SystemTimeSupport.cpp",
"UserDefaults.h",
"UserDefaults.mm",
]

if (chip_enable_wifi) {
Expand Down
15 changes: 13 additions & 2 deletions src/platform/Darwin/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "DnssdImpl.h"
#include "DnssdType.h"
#include "MdnsError.h"
#include "UserDefaults.h"

#include <cstdio>

Expand All @@ -29,6 +30,7 @@

using namespace chip::Dnssd;
using namespace chip::Dnssd::Internal;
using namespace chip::DeviceLayer;

namespace {

Expand All @@ -37,7 +39,7 @@ constexpr char kLocalDot[] = "local.";
constexpr char kSRPDot[] = "default.service.arpa.";

// The extra time in milliseconds that we will wait for the resolution on the SRP domain to complete.
constexpr uint16_t kSRPTimeoutInMsec = 250;
constexpr uint16_t kSRPTimeoutInMsec = 3000;

constexpr DNSServiceFlags kRegisterFlags = kDNSServiceFlagsNoAutoRename;
constexpr DNSServiceFlags kBrowseFlags = kDNSServiceFlagsShareConnection;
Expand Down Expand Up @@ -76,8 +78,17 @@ void LogOnFailure(const char * name, DNSServiceErrorType err)
*/
CHIP_ERROR StartSRPTimer(uint16_t timeoutInMSecs, ResolveContext * ctx)
{
// Check to see if an user default value exists for the SRP timeout. If it does, override the timeoutInMSecs with user default
nivi-apple marked this conversation as resolved.
Show resolved Hide resolved
// value. To override the timeout value, use ` defaults write org.csa-iot.matter.darwin SRPTimeoutInMSecsOverride
// <timeoutinMsecs>` See UserDefaults.mm for details
nivi-apple marked this conversation as resolved.
Show resolved Hide resolved
uint16_t userDefaultSRPTimeoutInMsecs = static_cast<uint16_t>(getUserDefaultDnssdSRPTimeoutInMSecs());
nivi-apple marked this conversation as resolved.
Show resolved Hide resolved
if (userDefaultSRPTimeoutInMsecs)
{
timeoutInMSecs = userDefaultSRPTimeoutInMsecs;
}
VerifyOrReturnValue(ctx != nullptr, CHIP_ERROR_INCORRECT_STATE);
ChipLogProgress(Discovery, "Starting timer to wait for possible SRP resolve results for %s", ctx->instanceName.c_str());
ChipLogProgress(Discovery, "Starting timer to wait for %d milliseconds for possible SRP resolve results for %s", timeoutInMSecs,
ctx->instanceName.c_str());
return chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds16(timeoutInMSecs),
ResolveContext::SRPTimerExpiredCallback, static_cast<void *>(ctx));
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Darwin/DnssdImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ struct ResolveContext : public GenericContext
std::shared_ptr<uint32_t> consumerCounter;
BrowseContext * const browseThatCausedResolve; // Can be null

// Indicates whether the timer for 250 msecs should be started
// to give the resolve on SRP domain some extra time to complete.
// Indicates whether the timer should be started to give the resolve
// on SRP domain some extra time to complete.
bool shouldStartSRPTimerForResolve = false;
bool isSRPTimerRunning = false;

Expand Down
26 changes: 26 additions & 0 deletions src/platform/Darwin/UserDefaults.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
*
nivi-apple marked this conversation as resolved.
Show resolved Hide resolved
* Copyright (c) 2024 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

namespace chip {
namespace DeviceLayer {
woody-apple marked this conversation as resolved.
Show resolved Hide resolved

uint16_t getUserDefaultDnssdSRPTimeoutInMSecs();
nivi-apple marked this conversation as resolved.
Show resolved Hide resolved
woody-apple marked this conversation as resolved.
Show resolved Hide resolved

} // namespace DeviceLayer
} // namespace chip
34 changes: 34 additions & 0 deletions src/platform/Darwin/UserDefaults.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

static NSString * const kUserDefaultDomain = @"org.csa-iot.matter.darwin";
static NSString * const kSRPTimeoutInMsecsUserDefaultKey = @"SRPTimeoutInMSecsOverride";

namespace chip {
namespace DeviceLayer {

uint16_t getUserDefaultDnssdSRPTimeoutInMSecs()
{
NSUserDefaults * defaults = [[NSUserDefaults alloc] initWithSuiteName:kUserDefaultDomain];
NSInteger srpTimeoutValue = [defaults integerForKey:kSRPTimeoutInMsecsUserDefaultKey];
return (srpTimeoutValue > 0 && srpTimeoutValue < UINT16_MAX) ? static_cast<uint16_t>(srpTimeoutValue) : 0;
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
}

} // namespace DeviceLayer
} // namespace chip
Loading