Add LoopbackListenHost

This commit is contained in:
Matt Joiner 2018-04-12 15:21:31 +10:00
parent b5df073217
commit 83e4c65fc4
3 changed files with 15 additions and 10 deletions

View File

@ -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,

View File

@ -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")

View File

@ -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"
}
}