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
105008b6
Commit
105008b6
authored
Jan 21, 2019
by
gluk256
Committed by
Anton Evangelatov
Jan 21, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
swarm/pss: fixing race condition (#18487)
parent
15b9b39e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
9 deletions
+11
-9
pss.go
swarm/pss/pss.go
+11
-9
No files found.
swarm/pss/pss.go
View file @
105008b6
...
...
@@ -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,13 +465,22 @@ 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 data race or deadlock
func
(
p
*
Pss
)
getHandlers
(
topic
Topic
)
(
ret
[]
*
handler
)
{
p
.
handlersMu
.
RLock
()
defer
p
.
handlersMu
.
RUnlock
()
for
k
:=
range
p
.
handlers
[
topic
]
{
ret
=
append
(
ret
,
k
)
}
return
ret
}
func
(
p
*
Pss
)
executeHandlers
(
topic
Topic
,
payload
[]
byte
,
from
PssAddress
,
raw
bool
,
prox
bool
,
asymmetric
bool
,
keyid
string
)
{
handlers
:=
p
.
getHandlers
(
topic
)
peer
:=
p2p
.
NewPeer
(
enode
.
ID
{},
fmt
.
Sprintf
(
"%x"
,
from
),
[]
p2p
.
Cap
{})
for
h
:=
range
handlers
{
for
_
,
h
:=
range
handlers
{
if
!
h
.
caps
.
raw
&&
raw
{
log
.
Warn
(
"norawhandler"
)
continue
...
...
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