1 package webseed_partial_seed
8 "github.com/anacrolix/torrent"
9 "github.com/anacrolix/torrent/internal/testutil"
10 qt "github.com/frankban/quicktest"
13 func testSrcDir() string {
14 _, b, _, _ := runtime.Caller(0)
15 return filepath.Dir(b)
18 func makeSeederClient(t *testing.T) *torrent.Client {
19 config := torrent.TestingConfig(t)
20 config.DisableIPv6 = true
21 config.ListenPort = 3030
23 config.Logger = config.Logger.WithNames("seeder")
24 config.MaxAllocPeerRequestDataPerConn = 1 << 20
25 c, err := torrent.NewClient(config)
30 func makeLeecherClient(t *testing.T) *torrent.Client {
31 config := torrent.TestingConfig(t)
33 config.DisableIPv6 = true
34 config.Logger = config.Logger.WithNames("leecher")
35 config.DisableWebseeds = true
36 c, err := torrent.NewClient(config)
41 func assertOk(err error) {
47 func downloadAll(t *torrent.Torrent) {
52 func TestWebseedPartialSeed(t *testing.T) {
54 seederClient := makeSeederClient(t)
55 defer seederClient.Close()
56 testutil.ExportStatusWriter(seederClient, "seeder", t)
57 const infoHashHex = "a88fda5954e89178c372716a6a78b8180ed4dad3"
58 metainfoPath := filepath.Join(testSrcDir(), "test.img.torrent")
59 seederTorrent, err := seederClient.AddTorrentFromFile(metainfoPath)
61 leecherClient := makeLeecherClient(t)
62 defer leecherClient.Close()
63 testutil.ExportStatusWriter(leecherClient, "leecher", t)
64 leecherTorrent, _ := leecherClient.AddTorrentFromFile(metainfoPath)
65 // TODO: Check that leecher has pieces before seeder completes. Currently I do this manually by
66 // looking at the GOPPROF http endpoint with the exported status writer
67 // /TestWebseedPartialSeed/leecher.
68 go downloadAll(leecherTorrent)
69 peer := make([]torrent.PeerInfo, 1)
70 peer[0] = torrent.PeerInfo{
71 Id: seederClient.PeerID(),
72 Addr: torrent.PeerRemoteAddr(seederClient.ListenAddrs()[0]),
74 SupportsEncryption: false,
78 go leecherTorrent.AddPeers(peer)
80 seederTorrent.DownloadAll()
81 allDownloaded := leecherClient.WaitAll()
82 c.Assert(allDownloaded, qt.IsTrue)