Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 24 additions & 3 deletions src/trel_dnssd/trel_dnssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ void TrelDnssd::OnTrelServiceInstanceAdded(const Mdns::Publisher::DiscoveredInst
Ip6Address selectedAddress;
otPlatTrelPeerInfo peerInfo;

// Remove any existing TREL service instance before adding
OnTrelServiceInstanceRemoved(instanceName);
memset(&peerInfo, 0, sizeof(peerInfo));
Comment thread
jwhui marked this conversation as resolved.

otbrLogDebug("Peer discovered: %s hostname %s addresses %zu port %d priority %d "
"weight %d",
Expand Down Expand Up @@ -331,6 +330,25 @@ void TrelDnssd::OnTrelServiceInstanceAdded(const Mdns::Publisher::DiscoveredInst

VerifyOrExit(peer.mValid, otbrLogWarning("Peer %s is invalid", aInstanceInfo.mName.c_str()));

auto it = mPeers.find(instanceName);
if (it != mPeers.end())
{
if (it->second.Matches(peer))
{
it->second.mDiscoverTime = Clock::now();
ExitNow();
}

if (memcmp(&it->second.mExtAddr, &peer.mExtAddr, sizeof(otExtAddress)) != 0)
{
OnTrelServiceInstanceRemoved(instanceName);
}
else
{
mPeers.erase(it);
}
}
Comment thread
jwhui marked this conversation as resolved.

otPlatTrelHandleDiscoveredPeerInfo(mHost.GetInstance(), &peerInfo);

mPeers.emplace(instanceName, peer);
Expand Down Expand Up @@ -387,6 +405,8 @@ void TrelDnssd::NotifyRemovePeer(const Peer &aPeer)
{
otPlatTrelPeerInfo peerInfo;

memset(&peerInfo, 0, sizeof(peerInfo));
Comment thread
jwhui marked this conversation as resolved.

peerInfo.mRemoved = true;
peerInfo.mTxtData = aPeer.mTxtData.data();
peerInfo.mTxtLength = aPeer.mTxtData.size();
Expand Down Expand Up @@ -466,7 +486,8 @@ uint16_t TrelDnssd::CountDuplicatePeers(const TrelDnssd::Peer &aPeer)
continue;
}

if (!memcmp(&entry.second.mSockAddr, &aPeer.mSockAddr, sizeof(otSockAddr)) &&
if ((entry.second.mSockAddr.mPort == aPeer.mSockAddr.mPort) &&
!memcmp(&entry.second.mSockAddr.mAddress, &aPeer.mSockAddr.mAddress, sizeof(otIp6Address)) &&
!memcmp(&entry.second.mExtAddr, &aPeer.mExtAddr, sizeof(otExtAddress)))
{
count++;
Expand Down
8 changes: 8 additions & 0 deletions src/trel_dnssd/trel_dnssd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#if OTBR_ENABLE_TREL_DNSSD

#include <assert.h>
#include <string.h>
Comment thread
jwhui marked this conversation as resolved.
#include <utility>

#include <openthread/instance.h>
Expand Down Expand Up @@ -141,6 +142,13 @@ class TrelDnssd : public Mdns::StateObserver

void ReadExtAddrFromTxtData(void);

bool Matches(const Peer &aOther) const
{
return (mSockAddr.mPort == aOther.mSockAddr.mPort) &&
(memcmp(&mSockAddr.mAddress, &aOther.mSockAddr.mAddress, sizeof(otIp6Address)) == 0) &&
(mTxtData == aOther.mTxtData);
}
Comment thread
jwhui marked this conversation as resolved.

Clock::time_point mDiscoverTime;
std::vector<uint8_t> mTxtData;
otSockAddr mSockAddr;
Expand Down
Loading