Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
9d3b90d6
Commit
9d3b90d6
authored
Sep 24, 2017
by
Eric Harris-Braun
Browse files
allow tag to be passed into NewMdnsService
parent
0bef0c74
Changes
2
Hide whitespace changes
Inline
Side-by-side
p2p/discovery/mdns.go
View file @
9d3b90d6
...
...
@@ -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
:
ServiceT
ag
,
Service
:
m
.
t
ag
,
Timeout
:
time
.
Second
*
5
,
}
...
...
p2p/discovery/mdns_test.go
View file @
9d3b90d6
...
...
@@ -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
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment