]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Start using new log package
authorMatt Joiner <anacrolix@gmail.com>
Sun, 28 Jan 2018 05:07:11 +0000 (16:07 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 28 Jan 2018 05:07:11 +0000 (16:07 +1100)
client.go
client_test.go
torrent.go
torrent_test.go

index 95d348f8e6d1a7bddf50fabcb6092467e7fa4572..689386cd05e15fe086159d04b5a042a8376f1d11 100644 (file)
--- a/client.go
+++ b/client.go
@@ -8,13 +8,14 @@ import (
        "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"
@@ -1040,6 +1041,7 @@ func (cl *Client) newTorrent(ih metainfo.Hash, specStorage storage.ClientImpl) (
                        L: &cl.mu,
                },
        }
+       t.logger = log.Default.Clone().AddValue(t)
        t.setChunkSize(defaultChunkSize)
        return
 }
index 56390b3d55af7986164451061d0e13ce954fc904..a16fdbf0fb2da332fdd0dd251c6bf387ad4fe69f 100644 (file)
@@ -18,7 +18,6 @@ import (
        _ "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"
@@ -100,14 +99,12 @@ func TestPieceHashSize(t *testing.T) {
 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()
index f342de225cbef828011bdee74cb28be111bcafb7..a215859d568c7cc61277007bc28d17115ec8d013 100644 (file)
@@ -6,7 +6,6 @@ import (
        "errors"
        "fmt"
        "io"
-       "log"
        "math"
        "math/rand"
        "net"
@@ -16,6 +15,8 @@ import (
        "text/tabwriter"
        "time"
 
+       "github.com/anacrolix/log"
+
        "github.com/davecgh/go-spew/spew"
 
        "github.com/anacrolix/dht"
@@ -45,7 +46,8 @@ type peersKey struct {
 
 // 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
index 3889aff216249ccaf6bd863836acb5d6fb97c36a..c407af0b1bb8c934d40e7ff412ec81a54cb8bf1b 100644 (file)
@@ -146,12 +146,9 @@ func TestEmptyFilesAndZeroPieceLengthWithMMapStorage(t *testing.T) {
 
 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)