Skip to content

Commit

Permalink
RCL-56 Multicast autopeering fix (Anet library)
Browse files Browse the repository at this point in the history
  • Loading branch information
vikulin committed Jun 19, 2024
1 parent 4ca6f4d commit 34c4f8e
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 4 deletions.
5 changes: 5 additions & 0 deletions contrib/mobile/mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("{}"))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions src/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/multicast/multicast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
37 changes: 37 additions & 0 deletions src/multicast/multicast_android.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions src/multicast/multicast_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"golang.org/x/sys/unix"
)

func (m *Multicast) SetOsVersion() {

}

func (m *Multicast) _multicastStarted() {

}
Expand Down
4 changes: 4 additions & 0 deletions src/multicast/multicast_darwin_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import (
"golang.org/x/sys/unix"
)

func (m *Multicast) SetOsVersion() {

}

func (m *Multicast) _multicastStarted() {
if !m._isOpen {
return
Expand Down
4 changes: 4 additions & 0 deletions src/multicast/multicast_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ package multicast

import "syscall"

func (m *Multicast) SetOsVersion() {

}

func (m *Multicast) _multicastStarted() {

}
Expand Down
7 changes: 6 additions & 1 deletion src/multicast/multicast_unix.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,6 +12,10 @@ import (
"golang.org/x/sys/unix"
)

func (m *Multicast) SetOsVersion() {

}

func (m *Multicast) _multicastStarted() {

}
Expand Down
4 changes: 4 additions & 0 deletions src/multicast/multicast_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"golang.org/x/sys/windows"
)

func (m *Multicast) SetOsVersion() {

}

func (m *Multicast) _multicastStarted() {

}
Expand Down

0 comments on commit 34c4f8e

Please sign in to comment.