Export PieceStateChange through piece state change pubsub
This commit is contained in:
parent
0c28a0f1b1
commit
dc215d083e
|
@ -294,8 +294,8 @@ func TestClientTransfer(t *testing.T) {
|
||||||
go func() {
|
go func() {
|
||||||
s := leecherGreeting.torrent.pieceStateChanges.Subscribe()
|
s := leecherGreeting.torrent.pieceStateChanges.Subscribe()
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
for i := range s.Values {
|
for v := range s.Values {
|
||||||
log.Print(i)
|
log.Printf("%#v", v)
|
||||||
}
|
}
|
||||||
log.Print("finished")
|
log.Print("finished")
|
||||||
}()
|
}()
|
||||||
|
|
12
torrent.go
12
torrent.go
|
@ -790,13 +790,21 @@ func (t *torrent) worstBadConn(cl *Client) *connection {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PieceStateChange struct {
|
||||||
|
Index int
|
||||||
|
PieceState
|
||||||
|
}
|
||||||
|
|
||||||
func (t *torrent) publishPieceChange(piece int) {
|
func (t *torrent) publishPieceChange(piece int) {
|
||||||
cur := t.pieceState(piece)
|
cur := t.pieceState(piece)
|
||||||
p := &t.Pieces[piece]
|
p := &t.Pieces[piece]
|
||||||
if cur != p.PublicPieceState {
|
if cur != p.PublicPieceState {
|
||||||
t.pieceStateChanges.Publish(piece)
|
|
||||||
}
|
|
||||||
p.PublicPieceState = cur
|
p.PublicPieceState = cur
|
||||||
|
t.pieceStateChanges.Publish(PieceStateChange{
|
||||||
|
piece,
|
||||||
|
cur,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *torrent) pieceNumPendingChunks(piece int) int {
|
func (t *torrent) pieceNumPendingChunks(piece int) int {
|
||||||
|
|
Loading…
Reference in New Issue