Allow DHT server config to be passed through when creating a new client

This commit is contained in:
Matt Joiner 2014-11-28 12:13:08 -06:00
parent 1c78c81075
commit 50e3db173f
2 changed files with 14 additions and 5 deletions

View File

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

View File

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