Skip to content

Commit

Permalink
Revert "project-chip#13227 debug"
Browse files Browse the repository at this point in the history
This reverts commit 1b98d6f.
  • Loading branch information
msandstedt committed Dec 30, 2021
1 parent 1b98d6f commit 11cce71
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/commissioner/Discoverer.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ struct CommissionableIpNodeDiscoverer : chip::Controller::AbstractDnssdDiscovery
{
// TODO: We have to retain the proxy. Due to #13227, mDNS can keep
// referencing this.
//mDNSResolver.GetDelegateProxy()->Retain();
mDNSResolver.GetDelegateProxy()->Retain();
mDNSResolver.Shutdown();
}

Expand Down
2 changes: 1 addition & 1 deletion src/commissioner/States.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ struct OperationalDiscovery : Base<TContext>, chip::Dnssd::ResolverDelegate
{
// TODO: We have to retain the proxy. Due to #13227, mDNS can keep
// referencing this.
//mDnsResolver.GetDelegateProxy()->Retain();
mDnsResolver.GetDelegateProxy()->Retain();
mDnsResolver.Shutdown();
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/core/ReferenceCounted.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ReferenceCounted
/** Get the current reference counter value */
count_type GetReferenceCount() const { return mRefCount; }

protected:
private:
count_type mRefCount = kInitRefCount;
};

Expand Down
26 changes: 2 additions & 24 deletions src/lib/dnssd/Discovery_ImplPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ static void HandleNodeResolve(void * context, DnssdService * result, CHIP_ERROR
{
ResolverDelegateProxy * proxy = static_cast<ResolverDelegateProxy *>(context);

ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
if (CHIP_NO_ERROR != error)
{
proxy->Release();
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
return;
}

Expand All @@ -74,41 +72,31 @@ ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, prox
FillNodeDataFromTxt(key, val, nodeData);
}

ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
proxy->OnNodeDiscoveryComplete(nodeData);
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
proxy->Release();
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
}

static void HandleNodeIdResolve(void * context, DnssdService * result, CHIP_ERROR error)
{
ResolverDelegateProxy * proxy = static_cast<ResolverDelegateProxy *>(context);
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
if (CHIP_NO_ERROR != error)
{
proxy->OnNodeIdResolutionFailed(PeerId(), error);
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
proxy->Release();
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
}

if (result == nullptr)
{
proxy->OnNodeIdResolutionFailed(PeerId(), CHIP_ERROR_UNKNOWN_RESOURCE_ID);
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
proxy->Release();
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
}

PeerId peerId;
error = ExtractIdFromInstanceName(result->mName, &peerId);
if (CHIP_NO_ERROR != error)
{
proxy->OnNodeIdResolutionFailed(PeerId(), error);
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
proxy->Release();
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
}

ResolvedNodeData nodeData;
Expand All @@ -134,36 +122,28 @@ ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, prox
#if CHIP_CONFIG_MDNS_CACHE_SIZE > 0
LogErrorOnFailure(sDnssdCache.Insert(nodeData));
#endif
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
proxy->OnNodeIdResolved(nodeData);
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
proxy->Release();
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
}

static void HandleNodeBrowse(void * context, DnssdService * services, size_t servicesSize, CHIP_ERROR error)
{
ResolverDelegateProxy * proxy = static_cast<ResolverDelegateProxy *>(context);
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
proxy->Release();

for (size_t i = 0; i < servicesSize; ++i)
{
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
proxy->Retain();
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
// For some platforms browsed services are already resolved, so verify if resolve is really needed or call resolve callback
if (!services[i].mAddress.HasValue())
{
ChipDnssdResolve(&services[i], services[i].mInterface, HandleNodeResolve, context);
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
}
else
{
HandleNodeResolve(context, &services[i], error);
ChipLogError(Controller, "%s %s %d proxy=%p", __FILE__, __func__, __LINE__, proxy);
}
}
proxy->Release();
}

