/
waku.go
487 lines (475 loc) · 14.4 KB
/
waku.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
package main
import (
"os"
"time"
logging "github.com/ipfs/go-log"
"github.com/status-im/go-waku/waku"
"github.com/status-im/go-waku/waku/cliutils"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/urfave/cli/v2"
)
var options waku.Options
func main() {
// Defaults
options.LogLevel = "INFO"
options.LogEncoding = "console"
cliFlags := []cli.Flag{
&cli.IntFlag{
Name: "tcp-port",
Aliases: []string{"port", "p"},
Value: 60000,
Usage: "Libp2p TCP listening port (0 for random)",
Destination: &options.Port,
},
&cli.StringFlag{
Name: "address",
Aliases: []string{"host", "listen-address"},
Value: "0.0.0.0",
Usage: "Listening address",
Destination: &options.Address,
},
&cli.BoolFlag{
Name: "websocket-support",
Aliases: []string{"ws"},
Usage: "Enable websockets support",
Destination: &options.Websocket.Enable,
},
&cli.IntFlag{
Name: "websocket-port",
Aliases: []string{"ws-port"},
Value: 60001,
Usage: "Libp2p TCP listening port for websocket connection (0 for random)",
Destination: &options.Websocket.WSPort,
},
&cli.IntFlag{
Name: "websocket-secure-port",
Aliases: []string{"wss-port"},
Value: 6443,
Usage: "Libp2p TCP listening port for secure websocket connection (0 for random, binding to 443 requires root access)",
Destination: &options.Websocket.WSSPort,
},
&cli.StringFlag{
Name: "websocket-address",
Aliases: []string{"ws-address"},
Value: "0.0.0.0",
Usage: "Listening address for websocket connections",
Destination: &options.Websocket.Address,
},
&cli.BoolFlag{
Name: "websocket-secure-support",
Aliases: []string{"wss"},
Usage: "Enable secure websockets support",
Destination: &options.Websocket.Secure,
},
&cli.PathFlag{
Name: "websocket-secure-key-path",
Aliases: []string{"wss-key"},
Value: "/path/to/key.txt",
Usage: "Secure websocket key path",
Destination: &options.Websocket.KeyPath,
},
&cli.PathFlag{
Name: "websocket-secure-cert-path",
Aliases: []string{"wss-cert"},
Value: "/path/to/cert.txt",
Usage: "Secure websocket certificate path",
Destination: &options.Websocket.CertPath,
},
&cli.StringFlag{
Name: "dns4-domain-name",
Value: "",
Usage: "The domain name resolving to the node's public IPv4 address",
Destination: &options.Dns4DomainName,
},
&cli.GenericFlag{
Name: "nodekey",
Usage: "P2P node private key as hex. Can also be set with GOWAKU-NODEKEY env variable (default random)",
Value: &cliutils.PrivateKeyValue{
Value: &options.NodeKey,
},
EnvVars: []string{"GOWAKU-NODEKEY"},
},
&cli.PathFlag{
Name: "key-file",
Value: "./nodekey",
Usage: "Path to a file containing the private key for the P2P node",
Destination: &options.KeyFile,
},
&cli.StringFlag{
Name: "key-password",
Value: "secret",
Usage: "Password used for the private key file",
Destination: &options.KeyPasswd,
},
&cli.BoolFlag{
Name: "generate-key",
Usage: "Generate private key file at path specified in --key-file with the password defined by --key-password",
Destination: &options.GenerateKey,
},
&cli.BoolFlag{
Name: "overwrite",
Usage: "When generating a keyfile, overwrite the nodekey file if it already exists",
Destination: &options.Overwrite,
},
&cli.GenericFlag{
Name: "staticnode",
Usage: "Multiaddr of peer to directly connect with. Option may be repeated",
Value: &cliutils.MultiaddrSlice{
Values: &options.StaticNodes,
},
},
&cli.DurationFlag{
Name: "keep-alive",
Value: 20 * time.Second,
Usage: "Interval in seconds for pinging peers to keep the connection alive.",
Destination: &options.KeepAlive,
},
&cli.BoolFlag{
Name: "use-db",
Aliases: []string{"sqlite-store"},
Usage: "Use SQLiteDB to persist information",
Destination: &options.UseDB,
},
&cli.BoolFlag{
Name: "persist-messages",
Usage: "Enable message persistence",
Destination: &options.Store.PersistMessages,
Value: false,
},
&cli.BoolFlag{
Name: "persist-peers",
Usage: "Enable peer persistence",
Destination: &options.PersistPeers,
Value: false,
},
&cli.StringFlag{
Name: "nat", // This was added so js-waku test don't fail
Usage: "TODO: Not implemented yet. Specify method to use for determining public address: any, none ('any' will attempt upnp/pmp)",
Value: "any",
Destination: &options.NAT, // TODO: accept none,any,upnp,extaddr
},
&cli.PathFlag{
Name: "db-path",
Aliases: []string{"dbpath"},
Value: "./store.db",
Usage: "Path to DB file",
Destination: &options.DBPath,
},
&cli.StringFlag{
Name: "advertise-address",
Usage: "External address to advertise to other nodes (overrides --address and --ws-address flags)",
Destination: &options.AdvertiseAddress,
},
&cli.BoolFlag{
Name: "show-addresses",
Usage: "Display listening addresses according to current configuration",
Destination: &options.ShowAddresses,
},
&cli.GenericFlag{
Name: "log-level",
Aliases: []string{"l"},
Value: &cliutils.ChoiceValue{
Choices: []string{"DEBUG", "INFO", "WARN", "ERROR", "DPANIC", "PANIC", "FATAL"},
Value: &options.LogLevel,
},
Usage: "Define the logging level,",
},
&cli.BoolFlag{
Name: "version",
Value: false,
Usage: "prints the version",
Destination: &options.Version,
},
&cli.GenericFlag{
Name: "log-encoding",
Usage: "Define the encoding used for the logs",
Value: &cliutils.ChoiceValue{
Choices: []string{"console", "json"},
Value: &options.LogEncoding,
},
},
&cli.BoolFlag{
Name: "relay",
Value: true,
Usage: "Enable relay protocol",
Destination: &options.Relay.Enable,
},
&cli.StringSliceFlag{
Name: "topics",
Usage: "List of topics to listen",
Destination: &options.Relay.Topics,
},
&cli.BoolFlag{
Name: "relay-peer-exchange",
Aliases: []string{"peer-exchange"},
Value: false,
Usage: "Enable GossipSub Peer Exchange",
Destination: &options.Relay.PeerExchange,
},
&cli.IntFlag{
Name: "min-relay-peers-to-publish",
Value: 1,
Usage: "Minimum number of peers to publish to Relay",
Destination: &options.Relay.MinRelayPeersToPublish,
},
&cli.BoolFlag{
Name: "store",
Usage: "Enable relay protocol",
Destination: &options.Store.Enable,
},
&cli.BoolFlag{
Name: "resume",
Usage: "Fix the gaps in message history",
Destination: &options.Store.ShouldResume,
},
&cli.DurationFlag{
Name: "store-duration",
Value: time.Hour * 24 * 30,
Usage: "maximum number of seconds before a message is removed from the store",
Destination: &options.Store.RetentionTime,
},
&cli.IntFlag{
Name: "store-capacity",
Value: 50000,
Usage: "maximum number of messages to store",
Destination: &options.Store.RetentionMaxMessages,
},
&cli.GenericFlag{
Name: "storenode",
Usage: "Multiaddr of a peer that supports store protocol. Option may be repeated",
Value: &cliutils.MultiaddrSlice{
Values: &options.Store.Nodes,
},
},
&cli.BoolFlag{
Name: "swap",
Usage: "Enable swap protocol",
Value: false,
Destination: &options.Swap.Enable,
},
&cli.IntFlag{
Name: "swap-mode",
Value: 0,
Usage: "Swap mode: 0=soft, 1=mock, 2=hard",
Destination: &options.Swap.Mode,
},
&cli.IntFlag{
Name: "swap-payment-threshold",
Value: 100,
Usage: "Threshold for payment",
Destination: &options.Swap.PaymentThreshold,
},
&cli.IntFlag{
Name: "swap-disconnect-threshold",
Value: -100,
Usage: "Threshold for disconnecting",
Destination: &options.Swap.DisconnectThreshold,
},
&cli.BoolFlag{
Name: "filter",
Usage: "Enable filter protocol",
Destination: &options.Filter.Enable,
},
&cli.BoolFlag{
Name: "light-client",
Usage: "Don't accept filter subscribers",
Destination: &options.Filter.DisableFullNode,
},
&cli.GenericFlag{
Name: "filternode",
Usage: "Multiaddr of a peer that supports filter protocol. Option may be repeated",
Value: &cliutils.MultiaddrSlice{
Values: &options.Filter.Nodes,
},
},
&cli.DurationFlag{
Name: "filter-timeout",
Value: 14400 * time.Second,
Usage: "Timeout for filter node in seconds",
Destination: &options.Filter.Timeout,
},
&cli.BoolFlag{
Name: "lightpush",
Usage: "Enable lightpush protocol",
Destination: &options.LightPush.Enable,
},
&cli.GenericFlag{
Name: "lightpushnode",
Usage: "Multiaddr of a peer that supports lightpush protocol. Option may be repeated",
Value: &cliutils.MultiaddrSlice{
Values: &options.LightPush.Nodes,
},
},
&cli.BoolFlag{
Name: "discv5-discovery",
Usage: "Enable discovering nodes via Node Discovery v5",
Destination: &options.DiscV5.Enable,
},
&cli.StringSliceFlag{
Name: "discv5-bootstrap-node",
Usage: "Text-encoded ENR for bootstrap node. Used when connecting to the network. Option may be repeated",
Destination: &options.DiscV5.Nodes,
},
&cli.IntFlag{
Name: "discv5-udp-port",
Value: 9000,
Usage: "Listening UDP port for Node Discovery v5.",
Destination: &options.DiscV5.Port,
},
&cli.BoolFlag{
Name: "discv5-enr-auto-update",
Usage: "Discovery can automatically update its ENR with the IP address as seen by other nodes it communicates with.",
Destination: &options.DiscV5.AutoUpdate,
},
&cli.BoolFlag{
Name: "rendezvous",
Usage: "Enable rendezvous protocol for peer discovery",
Destination: &options.Rendezvous.Enable,
},
&cli.GenericFlag{
Name: "rendezvous-node",
Usage: "Multiaddr of a waku2 rendezvous node. Option may be repeated",
Value: &cliutils.MultiaddrSlice{
Values: &options.Rendezvous.Nodes,
},
},
&cli.BoolFlag{
Name: "rendezvous-server",
Usage: "Node will act as rendezvous server",
Destination: &options.RendezvousServer.Enable,
},
&cli.PathFlag{
Name: "rendezvous-db-path",
Value: "/tmp/rendezvous",
Usage: "Path where peer records database will be stored",
Destination: &options.RendezvousServer.DBPath,
},
&cli.BoolFlag{
Name: "dns-discovery",
Usage: "Enable DNS discovery",
Destination: &options.DNSDiscovery.Enable,
},
&cli.StringSliceFlag{
Name: "dns-discovery-url",
Usage: "URL for DNS node list in format 'enrtree://<key>@<fqdn>'",
Destination: &options.DNSDiscovery.URLs,
},
&cli.StringFlag{
Name: "dns-discovery-name-server",
Aliases: []string{"dns-discovery-nameserver"},
Usage: "DNS nameserver IP to query (empty to use system's default)",
Destination: &options.DNSDiscovery.Nameserver,
},
&cli.BoolFlag{
Name: "metrics-server",
Aliases: []string{"metrics"},
Usage: "Enable the metrics server",
Destination: &options.Metrics.Enable,
},
&cli.StringFlag{
Name: "metrics-server-address",
Aliases: []string{"metrics-address"},
Value: "127.0.0.1",
Usage: "Listening address of the metrics server",
Destination: &options.Metrics.Address,
},
&cli.IntFlag{
Name: "metrics-server-port",
Aliases: []string{"metrics-port"},
Value: 8008,
Usage: "Listening HTTP port of the metrics server",
Destination: &options.Metrics.Port,
},
&cli.BoolFlag{
Name: "rpc",
Usage: "Enable the rpc server",
Destination: &options.RPCServer.Enable,
},
&cli.IntFlag{
Name: "rpc-port",
Value: 8545,
Usage: "Listening port of the rpc server",
Destination: &options.RPCServer.Port,
},
&cli.StringFlag{
Name: "rpc-address",
Value: "127.0.0.1",
Usage: "Listening address of the rpc server",
Destination: &options.RPCServer.Address,
},
&cli.BoolFlag{
Name: "rpc-admin",
Value: false,
Usage: "Enable access to JSON-RPC Admin API",
Destination: &options.RPCServer.Admin,
},
&cli.BoolFlag{
Name: "rpc-private",
Value: false,
Usage: "Enable access to JSON-RPC Private API",
Destination: &options.RPCServer.Private,
},
&cli.BoolFlag{
Name: "rest",
Usage: "Enable Waku REST HTTP server",
Destination: &options.RESTServer.Enable,
},
&cli.StringFlag{
Name: "rest-address",
Value: "127.0.0.1",
Usage: "Listening address of the REST HTTP server",
Destination: &options.RESTServer.Address,
},
&cli.IntFlag{
Name: "rest-port",
Value: 8645,
Usage: "Listening port of the REST HTTP server",
Destination: &options.RESTServer.Port,
},
&cli.IntFlag{
Name: "rest-relay-cache-capacity",
Value: 30,
Usage: "Capacity of the Relay REST API message cache",
Destination: &options.RESTServer.RelayCacheCapacity,
},
&cli.BoolFlag{
Name: "rest-admin",
Value: false,
Usage: "Enable access to REST HTTP Admin API",
Destination: &options.RESTServer.Admin,
},
&cli.BoolFlag{
Name: "rest-private",
Value: false,
Usage: "Enable access to REST HTTP Private API",
Destination: &options.RESTServer.Private,
},
}
rlnFlags := rlnFlags()
cliFlags = append(cliFlags, rlnFlags...)
app := &cli.App{
Flags: cliFlags,
Action: func(c *cli.Context) error {
// for go-libp2p loggers
lvl, err := logging.LevelFromString(options.LogLevel)
if err != nil {
return err
}
logging.SetAllLoggers(lvl)
// go-waku logger
err = utils.SetLogLevel(options.LogLevel)
if err != nil {
return err
}
// Set encoding for logs (console, json, ...)
// Note that libp2p reads the encoding from GOLOG_LOG_FMT env var.
utils.InitLogger(options.LogEncoding)
waku.Execute(options)
return nil
},
}
err := app.Run(os.Args)
if err != nil {
panic(err)
}
}