+type topTorrent struct {
+ infoHash metainfo.Hash
+ name string
+ tx int64
+}
+
+func fifoTopSeed(c *torrent.Client) {
+ pth := path.Join(FIFOsDir, "top-seed")
+ recreateFIFO(pth)
+ for {
+ fd, err := os.OpenFile(pth, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
+ if err != nil {
+ log.Println("OpenFile:", pth, err)
+ time.Sleep(time.Second)
+ continue
+ }
+ var ts []*topTorrent
+ for _, t := range c.Torrents() {
+ if t.Info() == nil {
+ continue
+ }
+ ts = append(ts, &topTorrent{
+ infoHash: t.InfoHash(),
+ name: t.Name(),
+ tx: TxStats[t.InfoHash()],
+ })
+ }
+ sort.Sort(ByTxTraffic(ts))
+ for _, t := range ts {
+ fmt.Fprintf(fd,
+ "%s%s%s %s%40s%s %s\n",
+ Blue, t.infoHash.HexString(), Reset,
+ Green, shortenName(t.name), Reset,
+ humanize.IBytes(uint64(t.tx)),
+ )
+ }
+ fd.Close()
+ time.Sleep(time.Second)
+ }
+}
+