diff --git a/doc/articles/advertising.md b/doc/articles/advertising.md new file mode 100644 index 0000000..56aedb4 --- /dev/null +++ b/doc/articles/advertising.md @@ -0,0 +1,32 @@ +# Advertising + +[ServiceDiscovery.Advertise](xref:Makaretu.Dns.ServiceDiscovery.Advertise*) +is used to generate all the DNS [resource records](xref:Makaretu.Dns.ResourceRecord) needed to +answer a Multicast DNS or DNS-SD query for a [service profile](xref:Makaretu.Dns.ServiceProfile). + +### Usage +```csharp +var profile = new ServiceProfile("me", "_myservice._udp", 1234, + new IPAddress[] { IPAddress.Loopback }); +profile.Subtypes.Add("apiv2"); +profile.AddProperty("someprop", "somevalue"); + +var sd = new ServiceDiscovery(); +sd.Advertise(profile); +``` + +### Resource records + +The following resource records are generated from the above profile. + +``` +_services._dns-sd._udp.local PTR _myservice._udp.local +_myservice._udp.local PTR me._myservice._udp.local +apiv2._sub._myservice._udp.local PTR me._myservice._udp.local + +me._myservice._udp.local SRV 0 0 1234 me.myservice.local +me._myservice._udp.local TXT txtvers=1 someprop=somevalue +me.myservice.local A 127.0.0.1 + +1.0.0.127.in-addr.arpa PTR me.myservice.local +``` diff --git a/doc/articles/toc.yml b/doc/articles/toc.yml index cfa5a07..410555e 100644 --- a/doc/articles/toc.yml +++ b/doc/articles/toc.yml @@ -7,5 +7,7 @@ items: - name: Subtypes href: subtype.md + - name: Advertising + href: advertising.md - name: Class Reference href: ../api/Makaretu.Dns.yml diff --git a/test/ServiceDiscoveryTest.cs b/test/ServiceDiscoveryTest.cs index 8437bb5..21287ae 100644 --- a/test/ServiceDiscoveryTest.cs +++ b/test/ServiceDiscoveryTest.cs @@ -435,5 +435,24 @@ public void ReverseAddressMapping() } } + [TestMethod] + public void ResourceRecords() + { + var profile = new ServiceProfile("me", "_myservice._udp", 1234, new IPAddress[] { IPAddress.Loopback }); + profile.Subtypes.Add("apiv2"); + profile.AddProperty("someprop", "somevalue"); + + using (var sd = new ServiceDiscovery()) + { + sd.Advertise(profile); + + var resourceRecords = sd.NameServer.Catalog.Values.SelectMany(node => node.Resources); + foreach (var r in resourceRecords) + { + Console.WriteLine(r.ToString()); + } + } + } + } }