forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
95 lines (86 loc) · 3.56 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package tendermint
import (
"net/url"
"strings"
"time"
"github.com/hyperledger/burrow/consensus/tendermint/abci"
tm_config "github.com/tendermint/tendermint/config"
)
// Burrow's view on Tendermint's config. Since we operate as a Tendermint harness not all configuration values
// are applicable, we may not allow some values to specified, or we may not allow some to be set independently.
// So this serves as a layer of indirection over Tendermint's real config that we derive from ours.
type BurrowTendermintConfig struct {
// Initial peers we connect to for peer exchange
Seeds string
// Whether this node should crawl the network looking for new peers - disconnecting to peers after it has shared addresses
SeedMode bool
// Peers to which we automatically connect
PersistentPeers string
ListenAddress string
// Optional external that nodes may provide with their NodeInfo
ExternalAddress string
// Set true for strict address routability rules
// Set false for private or local networks
AddrBookStrict bool
Moniker string
TendermintRoot string
// Peers ID or address this node is authorize to sync with
AuthorizedPeers string
// EmptyBlocks mode and possible interval between empty blocks in seconds
CreateEmptyBlocks bool
CreateEmptyBlocksInterval time.Duration
}
func DefaultBurrowTendermintConfig() *BurrowTendermintConfig {
tmDefaultConfig := tm_config.DefaultConfig()
return &BurrowTendermintConfig{
ListenAddress: tmDefaultConfig.P2P.ListenAddress,
ExternalAddress: tmDefaultConfig.P2P.ExternalAddress,
TendermintRoot: ".burrow",
CreateEmptyBlocks: tmDefaultConfig.Consensus.CreateEmptyBlocks,
CreateEmptyBlocksInterval: tmDefaultConfig.Consensus.CreateEmptyBlocksInterval,
}
}
func (btc *BurrowTendermintConfig) TendermintConfig() *tm_config.Config {
conf := tm_config.DefaultConfig()
if btc != nil {
// We may need to expose more of the P2P/Consensus/Mempool options, but I'd like to keep the configuration
// minimal
conf.RootDir = btc.TendermintRoot
conf.Consensus.RootDir = btc.TendermintRoot
conf.Consensus.CreateEmptyBlocks = btc.CreateEmptyBlocks
conf.Consensus.CreateEmptyBlocksInterval = btc.CreateEmptyBlocksInterval
conf.Mempool.RootDir = btc.TendermintRoot
conf.P2P.RootDir = btc.TendermintRoot
conf.P2P.Seeds = btc.Seeds
conf.P2P.SeedMode = btc.SeedMode
conf.P2P.PersistentPeers = btc.PersistentPeers
conf.P2P.ListenAddress = btc.ListenAddress
conf.P2P.ExternalAddress = btc.ExternalAddress
conf.P2P.AddrBookStrict = btc.AddrBookStrict
// We use this in tests and I am not aware of a strong reason to reject nodes on the same IP with different ports
conf.P2P.AllowDuplicateIP = true
conf.Moniker = btc.Moniker
// Unfortunately this stops metrics from being used at all
conf.Instrumentation.Prometheus = false
conf.FilterPeers = btc.AuthorizedPeers != ""
}
// Disable Tendermint RPC
conf.RPC.ListenAddress = ""
return conf
}
func (btc *BurrowTendermintConfig) DefaultAuthorizedPeersProvider() abci.PeersFilterProvider {
var authorizedPeersID, authorizedPeersAddress []string
authorizedPeersAddrOrID := strings.Split(btc.AuthorizedPeers, ",")
for _, authorizedPeerAddrOrID := range authorizedPeersAddrOrID {
_, err := url.Parse(authorizedPeerAddrOrID)
isNodeAddress := err != nil
if isNodeAddress {
authorizedPeersAddress = append(authorizedPeersAddress, authorizedPeerAddrOrID)
} else {
authorizedPeersID = append(authorizedPeersID, authorizedPeerAddrOrID)
}
}
return func() ([]string, []string) {
return authorizedPeersID, authorizedPeersAddress
}
}