2017-12-29 04:16:20 +00:00
|
|
|
package yggdrasil
|
|
|
|
|
|
|
|
import "io/ioutil"
|
|
|
|
import "log"
|
2018-01-09 08:08:54 +00:00
|
|
|
import "regexp"
|
2017-12-29 04:16:20 +00:00
|
|
|
|
|
|
|
type Core struct {
|
2018-01-04 22:37:51 +00:00
|
|
|
// This is the main data structure that holds everything else for a node
|
|
|
|
boxPub boxPubKey
|
|
|
|
boxPriv boxPrivKey
|
|
|
|
sigPub sigPubKey
|
|
|
|
sigPriv sigPrivKey
|
|
|
|
switchTable switchTable
|
|
|
|
peers peers
|
|
|
|
sigs sigManager
|
|
|
|
sessions sessions
|
|
|
|
router router
|
|
|
|
dht dht
|
|
|
|
tun tunDevice
|
2018-01-21 00:17:15 +00:00
|
|
|
admin admin
|
2018-01-04 22:37:51 +00:00
|
|
|
searches searches
|
|
|
|
tcp *tcpInterface
|
|
|
|
udp *udpInterface
|
|
|
|
log *log.Logger
|
2018-01-09 08:08:54 +00:00
|
|
|
ifceExpr *regexp.Regexp // the zone of link-local IPv6 peers must match this
|
2017-12-29 04:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Core) Init() {
|
2018-01-04 22:37:51 +00:00
|
|
|
// Only called by the simulator, to set up nodes with random keys
|
|
|
|
bpub, bpriv := newBoxKeys()
|
|
|
|
spub, spriv := newSigKeys()
|
|
|
|
c.init(bpub, bpriv, spub, spriv)
|
2017-12-29 04:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Core) init(bpub *boxPubKey,
|
2018-01-04 22:37:51 +00:00
|
|
|
bpriv *boxPrivKey,
|
|
|
|
spub *sigPubKey,
|
|
|
|
spriv *sigPrivKey) {
|
|
|
|
// TODO separate init and start functions
|
|
|
|
// Init sets up structs
|
|
|
|
// Start launches goroutines that depend on structs being set up
|
2018-01-26 23:30:51 +00:00
|
|
|
// This is pretty much required to completely avoid race conditions
|
2018-01-04 22:37:51 +00:00
|
|
|
util_initByteStore()
|
|
|
|
c.log = log.New(ioutil.Discard, "", 0)
|
|
|
|
c.boxPub, c.boxPriv = *bpub, *bpriv
|
|
|
|
c.sigPub, c.sigPriv = *spub, *spriv
|
2018-05-07 00:48:26 +00:00
|
|
|
c.admin.core = c
|
2018-01-04 22:37:51 +00:00
|
|
|
c.sigs.init()
|
|
|
|
c.searches.init(c)
|
|
|
|
c.dht.init(c)
|
|
|
|
c.sessions.init(c)
|
|
|
|
c.peers.init(c)
|
|
|
|
c.router.init(c)
|
|
|
|
c.switchTable.init(c, c.sigPub) // TODO move before peers? before router?
|
|
|
|
c.tun.init(c)
|
2017-12-29 04:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Core) GetNodeID() *NodeID {
|
2018-01-04 22:37:51 +00:00
|
|
|
return getNodeID(&c.boxPub)
|
2017-12-29 04:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Core) GetTreeID() *TreeID {
|
2018-01-04 22:37:51 +00:00
|
|
|
return getTreeID(&c.sigPub)
|
2017-12-29 04:16:20 +00:00
|
|
|
}
|