@ -47,6 +47,10 @@ import (
"github.com/tendermint/tendermint/version"
)
// CustomReactorNamePrefix is a prefix for all custom reactors to prevent
// clashes with built-in reactors.
const CustomReactorNamePrefix = "CUSTOM_"
//------------------------------------------------------------------------------
// DBContext specifies config information for loading a new DB.
@ -136,6 +140,18 @@ func DefaultMetricsProvider(config *cfg.InstrumentationConfig) MetricsProvider {
}
}
// Option sets a parameter for the node.
type Option func ( * Node )
// CustomReactors allows you to add custom reactors to the node's Switch.
func CustomReactors ( reactors map [ string ] p2p . Reactor ) Option {
return func ( n * Node ) {
for name , reactor := range reactors {
n . sw . AddReactor ( CustomReactorNamePrefix + name , reactor )
}
}
}
//------------------------------------------------------------------------------
// Node is the highest level interface to a full Tendermint node.
@ -433,6 +449,7 @@ func createSwitch(config *cfg.Config,
sw . AddReactor ( "BLOCKCHAIN" , bcReactor )
sw . AddReactor ( "CONSENSUS" , consensusReactor )
sw . AddReactor ( "EVIDENCE" , evidenceReactor )
sw . SetNodeInfo ( nodeInfo )
sw . SetNodeKey ( nodeKey )
@ -495,7 +512,8 @@ func NewNode(config *cfg.Config,
genesisDocProvider GenesisDocProvider ,
dbProvider DBProvider ,
metricsProvider MetricsProvider ,
logger log . Logger ) ( * Node , error ) {
logger log . Logger ,
options ... Option ) ( * Node , error ) {
blockStore , stateDB , err := initDBs ( config , dbProvider )
if err != nil {
@ -661,6 +679,11 @@ func NewNode(config *cfg.Config,
eventBus : eventBus ,
}
node . BaseService = * cmn . NewBaseService ( logger , "Node" , node )
for _ , option := range options {
option ( node )
}
return node , nil
}