implement node multicast timer
This commit is contained in:
parent
f75fa492a6
commit
339d588f99
1 changed files with 27 additions and 1 deletions
28
main.go
28
main.go
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/op/go-logging"
|
"github.com/op/go-logging"
|
||||||
"github.com/sevlyar/go-daemon"
|
"github.com/sevlyar/go-daemon"
|
||||||
|
|
@ -45,6 +46,8 @@ type NodeConfig struct {
|
||||||
Address string `xml:"address"`
|
Address string `xml:"address"`
|
||||||
} `xml:"neighbor"`
|
} `xml:"neighbor"`
|
||||||
|
|
||||||
|
Sync int `xml:"sync"`
|
||||||
|
|
||||||
RPCEndpoints []string `xml:"rpc"`
|
RPCEndpoints []string `xml:"rpc"`
|
||||||
|
|
||||||
Log LogConfig `xml:"log"`
|
Log LogConfig `xml:"log"`
|
||||||
|
|
@ -272,7 +275,29 @@ func nodeMain() {
|
||||||
// start node
|
// start node
|
||||||
node.Start()
|
node.Start()
|
||||||
|
|
||||||
// TODO: daemonize
|
// node state sync scheduled task
|
||||||
|
stopChan := make(chan struct{})
|
||||||
|
|
||||||
|
if config.Sync != 0 {
|
||||||
|
ticker := time.NewTicker(time.Duration(config.Sync) * time.Second)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
err := node.MulticastSync()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("MulticastSync err: %v", err)
|
||||||
|
}
|
||||||
|
case <-stopChan:
|
||||||
|
ticker.Stop()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
} else {
|
||||||
|
log.Info("sync interval is not set. Node will not sync with neighbors")
|
||||||
|
}
|
||||||
|
|
||||||
// register go channel to receive unix signals,
|
// register go channel to receive unix signals,
|
||||||
// while hogging main thread to read them and take action.
|
// while hogging main thread to read them and take action.
|
||||||
|
|
@ -293,6 +318,7 @@ signaling:
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop daemon
|
// stop daemon
|
||||||
|
close(stopChan)
|
||||||
node.Stop()
|
node.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue