Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Jul 3, 2024
1 parent 358f962 commit 03e1245
Showing 1 changed file with 67 additions and 67 deletions.
134 changes: 67 additions & 67 deletions torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (
"net/url"
"runtime"
"sort"
"strings"
"sync/atomic"
"text/tabwriter"
"time"
"unsafe"

Expand All @@ -31,6 +29,7 @@ import (
"github.com/anacrolix/missinggo/v2/pubsub"
"github.com/anacrolix/multiless"
"github.com/anacrolix/sync"
stack2 "github.com/go-stack/stack"

Check failure on line 32 in torrent.go

View workflow job for this annotation

GitHub Actions / bench (1.21)

missing go.sum entry for module providing package github.com/go-stack/stack (imported by github.com/anacrolix/torrent); to add:

Check failure on line 32 in torrent.go

View workflow job for this annotation

GitHub Actions / test (1.21, windows-latest)

missing go.sum entry for module providing package github.com/go-stack/stack (imported by github.com/anacrolix/torrent); to add:

Check failure on line 32 in torrent.go

View workflow job for this annotation

GitHub Actions / test (1.21, windows-latest)

missing go.sum entry for module providing package github.com/go-stack/stack (imported by github.com/anacrolix/torrent); to add:

Check failure on line 32 in torrent.go

View workflow job for this annotation

GitHub Actions / test-386 (1.21)

missing go.sum entry for module providing package github.com/go-stack/stack (imported by github.com/anacrolix/torrent); to add:

Check failure on line 32 in torrent.go

View workflow job for this annotation

GitHub Actions / test (1.21, macos-latest)

missing go.sum entry for module providing package github.com/go-stack/stack (imported by github.com/anacrolix/torrent); to add:

Check failure on line 32 in torrent.go

View workflow job for this annotation

GitHub Actions / test (1.21, macos-latest)

missing go.sum entry for module providing package github.com/go-stack/stack (imported by github.com/anacrolix/torrent); to add:

Check failure on line 32 in torrent.go

View workflow job for this annotation

GitHub Actions / build-wasm (1.21)

missing go.sum entry for module providing package github.com/go-stack/stack (imported by github.com/anacrolix/torrent); to add:

Check failure on line 32 in torrent.go

View workflow job for this annotation

GitHub Actions / test (1.21, ubuntu-latest)

missing go.sum entry for module providing package github.com/go-stack/stack (imported by github.com/anacrolix/torrent); to add:

Check failure on line 32 in torrent.go

View workflow job for this annotation

GitHub Actions / test (1.21, ubuntu-latest)

missing go.sum entry for module providing package github.com/go-stack/stack (imported by github.com/anacrolix/torrent); to add:

Check failure on line 32 in torrent.go

View workflow job for this annotation

GitHub Actions / test-benchmarks (1.21)

missing go.sum entry for module providing package github.com/go-stack/stack (imported by github.com/anacrolix/torrent); to add:
"github.com/pion/datachannel"
"golang.org/x/sync/errgroup"
"golang.org/x/time/rate"
Expand Down Expand Up @@ -854,7 +853,8 @@ func (t *Torrent) writeStatus(w io.Writer) {
t.imu.RLock()
defer t.imu.RUnlock()

fmt.Fprintf(w, "Infohash: %s\n", t.infoHash.HexString())
stack := stack2.Trace().TrimBelow(stack2.Caller(1)).String()
fmt.Fprintf(w, "Infohash: %s, %s\n", t.infoHash.HexString(), stack)
fmt.Fprintf(w, "Metadata length: %d\n", t.metadataSize(false))
if !t.haveInfo(false) {
fmt.Fprintf(w, "Metadata have: ")
Expand All @@ -880,70 +880,70 @@ func (t *Torrent) writeStatus(w io.Writer) {
}
}(),
)
if t.haveInfo(false) {
func() {
t.imu.RUnlock()
defer t.imu.RLock()

fmt.Fprintf(w, "Num Pieces: %d (%d completed)\n", t.numPieces(false), t.numPiecesCompleted(false))
fmt.Fprintf(w, "Piece States: %s\n", t.pieceStateRuns(false))
// Generates a huge, unhelpful listing when piece availability is very scattered. Prefer
// availability frequencies instead.
if false {
fmt.Fprintf(w, "Piece availability: %v\n", strings.Join(func() (ret []string) {
for _, run := range t.pieceAvailabilityRuns(false) {
ret = append(ret, run.String())
}
return
}(), " "))
}
fmt.Fprintf(w, "Piece availability frequency: %v\n", strings.Join(
func() (ret []string) {
for avail, freq := range t.pieceAvailabilityFrequencies(false) {
if freq == 0 {
continue
}
ret = append(ret, fmt.Sprintf("%v: %v", avail, freq))
}
return
}(),
", "))
}()
}
fmt.Fprintf(w, "Reader Pieces:")
t.forReaderOffsetPieces(func(begin, end pieceIndex) (again bool) {
fmt.Fprintf(w, " %d:%d", begin, end)
return true
}, false)
fmt.Fprintln(w)

fmt.Fprintf(w, "Enabled trackers:\n")
func() {
tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
fmt.Fprintf(tw, " URL\tExtra\n")
for _, ta := range slices.Sort(slices.FromMapElems(t.trackerAnnouncers), func(l, r torrentTrackerAnnouncer) bool {
lu := l.URL()
ru := r.URL()
var luns, runs url.URL = *lu, *ru
luns.Scheme = ""
runs.Scheme = ""
var ml missinggo.MultiLess
ml.StrictNext(luns.String() == runs.String(), luns.String() < runs.String())
ml.StrictNext(lu.String() == ru.String(), lu.String() < ru.String())
return ml.Less()
}).([]torrentTrackerAnnouncer) {
fmt.Fprintf(tw, " %q\t%v\n", ta.URL(), ta.statusLine())
}
tw.Flush()
}()

fmt.Fprintf(w, "DHT Announces: %d\n", t.numDHTAnnounces)

dumpStats(w, t.stats(false, false))
//if t.haveInfo(false) {
// func() {
// t.imu.RUnlock()
// defer t.imu.RLock()
//
// fmt.Fprintf(w, "Num Pieces: %d (%d completed)\n", t.numPieces(false), t.numPiecesCompleted(false))
// fmt.Fprintf(w, "Piece States: %s\n", t.pieceStateRuns(false))
// // Generates a huge, unhelpful listing when piece availability is very scattered. Prefer
// // availability frequencies instead.
// if false {
// fmt.Fprintf(w, "Piece availability: %v\n", strings.Join(func() (ret []string) {
// for _, run := range t.pieceAvailabilityRuns(false) {
// ret = append(ret, run.String())
// }
// return
// }(), " "))
// }
// fmt.Fprintf(w, "Piece availability frequency: %v\n", strings.Join(
// func() (ret []string) {
// for avail, freq := range t.pieceAvailabilityFrequencies(false) {
// if freq == 0 {
// continue
// }
// ret = append(ret, fmt.Sprintf("%v: %v", avail, freq))
// }
// return
// }(),
// ", "))
// }()
//}
//fmt.Fprintf(w, "Reader Pieces:")
//t.forReaderOffsetPieces(func(begin, end pieceIndex) (again bool) {
// fmt.Fprintf(w, " %d:%d", begin, end)
// return true
//}, false)
//fmt.Fprintln(w)
//
//fmt.Fprintf(w, "Enabled trackers:\n")
//func() {
// tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
// fmt.Fprintf(tw, " URL\tExtra\n")
// for _, ta := range slices.Sort(slices.FromMapElems(t.trackerAnnouncers), func(l, r torrentTrackerAnnouncer) bool {
// lu := l.URL()
// ru := r.URL()
// var luns, runs url.URL = *lu, *ru
// luns.Scheme = ""
// runs.Scheme = ""
// var ml missinggo.MultiLess
// ml.StrictNext(luns.String() == runs.String(), luns.String() < runs.String())
// ml.StrictNext(lu.String() == ru.String(), lu.String() < ru.String())
// return ml.Less()
// }).([]torrentTrackerAnnouncer) {
// fmt.Fprintf(tw, " %q\t%v\n", ta.URL(), ta.statusLine())
// }
// tw.Flush()
//}()

//fmt.Fprintf(w, "DHT Announces: %d\n", t.numDHTAnnounces)

//dumpStats(w, t.stats(false, false))
}()

fmt.Fprintf(w, "webseeds:\n")
t.writePeerStatuses(w, t.webSeedsAsSlice(false), false)
//t.writePeerStatuses(w, t.webSeedsAsSlice(false), false)

peerConns := t.peerConnsAsSlice(false)
defer peerConns.free()
Expand All @@ -962,9 +962,9 @@ func (t *Torrent) writeStatus(w io.Writer) {
})

fmt.Fprintf(w, "%v peer conns:\n", len(peerConns))
t.writePeerStatuses(w, g.SliceMap(peerConns, func(pc *PeerConn) *Peer {
return &pc.Peer
}), false)
//t.writePeerStatuses(w, g.SliceMap(peerConns, func(pc *PeerConn) *Peer {
// return &pc.Peer
//}), false)
}

func (t *Torrent) writePeerStatuses(w io.Writer, peers []*Peer, lockTorrent bool) {
Expand Down

0 comments on commit 03e1245

Please sign in to comment.