aboutsummaryrefslogtreecommitdiff
path: root/osp/go/mdns.go
diff options
context:
space:
mode:
Diffstat (limited to 'osp/go/mdns.go')
-rw-r--r--osp/go/mdns.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/osp/go/mdns.go b/osp/go/mdns.go
index 591ef6e7..7bda7ec6 100644
--- a/osp/go/mdns.go
+++ b/osp/go/mdns.go
@@ -4,9 +4,9 @@
package osp
-// TODO(pthatcher):
+// TODO(jophba):
// - Make our own abstraction that has
-// .InstanceName, .HostName, .MetadataVersion, .FingerPrint
+// .InstanceName, .HostName, .MetadataVersion, .FingerPrint
// rather than using mdns.ServiceEntry
// - Advertise TXT (text below) with "fp" and "mv"
@@ -21,8 +21,9 @@ const (
MdnsDomain = "local"
)
-// Returns a channel of mDNS entries
-// The critical parts are entry.Target (name) entry.HostName (address)
+// Returns a channel of mDNS entries. The critical parts are
+// entry.Target (service name) entry.HostName, entry.AddrIPv4, and
+// entry.AddrIPv6.
func BrowseMdns(ctx context.Context) (<-chan *mdns.ServiceEntry, error) {
entries := make(chan *mdns.ServiceEntry)
@@ -35,6 +36,20 @@ func BrowseMdns(ctx context.Context) (<-chan *mdns.ServiceEntry, error) {
return entries, err
}
+// Returns a channel of mDNS entries. The critical parts are,
+// entry.HostName, entry.AddrIPv4, and entry.AddrIPv6.
+func LookupMdns(ctx context.Context, target string) (<-chan *mdns.ServiceEntry, error) {
+ entries := make(chan *mdns.ServiceEntry)
+
+ resolver, err := mdns.NewResolver(nil)
+ if err != nil {
+ return entries, err
+ }
+
+ err = resolver.Lookup(ctx, target, MdnsServiceType, MdnsDomain, entries)
+ return entries, err
+}
+
func RunMdnsServer(ctx context.Context, instance string, port int) error {
var text []string
server, err := mdns.Register(instance, MdnsServiceType, MdnsDomain, port, text, nil /* ifaces */)