ZeroConf

用纯 Go 实现的 mDNS / DNS-SD 服务发现(又称 Bonjour)。「mDNS / DNS-SD Service Discovery in pure Go (also known as Bonjour)」

Github星跟踪图

ZeroConf: Service Discovery with mDNS

ZeroConf is a pure Golang library that employs Multicast DNS-SD for

  • browsing and resolving services in your network
  • registering own services

in the local network.

It basically implements aspects of the standards
RFC 6762 (mDNS) and
RFC 6763 (DNS-SD).
Though it does not support all requirements yet, the aim is to provide a compliant solution in the long-term with the community.

By now, it should be compatible to Avahi (tested) and Apple's Bonjour (untested).
Target environments: private LAN/Wifi, small or isolated networks.

GoDoc
Go Report Card
Build Status

Install

Nothing is as easy as that:

$ go get -u github.com/grandcat/zeroconf

This package requires Go 1.7 (context in std lib) or later.

Browse for services in your local network

// Discover all services on the network (e.g. _workstation._tcp)
resolver, err := zeroconf.NewResolver(nil)
if err != nil {
    log.Fatalln("Failed to initialize resolver:", err.Error())
}

entries := make(chan *zeroconf.ServiceEntry)
go func(results <-chan *zeroconf.ServiceEntry) {
    for entry := range results {
        log.Println(entry)
    }
    log.Println("No more entries.")
}(entries)

ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
err = resolver.Browse(ctx, "_workstation._tcp", "local.", entries)
if err != nil {
    log.Fatalln("Failed to browse:", err.Error())
}

<-ctx.Done()

A subtype may added to service name to narrow the set of results. E.g. to browse _workstation._tcp with subtype _windows, use_workstation._tcp,_windows.

See https://github.com/grandcat/zeroconf/blob/master/examples/resolv/client.go.

Lookup a specific service instance

// Example filled soon.

Register a service

server, err := zeroconf.Register("GoZeroconf", "_workstation._tcp", "local.", 42424, []string{"txtv=0", "lo=1", "la=2"}, nil)
if err != nil {
    panic(err)
}
defer server.Shutdown()

// Clean exit.
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
select {
case <-sig:
    // Exit by user
case <-time.After(time.Second * 120):
    // Exit by timeout
}

log.Println("Shutting down.")

Multiple subtypes may be added to service name, separated by commas. E.g _workstation._tcp,_windows has subtype _windows.

See https://github.com/grandcat/zeroconf/blob/master/examples/register/server.go.

Features and ToDo's

This list gives a quick impression about the state of this library.
See what needs to be done and submit a pull request :)

  • Browse / Lookup / Register services
  • Multiple IPv6 / IPv4 addresses support
  • Send multiple probes (exp. back-off) if no service answers (*)
  • Timestamp entries for TTL checks
  • Compare new multicasts with already received services

Notes:

(*) The denoted features might not be perfectly standards compliant, but shouldn't cause any problems.
Some tests showed improvements in overall robustness and performance with the features enabled.

Credits

Great thanks to hashicorp and to oleksandr and all contributing authors for the code this projects bases upon.
Large parts of the code are still the same.

However, there are several reasons why I decided to create a fork of the original project:
The previous project seems to be unmaintained. There are several useful pull requests waiting. I merged most of them in this project.
Still, the implementation has some bugs and lacks some other features that make it quite unreliable in real LAN environments when running continously.
Last but not least, the aim for this project is to build a solution that targets standard conformance in the long term with the support of the community.
Though, resiliency should remain a top goal.

主要指标

概览
名称与所有者grandcat/zeroconf
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证Other
所有者活动
创建于2016-07-25 13:00:34
推送于2023-12-07 12:06:15
最后一次提交2023-01-19 21:11:35
发布数1
最新版本名称v1.0.0 (发布于 )
第一版名称v1.0.0 (发布于 )
用户参与
星数812
关注者数24
派生数190
提交数172
已启用问题?
问题数55
打开的问题数32
拉请求数35
打开的拉请求数16
关闭的拉请求数15
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?