aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/pss
diff options
context:
space:
mode:
authorgluk256 <gluk256@gmail.com>2019-02-13 07:12:41 +0800
committerRafael Matias <rafael@skyle.net>2019-02-19 20:11:51 +0800
commit799fe99537e57f2651c24dcd628f3a2db2fe7ef9 (patch)
tree8287b57b3d146fed4ddb0446650adbd97c8672c4 /swarm/pss
parent3b02b0ba4b593a47e1e9e1975a47dd1e0d3afcae (diff)
downloadgo-tangerine-799fe99537e57f2651c24dcd628f3a2db2fe7ef9.tar.gz
go-tangerine-799fe99537e57f2651c24dcd628f3a2db2fe7ef9.tar.zst
go-tangerine-799fe99537e57f2651c24dcd628f3a2db2fe7ef9.zip
swarm/pss: mutex lifecycle fixed (#19045)
(cherry picked from commit b30109df3c7c56cb0d1752fc03f478474c3c190a)
Diffstat (limited to 'swarm/pss')
-rw-r--r--swarm/pss/protocol.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/swarm/pss/protocol.go b/swarm/pss/protocol.go
index 5fcae090e..5f47ee47d 100644
--- a/swarm/pss/protocol.go
+++ b/swarm/pss/protocol.go
@@ -228,6 +228,7 @@ func ToP2pMsg(msg []byte) (p2p.Msg, error) {
// to link the peer to.
// The key must exist in the pss store prior to adding the peer.
func (p *Protocol) AddPeer(peer *p2p.Peer, topic Topic, asymmetric bool, key string) (p2p.MsgReadWriter, error) {
+ var ok bool
rw := &PssReadWriter{
Pss: p.Pss,
rw: make(chan p2p.Msg),
@@ -242,19 +243,21 @@ func (p *Protocol) AddPeer(peer *p2p.Peer, topic Topic, asymmetric bool, key str
}
if asymmetric {
p.Pss.pubKeyPoolMu.Lock()
- if _, ok := p.Pss.pubKeyPool[key]; !ok {
+ _, ok = p.Pss.pubKeyPool[key]
+ p.Pss.pubKeyPoolMu.Unlock()
+ if !ok {
return nil, fmt.Errorf("asym key does not exist: %s", key)
}
- p.Pss.pubKeyPoolMu.Unlock()
p.RWPoolMu.Lock()
p.pubKeyRWPool[key] = rw
p.RWPoolMu.Unlock()
} else {
p.Pss.symKeyPoolMu.Lock()
- if _, ok := p.Pss.symKeyPool[key]; !ok {
+ _, ok = p.Pss.symKeyPool[key]
+ p.Pss.symKeyPoolMu.Unlock()
+ if !ok {
return nil, fmt.Errorf("symkey does not exist: %s", key)
}
- p.Pss.symKeyPoolMu.Unlock()
p.RWPoolMu.Lock()
p.symKeyRWPool[key] = rw
p.RWPoolMu.Unlock()