]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Export PieceStateChange through piece state change pubsub
authorMatt Joiner <anacrolix@gmail.com>
Sun, 7 Feb 2016 10:55:47 +0000 (21:55 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 7 Feb 2016 10:55:47 +0000 (21:55 +1100)
client_test.go
torrent.go

index b21de8bcbfa6f85cda1d1c0b5ccaf9c496259030..6e1c9b4058be0edf8da27cf15df59581daa15812 100644 (file)
@@ -294,8 +294,8 @@ func TestClientTransfer(t *testing.T) {
        go func() {
                s := leecherGreeting.torrent.pieceStateChanges.Subscribe()
                defer s.Close()
-               for i := range s.Values {
-                       log.Print(i)
+               for v := range s.Values {
+                       log.Printf("%#v", v)
                }
                log.Print("finished")
        }()
index eb6bcf0707f1c9094221e7d9d79c0bce6675e05f..d1764875bc12188dbf6a2af314d6b10292024ff3 100644 (file)
@@ -790,13 +790,21 @@ func (t *torrent) worstBadConn(cl *Client) *connection {
        return nil
 }
 
+type PieceStateChange struct {
+       Index int
+       PieceState
+}
+
 func (t *torrent) publishPieceChange(piece int) {
        cur := t.pieceState(piece)
        p := &t.Pieces[piece]
        if cur != p.PublicPieceState {
-               t.pieceStateChanges.Publish(piece)
+               p.PublicPieceState = cur
+               t.pieceStateChanges.Publish(PieceStateChange{
+                       piece,
+                       cur,
+               })
        }
-       p.PublicPieceState = cur
 }
 
 func (t *torrent) pieceNumPendingChunks(piece int) int {