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
c4f22493
Commit
c4f22493
authored
Jun 08, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/downloader: reject peer registration if head is banned
parent
63c6cedb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
downloader.go
eth/downloader/downloader.go
+15
-4
No files found.
eth/downloader/downloader.go
View file @
c4f22493
...
...
@@ -36,6 +36,7 @@ var (
errUnknownPeer
=
errors
.
New
(
"peer is unknown or unhealthy"
)
ErrBadPeer
=
errors
.
New
(
"action from bad peer ignored"
)
ErrStallingPeer
=
errors
.
New
(
"peer is stalling"
)
errBannedHead
=
errors
.
New
(
"peer head hash already banned"
)
errNoPeers
=
errors
.
New
(
"no peers to keep download active"
)
ErrPendingQueue
=
errors
.
New
(
"pending items in queue"
)
ErrTimeout
=
errors
.
New
(
"timeout"
)
...
...
@@ -72,11 +73,10 @@ type crossCheck struct {
type
Downloader
struct
{
mux
*
event
.
TypeMux
mu
sync
.
RWMutex
queue
*
queue
// Scheduler for selecting the hashes to download
peers
*
peerSet
// Set of active peers from which download can proceed
checks
map
[
common
.
Hash
]
*
crossCheck
// Pending cross checks to verify a hash chain
banned
*
set
.
Set
NonTS
// Set of hashes we've received and banned
banned
*
set
.
Set
// Set of hashes we've received and banned
// Callbacks
hasBlock
hashCheckFn
...
...
@@ -114,7 +114,7 @@ func New(mux *event.TypeMux, hasBlock hashCheckFn, getBlock getBlockFn) *Downloa
blockCh
:
make
(
chan
blockPack
,
1
),
}
// Inject all the known bad hashes
downloader
.
banned
=
set
.
New
NonTS
()
downloader
.
banned
=
set
.
New
()
for
hash
,
_
:=
range
core
.
BadHashes
{
downloader
.
banned
.
Add
(
hash
)
}
...
...
@@ -133,6 +133,12 @@ func (d *Downloader) Synchronising() bool {
// RegisterPeer injects a new download peer into the set of block source to be
// used for fetching hashes and blocks from.
func
(
d
*
Downloader
)
RegisterPeer
(
id
string
,
head
common
.
Hash
,
getHashes
hashFetcherFn
,
getBlocks
blockFetcherFn
)
error
{
// If the peer wants to send a banned hash, reject
if
d
.
banned
.
Has
(
head
)
{
glog
.
V
(
logger
.
Debug
)
.
Infoln
(
"Register rejected, head hash banned:"
,
id
)
return
errBannedHead
}
// Otherwise try to construct and register the peer
glog
.
V
(
logger
.
Detail
)
.
Infoln
(
"Registering peer"
,
id
)
if
err
:=
d
.
peers
.
Register
(
newPeer
(
id
,
head
,
getHashes
,
getBlocks
));
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infoln
(
"Register failed:"
,
err
)
...
...
@@ -199,6 +205,8 @@ func (d *Downloader) TakeBlocks() []*Block {
return
d
.
queue
.
TakeBlocks
()
}
// Has checks if the downloader knows about a particular hash, meaning that its
// either already downloaded of pending retrieval.
func
(
d
*
Downloader
)
Has
(
hash
common
.
Hash
)
bool
{
return
d
.
queue
.
Has
(
hash
)
}
...
...
@@ -604,14 +612,17 @@ func (d *Downloader) banBlocks(peerId string, head common.Hash) error {
// Ban the head hash and phase out any excess
d
.
banned
.
Add
(
blocks
[
index
]
.
Hash
())
for
d
.
banned
.
Size
()
>
maxBannedHashes
{
var
evacuate
common
.
Hash
d
.
banned
.
Each
(
func
(
item
interface
{})
bool
{
// Skip any hard coded bans
if
core
.
BadHashes
[
item
.
(
common
.
Hash
)]
{
return
true
}
d
.
banned
.
Remove
(
item
)
evacuate
=
item
.
(
common
.
Hash
)
return
false
})
d
.
banned
.
Remove
(
evacuate
)
}
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Banned %d blocks from: %s"
,
index
+
1
,
peerId
)
return
nil
...
...
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