From 9bb32f41f1ded43bc6d66ddccd3c9f6e0f50cd12 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 8 Sep 2016 18:56:02 -0400 Subject: [PATCH] config: filter_peers defaults to false --- config/tendermint/config.go | 1 + config/tendermint_test/config.go | 1 + node/node.go | 39 +++++++++++++++++--------------- proxy/multi_app_conn.go | 14 +----------- 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/config/tendermint/config.go b/config/tendermint/config.go index 2bb57077..4d2323ab 100644 --- a/config/tendermint/config.go +++ b/config/tendermint/config.go @@ -70,6 +70,7 @@ func GetConfig(rootDir string) cfg.Config { mapConfig.SetDefault("revision_file", rootDir+"/revision") mapConfig.SetDefault("cswal", rootDir+"/data/cswal") mapConfig.SetDefault("cswal_light", false) + mapConfig.SetDefault("filter_peers", false) mapConfig.SetDefault("block_size", 10000) mapConfig.SetDefault("disable_data_hash", false) diff --git a/config/tendermint_test/config.go b/config/tendermint_test/config.go index 42233756..687720be 100644 --- a/config/tendermint_test/config.go +++ b/config/tendermint_test/config.go @@ -83,6 +83,7 @@ func ResetConfig(localPath string) cfg.Config { mapConfig.SetDefault("revision_file", rootDir+"/revision") mapConfig.SetDefault("cswal", rootDir+"/data/cswal") mapConfig.SetDefault("cswal_light", false) + mapConfig.SetDefault("filter_peers", false) mapConfig.SetDefault("block_size", 10000) mapConfig.SetDefault("disable_data_hash", false) diff --git a/node/node.go b/node/node.go index 5499d3c2..f66dc836 100644 --- a/node/node.go +++ b/node/node.go @@ -58,8 +58,8 @@ func NewNode(config cfg.Config, privValidator *types.PrivValidator) *Node { // Get State state := getState(config, stateDB) - // Create the proxyApp, which houses two connections, - // one for the consensus and one for the mempool. + // Create the proxyApp, which houses three connections: + // query, consensus, and mempool proxyApp := proxy.NewAppConns(config, state, blockStore) // add the chainid and number of validators to the global config @@ -112,22 +112,25 @@ func NewNode(config cfg.Config, privValidator *types.PrivValidator) *Node { sw.AddReactor("BLOCKCHAIN", bcReactor) sw.AddReactor("CONSENSUS", consensusReactor) - // filter peers by addr or pubkey - // NOTE: query format subject to change - sw.SetAddrFilter(func(addr net.Addr) error { - res := proxyApp.Query().QuerySync([]byte(Fmt("p2p/filter/addr/%s", addr.String()))) - if res.IsOK() { - return nil - } - return res - }) - sw.SetPubKeyFilter(func(pubkey crypto.PubKeyEd25519) error { - res := proxyApp.Query().QuerySync([]byte(Fmt("p2p/filter/pubkey/%X", pubkey.Bytes()))) - if res.IsOK() { - return nil - } - return res - }) + // filter peers by addr or pubkey with a tmsp query. + // if the query return code is OK, add peer + // XXX: query format subject to change + if config.GetBool("filter_peers") { + sw.SetAddrFilter(func(addr net.Addr) error { + res := proxyApp.Query().QuerySync([]byte(Fmt("p2p/filter/addr/%s", addr.String()))) + if res.IsOK() { + return nil + } + return res + }) + sw.SetPubKeyFilter(func(pubkey crypto.PubKeyEd25519) error { + res := proxyApp.Query().QuerySync([]byte(Fmt("p2p/filter/pubkey/%X", pubkey.Bytes()))) + if res.IsOK() { + return nil + } + return res + }) + } // add the event switch to all services // they should all satisfy events.Eventable diff --git a/proxy/multi_app_conn.go b/proxy/multi_app_conn.go index f61fea5f..b51bf2be 100644 --- a/proxy/multi_app_conn.go +++ b/proxy/multi_app_conn.go @@ -11,7 +11,7 @@ import ( nilapp "github.com/tendermint/tmsp/example/nil" ) -// Get a connected tmsp client and perform handshake +// Get a connected tmsp client func NewTMSPClient(addr, transport string) (tmspcli.Client, error) { var client tmspcli.Client @@ -38,18 +38,6 @@ func NewTMSPClient(addr, transport string) (tmspcli.Client, error) { return client, nil } -// TODO -func Handshake(config cfg.Config, state State, blockStore BlockStore) { - // XXX: Handshake - /*res := client.CommitSync() - if res.IsErr() { - PanicCrisis(Fmt("Error in getting multiAppConnConn hash: %v", res)) - } - if !bytes.Equal(hash, res.Data) { - log.Warn(Fmt("ProxyApp hash does not match. Expected %X, got %X", hash, res.Data)) - }*/ -} - //--------- type AppConns interface {