* amount of downloaded/uploaded traffic during current session
* remote address with port
* client's name
+* fifos/top-seed -- list torrents sorted by total transfer data amount
For each torrent, corresponding .torrent file will be created.
Additional symbolic link with torrent's name will lead to HASH.torrent.
}
}
+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)
+ }
+}
+
type stringAddr string
func (stringAddr) Network() string { return "" }
os.Remove(path.Join(FIFOsDir, "dht"))
os.Remove(path.Join(FIFOsDir, "add"))
os.Remove(path.Join(FIFOsDir, "del"))
+ os.Remove(path.Join(FIFOsDir, "top-seed"))
os.RemoveAll(path.Join(FIFOsDir, PeersDir))
os.RemoveAll(path.Join(FIFOsDir, FilesDir))
}
return a[i].InfoHash().HexString() < a[j].InfoHash().HexString()
}
+type ByTxTraffic []*topTorrent
+
+func (a ByTxTraffic) Len() int {
+ return len(a)
+}
+
+func (a ByTxTraffic) Swap(i, j int) {
+ a[i], a[j] = a[j], a[i]
+}
+
+func (a ByTxTraffic) Less(i, j int) bool {
+ return a[i].tx < a[j].tx
+}
+
type ByPeerID []*torrent.PeerConn
func (a ByPeerID) Len() int {