aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/peer.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-19 00:54:57 +0800
committerobscuren <geffobscura@gmail.com>2015-04-19 00:55:13 +0800
commitc2c24b3bb419a8ffffb58ec25788b951bef779f9 (patch)
tree1d646493e36a0056b1d34fc8e876a9a5123c3fa2 /eth/downloader/peer.go
parent60613b57d1956275bb475a53b5085c4ead4ceb2c (diff)
downloaddexon-c2c24b3bb419a8ffffb58ec25788b951bef779f9.tar.gz
dexon-c2c24b3bb419a8ffffb58ec25788b951bef779f9.tar.zst
dexon-c2c24b3bb419a8ffffb58ec25788b951bef779f9.zip
downloader: improved downloading and synchronisation
* Downloader's peers keeps track of peer's previously requested hashes so that we don't have to re-request * Changed `AddBlock` to be fully synchronous
Diffstat (limited to 'eth/downloader/peer.go')
-rw-r--r--eth/downloader/peer.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/eth/downloader/peer.go b/eth/downloader/peer.go
index 4cd306a05..5d5208e8e 100644
--- a/eth/downloader/peer.go
+++ b/eth/downloader/peer.go
@@ -6,6 +6,7 @@ import (
"sync"
"github.com/ethereum/go-ethereum/common"
+ "gopkg.in/fatih/set.v0"
)
const (
@@ -64,13 +65,23 @@ type peer struct {
td *big.Int
recentHash common.Hash
+ requested *set.Set
+
getHashes hashFetcherFn
getBlocks blockFetcherFn
}
// create a new peer
func newPeer(id string, td *big.Int, hash common.Hash, getHashes hashFetcherFn, getBlocks blockFetcherFn) *peer {
- return &peer{id: id, td: td, recentHash: hash, getHashes: getHashes, getBlocks: getBlocks, state: idleState}
+ return &peer{
+ id: id,
+ td: td,
+ recentHash: hash,
+ getHashes: getHashes,
+ getBlocks: getBlocks,
+ state: idleState,
+ requested: set.New(),
+ }
}
// fetch a chunk using the peer
@@ -82,6 +93,8 @@ func (p *peer) fetch(chunk *chunk) error {
return errors.New("peer already fetching chunk")
}
+ p.requested.Merge(chunk.hashes)
+
// set working state
p.state = workingState
// convert the set to a fetchable slice