Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

mDNS / DNS-SD Service Discovery in pure Go (also known as Bonjour)

License

NotificationsYou must be signed in to change notification settings

libp2p/zeroconf

 
 

Repository files navigation

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 standardsRFC 6762 (mDNS) andRFC 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 toAvahi (tested) and Apple's Bonjour (untested).Target environments: private LAN/Wifi, small or isolated networks.

GoDocGo Report CardTests

Install

Nothing is as easy as that:

$ go get -u github.com/libp2p/zeroconf/v2

Browse for services in your local network

entries:=make(chan*zeroconf.ServiceEntry)gofunc(results<-chan*zeroconf.ServiceEntry) {forentry:=rangeresults {log.Println(entry)    }log.Println("No more entries.")}(entries)ctx,cancel:=context.WithTimeout(context.Background(),time.Second*15)defercancel()// Discover all services on the network (e.g. _workstation._tcp)err=zeroconf.Browse(ctx,"_workstation._tcp","local.",entries)iferr!=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.

Seehttps://github.com/libp2p/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)iferr!=nil {panic(err)}deferserver.Shutdown()// Clean exit.sig:=make(chan os.Signal,1)signal.Notify(sig,os.Interrupt,syscall.SIGTERM)select {case<-sig:// Exit by usercase<-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.

Seehttps://github.com/libp2p/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 tohashicorp and tooleksandr 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.

About

mDNS / DNS-SD Service Discovery in pure Go (also known as Bonjour)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go100.0%

[8]ページ先頭

©2009-2025 Movatter.jp