mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
swarm/pss: fxing race condition
This commit is contained in:
parent
4aeeecfded
commit
1ca00afa2d
1 changed files with 13 additions and 8 deletions
|
|
@ -340,6 +340,7 @@ func (p *Pss) Register(topic *Topic, hndlr *handler) func() {
|
|||
}
|
||||
return func() { p.deregister(topic, hndlr) }
|
||||
}
|
||||
|
||||
func (p *Pss) deregister(topic *Topic, hndlr *handler) {
|
||||
p.handlersMu.Lock()
|
||||
defer p.handlersMu.Unlock()
|
||||
|
|
@ -362,13 +363,6 @@ func (p *Pss) deregister(topic *Topic, hndlr *handler) {
|
|||
delete(handlers, hndlr)
|
||||
}
|
||||
|
||||
// get all registered handlers for respective topics
|
||||
func (p *Pss) getHandlers(topic Topic) map[*handler]bool {
|
||||
p.handlersMu.RLock()
|
||||
defer p.handlersMu.RUnlock()
|
||||
return p.handlers[topic]
|
||||
}
|
||||
|
||||
// Filters incoming messages for processing or forwarding.
|
||||
// Check if address partially matches
|
||||
// If yes, it CAN be for us, and we process it
|
||||
|
|
@ -427,7 +421,6 @@ func (p *Pss) handlePssMsg(ctx context.Context, msg interface{}) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// Entry point to processing a message for which the current node can be the intended recipient.
|
||||
|
|
@ -472,7 +465,19 @@ func (p *Pss) process(pssmsg *PssMsg, raw bool, prox bool) error {
|
|||
p.executeHandlers(psstopic, payload, from, raw, prox, asymmetric, keyid)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// copy all registered handlers for respective topic in order to avoid deadlock
|
||||
func (p *Pss) getHandlers(topic Topic) map[*handler]bool {
|
||||
p.handlersMu.RLock()
|
||||
defer p.handlersMu.RUnlock()
|
||||
|
||||
ret := make(map[*handler]bool)
|
||||
h := p.handlers[topic]
|
||||
for k, v := range h {
|
||||
ret[k] = v
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p *Pss) executeHandlers(topic Topic, payload []byte, from PssAddress, raw bool, prox bool, asymmetric bool, keyid string) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue