Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
406e74e2
Commit
406e74e2
authored
Apr 22, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whisper: fix a small data race duirng peer connection
parent
70ded4cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
14 deletions
+12
-14
peer.go
whisper/peer.go
+2
-6
whisper.go
whisper/whisper.go
+10
-8
No files found.
whisper/peer.go
View file @
406e74e2
...
...
@@ -23,18 +23,14 @@ type peer struct {
// newPeer creates and initializes a new whisper peer connection, returning either
// the newly constructed link or a failure reason.
func
newPeer
(
host
*
Whisper
,
remote
*
p2p
.
Peer
,
rw
p2p
.
MsgReadWriter
)
(
*
peer
,
error
)
{
p
:=
&
peer
{
func
newPeer
(
host
*
Whisper
,
remote
*
p2p
.
Peer
,
rw
p2p
.
MsgReadWriter
)
*
peer
{
return
&
peer
{
host
:
host
,
peer
:
remote
,
ws
:
rw
,
known
:
set
.
New
(),
quit
:
make
(
chan
struct
{}),
}
if
err
:=
p
.
handshake
();
err
!=
nil
{
return
nil
,
err
}
return
p
,
nil
}
// start initiates the peer updater, periodically broadcasting the whisper packets
...
...
whisper/whisper.go
View file @
406e74e2
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment