From dc215d083e1f36de5380c9db3fcdd003822df8ce Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 7 Feb 2016 21:55:47 +1100 Subject: [PATCH] Export PieceStateChange through piece state change pubsub --- client_test.go | 4 ++-- torrent.go | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client_test.go b/client_test.go index b21de8bc..6e1c9b40 100644 --- a/client_test.go +++ b/client_test.go @@ -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") }() diff --git a/torrent.go b/torrent.go index eb6bcf07..d1764875 100644 --- a/torrent.go +++ b/torrent.go @@ -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 { -- 2.48.1