Add default DHT servers when UTP disabled

Also ensures that UDP and TCP sockets are reserved, even if not used, and fixes tests. Fixes #289.
This commit is contained in:
Matt Joiner 2018-11-04 17:43:47 +11:00
parent 8a0f333bb9
commit 1a4950ad4a
2 changed files with 3 additions and 19 deletions

View File

@ -230,7 +230,7 @@ func NewClient(cfg *ClientConfig) (cl *Client, err error) {
}
}
cl.conns, err = listenAll(cl.enabledPeerNetworks(), cl.config.ListenHost, cl.config.ListenPort, cl.config.ProxyURL, cl.firewallCallback)
cl.conns, err = listenAll(allPeerNetworks, cl.config.ListenHost, cl.config.ListenPort, cl.config.ProxyURL, cl.firewallCallback)
if err != nil {
return
}

View File

@ -873,37 +873,21 @@ func TestClientDynamicListenPortAllProtocols(t *testing.T) {
func TestClientDynamicListenTCPOnly(t *testing.T) {
cfg := TestingConfig()
cfg.DisableUTP = true
cfg.DisableTCP = false
cl, err := NewClient(cfg)
require.NoError(t, err)
defer cl.Close()
assert.NotEqual(t, 0, cl.LocalPort())
cl.eachListener(func(s socket) bool {
assert.True(t, isTcpNetwork(s.Addr().Network()))
return true
})
}
func TestClientDynamicListenUTPOnly(t *testing.T) {
cfg := TestingConfig()
cfg.DisableTCP = true
cfg.DisableUTP = false
cl, err := NewClient(cfg)
require.NoError(t, err)
defer cl.Close()
assert.NotEqual(t, 0, cl.LocalPort())
cl.eachListener(func(s socket) bool {
assert.True(t, isUtpNetwork(s.Addr().Network()))
return true
})
}
func TestClientDynamicListenPortNoProtocols(t *testing.T) {
cfg := TestingConfig()
cfg.DisableTCP = true
cfg.DisableUTP = true
cl, err := NewClient(cfg)
require.NoError(t, err)
defer cl.Close()
assert.Equal(t, 0, cl.LocalPort())
}
func totalConns(tts []*Torrent) (ret int) {