Skip to content

Commit

Permalink
[mdns-msdnssd] simplify service and host registrations
Browse files Browse the repository at this point in the history
This commit updates and enhances the `Mdns::PublisherMDnsSd` class,
which implements the `Mdns::Publisher` interface using MDNSResponder
as its underlying DNS-SD provider.

The following changes are made related to service registration:

- Registration simplified: The `PublishServiceImpl()` method is
  updated to allocate a `DnssdServiceRegistration` object first and
  add it to the list of registrations before asking it to `Register
  ()` itself. This simplifies the code path for invoking the
  `ResultCallback` on success or failure (one path to handle all
  cases) and also makes it clear that the `DNSServiceRef` object is
  owned and managed by the `DnssdServiceRegistration` instance.

- The `HandleRegisterResult` callback passed to the MDNSResponder
  `DNSServiceRegister()` function is now defined and handled by the
  `DnssdServiceRegistration` class instead of by the
  `PublisherMDnsSd` class. This simplifies the code, as we no longer
  need to iterate through the full list of `Registration` objects to
  find the one corresponding to a related `mServiceRef`. It also fits
  well with the notion of the `mServiceRef` being owned by a
  corresponding `DnssdServiceRegistration` object (the destructor
  will call the `DNSServiceRefDeallocate()` function to deallocate
  the `mServiceRef`, which will stop the MDNSResponder from invoking
  the callback).

This commit also makes similar changes to the `PublishHostImpl()` and
`DnssdHostRegistration methods, but there are some additional changes
specific to host registration:

- The `DnssdHostRegistration` class now tracks whether each host IPv6
  address is registered or not.

- The `DnssdHostRegistration` destructor is also changed so that it
  will always remove all outstanding `DNSRecordRef` objects for all
  host IPv6 addresses. This updates and fixes the existing behavior
  where the records were removed only if `IsCompleted()` returned
  true, which requires all addresses to be registered, and could lead
  to some of the address records not being removed if the host
  registration was replaced or deleted quickly after its
  registration.
  • Loading branch information
abtink committed Sep 10, 2023
1 parent 8a280e3 commit 7cd3bb8
Show file tree
Hide file tree
Showing 2 changed files with 247 additions and 286 deletions.
Loading

0 comments on commit 7cd3bb8

Please sign in to comment.