예제 #1
0
파일: main.go 프로젝트: jakop345/torrent
func addTestPeer(client *torrent.Client) {
	for _, t := range client.Torrents() {
		t.AddPeers([]torrent.Peer{{
			IP:   testPeerAddr.IP,
			Port: testPeerAddr.Port,
		}})
	}
}
예제 #2
0
파일: main.go 프로젝트: soul9/torrent
func bytesCompleted(tc *torrent.Client) (ret int64) {
	for _, t := range tc.Torrents() {
		if t.Info() != nil {
			ret += t.BytesCompleted()
		}
	}
	return
}
예제 #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)
			}
		}
	}
}
예제 #4
0
파일: main.go 프로젝트: soul9/torrent
// 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
}
예제 #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
}