diff --git a/contrib/mobile/mobile.go b/contrib/mobile/mobile.go index 177fd1dd7..62c3cb0dd 100644 --- a/contrib/mobile/mobile.go +++ b/contrib/mobile/mobile.go @@ -34,6 +34,11 @@ type Mesh struct { log MobileLogger } +// This method initialize Anet library for multicast module fix in Android +func (m *Mesh) SetOsVersion(version uint) { + m.core.OsVersion = version +} + // StartAutoconfigure starts a node with a randomly generated config func (m *Mesh) StartAutoconfigure() error { return m.StartJSON([]byte("{}")) diff --git a/go.mod b/go.mod index 95737facf..773434393 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require gerace.dev/zipfs v0.2.0 require ( github.com/slonm/tableprinter v0.0.0-20230107100804-643098716018 github.com/vorot93/golang-signals v0.0.0-20170221070717-d9e83421ce45 + github.com/wlynxg/anet v0.0.2 golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15 golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 ) @@ -45,7 +46,6 @@ require ( github.com/libp2p/go-buffer-pool v0.0.2 // indirect github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect github.com/rivo/uniseg v0.3.4 // indirect - github.com/wlynxg/anet v0.0.1 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.19.1 // indirect diff --git a/go.sum b/go.sum index 406f0649e..bfb3ec828 100644 --- a/go.sum +++ b/go.sum @@ -77,8 +77,8 @@ github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f h1:p4VB7kIXpOQvV github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/vorot93/golang-signals v0.0.0-20170221070717-d9e83421ce45 h1:hB/hkjwf3BQnZE6Wk3SBwMJz0NqnGdwXoNzHVSYb0N0= github.com/vorot93/golang-signals v0.0.0-20170221070717-d9e83421ce45/go.mod h1:dfjQkJsG5auteUbnfLIcU72Y/z8tj7DuW9fik8f2Zn0= -github.com/wlynxg/anet v0.0.1 h1:VbkEEgHxPSrRQSiyRd0pmrbcEQAEU2TTb8fb4DmSYoQ= -github.com/wlynxg/anet v0.0.1/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA= +github.com/wlynxg/anet v0.0.2 h1:kH9s2huwMsED3eQknbL7gQBoW2Gsh5FCD/ceucpaIbk= +github.com/wlynxg/anet v0.0.2/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= diff --git a/src/core/core.go b/src/core/core.go index 391c20665..2d0e4a519 100644 --- a/src/core/core.go +++ b/src/core/core.go @@ -44,6 +44,7 @@ type Core struct { _allowedPublicKeys map[[32]byte]struct{} // configurable after startup networkdomain NetworkDomain // immutable after startup } + OsVersion uint } func New(secret ed25519.PrivateKey, logger Logger, opts ...SetupOption) (*Core, error) { diff --git a/src/multicast/multicast.go b/src/multicast/multicast.go index 81c79ff4f..a37caaf20 100644 --- a/src/multicast/multicast.go +++ b/src/multicast/multicast.go @@ -65,6 +65,7 @@ func New(core *core.Core, log *log.Logger, opts ...SetupOption) (*Multicast, err _listeners: make(map[string]*listenerInfo), _interfaces: make(map[string]*interfaceInfo), } + m.SetOsVersion() m.config._interfaces = map[MulticastInterface]struct{}{} m.config._groupAddr = GroupAddress("[ff02::114]:9001") for _, opt := range opts { diff --git a/src/multicast/multicast_android.go b/src/multicast/multicast_android.go new file mode 100644 index 000000000..44555a14f --- /dev/null +++ b/src/multicast/multicast_android.go @@ -0,0 +1,37 @@ +//go:build android +// +build android + +package multicast + +import ( + "fmt" + "os" + "syscall" + + "github.com/wlynxg/anet" + "golang.org/x/sys/unix" +) + +func (m *Multicast) SetOsVersion() { + anet.SetAndroidVersion(m.core.OsVersion) +} + +func (m *Multicast) _multicastStarted() { + +} + +func (m *Multicast) multicastReuse(network string, address string, c syscall.RawConn) error { + var control error + var reuseaddr error + + control = c.Control(func(fd uintptr) { + // Previously we used SO_REUSEPORT here, but that meant that machines running + // RiV-mesh nodes as different users would inevitably fail with EADDRINUSE. + // The behaviour for multicast is similar with both, so we'll use SO_REUSEADDR + // instead. + if reuseaddr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1); reuseaddr != nil { + fmt.Fprintf(os.Stderr, "Failed to set SO_REUSEADDR on socket: %s\n", reuseaddr) + } + }) + return control +} diff --git a/src/multicast/multicast_darwin.go b/src/multicast/multicast_darwin.go index 22cf3998e..ccc5feb47 100644 --- a/src/multicast/multicast_darwin.go +++ b/src/multicast/multicast_darwin.go @@ -10,6 +10,10 @@ import ( "golang.org/x/sys/unix" ) +func (m *Multicast) SetOsVersion() { + +} + func (m *Multicast) _multicastStarted() { } diff --git a/src/multicast/multicast_darwin_cgo.go b/src/multicast/multicast_darwin_cgo.go index 5c2af7aba..00f5e0c42 100644 --- a/src/multicast/multicast_darwin_cgo.go +++ b/src/multicast/multicast_darwin_cgo.go @@ -30,6 +30,10 @@ import ( "golang.org/x/sys/unix" ) +func (m *Multicast) SetOsVersion() { + +} + func (m *Multicast) _multicastStarted() { if !m._isOpen { return diff --git a/src/multicast/multicast_other.go b/src/multicast/multicast_other.go index 263f4ffc5..898418a3a 100644 --- a/src/multicast/multicast_other.go +++ b/src/multicast/multicast_other.go @@ -5,6 +5,10 @@ package multicast import "syscall" +func (m *Multicast) SetOsVersion() { + +} + func (m *Multicast) _multicastStarted() { } diff --git a/src/multicast/multicast_unix.go b/src/multicast/multicast_unix.go index 4247d7d18..c20d327d0 100644 --- a/src/multicast/multicast_unix.go +++ b/src/multicast/multicast_unix.go @@ -1,4 +1,5 @@ -//go:build linux || netbsd || freebsd || openbsd || dragonflybsd +//go:build !android && (linux || netbsd || freebsd || openbsd || dragonflybsd) +// +build !android // +build linux netbsd freebsd openbsd dragonflybsd package multicast @@ -11,6 +12,10 @@ import ( "golang.org/x/sys/unix" ) +func (m *Multicast) SetOsVersion() { + +} + func (m *Multicast) _multicastStarted() { } diff --git a/src/multicast/multicast_windows.go b/src/multicast/multicast_windows.go index fa194ac67..c6f4f6b49 100644 --- a/src/multicast/multicast_windows.go +++ b/src/multicast/multicast_windows.go @@ -9,6 +9,10 @@ import ( "golang.org/x/sys/windows" ) +func (m *Multicast) SetOsVersion() { + +} + func (m *Multicast) _multicastStarted() { }