12 "github.com/anacrolix/torrent/dht"
13 "github.com/anacrolix/torrent/metainfo"
16 var numclients int = 0
20 return filepath.Join(os.TempDir(), "wtp-test/", fmt.Sprintf("%d/", numclients))
23 func addirs(cf *Config) *Config {
26 cf.DataDir = filepath.Join(d, "/data")
27 os.MkdirAll(cf.DataDir, 0700)
28 cf.ConfigDir = filepath.Join(d, "/config")
29 os.MkdirAll(cf.ConfigDir, 0700)
33 func issue35TestingConfig() *Config {
35 ListenAddr: "localhost:0",
37 DisableTrackers: true,
39 DisableMetainfoCache: true,
43 DataDir: filepath.Join(os.TempDir(), "torrent-test/data"),
44 ConfigDir: filepath.Join(os.TempDir(), "torrent-test/config"),
45 DHTConfig: dht.ServerConfig{
47 BootstrapNodes: []string{},
49 NoDefaultBootstrap: true,
55 func writeranddata(path string) error {
57 var to_write int64 = 1024 * 1024 //1MB
58 f, err := os.Create(path)
63 rnd, err := os.Open("/dev/urandom")
68 w, err = io.CopyN(f, rnd, to_write)
73 return errors.New("Short read on /dev/random")
78 func TestInfohash(t *testing.T) {
79 os.RemoveAll(filepath.Join(os.TempDir(), "torrent-test"))
80 os.MkdirAll(filepath.Join(os.TempDir(), "torrent-test"), 0700)
87 cf_one = issue35TestingConfig()
88 cf_one.ListenAddr = "localhost:43433"
89 cf_one = addirs(cf_one)
90 cl_one, err = NewClient(cf_one)
94 tfp := filepath.Join(cf_one.DataDir, "testdata")
96 b := metainfo.Builder{}
98 b.AddDhtNodes([]string{"1.2.3.4:5555"})
103 ttfp := filepath.Join(cf_one.ConfigDir, "/../torrent")
104 ttf, err := os.Create(ttfp)
108 ec, _ := ba.Start(ttf, runtime.NumCPU())
115 tor, err := cl_one.AddTorrentFromFile(ttfp)
121 if cl_one.WaitAll() == false {
122 t.Fatal(errors.New("One did not download torrent"))