"testing"
"github.com/anacrolix/dht/v2/krpc"
- "github.com/bradfitz/iter"
-
"github.com/anacrolix/torrent/bencode"
)
}
tb.ReportAllocs()
tb.ResetTimer()
- for range iter.N(tb.N) {
+ for i := 0; i < tb.N; i += 1 {
marshalAndUnmarshal(tb, orig)
}
}
"testing/iotest"
"time"
- "github.com/bradfitz/iter"
"github.com/frankban/quicktest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
cl, err := NewClient(TestingConfig(t))
require.NoError(t, err)
defer cl.Close()
- for i := range iter.N(1000) {
+ for i := 0; i < 1000; i += 1 {
var spec TorrentSpec
binary.PutVarint(spec.InfoHash[:], int64(i))
tt, new, err := cl.AddTorrentSpec(&spec)
require.NoError(b, err)
defer cl.Close()
b.ReportAllocs()
- for range iter.N(b.N) {
+ for i := 0; i < b.N; i += 1 {
t, err := cl.AddTorrentFromFile("testdata/bootstrap.dat.torrent")
if err != nil {
b.Fatal(err)
}
func writeTorrentData(ts *storage.Torrent, info metainfo.Info, b []byte) {
- for i := range iter.N(info.NumPieces()) {
+ for i := 0; i < info.NumPieces(); i += 1 {
p := info.Piece(i)
ts.Piece(p).WriteAt(b[p.Offset():p.Offset()+p.Length()], 0)
}
cfg := TestingConfig(t)
cfg.DisableAcceptRateLimiting = true
cfg.DropDuplicatePeerIds = true
- for i := range iter.N(3) {
+ for i := 0; i < 3; i += 1 {
cl, err := NewClient(cfg)
require.NoError(t, err)
defer cl.Close()
"github.com/anacrolix/envpprof"
"github.com/anacrolix/tagflag"
- "github.com/bradfitz/iter"
"github.com/anacrolix/torrent/metainfo"
)
}
if flags.PieceHashes {
d["PieceHashes"] = func() (ret []string) {
- for i := range iter.N(info.NumPieces()) {
+ for i, numPieces := 0, info.NumPieces(); i < numPieces; i += 1 {
ret = append(ret, hex.EncodeToString(info.Pieces[i*20:(i+1)*20]))
}
return
"path/filepath"
"github.com/anacrolix/tagflag"
- "github.com/bradfitz/iter"
"github.com/edsrzf/mmap-go"
"github.com/anacrolix/torrent/metainfo"
span.Append(mm)
}
span.InitIndex()
- for i := range iter.N(info.NumPieces()) {
+ for i, numPieces := 0, info.NumPieces(); i < numPieces; i += 1 {
p := info.Piece(i)
hash := sha1.New()
_, err := io.Copy(hash, io.NewSectionReader(span, p.Offset(), p.Length()))
"strings"
"testing"
- "github.com/bradfitz/iter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestIPv4RangeLen(t *testing.T) {
ranges, _ := sampleRanges(t)
- for i := range iter.N(3) {
+ for i := 0; i < 3; i += 1 {
if len(ranges[i].First) != 4 {
t.FailNow()
}
func BenchmarkIterBitmapsDistinct(t *testing.B) {
t.ReportAllocs()
- for range iter.N(t.N) {
+ for i := 0; i < t.N; i += 1 {
var skip, first, second bitmap.Bitmap
skip.Add(1)
first.Add(1, 0, 3)
"testing"
_ "github.com/anacrolix/envpprof"
- "github.com/bradfitz/iter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
}
func BenchmarkHandshakeDefault(b *testing.B) {
- for range iter.N(b.N) {
+ for i := 0; i < b.N; i += 1 {
allHandshakeTests(b, AllSupportedCrypto, DefaultCryptoSelector)
}
}
t.StopTimer()
t.SetBytes(int64(len(ia) + len(a) + len(b)))
t.ResetTimer()
- for range iter.N(t.N) {
+ for i := 0; i < t.N; i += 1 {
ac, bc := net.Pipe()
ar := make([]byte, len(b))
br := make([]byte, len(ia)+len(a))
b := make([]byte, len(a))
t.SetBytes(int64(len(a)))
t.ResetTimer()
- for range iter.N(t.N) {
+ for i := 0; i < t.N; i += 1 {
n, _ = w.Write(a)
if n != len(a) {
t.FailNow()
func BenchmarkSkeysReceive(b *testing.B) {
var skeys [][]byte
- for range iter.N(100000) {
+ for i := 0; i < 100000; i += 1 {
skeys = append(skeys, make([]byte, 20))
}
fillRand(b, skeys...)
//c := qt.New(b)
b.ReportAllocs()
b.ResetTimer()
- for range iter.N(b.N) {
+ for i := 0; i < b.N; i += 1 {
initiator, receiver := net.Pipe()
go func() {
_, _, err := InitiateHandshake(initiator, initSkey, nil, AllSupportedCrypto)
"sync"
"testing"
- "github.com/bradfitz/iter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
},
},
}
- for range iter.N(t.N) {
+ for i := 0; i < t.N; i += 1 {
var msg Message
require.NoError(t, d.Decode(&msg))
// WWJD
func (cn *Peer) onPeerHasAllPieces() {
t := cn.t
if t.haveInfo() {
- pp := cn.newPeerPieces()
- for i := range iter.N(t.numPieces()) {
- if !pp.Contains(bitmap.BitIndex(i)) {
+ npp, pc := cn.newPeerPieces(), t.numPieces()
+ for i := 0; i < pc; i += 1 {
+ if !npp.Contains(bitmap.BitIndex(i)) {
t.incPieceAvailability(i)
}
}
"testing"
"github.com/anacrolix/missinggo/pubsub"
- "github.com/bradfitz/iter"
"github.com/frankban/quicktest"
"github.com/stretchr/testify/require"
go func() {
defer w.Close()
ts.writeSem.Lock()
- for range iter.N(b.N) {
+ for i := 0; i < b.N; i += 1 {
cl.lock()
// The chunk must be written to storage everytime, to ensure the
// writeSem is unlocked.
"math"
"testing"
- "github.com/bradfitz/iter"
qt "github.com/frankban/quicktest"
pp "github.com/anacrolix/torrent/peer_protocol"
func chunkIterRange(end int) func(func(ChunkSpec)) {
return func(f func(ChunkSpec)) {
- for offset := range iter.N(end) {
+ for offset := 0; offset < end; offset += 1 {
f(ChunkSpec{pp.Integer(offset), 1})
}
}
"testing"
"time"
- "github.com/bradfitz/iter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/time/rate"
}
reads := make(chan read)
done := make(chan struct{})
- for range iter.N(numReaders) {
+ for i := 0; i < numReaders; i += 1 {
r, w := io.Pipe()
ws = append(ws, w)
cs = append(cs, w)
}()
written := 0
go func() {
- for range iter.N(writeRounds) {
+ for i := 0; i < writeRounds; i += 1 {
err := writeN(ws, bytesPerRound)
if err != nil {
log.Printf("error writing: %s", err)
"github.com/anacrolix/torrent/metainfo"
"github.com/anacrolix/torrent/storage"
- "github.com/bradfitz/iter"
qt "github.com/frankban/quicktest"
)
readData := make([]byte, pieceSize)
b.SetBytes(int64(numPieces) * pieceSize)
oneIter := func() {
- for pieceIndex := range iter.N(numPieces) {
+ for pieceIndex := 0; pieceIndex < numPieces; pieceIndex += 1 {
pi := tw.Piece(info.Piece(pieceIndex))
rand.Read(data)
b.StartTimer()
}
// Fill the cache
if capacity > 0 {
- for range iter.N(int((capacity + info.TotalLength() - 1) / info.TotalLength())) {
+ iterN := int((capacity + info.TotalLength() - 1) / info.TotalLength())
+ for i := 0; i < iterN; i += 1 {
oneIter()
}
}
b.ResetTimer()
- for range iter.N(b.N) {
+ for i := 0; i < b.N; i += 1 {
oneIter()
}
}
"github.com/anacrolix/chansync"
"github.com/anacrolix/dht/v2"
"github.com/anacrolix/log"
- "github.com/anacrolix/missinggo/iter"
"github.com/anacrolix/missinggo/perf"
"github.com/anacrolix/missinggo/pubsub"
"github.com/anacrolix/missinggo/slices"
activeRequests: make(map[Request]webseed.Request, maxRequests),
}
ws.requesterCond.L = t.cl.locker()
- for range iter.N(maxRequests) {
+ for i := 0; i < maxRequests; i += 1 {
go ws.requester()
}
for _, f := range t.callbacks().NewPeer {
"github.com/anacrolix/missinggo/v2"
"github.com/anacrolix/missinggo/v2/bitmap"
- "github.com/bradfitz/iter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Length: pieceLength * numPieces,
}))
assert.EqualValues(b, 13410, t.numPieces())
- for range iter.N(7) {
+ for i := 0; i < 7; i += 1 {
r := t.NewReader()
r.SetReadahead(32 << 20)
r.Seek(3500000, io.SeekStart)
t._completedPieces.Add(bitmap.BitIndex(i))
}
t.DownloadPieces(0, t.numPieces())
- for range iter.N(b.N) {
+ for i := 0; i < b.N; i += 1 {
t.updateAllPiecePriorities()
}
}