Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
d2d5dbc6
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,体验更适合开发者的 AI 搜索 >>
提交
d2d5dbc6
编写于
5月 13, 2015
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
eth/downloader: fix active peer shadowing, polish func names
上级
6dec9046
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
16 addition
and
24 deletion
+16
-24
eth/downloader/downloader.go
eth/downloader/downloader.go
+10
-18
eth/downloader/downloader_test.go
eth/downloader/downloader_test.go
+4
-4
eth/handler.go
eth/handler.go
+2
-2
未找到文件。
eth/downloader/downloader.go
浏览文件 @
d2d5dbc6
...
...
@@ -55,10 +55,9 @@ type hashPack struct {
}
type
Downloader
struct
{
mu
sync
.
RWMutex
queue
*
queue
peers
*
peerSet
activePeer
string
mu
sync
.
RWMutex
queue
*
queue
peers
*
peerSet
// Callbacks
hasBlock
hashCheckFn
...
...
@@ -162,7 +161,6 @@ func (d *Downloader) Has(hash common.Hash) bool {
// syncWithPeer starts a block synchronization based on the hash chain from the
// specified peer and head hash.
func
(
d
*
Downloader
)
syncWithPeer
(
p
*
peer
,
hash
common
.
Hash
)
(
err
error
)
{
d
.
activePeer
=
p
.
id
defer
func
()
{
// reset on error
if
err
!=
nil
{
...
...
@@ -416,32 +414,26 @@ out:
return
nil
}
// Deliver
a chunk to the downloader. This is usually done through the BlocksMsg by
// the protocol handler.
func
(
d
*
Downloader
)
Deliver
Chunk
(
id
string
,
blocks
[]
*
types
.
Block
)
error
{
// Deliver
Blocks injects a new batch of blocks received from a remote node.
//
This is usually invoked through the BlocksMsg by
the protocol handler.
func
(
d
*
Downloader
)
Deliver
Blocks
(
id
string
,
blocks
[]
*
types
.
Block
)
error
{
// Make sure the downloader is active
if
atomic
.
LoadInt32
(
&
d
.
synchronising
)
==
0
{
return
errNoSyncActive
}
d
.
blockCh
<-
blockPack
{
id
,
blocks
}
return
nil
}
func
(
d
*
Downloader
)
AddHashes
(
id
string
,
hashes
[]
common
.
Hash
)
error
{
// DeliverHashes injects a new batch of hashes received from a remote node into
// the download schedule. This is usually invoked through the BlockHashesMsg by
// the protocol handler.
func
(
d
*
Downloader
)
DeliverHashes
(
id
string
,
hashes
[]
common
.
Hash
)
error
{
// Make sure the downloader is active
if
atomic
.
LoadInt32
(
&
d
.
synchronising
)
==
0
{
return
errNoSyncActive
}
// make sure that the hashes that are being added are actually from the peer
// that's the current active peer. hashes that have been received from other
// peers are dropped and ignored.
if
d
.
activePeer
!=
id
{
return
fmt
.
Errorf
(
"received hashes from %s while active peer is %s"
,
id
,
d
.
activePeer
)
}
if
glog
.
V
(
logger
.
Debug
)
&&
len
(
hashes
)
!=
0
{
from
,
to
:=
hashes
[
0
],
hashes
[
len
(
hashes
)
-
1
]
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"adding %d (T=%d) hashes [ %x / %x ] from: %s
\n
"
,
len
(
hashes
),
d
.
queue
.
Pending
(),
from
[
:
4
],
to
[
:
4
],
id
)
...
...
eth/downloader/downloader_test.go
浏览文件 @
d2d5dbc6
...
...
@@ -76,7 +76,7 @@ func (dl *downloadTester) getBlock(hash common.Hash) *types.Block {
}
func
(
dl
*
downloadTester
)
getHashes
(
hash
common
.
Hash
)
error
{
dl
.
downloader
.
Add
Hashes
(
dl
.
activePeerId
,
dl
.
hashes
)
dl
.
downloader
.
Deliver
Hashes
(
dl
.
activePeerId
,
dl
.
hashes
)
return
nil
}
...
...
@@ -87,7 +87,7 @@ func (dl *downloadTester) getBlocks(id string) func([]common.Hash) error {
blocks
[
i
]
=
dl
.
blocks
[
hash
]
}
go
dl
.
downloader
.
Deliver
Chunk
(
id
,
blocks
)
go
dl
.
downloader
.
Deliver
Blocks
(
id
,
blocks
)
return
nil
}
...
...
@@ -188,12 +188,12 @@ func TestInactiveDownloader(t *testing.T) {
blocks
:=
createBlocksFromHashSet
(
createHashSet
(
hashes
))
tester
:=
newTester
(
t
,
hashes
,
nil
)
err
:=
tester
.
downloader
.
Add
Hashes
(
"bad peer 001"
,
hashes
)
err
:=
tester
.
downloader
.
Deliver
Hashes
(
"bad peer 001"
,
hashes
)
if
err
!=
errNoSyncActive
{
t
.
Error
(
"expected no sync error, got"
,
err
)
}
err
=
tester
.
downloader
.
Deliver
Chunk
(
"bad peer 001"
,
blocks
)
err
=
tester
.
downloader
.
Deliver
Blocks
(
"bad peer 001"
,
blocks
)
if
err
!=
errNoSyncActive
{
t
.
Error
(
"expected no sync error, got"
,
err
)
}
...
...
eth/handler.go
浏览文件 @
d2d5dbc6
...
...
@@ -224,7 +224,7 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
if
err
:=
msgStream
.
Decode
(
&
hashes
);
err
!=
nil
{
break
}
err
:=
self
.
downloader
.
Add
Hashes
(
p
.
id
,
hashes
)
err
:=
self
.
downloader
.
Deliver
Hashes
(
p
.
id
,
hashes
)
if
err
!=
nil
{
glog
.
V
(
logger
.
Debug
)
.
Infoln
(
err
)
}
...
...
@@ -264,7 +264,7 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
glog
.
V
(
logger
.
Detail
)
.
Infoln
(
"Decode error"
,
err
)
blocks
=
nil
}
self
.
downloader
.
Deliver
Chunk
(
p
.
id
,
blocks
)
self
.
downloader
.
Deliver
Blocks
(
p
.
id
,
blocks
)
case
NewBlockMsg
:
var
request
newBlockMsgData
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录