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 // conn "github.com/vapor/p2p/connection"
15 "github.com/vapor/p2p/signlib"
16 "github.com/vapor/toolbar/precog/config"
17 "github.com/vapor/toolbar/precog/database/orm"
25 func NewMonitor(cfg *config.Config, db *gorm.DB) *monitor {
32 func (m *monitor) Run() {
33 m.updateBootstrapNodes()
35 ticker := time.NewTicker(time.Duration(m.cfg.CheckFreqSeconds) * time.Second)
36 for ; true; <-ticker.C {
42 // create or update: https://github.com/jinzhu/gorm/issues/1307
43 func (m *monitor) updateBootstrapNodes() {
44 for _, node := range m.cfg.Nodes {
46 PublicKey: node.PublicKey.String(),
52 if err := m.db.Where(&orm.Node{PublicKey: ormNode.PublicKey}).
57 }).FirstOrCreate(ormNode).Error; err != nil {
65 // implement logic first, and then refactor
66 // /home/gavin/work/go/src/github.com/vapor/
69 func (m *monitor) discovery() {
71 // TODO: 包一下? common cfg 之类的?
72 mCfg := cfg.DefaultConfig()
74 dirPath, err := ioutil.TempDir(".", "")
79 defer os.RemoveAll(dirPath)
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