CHIP_ERROR AddPtrRecord(DiscoveryFilter filter, const char ** entries, size_t & entriesCount, char * buffer, size_t bufferLen)
Expand Down Expand Up @@ -624,9 +604,7 @@ CHIP_ERROR ResolverProxy::ResolveNodeId(const PeerId & peerId, Inet::IPAddressTy
CHIP_ERROR ResolverProxy::FindCommissionableNodes(DiscoveryFilter filter)
{
VerifyOrReturnError(mDelegate != nullptr, CHIP_ERROR_INCORRECT_STATE);
ChipLogError(Controller, "%s %s %d mDelegate=%p", __FILE__, __func__, __LINE__, mDelegate);
mDelegate->Retain();
ChipLogError(Controller, "%s %s %d mDelegate=%p", __FILE__, __func__, __LINE__, mDelegate);

char serviceName[kMaxCommissionableServiceNameSize];
ReturnErrorOnFailure(MakeServiceTypeName(serviceName, sizeof(serviceName), filter, DiscoveryType::kCommissionableNode));
Expand Down
12 changes: 0 additions & 12 deletions src/lib/dnssd/ResolverProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ class ResolverDelegateProxy : public ReferenceCounted<ResolverDelegateProxy>, pu
public:
void SetDelegate(ResolverDelegate * delegate) { mDelegate = delegate; }

void Retain()
{
ChipLogError(Controller, "%s %s %d count=%u this=%p", __FILE__, __func__, __LINE__, this->mRefCount, this);
ReferenceCounted<ResolverDelegateProxy>::Retain();
ChipLogError(Controller, "%s %s %d count=%u this=%p", __FILE__, __func__, __LINE__, this->mRefCount, this);
}
void Release()
{
ChipLogError(Controller, "%s %s %d count=%u this=%p", __FILE__, __func__, __LINE__, this->mRefCount, this);
ReferenceCounted<ResolverDelegateProxy>::Release();
ChipLogError(Controller, "%s %s %d count=%u this=%p", __FILE__, __func__, __LINE__, this->mRefCount, this);
}
/// ResolverDelegate interface
void OnNodeIdResolved(const ResolvedNodeData & nodeData) override
{
Expand Down
20 changes: 2 additions & 18 deletions src/platform/Darwin/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,18 @@ CHIP_ERROR MdnsContexts::Remove(GenericContext * context)
std::vector<GenericContext *>::const_iterator iter = mContexts.cbegin();
while (iter != mContexts.cend())
{
ChipLogError(Controller, "%s %s %d", __FILE__, __func__, __LINE__);
if (*iter != context)
{
iter++;
continue;
}
ChipLogError(Controller, "%s %s %d", __FILE__, __func__, __LINE__);

Delete(*iter);
mContexts.erase(iter);
found = true;
break;
}

ChipLogError(Controller, "%s %s %d", __FILE__, __func__, __LINE__);
return found ? CHIP_NO_ERROR : CHIP_ERROR_KEY_NOT_FOUND;
}

Expand Down Expand Up @@ -243,30 +240,25 @@ bool CheckForSuccess(GenericContext * context, const char * name, DNSServiceErro
// Nothing special to do. Maybe ChipDnssdPublishService should take a callback ?
break;
case ContextType::Browse: {
ChipLogError(Controller, "%s %s %d", __FILE__, __func__, __LINE__);
BrowseContext * browseContext = reinterpret_cast<BrowseContext *>(context);
browseContext->callback(browseContext->context, nullptr, 0, CHIP_ERROR_INTERNAL);
break;
}
case ContextType::Resolve: {
ChipLogError(Controller, "%s %s %d", __FILE__, __func__, __LINE__);
ResolveContext * resolveContext = reinterpret_cast<ResolveContext *>(context);
resolveContext->callback(resolveContext->context, nullptr, CHIP_ERROR_INTERNAL);
break;
}
case ContextType::GetAddrInfo: {
ChipLogError(Controller, "%s %s %d", __FILE__, __func__, __LINE__);
GetAddrInfoContext * resolveContext = reinterpret_cast<GetAddrInfoContext *>(context);
resolveContext->callback(resolveContext->context, nullptr, CHIP_ERROR_INTERNAL);
break;
}
}
}

ChipLogError(Controller, "%s %s %d", __FILE__, __func__, __LINE__);
if (CHIP_ERROR_KEY_NOT_FOUND == MdnsContexts::GetInstance().Remove(context))
{
ChipLogError(Controller, "%s %s %d", __FILE__, __func__, __LINE__);
chip::Platform::Delete(context);
}

Expand Down Expand Up @@ -379,7 +371,7 @@ CHIP_ERROR Browse(void * context, DnssdBrowseCallback callback, uint32_t interfa
DNSServiceErrorType err;
DNSServiceRef sdRef;
BrowseContext * sdCtx;
ChipLogError(Controller, "%s %s %d context=%p", __FILE__, __func__, __LINE__, context);

std::string regtype(type);
std::string subtypeDelimiter = "._sub.";
size_t position = regtype.find(subtypeDelimiter);
Expand All @@ -389,13 +381,9 @@ ChipLogError(Controller, "%s %s %d context=%p", __FILE__, __func__, __LINE__, co
}

sdCtx = chip::Platform::New<BrowseContext>(context, callback, protocol);
ChipLogError(Controller, "%s %s %d context=%p", __FILE__, __func__, __LINE__, context);
err = DNSServiceBrowse(&sdRef, 0 /* flags */, interfaceId, regtype.c_str(), kLocalDot, OnBrowse, sdCtx);
ChipLogError(Controller, "%s %s %d context=%p", __FILE__, __func__, __LINE__, context);
VerifyOrReturnError(CheckForSuccess(sdCtx, __func__, err), CHIP_ERROR_INTERNAL);
ChipLogError(Controller, "%s %s %d context=%p", __FILE__, __func__, __LINE__, context);

ChipLogError(Controller, "%s %s %d context=%p", __FILE__, __func__, __LINE__, context);
err = DNSServiceSetDispatchQueue(sdRef, chip::DeviceLayer::PlatformMgrImpl().GetWorkQueue());
VerifyOrReturnError(CheckForSuccess(sdCtx, __func__, err, true), CHIP_ERROR_INTERNAL);

Expand All @@ -421,9 +409,7 @@ static void OnGetAddrInfo(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t i
Platform::CopyString(service.mHostName, hostname);
service.mInterface = Inet::InterfaceId(sdCtx->interfaceId);

ChipLogError(Controller, "%s %s %d", __FILE__, __func__, __LINE__);
sdCtx->callback(sdCtx->context, &service, status);
ChipLogError(Controller, "%s %s %d", __FILE__, __func__, __LINE__);
MdnsContexts::GetInstance().Remove(sdCtx);
}

Expand Down Expand Up @@ -514,15 +500,13 @@ static void OnResolve(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t inter
const char * fullname, const char * hostname, uint16_t port, uint16_t txtLen, const unsigned char * txtRecord,
void * context)
{
ChipLogError(Controller, "%s %s %d", __FILE__, __func__, __LINE__);
ChipLogDetail(DeviceLayer, "Resolved interface id: %u", interfaceId);

ResolveContext * sdCtx = reinterpret_cast<ResolveContext *>(context);
VerifyOrReturn(CheckForSuccess(sdCtx, __func__, err, true));

GetAddrInfo(sdCtx->context, sdCtx->callback, interfaceId, sdCtx->addressType, sdCtx->name, hostname, ntohs(port), txtLen,
txtRecord);
ChipLogError(Controller, "%s %s %d", __FILE__, __func__, __LINE__);
MdnsContexts::GetInstance().Remove(sdCtx);
}

Expand Down Expand Up @@ -603,7 +587,7 @@ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chi

std::string regtype = GetFullType(type, protocol);
uint32_t interfaceId = GetInterfaceId(interface);
ChipLogError(Controller, "%s %s %d context=%p", __FILE__, __func__, __LINE__, context);

return Browse(context, callback, interfaceId, regtype.c_str(), protocol);
}

Expand Down

0 comments on commit 11cce71

Please sign in to comment.