Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "os"
- "time"
- "github.com/anacrolix/dht"
- "github.com/anacrolix/torrent"
- )
- func waitForInfo(clientTorrent *torrent.Torrent, seconds time.Duration) (deleted bool) {
- timeout := make(chan bool, 1) //creating a timeout channel for our gotinfo
- go func() {
- time.Sleep(seconds * time.Second)
- timeout <- true
- }()
- select {
- case <-clientTorrent.GotInfo(): //attempting to retrieve info for torrent
- clientTorrent.DownloadAll()
- return false
- case <-timeout: // getting info for torrent has timed out so purging the torrent
- clientTorrent.Drop()
- return true
- }
- }
- func main() {
- config := torrent.Config{DataDir: "downloads",
- DHTConfig: dht.ServerConfig{StartingNodes: dht.GlobalBootstrapAddrs},
- }
- tclient, err := torrent.NewClient(&config) //pulling out the torrent specific config to use
- if err != nil {
- fmt.Println("Error with creating client", err)
- }
- ubuntuTorrent, err := tclient.AddMagnet("magnet:?xt=urn:btih:9f9165d9a281a9b8e782cd5176bbcc8256fd1871&dn=Ubuntu+16.04.1+LTS+Desktop+64-bit&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969")
- if err != nil {
- fmt.Println("Error adding Torrent", err)
- }
- timedOut := waitForInfo(ubuntuTorrent, 30)
- if timedOut {
- fmt.Println("Timed out awaiting info...")
- os.Exit(3)
- }
- ubuntuTorrent.DownloadAll()
- fmt.Println("downloading all.. now sleeping 60 seconds..")
- time.Sleep(60 * time.Second)
- fmt.Println("now forcing max connections to zero.")
- fmt.Println("current amount downloaded", ubuntuTorrent.Stats().BytesReadUsefulData)
- fmt.Println("Number of open peers", ubuntuTorrent.Stats().ActivePeers)
- ubuntuTorrent.SetMaxEstablishedConns(0)
- fmt.Println("now waiting 10 seconds")
- time.Sleep(10 * time.Second)
- oldMax := ubuntuTorrent.SetMaxEstablishedConns(80)
- fmt.Println("Reseting peers", oldMax)
- fmt.Println("now waiting 10 seconds")
- time.Sleep(10 * time.Second)
- ubuntuTorrent.Drop()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement