diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-04-22 22:40:39 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-04-28 15:49:05 +0800 |
commit | 406e74e2afdce374fd227873f4eb96a0ba99bd23 (patch) | |
tree | af605ae0512e7dab0802f0f8ebebe2e02f2798c1 /whisper/whisper.go | |
parent | 70ded4cbf06d19993d829d843a27002cf181c619 (diff) | |
download | go-tangerine-406e74e2afdce374fd227873f4eb96a0ba99bd23.tar go-tangerine-406e74e2afdce374fd227873f4eb96a0ba99bd23.tar.gz go-tangerine-406e74e2afdce374fd227873f4eb96a0ba99bd23.tar.bz2 go-tangerine-406e74e2afdce374fd227873f4eb96a0ba99bd23.tar.lz go-tangerine-406e74e2afdce374fd227873f4eb96a0ba99bd23.tar.xz go-tangerine-406e74e2afdce374fd227873f4eb96a0ba99bd23.tar.zst go-tangerine-406e74e2afdce374fd227873f4eb96a0ba99bd23.zip |
whisper: fix a small data race duirng peer connection
Diffstat (limited to 'whisper/whisper.go')
-rw-r--r-- | whisper/whisper.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/whisper/whisper.go b/whisper/whisper.go index 5d6ee6e3b..a48e1e380 100644 --- a/whisper/whisper.go +++ b/whisper/whisper.go @@ -168,15 +168,9 @@ func (self *Whisper) Messages(id int) []*Message { // handlePeer is called by the underlying P2P layer when the whisper sub-protocol // connection is negotiated. func (self *Whisper) handlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error { - // Create, initialize and start the whisper peer - whisperPeer, err := newPeer(self, peer, rw) - if err != nil { - return err - } - whisperPeer.start() - defer whisperPeer.stop() + // Create the new peer and start tracking it + whisperPeer := newPeer(self, peer, rw) - // Start tracking the active peer self.peerMu.Lock() self.peers[whisperPeer] = struct{}{} self.peerMu.Unlock() @@ -186,6 +180,14 @@ func (self *Whisper) handlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error { delete(self.peers, whisperPeer) self.peerMu.Unlock() }() + + // Run the peer handshake and state updates + if err := whisperPeer.handshake(); err != nil { + return err + } + whisperPeer.start() + defer whisperPeer.stop() + // Read and process inbound messages directly to merge into client-global state for { // Fetch the next packet and decode the contained envelopes |