Skip to content

Commit

Permalink
Update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 committed Dec 16, 2024
1 parent d753ee8 commit b087373
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib/address_resolve/AddressResolve_DefaultImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ bool NodeLookupResults::UpdateResults(const ResolveResult & result, const Dnssd:
return false;
}

// we can insert IF AND ONLY IF we are not duplicating an existing entry
// TODO: implement
// we are guaranteed no duplicates here:
// - insertAtIndex MUST be with some score that is `< newScore`, so all
// addresses with a `newScore` were duplicate-checked

// Move the following valid entries one level down.
for (auto i = count; i > insertAtIndex; i--)
Expand Down
37 changes: 37 additions & 0 deletions src/lib/address_resolve/tests/TestAddressResolve_DefaultImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,43 @@ Transport::PeerAddress GetAddressWithHighScore(uint16_t port = CHIP_PORT, Inet::
return Transport::PeerAddress::UDP(ipAddress, port, interfaceId);
}

TEST(TestAddressResolveDefaultImpl, UpdateResultsDoesNotAddDuplicatesWhenFull) {
Impl::NodeLookupResults results;
ASSERT_EQ(results.count, 0);

for (auto i = 0; i < kNumberOfAvailableSlots; i++)
{
ResolveResult result;
result.address = GetAddressWithLowScore(i + 10);
ASSERT_TRUE(results.UpdateResults(result, Dnssd::IPAddressSorter::IpScore::kUniqueLocal));
}
ASSERT_EQ(results.count, kNumberOfAvailableSlots);

// Adding another one should fail as there is no more room
ResolveResult result;
result.address = GetAddressWithLowScore(5);
ASSERT_FALSE(results.UpdateResults(result, Dnssd::IPAddressSorter::IpScore::kUniqueLocal));
ASSERT_EQ(results.count, kNumberOfAvailableSlots);

// however one with higher priority should work
result.address = GetAddressWithHighScore();
ASSERT_TRUE(results.UpdateResults(result, Dnssd::IPAddressSorter::IpScore::kGlobalUnicast));
ASSERT_EQ(results.count, kNumberOfAvailableSlots);

// however not duplicate
ASSERT_FALSE(results.UpdateResults(result, Dnssd::IPAddressSorter::IpScore::kGlobalUnicast));
ASSERT_EQ(results.count, kNumberOfAvailableSlots);

// another higher priority one
result.address = GetAddressWithMediumScore();
ASSERT_TRUE(results.UpdateResults(result, Dnssd::IPAddressSorter::IpScore::kLinkLocal));
ASSERT_EQ(results.count, kNumberOfAvailableSlots);

// however not duplicate
ASSERT_FALSE(results.UpdateResults(result, Dnssd::IPAddressSorter::IpScore::kLinkLocal));
ASSERT_EQ(results.count, kNumberOfAvailableSlots);
}

TEST(TestAddressResolveDefaultImpl, UpdateResultsDoesNotAddDuplicates)
{
static_assert(Impl::kNodeLookupResultsLen >= 3, "Test uses 3 address slots");
Expand Down

0 comments on commit b087373

Please sign in to comment.