]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix race to set IPBlocklist on DHT before it bootstraps and serves
authorMatt Joiner <anacrolix@gmail.com>
Tue, 2 Jun 2015 13:58:49 +0000 (23:58 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 2 Jun 2015 13:58:49 +0000 (23:58 +1000)
client.go
dht/dht.go

index 29e0f1ef2c7001d5673a8e23cf65ad3f8db0c2ab..7e743b8f711519e723e45377642977395a3e5412 100644 (file)
--- a/client.go
+++ b/client.go
@@ -514,7 +514,9 @@ func NewClient(cfg *Config) (cl *Client, err error) {
        if !cfg.NoDHT {
                dhtCfg := cfg.DHTConfig
                if dhtCfg == nil {
-                       dhtCfg = &dht.ServerConfig{}
+                       dhtCfg = &dht.ServerConfig{
+                               IPBlocklist: cl.ipBlockList,
+                       }
                }
                if dhtCfg.Addr == "" {
                        dhtCfg.Addr = listenAddr()
@@ -526,9 +528,6 @@ func NewClient(cfg *Config) (cl *Client, err error) {
                if err != nil {
                        return
                }
-               if cl.ipBlockList != nil {
-                       cl.dHT.SetIPBlockList(cl.ipBlockList)
-               }
        }
 
        return
index de96fe9ecb4e1e7e3c218752511e608b9e42423a..01d2835209a7c0221bbe421087042be1acce1c72 100644 (file)
@@ -65,6 +65,9 @@ type ServerConfig struct {
        // Disable the DHT security extension:
        // http://www.libtorrent.org/dht_sec.html.
        NoSecurity bool
+       // Initial IP blocklist to use. Applied before serving and bootstrapping
+       // begins.
+       IPBlocklist *iplist.IPList
 }
 
 type ServerStats struct {
@@ -115,7 +118,8 @@ func NewServer(c *ServerConfig) (s *Server, err error) {
                c = &ServerConfig{}
        }
        s = &Server{
-               config: *c,
+               config:      *c,
+               ipBlockList: c.IPBlocklist,
        }
        if c.Conn != nil {
                s.socket = c.Conn