mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-27 21:55:07 +03:00
Merge branch 'develop' into future
This commit is contained in:
commit
6ab0639b82
10 changed files with 94 additions and 8 deletions
|
@ -37,7 +37,7 @@ if [ $IOS ]; then
|
|||
echo "Building framework for iOS"
|
||||
go get golang.org/x/mobile/bind
|
||||
gomobile bind \
|
||||
-target ios -tags mobile -o Yggdrasil.xcframework \
|
||||
-target ios,macos -tags mobile -o Yggdrasil.xcframework \
|
||||
-ldflags="$LDFLAGS $STRIP" -gcflags="$GCFLAGS" \
|
||||
./contrib/mobile ./src/config;
|
||||
fi
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"net"
|
||||
"regexp"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/gologme/log"
|
||||
|
||||
|
@ -13,6 +14,7 @@ import (
|
|||
"github.com/yggdrasil-network/yggdrasil-go/src/core"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/ipv6rwc"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/tun"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/version"
|
||||
|
||||
_ "golang.org/x/mobile/bind"
|
||||
|
@ -28,7 +30,9 @@ type Yggdrasil struct {
|
|||
iprwc *ipv6rwc.ReadWriteCloser
|
||||
config *config.NodeConfig
|
||||
multicast *multicast.Multicast
|
||||
tun *tun.TunAdapter // optional
|
||||
log MobileLogger
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
// StartAutoconfigure starts a node with a randomly generated config
|
||||
|
@ -39,6 +43,8 @@ func (m *Yggdrasil) StartAutoconfigure() error {
|
|||
// StartJSON starts a node with the given JSON config. You can get JSON config
|
||||
// (rather than HJSON) by using the GenerateConfigJSON() function
|
||||
func (m *Yggdrasil) StartJSON(configjson []byte) error {
|
||||
debug.SetMemoryLimit(1024 * 1024 * 40)
|
||||
|
||||
logger := log.New(m.log, "", 0)
|
||||
logger.EnableLevel("error")
|
||||
logger.EnableLevel("warn")
|
||||
|
@ -88,9 +94,9 @@ func (m *Yggdrasil) StartJSON(configjson []byte) error {
|
|||
Priority: uint8(intf.Priority),
|
||||
})
|
||||
}
|
||||
m.multicast, err = multicast.New(m.core, logger, options...)
|
||||
m.multicast, err = multicast.New(m.core, m.logger, options...)
|
||||
if err != nil {
|
||||
logger.Errorln("An error occurred starting multicast:", err)
|
||||
m.logger.Errorln("An error occurred starting multicast:", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,6 +159,11 @@ func (m *Yggdrasil) Stop() error {
|
|||
if err := m.multicast.Stop(); err != nil {
|
||||
return err
|
||||
}
|
||||
if m.tun != nil {
|
||||
if err := m.tun.Stop(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
m.core.Stop()
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ void Log(const char *text) {
|
|||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/tun"
|
||||
)
|
||||
|
||||
type MobileLogger struct {
|
||||
|
@ -26,3 +28,13 @@ func (nsl MobileLogger) Write(p []byte) (n int, err error) {
|
|||
C.Log(cstr)
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func (m *Yggdrasil) TakeOverTUN(fd int32) error {
|
||||
options := []tun.SetupOption{
|
||||
tun.FileDescriptor(fd),
|
||||
tun.InterfaceMTU(m.iprwc.MTU()),
|
||||
}
|
||||
var err error
|
||||
m.tun, err = tun.New(m.iprwc, m.logger, options...)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue