mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 14:45:07 +03:00
Add some simple functions for Swift bindings (iOS)
This commit is contained in:
parent
d08a3c6643
commit
53aeca8fa2
4 changed files with 113 additions and 64 deletions
|
@ -1,17 +1,8 @@
|
|||
package yggdrasil
|
||||
|
||||
// Defines the minimum required functions for an adapter type.
|
||||
type AdapterInterface interface {
|
||||
init(core *Core, send chan<- []byte, recv <-chan []byte)
|
||||
read() error
|
||||
write() error
|
||||
close() error
|
||||
}
|
||||
|
||||
// Defines the minimum required struct members for an adapter type (this is
|
||||
// now the base type for tunAdapter in tun.go)
|
||||
type Adapter struct {
|
||||
AdapterInterface
|
||||
core *Core
|
||||
send chan<- []byte
|
||||
recv <-chan []byte
|
||||
|
|
51
src/yggdrasil/ios.go
Normal file
51
src/yggdrasil/ios.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
// +build mobile
|
||||
|
||||
package yggdrasil
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/config"
|
||||
)
|
||||
|
||||
// This file is meant to "plug the gap" for Gomobile support, as Gomobile
|
||||
// will not create headers for Swift/Obj-C if they have complex (read: non-
|
||||
// native) types. Therefore for iOS we will expose some nice simple functions
|
||||
// to do what we need to do.
|
||||
|
||||
func (c *Core) StartAutoconfigure() error {
|
||||
logger := log.New(os.Stdout, "", 0)
|
||||
//logger.Println("Created logger")
|
||||
//c := Core{}
|
||||
//logger.Println("Created Core")
|
||||
nc := config.GenerateConfig(true)
|
||||
//logger.Println("Generated config")
|
||||
nc.IfName = "none"
|
||||
nc.AdminListen = "tcp://[::]:9001"
|
||||
nc.Peers = []string{}
|
||||
//logger.Println("Set some config options")
|
||||
ifceExpr, err := regexp.Compile(".*")
|
||||
if err == nil {
|
||||
c.ifceExpr = append(c.ifceExpr, ifceExpr)
|
||||
}
|
||||
//logger.Println("Added multicast interface")
|
||||
if err := c.Start(nc, logger); err != nil {
|
||||
return err
|
||||
}
|
||||
//logger.Println("Started")
|
||||
address := c.GetAddress()
|
||||
subnet := c.GetSubnet()
|
||||
logger.Printf("Your IPv6 address is %s", address.String())
|
||||
logger.Printf("Your IPv6 subnet is %s", subnet.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Core) GetAddressString() string {
|
||||
return c.GetAddress().String()
|
||||
}
|
||||
|
||||
func (c *Core) GetSubetString() string {
|
||||
return c.GetSubnet().String()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue