From 39592eba78bc139b9eeecdff978905d655c674cc Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 9 Jan 2018 19:13:25 -0800 Subject: [PATCH] btcd: pass user agent black and white lists to server --- btcd.go | 4 ++-- server.go | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/btcd.go b/btcd.go index a0ccb3ea..c17d6ab4 100644 --- a/btcd.go +++ b/btcd.go @@ -145,8 +145,8 @@ func btcdMain(serverChan chan<- *server) error { } // Create server and start it. - server, err := newServer(cfg.Listeners, db, activeNetParams.Params, - interrupt) + server, err := newServer(cfg.Listeners, cfg.AgentBlacklist, + cfg.AgentWhitelist, db, activeNetParams.Params, interrupt) if err != nil { // TODO: this logging could do with some beautifying. btcdLog.Errorf("Unable to start server on %v: %v", diff --git a/server.go b/server.go index ab2c31fe..d8fac256 100644 --- a/server.go +++ b/server.go @@ -2552,7 +2552,10 @@ func setupRPCListeners() ([]net.Listener, error) { // newServer returns a new btcd server configured to listen on addr for the // bitcoin network type specified by chainParams. Use start to begin accepting // connections from peers. -func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Params, interrupt <-chan struct{}) (*server, error) { +func newServer(listenAddrs, agentBlacklist, agentWhitelist []string, + db database.DB, chainParams *chaincfg.Params, + interrupt <-chan struct{}) (*server, error) { + services := defaultServices if cfg.NoPeerBloomFilters { services &^= wire.SFNodeBloom @@ -2576,6 +2579,13 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param } } + if len(agentBlacklist) > 0 { + srvrLog.Infof("User-agent blacklist %s", agentBlacklist) + } + if len(agentWhitelist) > 0 { + srvrLog.Infof("User-agent whitelist %s", agentWhitelist) + } + s := server{ chainParams: chainParams, addrManager: amgr, @@ -2595,6 +2605,8 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param sigCache: txscript.NewSigCache(cfg.SigCacheMaxSize), hashCache: txscript.NewHashCache(cfg.SigCacheMaxSize), cfCheckptCaches: make(map[wire.FilterType][]cfHeaderKV), + agentBlacklist: agentBlacklist, + agentWhitelist: agentWhitelist, } // Create the transaction and address indexes if needed.