Add Android support, add addStaticPeers

This commit is contained in:
Neil Alexander 2019-01-10 10:44:44 +00:00
parent 38209ee9b9
commit a371e34a18
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
2 changed files with 36 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"log" "log"
"os" "os"
"regexp" "regexp"
"time"
hjson "github.com/hjson/hjson-go" hjson "github.com/hjson/hjson-go"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
@ -23,6 +24,25 @@ import (
// that in the case of iOS we handle reading/writing to/from TUN in Swift // that in the case of iOS we handle reading/writing to/from TUN in Swift
// therefore we use the "dummy" TUN interface instead. // 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 { func (c *Core) StartAutoconfigure() error {
mobilelog := MobileLogger{} mobilelog := MobileLogger{}
logger := log.New(mobilelog, "", 0) logger := log.New(mobilelog, "", 0)
@ -40,6 +60,7 @@ func (c *Core) StartAutoconfigure() error {
if err := c.Start(nc, logger); err != nil { if err := c.Start(nc, logger); err != nil {
return err return err
} }
go c.addStaticPeers(nc)
return nil return nil
} }
@ -55,7 +76,9 @@ func (c *Core) StartJSON(configjson []byte) error {
return err return err
} }
nc.IfName = "dummy" nc.IfName = "dummy"
//c.log.Println(nc.MulticastInterfaces)
for _, ll := range nc.MulticastInterfaces { for _, ll := range nc.MulticastInterfaces {
//c.log.Println("Processing MC", ll)
ifceExpr, err := regexp.Compile(ll) ifceExpr, err := regexp.Compile(ll)
if err != nil { if err != nil {
panic(err) panic(err)
@ -65,6 +88,7 @@ func (c *Core) StartJSON(configjson []byte) error {
if err := c.Start(nc, logger); err != nil { if err := c.Start(nc, logger); err != nil {
return err return err
} }
go c.addStaticPeers(nc)
return nil return nil
} }

View File

@ -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
}