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
c4201a20
Commit
c4201a20
authored
Mar 15, 2017
by
Hector Sanjuan
Browse files
discovery: make golint happy, improve docs
License: MIT Signed-off-by:
Hector Sanjuan
<
hector@protocol.ai
>
parent
4557f31f
Changes
1
Hide whitespace changes
Inline
Side-by-side
p2p/discovery/mdns.go
View file @
c4201a20
// Package discovery provides mDNS announcements and discovery for libp2p hosts.
// It can be used to auto-discover peers in networks where mDNS (multicast)
// is not blocked.
package
discovery
package
discovery
import
(
import
(
...
@@ -21,14 +24,20 @@ import (
...
@@ -21,14 +24,20 @@ import (
var
log
=
logging
.
Logger
(
"mdns"
)
var
log
=
logging
.
Logger
(
"mdns"
)
// ServiceTag is used to identify the mDNS service
const
ServiceTag
=
"_ipfs-discovery._udp"
const
ServiceTag
=
"_ipfs-discovery._udp"
// Service provides an interface for mDNS service implementations.
// Currently they support registration and removal of notifees, which
// are notified when a new peer is found.
type
Service
interface
{
type
Service
interface
{
io
.
Closer
io
.
Closer
RegisterNotifee
(
Notifee
)
RegisterNotifee
(
Notifee
)
UnregisterNotifee
(
Notifee
)
UnregisterNotifee
(
Notifee
)
}
}
// Notifee is an interface which allows to be notified
// when a new peer is found by a mDNS service.
type
Notifee
interface
{
type
Notifee
interface
{
HandlePeerFound
(
pstore
.
PeerInfo
)
HandlePeerFound
(
pstore
.
PeerInfo
)
}
}
...
@@ -61,6 +70,10 @@ func getDialableListenAddrs(ph host.Host) ([]*net.TCPAddr, error) {
...
@@ -61,6 +70,10 @@ func getDialableListenAddrs(ph host.Host) ([]*net.TCPAddr, error) {
return
out
,
nil
return
out
,
nil
}
}
// NewMdnsService creates and initializes a new Service. It receives a
// cancellable context (used to cancel mDNS polling), a Host (whose information
// is multicasted to the local network), and an interval which specifies how
// often to perform mDNS queries.
func
NewMdnsService
(
ctx
context
.
Context
,
peerhost
host
.
Host
,
interval
time
.
Duration
)
(
Service
,
error
)
{
func
NewMdnsService
(
ctx
context
.
Context
,
peerhost
host
.
Host
,
interval
time
.
Duration
)
(
Service
,
error
)
{
// TODO: dont let mdns use logging...
// TODO: dont let mdns use logging...
...
...
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