From d43fb768a006c8bc6a05ce90d3c57e67ef3c215a Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 6 Aug 2024 09:32:02 +0200 Subject: [PATCH] feat: use anet for android compatibility --- go.mod | 1 + go.sum | 4 ++++ reach/discovery/discovery.go | 14 +++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 631b4df..1f10af3 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/cenkalti/backoff v2.2.1+incompatible // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/miekg/dns v1.1.27 // indirect + github.com/wlynxg/anet v0.0.4-0.20240806025826-e684438fc7c6 // indirect golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe // indirect diff --git a/go.sum b/go.sum index 0c5f228..c464e3e 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,10 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/wlynxg/anet v0.0.3 h1:PvR53psxFXstc12jelG6f1Lv4MWqE0tI76/hHGjh9rg= +github.com/wlynxg/anet v0.0.3/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA= +github.com/wlynxg/anet v0.0.4-0.20240806025826-e684438fc7c6 h1:c/wkXIJvpg2oot7iFqPESTBAO9UvhWTBnW97y9aPgyU= +github.com/wlynxg/anet v0.0.4-0.20240806025826-e684438fc7c6/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= diff --git a/reach/discovery/discovery.go b/reach/discovery/discovery.go index 7f2a723..f6deea6 100644 --- a/reach/discovery/discovery.go +++ b/reach/discovery/discovery.go @@ -2,10 +2,12 @@ package discovery import ( "context" + "log" "net" "github.com/grandcat/zeroconf" "github.com/pkg/errors" + "github.com/wlynxg/anet" ) // Service is a ReachRS service discovered via MDNS-SD @@ -33,9 +35,19 @@ func Discover(ctx context.Context) ([]Service, error) { // Watch watches ReachRS services on the local network via mDNS-SD func Watch(ctx context.Context) (chan Service, error) { + ifaces, err := anet.Interfaces() + if err != nil { + return nil, errors.WithStack(err) + } + + log.Printf("%v", ifaces) + out := make(chan Service, 0) - resolver, err := zeroconf.NewResolver() + resolver, err := zeroconf.NewResolver( + zeroconf.SelectIfaces(ifaces), + zeroconf.SelectIPTraffic(zeroconf.IPv4), + ) if err != nil { return nil, errors.WithStack(err) }