Skip to content

Commit

Permalink
dht:init wait group in the beginning
Browse files Browse the repository at this point in the history
  • Loading branch information
bysomeone authored and vipwzw committed Sep 12, 2023
1 parent 649f049 commit aba5e9f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions system/p2p/dht/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func New(mgr *p2p.Manager, subCfg []byte) p2p.IP2P {

func initP2P(p *P2P) *P2P {
//other init work
p.taskGroup = &sync.WaitGroup{}
p.ctx, p.cancel = context.WithCancel(context.Background())
priv := p.addrBook.GetPrivkey()
if priv == nil { //addrbook存储的peer key 为空
if p.p2pCfg.WaitPid { //p2p阻塞,直到创建钱包之后
Expand Down Expand Up @@ -169,7 +171,6 @@ func initP2P(p *P2P) *P2P {
p.discovery = InitDhtDiscovery(p.ctx, p.host, p.addrBook.AddrsInfo(), p.chainCfg, p.subCfg)
p.connManager = manage.NewConnManager(p.ctx, p.host, p.discovery.RoutingTable(), bandwidthTracker, p.subCfg)
p.peerInfoManager = manage.NewPeerInfoManager(p.ctx, p.host, p.client)
p.taskGroup = &sync.WaitGroup{}

p.db = newDB("", p.p2pCfg.Driver, filepath.Dir(p.p2pCfg.DbPath), p.subCfg.DHTDataCache)
return p
Expand All @@ -179,7 +180,6 @@ func initP2P(p *P2P) *P2P {
func (p *P2P) StartP2P() {
if atomic.LoadInt32(&p.restart) == 1 {
log.Info("RestartP2P...")
p.ctx, p.cancel = context.WithCancel(context.Background())
initP2P(p) //重新创建host
}
atomic.StoreInt32(&p.restart, 0)
Expand Down

0 comments on commit aba5e9f

Please sign in to comment.