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