mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-27 12:05:23 +00:00
move periodic switch maintenance into the router instead of its own goroutine
This commit is contained in:
parent
5dc0cb5544
commit
3b783fbf97
@ -103,11 +103,6 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.switchTable.start(); err != nil {
|
|
||||||
c.log.Println("Failed to start switch table ticker")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.admin.start(); err != nil {
|
if err := c.admin.start(); err != nil {
|
||||||
c.log.Println("Failed to start admin socket")
|
c.log.Println("Failed to start admin socket")
|
||||||
return err
|
return err
|
||||||
|
@ -36,7 +36,6 @@ func (c *Core) Init() {
|
|||||||
spub, spriv := newSigKeys()
|
spub, spriv := newSigKeys()
|
||||||
c.init(bpub, bpriv, spub, spriv)
|
c.init(bpub, bpriv, spub, spriv)
|
||||||
c.router.start()
|
c.router.start()
|
||||||
c.switchTable.start()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -310,9 +309,6 @@ func (c *Core) DEBUG_init(bpub []byte,
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.switchTable.start(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -91,6 +91,7 @@ func (r *router) mainLoop() {
|
|||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
{
|
{
|
||||||
// Any periodic maintenance stuff goes here
|
// Any periodic maintenance stuff goes here
|
||||||
|
r.core.switchTable.doMaintenance()
|
||||||
r.core.dht.doMaintenance()
|
r.core.dht.doMaintenance()
|
||||||
util_getBytes() // To slowly drain things
|
util_getBytes() // To slowly drain things
|
||||||
}
|
}
|
||||||
|
@ -170,26 +170,13 @@ func (t *switchTable) init(core *Core, key sigPubKey) {
|
|||||||
t.drop = make(map[sigPubKey]int64)
|
t.drop = make(map[sigPubKey]int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *switchTable) start() error {
|
|
||||||
doTicker := func() {
|
|
||||||
ticker := time.NewTicker(time.Second)
|
|
||||||
defer ticker.Stop()
|
|
||||||
for {
|
|
||||||
<-ticker.C
|
|
||||||
t.Tick()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
go doTicker()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *switchTable) getLocator() switchLocator {
|
func (t *switchTable) getLocator() switchLocator {
|
||||||
t.mutex.RLock()
|
t.mutex.RLock()
|
||||||
defer t.mutex.RUnlock()
|
defer t.mutex.RUnlock()
|
||||||
return t.data.locator.clone()
|
return t.data.locator.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *switchTable) Tick() {
|
func (t *switchTable) doMaintenance() {
|
||||||
// Periodic maintenance work to keep things internally consistent
|
// Periodic maintenance work to keep things internally consistent
|
||||||
t.mutex.Lock() // Write lock
|
t.mutex.Lock() // Write lock
|
||||||
defer t.mutex.Unlock() // Release lock when we're done
|
defer t.mutex.Unlock() // Release lock when we're done
|
||||||
|
Loading…
Reference in New Issue
Block a user