client.go | 4 ++-- connection_test.go | 13 +++++++------ misc.go | 3 +++ diff --git a/client.go b/client.go index 8b8f9b4f86bd90db09df81f46bba4a42fb9c5f02..5f28b12d078833232158e2920991316a4813a4ef 100644 --- a/client.go +++ b/client.go @@ -192,12 +192,12 @@ } cl.Close() }() if cfg.UploadRateLimiter == nil { - cl.uploadLimit = rate.NewLimiter(rate.Inf, 0) + cl.uploadLimit = unlimited } else { cl.uploadLimit = cfg.UploadRateLimiter } if cfg.DownloadRateLimiter == nil { - cl.downloadLimit = rate.NewLimiter(rate.Inf, 0) + cl.downloadLimit = unlimited } else { cl.downloadLimit = cfg.DownloadRateLimiter } diff --git a/connection_test.go b/connection_test.go index 6b4ccd6b349df5e968d00821f3a7dd190ca58a2d..92af06819e89c651e9f50bb4d3d265a5465fbdd4 100644 --- a/connection_test.go +++ b/connection_test.go @@ -2,6 +2,7 @@ package torrent import ( "io" + "net" "sync" "testing" "time" @@ -85,7 +86,9 @@ return len(b), nil } func BenchmarkConnectionMainReadLoop(b *testing.B) { - cl := &Client{} + cl := &Client{ + downloadLimit: unlimited, + } ts := &torrentStorage{} t := &Torrent{ cl: cl, @@ -99,11 +102,9 @@ PieceLength: 1 << 20, })) t.setChunkSize(defaultChunkSize) t.pendingPieces.Set(0, PiecePriorityNormal.BitmapPriority()) - r, w := io.Pipe() - cn := &connection{ - t: t, - r: r, - } + r, w := net.Pipe() + cn := cl.newConnection(r) + cn.setTorrent(t) mrlErr := make(chan error) cl.mu.Lock() go func() { diff --git a/misc.go b/misc.go index 6fdb77c0d34d5c3d42ac0d2571ff3fcd2d5453a4..10df12447466360a6715cffd0c775bdab0970122 100644 --- a/misc.go +++ b/misc.go @@ -7,6 +7,7 @@ "github.com/anacrolix/missinggo" "github.com/anacrolix/torrent/metainfo" pp "github.com/anacrolix/torrent/peer_protocol" + "golang.org/x/time/rate" ) type chunkSpec struct { @@ -165,3 +166,5 @@ } } return ret } + +var unlimited = rate.NewLimiter(rate.Inf, 0)