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
3e400739
Commit
3e400739
authored
Jan 28, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented get chain msg
parent
4a82230d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
11 deletions
+33
-11
peer.go
peer.go
+33
-11
No files found.
peer.go
View file @
3e400739
...
...
@@ -178,9 +178,14 @@ out:
// Respond back with pong
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgPongTy
,
""
))
case
ethwire
.
MsgPongTy
:
// If we received a pong back from a peer we set the
// last pong so the peer handler knows this peer is still
// active.
p
.
lastPong
=
time
.
Now
()
.
Unix
()
case
ethwire
.
MsgBlockTy
:
for
i
:=
0
;
i
<
msg
.
Data
.
Length
();
i
++
{
// Get all blocks and process them (TODO reverse order?)
msg
.
Data
=
msg
.
Data
.
Get
(
0
)
for
i
:=
msg
.
Data
.
Length
()
-
1
;
i
>=
0
;
i
--
{
block
:=
ethchain
.
NewBlockFromRlpValue
(
msg
.
Data
.
Get
(
i
))
err
:=
p
.
ethereum
.
BlockManager
.
ProcessBlock
(
block
)
...
...
@@ -189,10 +194,15 @@ out:
}
}
case
ethwire
.
MsgTxTy
:
// If the message was a transaction queue the transaction
// in the TxPool where it will undergo validation and
// processing when a new block is found
for
i
:=
0
;
i
<
msg
.
Data
.
Length
();
i
++
{
p
.
ethereum
.
TxPool
.
QueueTransaction
(
ethchain
.
NewTransactionFromRlpValue
(
msg
.
Data
.
Get
(
i
)))
}
case
ethwire
.
MsgGetPeersTy
:
// Flag this peer as a 'requested of new peers' this to
// prevent malicious peers being forced.
p
.
requestedPeerList
=
true
// Peer asked for list of connected peers
p
.
pushPeers
()
...
...
@@ -214,22 +224,31 @@ out:
p
.
requestedPeerList
=
false
}
case
ethwire
.
MsgGetChainTy
:
blocksFound
:=
0
l
:=
msg
.
Data
.
Length
()
var
parent
*
ethchain
.
Block
// FIXME
msg
.
Data
=
msg
.
Data
.
Get
(
0
)
// Length minus one since the very last element in the array is a count
l
:=
msg
.
Data
.
Length
()
-
1
// Amount of parents in the canonical chain
amountOfBlocks
:=
msg
.
Data
.
Get
(
l
)
.
AsUint
()
// Check each SHA block hash from the message and determine whether
// the SHA is in the database
for
i
:=
0
;
i
<
l
;
i
++
{
if
p
.
ethereum
.
BlockManager
.
BlockChain
()
.
HasBlock
(
msg
.
Data
.
Get
(
i
)
.
AsString
()
)
{
blocksFound
++
// TODO send reply
if
data
:=
msg
.
Data
.
Get
(
i
)
.
AsBytes
();
p
.
ethereum
.
BlockManager
.
BlockChain
()
.
HasBlock
(
data
)
{
parent
=
p
.
ethereum
.
BlockManager
.
BlockChain
()
.
GetBlock
(
data
)
break
}
}
// If no blocks are found we send back a reply with msg not in chain
// and the last hash from get chain
if
blocksFound
==
0
{
lastHash
:=
msg
.
Data
.
Get
(
l
-
1
)
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgNotInChainTy
,
lastHash
))
// If a parent is found send back a reply
if
parent
!=
nil
{
chain
:=
p
.
ethereum
.
BlockManager
.
BlockChain
()
.
GetChainFromHash
(
parent
.
Hash
(),
amountOfBlocks
)
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgBlockTy
,
chain
))
}
else
{
// If no blocks are found we send back a reply with msg not in chain
// and the last hash from get chain
lastHash
:=
msg
.
Data
.
Get
(
l
)
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgNotInChainTy
,
lastHash
.
AsRaw
()))
}
case
ethwire
.
MsgNotInChainTy
:
log
.
Println
(
"Not in chain, not yet implemented"
)
...
...
@@ -320,6 +339,9 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
p
.
Stop
()
}
}
else
{
msg
:=
ethwire
.
NewMessage
(
ethwire
.
MsgGetChainTy
,
[]
interface
{}{
p
.
ethereum
.
BlockManager
.
BlockChain
()
.
CurrentBlock
.
Hash
(),
uint64
(
100
)})
p
.
QueueMessage
(
msg
)
}
}
...
...
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