Exemple #1
0
func addTestPeer(client *torrent.Client) {
	for _, t := range client.Torrents() {
		t.AddPeers([]torrent.Peer{{
			IP:   testPeerAddr.IP,
			Port: testPeerAddr.Port,
		}})
	}
}
Exemple #2
0
func bytesCompleted(tc *torrent.Client) (ret int64) {
	for _, t := range tc.Torrents() {
		if t.Info() != nil {
			ret += t.BytesCompleted()
		}
	}
	return
}
Exemple #3
0
func addTestPeer(client *torrent.Client) {
	for _, t := range client.Torrents() {
		if testPeerAddr != nil {
			if err := t.AddPeers([]torrent.Peer{{
				IP:   testPeerAddr.IP,
				Port: testPeerAddr.Port,
			}}); err != nil {
				log.Print(err)
			}
		}
	}
}
Exemple #4
0
// Returns an estimate of the total bytes for all torrents.
func totalBytesEstimate(tc *torrent.Client) (ret int64) {
	var noInfo, hadInfo int64
	for _, t := range tc.Torrents() {
		info := t.Info()
		if info == nil {
			noInfo++
			continue
		}
		ret += info.TotalLength()
		hadInfo++
	}
	if hadInfo != 0 {
		// Treat each torrent without info as the average of those with,
		// rounded up.
		ret += (noInfo*ret + hadInfo - 1) / hadInfo
	}
	return
}
Exemple #5
0
func actionOnTorrent(client torrent.Client, torrentName string, action string) bool {

	allTorrents := client.Torrents()
	for _, torrent := range allTorrents {
		if torrent.Name() == torrentName {
			switch action {
			case util.Start:
				torrent.DownloadAll()
				return true
			case util.Kill:
				torrent.Drop()
				return true
			}
		}
	}

	return false
}