Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
a26c4791
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,发现更多精彩内容 >>
提交
a26c4791
编写于
9月 17, 2014
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added len
上级
9559b532
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
9 deletion
+45
-9
block_pool.go
block_pool.go
+4
-0
peer.go
peer.go
+41
-9
未找到文件。
block_pool.go
浏览文件 @
a26c4791
...
...
@@ -33,6 +33,10 @@ func NewBlockPool(eth *Ethereum) *BlockPool {
}
}
func
(
self
*
BlockPool
)
Len
()
int
{
return
len
(
self
.
hashPool
)
}
func
(
self
*
BlockPool
)
HasLatestHash
()
bool
{
return
self
.
pool
[
string
(
self
.
eth
.
BlockChain
()
.
CurrentBlock
.
Hash
())]
!=
nil
}
...
...
peer.go
浏览文件 @
a26c4791
...
...
@@ -287,7 +287,7 @@ func (p *Peer) writeMessage(msg *ethwire.Msg) {
*/
}
peerlogger
.
DebugDetailf
(
"(%v) <= %v
%v
\n
"
,
p
.
conn
.
RemoteAddr
(),
msg
.
Type
,
msg
.
Data
)
peerlogger
.
DebugDetailf
(
"(%v) <= %v
\n
"
,
p
.
conn
.
RemoteAddr
(),
formatMessage
(
msg
)
)
err
:=
ethwire
.
WriteMessage
(
p
.
conn
,
msg
)
if
err
!=
nil
{
...
...
@@ -351,6 +351,27 @@ clean:
}
}
func
formatMessage
(
msg
*
ethwire
.
Msg
)
(
ret
string
)
{
ret
=
fmt
.
Sprintf
(
"%v "
,
msg
.
Type
)
/*
XXX Commented out because I need the log level here to determine
if i should or shouldn't generate this message
*/
switch
msg
.
Type
{
case
ethwire
.
MsgPeersTy
:
ret
+=
fmt
.
Sprintf
(
"(%d entries)"
,
msg
.
Data
.
Len
())
case
ethwire
.
MsgBlockTy
:
b1
,
b2
:=
ethchain
.
NewBlockFromRlpValue
(
msg
.
Data
.
Get
(
0
)),
ethchain
.
NewBlockFromRlpValue
(
msg
.
Data
.
Get
(
msg
.
Data
.
Len
()
-
1
))
ret
+=
fmt
.
Sprintf
(
"(%d entries) %x - %x"
,
msg
.
Data
.
Len
(),
b1
.
Hash
()[
0
:
4
],
b2
.
Hash
()[
0
:
4
])
case
ethwire
.
MsgBlockHashesTy
:
h1
,
h2
:=
msg
.
Data
.
Get
(
0
)
.
Bytes
(),
msg
.
Data
.
Get
(
msg
.
Data
.
Len
()
-
1
)
.
Bytes
()
ret
+=
fmt
.
Sprintf
(
"(%d entries) %x - %x"
,
msg
.
Data
.
Len
(),
h1
[
0
:
4
],
h2
[
0
:
4
])
}
return
}
// Inbound handler. Inbound messages are received here and passed to the appropriate methods
func
(
p
*
Peer
)
HandleInbound
()
{
for
atomic
.
LoadInt32
(
&
p
.
disconnect
)
==
0
{
...
...
@@ -363,7 +384,7 @@ func (p *Peer) HandleInbound() {
peerlogger
.
Debugln
(
err
)
}
for
_
,
msg
:=
range
msgs
{
peerlogger
.
DebugDetailf
(
"(%v) => %v
%v
\n
"
,
p
.
conn
.
RemoteAddr
(),
msg
.
Type
,
msg
.
Data
)
peerlogger
.
DebugDetailf
(
"(%v) => %v
\n
"
,
p
.
conn
.
RemoteAddr
(),
formatMessage
(
msg
)
)
switch
msg
.
Type
{
case
ethwire
.
MsgHandshakeTy
:
...
...
@@ -505,7 +526,10 @@ func (p *Peer) HandleInbound() {
if
err
!=
nil
{
peerlogger
.
Infoln
(
err
)
}
else
{
p
.
FetchBlocks
()
// Don't trigger if there's just one block.
if
blockPool
.
Len
()
!=
0
&&
msg
.
Data
.
Len
()
>
1
{
p
.
FetchBlocks
()
}
}
}
}
...
...
@@ -643,7 +667,11 @@ func (self *Peer) handleStatus(msg *ethwire.Msg) {
bestHash
=
c
.
Get
(
3
)
.
Bytes
()
genesis
=
c
.
Get
(
4
)
.
Bytes
()
)
ethlogger
.
Infof
(
"gen = %x
\n
"
,
genesis
)
if
bytes
.
Compare
(
self
.
ethereum
.
BlockChain
()
.
Genesis
()
.
Hash
(),
genesis
)
!=
0
{
ethlogger
.
Warnf
(
"Invalid genisis hash %x. Disabling [ETH]
\n
"
,
genesis
)
return
}
// Get the td and last hash
self
.
td
=
td
...
...
@@ -734,17 +762,21 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
p
.
ethereum
.
PushPeer
(
p
)
p
.
ethereum
.
reactor
.
Post
(
"peerList"
,
p
.
ethereum
.
Peers
())
ethlogger
.
Infof
(
"Added peer (%s) %d / %d (%v)
\n
"
,
p
.
conn
.
RemoteAddr
(),
p
.
ethereum
.
Peers
()
.
Len
(),
p
.
ethereum
.
MaxPeers
,
caps
.
Raw
())
peerlogger
.
Debugln
(
p
)
capsIt
:=
caps
.
NewIterator
()
var
capsStrs
[]
string
for
capsIt
.
Next
()
{
switch
capsIt
.
Value
()
.
Str
()
{
cap
:=
capsIt
.
Value
()
.
Str
()
switch
cap
{
case
"eth"
:
p
.
pushStatus
()
}
capsStrs
=
append
(
capsStrs
,
cap
)
}
ethlogger
.
Infof
(
"Added peer (%s) %d / %d (%v)
\n
"
,
p
.
conn
.
RemoteAddr
(),
p
.
ethereum
.
Peers
()
.
Len
(),
p
.
ethereum
.
MaxPeers
,
capsStrs
)
peerlogger
.
Debugln
(
p
)
}
func
(
p
*
Peer
)
String
()
string
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录