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