aboutsummaryrefslogtreecommitdiffstats
path: root/eth/handler.go
diff options
context:
space:
mode:
authorzsfelfoldi <zsfelfoldi@gmail.com>2016-01-14 02:35:48 +0800
committerFelix Lange <fjl@twurst.com>2016-11-09 09:12:53 +0800
commit7db7109a5b53c339f00e9c05ac826b3dbd1f98e1 (patch)
treec447d9816c4490e71cb2a8d2420d82f938d8757a /eth/handler.go
parent9f8d192991c4f68fa14c91366722bbca601da117 (diff)
downloadgo-tangerine-7db7109a5b53c339f00e9c05ac826b3dbd1f98e1.tar.gz
go-tangerine-7db7109a5b53c339f00e9c05ac826b3dbd1f98e1.tar.zst
go-tangerine-7db7109a5b53c339f00e9c05ac826b3dbd1f98e1.zip
cmd, eth: added light client and light server modes
Diffstat (limited to 'eth/handler.go')
-rw-r--r--eth/handler.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/eth/handler.go b/eth/handler.go
index e478990f7..9d6b1ced2 100644
--- a/eth/handler.go
+++ b/eth/handler.go
@@ -68,6 +68,7 @@ type ProtocolManager struct {
blockchain *core.BlockChain
chaindb ethdb.Database
chainconfig *core.ChainConfig
+ maxPeers int
downloader *downloader.Downloader
fetcher *fetcher.Fetcher
@@ -94,7 +95,7 @@ type ProtocolManager struct {
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
// with the ethereum network.
-func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, blockchain *core.BlockChain, chaindb ethdb.Database) (*ProtocolManager, error) {
+func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int, maxPeers int, mux *event.TypeMux, txpool txPool, pow pow.PoW, blockchain *core.BlockChain, chaindb ethdb.Database) (*ProtocolManager, error) {
// Create the protocol manager with the base fields
manager := &ProtocolManager{
networkId: networkId,
@@ -103,6 +104,7 @@ func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int,
blockchain: blockchain,
chaindb: chaindb,
chainconfig: config,
+ maxPeers: maxPeers,
peers: newPeerSet(),
newPeerCh: make(chan *peer),
noMorePeers: make(chan struct{}),
@@ -156,7 +158,7 @@ func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int,
return nil, errIncompatibleConfig
}
// Construct the different synchronisation mechanisms
- manager.downloader = downloader.New(chaindb, manager.eventMux, blockchain.HasHeader, blockchain.HasBlockAndState, blockchain.GetHeaderByHash,
+ manager.downloader = downloader.New(downloader.FullSync, chaindb, manager.eventMux, blockchain.HasHeader, blockchain.HasBlockAndState, blockchain.GetHeaderByHash,
blockchain.GetBlockByHash, blockchain.CurrentHeader, blockchain.CurrentBlock, blockchain.CurrentFastBlock, blockchain.FastSyncCommitHead,
blockchain.GetTdByHash, blockchain.InsertHeaderChain, manager.insertChain, blockchain.InsertReceiptChain, blockchain.Rollback,
manager.removePeer)
@@ -253,6 +255,10 @@ func (pm *ProtocolManager) newPeer(pv int, p *p2p.Peer, rw p2p.MsgReadWriter) *p
// handle is the callback invoked to manage the life cycle of an eth peer. When
// this function terminates, the peer is disconnected.
func (pm *ProtocolManager) handle(p *peer) error {
+ if pm.peers.Len() >= pm.maxPeers {
+ return p2p.DiscTooManyPeers
+ }
+
glog.V(logger.Debug).Infof("%v: peer connected [%s]", p, p.Name())
// Execute the Ethereum handshake