Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
c43db8a2
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,发现更多精彩内容 >>
提交
c43db8a2
编写于
10月 23, 2015
作者:
J
Jeffrey Wilcke
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1924 from fjl/eth-status-timeout
eth: time out status message exchange after 5s
上级
0aeab5fd
3cf74336
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
9 deletion
+27
-9
eth/peer.go
eth/peer.go
+27
-9
未找到文件。
eth/peer.go
浏览文件 @
c43db8a2
...
...
@@ -21,6 +21,7 @@ import (
"fmt"
"math/big"
"sync"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
...
...
@@ -38,8 +39,9 @@ var (
)
const
(
maxKnownTxs
=
32768
// Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownBlocks
=
1024
// Maximum block hashes to keep in the known list (prevent DOS)
maxKnownTxs
=
32768
// Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownBlocks
=
1024
// Maximum block hashes to keep in the known list (prevent DOS)
handshakeTimeout
=
5
*
time
.
Second
)
type
peer
struct
{
...
...
@@ -267,8 +269,8 @@ func (p *peer) RequestReceipts(hashes []common.Hash) error {
// Handshake executes the eth protocol handshake, negotiating version number,
// network IDs, difficulties, head and genesis blocks.
func
(
p
*
peer
)
Handshake
(
td
*
big
.
Int
,
head
common
.
Hash
,
genesis
common
.
Hash
)
error
{
// Send out own handshake in a new thread
errc
:=
make
(
chan
error
,
1
)
errc
:=
make
(
chan
error
,
2
)
var
status
statusData
// safe to read after two values have been received from errc
go
func
()
{
errc
<-
p2p
.
Send
(
p
.
rw
,
StatusMsg
,
&
statusData
{
ProtocolVersion
:
uint32
(
p
.
version
),
...
...
@@ -278,7 +280,26 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, genesis common.Hash) err
GenesisBlock
:
genesis
,
})
}()
// In the mean time retrieve the remote status message
go
func
()
{
errc
<-
p
.
readStatus
(
&
status
,
genesis
)
}()
timeout
:=
time
.
NewTimer
(
handshakeTimeout
)
defer
timeout
.
Stop
()
for
i
:=
0
;
i
<
2
;
i
++
{
select
{
case
err
:=
<-
errc
:
if
err
!=
nil
{
return
err
}
case
<-
timeout
.
C
:
return
p2p
.
DiscReadTimeout
}
}
p
.
td
,
p
.
head
=
status
.
TD
,
status
.
CurrentBlock
return
nil
}
func
(
p
*
peer
)
readStatus
(
status
*
statusData
,
genesis
common
.
Hash
)
(
err
error
)
{
msg
,
err
:=
p
.
rw
.
ReadMsg
()
if
err
!=
nil
{
return
err
...
...
@@ -290,7 +311,6 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, genesis common.Hash) err
return
errResp
(
ErrMsgTooLarge
,
"%v > %v"
,
msg
.
Size
,
ProtocolMaxMsgSize
)
}
// Decode the handshake and make sure everything matches
var
status
statusData
if
err
:=
msg
.
Decode
(
&
status
);
err
!=
nil
{
return
errResp
(
ErrDecode
,
"msg %v: %v"
,
msg
,
err
)
}
...
...
@@ -303,9 +323,7 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, genesis common.Hash) err
if
int
(
status
.
ProtocolVersion
)
!=
p
.
version
{
return
errResp
(
ErrProtocolVersionMismatch
,
"%d (!= %d)"
,
status
.
ProtocolVersion
,
p
.
version
)
}
// Configure the remote peer, and sanity check out handshake too
p
.
td
,
p
.
head
=
status
.
TD
,
status
.
CurrentBlock
return
<-
errc
return
nil
}
// String implements fmt.Stringer.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录