diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-08-06 17:58:14 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-08-06 18:58:54 +0800 |
commit | c32073b11f12c3735c117b3b3c814505974d5a92 (patch) | |
tree | cfe83a65139ae8160dc7d1bbed8e22c56050bfd3 /miner/remote_agent.go | |
parent | 82ef26f6007986debd6ce082f57050f0c7e36006 (diff) | |
download | dexon-c32073b11f12c3735c117b3b3c814505974d5a92.tar.gz dexon-c32073b11f12c3735c117b3b3c814505974d5a92.tar.zst dexon-c32073b11f12c3735c117b3b3c814505974d5a92.zip |
miner, rpc: added submit hashrate for remote agents
Diffstat (limited to 'miner/remote_agent.go')
-rw-r--r-- | miner/remote_agent.go | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/miner/remote_agent.go b/miner/remote_agent.go index 674ca40ac..5c672a6e0 100644 --- a/miner/remote_agent.go +++ b/miner/remote_agent.go @@ -27,6 +27,11 @@ import ( "github.com/ethereum/go-ethereum/logger/glog" ) +type hashrate struct { + ping time.Time + rate uint64 +} + type RemoteAgent struct { mu sync.Mutex @@ -36,14 +41,24 @@ type RemoteAgent struct { currentWork *Work work map[common.Hash]*Work + + hashrateMu sync.RWMutex + hashrate map[common.Hash]hashrate } func NewRemoteAgent() *RemoteAgent { - agent := &RemoteAgent{work: make(map[common.Hash]*Work)} + agent := &RemoteAgent{work: make(map[common.Hash]*Work), hashrate: make(map[common.Hash]hashrate)} return agent } +func (a *RemoteAgent) SubmitHashrate(id common.Hash, rate uint64) { + a.hashrateMu.Lock() + defer a.hashrateMu.Unlock() + + a.hashrate[id] = hashrate{time.Now(), rate} +} + func (a *RemoteAgent) Work() chan<- *Work { return a.workCh } @@ -63,7 +78,17 @@ func (a *RemoteAgent) Stop() { close(a.workCh) } -func (a *RemoteAgent) GetHashRate() int64 { return 0 } +// GetHashRate returns the accumulated hashrate of all identifier combined +func (a *RemoteAgent) GetHashRate() (tot int64) { + a.hashrateMu.RLock() + defer a.hashrateMu.RUnlock() + + // this could overflow + for _, hashrate := range a.hashrate { + tot += int64(hashrate.rate) + } + return +} func (a *RemoteAgent) GetWork() [3]string { a.mu.Lock() @@ -131,6 +156,14 @@ out: } } a.mu.Unlock() + + a.hashrateMu.Lock() + for id, hashrate := range a.hashrate { + if time.Since(hashrate.ping) > 10*time.Second { + delete(a.hashrate, id) + } + } + a.hashrateMu.Unlock() } } } |