github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/rpc/config.go (about)

     1  package rpc
     2  
     3  import (
     4  	"net"
     5  )
     6  
     7  // 'LocalHost' gets interpreted as ipv6
     8  // TODO: revisit this
     9  const LocalHost = "127.0.0.1"
    10  const AnyLocal = "0.0.0.0"
    11  
    12  type RPCConfig struct {
    13  	Info     *ServerConfig  `json:",omitempty" toml:",omitempty"`
    14  	Profiler *ServerConfig  `json:",omitempty" toml:",omitempty"`
    15  	GRPC     *ServerConfig  `json:",omitempty" toml:",omitempty"`
    16  	Metrics  *MetricsConfig `json:",omitempty" toml:",omitempty"`
    17  	Web3     *ServerConfig  `json:",omitempty" toml:",omitempty"`
    18  }
    19  
    20  type ServerConfig struct {
    21  	Enabled    bool
    22  	ListenHost string
    23  	ListenPort string
    24  }
    25  
    26  func (sc *ServerConfig) ListenAddress() string {
    27  	return net.JoinHostPort(sc.ListenHost, sc.ListenPort)
    28  }
    29  
    30  type MetricsConfig struct {
    31  	ServerConfig
    32  	MetricsPath     string
    33  	BlockSampleSize int
    34  }
    35  
    36  func DefaultRPCConfig() *RPCConfig {
    37  	return &RPCConfig{
    38  		Info:     DefaultInfoConfig(),
    39  		Profiler: DefaultProfilerConfig(),
    40  		GRPC:     DefaultGRPCConfig(),
    41  		Metrics:  DefaultMetricsConfig(),
    42  		Web3:     DefaultWeb3Config(),
    43  	}
    44  }
    45  
    46  func DefaultInfoConfig() *ServerConfig {
    47  	return &ServerConfig{
    48  		Enabled:    true,
    49  		ListenHost: AnyLocal,
    50  		ListenPort: "26658",
    51  	}
    52  }
    53  
    54  func DefaultGRPCConfig() *ServerConfig {
    55  	return &ServerConfig{
    56  		Enabled:    true,
    57  		ListenHost: AnyLocal,
    58  		ListenPort: "10997",
    59  	}
    60  }
    61  
    62  func DefaultProfilerConfig() *ServerConfig {
    63  	return &ServerConfig{
    64  		Enabled:    false,
    65  		ListenHost: AnyLocal,
    66  		ListenPort: "6060",
    67  	}
    68  }
    69  
    70  func DefaultMetricsConfig() *MetricsConfig {
    71  	return &MetricsConfig{
    72  		ServerConfig: ServerConfig{
    73  			Enabled:    false,
    74  			ListenHost: AnyLocal,
    75  			ListenPort: "9102",
    76  		},
    77  		MetricsPath:     "/metrics",
    78  		BlockSampleSize: 100,
    79  	}
    80  }
    81  
    82  func DefaultWeb3Config() *ServerConfig {
    83  	return &ServerConfig{
    84  		Enabled:    true,
    85  		ListenHost: AnyLocal,
    86  		ListenPort: "26660",
    87  	}
    88  }