From: Matt Joiner Date: Tue, 24 May 2016 09:46:24 +0000 (+1000) Subject: Improve the logic for which address to use for DHT X-Git-Tag: v1.0.0~692 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=060ff721755ad7a69f26ae7a79cc81e2873ddf47;p=btrtrc.git Improve the logic for which address to use for DHT --- diff --git a/client.go b/client.go index 340c7317..fe863299 100644 --- a/client.go +++ b/client.go @@ -314,9 +314,7 @@ func NewClient(cfg *Config) (cl *Client, err error) { if dhtCfg.IPBlocklist == nil { dhtCfg.IPBlocklist = cl.ipBlockList } - if dhtCfg.Addr == "" { - dhtCfg.Addr = cl.listenAddr - } + dhtCfg.Addr = firstNonEmptyString(dhtCfg.Addr, cl.listenAddr, cl.config.ListenAddr) if dhtCfg.Conn == nil && cl.utpSock != nil { dhtCfg.Conn = cl.utpSock } @@ -329,6 +327,15 @@ func NewClient(cfg *Config) (cl *Client, err error) { return } +func firstNonEmptyString(ss ...string) string { + for _, s := range ss { + if s != "" { + return s + } + } + return "" +} + // Stops the client. All connections to peers are closed and all activity will // come to a halt. func (cl *Client) Close() {