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
168d0e9e
Commit
168d0e9e
authored
Nov 25, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1996 from obscuren/whisper-spam-fix
whisper: fixed broadcast race
parents
b0fb48c3
5f0a4416
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
2 deletions
+19
-2
peer_test.go
whisper/peer_test.go
+5
-2
whisper.go
whisper/whisper.go
+5
-0
whisper_test.go
whisper/whisper_test.go
+9
-0
No files found.
whisper/peer_test.go
View file @
168d0e9e
...
@@ -239,14 +239,17 @@ func TestPeerMessageExpiration(t *testing.T) {
...
@@ -239,14 +239,17 @@ func TestPeerMessageExpiration(t *testing.T) {
}
}
payload
:=
[]
interface
{}{
envelope
}
payload
:=
[]
interface
{}{
envelope
}
if
err
:=
p2p
.
ExpectMsg
(
tester
.
stream
,
messagesCode
,
payload
);
err
!=
nil
{
if
err
:=
p2p
.
ExpectMsg
(
tester
.
stream
,
messagesCode
,
payload
);
err
!=
nil
{
t
.
Fatalf
(
"message mismatch: %v"
,
err
)
// A premature empty message may have been broadcast, check the next too
if
err
:=
p2p
.
ExpectMsg
(
tester
.
stream
,
messagesCode
,
payload
);
err
!=
nil
{
t
.
Fatalf
(
"message mismatch: %v"
,
err
)
}
}
}
// Check that the message is inside the cache
// Check that the message is inside the cache
if
!
peer
.
known
.
Has
(
envelope
.
Hash
())
{
if
!
peer
.
known
.
Has
(
envelope
.
Hash
())
{
t
.
Fatalf
(
"message not found in cache"
)
t
.
Fatalf
(
"message not found in cache"
)
}
}
// Discard messages until expiration and check cache again
// Discard messages until expiration and check cache again
exp
:=
time
.
Now
()
.
Add
(
time
.
Second
+
expirationCycle
)
exp
:=
time
.
Now
()
.
Add
(
time
.
Second
+
2
*
expirationCycle
+
100
*
time
.
Millisecond
)
for
time
.
Now
()
.
Before
(
exp
)
{
for
time
.
Now
()
.
Before
(
exp
)
{
if
err
:=
p2p
.
ExpectMsg
(
tester
.
stream
,
messagesCode
,
[]
interface
{}{});
err
!=
nil
{
if
err
:=
p2p
.
ExpectMsg
(
tester
.
stream
,
messagesCode
,
[]
interface
{}{});
err
!=
nil
{
t
.
Fatalf
(
"message mismatch: %v"
,
err
)
t
.
Fatalf
(
"message mismatch: %v"
,
err
)
...
...
whisper/whisper.go
View file @
168d0e9e
...
@@ -234,6 +234,11 @@ func (self *Whisper) add(envelope *Envelope) error {
...
@@ -234,6 +234,11 @@ func (self *Whisper) add(envelope *Envelope) error {
self
.
poolMu
.
Lock
()
self
.
poolMu
.
Lock
()
defer
self
.
poolMu
.
Unlock
()
defer
self
.
poolMu
.
Unlock
()
// short circuit when a received envelope has already expired
if
envelope
.
Expiry
<=
uint32
(
time
.
Now
()
.
Unix
())
{
return
nil
}
// Insert the message into the tracked pool
// Insert the message into the tracked pool
hash
:=
envelope
.
Hash
()
hash
:=
envelope
.
Hash
()
if
_
,
ok
:=
self
.
messages
[
hash
];
ok
{
if
_
,
ok
:=
self
.
messages
[
hash
];
ok
{
...
...
whisper/whisper_test.go
View file @
168d0e9e
...
@@ -207,4 +207,13 @@ func TestMessageExpiration(t *testing.T) {
...
@@ -207,4 +207,13 @@ func TestMessageExpiration(t *testing.T) {
if
found
{
if
found
{
t
.
Fatalf
(
"message not expired from cache"
)
t
.
Fatalf
(
"message not expired from cache"
)
}
}
node
.
add
(
envelope
)
node
.
poolMu
.
RLock
()
_
,
found
=
node
.
messages
[
envelope
.
Hash
()]
node
.
poolMu
.
RUnlock
()
if
found
{
t
.
Fatalf
(
"message was added to cache"
)
}
}
}
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