feat: use anet for android compatibility

This commit is contained in:
wpetit 2024-08-06 09:32:02 +02:00
parent 6842d4d88a
commit d43fb768a0
3 changed files with 18 additions and 1 deletions

1
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

View File

@ -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)
}