/
default.go
130 lines (114 loc) · 3.31 KB
/
default.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package config
import (
"fmt"
"github.com/coschain/contentos-go/common"
"github.com/coschain/contentos-go/common/constants"
"github.com/coschain/contentos-go/iservices/service-configs"
"github.com/coschain/contentos-go/mylog"
"github.com/coschain/contentos-go/node"
"github.com/pelletier/go-toml"
"io/ioutil"
"os"
"os/user"
"path/filepath"
"runtime"
)
const (
DefaultMinDiskSpaceInGB = 200
)
const (
DefaultRPCEndPoint = "0.0.0.0:8888"
DefaultHTTPEndPoint = "0.0.0.0:8080"
)
const (
DEFAULT_NODE_PORT = uint(20338)
DEFAULT_CONSENSUS_PORT = uint(20339)
DEFAULT_MAX_CONN_IN_BOUND = uint(23)
DEFAULT_MAX_CONN_OUT_BOUND = uint(23)
DEFAULT_MAX_CONN_IN_BOUND_FOR_SINGLE_IP = uint(23)
)
var TestNetConfig = &service_configs.GenesisConfig{
SeedList: []string{
fmt.Sprintf("127.0.0.1:%d", DEFAULT_NODE_PORT)},
}
var DevNetConfig = &service_configs.GenesisConfig{
SeedList: []string{
fmt.Sprintf("127.0.0.1:%d", DEFAULT_NODE_PORT)},
}
var MainNetConfig = &service_configs.GenesisConfig{
SeedList: []string{
fmt.Sprintf("127.0.0.1:%d", DEFAULT_NODE_PORT)},
}
// DefaultConfig contains reasonable default settings.
var DefaultNodeConfig = node.Config{
ChainId: common.ChainNameMainNet,
DataDir: DefaultDataDir(),
LogLevel: mylog.DebugLevel,
MinDiskSpaceInGB: DefaultMinDiskSpaceInGB,
P2P: service_configs.P2PConfig{
Genesis: MainNetConfig,
EnableConsensus: true,
ReservedCfg: &service_configs.P2PRsvConfig{},
ReservedPeersOnly: false,
NodePort: DEFAULT_NODE_PORT,
NodeConsensusPort: DEFAULT_CONSENSUS_PORT,
DualPortSupport: true,
IsTLS: false,
CertPath: "",
KeyPath: "",
CAPath: "",
MaxConnInBound: DEFAULT_MAX_CONN_IN_BOUND,
MaxConnOutBound: DEFAULT_MAX_CONN_OUT_BOUND,
MaxConnInBoundForSingleIP: DEFAULT_MAX_CONN_IN_BOUND_FOR_SINGLE_IP,
},
GRPC: service_configs.GRPCConfig{
RPCName: "rpc",
RPCListen: DefaultRPCEndPoint,
HTTPListen: DefaultHTTPEndPoint,
HTTPCors: []string{"*"},
HTTPLimit: 100,
},
Consensus: service_configs.ConsensusConfig{
Type: "SABFT",
BootStrap: true,
LocalBpName: constants.COSInitMiner,
LocalBpPrivateKey: constants.InitminerPrivKey,
},
HealthCheck: service_configs.HCheck{
Port: "9090",
},
// only for local or testing environment
Database: &service_configs.DatabaseConfig{
Driver: "mysql",
User: "contentos",
Password: "123456",
Db: "contentosdb",
},
}
func DefaultDataDir() string {
home := homeDir()
if home != "" {
return filepath.Join(home, ".coschain")
}
return ""
}
func homeDir() string {
if home := os.Getenv("HOME"); home != "" {
return home
}
if usr, err := user.Current(); err == nil {
return usr.HomeDir
}
return ""
}
func WriteNodeConfigFile(configDirPath string, configName string, config node.Config, mode os.FileMode) error {
configPath := filepath.Join(configDirPath, configName)
buffer, err := toml.Marshal(config)
if err != nil {
return err
}
return ioutil.WriteFile(configPath, buffer, mode)
}
func MakeName(name, version string) string {
return fmt.Sprintf("%s/%s/%s/%s", name, version, runtime.GOOS, runtime.Version())
}