"expvar"
"fmt"
"io"
- "log"
"net"
"net/url"
"strconv"
"strings"
"time"
+ "github.com/anacrolix/log"
+
"github.com/anacrolix/dht"
"github.com/anacrolix/dht/krpc"
"github.com/anacrolix/missinggo"
L: &cl.mu,
},
}
+ t.logger = log.Default.Clone().AddValue(t)
t.setChunkSize(defaultChunkSize)
return
}
_ "github.com/anacrolix/envpprof"
"github.com/anacrolix/missinggo"
"github.com/anacrolix/missinggo/filecache"
- "github.com/anacrolix/missinggo/pubsub"
"github.com/bradfitz/iter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
func TestTorrentInitialState(t *testing.T) {
dir, mi := testutil.GreetingTestTorrent()
defer os.RemoveAll(dir)
- tor := &Torrent{
- infoHash: mi.HashInfoBytes(),
- pieceStateChanges: pubsub.NewPubSub(),
- }
- tor.chunkSize = 2
- tor.storageOpener = storage.NewClient(storage.NewFileWithCompletion(tempDir(), storage.NewMapPieceCompletion()))
- // Needed to lock for asynchronous piece verification.
- tor.cl = new(Client)
+ cl := &Client{}
+ tor := cl.newTorrent(
+ mi.HashInfoBytes(),
+ storage.NewFileWithCompletion(tempDir(), storage.NewMapPieceCompletion()),
+ )
+ tor.setChunkSize(2)
tor.cl.mu.Lock()
err := tor.setInfoBytes(mi.InfoBytes)
tor.cl.mu.Unlock()
"errors"
"fmt"
"io"
- "log"
"math"
"math/rand"
"net"
"text/tabwriter"
"time"
+ "github.com/anacrolix/log"
+
"github.com/davecgh/go-spew/spew"
"github.com/anacrolix/dht"
// Maintains state of torrent within a Client.
type Torrent struct {
- cl *Client
+ cl *Client
+ logger *log.Logger
networkingEnabled bool
// Determines what chunks to request from peers. 1: Favour higher priority
func TestPieceHashFailed(t *testing.T) {
mi := testutil.GreetingMetaInfo()
- tt := Torrent{
- cl: new(Client),
- infoHash: mi.HashInfoBytes(),
- storageOpener: storage.NewClient(badStorage{}),
- chunkSize: 2,
- }
+ cl := new(Client)
+ tt := cl.newTorrent(mi.HashInfoBytes(), badStorage{})
+ tt.setChunkSize(2)
require.NoError(t, tt.setInfoBytes(mi.InfoBytes))
tt.cl.mu.Lock()
tt.pieces[1].dirtyChunks.AddRange(0, 3)