]> Sergey Matveev's repositories - btrtrc.git/blobdiff - tests/issue-930/noServer.go
Add issue-930 demo
[btrtrc.git] / tests / issue-930 / noServer.go
diff --git a/tests/issue-930/noServer.go b/tests/issue-930/noServer.go
new file mode 100644 (file)
index 0000000..2d7990e
--- /dev/null
@@ -0,0 +1,35 @@
+package main
+
+import (
+       "fmt"
+       "os"
+       "os/signal"
+       "syscall"
+
+       "github.com/anacrolix/torrent/metainfo"
+)
+
+func noServer() {
+       fmt.Println("Ctrl+C to start downloading")
+       sc := make(chan os.Signal, 1)
+       signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
+       <-sc
+
+       for _, hash := range infoHashes {
+               t, _ := client.AddTorrentInfoHash(metainfo.NewHashFromHex(hash))
+               infoHash := hash
+               go func() {
+                       <-t.GotInfo()
+                       fmt.Println("Download started for", infoHash)
+                       t.DownloadAll()
+               }()
+       }
+
+       client.WaitAll()
+       fmt.Println("All torrents downloaded")
+
+       fmt.Println("Ctrl+C to stop program")
+       sc2 := make(chan os.Signal, 1)
+       signal.Notify(sc2, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
+       <-sc2
+}