Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
6ceb253f
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,发现更多精彩内容 >>
提交
6ceb253f
编写于
4月 15, 2015
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
whisper: use async handshakes to handle blocking peers
上级
46ea193a
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
12 addition
and
47 deletion
+12
-47
whisper/common_test.go
whisper/common_test.go
+0
-40
whisper/peer.go
whisper/peer.go
+11
-6
whisper/whisper_test.go
whisper/whisper_test.go
+1
-1
未找到文件。
whisper/common_test.go
已删除
100644 → 0
浏览文件 @
46ea193a
// Contains some common utility functions for testing.
package
whisper
import
(
"bytes"
"io/ioutil"
"github.com/ethereum/go-ethereum/p2p"
)
// bufMsgPipe creates a buffered message pipe between two endpoints.
func
bufMsgPipe
()
(
*
p2p
.
MsgPipeRW
,
*
p2p
.
MsgPipeRW
)
{
A
,
midA
:=
p2p
.
MsgPipe
()
midB
,
B
:=
p2p
.
MsgPipe
()
go
copyMsgPipe
(
midA
,
midB
)
go
copyMsgPipe
(
midB
,
midA
)
return
A
,
B
}
// copyMsgPipe copies messages from the src pipe to the dest.
func
copyMsgPipe
(
dst
,
src
*
p2p
.
MsgPipeRW
)
{
defer
dst
.
Close
()
for
{
msg
,
err
:=
src
.
ReadMsg
()
if
err
!=
nil
{
return
}
data
,
err
:=
ioutil
.
ReadAll
(
msg
.
Payload
)
if
err
!=
nil
{
return
}
msg
.
Payload
=
bytes
.
NewReader
(
data
)
if
err
:=
dst
.
WriteMsg
(
msg
);
err
!=
nil
{
return
}
}
}
whisper/peer.go
浏览文件 @
6ceb253f
...
...
@@ -53,10 +53,12 @@ func (self *peer) stop() {
// handshake sends the protocol initiation status message to the remote peer and
// verifies the remote status too.
func
(
self
*
peer
)
handshake
()
error
{
// Send own status message, fetch remote one
if
err
:=
p2p
.
SendItems
(
self
.
ws
,
statusCode
,
protocolVersion
);
err
!=
nil
{
return
err
}
// Send the handshake status message asynchronously
errc
:=
make
(
chan
error
,
1
)
go
func
()
{
errc
<-
p2p
.
SendItems
(
self
.
ws
,
statusCode
,
protocolVersion
)
}()
// Fetch the remote status packet and verify protocol match
packet
,
err
:=
self
.
ws
.
ReadMsg
()
if
err
!=
nil
{
return
err
...
...
@@ -64,7 +66,6 @@ func (self *peer) handshake() error {
if
packet
.
Code
!=
statusCode
{
return
fmt
.
Errorf
(
"peer sent %x before status packet"
,
packet
.
Code
)
}
// Decode the rest of the status packet and verify protocol match
s
:=
rlp
.
NewStream
(
packet
.
Payload
)
if
_
,
err
:=
s
.
List
();
err
!=
nil
{
return
fmt
.
Errorf
(
"bad status message: %v"
,
err
)
...
...
@@ -76,7 +77,11 @@ func (self *peer) handshake() error {
if
peerVersion
!=
protocolVersion
{
return
fmt
.
Errorf
(
"protocol version mismatch %d != %d"
,
peerVersion
,
protocolVersion
)
}
return
packet
.
Discard
()
// ignore anything after protocol version
// Wait until out own status is consumed too
if
err
:=
<-
errc
;
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to send status packet: %v"
,
err
)
}
return
nil
}
// update executes periodic operations on the peer, including message transmission
...
...
whisper/whisper_test.go
浏览文件 @
6ceb253f
...
...
@@ -21,7 +21,7 @@ func startTestCluster(n int) []*Whisper {
}
// Wire all the peers to the root one
for
i
:=
1
;
i
<
n
;
i
++
{
src
,
dst
:=
buf
MsgPipe
()
src
,
dst
:=
p2p
.
MsgPipe
()
go
whispers
[
0
]
.
handlePeer
(
nodes
[
i
],
src
)
go
whispers
[
i
]
.
handlePeer
(
nodes
[
0
],
dst
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录