Export PieceStateChange through piece state change pubsub

This commit is contained in:
Matt Joiner 2016-02-07 21:55:47 +11:00
parent 0c28a0f1b1
commit dc215d083e
2 changed files with 12 additions and 4 deletions

View 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")
}()

View 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 {