github.com/anacrolix/torrent@v1.61.0/internal/cmd/issue-906/main.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"net/http"
     6  	"os"
     7  
     8  	_ "github.com/anacrolix/envpprof"
     9  
    10  	"github.com/anacrolix/torrent"
    11  )
    12  
    13  func main() {
    14  	cfg := torrent.NewDefaultClientConfig()
    15  	cfg.Debug = true
    16  	cfg.DisablePEX = true
    17  	cfg.DisableTrackers = true
    18  	cfg.NoDHT = true
    19  	cfg.NoDefaultPortForwarding = true
    20  
    21  	c, _ := torrent.NewClient(cfg)
    22  	defer c.Close()
    23  	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    24  		c.WriteStatus(w)
    25  	})
    26  	torrentFile := os.Args[1]
    27  	peerAddr := os.Args[2]
    28  	t, _ := c.AddTorrentFromFile(torrentFile)
    29  	println(t.AddPeers([]torrent.PeerInfo{{Addr: addr(peerAddr)}}))
    30  	<-t.GotInfo()
    31  	t.DownloadAll()
    32  	c.WaitAll()
    33  	log.Print("ermahgerd, torrent downloaded")
    34  }
    35  
    36  type addr string
    37  
    38  func (a addr) String() string {
    39  	return string(a)
    40  }