From 0072778c7f3ed36e4e1db341c25650d5a2053f4d Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Fri, 3 Sep 2021 13:05:59 -0700 Subject: [PATCH] fix config save/ensure/load logic --- cmd/gnoland/main.go | 4 +- go.mod | 1 + go.sum | 2 + pkgs/bft/config/config.go | 76 +++++++++++++++++++++-------- pkgs/bft/config/toml.go | 39 +++++---------- pkgs/bft/consensus/config/config.go | 28 +++++------ pkgs/bft/mempool/config/config.go | 14 +++--- pkgs/bft/rpc/config/config.go | 28 +++++------ pkgs/p2p/config/config.go | 42 ++++++++-------- pkgs/p2p/conn/connection.go | 12 ++--- 10 files changed, 134 insertions(+), 112 deletions(-) diff --git a/cmd/gnoland/main.go b/cmd/gnoland/main.go index 0bbe9e5503d..4cb9eadbb76 100644 --- a/cmd/gnoland/main.go +++ b/cmd/gnoland/main.go @@ -18,10 +18,8 @@ import ( func main() { logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) - cfg := config.DefaultConfig() rootDir := "testdir" - config.EnsureRoot(rootDir) - cfg.SetRootDir(rootDir) + cfg := config.LoadOrMakeDefaultConfig(rootDir) // create priv validator first. // need it to generate genesis.json diff --git a/go.mod b/go.mod index 3f27508a487..3c5cf6114e8 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/jmhodges/levigo v1.0.0 github.com/libp2p/go-buffer-pool v0.0.2 github.com/mattn/go-runewidth v0.0.10 + github.com/pelletier/go-toml v1.9.3 // indirect github.com/stretchr/testify v1.6.1 github.com/syndtr/goleveldb v1.0.0 github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c diff --git a/go.sum b/go.sum index 9f9219a3cd3..7fd8f62a5fa 100644 --- a/go.sum +++ b/go.sum @@ -64,6 +64,8 @@ github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= +github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY= diff --git a/pkgs/bft/config/config.go b/pkgs/bft/config/config.go index 907cafbf1e8..425d242baeb 100644 --- a/pkgs/bft/config/config.go +++ b/pkgs/bft/config/config.go @@ -10,19 +10,20 @@ import ( mem "github.com/gnolang/gno/pkgs/bft/mempool/config" rpc "github.com/gnolang/gno/pkgs/bft/rpc/config" "github.com/gnolang/gno/pkgs/errors" + osm "github.com/gnolang/gno/pkgs/os" p2p "github.com/gnolang/gno/pkgs/p2p/config" ) // Config defines the top level configuration for a Tendermint node type Config struct { // Top level options use an anonymous struct - BaseConfig `mapstructure:",squash"` + BaseConfig `toml:",squash"` // Options for services - RPC *rpc.RPCConfig `mapstructure:"rpc"` - P2P *p2p.P2PConfig `mapstructure:"p2p"` - Mempool *mem.MempoolConfig `mapstructure:"mempool"` - Consensus *cns.ConsensusConfig `mapstructure:"consensus"` + RPC *rpc.RPCConfig `toml:"rpc"` + P2P *p2p.P2PConfig `toml:"p2p"` + Mempool *mem.MempoolConfig `toml:"mempool"` + Consensus *cns.ConsensusConfig `toml:"consensus"` } // DefaultConfig returns a default configuration for a Tendermint node @@ -36,6 +37,25 @@ func DefaultConfig() *Config { } } +// LoadOrMakeDefaultConfig() loads configuration or saves a default one. +func LoadOrMakeDefaultConfig(root string) (cfg *Config) { + configPath := rootify(defaultConfigFilePath, root) + if osm.FileExists(configPath) { + cfg = LoadConfigFile(configPath) + cfg.SetRootDir(root) + cfg.EnsureDirs() + } else { + cfg = DefaultConfig() + cfg.SetRootDir(root) + cfg.EnsureDirs() + WriteConfigFile(configPath, cfg) + } + if err := cfg.ValidateBasic(); err != nil { + panic(err) + } + return cfg +} + // TestConfig returns a configuration that can be used for testing func TestConfig() *Config { return &Config{ @@ -57,6 +77,20 @@ func (cfg *Config) SetRootDir(root string) *Config { return cfg } +// EnsureDirs ensures default directories in root dir (and root dir). +func (cfg *Config) EnsureDirs() { + rootDir := cfg.BaseConfig.RootDir + if err := osm.EnsureDir(rootDir, DefaultDirPerm); err != nil { + panic(err.Error()) + } + if err := osm.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil { + panic(err.Error()) + } + if err := osm.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil { + panic(err.Error()) + } +} + // ValidateBasic performs basic validation (checking param bounds, etc.) and // returns an error if any check fails. func (cfg *Config) ValidateBasic() error { @@ -112,23 +146,23 @@ type BaseConfig struct { // The root directory for all data. // This should be set in viper so it can unmarshal into this struct - RootDir string `mapstructure:"home"` + RootDir string `toml:"home"` // TCP or UNIX socket address of the ABCI application, // or the name of an ABCI application compiled in with the Tendermint binary, // or empty if local application instance. - ProxyApp string `mapstructure:"proxy_app"` + ProxyApp string `toml:"proxy_app"` // Local application instance in lieu of remote app. LocalApp abci.Application // A custom human readable name for this node - Moniker string `mapstructure:"moniker"` + Moniker string `toml:"moniker"` // If this node is many blocks behind the tip of the chain, FastSync // allows them to catchup quickly by downloading blocks in parallel // and verifying their commits - FastSyncMode bool `mapstructure:"fast_sync"` + FastSyncMode bool `toml:"fast_sync"` // Database backend: goleveldb | cleveldb | boltdb // * goleveldb (github.com/syndtr/goleveldb - most popular implementation) @@ -142,42 +176,42 @@ type BaseConfig struct { // - EXPERIMENTAL // - may be faster is some use-cases (random reads - indexer) // - use boltdb build tag (go build -tags boltdb) - DBBackend string `mapstructure:"db_backend"` + DBBackend string `toml:"db_backend"` // Database directory - DBPath string `mapstructure:"db_dir"` + DBPath string `toml:"db_dir"` // Output level for logging - LogLevel string `mapstructure:"log_level"` + LogLevel string `toml:"log_level"` // Output format: 'plain' (colored text) or 'json' - LogFormat string `mapstructure:"log_format"` + LogFormat string `toml:"log_format"` // Path to the JSON file containing the initial validator set and other meta data - Genesis string `mapstructure:"genesis_file"` + Genesis string `toml:"genesis_file"` // Path to the JSON file containing the private key to use as a validator in the consensus protocol - PrivValidatorKey string `mapstructure:"priv_validator_key_file"` + PrivValidatorKey string `toml:"priv_validator_key_file"` // Path to the JSON file containing the last sign state of a validator - PrivValidatorState string `mapstructure:"priv_validator_state_file"` + PrivValidatorState string `toml:"priv_validator_state_file"` // TCP or UNIX socket address for Tendermint to listen on for // connections from an external PrivValidator process - PrivValidatorListenAddr string `mapstructure:"priv_validator_laddr"` + PrivValidatorListenAddr string `toml:"priv_validator_laddr"` // A JSON file containing the private key to use for p2p authenticated encryption - NodeKey string `mapstructure:"node_key_file"` + NodeKey string `toml:"node_key_file"` // Mechanism to connect to the ABCI application: local | socket - ABCI string `mapstructure:"abci"` + ABCI string `toml:"abci"` // TCP or UNIX socket address for the profiling server to listen on - ProfListenAddress string `mapstructure:"prof_laddr"` + ProfListenAddress string `toml:"prof_laddr"` // If true, query the ABCI app on connecting to a new peer // so the app can decide if we should keep the connection or not - FilterPeers bool `mapstructure:"filter_peers"` // false + FilterPeers bool `toml:"filter_peers"` // false } // DefaultBaseConfig returns a default base configuration for a Tendermint node diff --git a/pkgs/bft/config/toml.go b/pkgs/bft/config/toml.go index 6580b3e9c4f..a3bb541be7c 100644 --- a/pkgs/bft/config/toml.go +++ b/pkgs/bft/config/toml.go @@ -8,6 +8,7 @@ import ( "text/template" osm "github.com/gnolang/gno/pkgs/os" + "github.com/pelletier/go-toml" ) // DefaultDirPerm is the default permissions used when creating directories. @@ -22,34 +23,20 @@ func init() { } } -/****** these are for production settings ***********/ - -// EnsureRoot creates the root, config, and data directories if they don't exist, -// and panics if it fails. -func EnsureRoot(rootDir string) { - if err := osm.EnsureDir(rootDir, DefaultDirPerm); err != nil { - panic(err.Error()) - } - if err := osm.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil { - panic(err.Error()) - } - if err := osm.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil { - panic(err.Error()) +func LoadConfigFile(configFilePath string) *Config { + bz, err := ioutil.ReadFile(configFilePath) + if err != nil { + panic(err) } - - configFilePath := filepath.Join(rootDir, defaultConfigFilePath) - - // Write default config file if missing. - if !osm.FileExists(configFilePath) { - writeDefaultConfigFile(configFilePath) + var config Config + err = toml.Unmarshal(bz, &config) + if err != nil { + panic(err) } + return &config } -// XXX: this func should probably be called by cmd/tendermint/commands/init.go -// alongside the writing of the genesis.json and priv_validator.json -func writeDefaultConfigFile(configFilePath string) { - WriteConfigFile(configFilePath, DefaultConfig()) -} +/****** these are for production settings ***********/ // WriteConfigFile renders config using the template and writes it to configFilePath. func WriteConfigFile(configFilePath string, config *Config) { @@ -62,7 +49,7 @@ func WriteConfigFile(configFilePath string, config *Config) { osm.MustWriteFile(configFilePath, buffer.Bytes(), 0644) } -// Note: any changes to the comments/variables/mapstructure +// Note: any changes to the comments/variables/field-names // must be reflected in the appropriate struct in config/config.go const defaultConfigTemplate = `# This is a TOML config file. # For more information, see https://github.com/toml-lang/toml @@ -330,7 +317,7 @@ func ResetTestRootWithChainID(testName string, chainID string) *Config { // Write default config file if missing. if !osm.FileExists(configFilePath) { - writeDefaultConfigFile(configFilePath) + WriteConfigFile(configFilePath, DefaultConfig()) } if !osm.FileExists(genesisFilePath) { if chainID == "" { diff --git a/pkgs/bft/consensus/config/config.go b/pkgs/bft/consensus/config/config.go index f13851b24d7..6358473b30b 100644 --- a/pkgs/bft/consensus/config/config.go +++ b/pkgs/bft/consensus/config/config.go @@ -16,28 +16,28 @@ const ( // ConsensusConfig defines the configuration for the Tendermint consensus service, // including timeouts and details about the WAL and the block structure. type ConsensusConfig struct { - RootDir string `mapstructure:"home"` - WalPath string `mapstructure:"wal_file"` + RootDir string `toml:"home"` + WalPath string `toml:"wal_file"` walFile string // overrides WalPath if set - TimeoutPropose time.Duration `mapstructure:"timeout_propose"` - TimeoutProposeDelta time.Duration `mapstructure:"timeout_propose_delta"` - TimeoutPrevote time.Duration `mapstructure:"timeout_prevote"` - TimeoutPrevoteDelta time.Duration `mapstructure:"timeout_prevote_delta"` - TimeoutPrecommit time.Duration `mapstructure:"timeout_precommit"` - TimeoutPrecommitDelta time.Duration `mapstructure:"timeout_precommit_delta"` - TimeoutCommit time.Duration `mapstructure:"timeout_commit"` + TimeoutPropose time.Duration `toml:"timeout_propose"` + TimeoutProposeDelta time.Duration `toml:"timeout_propose_delta"` + TimeoutPrevote time.Duration `toml:"timeout_prevote"` + TimeoutPrevoteDelta time.Duration `toml:"timeout_prevote_delta"` + TimeoutPrecommit time.Duration `toml:"timeout_precommit"` + TimeoutPrecommitDelta time.Duration `toml:"timeout_precommit_delta"` + TimeoutCommit time.Duration `toml:"timeout_commit"` // Make progress as soon as we have all the precommits (as if TimeoutCommit = 0) - SkipTimeoutCommit bool `mapstructure:"skip_timeout_commit"` + SkipTimeoutCommit bool `toml:"skip_timeout_commit"` // EmptyBlocks mode and possible interval between empty blocks - CreateEmptyBlocks bool `mapstructure:"create_empty_blocks"` - CreateEmptyBlocksInterval time.Duration `mapstructure:"create_empty_blocks_interval"` + CreateEmptyBlocks bool `toml:"create_empty_blocks"` + CreateEmptyBlocksInterval time.Duration `toml:"create_empty_blocks_interval"` // Reactor sleep duration parameters - PeerGossipSleepDuration time.Duration `mapstructure:"peer_gossip_sleep_duration"` - PeerQueryMaj23SleepDuration time.Duration `mapstructure:"peer_query_maj23_sleep_duration"` + PeerGossipSleepDuration time.Duration `toml:"peer_gossip_sleep_duration"` + PeerQueryMaj23SleepDuration time.Duration `toml:"peer_query_maj23_sleep_duration"` } // DefaultConsensusConfig returns a default configuration for the consensus service diff --git a/pkgs/bft/mempool/config/config.go b/pkgs/bft/mempool/config/config.go index a5aaa12213c..d5c58bbfd90 100644 --- a/pkgs/bft/mempool/config/config.go +++ b/pkgs/bft/mempool/config/config.go @@ -7,13 +7,13 @@ import "github.com/gnolang/gno/pkgs/errors" // MempoolConfig defines the configuration options for the Tendermint mempool type MempoolConfig struct { - RootDir string `mapstructure:"home"` - Recheck bool `mapstructure:"recheck"` - Broadcast bool `mapstructure:"broadcast"` - WalPath string `mapstructure:"wal_dir"` - Size int `mapstructure:"size"` - MaxPendingTxsBytes int64 `mapstructure:"max_pending_txs_bytes"` - CacheSize int `mapstructure:"cache_size"` + RootDir string `toml:"home"` + Recheck bool `toml:"recheck"` + Broadcast bool `toml:"broadcast"` + WalPath string `toml:"wal_dir"` + Size int `toml:"size"` + MaxPendingTxsBytes int64 `toml:"max_pending_txs_bytes"` + CacheSize int `toml:"cache_size"` } // DefaultMempoolConfig returns a default configuration for the Tendermint mempool diff --git a/pkgs/bft/rpc/config/config.go b/pkgs/bft/rpc/config/config.go index 694b4d31e8a..253f11196fd 100644 --- a/pkgs/bft/rpc/config/config.go +++ b/pkgs/bft/rpc/config/config.go @@ -16,36 +16,36 @@ const ( // RPCConfig defines the configuration options for the Tendermint RPC server type RPCConfig struct { - RootDir string `mapstructure:"home"` + RootDir string `toml:"home"` // TCP or UNIX socket address for the RPC server to listen on - ListenAddress string `mapstructure:"laddr"` + ListenAddress string `toml:"laddr"` // A list of origins a cross-domain request can be executed from. // If the special '*' value is present in the list, all origins will be allowed. // An origin may contain a wildcard (*) to replace 0 or more characters (i.e.: http://*.domain.com). // Only one wildcard can be used per origin. - CORSAllowedOrigins []string `mapstructure:"cors_allowed_origins"` + CORSAllowedOrigins []string `toml:"cors_allowed_origins"` // A list of methods the client is allowed to use with cross-domain requests. - CORSAllowedMethods []string `mapstructure:"cors_allowed_methods"` + CORSAllowedMethods []string `toml:"cors_allowed_methods"` // A list of non simple headers the client is allowed to use with cross-domain requests. - CORSAllowedHeaders []string `mapstructure:"cors_allowed_headers"` + CORSAllowedHeaders []string `toml:"cors_allowed_headers"` // TCP or UNIX socket address for the gRPC server to listen on // NOTE: This server only supports /broadcast_tx_commit - GRPCListenAddress string `mapstructure:"grpc_laddr"` + GRPCListenAddress string `toml:"grpc_laddr"` // Maximum number of simultaneous connections. // Does not include RPC (HTTP&WebSocket) connections. See max_open_connections // If you want to accept a larger number than the default, make sure // you increase your OS limits. // 0 - unlimited. - GRPCMaxOpenConnections int `mapstructure:"grpc_max_open_connections"` + GRPCMaxOpenConnections int `toml:"grpc_max_open_connections"` // Activate unsafe RPC commands like /dial_persistent_peers and /unsafe_flush_mempool - Unsafe bool `mapstructure:"unsafe"` + Unsafe bool `toml:"unsafe"` // Maximum number of simultaneous connections (including WebSocket). // Does not include gRPC connections. See grpc_max_open_connections @@ -54,19 +54,19 @@ type RPCConfig struct { // 0 - unlimited. // Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files} // 1024 - 40 - 10 - 50 = 924 = ~900 - MaxOpenConnections int `mapstructure:"max_open_connections"` + MaxOpenConnections int `toml:"max_open_connections"` // How long to wait for a tx to be committed during /broadcast_tx_commit // WARNING: Using a value larger than 10s will result in increasing the // global HTTP write timeout, which applies to all connections and endpoints. // See https://github.com/gnolang/gno/pkgs/bft/issues/3435 - TimeoutBroadcastTxCommit time.Duration `mapstructure:"timeout_broadcast_tx_commit"` + TimeoutBroadcastTxCommit time.Duration `toml:"timeout_broadcast_tx_commit"` // Maximum size of request body, in bytes - MaxBodyBytes int64 `mapstructure:"max_body_bytes"` + MaxBodyBytes int64 `toml:"max_body_bytes"` // Maximum size of request header, in bytes - MaxHeaderBytes int `mapstructure:"max_header_bytes"` + MaxHeaderBytes int `toml:"max_header_bytes"` // The path to a file containing certificate that is used to create the HTTPS server. // Migth be either absolute path or path related to tendermint's config directory. @@ -76,13 +76,13 @@ type RPCConfig struct { // and the CA's certificate. // // NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server. Otherwise, HTTP server is run. - TLSCertFile string `mapstructure:"tls_cert_file"` + TLSCertFile string `toml:"tls_cert_file"` // The path to a file containing matching private key that is used to create the HTTPS server. // Migth be either absolute path or path related to tendermint's config directory. // // NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server. Otherwise, HTTP server is run. - TLSKeyFile string `mapstructure:"tls_key_file"` + TLSKeyFile string `toml:"tls_key_file"` } // DefaultRPCConfig returns a default configuration for the RPC server diff --git a/pkgs/p2p/config/config.go b/pkgs/p2p/config/config.go index 3c3d35987ec..ddfe27a962e 100644 --- a/pkgs/p2p/config/config.go +++ b/pkgs/p2p/config/config.go @@ -22,67 +22,67 @@ var ( // P2PConfig defines the configuration options for the Tendermint peer-to-peer networking layer type P2PConfig struct { - RootDir string `mapstructure:"home"` + RootDir string `toml:"home"` // Address to listen for incoming connections - ListenAddress string `mapstructure:"laddr"` + ListenAddress string `toml:"laddr"` // Address to advertise to peers for them to dial - ExternalAddress string `mapstructure:"external_address"` + ExternalAddress string `toml:"external_address"` // Comma separated list of seed nodes to connect to - Seeds string `mapstructure:"seeds"` + Seeds string `toml:"seeds"` // Comma separated list of nodes to keep persistent connections to - PersistentPeers string `mapstructure:"persistent_peers"` + PersistentPeers string `toml:"persistent_peers"` // UPNP port forwarding - UPNP bool `mapstructure:"upnp"` + UPNP bool `toml:"upnp"` // Maximum number of inbound peers - MaxNumInboundPeers int `mapstructure:"max_num_inbound_peers"` + MaxNumInboundPeers int `toml:"max_num_inbound_peers"` // Maximum number of outbound peers to connect to, excluding persistent peers - MaxNumOutboundPeers int `mapstructure:"max_num_outbound_peers"` + MaxNumOutboundPeers int `toml:"max_num_outbound_peers"` // Time to wait before flushing messages out on the connection - FlushThrottleTimeout time.Duration `mapstructure:"flush_throttle_timeout"` + FlushThrottleTimeout time.Duration `toml:"flush_throttle_timeout"` // Maximum size of a message packet payload, in bytes - MaxPacketMsgPayloadSize int `mapstructure:"max_packet_msg_payload_size"` + MaxPacketMsgPayloadSize int `toml:"max_packet_msg_payload_size"` // Rate at which packets can be sent, in bytes/second - SendRate int64 `mapstructure:"send_rate"` + SendRate int64 `toml:"send_rate"` // Rate at which packets can be received, in bytes/second - RecvRate int64 `mapstructure:"recv_rate"` + RecvRate int64 `toml:"recv_rate"` // Set true to enable the peer-exchange reactor - PexReactor bool `mapstructure:"pex"` + PexReactor bool `toml:"pex"` // Seed mode, in which node constantly crawls the network and looks for // peers. If another node asks it for addresses, it responds and disconnects. // // Does not work if the peer-exchange reactor is disabled. - SeedMode bool `mapstructure:"seed_mode"` + SeedMode bool `toml:"seed_mode"` // Comma separated list of peer IDs to keep private (will not be gossiped to // other peers) - PrivatePeerIDs string `mapstructure:"private_peer_ids"` + PrivatePeerIDs string `toml:"private_peer_ids"` // Toggle to disable guard against peers connecting from the same ip. - AllowDuplicateIP bool `mapstructure:"allow_duplicate_ip"` + AllowDuplicateIP bool `toml:"allow_duplicate_ip"` // Peer connection configuration. - HandshakeTimeout time.Duration `mapstructure:"handshake_timeout"` - DialTimeout time.Duration `mapstructure:"dial_timeout"` + HandshakeTimeout time.Duration `toml:"handshake_timeout"` + DialTimeout time.Duration `toml:"dial_timeout"` // Testing params. // Force dial to fail - TestDialFail bool `mapstructure:"test_dial_fail"` + TestDialFail bool `toml:"test_dial_fail"` // FUzz connection - TestFuzz bool `mapstructure:"test_fuzz"` - TestFuzzConfig *FuzzConnConfig `mapstructure:"test_fuzz_config"` + TestFuzz bool `toml:"test_fuzz"` + TestFuzzConfig *FuzzConnConfig `toml:"test_fuzz_config"` } // DefaultP2PConfig returns a default configuration for the peer-to-peer layer diff --git a/pkgs/p2p/conn/connection.go b/pkgs/p2p/conn/connection.go index 5ad8909ad59..91c68d41ba0 100644 --- a/pkgs/p2p/conn/connection.go +++ b/pkgs/p2p/conn/connection.go @@ -117,20 +117,20 @@ type MConnection struct { // MConnConfig is a MConnection configuration. type MConnConfig struct { - SendRate int64 `mapstructure:"send_rate"` - RecvRate int64 `mapstructure:"recv_rate"` + SendRate int64 `toml:"send_rate"` + RecvRate int64 `toml:"recv_rate"` // Maximum payload size - MaxPacketMsgPayloadSize int `mapstructure:"max_packet_msg_payload_size"` + MaxPacketMsgPayloadSize int `toml:"max_packet_msg_payload_size"` // Interval to flush writes (throttled) - FlushThrottle time.Duration `mapstructure:"flush_throttle"` + FlushThrottle time.Duration `toml:"flush_throttle"` // Interval to send pings - PingInterval time.Duration `mapstructure:"ping_interval"` + PingInterval time.Duration `toml:"ping_interval"` // Maximum wait time for pongs - PongTimeout time.Duration `mapstructure:"pong_timeout"` + PongTimeout time.Duration `toml:"pong_timeout"` } // DefaultMConnConfig returns the default config.