2
0
mirror of synced 2025-02-24 14:48:27 +00:00

Fix race to set IPBlocklist on DHT before it bootstraps and serves

This commit is contained in:
Matt Joiner 2015-06-02 23:58:49 +10:00
parent 665e3c72fc
commit 5de6abd6a7
2 changed files with 8 additions and 5 deletions

View File

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

View 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