diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index 5bf9d3fa..378f951c 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -213,6 +213,9 @@ func (a *admin) init(c *Core, listenaddr string) { }, errors.New("Failed to remove allowed box pub key") } }) +} + +func (a *admin) start() { go a.listen() } diff --git a/src/yggdrasil/core.go b/src/yggdrasil/core.go index 7b077946..96397cf3 100644 --- a/src/yggdrasil/core.go +++ b/src/yggdrasil/core.go @@ -3,6 +3,8 @@ package yggdrasil import "io/ioutil" import "log" import "regexp" +import "net" +import "yggdrasil/config" type Core struct { // This is the main data structure that holds everything else for a node @@ -33,6 +35,29 @@ func (c *Core) Init() { c.init(bpub, bpriv, spub, spriv) } +func (c *Core) Run(nc *config.NodeConfig) { + var boxPub boxPubKey + var boxPriv boxPrivKey + var sigPub sigPubKey + var sigPriv sigPrivKey + copy(boxPub[:], nc.EncryptionPublicKey) + copy(boxPriv[:], nc.EncryptionPrivateKey) + copy(sigPub[:], nc.SigningPublicKey) + copy(sigPriv[:], nc.SigningPrivateKey) + + c.init(&boxPub, &boxPriv, &sigPub, &sigPriv) + + c.udp.init(c, nc.Listen) + c.tcp.init(c, nc.Listen) + c.admin.init(c, nc.AdminListen) + + c.multicast.start() + c.router.start() + c.switchTable.start() + c.tun.setup(nc.IfName, nc.IfTAPMode, net.IP(c.router.addr[:]).String(), nc.IfMTU) + c.admin.start() +} + func (c *Core) init(bpub *boxPubKey, bpriv *boxPrivKey, spub *sigPubKey, diff --git a/src/yggdrasil/router.go b/src/yggdrasil/router.go index ad11d6e7..3b90258b 100644 --- a/src/yggdrasil/router.go +++ b/src/yggdrasil/router.go @@ -64,6 +64,10 @@ func (r *router) init(core *Core) { r.core.tun.send = send r.reset = make(chan struct{}, 1) r.admin = make(chan func()) + // go r.mainLoop() +} + +func (r *router) start() { go r.mainLoop() } diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index a005b106..5f6c2b9b 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -167,6 +167,9 @@ func (t *switchTable) init(core *Core, key sigPubKey) { t.updater.Store(&sync.Once{}) t.table.Store(lookupTable{}) t.drop = make(map[sigPubKey]int64) +} + +func (t *switchTable) start() { doTicker := func() { ticker := time.NewTicker(time.Second) defer ticker.Stop()