forked from FactomProject/FactomCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
143 lines (129 loc) · 4.55 KB
/
config.go
File metadata and controls
143 lines (129 loc) · 4.55 KB
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
package util
import (
"log"
"os"
"os/user"
"code.google.com/p/gcfg"
)
type FactomdConfig struct {
App struct {
PortNumber int
LdbPath string // should be removed, and default to $defaultDataDir/ldb9
DataStorePath string // should be removed, and default to $defaultDataDir/store
DirectoryBlockInSeconds int
NodeMode string
ServerPrivKey string
}
Btc struct {
BTCPubAddr string
SendToBTCinSeconds int
WalletPassphrase string
CertHomePath string
RpcClientHost string
RpcClientEndpoint string
RpcClientUser string
RpcClientPass string
BtcTransFee float64
CertHomePathBtcd string
RpcBtcdHost string
RpcUser string
RpcPass string
}
Rpc struct {
PortNumber int
ApplicationName string
RefreshInSeconds int
}
Wsapi struct {
PortNumber int
ApplicationName string
RefreshInSeconds int
}
Log struct {
LogPath string
LogLevel string
}
// AddPeers []string `short:"a" long:"addpeer" description:"Add a peer to connect with at startup"`
// ConnectPeers []string `long:"connect" description:"Connect only to the specified peers at startup"`
Proxy string `long:"proxy" description:"Connect via SOCKS5 proxy (eg. 127.0.0.1:9050)"`
DisableListen bool `long:"nolisten" description:"Disable listening for incoming connections -- NOTE: Listening is automatically disabled if the --connect or --proxy options are used without also specifying listen interfaces via --listen"`
DisableRPC bool `long:"norpc" description:"Disable built-in RPC server -- NOTE: The RPC server is disabled by default if no rpcuser/rpcpass is specified"`
DisableTLS bool `long:"notls" description:"Disable TLS for the RPC server -- NOTE: This is only allowed if the RPC server is bound to localhost"`
DisableDNSSeed bool `long:"nodnsseed" description:"Disable DNS seeding for peers"`
}
// defaultConfig
const defaultConfig = `
; ------------------------------------------------------------------------------
; App settings
; ------------------------------------------------------------------------------
[app]
PortNumber = 8088
LdbPath = "/tmp/ldb9"
DataStorePath = "/tmp/store/seed/"
DirectoryBlockInSeconds = 60
;---- NodeMode - FULL,SERVER,LIGHT -----
NodeMode = FULL
ServerPrivKey = ""
[btc]
BTCPubAddr = "movaFTARmsaTMk3j71MpX8HtMURpsKhdra"
SendToBTCinSeconds = 600
WalletPassphrase = "lindasilva"
CertHomePath = "btcwallet"
RpcClientHost = "localhost:18332"
RpcClientEndpoint = "ws"
RpcClientUser = "testuser"
RpcClientPass = "notarychain"
BtcTransFee = 0.0001
CertHomePathBtcd = "btcd"
RpcBtcdHost = "localhost:18334"
[wsapi]
ApplicationName = "Factom/wsapi"
PortNumber = 8088
RefreshInSeconds = 60
; ------------------------------------------------------------------------------
; LogLevel - debug,info,notice,warning,error,critical,alert,emergency,none
; ------------------------------------------------------------------------------
[log]
LogLevel = warning
LogPath = /tmp/factomd.log
`
// GetConfig reads the default factomd.conf file and returns a FactomConfig
// object corresponding to the state of the file.
func ReadConfig() *FactomdConfig {
cfg := new(FactomdConfig)
filename := getHomeDir() + "/.factom/factomd.conf"
log.Println("read factom config file: ", filename)
// This makes factom config file located at
// POSIX (Linux/BSD): ~/.factom/factom.conf
// Mac OS: $HOME/Library/Application Support/Factom/factom.conf
// Windows: %LOCALAPPDATA%\Factom\factom.conf
// Plan 9: $home/factom/factom.conf
//factomHomeDir := btcutil.AppDataDir("factom", false)
//defaultConfigFile := filepath.Join(factomHomeDir, "factomd.conf")
//
// eventually we need to make data dir as following
//defaultDataDir = filepath.Join(factomHomeDir, "data")
//LdbPath = filepath.Join(defaultDataDir, "ldb9")
//DataStorePath = filepath.Join(defaultDataDir, "store/seed/")
err := gcfg.ReadFileInto(cfg, filename)
if err != nil {
log.Println("Server starting with default settings...")
gcfg.ReadStringInto(cfg, defaultConfig)
}
return cfg
}
func getHomeDir() string {
// Get the OS specific home directory via the Go standard lib.
var homeDir string
usr, err := user.Current()
if err == nil {
homeDir = usr.HomeDir
}
// Fall back to standard HOME environment variable that works
// for most POSIX OSes if the directory from the Go standard
// lib failed.
if err != nil || homeDir == "" {
homeDir = os.Getenv("HOME")
}
return homeDir
}