refactor(beacon, osutil, upnp, netutil): only use anet on Android (#10211)

Add a wrapper that uses anet on Android, but net on other platforms.

### Purpose

Fixes
https://forum.syncthing.net/t/workaround-for-android-local-discovery/20403/12

### Testing

Run two Syncthing instances with Global Discovery disabled. Pair them
with each other, don't hardcode their addresses, and verify they
connect.
This commit is contained in:
Marcus B Spencer
2025-07-08 08:18:51 +02:00
committed by GitHub
parent e8cfc8acfb
commit 32a913c0ff
7 changed files with 55 additions and 15 deletions
+3 -3
View File
@@ -11,7 +11,7 @@ import (
"net"
"time"
"github.com/wlynxg/anet"
"github.com/syncthing/syncthing/lib/netutil"
)
func NewBroadcast(port int) Interface {
@@ -46,7 +46,7 @@ func writeBroadcasts(ctx context.Context, inbox <-chan []byte, port int) error {
return doneCtx.Err()
}
intfs, err := anet.Interfaces()
intfs, err := netutil.Interfaces()
if err != nil {
l.Debugln("Failed to list interfaces:", err)
// net.Interfaces() is broken on Android. see https://github.com/golang/go/issues/40569
@@ -61,7 +61,7 @@ func writeBroadcasts(ctx context.Context, inbox <-chan []byte, port int) error {
continue
}
addrs, err := anet.InterfaceAddrsByInterface(&intf)
addrs, err := netutil.InterfaceAddrsByInterface(&intf)
if err != nil {
l.Debugln("Failed to list interface addresses:", err)
// Interface discovery might work while retrieving the addresses doesn't. So log the error and carry on.
+3 -3
View File
@@ -12,7 +12,7 @@ import (
"net"
"time"
"github.com/wlynxg/anet"
"github.com/syncthing/syncthing/lib/netutil"
"golang.org/x/net/ipv6"
)
@@ -61,7 +61,7 @@ func writeMulticasts(ctx context.Context, inbox <-chan []byte, addr string) erro
return doneCtx.Err()
}
intfs, err := anet.Interfaces()
intfs, err := netutil.Interfaces()
if err != nil {
l.Debugln(err)
return err
@@ -119,7 +119,7 @@ func readMulticasts(ctx context.Context, outbox chan<- recv, addr string) error
conn.Close()
}()
intfs, err := anet.Interfaces()
intfs, err := netutil.Interfaces()
if err != nil {
l.Debugln(err)
return err