mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-12-22 16:07:31 +00:00
Unexport/modify some interfaces to revive broken iOS/Android builds
This commit is contained in:
parent
4c0c3a23cb
commit
39baf7365c
@ -148,11 +148,11 @@ func (tun *TunAdapter) Start(a address.Address, s address.Subnet) error {
|
|||||||
tun.mutex.Unlock()
|
tun.mutex.Unlock()
|
||||||
go func() {
|
go func() {
|
||||||
tun.log.Debugln("Starting TUN/TAP reader goroutine")
|
tun.log.Debugln("Starting TUN/TAP reader goroutine")
|
||||||
tun.log.Errorln("WARNING: tun.read() exited with error:", tun.Read())
|
tun.log.Errorln("WARNING: tun.read() exited with error:", tun.read())
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
tun.log.Debugln("Starting TUN/TAP writer goroutine")
|
tun.log.Debugln("Starting TUN/TAP writer goroutine")
|
||||||
tun.log.Errorln("WARNING: tun.write() exited with error:", tun.Write())
|
tun.log.Errorln("WARNING: tun.write() exited with error:", tun.write())
|
||||||
}()
|
}()
|
||||||
if iftapmode {
|
if iftapmode {
|
||||||
go func() {
|
go func() {
|
||||||
@ -177,7 +177,7 @@ func (tun *TunAdapter) Start(a address.Address, s address.Subnet) error {
|
|||||||
// Writes a packet to the TUN/TAP adapter. If the adapter is running in TAP
|
// Writes a packet to the TUN/TAP adapter. If the adapter is running in TAP
|
||||||
// mode then additional ethernet encapsulation is added for the benefit of the
|
// mode then additional ethernet encapsulation is added for the benefit of the
|
||||||
// host operating system.
|
// host operating system.
|
||||||
func (tun *TunAdapter) Write() error {
|
func (tun *TunAdapter) write() error {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case reject := <-tun.Reject:
|
case reject := <-tun.Reject:
|
||||||
@ -310,7 +310,7 @@ func (tun *TunAdapter) Write() error {
|
|||||||
// is running in TAP mode then the ethernet headers will automatically be
|
// is running in TAP mode then the ethernet headers will automatically be
|
||||||
// processed and stripped if necessary. If an ICMPv6 packet is found, then
|
// processed and stripped if necessary. If an ICMPv6 packet is found, then
|
||||||
// the relevant helper functions in icmpv6.go are called.
|
// the relevant helper functions in icmpv6.go are called.
|
||||||
func (tun *TunAdapter) Read() error {
|
func (tun *TunAdapter) read() error {
|
||||||
mtu := tun.mtu
|
mtu := tun.mtu
|
||||||
if tun.iface.IsTAP() {
|
if tun.iface.IsTAP() {
|
||||||
mtu += tun_ETHER_HEADER_LENGTH
|
mtu += tun_ETHER_HEADER_LENGTH
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
// you should extend the adapter struct with this one and should call the
|
// you should extend the adapter struct with this one and should call the
|
||||||
// Adapter.Init() function when initialising.
|
// Adapter.Init() function when initialising.
|
||||||
type Adapter struct {
|
type Adapter struct {
|
||||||
AdapterImplementation
|
adapterImplementation
|
||||||
Core *Core
|
Core *Core
|
||||||
Send chan<- []byte
|
Send chan<- []byte
|
||||||
Recv <-chan []byte
|
Recv <-chan []byte
|
||||||
@ -20,15 +20,14 @@ type Adapter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Defines the minimum required functions for an adapter type. Note that the
|
// Defines the minimum required functions for an adapter type. Note that the
|
||||||
// implementation of Init() should call Adapter.Init().
|
// implementation of Init() should call Adapter.Init(). This is not exported
|
||||||
type AdapterImplementation interface {
|
// because doing so breaks the gomobile bindings for iOS/Android.
|
||||||
|
type adapterImplementation interface {
|
||||||
Init(*config.NodeState, *log.Logger, chan<- []byte, <-chan []byte, <-chan RejectedPacket)
|
Init(*config.NodeState, *log.Logger, chan<- []byte, <-chan []byte, <-chan RejectedPacket)
|
||||||
Name() string
|
Name() string
|
||||||
MTU() int
|
MTU() int
|
||||||
IsTAP() bool
|
IsTAP() bool
|
||||||
Start(address.Address, address.Subnet) error
|
Start(address.Address, address.Subnet) error
|
||||||
Read() error
|
|
||||||
Write() error
|
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +36,6 @@ type AdapterImplementation interface {
|
|||||||
// function from within it's own Init function to set up the channels. It is
|
// function from within it's own Init function to set up the channels. It is
|
||||||
// otherwise not expected for you to call this function directly.
|
// otherwise not expected for you to call this function directly.
|
||||||
func (adapter *Adapter) Init(config *config.NodeState, log *log.Logger, send chan<- []byte, recv <-chan []byte, reject <-chan RejectedPacket) {
|
func (adapter *Adapter) Init(config *config.NodeState, log *log.Logger, send chan<- []byte, recv <-chan []byte, reject <-chan RejectedPacket) {
|
||||||
log.Traceln("Adapter setup - given channels:", send, recv)
|
|
||||||
adapter.Send = send
|
adapter.Send = send
|
||||||
adapter.Recv = recv
|
adapter.Recv = recv
|
||||||
adapter.Reject = reject
|
adapter.Reject = reject
|
||||||
|
@ -168,10 +168,15 @@ func BuildVersion() string {
|
|||||||
|
|
||||||
// SetRouterAdapter instructs Yggdrasil to use the given adapter when starting
|
// SetRouterAdapter instructs Yggdrasil to use the given adapter when starting
|
||||||
// the router. The adapter must implement the standard
|
// the router. The adapter must implement the standard
|
||||||
// adapter.AdapterImplementation interface and should extend the adapter.Adapter
|
// adapter.adapterImplementation interface and should extend the adapter.Adapter
|
||||||
// struct.
|
// struct.
|
||||||
func (c *Core) SetRouterAdapter(adapter AdapterImplementation) {
|
func (c *Core) SetRouterAdapter(adapter interface{}) {
|
||||||
c.router.adapter = adapter
|
// We do this because adapterImplementation is not a valid type for the
|
||||||
|
// gomobile bindings so we just ask for a generic interface and try to cast it
|
||||||
|
// to adapterImplementation instead
|
||||||
|
if a, ok := adapter.(adapterImplementation); ok {
|
||||||
|
c.router.adapter = a
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts up Yggdrasil using the provided config.NodeConfig, and outputs
|
// Start starts up Yggdrasil using the provided config.NodeConfig, and outputs
|
||||||
|
@ -23,7 +23,6 @@ type link struct {
|
|||||||
reconfigure chan chan error
|
reconfigure chan chan error
|
||||||
mutex sync.RWMutex // protects interfaces below
|
mutex sync.RWMutex // protects interfaces below
|
||||||
interfaces map[linkInfo]*linkInterface
|
interfaces map[linkInfo]*linkInterface
|
||||||
awdl awdl // AWDL interface support
|
|
||||||
tcp tcp // TCP interface support
|
tcp tcp // TCP interface support
|
||||||
// TODO timeout (to remove from switch), read from config.ReadTimeout
|
// TODO timeout (to remove from switch), read from config.ReadTimeout
|
||||||
}
|
}
|
||||||
@ -68,26 +67,15 @@ func (l *link) init(c *Core) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := l.awdl.init(l); err != nil {
|
|
||||||
c.log.Errorln("Failed to start AWDL interface")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
e := <-l.reconfigure
|
e := <-l.reconfigure
|
||||||
tcpresponse := make(chan error)
|
tcpresponse := make(chan error)
|
||||||
awdlresponse := make(chan error)
|
|
||||||
l.tcp.reconfigure <- tcpresponse
|
l.tcp.reconfigure <- tcpresponse
|
||||||
if err := <-tcpresponse; err != nil {
|
if err := <-tcpresponse; err != nil {
|
||||||
e <- err
|
e <- err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
l.awdl.reconfigure <- awdlresponse
|
|
||||||
if err := <-awdlresponse; err != nil {
|
|
||||||
e <- err
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
e <- nil
|
e <- nil
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -52,7 +52,7 @@ func (c *Core) StartAutoconfigure() error {
|
|||||||
if hostname, err := os.Hostname(); err == nil {
|
if hostname, err := os.Hostname(); err == nil {
|
||||||
nc.NodeInfo = map[string]interface{}{"name": hostname}
|
nc.NodeInfo = map[string]interface{}{"name": hostname}
|
||||||
}
|
}
|
||||||
if err := c.Start(nc, logger); err != nil {
|
if _, err := c.Start(nc, logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
go c.addStaticPeers(nc)
|
go c.addStaticPeers(nc)
|
||||||
@ -73,7 +73,7 @@ func (c *Core) StartJSON(configjson []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
nc.IfName = "dummy"
|
nc.IfName = "dummy"
|
||||||
if err := c.Start(nc, logger); err != nil {
|
if _, err := c.Start(nc, logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
go c.addStaticPeers(nc)
|
go c.addStaticPeers(nc)
|
||||||
@ -93,12 +93,12 @@ func GenerateConfigJSON() []byte {
|
|||||||
|
|
||||||
// Gets the node's IPv6 address.
|
// Gets the node's IPv6 address.
|
||||||
func (c *Core) GetAddressString() string {
|
func (c *Core) GetAddressString() string {
|
||||||
return c.GetAddress().String()
|
return c.Address().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the node's IPv6 subnet in CIDR notation.
|
// Gets the node's IPv6 subnet in CIDR notation.
|
||||||
func (c *Core) GetSubnetString() string {
|
func (c *Core) GetSubnetString() string {
|
||||||
return c.GetSubnet().String()
|
return c.Subnet().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the node's public encryption key.
|
// Gets the node's public encryption key.
|
||||||
@ -115,7 +115,7 @@ func (c *Core) GetSigPubKeyString() string {
|
|||||||
// dummy adapter in place of real TUN - when this call returns a packet, you
|
// dummy adapter in place of real TUN - when this call returns a packet, you
|
||||||
// will probably want to give it to the OS to write to TUN.
|
// will probably want to give it to the OS to write to TUN.
|
||||||
func (c *Core) RouterRecvPacket() ([]byte, error) {
|
func (c *Core) RouterRecvPacket() ([]byte, error) {
|
||||||
packet := <-c.router.tun.Recv
|
packet := <-c.router.recv
|
||||||
return packet, nil
|
return packet, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +125,6 @@ func (c *Core) RouterRecvPacket() ([]byte, error) {
|
|||||||
// Yggdrasil.
|
// Yggdrasil.
|
||||||
func (c *Core) RouterSendPacket(buf []byte) error {
|
func (c *Core) RouterSendPacket(buf []byte) error {
|
||||||
packet := append(util.GetBytes(), buf[:]...)
|
packet := append(util.GetBytes(), buf[:]...)
|
||||||
c.router.tun.Send <- packet
|
c.router.send <- packet
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,7 @@ void Log(const char *text) {
|
|||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MobileLogger struct {
|
type MobileLogger struct {
|
||||||
@ -29,6 +26,7 @@ func (nsl MobileLogger) Write(p []byte) (n int, err error) {
|
|||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func (c *Core) AWDLCreateInterface(name, local, remote string, incoming bool) error {
|
func (c *Core) AWDLCreateInterface(name, local, remote string, incoming bool) error {
|
||||||
if intf, err := c.link.awdl.create(name, local, remote, incoming); err != nil || intf == nil {
|
if intf, err := c.link.awdl.create(name, local, remote, incoming); err != nil || intf == nil {
|
||||||
c.log.Println("c.link.awdl.create:", err)
|
c.log.Println("c.link.awdl.create:", err)
|
||||||
@ -60,3 +58,4 @@ func (c *Core) AWDLSendPacket(identity string, buf []byte) error {
|
|||||||
}
|
}
|
||||||
return errors.New("AWDLSendPacket identity not known: " + identity)
|
return errors.New("AWDLSendPacket identity not known: " + identity)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
@ -41,7 +41,7 @@ type router struct {
|
|||||||
in <-chan []byte // packets we received from the network, link to peer's "out"
|
in <-chan []byte // packets we received from the network, link to peer's "out"
|
||||||
out func([]byte) // packets we're sending to the network, link to peer's "in"
|
out func([]byte) // packets we're sending to the network, link to peer's "in"
|
||||||
toRecv chan router_recvPacket // packets to handle via recvPacket()
|
toRecv chan router_recvPacket // packets to handle via recvPacket()
|
||||||
adapter AdapterImplementation // TUN/TAP adapter
|
adapter adapterImplementation // TUN/TAP adapter
|
||||||
recv chan<- []byte // place where the adapter pulls received packets from
|
recv chan<- []byte // place where the adapter pulls received packets from
|
||||||
send <-chan []byte // place where the adapter puts outgoing packets
|
send <-chan []byte // place where the adapter puts outgoing packets
|
||||||
reject chan<- RejectedPacket // place where we send error packets back to adapter
|
reject chan<- RejectedPacket // place where we send error packets back to adapter
|
||||||
|
Loading…
x
Reference in New Issue
Block a user