github.com/anacrolix/torrent@v1.61.0/tests/issue-930/main.go (about) 1 package main 2 3 import ( 4 "math/rand" 5 "os" 6 7 "github.com/anacrolix/envpprof" 8 9 "github.com/anacrolix/torrent" 10 "github.com/anacrolix/torrent/metainfo" 11 "github.com/anacrolix/torrent/storage" 12 ) 13 14 var client *torrent.Client 15 16 var index = 0 17 var infoHashes = []string{ 18 "6853ab2b86b2cb6a3c778b8aafe3dffd94242321", 19 "4d29c6c02c97caad937d8a9b66b0bb1b6f7cbbfe", 20 } 21 22 func init() { 23 opts := storage.NewFileClientOpts{ 24 ClientBaseDir: "./temp", 25 TorrentDirMaker: func(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string { 26 return baseDir + "/" + infoHash.HexString() 27 }, 28 } 29 conf := torrent.NewDefaultClientConfig() 30 conf.DefaultStorage = storage.NewFileOpts(opts) 31 conf.ListenPort = rand.Intn(65535-49152) + 49152 32 33 _client, err := torrent.NewClient(conf) 34 if err != nil { 35 panic(err) 36 } 37 38 client = _client 39 } 40 41 func main() { 42 defer envpprof.Stop() 43 if len(os.Args) > 1 { 44 noServer() 45 return 46 } 47 48 server() 49 }