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
629705ad
Commit
629705ad
authored
Jun 18, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth: clean the block request packet handling a bit
parent
5ec6ecc5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
handler.go
eth/handler.go
+17
-17
No files found.
eth/handler.go
View file @
629705ad
...
@@ -252,33 +252,31 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
...
@@ -252,33 +252,31 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
}
case
GetBlocksMsg
:
case
GetBlocksMsg
:
var
blocks
[]
*
types
.
Block
// Decode the retrieval message
msgStream
:=
rlp
.
NewStream
(
msg
.
Payload
,
uint64
(
msg
.
Size
))
msgStream
:=
rlp
.
NewStream
(
msg
.
Payload
,
uint64
(
msg
.
Size
))
if
_
,
err
:=
msgStream
.
List
();
err
!=
nil
{
if
_
,
err
:=
msgStream
.
List
();
err
!=
nil
{
return
err
return
err
}
}
// Gather blocks until the fetch or network limits is reached
var
(
var
(
i
int
hash
common
.
Hash
totalsize
common
.
StorageSize
bytes
common
.
StorageSize
blocks
[]
*
types
.
Block
)
)
for
{
for
{
i
++
var
hash
common
.
Hash
err
:=
msgStream
.
Decode
(
&
hash
)
err
:=
msgStream
.
Decode
(
&
hash
)
if
err
==
rlp
.
EOL
{
if
err
==
rlp
.
EOL
{
break
break
}
else
if
err
!=
nil
{
}
else
if
err
!=
nil
{
return
errResp
(
ErrDecode
,
"msg %v: %v"
,
msg
,
err
)
return
errResp
(
ErrDecode
,
"msg %v: %v"
,
msg
,
err
)
}
}
// Retrieve the requested block, stopping if enough was found
block
:=
pm
.
chainman
.
GetBlock
(
hash
)
if
block
:=
pm
.
chainman
.
GetBlock
(
hash
);
block
!=
nil
{
if
block
!=
nil
{
blocks
=
append
(
blocks
,
block
)
blocks
=
append
(
blocks
,
block
)
totalsize
+=
block
.
Size
()
bytes
+=
block
.
Size
()
}
if
len
(
blocks
)
>=
downloader
.
MaxBlockFetch
||
bytes
>
maxBlockRespSize
{
if
i
==
downloader
.
MaxBlockFetch
||
totalsize
>
maxBlockRespSize
{
break
break
}
}
}
}
}
return
p
.
sendBlocks
(
blocks
)
return
p
.
sendBlocks
(
blocks
)
...
@@ -360,8 +358,10 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
...
@@ -360,8 +358,10 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
// BroadcastBlock will propagate the block to a subset of its connected peers,
// BroadcastBlock will propagate the block to a subset of its connected peers,
// only notifying the rest of the block's appearance.
// only notifying the rest of the block's appearance.
func
(
pm
*
ProtocolManager
)
BroadcastBlock
(
block
*
types
.
Block
)
{
func
(
pm
*
ProtocolManager
)
BroadcastBlock
(
block
*
types
.
Block
)
{
hash
:=
block
.
Hash
()
// Retrieve all the target peers and split between full broadcast or only notification
// Retrieve all the target peers and split between full broadcast or only notification
peers
:=
pm
.
peers
.
PeersWithoutBlock
(
block
.
Hash
()
)
peers
:=
pm
.
peers
.
PeersWithoutBlock
(
hash
)
split
:=
int
(
math
.
Sqrt
(
float64
(
len
(
peers
))))
split
:=
int
(
math
.
Sqrt
(
float64
(
len
(
peers
))))
transfer
:=
peers
[
:
split
]
transfer
:=
peers
[
:
split
]
...
@@ -369,14 +369,14 @@ func (pm *ProtocolManager) BroadcastBlock(block *types.Block) {
...
@@ -369,14 +369,14 @@ func (pm *ProtocolManager) BroadcastBlock(block *types.Block) {
// Send out the data transfers and the notifications
// Send out the data transfers and the notifications
for
_
,
peer
:=
range
notify
{
for
_
,
peer
:=
range
notify
{
peer
.
sendNewBlockHashes
([]
common
.
Hash
{
block
.
Hash
()
})
peer
.
sendNewBlockHashes
([]
common
.
Hash
{
hash
})
}
}
glog
.
V
(
logger
.
Detail
)
.
Info
ln
(
"broadcast hash to"
,
len
(
notify
),
"peers."
)
glog
.
V
(
logger
.
Detail
)
.
Info
f
(
"broadcast hash %x to %d peers."
,
hash
[
:
4
],
len
(
notify
)
)
for
_
,
peer
:=
range
transfer
{
for
_
,
peer
:=
range
transfer
{
peer
.
sendNewBlock
(
block
)
peer
.
sendNewBlock
(
block
)
}
}
glog
.
V
(
logger
.
Detail
)
.
Info
ln
(
"broadcast block to"
,
len
(
transfer
),
"peers. Total processing time:"
,
time
.
Since
(
block
.
ReceivedAt
))
glog
.
V
(
logger
.
Detail
)
.
Info
f
(
"broadcast block %x to %d peers. Total processing time: %v"
,
hash
[
:
4
],
len
(
transfer
)
,
time
.
Since
(
block
.
ReceivedAt
))
}
}
// BroadcastTx will propagate the block to its connected peers. It will sort
// BroadcastTx will propagate the block to its connected peers. It will sort
...
...
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