5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-10 05:10:26 +00:00

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

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
}