diff options
author | zelig <viktor.tron@gmail.com> | 2014-07-21 20:26:29 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2014-07-21 20:26:29 +0800 |
commit | 1e4af85a380977233a3bceaf5e2a020a281aa19a (patch) | |
tree | acf6f1506952e9edc400d3b450d153db90ce536e /ethereum.go | |
parent | 017d36e6b2e127084448dfb38bd1b8de7424e1c9 (diff) | |
parent | 2762ec22d0693b406ead2f0c07b62e9b66d395e4 (diff) | |
download | go-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar go-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar.gz go-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar.bz2 go-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar.lz go-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar.xz go-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar.zst go-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.zip |
merge upstream
Diffstat (limited to 'ethereum.go')
-rw-r--r-- | ethereum.go | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/ethereum.go b/ethereum.go index c2d2f5241..c48ac00e4 100644 --- a/ethereum.go +++ b/ethereum.go @@ -81,6 +81,8 @@ type Ethereum struct { keyManager *ethcrypto.KeyManager clientIdentity ethwire.ClientIdentity + + isUpToDate bool } func New(db ethutil.Database, clientIdentity ethwire.ClientIdentity, keyManager *ethcrypto.KeyManager, caps Caps, usePnp bool) (*Ethereum, error) { @@ -108,6 +110,7 @@ func New(db ethutil.Database, clientIdentity ethwire.ClientIdentity, keyManager nat: nat, keyManager: keyManager, clientIdentity: clientIdentity, + isUpToDate: true, } ethereum.reactor = ethreact.New() @@ -158,7 +161,7 @@ func (s *Ethereum) IsUpToDate() bool { upToDate := true eachPeer(s.peers, func(peer *Peer, e *list.Element) { if atomic.LoadInt32(&peer.connected) == 1 { - if peer.catchingUp == true { + if peer.catchingUp == true && peer.versionKnown { upToDate = false } } @@ -373,6 +376,7 @@ func (s *Ethereum) Start(seed bool) { // Start the reaping processes go s.ReapDeadPeerHandler() + go s.update() if seed { s.Seed() @@ -514,3 +518,23 @@ out: ethlogger.Debugln("succesfully disestablished UPnP port mapping") } } + +func (self *Ethereum) update() { + upToDateTimer := time.NewTicker(1 * time.Second) + +out: + for { + select { + case <-upToDateTimer.C: + if self.IsUpToDate() && !self.isUpToDate { + self.reactor.Post("chainSync", false) + self.isUpToDate = true + } else if !self.IsUpToDate() && self.isUpToDate { + self.reactor.Post("chainSync", true) + self.isUpToDate = false + } + case <-self.quit: + break out + } + } +} |