7 "github.com/grandcat/zeroconf"
11 instanceName = "vapord"
12 serviceName = "vapor%sLanDiscover"
16 // Protocol decoration ZeroConf,which is a pure Golang library
17 // that employs Multicast DNS-SD.
18 type Protocol struct {
19 entries chan *zeroconf.ServiceEntry
20 server *zeroconf.Server
25 // NewProtocol create a specific Protocol.
26 func NewProtocol(chainID string) *Protocol {
28 entries: make(chan *zeroconf.ServiceEntry),
29 serviceName: fmt.Sprintf(serviceName, chainID),
30 quite: make(chan struct{}),
34 func (p *Protocol) getLanPeerLoop(event chan LANPeerEvent) {
37 case entry := <-p.entries:
38 event <- LANPeerEvent{IP: entry.AddrIPv4, Port: entry.Port}
45 func (p *Protocol) registerService(port int) error {
47 p.server, err = zeroconf.Register(instanceName, p.serviceName, domainName, port, nil, nil)
51 func (m *Protocol) registerResolver(event chan LANPeerEvent) error {
52 go m.getLanPeerLoop(event)
53 resolver, err := zeroconf.NewResolver(nil)
58 return resolver.Browse(context.Background(), m.serviceName, domainName, m.entries)
61 func (p *Protocol) stopResolver() {
65 func (p *Protocol) stopService() {