From: Matt Joiner Date: Thu, 12 Apr 2018 05:21:31 +0000 (+1000) Subject: Add LoopbackListenHost X-Git-Tag: v1.0.0~149^2~4 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=83e4c65fc4201a073ab1626052d3757bcb91fed7;p=btrtrc.git Add LoopbackListenHost --- diff --git a/client_test.go b/client_test.go index 0d55a20b..5e176218 100644 --- a/client_test.go +++ b/client_test.go @@ -9,7 +9,6 @@ import ( "net" "os" "path/filepath" - "strings" "sync" "testing" "time" @@ -32,13 +31,7 @@ import ( 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 6f89aeea..8d56fb75 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 68c4b768..0e1b5c0d 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 @@ func handleErr(h func(), fs ...func() error) error { } return nil } + +func LoopbackListenHost(network string) string { + if strings.Contains(network, "4") { + return "127.0.0.1" + } else { + return "::1" + } +}