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
7f48eb87
Commit
7f48eb87
authored
Apr 21, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whisper, xeth/whisper: surface TTL and hash to the API
parent
19bc4624
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
6 deletions
+25
-6
envelope.go
whisper/envelope.go
+2
-1
envelope_test.go
whisper/envelope_test.go
+5
-1
message.go
whisper/message.go
+7
-3
message_test.go
whisper/message_test.go
+4
-0
whisper_message.go
xeth/whisper_message.go
+7
-1
No files found.
whisper/envelope.go
View file @
7f48eb87
...
@@ -72,7 +72,8 @@ func (self *Envelope) Open(key *ecdsa.PrivateKey) (msg *Message, err error) {
...
@@ -72,7 +72,8 @@ func (self *Envelope) Open(key *ecdsa.PrivateKey) (msg *Message, err error) {
message
:=
&
Message
{
message
:=
&
Message
{
Flags
:
data
[
0
],
Flags
:
data
[
0
],
Sent
:
int64
(
self
.
Expiry
-
self
.
TTL
),
Sent
:
time
.
Unix
(
int64
(
self
.
Expiry
-
self
.
TTL
),
0
),
TTL
:
time
.
Duration
(
self
.
TTL
)
*
time
.
Second
,
Hash
:
self
.
Hash
(),
Hash
:
self
.
Hash
(),
}
}
data
=
data
[
1
:
]
data
=
data
[
1
:
]
...
...
whisper/envelope_test.go
View file @
7f48eb87
...
@@ -3,6 +3,7 @@ package whisper
...
@@ -3,6 +3,7 @@ package whisper
import
(
import
(
"bytes"
"bytes"
"testing"
"testing"
"time"
)
)
func
TestEnvelopeOpen
(
t
*
testing
.
T
)
{
func
TestEnvelopeOpen
(
t
*
testing
.
T
)
{
...
@@ -26,9 +27,12 @@ func TestEnvelopeOpen(t *testing.T) {
...
@@ -26,9 +27,12 @@ func TestEnvelopeOpen(t *testing.T) {
if
bytes
.
Compare
(
opened
.
Payload
,
message
.
Payload
)
!=
0
{
if
bytes
.
Compare
(
opened
.
Payload
,
message
.
Payload
)
!=
0
{
t
.
Fatalf
(
"payload mismatch: have 0x%x, want 0x%x"
,
opened
.
Payload
,
message
.
Payload
)
t
.
Fatalf
(
"payload mismatch: have 0x%x, want 0x%x"
,
opened
.
Payload
,
message
.
Payload
)
}
}
if
opened
.
Sent
!=
message
.
Sent
{
if
opened
.
Sent
.
Unix
()
!=
message
.
Sent
.
Unix
()
{
t
.
Fatalf
(
"send time mismatch: have %d, want %d"
,
opened
.
Sent
,
message
.
Sent
)
t
.
Fatalf
(
"send time mismatch: have %d, want %d"
,
opened
.
Sent
,
message
.
Sent
)
}
}
if
opened
.
TTL
/
time
.
Second
!=
DefaultTTL
/
time
.
Second
{
t
.
Fatalf
(
"message TTL mismatch: have %v, want %v"
,
opened
.
TTL
,
DefaultTTL
)
}
if
opened
.
Hash
!=
envelope
.
Hash
()
{
if
opened
.
Hash
!=
envelope
.
Hash
()
{
t
.
Fatalf
(
"message hash mismatch: have 0x%x, want 0x%x"
,
opened
.
Hash
,
envelope
.
Hash
())
t
.
Fatalf
(
"message hash mismatch: have 0x%x, want 0x%x"
,
opened
.
Hash
,
envelope
.
Hash
())
...
...
whisper/message.go
View file @
7f48eb87
...
@@ -21,10 +21,12 @@ type Message struct {
...
@@ -21,10 +21,12 @@ type Message struct {
Flags
byte
// First bit is signature presence, rest reserved and should be random
Flags
byte
// First bit is signature presence, rest reserved and should be random
Signature
[]
byte
Signature
[]
byte
Payload
[]
byte
Payload
[]
byte
Sent
int64
Sent
time
.
Time
// Time when the message was posted into the network
TTL
time
.
Duration
// Maximum time to live allowed for the message
To
*
ecdsa
.
PublicKey
// Message recipient (identity used to decode the message)
To
*
ecdsa
.
PublicKey
// Message recipient (identity used to decode the message)
Hash
common
.
Hash
// Message envelope hash to act as a unique id
in de-duplication
Hash
common
.
Hash
// Message envelope hash to act as a unique id
}
}
// Options specifies the exact way a message should be wrapped into an Envelope.
// Options specifies the exact way a message should be wrapped into an Envelope.
...
@@ -45,7 +47,7 @@ func NewMessage(payload []byte) *Message {
...
@@ -45,7 +47,7 @@ func NewMessage(payload []byte) *Message {
return
&
Message
{
return
&
Message
{
Flags
:
flags
,
Flags
:
flags
,
Payload
:
payload
,
Payload
:
payload
,
Sent
:
time
.
Now
()
.
Unix
()
,
Sent
:
time
.
Now
(),
}
}
}
}
...
@@ -66,6 +68,8 @@ func (self *Message) Wrap(pow time.Duration, options Options) (*Envelope, error)
...
@@ -66,6 +68,8 @@ func (self *Message) Wrap(pow time.Duration, options Options) (*Envelope, error)
if
options
.
TTL
==
0
{
if
options
.
TTL
==
0
{
options
.
TTL
=
DefaultTTL
options
.
TTL
=
DefaultTTL
}
}
self
.
TTL
=
options
.
TTL
// Sign and encrypt the message if requested
// Sign and encrypt the message if requested
if
options
.
From
!=
nil
{
if
options
.
From
!=
nil
{
if
err
:=
self
.
sign
(
options
.
From
);
err
!=
nil
{
if
err
:=
self
.
sign
(
options
.
From
);
err
!=
nil
{
...
...
whisper/message_test.go
View file @
7f48eb87
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"bytes"
"bytes"
"crypto/elliptic"
"crypto/elliptic"
"testing"
"testing"
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
)
)
...
@@ -25,6 +26,9 @@ func TestMessageSimpleWrap(t *testing.T) {
...
@@ -25,6 +26,9 @@ func TestMessageSimpleWrap(t *testing.T) {
if
bytes
.
Compare
(
msg
.
Payload
,
payload
)
!=
0
{
if
bytes
.
Compare
(
msg
.
Payload
,
payload
)
!=
0
{
t
.
Fatalf
(
"payload mismatch after wrapping: have 0x%x, want 0x%x"
,
msg
.
Payload
,
payload
)
t
.
Fatalf
(
"payload mismatch after wrapping: have 0x%x, want 0x%x"
,
msg
.
Payload
,
payload
)
}
}
if
msg
.
TTL
/
time
.
Second
!=
DefaultTTL
/
time
.
Second
{
t
.
Fatalf
(
"message TTL mismatch: have %v, want %v"
,
msg
.
TTL
,
DefaultTTL
)
}
}
}
// Tests whether a message can be signed, and wrapped in plain-text.
// Tests whether a message can be signed, and wrapped in plain-text.
...
...
xeth/whisper_message.go
View file @
7f48eb87
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
package
xeth
package
xeth
import
(
import
(
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/whisper"
"github.com/ethereum/go-ethereum/whisper"
...
@@ -16,6 +18,8 @@ type WhisperMessage struct {
...
@@ -16,6 +18,8 @@ type WhisperMessage struct {
To
string
`json:"to"`
To
string
`json:"to"`
From
string
`json:"from"`
From
string
`json:"from"`
Sent
int64
`json:"sent"`
Sent
int64
`json:"sent"`
TTL
int64
`json:"ttl"`
Hash
string
`json:"hash"`
}
}
// NewWhisperMessage converts an internal message into an API version.
// NewWhisperMessage converts an internal message into an API version.
...
@@ -26,6 +30,8 @@ func NewWhisperMessage(message *whisper.Message) WhisperMessage {
...
@@ -26,6 +30,8 @@ func NewWhisperMessage(message *whisper.Message) WhisperMessage {
Payload
:
common
.
ToHex
(
message
.
Payload
),
Payload
:
common
.
ToHex
(
message
.
Payload
),
From
:
common
.
ToHex
(
crypto
.
FromECDSAPub
(
message
.
Recover
())),
From
:
common
.
ToHex
(
crypto
.
FromECDSAPub
(
message
.
Recover
())),
To
:
common
.
ToHex
(
crypto
.
FromECDSAPub
(
message
.
To
)),
To
:
common
.
ToHex
(
crypto
.
FromECDSAPub
(
message
.
To
)),
Sent
:
message
.
Sent
,
Sent
:
message
.
Sent
.
Unix
(),
TTL
:
int64
(
message
.
TTL
/
time
.
Second
),
Hash
:
common
.
ToHex
(
message
.
Hash
.
Bytes
()),
}
}
}
}
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