Commit 4ec73134 authored by Jeromy Johnson's avatar Jeromy Johnson Committed by GitHub
Browse files

Merge pull request #233 from metacurrency/master

allow tag to be passed into NewMdnsService
parents 0bef0c74 9d3b90d6
...@@ -37,6 +37,7 @@ type mdnsService struct { ...@@ -37,6 +37,7 @@ type mdnsService struct {
server *mdns.Server server *mdns.Server
service *mdns.MDNSService service *mdns.MDNSService
host host.Host host host.Host
tag string
lk sync.Mutex lk sync.Mutex
notifees []Notifee notifees []Notifee
...@@ -61,7 +62,7 @@ func getDialableListenAddrs(ph host.Host) ([]*net.TCPAddr, error) { ...@@ -61,7 +62,7 @@ func getDialableListenAddrs(ph host.Host) ([]*net.TCPAddr, error) {
return out, nil 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... // TODO: dont let mdns use logging...
golog.SetOutput(ioutil.Discard) golog.SetOutput(ioutil.Discard)
...@@ -82,7 +83,10 @@ func NewMdnsService(ctx context.Context, peerhost host.Host, interval time.Durat ...@@ -82,7 +83,10 @@ func NewMdnsService(ctx context.Context, peerhost host.Host, interval time.Durat
myid := peerhost.ID().Pretty() myid := peerhost.ID().Pretty()
info := []string{myid} 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 { if err != nil {
return nil, err return nil, err
} }
...@@ -98,6 +102,7 @@ func NewMdnsService(ctx context.Context, peerhost host.Host, interval time.Durat ...@@ -98,6 +102,7 @@ func NewMdnsService(ctx context.Context, peerhost host.Host, interval time.Durat
service: service, service: service,
host: peerhost, host: peerhost,
interval: interval, interval: interval,
tag: serviceTag,
} }
go s.pollForEntries(ctx) go s.pollForEntries(ctx)
...@@ -126,7 +131,7 @@ func (m *mdnsService) pollForEntries(ctx context.Context) { ...@@ -126,7 +131,7 @@ func (m *mdnsService) pollForEntries(ctx context.Context) {
qp := &mdns.QueryParam{ qp := &mdns.QueryParam{
Domain: "local", Domain: "local",
Entries: entriesCh, Entries: entriesCh,
Service: ServiceTag, Service: m.tag,
Timeout: time.Second * 5, Timeout: time.Second * 5,
} }
......
...@@ -28,12 +28,12 @@ func TestMdnsDiscovery(t *testing.T) { ...@@ -28,12 +28,12 @@ func TestMdnsDiscovery(t *testing.T) {
a := bhost.New(netutil.GenSwarmNetwork(t, ctx)) a := bhost.New(netutil.GenSwarmNetwork(t, ctx))
b := 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
sb, err := NewMdnsService(ctx, b, time.Second) sb, err := NewMdnsService(ctx, b, time.Second, "someTag")
if err != nil { if err != nil {
t.Fatal(err) 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