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
483d43a1
Commit
483d43a1
authored
Mar 20, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whisper: use package rlp
parent
a829a565
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
37 deletions
+24
-37
envelope.go
whisper/envelope.go
+15
-25
peer.go
whisper/peer.go
+9
-12
No files found.
whisper/envelope.go
View file @
483d43a1
...
...
@@ -28,9 +28,9 @@ type Envelope struct {
func
(
self
*
Envelope
)
Hash
()
Hash
{
if
self
.
hash
==
EmptyHash
{
self
.
hash
=
H
(
crypto
.
Sha3
(
common
.
Encode
(
self
)))
enc
,
_
:=
rlp
.
EncodeToBytes
(
self
)
self
.
hash
=
H
(
crypto
.
Sha3
(
enc
))
}
return
self
.
hash
}
...
...
@@ -76,7 +76,8 @@ func (self *Envelope) Open(prv *ecdsa.PrivateKey) (msg *Message, err error) {
func
(
self
*
Envelope
)
proveWork
(
dura
time
.
Duration
)
{
var
bestBit
int
d
:=
make
([]
byte
,
64
)
copy
(
d
[
:
32
],
common
.
Encode
(
self
.
withoutNonce
()))
enc
,
_
:=
rlp
.
EncodeToBytes
(
self
.
withoutNonce
())
copy
(
d
[
:
32
],
enc
)
then
:=
time
.
Now
()
.
Add
(
dura
)
.
UnixNano
()
for
n
:=
uint32
(
0
);
time
.
Now
()
.
UnixNano
()
<
then
;
{
...
...
@@ -96,39 +97,28 @@ func (self *Envelope) proveWork(dura time.Duration) {
func
(
self
*
Envelope
)
valid
()
bool
{
d
:=
make
([]
byte
,
64
)
copy
(
d
[
:
32
],
common
.
Encode
(
self
.
withoutNonce
()))
enc
,
_
:=
rlp
.
EncodeToBytes
(
self
.
withoutNonce
())
copy
(
d
[
:
32
],
enc
)
binary
.
BigEndian
.
PutUint32
(
d
[
60
:
],
self
.
Nonce
)
return
common
.
FirstBitSet
(
common
.
BigD
(
crypto
.
Sha3
(
d
)))
>
0
}
func
(
self
*
Envelope
)
withoutNonce
()
interface
{}
{
return
[]
interface
{}{
self
.
Expiry
,
self
.
Ttl
,
common
.
ByteSliceToInterface
(
self
.
Topics
)
,
self
.
Data
}
return
[]
interface
{}{
self
.
Expiry
,
self
.
Ttl
,
self
.
Topics
,
self
.
Data
}
}
func
(
self
*
Envelope
)
RlpData
()
interface
{}
{
return
[]
interface
{}{
self
.
Expiry
,
self
.
Ttl
,
common
.
ByteSliceToInterface
(
self
.
Topics
),
self
.
Data
,
self
.
Nonce
}
}
// rlpenv is an Envelope but is not an rlp.Decoder.
// It is used for decoding because we need to
type
rlpenv
Envelope
func
(
self
*
Envelope
)
DecodeRLP
(
s
*
rlp
.
Stream
)
error
{
var
extenv
struct
{
Expiry
uint32
Ttl
uint32
Topics
[][]
byte
Data
[]
byte
Nonce
uint32
raw
,
err
:=
s
.
Raw
()
if
err
!=
nil
{
return
err
}
if
err
:=
s
.
Decode
(
&
extenv
);
err
!=
nil
{
if
err
:=
rlp
.
DecodeBytes
(
raw
,
(
*
rlpenv
)(
self
)
);
err
!=
nil
{
return
err
}
self
.
Expiry
=
extenv
.
Expiry
self
.
Ttl
=
extenv
.
Ttl
self
.
Topics
=
extenv
.
Topics
self
.
Data
=
extenv
.
Data
self
.
Nonce
=
extenv
.
Nonce
// TODO We should use the stream directly here.
self
.
hash
=
H
(
crypto
.
Sha3
(
common
.
Encode
(
self
)))
self
.
hash
=
H
(
crypto
.
Sha3
(
raw
))
return
nil
}
whisper/peer.go
View file @
483d43a1
...
...
@@ -10,7 +10,7 @@ import (
)
const
(
protocolVersion
=
0x02
protocolVersion
uint64
=
0x02
)
type
peer
struct
{
...
...
@@ -66,21 +66,18 @@ out:
}
func
(
self
*
peer
)
broadcast
(
envelopes
[]
*
Envelope
)
error
{
envs
:=
make
([]
interface
{},
len
(
envelopes
))
i
:=
0
for
_
,
envelope
:=
range
envelopes
{
if
!
self
.
known
.
Has
(
envelope
.
Hash
())
{
envs
[
i
]
=
envelope
self
.
known
.
Add
(
envelope
.
Hash
())
i
++
envs
:=
make
([]
*
Envelope
,
0
,
len
(
envelopes
))
for
_
,
env
:=
range
envelopes
{
if
!
self
.
known
.
Has
(
env
.
Hash
())
{
envs
=
append
(
envs
,
env
)
self
.
known
.
Add
(
env
.
Hash
())
}
}
if
i
>
0
{
if
err
:=
p2p
.
Send
(
self
.
ws
,
envelopesMsg
,
envs
[
:
i
]);
err
!=
nil
{
if
len
(
envs
)
>
0
{
if
err
:=
p2p
.
Send
(
self
.
ws
,
envelopesMsg
,
envs
);
err
!=
nil
{
return
err
}
self
.
peer
.
DebugDetailln
(
"broadcasted"
,
i
,
"message(s)"
)
self
.
peer
.
DebugDetailln
(
"broadcasted"
,
len
(
envs
)
,
"message(s)"
)
}
return
nil
}
...
...
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