]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Make Torrent.Complete a method and make it return a read-only interface
authorMatt Joiner <anacrolix@gmail.com>
Thu, 27 Jun 2024 04:32:32 +0000 (14:32 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 27 Jun 2024 04:34:56 +0000 (14:34 +1000)
test/leecher-storage.go
tests/issue-930/server.go
torrent.go
torrent_test.go

index a60f077a0a4498facc61be5add4cc3db781a0a7e..8a5f981951d5bcd51fbadbba17961f3cdc71f826 100644 (file)
@@ -137,7 +137,7 @@ func testClientTransfer(t *testing.T, ps testClientTransferParams) {
        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 @@ func testClientTransfer(t *testing.T, ps testClientTransferParams) {
                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 @@ func testClientTransfer(t *testing.T, ps testClientTransferParams) {
                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()
index 69473953c134a33183f88cc4b04111fc01717db1..5507f53da18c5104c6f662c759bd8d32e1419b1f 100644 (file)
@@ -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()
                                }
index 3dd785cfaeabcaee41eb6f3e1271e78d0e127397..440fc891c1e16b48909c3192ebd9acba6a8b262b 100644 (file)
@@ -163,7 +163,7 @@ type Torrent struct {
        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 @@ func (t *Torrent) pieceRequestIndexOffset(piece pieceIndex) RequestIndex {
 }
 
 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 @@ file:
        }
        return
 }
+
+// Is On when all pieces are complete.
+func (t *Torrent) Complete() chansync.ReadOnlyFlag {
+       return &t.complete
+}
index 15c2a4fc3466cc27371bcff73d38f42cdfb501f6..ab3f4361032a575514fde5e4c24cb05c4cfd5c31 100644 (file)
@@ -135,7 +135,7 @@ func testEmptyFilesAndZeroPieceLength(t *testing.T, cfg *ClientConfig) {
        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))
 }