Skip to content

Commit

Permalink
docs: advertising
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jun 21, 2019
1 parent 531ac28 commit 047e848
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
32 changes: 32 additions & 0 deletions doc/articles/advertising.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 2 additions & 0 deletions doc/articles/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
items:
- name: Subtypes
href: subtype.md
- name: Advertising
href: advertising.md
- name: Class Reference
href: ../api/Makaretu.Dns.yml
19 changes: 19 additions & 0 deletions test/ServiceDiscoveryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}

}
}

0 comments on commit 047e848

Please sign in to comment.