import (
"fmt"
- "io/ioutil"
"os"
"os/user"
"strings"
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)
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),
}
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))
}
m.dialCh <- struct{}{}
- // var discvWg sync.WaitGroup
- go m.discoveryRoutine( /*&discvWg*/ )
- // go m.collectDiscoveredNodes(&discvWg)
+ go m.discoveryRoutine()
go m.connectNodesRoutine()
go m.checkStatusRoutine()
}
peers.RemovePeer(p.ID())
}
log.Info("Disonnect all peers.")
+
m.Unlock()
m.dialCh <- struct{}{}
}