From 799fe99537e57f2651c24dcd628f3a2db2fe7ef9 Mon Sep 17 00:00:00 2001 From: gluk256 Date: Wed, 13 Feb 2019 03:12:41 +0400 Subject: swarm/pss: mutex lifecycle fixed (#19045) (cherry picked from commit b30109df3c7c56cb0d1752fc03f478474c3c190a) --- swarm/pss/protocol.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'swarm/pss/protocol.go') 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() -- cgit From d6c1fcbe045c94cf629a9df956bd7aef7dcf8d72 Mon Sep 17 00:00:00 2001 From: gluk256 Date: Sun, 17 Feb 2019 09:29:41 +0400 Subject: swarm/pss: refactoring (#19110) * swarm/pss: split pss and keystore * swarm/pss: moved whisper to keystore * swarm/pss: goimports fixed (cherry picked from commit 12ca3b172a7e1b2b63ef2369e8dc37c75144c81f) --- swarm/pss/protocol.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'swarm/pss/protocol.go') diff --git a/swarm/pss/protocol.go b/swarm/pss/protocol.go index 5f47ee47d..7f186f615 100644 --- a/swarm/pss/protocol.go +++ b/swarm/pss/protocol.go @@ -228,7 +228,6 @@ 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,20 +241,14 @@ func (p *Protocol) AddPeer(peer *p2p.Peer, topic Topic, asymmetric bool, key str rw.sendFunc = p.Pss.SendSym } if asymmetric { - p.Pss.pubKeyPoolMu.Lock() - _, ok = p.Pss.pubKeyPool[key] - p.Pss.pubKeyPoolMu.Unlock() - if !ok { + if !p.Pss.isPubKeyStored(key) { return nil, fmt.Errorf("asym key does not exist: %s", key) } p.RWPoolMu.Lock() p.pubKeyRWPool[key] = rw p.RWPoolMu.Unlock() } else { - p.Pss.symKeyPoolMu.Lock() - _, ok = p.Pss.symKeyPool[key] - p.Pss.symKeyPoolMu.Unlock() - if !ok { + if !p.Pss.isSymKeyStored(key) { return nil, fmt.Errorf("symkey does not exist: %s", key) } p.RWPoolMu.Lock() -- cgit