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
+2 -2
View File
@@ -40,7 +40,7 @@ import (
"net"
"time"
"github.com/wlynxg/anet"
"github.com/syncthing/syncthing/lib/netutil"
"github.com/syncthing/syncthing/lib/nat"
)
@@ -67,7 +67,7 @@ func (s *IGDService) AddPinhole(ctx context.Context, protocol nat.Protocol, intA
return nil, errors.New("no interface")
}
addrs, err := anet.InterfaceAddrsByInterface(s.Interface)
addrs, err := netutil.InterfaceAddrsByInterface(s.Interface)
if err != nil {
return nil, err
}
+4 -4
View File
@@ -48,7 +48,7 @@ import (
"sync"
"time"
"github.com/wlynxg/anet"
"github.com/syncthing/syncthing/lib/netutil"
"github.com/syncthing/syncthing/lib/build"
"github.com/syncthing/syncthing/lib/dialer"
@@ -106,7 +106,7 @@ const (
func Discover(ctx context.Context, _, timeout time.Duration) []nat.Device {
var results []nat.Device
interfaces, err := anet.Interfaces()
interfaces, err := netutil.Interfaces()
if err != nil {
l.Infoln("Listing network interfaces:", err)
return results
@@ -388,7 +388,7 @@ func parseResponse(ctx context.Context, deviceType string, addr *net.UDPAddr, re
}
func localIPv4(netInterface *net.Interface) (net.IP, error) {
addrs, err := anet.InterfaceAddrsByInterface(netInterface)
addrs, err := netutil.InterfaceAddrsByInterface(netInterface)
if err != nil {
return nil, err
}
@@ -631,7 +631,7 @@ func soapRequestWithIP(ctx context.Context, url, service, function, message stri
}
func interfaceHasGUAIPv6(intf net.Interface) (bool, error) {
addrs, err := anet.InterfaceAddrsByInterface(&intf)
addrs, err := netutil.InterfaceAddrsByInterface(&intf)
if err != nil {
return false, err
}