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
75ae5af6
Commit
75ae5af6
authored
Aug 29, 2018
by
Adam Babik
Committed by
Péter Szilágyi
Aug 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whisper: fix loop in expire() (#17532)
parent
95749681
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
28 deletions
+42
-28
whisper.go
whisper/whisperv5/whisper.go
+1
-1
whisper_test.go
whisper/whisperv5/whisper_test.go
+20
-13
whisper.go
whisper/whisperv6/whisper.go
+1
-1
whisper_test.go
whisper/whisperv6/whisper_test.go
+20
-13
No files found.
whisper/whisperv5/whisper.go
View file @
75ae5af6
...
@@ -717,7 +717,7 @@ func (w *Whisper) expire() {
...
@@ -717,7 +717,7 @@ func (w *Whisper) expire() {
w
.
stats
.
messagesCleared
++
w
.
stats
.
messagesCleared
++
w
.
stats
.
memoryCleared
+=
sz
w
.
stats
.
memoryCleared
+=
sz
w
.
stats
.
memoryUsed
-=
sz
w
.
stats
.
memoryUsed
-=
sz
return
tru
e
return
fals
e
})
})
w
.
expirations
[
expiry
]
.
Clear
()
w
.
expirations
[
expiry
]
.
Clear
()
delete
(
w
.
expirations
,
expiry
)
delete
(
w
.
expirations
,
expiry
)
...
...
whisper/whisperv5/whisper_test.go
View file @
75ae5af6
...
@@ -487,8 +487,14 @@ func TestExpiry(t *testing.T) {
...
@@ -487,8 +487,14 @@ func TestExpiry(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"failed generateMessageParams with seed %d: %s."
,
seed
,
err
)
t
.
Fatalf
(
"failed generateMessageParams with seed %d: %s."
,
seed
,
err
)
}
}
params
.
TTL
=
1
params
.
TTL
=
1
messagesCount
:=
5
// Send a few messages one after another. Due to low PoW and expiration buckets
// with one second resolution, it covers a case when there are multiple items
// in a single expiration bucket.
for
i
:=
0
;
i
<
messagesCount
;
i
++
{
msg
,
err
:=
NewSentMessage
(
params
)
msg
,
err
:=
NewSentMessage
(
params
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create new message with seed %d: %s."
,
seed
,
err
)
t
.
Fatalf
(
"failed to create new message with seed %d: %s."
,
seed
,
err
)
...
@@ -502,12 +508,13 @@ func TestExpiry(t *testing.T) {
...
@@ -502,12 +508,13 @@ func TestExpiry(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"failed to send envelope with seed %d: %s."
,
seed
,
err
)
t
.
Fatalf
(
"failed to send envelope with seed %d: %s."
,
seed
,
err
)
}
}
}
// wait till received or timeout
// wait till received or timeout
var
received
,
expired
bool
var
received
,
expired
bool
for
j
:=
0
;
j
<
20
;
j
++
{
for
j
:=
0
;
j
<
20
;
j
++
{
time
.
Sleep
(
100
*
time
.
Millisecond
)
time
.
Sleep
(
100
*
time
.
Millisecond
)
if
len
(
w
.
Envelopes
())
>
0
{
if
len
(
w
.
Envelopes
())
==
messagesCount
{
received
=
true
received
=
true
break
break
}
}
...
...
whisper/whisperv6/whisper.go
View file @
75ae5af6
...
@@ -900,7 +900,7 @@ func (whisper *Whisper) expire() {
...
@@ -900,7 +900,7 @@ func (whisper *Whisper) expire() {
whisper
.
stats
.
messagesCleared
++
whisper
.
stats
.
messagesCleared
++
whisper
.
stats
.
memoryCleared
+=
sz
whisper
.
stats
.
memoryCleared
+=
sz
whisper
.
stats
.
memoryUsed
-=
sz
whisper
.
stats
.
memoryUsed
-=
sz
return
tru
e
return
fals
e
})
})
whisper
.
expirations
[
expiry
]
.
Clear
()
whisper
.
expirations
[
expiry
]
.
Clear
()
delete
(
whisper
.
expirations
,
expiry
)
delete
(
whisper
.
expirations
,
expiry
)
...
...
whisper/whisperv6/whisper_test.go
View file @
75ae5af6
...
@@ -465,8 +465,14 @@ func TestExpiry(t *testing.T) {
...
@@ -465,8 +465,14 @@ func TestExpiry(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"failed generateMessageParams with seed %d: %s."
,
seed
,
err
)
t
.
Fatalf
(
"failed generateMessageParams with seed %d: %s."
,
seed
,
err
)
}
}
params
.
TTL
=
1
params
.
TTL
=
1
messagesCount
:=
5
// Send a few messages one after another. Due to low PoW and expiration buckets
// with one second resolution, it covers a case when there are multiple items
// in a single expiration bucket.
for
i
:=
0
;
i
<
messagesCount
;
i
++
{
msg
,
err
:=
NewSentMessage
(
params
)
msg
,
err
:=
NewSentMessage
(
params
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create new message with seed %d: %s."
,
seed
,
err
)
t
.
Fatalf
(
"failed to create new message with seed %d: %s."
,
seed
,
err
)
...
@@ -480,12 +486,13 @@ func TestExpiry(t *testing.T) {
...
@@ -480,12 +486,13 @@ func TestExpiry(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"failed to send envelope with seed %d: %s."
,
seed
,
err
)
t
.
Fatalf
(
"failed to send envelope with seed %d: %s."
,
seed
,
err
)
}
}
}
// wait till received or timeout
// wait till received or timeout
var
received
,
expired
bool
var
received
,
expired
bool
for
j
:=
0
;
j
<
20
;
j
++
{
for
j
:=
0
;
j
<
20
;
j
++
{
time
.
Sleep
(
100
*
time
.
Millisecond
)
time
.
Sleep
(
100
*
time
.
Millisecond
)
if
len
(
w
.
Envelopes
())
>
0
{
if
len
(
w
.
Envelopes
())
==
messagesCount
{
received
=
true
received
=
true
break
break
}
}
...
...
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