From ee33bd248f19945d83d1b84db65d97030739eb3e Mon Sep 17 00:00:00 2001 From: Revertron <105154+Revertron@users.noreply.github.com> Date: Tue, 1 Nov 2022 13:10:50 +0100 Subject: [PATCH 1/3] Added two new methods to `mobile` package (#974) * Added two new methods In order to implement https://github.com/yggdrasil-network/yggdrasil-android/issues/25 we need these new methods. * Renamed methods, changed comments --- contrib/mobile/mobile.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/contrib/mobile/mobile.go b/contrib/mobile/mobile.go index 78a3f506..9b146492 100644 --- a/contrib/mobile/mobile.go +++ b/contrib/mobile/mobile.go @@ -115,6 +115,18 @@ func (m *Yggdrasil) Send(p []byte) error { return nil } +// Send sends a packet from given buffer to Yggdrasil. From first byte up to length. +func (m *Yggdrasil) SendBuffer(p []byte, length int) error { + if m.iprwc == nil { + return nil + } + if len(p) < length { + return nil + } + _, _ = m.iprwc.Write(p[:length]) + return nil +} + // Recv waits for and reads a packet coming from Yggdrasil. It // will be a fully formed IPv6 packet func (m *Yggdrasil) Recv() ([]byte, error) { @@ -126,6 +138,15 @@ func (m *Yggdrasil) Recv() ([]byte, error) { return buf[:n], nil } +// Recv waits for and reads a packet coming from Yggdrasil to given buffer, returning size of packet +func (m *Yggdrasil) RecvBuffer(buf []byte) (int, error) { + if m.iprwc == nil { + return 0, nil + } + n, _ := m.iprwc.Read(buf) + return n, nil +} + // Stop the mobile Yggdrasil instance func (m *Yggdrasil) Stop() error { logger := log.New(m.log, "", 0) From 590d83aa9c90b151de471d13571c331075506481 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 1 Nov 2022 17:42:52 +0000 Subject: [PATCH 2/3] Fix #975 by not exporting `uint8` --- contrib/mobile/mobile.go | 4 ++-- go.mod | 2 +- go.sum | 5 ++--- src/admin/getpeers.go | 4 ++-- src/config/config.go | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/contrib/mobile/mobile.go b/contrib/mobile/mobile.go index 9b146492..ff22b9d7 100644 --- a/contrib/mobile/mobile.go +++ b/contrib/mobile/mobile.go @@ -87,7 +87,7 @@ func (m *Yggdrasil) StartJSON(configjson []byte) error { Beacon: intf.Beacon, Listen: intf.Listen, Port: intf.Port, - Priority: intf.Priority, + Priority: uint8(intf.Priority), }) } m.multicast, err = multicast.New(m.core, logger, options...) @@ -138,7 +138,7 @@ func (m *Yggdrasil) Recv() ([]byte, error) { return buf[:n], nil } -// Recv waits for and reads a packet coming from Yggdrasil to given buffer, returning size of packet +// Recv waits for and reads a packet coming from Yggdrasil to given buffer, returning size of packet func (m *Yggdrasil) RecvBuffer(buf []byte) (int, error) { if m.iprwc == nil { return 0, nil diff --git a/go.mod b/go.mod index 156b42ce..adaf7cf8 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/kardianos/minwinsvc v1.0.2 github.com/mitchellh/mapstructure v1.4.1 github.com/vishvananda/netlink v1.1.0 - golang.org/x/mobile v0.0.0-20221012134814-c746ac228303 + golang.org/x/mobile v0.0.0-20221020085226-b36e6246172e golang.org/x/net v0.0.0-20221014081412-f15817d10f9b golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43 golang.org/x/text v0.3.8 diff --git a/go.sum b/go.sum index b6655087..e398aca6 100644 --- a/go.sum +++ b/go.sum @@ -55,8 +55,8 @@ golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9t golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20221012134814-c746ac228303 h1:K4fp1rDuJBz0FCPAWzIJwnzwNEM7S6yobdZzMrZ/Zws= -golang.org/x/mobile v0.0.0-20221012134814-c746ac228303/go.mod h1:M32cGdzp91A8Ex9qQtyZinr19EYxzkFqDjW2oyHzTDQ= +golang.org/x/mobile v0.0.0-20221020085226-b36e6246172e h1:zSgtO19fpg781xknwqiQPmOHaASr6E7ZVlTseLd9Fx4= +golang.org/x/mobile v0.0.0-20221020085226-b36e6246172e/go.mod h1:aAjjkJNdrh3PMckS4B10TGS2nag27cbKR1y2BpUxsiY= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= @@ -108,7 +108,6 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= -golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/src/admin/getpeers.go b/src/admin/getpeers.go index c1c9a6f9..d51b184d 100644 --- a/src/admin/getpeers.go +++ b/src/admin/getpeers.go @@ -19,7 +19,7 @@ type PeerEntry struct { IPAddress string `json:"address"` PublicKey string `json:"key"` Port uint64 `json:"port"` - Priority uint8 `json:"priority"` + Priority uint64 `json:"priority"` Coords []uint64 `json:"coords"` Remote string `json:"remote"` RXBytes DataUnit `json:"bytes_recvd"` @@ -36,7 +36,7 @@ func (a *AdminSocket) getPeersHandler(req *GetPeersRequest, res *GetPeersRespons IPAddress: net.IP(addr[:]).String(), PublicKey: hex.EncodeToString(p.Key), Port: p.Port, - Priority: p.Priority, + Priority: uint64(p.Priority), // can't be uint8 thanks to gobind Coords: p.Coords, Remote: p.Remote, RXBytes: DataUnit(p.RXBytes), diff --git a/src/config/config.go b/src/config/config.go index 3fc9c4ed..f7f0f6ba 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -44,7 +44,7 @@ type MulticastInterfaceConfig struct { Beacon bool Listen bool Port uint16 - Priority uint8 + Priority uint64 // really uint8, but gobind won't export it } // NewSigningKeys replaces the signing keypair in the NodeConfig with a new From 6112c9cf18929547229e55c9d364efec6f775f88 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 1 Nov 2022 18:34:49 +0000 Subject: [PATCH 3/3] Fix build --- cmd/yggdrasil/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/yggdrasil/main.go b/cmd/yggdrasil/main.go index 8185dee0..2d1da6b9 100644 --- a/cmd/yggdrasil/main.go +++ b/cmd/yggdrasil/main.go @@ -339,7 +339,7 @@ func run(args yggArgs, ctx context.Context) { Beacon: intf.Beacon, Listen: intf.Listen, Port: intf.Port, - Priority: intf.Priority, + Priority: uint8(intf.Priority), }) } if n.multicast, err = multicast.New(n.core, logger, options...); err != nil {