]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Allow DHT server config to be passed through when creating a new client
authorMatt Joiner <anacrolix@gmail.com>
Fri, 28 Nov 2014 18:13:08 +0000 (12:13 -0600)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 28 Nov 2014 18:13:08 +0000 (12:13 -0600)
client.go
config.go

index 7230118bb060203c3918ec63e8c5ce0825b6ee33..d00c2c43dca2a722352f7a665e88a921897f71df 100644 (file)
--- 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
                }
index 06c35761ca455ba8ce1195110f1c3b46dfffe922..9b1cae618f069d8c0615e44d625d8416020d27c2 100644 (file)
--- 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