mirror of
https://github.com/yggdrasil-network/yggdrasil-go
synced 2024-11-09 23:20:26 +03: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()
|
||||
go func() {
|
||||
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() {
|
||||
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 {
|
||||
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
|
||||
// mode then additional ethernet encapsulation is added for the benefit of the
|
||||
// host operating system.
|
||||
func (tun *TunAdapter) Write() error {
|
||||
func (tun *TunAdapter) write() error {
|
||||
for {
|
||||
select {
|
||||
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
|
||||
// processed and stripped if necessary. If an ICMPv6 packet is found, then
|
||||
// the relevant helper functions in icmpv6.go are called.
|
||||
func (tun *TunAdapter) Read() error {
|
||||
func (tun *TunAdapter) read() error {
|
||||
mtu := tun.mtu
|
||||
if tun.iface.IsTAP() {
|
||||
mtu += tun_ETHER_HEADER_LENGTH
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
// you should extend the adapter struct with this one and should call the
|
||||
// Adapter.Init() function when initialising.
|
||||
type Adapter struct {
|
||||
AdapterImplementation
|
||||
adapterImplementation
|
||||
Core *Core
|
||||
Send chan<- []byte
|
||||
Recv <-chan []byte
|
||||
@ -20,15 +20,14 @@ type Adapter struct {
|
||||
}
|
||||
|
||||
// Defines the minimum required functions for an adapter type. Note that the
|
||||
// implementation of Init() should call Adapter.Init().
|
||||
type AdapterImplementation interface {
|
||||
// implementation of Init() should call Adapter.Init(). This is not exported
|
||||
// because doing so breaks the gomobile bindings for iOS/Android.
|
||||
type adapterImplementation interface {
|
||||
Init(*config.NodeState, *log.Logger, chan<- []byte, <-chan []byte, <-chan RejectedPacket)
|
||||
Name() string
|
||||
MTU() int
|
||||
IsTAP() bool
|
||||
Start(address.Address, address.Subnet) error
|
||||
Read() error
|
||||
Write() 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
|
||||
// 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) {
|
||||
log.Traceln("Adapter setup - given channels:", send, recv)
|
||||
adapter.Send = send
|
||||
adapter.Recv = recv
|
||||
adapter.Reject = reject
|
||||
|
@ -168,10 +168,15 @@ func BuildVersion() string {
|
||||
|
||||
// SetRouterAdapter instructs Yggdrasil to use the given adapter when starting
|
||||
// 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.
|
||||
func (c *Core) SetRouterAdapter(adapter AdapterImplementation) {
|
||||
c.router.adapter = adapter
|
||||
func (c *Core) SetRouterAdapter(adapter interface{}) {
|
||||
// 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
|
||||
|
@ -23,8 +23,7 @@ type link struct {
|
||||
reconfigure chan chan error
|
||||
mutex sync.RWMutex // protects interfaces below
|
||||
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
|
||||
}
|
||||
|
||||
@ -68,26 +67,15 @@ func (l *link) init(c *Core) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := l.awdl.init(l); err != nil {
|
||||
c.log.Errorln("Failed to start AWDL interface")
|
||||
return err
|
||||
}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
e := <-l.reconfigure
|
||||
tcpresponse := make(chan error)
|
||||
awdlresponse := make(chan error)
|
||||
l.tcp.reconfigure <- tcpresponse
|
||||
if err := <-tcpresponse; err != nil {
|
||||
e <- err
|
||||
continue
|
||||
}
|
||||
l.awdl.reconfigure <- awdlresponse
|
||||
if err := <-awdlresponse; err != nil {
|
||||
e <- err
|
||||
continue
|
||||
}
|
||||
e <- nil
|
||||
}
|
||||
}()
|
||||
|
@ -52,7 +52,7 @@ func (c *Core) StartAutoconfigure() error {
|
||||
if hostname, err := os.Hostname(); err == nil {
|
||||
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
|
||||
}
|
||||
go c.addStaticPeers(nc)
|
||||
@ -73,7 +73,7 @@ func (c *Core) StartJSON(configjson []byte) error {
|
||||
return err
|
||||
}
|
||||
nc.IfName = "dummy"
|
||||
if err := c.Start(nc, logger); err != nil {
|
||||
if _, err := c.Start(nc, logger); err != nil {
|
||||
return err
|
||||
}
|
||||
go c.addStaticPeers(nc)
|
||||
@ -93,12 +93,12 @@ func GenerateConfigJSON() []byte {
|
||||
|
||||
// Gets the node's IPv6 address.
|
||||
func (c *Core) GetAddressString() string {
|
||||
return c.GetAddress().String()
|
||||
return c.Address().String()
|
||||
}
|
||||
|
||||
// Gets the node's IPv6 subnet in CIDR notation.
|
||||
func (c *Core) GetSubnetString() string {
|
||||
return c.GetSubnet().String()
|
||||
return c.Subnet().String()
|
||||
}
|
||||
|
||||
// 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
|
||||
// will probably want to give it to the OS to write to TUN.
|
||||
func (c *Core) RouterRecvPacket() ([]byte, error) {
|
||||
packet := <-c.router.tun.Recv
|
||||
packet := <-c.router.recv
|
||||
return packet, nil
|
||||
}
|
||||
|
||||
@ -125,6 +125,6 @@ func (c *Core) RouterRecvPacket() ([]byte, error) {
|
||||
// Yggdrasil.
|
||||
func (c *Core) RouterSendPacket(buf []byte) error {
|
||||
packet := append(util.GetBytes(), buf[:]...)
|
||||
c.router.tun.Send <- packet
|
||||
c.router.send <- packet
|
||||
return nil
|
||||
}
|
||||
|
@ -13,10 +13,7 @@ void Log(const char *text) {
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/util"
|
||||
)
|
||||
|
||||
type MobileLogger struct {
|
||||
@ -29,6 +26,7 @@ func (nsl MobileLogger) Write(p []byte) (n int, err error) {
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
/*
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
*/
|
||||
|
@ -41,7 +41,7 @@ type router struct {
|
||||
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"
|
||||
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
|
||||
send <-chan []byte // place where the adapter puts outgoing packets
|
||||
reject chan<- RejectedPacket // place where we send error packets back to adapter
|
||||
|
Loading…
Reference in New Issue
Block a user