var (
TorrentStats = map[metainfo.Hash]TorrentStat{}
TorrentStatsM sync.RWMutex
+ Torrents []metainfo.Hash
+ TorrentsM sync.RWMutex
)
func recreateFIFO(pth string) {
time.Sleep(time.Second)
continue
}
- ts := c.Torrents()
- sort.Sort(ByInfoHash(ts))
- for _, t := range ts {
- if t.Info() == nil {
+ ts := make([]*torrent.Torrent, 0, len(Torrents))
+ TorrentsM.RLock()
+ for _, h := range Torrents {
+ t, _ := c.Torrent(h)
+ if t == nil || t.Info() == nil {
fmt.Fprintf(fd, "%s not ready\n", t.Name())
continue
}
+ ts = append(ts, t)
+ }
+ TorrentsM.RUnlock()
+ for _, t := range ts {
stats := t.Stats()
done := t.BytesCompleted() * 100 / t.Length()
percColour := Red
if len(cols) > 1 {
t.AddPeers(resolveTestPeers(cols[1:]))
}
+ TorrentsM.Lock()
+ for _, h := range Torrents {
+ if h.HexString() == t.InfoHash().HexString() {
+ goto OldOne
+ }
+ }
+ Torrents = append(Torrents, t.InfoHash())
+ OldOne:
+ TorrentsM.Unlock()
go fifoPeerList(t)
go fifoFileList(t)
log.Println("added:", t.InfoHash().HexString(), t.Name())
}
var i infohash.T
copy(i[:], raw)
+ TorrentsM.Lock()
+ for n, h := range Torrents {
+ if h.HexString() == i.HexString() {
+ Torrents = append(Torrents[:n], Torrents[n+1:]...)
+ break
+ }
+ }
+ TorrentsM.Unlock()
t, ok := c.Torrent(i)
if !ok {
- log.Println("no suck torrent", what)
+ log.Println("no such torrent", what)
continue
}
txStatsDump(t)