@@ -2,8 +2,10 @@ package main
22
33import (
44 "context"
5+ "fmt"
56 "os"
67 "os/signal"
8+ "strings"
79 "syscall"
810 "time"
911
@@ -19,37 +21,40 @@ const (
1921 flagCategoryDatabase = "Database Configuration:"
2022 flagCategoryDebugging = "Debugging Configuration:"
2123 flagCategoryCache = "Cache Configuration:"
24+ flagCategoryNetwork = "Network Specific Configuration:"
2225)
2326
24- var (
25- // RawVersion and build tag of the
26- // Nebula command line tool.
27- RawVersion = "dev"
28- )
27+ // RawVersion and build tag of the Nebula command line tool.
28+ var RawVersion = "dev"
2929
3030var rootConfig = & config.Root {
31- RawVersion : RawVersion ,
32- Debug : false ,
33- LogLevel : 4 ,
34- DialTimeout : time .Minute ,
35- TelemetryHost : "0.0.0.0" ,
36- TelemetryPort : 6666 ,
37- DatabaseHost : "localhost" ,
38- DatabasePort : 5432 ,
39- DatabaseName : "nebula" ,
40- DatabasePassword : "password" ,
41- DatabaseUser : "nebula" ,
42- DatabaseSSLMode : "disable" ,
43- AgentVersionsCacheSize : 200 ,
44- ProtocolsCacheSize : 100 ,
45- ProtocolsSetCacheSize : 200 ,
31+ RawVersion : RawVersion ,
32+ Debug : false ,
33+ LogLevel : 4 ,
34+ LogFormat : "text" ,
35+ LogDisableColor : false ,
36+ DialTimeout : time .Minute ,
37+ TelemetryHost : "0.0.0.0" ,
38+ TelemetryPort : 6666 ,
39+ Database : & config.Database {
40+ DryRun : false ,
41+ JSONOut : "" ,
42+ DatabaseHost : "localhost" ,
43+ DatabasePort : 5432 ,
44+ DatabaseName : "nebula" ,
45+ DatabasePassword : "password" ,
46+ DatabaseUser : "nebula" ,
47+ DatabaseSSLMode : "disable" ,
48+ AgentVersionsCacheSize : 200 ,
49+ ProtocolsCacheSize : 100 ,
50+ ProtocolsSetCacheSize : 200 ,
51+ },
4652}
4753
4854func main () {
49-
5055 app := & cli.App {
5156 Name : "nebula" ,
52- Usage : "A libp2p DHT crawler, monitor, and measurement tool that exposes timely information about DHT networks." ,
57+ Usage : "A DHT crawler, monitor, and measurement tool that exposes timely information about DHT networks." ,
5358 UsageText : "nebula [global options] command [command options] [arguments...]" ,
5459 Authors : []* cli.Author {
5560 {
@@ -76,6 +81,29 @@ func main() {
7681 Destination : & rootConfig .LogLevel ,
7782 Category : flagCategoryDebugging ,
7883 },
84+ & cli.StringFlag {
85+ Name : "log-format" ,
86+ Usage : "Define the formatting of the log output (values: text, json)" ,
87+ EnvVars : []string {"NEBULA_LOG_FORMAT" },
88+ Value : rootConfig .LogFormat ,
89+ Destination : & rootConfig .LogFormat ,
90+ Category : flagCategoryDebugging ,
91+ },
92+ & cli.BoolFlag {
93+ Name : "log-disable-color" ,
94+ Usage : "Whether to have colorized log output (only text log format)" ,
95+ EnvVars : []string {"NEBULA_LOG_COLOR" },
96+ Value : rootConfig .LogDisableColor ,
97+ Destination : & rootConfig .LogDisableColor ,
98+ Category : flagCategoryDebugging ,
99+ },
100+ & cli.DurationFlag {
101+ Name : "dial-timeout" ,
102+ Usage : "Global timeout when trying to connect to or dial another peer in the network." ,
103+ EnvVars : []string {"NEBULA_DIAL_TIMEOUT" },
104+ Value : rootConfig .DialTimeout ,
105+ Destination : & rootConfig .DialTimeout ,
106+ },
79107 & cli.StringFlag {
80108 Name : "telemetry-host" ,
81109 Usage : "To which network address should the telemetry (prometheus, pprof) server bind" ,
@@ -92,76 +120,92 @@ func main() {
92120 Destination : & rootConfig .TelemetryPort ,
93121 Category : flagCategoryDebugging ,
94122 },
123+ & cli.BoolFlag {
124+ Name : "dry-run" ,
125+ Usage : "Don't write anything to disk" ,
126+ EnvVars : []string {"NEBULA_DRY_RUN" , "NEBULA_CRAWL_DRY_RUN" /*<-legacy*/ },
127+ Value : rootConfig .Database .DryRun ,
128+ Destination : & rootConfig .Database .DryRun ,
129+ Category : flagCategoryDatabase ,
130+ },
131+ & cli.StringFlag {
132+ Name : "json-out" ,
133+ Usage : "If set, stores results as JSON documents at `DIR` (takes precedence over database settings)." ,
134+ EnvVars : []string {"NEBULA_JSON_OUT" , "NEBULA_CRAWL_JSON_OUT" /*<-legacy*/ },
135+ Value : rootConfig .Database .JSONOut ,
136+ Destination : & rootConfig .Database .JSONOut ,
137+ Category : flagCategoryDatabase ,
138+ },
95139 & cli.StringFlag {
96140 Name : "db-host" ,
97141 Usage : "On which host address can nebula reach the database" ,
98142 EnvVars : []string {"NEBULA_DATABASE_HOST" },
99- Value : rootConfig .DatabaseHost ,
100- Destination : & rootConfig .DatabaseHost ,
143+ Value : rootConfig .Database . DatabaseHost ,
144+ Destination : & rootConfig .Database . DatabaseHost ,
101145 Category : flagCategoryDatabase ,
102146 },
103147 & cli.IntFlag {
104148 Name : "db-port" ,
105149 Usage : "On which port can nebula reach the database" ,
106150 EnvVars : []string {"NEBULA_DATABASE_PORT" },
107- Value : rootConfig .DatabasePort ,
108- Destination : & rootConfig .DatabasePort ,
151+ Value : rootConfig .Database . DatabasePort ,
152+ Destination : & rootConfig .Database . DatabasePort ,
109153 Category : flagCategoryDatabase ,
110154 },
111155 & cli.StringFlag {
112156 Name : "db-name" ,
113157 Usage : "The name of the database to use" ,
114158 EnvVars : []string {"NEBULA_DATABASE_NAME" },
115- Value : rootConfig .DatabaseName ,
116- Destination : & rootConfig .DatabaseName ,
159+ Value : rootConfig .Database . DatabaseName ,
160+ Destination : & rootConfig .Database . DatabaseName ,
117161 Category : flagCategoryDatabase ,
118162 },
119163 & cli.StringFlag {
120164 Name : "db-password" ,
121165 Usage : "The password for the database to use" ,
122166 EnvVars : []string {"NEBULA_DATABASE_PASSWORD" },
123- Value : rootConfig .DatabasePassword ,
124- Destination : & rootConfig .DatabasePassword ,
167+ Value : rootConfig .Database . DatabasePassword ,
168+ Destination : & rootConfig .Database . DatabasePassword ,
125169 Category : flagCategoryDatabase ,
126170 },
127171 & cli.StringFlag {
128172 Name : "db-user" ,
129173 Usage : "The user with which to access the database to use" ,
130174 EnvVars : []string {"NEBULA_DATABASE_USER" },
131- Value : rootConfig .DatabaseUser ,
132- Destination : & rootConfig .DatabaseUser ,
175+ Value : rootConfig .Database . DatabaseUser ,
176+ Destination : & rootConfig .Database . DatabaseUser ,
133177 Category : flagCategoryDatabase ,
134178 },
135179 & cli.StringFlag {
136180 Name : "db-sslmode" ,
137181 Usage : "The sslmode to use when connecting the the database" ,
138182 EnvVars : []string {"NEBULA_DATABASE_SSL_MODE" },
139- Value : rootConfig .DatabaseSSLMode ,
140- Destination : & rootConfig .DatabaseSSLMode ,
183+ Value : rootConfig .Database . DatabaseSSLMode ,
184+ Destination : & rootConfig .Database . DatabaseSSLMode ,
141185 Category : flagCategoryDatabase ,
142186 },
143187 & cli.IntFlag {
144188 Name : "agent-versions-cache-size" ,
145189 Usage : "The cache size to hold agent versions in memory" ,
146190 EnvVars : []string {"NEBULA_AGENT_VERSIONS_CACHE_SIZE" },
147- Value : rootConfig .AgentVersionsCacheSize ,
148- Destination : & rootConfig .AgentVersionsCacheSize ,
191+ Value : rootConfig .Database . AgentVersionsCacheSize ,
192+ Destination : & rootConfig .Database . AgentVersionsCacheSize ,
149193 Category : flagCategoryCache ,
150194 },
151195 & cli.IntFlag {
152196 Name : "protocols-cache-size" ,
153197 Usage : "The cache size to hold protocols in memory" ,
154198 EnvVars : []string {"NEBULA_PROTOCOLS_CACHE_SIZE" },
155- Value : rootConfig .ProtocolsCacheSize ,
156- Destination : & rootConfig .ProtocolsCacheSize ,
199+ Value : rootConfig .Database . ProtocolsCacheSize ,
200+ Destination : & rootConfig .Database . ProtocolsCacheSize ,
157201 Category : flagCategoryCache ,
158202 },
159203 & cli.IntFlag {
160204 Name : "protocols-set-cache-size" ,
161205 Usage : "The cache size to hold sets of protocols in memory" ,
162206 EnvVars : []string {"NEBULA_PROTOCOLS_SET_CACHE_SIZE" },
163- Value : rootConfig .ProtocolsSetCacheSize ,
164- Destination : & rootConfig .ProtocolsSetCacheSize ,
207+ Value : rootConfig .Database . ProtocolsSetCacheSize ,
208+ Destination : & rootConfig .Database . ProtocolsSetCacheSize ,
165209 Category : flagCategoryCache ,
166210 },
167211 },
@@ -170,6 +214,7 @@ func main() {
170214 CrawlCommand ,
171215 MonitorCommand ,
172216 ResolveCommand ,
217+ NetworksCommand ,
173218 },
174219 }
175220
@@ -179,7 +224,7 @@ func main() {
179224 signal .Notify (sigs , syscall .SIGINT , syscall .SIGTERM , os .Interrupt , os .Kill )
180225 go func () {
181226 sig := <- sigs
182- log .Printf ("Received %s signal - Stopping...\n " , sig .String ())
227+ log .Infof ("Received %s signal - Stopping...\n " , sig .String ())
183228 signal .Stop (sigs )
184229 cancel ()
185230 }()
@@ -205,6 +250,17 @@ func Before(c *cli.Context) error {
205250 }
206251 }
207252
253+ switch strings .ToLower (c .String ("log-format" )) {
254+ case "text" :
255+ log .SetFormatter (& log.TextFormatter {
256+ DisableColors : c .Bool ("log-disable-color" ),
257+ })
258+ case "json" :
259+ log .SetFormatter (& log.JSONFormatter {})
260+ default :
261+ return fmt .Errorf ("unknown log format: %q" , c .String ("log-format" ))
262+ }
263+
208264 // Start prometheus metrics endpoint
209265 go metrics .ListenAndServe (rootConfig .TelemetryHost , rootConfig .TelemetryPort )
210266
0 commit comments