From a371e34a187cc3642a2bdaa7ff150f443b5e55dc Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 10 Jan 2019 10:44:44 +0000 Subject: [PATCH] Add Android support, add addStaticPeers --- src/yggdrasil/mobile.go | 24 ++++++++++++++++++++++++ src/yggdrasil/mobile_android.go | 12 ++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/yggdrasil/mobile_android.go diff --git a/src/yggdrasil/mobile.go b/src/yggdrasil/mobile.go index 300d132a..5cd15ece 100644 --- a/src/yggdrasil/mobile.go +++ b/src/yggdrasil/mobile.go @@ -9,6 +9,7 @@ import ( "log" "os" "regexp" + "time" hjson "github.com/hjson/hjson-go" "github.com/mitchellh/mapstructure" @@ -23,6 +24,25 @@ import ( // that in the case of iOS we handle reading/writing to/from TUN in Swift // therefore we use the "dummy" TUN interface instead. +func (c *Core) addStaticPeers(cfg *config.NodeConfig) { + if len(cfg.Peers) == 0 && len(cfg.InterfacePeers) == 0 { + return + } + for { + for _, peer := range cfg.Peers { + c.AddPeer(peer, "") + time.Sleep(time.Second) + } + for intf, intfpeers := range cfg.InterfacePeers { + for _, peer := range intfpeers { + c.AddPeer(peer, intf) + time.Sleep(time.Second) + } + } + time.Sleep(time.Minute) + } +} + func (c *Core) StartAutoconfigure() error { mobilelog := MobileLogger{} logger := log.New(mobilelog, "", 0) @@ -40,6 +60,7 @@ func (c *Core) StartAutoconfigure() error { if err := c.Start(nc, logger); err != nil { return err } + go c.addStaticPeers(nc) return nil } @@ -55,7 +76,9 @@ func (c *Core) StartJSON(configjson []byte) error { return err } nc.IfName = "dummy" + //c.log.Println(nc.MulticastInterfaces) for _, ll := range nc.MulticastInterfaces { + //c.log.Println("Processing MC", ll) ifceExpr, err := regexp.Compile(ll) if err != nil { panic(err) @@ -65,6 +88,7 @@ func (c *Core) StartJSON(configjson []byte) error { if err := c.Start(nc, logger); err != nil { return err } + go c.addStaticPeers(nc) return nil } diff --git a/src/yggdrasil/mobile_android.go b/src/yggdrasil/mobile_android.go new file mode 100644 index 00000000..24764840 --- /dev/null +++ b/src/yggdrasil/mobile_android.go @@ -0,0 +1,12 @@ +// +build android + +package yggdrasil + +import "log" + +type MobileLogger struct{} + +func (nsl MobileLogger) Write(p []byte) (n int, err error) { + log.Println(string(p)) + return len(p), nil +}