8 "github.com/jinzhu/gorm"
9 log "github.com/sirupsen/logrus"
10 dbm "github.com/vapor/database/leveldb"
12 cfg "github.com/vapor/config"
13 "github.com/vapor/p2p"
14 "github.com/vapor/p2p/signlib"
15 "github.com/vapor/toolbar/precog/config"
16 "github.com/vapor/toolbar/precog/database/orm"
24 func NewMonitor(cfg *config.Config, db *gorm.DB) *monitor {
31 func (m *monitor) Run() {
32 m.updateBootstrapNodes()
34 ticker := time.NewTicker(time.Duration(m.cfg.CheckFreqSeconds) * time.Second)
35 for ; true; <-ticker.C {
41 // create or update: https://github.com/jinzhu/gorm/issues/1307
42 func (m *monitor) updateBootstrapNodes() {
43 for _, node := range m.cfg.Nodes {
45 PublicKey: node.PublicKey.String(),
51 if err := m.db.Where(&orm.Node{PublicKey: ormNode.PublicKey}).
56 }).FirstOrCreate(ormNode).Error; err != nil {
64 // implement logic first, and then refactor
65 // /home/gavin/work/go/src/github.com/vapor/
68 func (m *monitor) discovery() {
71 dirPath, err := ioutil.TempDir(".", "")
75 defer os.RemoveAll(dirPath)
80 mCfg.P2P.ListenAddress = "127.0.1.1:0"
81 swPrivKey, err := signlib.NewPrivKey()
86 testDB := dbm.NewDB("testdb", "leveldb", dirPath)
88 sw := p2p.MakeSwitch(mCfg, testDB, swPrivKey, initSwitchFunc)
93 func (m *monitor) monitorRountine() error {
94 // TODO: dail nodes, get lantency & best_height
95 // TODO: decide check_height("best best_height" - "confirmations")
96 // TODO: get blockhash by check_height, get latency
97 // TODO: update lantency, active_time and status