Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
a26c4791
Commit
a26c4791
authored
Sep 17, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added len
parent
9559b532
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
9 deletions
+45
-9
block_pool.go
block_pool.go
+4
-0
peer.go
peer.go
+41
-9
No files found.
block_pool.go
View file @
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
View file @
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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment