Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
7f48eb87
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7f48eb87
编写于
4月 21, 2015
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
whisper, xeth/whisper: surface TTL and hash to the API
上级
19bc4624
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
25 addition
and
6 deletion
+25
-6
whisper/envelope.go
whisper/envelope.go
+2
-1
whisper/envelope_test.go
whisper/envelope_test.go
+5
-1
whisper/message.go
whisper/message.go
+7
-3
whisper/message_test.go
whisper/message_test.go
+4
-0
xeth/whisper_message.go
xeth/whisper_message.go
+7
-1
未找到文件。
whisper/envelope.go
浏览文件 @
7f48eb87
...
...
@@ -72,7 +72,8 @@ func (self *Envelope) Open(key *ecdsa.PrivateKey) (msg *Message, err error) {
message
:=
&
Message
{
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
(),
}
data
=
data
[
1
:
]
...
...
whisper/envelope_test.go
浏览文件 @
7f48eb87
...
...
@@ -3,6 +3,7 @@ package whisper
import
(
"bytes"
"testing"
"time"
)
func
TestEnvelopeOpen
(
t
*
testing
.
T
)
{
...
...
@@ -26,9 +27,12 @@ func TestEnvelopeOpen(t *testing.T) {
if
bytes
.
Compare
(
opened
.
Payload
,
message
.
Payload
)
!=
0
{
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
)
}
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
()
{
t
.
Fatalf
(
"message hash mismatch: have 0x%x, want 0x%x"
,
opened
.
Hash
,
envelope
.
Hash
())
...
...
whisper/message.go
浏览文件 @
7f48eb87
...
...
@@ -21,10 +21,12 @@ type Message struct {
Flags
byte
// First bit is signature presence, rest reserved and should be random
Signature
[]
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)
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.
...
...
@@ -45,7 +47,7 @@ func NewMessage(payload []byte) *Message {
return
&
Message
{
Flags
:
flags
,
Payload
:
payload
,
Sent
:
time
.
Now
()
.
Unix
()
,
Sent
:
time
.
Now
(),
}
}
...
...
@@ -66,6 +68,8 @@ func (self *Message) Wrap(pow time.Duration, options Options) (*Envelope, error)
if
options
.
TTL
==
0
{
options
.
TTL
=
DefaultTTL
}
self
.
TTL
=
options
.
TTL
// Sign and encrypt the message if requested
if
options
.
From
!=
nil
{
if
err
:=
self
.
sign
(
options
.
From
);
err
!=
nil
{
...
...
whisper/message_test.go
浏览文件 @
7f48eb87
...
...
@@ -4,6 +4,7 @@ import (
"bytes"
"crypto/elliptic"
"testing"
"time"
"github.com/ethereum/go-ethereum/crypto"
)
...
...
@@ -25,6 +26,9 @@ func TestMessageSimpleWrap(t *testing.T) {
if
bytes
.
Compare
(
msg
.
Payload
,
payload
)
!=
0
{
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.
...
...
xeth/whisper_message.go
浏览文件 @
7f48eb87
...
...
@@ -3,6 +3,8 @@
package
xeth
import
(
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/whisper"
...
...
@@ -16,6 +18,8 @@ type WhisperMessage struct {
To
string
`json:"to"`
From
string
`json:"from"`
Sent
int64
`json:"sent"`
TTL
int64
`json:"ttl"`
Hash
string
`json:"hash"`
}
// NewWhisperMessage converts an internal message into an API version.
...
...
@@ -26,6 +30,8 @@ func NewWhisperMessage(message *whisper.Message) WhisperMessage {
Payload
:
common
.
ToHex
(
message
.
Payload
),
From
:
common
.
ToHex
(
crypto
.
FromECDSAPub
(
message
.
Recover
())),
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
()),
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录