Commit 9d3b90d6 authored by Eric Harris-Braun's avatar Eric Harris-Braun
Browse files

allow tag to be passed into NewMdnsService

parent 0bef0c74
......@@ -37,6 +37,7 @@ type mdnsService struct {
server *mdns.Server
service *mdns.MDNSService
host host.Host
tag string
lk sync.Mutex
notifees []Notifee
......@@ -61,7 +62,7 @@ func getDialableListenAddrs(ph host.Host) ([]*net.TCPAddr, error) {
return out, nil
}
func NewMdnsService(ctx context.Context, peerhost host.Host, interval time.Duration) (Service, error) {
func NewMdnsService(ctx context.Context, peerhost host.Host, interval time.Duration, serviceTag string) (Service, error) {
// TODO: dont let mdns use logging...
golog.SetOutput(ioutil.Discard)
......@@ -82,7 +83,10 @@ func NewMdnsService(ctx context.Context, peerhost host.Host, interval time.Durat
myid := peerhost.ID().Pretty()
info := []string{myid}
service, err := mdns.NewMDNSService(myid, ServiceTag, "", "", port, ipaddrs, info)
if serviceTag == "" {
serviceTag = ServiceTag
}
service, err := mdns.NewMDNSService(myid, serviceTag, "", "", port, ipaddrs, info)
if err != nil {
return nil, err
}
......@@ -98,6 +102,7 @@ func NewMdnsService(ctx context.Context, peerhost host.Host, interval time.Durat
service: service,
host: peerhost,
interval: interval,
tag: serviceTag,
}
go s.pollForEntries(ctx)
......@@ -126,7 +131,7 @@ func (m *mdnsService) pollForEntries(ctx context.Context) {
qp := &mdns.QueryParam{
Domain: "local",
Entries: entriesCh,
Service: ServiceTag,
Service: m.tag,
Timeout: time.Second * 5,
}
......
......@@ -28,12 +28,12 @@ func TestMdnsDiscovery(t *testing.T) {
a := bhost.New(netutil.GenSwarmNetwork(t, ctx))
b := bhost.New(netutil.GenSwarmNetwork(t, ctx))
sa, err := NewMdnsService(ctx, a, time.Second)
sa, err := NewMdnsService(ctx, a, time.Second, "someTag")
if err != nil {
t.Fatal(err)
}
sb, err := NewMdnsService(ctx, b, time.Second)
sb, err := NewMdnsService(ctx, b, time.Second, "someTag")
if err != nil {
t.Fatal(err)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment