From: Matt Joiner Date: Fri, 28 Nov 2014 18:13:08 +0000 (-0600) Subject: Allow DHT server config to be passed through when creating a new client X-Git-Tag: v1.0.0~1476 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=50e3db173f6148e7153e59afa0b4c89a05112636;p=btrtrc.git Allow DHT server config to be passed through when creating a new client --- 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