diff options
author | zelig <viktor.tron@gmail.com> | 2015-03-20 06:46:54 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-03-20 18:41:40 +0800 |
commit | 50661f0e683b4975894a0e8fe16024724adef72d (patch) | |
tree | 1a7769500acdd3d2b5815c472b7e6701e8ae2d8f /blockpool/blockpool.go | |
parent | 01ff0b3176e6d83dcc5e6716f04301de71e3fc9e (diff) | |
download | dexon-50661f0e683b4975894a0e8fe16024724adef72d.tar.gz dexon-50661f0e683b4975894a0e8fe16024724adef72d.tar.zst dexon-50661f0e683b4975894a0e8fe16024724adef72d.zip |
peer suspension to disallow reconnect after disconnect on fatal error for set period (PeerSuspensionInterval)
Diffstat (limited to 'blockpool/blockpool.go')
-rw-r--r-- | blockpool/blockpool.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/blockpool/blockpool.go b/blockpool/blockpool.go index c5af481a7..ef619b27b 100644 --- a/blockpool/blockpool.go +++ b/blockpool/blockpool.go @@ -33,7 +33,8 @@ var ( // timeout interval: max time allowed for peer without sending a block blocksTimeout = 60 * time.Second // - idleBestPeerTimeout = 120 * time.Second + idleBestPeerTimeout = 120 * time.Second + peerSuspensionInterval = 300 * time.Second ) // config embedded in components, by default fall back to constants @@ -48,6 +49,7 @@ type Config struct { BlockHashesTimeout time.Duration BlocksTimeout time.Duration IdleBestPeerTimeout time.Duration + PeerSuspensionInterval time.Duration } // blockpool errors @@ -96,6 +98,9 @@ func (self *Config) init() { if self.IdleBestPeerTimeout == 0 { self.IdleBestPeerTimeout = idleBestPeerTimeout } + if self.PeerSuspensionInterval == 0 { + self.PeerSuspensionInterval = peerSuspensionInterval + } } // node is the basic unit of the internal model of block chain/tree in the blockpool @@ -188,9 +193,10 @@ func (self *BlockPool) Start() { Errors: errorToString, Level: severity, }, - peers: make(map[string]*peer), - status: self.status, - bp: self, + peers: make(map[string]*peer), + blacklist: make(map[string]time.Time), + status: self.status, + bp: self, } timer := time.NewTicker(3 * time.Second) go func() { @@ -267,7 +273,8 @@ func (self *BlockPool) AddPeer( requestBlocks func([]common.Hash) error, peerError func(*errs.Error), -) (best bool) { +) (best bool, suspended bool) { + return self.peers.addPeer(td, currentBlockHash, peerId, requestBlockHashes, requestBlocks, peerError) } |