test/leecher-storage.go | 8 ++++---- tests/issue-930/server.go | 2 +- torrent.go | 9 +++++++-- torrent_test.go | 2 +- diff --git a/test/leecher-storage.go b/test/leecher-storage.go index a60f077a0a4498facc61be5add4cc3db781a0a7e..8a5f981951d5bcd51fbadbba17961f3cdc71f826 100644 --- a/test/leecher-storage.go +++ b/test/leecher-storage.go @@ -137,7 +137,7 @@ defer seederTorrent.Stats() defer seeder.Close() // Adding a torrent and setting the info should trigger piece checks for everything // automatically. Wait until the seed Torrent agrees that everything is available. - <-seederTorrent.Complete.On() + <-seederTorrent.Complete().On() // Create leecher and a Torrent. leecherDataDir := t.TempDir() cfg = torrent.TestingConfig(t) @@ -174,7 +174,7 @@ } return }()) require.NoError(t, err) - assert.False(t, leecherTorrent.Complete.Bool()) + assert.False(t, leecherTorrent.Complete().Bool()) assert.True(t, new) //// This was used when observing coalescing of piece state changes. @@ -210,9 +210,9 @@ // to force a refresh since we just read the contents from start to finish. go leecherTorrent.VerifyData() } if canComplete { - <-leecherTorrent.Complete.On() + <-leecherTorrent.Complete().On() } else { - <-leecherTorrent.Complete.Off() + <-leecherTorrent.Complete().Off() } assert.NotEmpty(t, seederTorrent.PeerConns()) leecherPeerConns := leecherTorrent.PeerConns() diff --git a/tests/issue-930/server.go b/tests/issue-930/server.go index 69473953c134a33183f88cc4b04111fc01717db1..5507f53da18c5104c6f662c759bd8d32e1419b1f 100644 --- a/tests/issue-930/server.go +++ b/tests/issue-930/server.go @@ -12,7 +12,7 @@ func server() { go func() { for range time.Tick(time.Second * 5) { for _, torrent := range client.Torrents() { - if torrent.Complete.Bool() { + if torrent.Complete().Bool() { fmt.Println("Dropping torrent", torrent.InfoHash().HexString()) torrent.Drop() } diff --git a/torrent.go b/torrent.go index 3dd785cfaeabcaee41eb6f3e1271e78d0e127397..440fc891c1e16b48909c3192ebd9acba6a8b262b 100644 --- a/torrent.go +++ b/torrent.go @@ -163,7 +163,7 @@ pex pexState // Is On when all pieces are complete. - Complete chansync.Flag + complete chansync.Flag // Torrent sources in use keyed by the source string. activeSources sync.Map @@ -2930,7 +2930,7 @@ return RequestIndex(piece) * t.chunksPerRegularPiece() } func (t *Torrent) updateComplete() { - t.Complete.SetBool(t.haveAllPieces()) + t.complete.SetBool(t.haveAllPieces()) } func (t *Torrent) cancelRequest(r RequestIndex) *Peer { @@ -3257,3 +3257,8 @@ pieceLayers[string(key[:])] = value.String() } return } + +// Is On when all pieces are complete. +func (t *Torrent) Complete() chansync.ReadOnlyFlag { + return &t.complete +} diff --git a/torrent_test.go b/torrent_test.go index 15c2a4fc3466cc27371bcff73d38f42cdfb501f6..ab3f4361032a575514fde5e4c24cb05c4cfd5c31 100644 --- a/torrent_test.go +++ b/torrent_test.go @@ -135,7 +135,7 @@ require.NoError(t, err) defer tt.Drop() tt.DownloadAll() require.True(t, cl.WaitAll()) - assert.True(t, tt.Complete.Bool()) + assert.True(t, tt.Complete().Bool()) assert.True(t, missinggo.FilePathExists(fp)) }