-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
195 lines (182 loc) · 5.52 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// Copyright 2017-2021 Digital Asset Exchange Limited. All rights reserved.
// Use of this source code is governed by BSD-3-Clause "New" or "Revised"
// License (BSD-3-Clause) that can be found in the LICENSE file.
package main
import (
"strconv"
"strings"
"time"
cli "github.com/jawher/mow.cli"
)
// defaultLogLevel might be overridden by testing.go
var defaultLogLevel = "4"
var (
goMaxProcs = app.String(cli.StringOpt{
Name: "p go-procs",
Desc: "The maximum number of CPUs that can be used simultaneously by Go runtime.",
EnvVar: "AN_GOMAXPROCS",
Value: "128",
})
// logLevel is set in main func
logLevel *string
)
var (
stateDir = app.String(cli.StringOpt{
Name: "S state-dir",
Desc: "Directory prefix for state indexed storage.",
EnvVar: "AN_STATE_DIR",
Value: "var/state",
})
stateGcInterval = app.String(cli.StringOpt{
Name: "state-gcinterval",
Desc: "Set a default GC interval for the state DB. Setting it lower will result in increased CPU load.",
EnvVar: "AN_STATE_GCINTERVAL",
Value: "5m",
})
fsDir = app.String(cli.StringOpt{
Name: "F fs-dir",
Desc: "Directory prefix for IPFS filesystem storage.",
EnvVar: "AN_FS_DIR",
Value: "var/fs",
})
logDir = app.String(cli.StringOpt{
Name: "log-dir",
Desc: "Directory prefix for logs",
EnvVar: "AN_LOG_DIR",
Value: "var/log",
})
fsBootstrapPeers = app.Strings(cli.StringsOpt{
Name: "B bootstrap-peers",
Desc: "Append to the list of IPFS bootstrap peers.",
EnvVar: "AN_FS_BOOTSTRAP_PEERS",
Value: []string{},
HideValue: true,
})
fsRelayEnabled = app.String(cli.StringOpt{
Name: "R relay-enabled",
Desc: "Enables IPFS relay support, may implicitly use extra network bandwidth.",
EnvVar: "AN_FS_RELAY_ENABLED",
Value: "true",
})
fsWarmupDur = app.String(cli.StringOpt{
Name: "warmup",
Desc: "Allocate some time for IPFS to warmup and find peers.",
EnvVar: "AN_FS_WARMUP_DUR",
Value: "5s",
})
fsSyncTimeout = app.String(cli.StringOpt{
Name: "sync-timeout",
Desc: "Sets the timeout for IPFS storage record sync.",
EnvVar: "AN_FS_SYNC_TIMEOUT",
Value: "10m",
})
fsListenAddr = app.String(cli.StringOpt{
Name: "L fs-listen-addr",
Desc: "Sets IPFS listen address to communicate with peers.",
EnvVar: "AN_FS_LISTEN_ADDR",
Value: "0.0.0.0:33770",
})
webListenAddr = app.String(cli.StringOpt{
Name: "W web-listen-addr",
Desc: "Sets webserver listen address for public API.",
EnvVar: "AN_WEB_LISTEN_ADDR",
Value: "0.0.0.0:33780",
})
// clusterEnabled = app.String(cli.StringOpt{
// Name: "cluster-enabled",
// Desc: "Enable cluster discovery (experimental).",
// EnvVar: "AN_CLUSTER_ENABLED",
// Value: "false",
// })
// clusterName = app.String(cli.StringOpt{
// Name: "C cluster-name",
// Desc: "Specifies cluster name.",
// EnvVar: "AN_CLUSTER_NAME",
// Value: "",
// })
fsNetworkProfile = app.String(cli.StringOpt{
Name: "N fs-network-profile",
Desc: "Sets IPFS network profile. Available: default, server, no-modify.",
EnvVar: "AN_FS_NETWORK_PROFILE",
Value: "default",
})
envTestnet = app.Bool(cli.BoolOpt{
Name: "T testnet",
Desc: "Switch node into testing mode, it runs in a seprate testnet environment.",
EnvVar: "AN_TESTNET_ENABLED",
Value: false,
})
envTestnetKey = app.String(cli.StringOpt{
Name: "testnet-key",
Desc: "Override the default testnet key with yours (generate it using atlant-keygen).",
EnvVar: "AN_TESTNET_KEY",
Value: testKey,
HideValue: true,
})
envTestnetDomains = app.Strings(cli.StringsOpt{
Name: "testnet-auth-domains",
Desc: "Specify additional DNS authority domains for a testnet environment.",
EnvVar: "AN_TESTNET_DOMAINS",
Value: nil,
HideValue: true,
})
envTestnetUrls = app.Strings(cli.StringsOpt{
Name: "testnet-auth-urls",
Desc: "Specify additional authority HTTP endpoints for a testnet environment.",
EnvVar: "AN_TESTNET_URLS",
Value: nil,
HideValue: true,
})
)
var (
ethAddress = app.String(cli.StringOpt{
Name: "E ethereum-wallet",
Desc: "Specify Ethereum wallet to associate with work done in the session.",
EnvVar: "AN_ETHEREUM_WALLET",
Value: "",
HideValue: true,
})
)
// use atlant-keygen to generate a custom key
var (
mainKey = "cc54285ef67145dd2d0f46f1ad1150cc1f1e22e0806e065c02746621a9ccda3d"
testKey = "eb4d8d6b43697aff9ee41bcd05e7125838e428ca44c7bbc65cc6cf1c9b881d0b"
)
var (
mainBootstrapPeers = []string{}
testBootstrapPeers = []string{
"/dns4/node-dev1.atlant.io/tcp/33770/ipfs/14V8BdHqHhExw4645xB3Xa2iheBrjYCMr7StXWUA9hBTqp8cM",
"/dns4/node-dev2.atlant.io/tcp/33770/ipfs/14V8Bds64aUZJx6ag2TUXozS78Sko6fJ8kbkHF4bgvv9zgR6j",
"/dns4/node-dev3.atlant.io/tcp/33770/ipfs/14V8BVs2FyU5qREKd68SgPqccrChiWX2uKdeeMtUhGfqJZjyK",
"/dns4/node-dev4.atlant.io/tcp/33770/ipfs/14V8BTKR9MjKhfqgT4ybBjSb7kZHXmwvgBba7ujhN6ecTXJji",
}
)
func duration(s string, defaults time.Duration) time.Duration {
dur, err := time.ParseDuration(s)
if err != nil {
dur = defaults
}
return dur
}
func toList(s string) []string {
return strings.Split(s, ",")
}
func toBool(s string) bool {
switch strings.ToLower(s) {
case "true", "1", "t", "yes":
return true
default:
return false
}
}
func toNatural(s string, defaults uint64) int {
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
// defaults in case of incorrect or empty "" value
return int(defaults)
} else if i < 0 {
// not defaults, because nobody expects +100 while specifying -100
return 0
}
return int(i)
}