OSDN Git Service

clean
[bytom/vapor.git] / toolbar / precog / monitor / monitor.go
index fab14f1..f9ae5f0 100644 (file)
@@ -2,7 +2,6 @@ package monitor
 
 import (
        "fmt"
-       "io/ioutil"
        "os"
        "os/user"
        "strings"
@@ -35,18 +34,13 @@ type monitor struct {
        privKey chainkd.XPrv
        chain   *mock.Chain
        txPool  *mock.Mempool
-       discvCh chan *dht.Node
-       // nodeMap maps a node's public key to the node itself
-       nodeMap       map[string]*dht.Node
+       // discvMap maps a node's public key to the node itself
+       discvMap      map[string]*dht.Node
        dialCh        chan struct{}
        checkStatusCh chan struct{}
 }
 
-// TODO: set myself as SPV?
 func NewMonitor(cfg *config.Config, db *gorm.DB) *monitor {
-       //TODO: for test
-       cfg.CheckFreqSeconds = 15
-
        dbPath, err := makePath()
        if err != nil {
                log.Fatal(err)
@@ -77,8 +71,7 @@ func NewMonitor(cfg *config.Config, db *gorm.DB) *monitor {
                privKey:       privKey.(chainkd.XPrv),
                chain:         chain,
                txPool:        txPool,
-               discvCh:       make(chan *dht.Node),
-               nodeMap:       make(map[string]*dht.Node),
+               discvMap:      make(map[string]*dht.Node),
                dialCh:        make(chan struct{}, 1),
                checkStatusCh: make(chan struct{}, 1),
        }
@@ -95,17 +88,10 @@ func makePath() (string, error) {
                return "", err
        }
 
-       tmpDir, err := ioutil.TempDir(dataPath, "")
-       if err != nil {
-               return "", err
-       }
-
-       return tmpDir, nil
+       return dataPath, nil
 }
 
 func (m *monitor) Run() {
-       defer os.RemoveAll(m.nodeCfg.DBPath)
-
        var seeds []string
        for _, node := range m.cfg.Nodes {
                seeds = append(seeds, fmt.Sprintf("%s:%d", node.Host, node.Port))
@@ -119,9 +105,7 @@ func (m *monitor) Run() {
        }
 
        m.dialCh <- struct{}{}
-       // var discvWg sync.WaitGroup
-       go m.discoveryRoutine( /*&discvWg*/ )
-       // go m.collectDiscoveredNodes(&discvWg)
+       go m.discoveryRoutine()
        go m.connectNodesRoutine()
        go m.checkStatusRoutine()
 }
@@ -210,6 +194,7 @@ func (m *monitor) checkStatusRoutine() {
                        peers.RemovePeer(p.ID())
                }
                log.Info("Disonnect all peers.")
+
                m.Unlock()
                m.dialCh <- struct{}{}
        }