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
aac2b6ae
Commit
aac2b6ae
authored
Jun 29, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth: add the blocks from numbers protocol message
parent
5db8f447
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
26 deletions
+43
-26
handler.go
eth/handler.go
+2
-2
peer.go
eth/peer.go
+11
-17
protocol.go
eth/protocol.go
+26
-3
protocol_test.go
eth/protocol_test.go
+4
-4
No files found.
eth/handler.go
View file @
aac2b6ae
...
@@ -240,7 +240,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
...
@@ -240,7 +240,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
pm
.
txpool
.
AddTransactions
(
txs
)
pm
.
txpool
.
AddTransactions
(
txs
)
case
GetBlockHashesMsg
:
case
GetBlockHashesMsg
:
var
request
getBlockHashes
Msg
Data
var
request
getBlockHashesData
if
err
:=
msg
.
Decode
(
&
request
);
err
!=
nil
{
if
err
:=
msg
.
Decode
(
&
request
);
err
!=
nil
{
return
errResp
(
ErrDecode
,
"->msg %v: %v"
,
msg
,
err
)
return
errResp
(
ErrDecode
,
"->msg %v: %v"
,
msg
,
err
)
}
}
...
@@ -368,7 +368,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
...
@@ -368,7 +368,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
case
NewBlockMsg
:
case
NewBlockMsg
:
// Retrieve and decode the propagated block
// Retrieve and decode the propagated block
var
request
newBlock
Msg
Data
var
request
newBlockData
if
err
:=
msg
.
Decode
(
&
request
);
err
!=
nil
{
if
err
:=
msg
.
Decode
(
&
request
);
err
!=
nil
{
return
errResp
(
ErrDecode
,
"%v: %v"
,
msg
,
err
)
return
errResp
(
ErrDecode
,
"%v: %v"
,
msg
,
err
)
}
}
...
...
eth/peer.go
View file @
aac2b6ae
...
@@ -25,19 +25,6 @@ const (
...
@@ -25,19 +25,6 @@ const (
maxKnownBlocks
=
1024
// Maximum block hashes to keep in the known list (prevent DOS)
maxKnownBlocks
=
1024
// Maximum block hashes to keep in the known list (prevent DOS)
)
)
type
statusMsgData
struct
{
ProtocolVersion
uint32
NetworkId
uint32
TD
*
big
.
Int
CurrentBlock
common
.
Hash
GenesisBlock
common
.
Hash
}
type
getBlockHashesMsgData
struct
{
Hash
common
.
Hash
Amount
uint64
}
type
peer
struct
{
type
peer
struct
{
*
p2p
.
Peer
*
p2p
.
Peer
...
@@ -181,8 +168,15 @@ func (p *peer) SendNewBlock(block *types.Block) error {
...
@@ -181,8 +168,15 @@ func (p *peer) SendNewBlock(block *types.Block) error {
// RequestHashes fetches a batch of hashes from a peer, starting at from, going
// RequestHashes fetches a batch of hashes from a peer, starting at from, going
// towards the genesis block.
// towards the genesis block.
func
(
p
*
peer
)
RequestHashes
(
from
common
.
Hash
)
error
{
func
(
p
*
peer
)
RequestHashes
(
from
common
.
Hash
)
error
{
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Peer [%s] fetching hashes (%d) %x...
\n
"
,
p
.
id
,
downloader
.
MaxHashFetch
,
from
[
:
4
])
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Peer [%s] fetching hashes (%d) from %x...
\n
"
,
p
.
id
,
downloader
.
MaxHashFetch
,
from
[
:
4
])
return
p2p
.
Send
(
p
.
rw
,
GetBlockHashesMsg
,
getBlockHashesMsgData
{
from
,
uint64
(
downloader
.
MaxHashFetch
)})
return
p2p
.
Send
(
p
.
rw
,
GetBlockHashesMsg
,
getBlockHashesData
{
from
,
uint64
(
downloader
.
MaxHashFetch
)})
}
// RequestHashesFromNumber fetches a batch of hashes from a peer, starting at the
// requested block number, going upwards towards the genesis block.
func
(
p
*
peer
)
RequestHashesFromNumber
(
from
uint64
)
error
{
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Peer [%s] fetching hashes (%d) from #%d...
\n
"
,
p
.
id
,
downloader
.
MaxHashFetch
,
from
)
return
p2p
.
Send
(
p
.
rw
,
GetBlockHashesFromNumberMsg
,
getBlockHashesFromNumberData
{
from
,
uint64
(
downloader
.
MaxHashFetch
)})
}
}
// RequestBlocks fetches a batch of blocks corresponding to the specified hashes.
// RequestBlocks fetches a batch of blocks corresponding to the specified hashes.
...
@@ -197,7 +191,7 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, genesis common.Hash) err
...
@@ -197,7 +191,7 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, genesis common.Hash) err
// Send out own handshake in a new thread
// Send out own handshake in a new thread
errc
:=
make
(
chan
error
,
1
)
errc
:=
make
(
chan
error
,
1
)
go
func
()
{
go
func
()
{
errc
<-
p2p
.
Send
(
p
.
rw
,
StatusMsg
,
&
status
Msg
Data
{
errc
<-
p2p
.
Send
(
p
.
rw
,
StatusMsg
,
&
statusData
{
ProtocolVersion
:
uint32
(
p
.
version
),
ProtocolVersion
:
uint32
(
p
.
version
),
NetworkId
:
uint32
(
p
.
network
),
NetworkId
:
uint32
(
p
.
network
),
TD
:
td
,
TD
:
td
,
...
@@ -217,7 +211,7 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, genesis common.Hash) err
...
@@ -217,7 +211,7 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, genesis common.Hash) err
return
errResp
(
ErrMsgTooLarge
,
"%v > %v"
,
msg
.
Size
,
ProtocolMaxMsgSize
)
return
errResp
(
ErrMsgTooLarge
,
"%v > %v"
,
msg
.
Size
,
ProtocolMaxMsgSize
)
}
}
// Decode the handshake and make sure everything matches
// Decode the handshake and make sure everything matches
var
status
status
Msg
Data
var
status
statusData
if
err
:=
msg
.
Decode
(
&
status
);
err
!=
nil
{
if
err
:=
msg
.
Decode
(
&
status
);
err
!=
nil
{
return
errResp
(
ErrDecode
,
"msg %v: %v"
,
msg
,
err
)
return
errResp
(
ErrDecode
,
"msg %v: %v"
,
msg
,
err
)
}
}
...
...
eth/protocol.go
View file @
aac2b6ae
...
@@ -28,7 +28,7 @@ const (
...
@@ -28,7 +28,7 @@ const (
GetBlocksMsg
GetBlocksMsg
BlocksMsg
BlocksMsg
NewBlockMsg
NewBlockMsg
BlockHashesFromNumbers
GetBlockHashesFromNumberMsg
)
)
type
errCode
int
type
errCode
int
...
@@ -77,8 +77,31 @@ type chainManager interface {
...
@@ -77,8 +77,31 @@ type chainManager interface {
Status
()
(
td
*
big
.
Int
,
currentBlock
common
.
Hash
,
genesisBlock
common
.
Hash
)
Status
()
(
td
*
big
.
Int
,
currentBlock
common
.
Hash
,
genesisBlock
common
.
Hash
)
}
}
// message structs used for RLP serialization
// statusData is the network packet for the status message.
type
newBlockMsgData
struct
{
type
statusData
struct
{
ProtocolVersion
uint32
NetworkId
uint32
TD
*
big
.
Int
CurrentBlock
common
.
Hash
GenesisBlock
common
.
Hash
}
// getBlockHashesData is the network packet for the hash based block retrieval
// message.
type
getBlockHashesData
struct
{
Hash
common
.
Hash
Amount
uint64
}
// getBlockHashesFromNumberData is the network packet for the number based block
// retrieval message.
type
getBlockHashesFromNumberData
struct
{
Number
uint64
Amount
uint64
}
// newBlockData is the network packet for the block propagation message.
type
newBlockData
struct
{
Block
*
types
.
Block
Block
*
types
.
Block
TD
*
big
.
Int
TD
*
big
.
Int
}
}
eth/protocol_test.go
View file @
aac2b6ae
...
@@ -39,15 +39,15 @@ func TestStatusMsgErrors(t *testing.T) {
...
@@ -39,15 +39,15 @@ func TestStatusMsgErrors(t *testing.T) {
wantError
:
errResp
(
ErrNoStatusMsg
,
"first msg has code 2 (!= 0)"
),
wantError
:
errResp
(
ErrNoStatusMsg
,
"first msg has code 2 (!= 0)"
),
},
},
{
{
code
:
StatusMsg
,
data
:
status
Msg
Data
{
10
,
NetworkId
,
td
,
currentBlock
,
genesis
},
code
:
StatusMsg
,
data
:
statusData
{
10
,
NetworkId
,
td
,
currentBlock
,
genesis
},
wantError
:
errResp
(
ErrProtocolVersionMismatch
,
"10 (!= 0)"
),
wantError
:
errResp
(
ErrProtocolVersionMismatch
,
"10 (!= 0)"
),
},
},
{
{
code
:
StatusMsg
,
data
:
status
Msg
Data
{
uint32
(
ProtocolVersions
[
0
]),
999
,
td
,
currentBlock
,
genesis
},
code
:
StatusMsg
,
data
:
statusData
{
uint32
(
ProtocolVersions
[
0
]),
999
,
td
,
currentBlock
,
genesis
},
wantError
:
errResp
(
ErrNetworkIdMismatch
,
"999 (!= 0)"
),
wantError
:
errResp
(
ErrNetworkIdMismatch
,
"999 (!= 0)"
),
},
},
{
{
code
:
StatusMsg
,
data
:
status
Msg
Data
{
uint32
(
ProtocolVersions
[
0
]),
NetworkId
,
td
,
currentBlock
,
common
.
Hash
{
3
}},
code
:
StatusMsg
,
data
:
statusData
{
uint32
(
ProtocolVersions
[
0
]),
NetworkId
,
td
,
currentBlock
,
common
.
Hash
{
3
}},
wantError
:
errResp
(
ErrGenesisBlockMismatch
,
"0300000000000000000000000000000000000000000000000000000000000000 (!= %x)"
,
genesis
),
wantError
:
errResp
(
ErrGenesisBlockMismatch
,
"0300000000000000000000000000000000000000000000000000000000000000 (!= %x)"
,
genesis
),
},
},
}
}
...
@@ -188,7 +188,7 @@ func newTestPeer(pm *ProtocolManager) (*testPeer, <-chan error) {
...
@@ -188,7 +188,7 @@ func newTestPeer(pm *ProtocolManager) (*testPeer, <-chan error) {
func
(
p
*
testPeer
)
handshake
(
t
*
testing
.
T
)
{
func
(
p
*
testPeer
)
handshake
(
t
*
testing
.
T
)
{
td
,
currentBlock
,
genesis
:=
p
.
pm
.
chainman
.
Status
()
td
,
currentBlock
,
genesis
:=
p
.
pm
.
chainman
.
Status
()
msg
:=
&
status
Msg
Data
{
msg
:=
&
statusData
{
ProtocolVersion
:
uint32
(
p
.
pm
.
protVer
),
ProtocolVersion
:
uint32
(
p
.
pm
.
protVer
),
NetworkId
:
uint32
(
p
.
pm
.
netId
),
NetworkId
:
uint32
(
p
.
pm
.
netId
),
TD
:
td
,
TD
:
td
,
...
...
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