]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Improve the logic for which address to use for DHT
authorMatt Joiner <anacrolix@gmail.com>
Tue, 24 May 2016 09:46:24 +0000 (19:46 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 24 May 2016 09:46:24 +0000 (19:46 +1000)
client.go

index 340c7317c4d0769820a6fa18e1dae810a39eaedb..fe86329966eca84454930fc004bc7ba09243e18c 100644 (file)
--- 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() {