From 50e3db173f6148e7153e59afa0b4c89a05112636 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 28 Nov 2014 12:13:08 -0600 Subject: [PATCH] Allow DHT server config to be passed through when creating a new client --- client.go | 14 +++++++++----- config.go | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index 7230118b..d00c2c43 100644 --- a/client.go +++ b/client.go @@ -333,13 +333,17 @@ func NewClient(cfg *Config) (cl *Client, err error) { go cl.acceptConnections(utpL, true) } if !cfg.NoDHT { - cfg := dht.ServerConfig{ - Addr: listenAddr(), + dhtCfg := cfg.DHTConfig + if dhtCfg == nil { + dhtCfg = &dht.ServerConfig{} } - if utpL != nil { - cfg.Conn = utpL.RawConn + if dhtCfg.Addr == "" { + dhtCfg.Addr = listenAddr() } - cl.dHT, err = dht.NewServer(&cfg) + if dhtCfg.Conn == nil && utpL != nil { + dhtCfg.Conn = utpL.RawConn + } + cl.dHT, err = dht.NewServer(dhtCfg) if err != nil { return } diff --git a/config.go b/config.go index 06c35761..9b1cae61 100644 --- a/config.go +++ b/config.go @@ -1,11 +1,16 @@ package torrent +import ( + "bitbucket.org/anacrolix/go.torrent/dht" +) + type Config struct { DataDir string ListenAddr string DisableTrackers bool DownloadStrategy DownloadStrategy NoDHT bool + DHTConfig *dht.ServerConfig NoUpload bool PeerID string DisableUTP bool -- 2.48.1