提交 326e6f2a 作者: Brian Tiger Chow

use rate-limiter

@jbenet
上级 ed019e2f
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
process "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess" process "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
ratelimit "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/ratelimit"
blocks "github.com/jbenet/go-ipfs/blocks" blocks "github.com/jbenet/go-ipfs/blocks"
exchange "github.com/jbenet/go-ipfs/exchange" exchange "github.com/jbenet/go-ipfs/exchange"
util "github.com/jbenet/go-ipfs/util" util "github.com/jbenet/go-ipfs/util"
...@@ -124,6 +125,7 @@ func (w *Worker) start(c Config) { ...@@ -124,6 +125,7 @@ func (w *Worker) start(c Config) {
cancel() cancel()
}) })
limiter := ratelimit.NewRateLimiter(proc, c.NumWorkers)
for { for {
select { select {
case <-proc.Closing(): case <-proc.Closing():
...@@ -132,9 +134,11 @@ func (w *Worker) start(c Config) { ...@@ -132,9 +134,11 @@ func (w *Worker) start(c Config) {
if !ok { if !ok {
return return
} }
if err := w.exchange.HasBlock(ctx, block); err != nil { limiter.LimitedGo(func(proc process.Process) {
// TODO log event? if err := w.exchange.HasBlock(ctx, block); err != nil {
} // TODO log event?
}
})
} }
} }
}) })
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论