mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-12-25 01:07:49 +00:00
Add Android support, add addStaticPeers
This commit is contained in:
parent
38209ee9b9
commit
a371e34a18
@ -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
|
||||
}
|
||||
|
||||
|
12
src/yggdrasil/mobile_android.go
Normal file
12
src/yggdrasil/mobile_android.go
Normal 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user