client_test.go | 9 +-------- fs/torrentfs_test.go | 6 ++++-- listen.go | 10 ++++++++++ diff --git a/client_test.go b/client_test.go index 0d55a20b1fb1874858d17c1a1ad077a7b6baeb2d..5e176218756d4149b6ccc5c62864c9f3072f8406 100644 --- a/client_test.go +++ b/client_test.go @@ -9,7 +9,6 @@ "io/ioutil" "net" "os" "path/filepath" - "strings" "sync" "testing" "time" @@ -32,13 +31,7 @@ ) func TestingConfig() *Config { return &Config{ - ListenHost: func(network string) string { - if strings.Contains(network, "4") { - return "127.0.0.1" - } else { - return "::1" - } - }, + ListenHost: LoopbackListenHost, NoDHT: true, DataDir: tempDir(), DisableTrackers: true, diff --git a/fs/torrentfs_test.go b/fs/torrentfs_test.go index 6f89aeea15d6f375134af76de29027deb54da1cf..8d56fb75a6c91136d6fc817279aa91964fc2aead 100644 --- a/fs/torrentfs_test.go +++ b/fs/torrentfs_test.go @@ -165,12 +165,14 @@ func TestDownloadOnDemand(t *testing.T) { layout, err := newGreetingLayout() require.NoError(t, err) defer layout.Destroy() - seeder, err := torrent.NewClient((&torrent.Config{ + cfg := torrent.Config{ DataDir: layout.Completed, DisableTrackers: true, NoDHT: true, Seed: true, - }).SetListenAddr("localhost:0")) + ListenHost: torrent.LoopbackListenHost, + } + seeder, err := torrent.NewClient(&cfg) require.NoError(t, err) defer seeder.Close() testutil.ExportStatusWriter(seeder, "s") diff --git a/listen.go b/listen.go index 68c4b7685533136d39db23b744de73d8ad14821a..0e1b5c0d309b88e30498007673f2590f68f77614 100644 --- a/listen.go +++ b/listen.go @@ -1,5 +1,7 @@ package torrent +import "strings" + type peerNetworks struct { tcp4, tcp6 bool utp4, utp6 bool @@ -15,3 +17,11 @@ } } return nil } + +func LoopbackListenHost(network string) string { + if strings.Contains(network, "4") { + return "127.0.0.1" + } else { + return "::1" + } +}