Skip to content

Commit 947b6ad

Browse files
authored
Restore local peer discovery mechanism on Android 11+ (#1158)
This solution is bases on https://github.com/wlynxg/anet project. `github.com/wlynxg/anet` is a partial alternative implementation of the `golang.org/x/net` module. The goal of `anet` module is to provide workarounds of the issues golang/go#40569 and golang/go#68082 on Android 11+. Tested on AOSP 13. Resolves: #1149
1 parent 340cedb commit 947b6ad

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/kardianos/minwinsvc v1.0.2
1313
github.com/quic-go/quic-go v0.45.1
1414
github.com/vishvananda/netlink v1.1.0
15+
github.com/wlynxg/anet v0.0.4-0.20240806025826-e684438fc7c6
1516
golang.org/x/crypto v0.25.0
1617
golang.org/x/mobile v0.0.0-20240716161057-1ad2df20a8b6
1718
golang.org/x/net v0.27.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYp
7070
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
7171
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f h1:p4VB7kIXpOQvVn1ZaTIVp+3vuYAXFe3OJEvjbUYJLaA=
7272
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
73+
github.com/wlynxg/anet v0.0.4-0.20240806025826-e684438fc7c6 h1:c/wkXIJvpg2oot7iFqPESTBAO9UvhWTBnW97y9aPgyU=
74+
github.com/wlynxg/anet v0.0.4-0.20240806025826-e684438fc7c6/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
7375
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
7476
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
7577
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=

src/multicast/multicast.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/Arceliar/phony"
1616
"github.com/gologme/log"
17+
"github.com/wlynxg/anet"
1718

1819
"github.com/yggdrasil-network/yggdrasil-go/src/core"
1920
"golang.org/x/crypto/blake2b"
@@ -148,14 +149,16 @@ func (m *Multicast) _stop() error {
148149
func (m *Multicast) _updateInterfaces() {
149150
interfaces := m._getAllowedInterfaces()
150151
for name, info := range interfaces {
151-
addrs, err := info.iface.Addrs()
152+
// 'anet' package is used here to avoid https://github.com/golang/go/issues/40569
153+
addrs, err := anet.InterfaceAddrsByInterface(&info.iface)
152154
if err != nil {
153155
m.log.Warnf("Failed up get addresses for interface %s: %s", name, err)
154156
delete(interfaces, name)
155157
continue
156158
}
157159
info.addrs = addrs
158160
interfaces[name] = info
161+
m.log.Debugf("Discovered addresses for interface %s: %s", name, addrs)
159162
}
160163
m._interfaces = interfaces
161164
}
@@ -174,10 +177,11 @@ func (m *Multicast) Interfaces() map[string]net.Interface {
174177
func (m *Multicast) _getAllowedInterfaces() map[string]*interfaceInfo {
175178
interfaces := make(map[string]*interfaceInfo)
176179
// Ask the system for network interfaces
177-
allifaces, err := net.Interfaces()
180+
// 'anet' package is used here to avoid https://github.com/golang/go/issues/40569
181+
allifaces, err := anet.Interfaces()
178182
if err != nil {
179183
// Don't panic, since this may be from e.g. too many open files (from too much connection spam)
180-
// TODO? log something
184+
m.log.Debugf("Failed to get interfaces: %s", err)
181185
return nil
182186
}
183187
// Work out which interfaces to announce on

0 commit comments

Comments
 (0)