Improve num requests per piece status output

This commit is contained in:
Matt Joiner 2021-05-12 21:48:23 +10:00
parent f19564d597
commit 233135493f
1 changed files with 13 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"io"
"math/rand"
"net"
"sort"
"strconv"
"strings"
"sync"
@ -366,8 +367,19 @@ func (cn *Peer) writeStatus(w io.Writer, t *Torrent) {
cn.downloadRate()/(1<<10),
)
fmt.Fprintf(w, " requested pieces:")
type pieceNumRequestsType struct {
piece pieceIndex
numRequests int
}
var pieceNumRequests []pieceNumRequestsType
for piece, count := range cn.numRequestsByPiece() {
fmt.Fprintf(w, " %v (%v)", piece, count)
pieceNumRequests = append(pieceNumRequests, pieceNumRequestsType{piece, count})
}
sort.Slice(pieceNumRequests, func(i, j int) bool {
return pieceNumRequests[i].piece < pieceNumRequests[j].piece
})
for _, elem := range pieceNumRequests {
fmt.Fprintf(w, " %v(%v)", elem.piece, elem.numRequests)
}
fmt.Fprintf(w, "\n")
}