Rework tracker status lines

This commit is contained in:
Matt Joiner 2020-04-28 09:13:44 +10:00
parent cad8802e9c
commit 15fff58d7b
3 changed files with 10 additions and 11 deletions

View File

@ -603,11 +603,11 @@ func (t *Torrent) writeStatus(w io.Writer) {
fmt.Fprintf(w, "Enabled trackers:\n")
func() {
tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
fmt.Fprintf(tw, " URL\tNext announce\tLast announce\n")
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
var luns, runs url.URL = *lu, *ru
luns.Scheme = ""
runs.Scheme = ""
var ml missinggo.MultiLess
@ -615,7 +615,7 @@ func (t *Torrent) writeStatus(w io.Writer) {
ml.StrictNext(lu.String() == ru.String(), lu.String() < ru.String())
return ml.Less()
}).([]torrentTrackerAnnouncer) {
fmt.Fprintf(tw, " %s\n", ta.statusLine())
fmt.Fprintf(tw, " %q\t%v\n", ta.URL(), ta.statusLine())
}
tw.Flush()
}()

View File

@ -24,17 +24,16 @@ type trackerScraper struct {
type torrentTrackerAnnouncer interface {
statusLine() string
URL() url.URL
URL() *url.URL
}
func (me trackerScraper) URL() url.URL {
return me.u
func (me trackerScraper) URL() *url.URL {
return &me.u
}
func (ts *trackerScraper) statusLine() string {
var w bytes.Buffer
fmt.Fprintf(&w, "%q\t%s\t%s",
ts.u.String(),
fmt.Fprintf(&w, "next ann: %v, last ann: %v",
func() string {
na := time.Until(ts.lastAnnounce.Completed.Add(ts.lastAnnounce.Interval))
if na > 0 {

View File

@ -18,11 +18,11 @@ type websocketTrackerStatus struct {
}
func (me websocketTrackerStatus) statusLine() string {
return fmt.Sprintf("%q: %+v", me.tc.Url, me.tc.Stats())
return fmt.Sprintf("%+v", me.tc.Stats())
}
func (me websocketTrackerStatus) URL() url.URL {
return me.url
func (me websocketTrackerStatus) URL() *url.URL {
return &me.url
}
type refCountedWebtorrentTrackerClient struct {