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
c733792b
Commit
c733792b
authored
Feb 27, 2018
by
Vlad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whsiper: refactoring
parent
014d8d98
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
61 deletions
+22
-61
filter.go
whisper/whisperv6/filter.go
+6
-23
filter_test.go
whisper/whisperv6/filter_test.go
+15
-10
whisper.go
whisper/whisperv6/whisper.go
+0
-18
whisper_test.go
whisper/whisperv6/whisper_test.go
+1
-10
No files found.
whisper/whisperv6/filter.go
View file @
c733792b
...
...
@@ -238,16 +238,17 @@ func (f *Filter) Retrieve() (all []*ReceivedMessage) {
// MatchMessage checks if the filter matches an already decrypted
// message (i.e. a Message that has already been handled by
// MatchEnvelope when checked by a previous filter)
// MatchEnvelope when checked by a previous filter).
// Topics are not checked here, since this is done by topic matchers.
func
(
f
*
Filter
)
MatchMessage
(
msg
*
ReceivedMessage
)
bool
{
if
f
.
PoW
>
0
&&
msg
.
PoW
<
f
.
PoW
{
return
false
}
if
f
.
expectsAsymmetricEncryption
()
&&
msg
.
isAsymmetricEncryption
()
{
return
IsPubKeyEqual
(
&
f
.
KeyAsym
.
PublicKey
,
msg
.
Dst
)
&&
f
.
MatchTopic
(
msg
.
Topic
)
return
IsPubKeyEqual
(
&
f
.
KeyAsym
.
PublicKey
,
msg
.
Dst
)
}
else
if
f
.
expectsSymmetricEncryption
()
&&
msg
.
isSymmetricEncryption
()
{
return
f
.
SymKeyHash
==
msg
.
SymKeyHash
&&
f
.
MatchTopic
(
msg
.
Topic
)
return
f
.
SymKeyHash
==
msg
.
SymKeyHash
}
return
false
}
...
...
@@ -255,27 +256,9 @@ func (f *Filter) MatchMessage(msg *ReceivedMessage) bool {
// MatchEnvelope checks if it's worth decrypting the message. If
// it returns `true`, client code is expected to attempt decrypting
// the message and subsequently call MatchMessage.
// Topics are not checked here, since this is done by topic matchers.
func
(
f
*
Filter
)
MatchEnvelope
(
envelope
*
Envelope
)
bool
{
if
f
.
PoW
>
0
&&
envelope
.
pow
<
f
.
PoW
{
return
false
}
return
f
.
MatchTopic
(
envelope
.
Topic
)
}
// MatchTopic checks that the filter captures a given topic.
func
(
f
*
Filter
)
MatchTopic
(
topic
TopicType
)
bool
{
if
len
(
f
.
Topics
)
==
0
{
// any topic matches
return
true
}
for
_
,
bt
:=
range
f
.
Topics
{
if
matchSingleTopic
(
topic
,
bt
)
{
return
true
}
}
return
false
return
f
.
PoW
<=
0
||
envelope
.
pow
>=
f
.
PoW
}
func
matchSingleTopic
(
topic
TopicType
,
bt
[]
byte
)
bool
{
...
...
whisper/whisperv6/filter_test.go
View file @
c733792b
...
...
@@ -303,9 +303,8 @@ func TestMatchEnvelope(t *testing.T) {
t
.
Fatalf
(
"failed generateMessageParams with seed %d: %s."
,
seed
,
err
)
}
params
.
Topic
[
0
]
=
0xFF
//
ensure
mismatch
params
.
Topic
[
0
]
=
0xFF
//
topic
mismatch
// mismatch with pseudo-random data
msg
,
err
:=
NewSentMessage
(
params
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create new message with seed %d: %s."
,
seed
,
err
)
...
...
@@ -315,11 +314,13 @@ func TestMatchEnvelope(t *testing.T) {
t
.
Fatalf
(
"failed Wrap with seed %d: %s."
,
seed
,
err
)
}
match
:=
fsym
.
MatchEnvelope
(
env
)
if
match
{
if
!
match
{
// topic mismatch should have no affect, as topics are handled by topic matchers
t
.
Fatalf
(
"failed MatchEnvelope symmetric with seed %d."
,
seed
)
}
match
=
fasym
.
MatchEnvelope
(
env
)
if
match
{
if
!
match
{
// topic mismatch should have no affect, as topics are handled by topic matchers
t
.
Fatalf
(
"failed MatchEnvelope asymmetric with seed %d."
,
seed
)
}
...
...
@@ -396,7 +397,7 @@ func TestMatchEnvelope(t *testing.T) {
// asymmetric + matching topic: match
fasym
.
Topics
[
i
]
=
fasym
.
Topics
[
i
+
1
]
match
=
fasym
.
MatchEnvelope
(
env
)
if
match
{
if
!
match
{
t
.
Fatalf
(
"failed MatchEnvelope(asymmetric + matching topic) with seed %d."
,
seed
)
}
...
...
@@ -431,7 +432,8 @@ func TestMatchEnvelope(t *testing.T) {
// filter with topic + envelope without topic: mismatch
fasym
.
Topics
=
fsym
.
Topics
match
=
fasym
.
MatchEnvelope
(
env
)
if
match
{
if
!
match
{
// topic mismatch should have no affect, as topics are handled by topic matchers
t
.
Fatalf
(
"failed MatchEnvelope(filter without topic + envelope without topic) with seed %d."
,
seed
)
}
}
...
...
@@ -487,7 +489,8 @@ func TestMatchMessageSym(t *testing.T) {
// topic mismatch
f
.
Topics
[
index
][
0
]
++
if
f
.
MatchMessage
(
msg
)
{
if
!
f
.
MatchMessage
(
msg
)
{
// topic mismatch should have no affect, as topics are handled by topic matchers
t
.
Fatalf
(
"failed MatchEnvelope(topic mismatch) with seed %d."
,
seed
)
}
f
.
Topics
[
index
][
0
]
--
...
...
@@ -580,7 +583,8 @@ func TestMatchMessageAsym(t *testing.T) {
// topic mismatch
f
.
Topics
[
index
][
0
]
++
if
f
.
MatchMessage
(
msg
)
{
if
!
f
.
MatchMessage
(
msg
)
{
// topic mismatch should have no affect, as topics are handled by topic matchers
t
.
Fatalf
(
"failed MatchEnvelope(topic mismatch) with seed %d."
,
seed
)
}
f
.
Topics
[
index
][
0
]
--
...
...
@@ -829,8 +833,9 @@ func TestVariableTopics(t *testing.T) {
f
.
Topics
[
i
][
lastTopicByte
]
++
match
=
f
.
MatchEnvelope
(
env
)
if
match
{
t
.
Fatalf
(
"MatchEnvelope symmetric with seed %d, step %d: false positive."
,
seed
,
i
)
if
!
match
{
// topic mismatch should have no affect, as topics are handled by topic matchers
t
.
Fatalf
(
"MatchEnvelope symmetric with seed %d, step %d."
,
seed
,
i
)
}
}
}
...
...
whisper/whisperv6/whisper.go
View file @
c733792b
...
...
@@ -928,24 +928,6 @@ func (whisper *Whisper) Envelopes() []*Envelope {
return
all
}
// Messages iterates through all currently floating envelopes
// and retrieves all the messages, that this filter could decrypt.
func
(
whisper
*
Whisper
)
Messages
(
id
string
)
[]
*
ReceivedMessage
{
result
:=
make
([]
*
ReceivedMessage
,
0
)
whisper
.
poolMu
.
RLock
()
defer
whisper
.
poolMu
.
RUnlock
()
if
filter
:=
whisper
.
filters
.
Get
(
id
);
filter
!=
nil
{
for
_
,
env
:=
range
whisper
.
envelopes
{
msg
:=
filter
.
processEnvelope
(
env
)
if
msg
!=
nil
{
result
=
append
(
result
,
msg
)
}
}
}
return
result
}
// isEnvelopeCached checks if envelope with specific hash has already been received and cached.
func
(
whisper
*
Whisper
)
isEnvelopeCached
(
hash
common
.
Hash
)
bool
{
whisper
.
poolMu
.
Lock
()
...
...
whisper/whisperv6/whisper_test.go
View file @
c733792b
...
...
@@ -75,10 +75,6 @@ func TestWhisperBasic(t *testing.T) {
if
len
(
mail
)
!=
0
{
t
.
Fatalf
(
"failed w.Envelopes()."
)
}
m
:=
w
.
Messages
(
"non-existent"
)
if
len
(
m
)
!=
0
{
t
.
Fatalf
(
"failed w.Messages."
)
}
derived
:=
pbkdf2
.
Key
([]
byte
(
peerID
),
nil
,
65356
,
aesKeyLength
,
sha256
.
New
)
if
!
validateDataIntegrity
(
derived
,
aesKeyLength
)
{
...
...
@@ -593,7 +589,7 @@ func TestCustomization(t *testing.T) {
}
// check w.messages()
id
,
err
:
=
w
.
Subscribe
(
f
)
_
,
err
=
w
.
Subscribe
(
f
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed subscribe with seed %d: %s."
,
seed
,
err
)
}
...
...
@@ -602,11 +598,6 @@ func TestCustomization(t *testing.T) {
if
len
(
mail
)
>
0
{
t
.
Fatalf
(
"received premature mail"
)
}
mail
=
w
.
Messages
(
id
)
if
len
(
mail
)
!=
2
{
t
.
Fatalf
(
"failed to get whisper messages"
)
}
}
func
TestSymmetricSendCycle
(
t
*
testing
.
T
)
{
...
...
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