Skip to content

Commit d8d051c

Browse files
authored
Add Ethereum Consensus Layer Support (#42)
1 parent 812c0ba commit d8d051c

112 files changed

Lines changed: 10946 additions & 2279 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pull_request_main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
ports:
1919
- "2345:5432"
2020
env:
21-
POSTGRES_PASSWORD: password_test
21+
POSTGRES_PASSWORD: password
2222
POSTGRES_USER: nebula_test
2323
POSTGRES_DB: nebula_test
2424
options: >-

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,6 @@ override.tf.json
180180
terraform.rc
181181

182182
# End of https://www.toptal.com/developers/gitignore/api/terraform
183-
183+
out
184184
report/db.toml
185+
.tool-versions

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.RawVersion=`cat version`
1212
# Create lightweight container to run nebula
1313
FROM alpine:latest
1414

15-
# Create user ot
15+
# Create user nebula
1616
RUN adduser -D -H nebula
1717
WORKDIR /home/nebula
18-
RUN mkdir .config && chown nebula:nebula .config
1918
USER nebula
2019

2120
COPY --from=builder /build/nebula /usr/local/bin/nebula

Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,25 @@ tools:
2828
go install github.com/volatiletech/sqlboiler/v4@v4.13.0
2929
go install github.com/volatiletech/sqlboiler/v4/drivers/sqlboiler-psql@v4.13.0
3030

31-
database-reset: migrate-down migrate-up models
31+
database-reset: database-stop databased migrate-up models
3232

3333
database:
34-
docker run --rm -p 5432:5432 -e POSTGRES_PASSWORD=password -e POSTGRES_USER=nebula -e POSTGRES_DB=nebula postgres:14
34+
docker run --rm -p 2345:5432 -e POSTGRES_PASSWORD=password -e POSTGRES_USER=nebula_test -e POSTGRES_DB=nebula_test --name nebula_test_db postgres:14
3535

36-
database-test:
37-
docker run --rm -p 2345:5432 -e POSTGRES_PASSWORD=password_test -e POSTGRES_USER=nebula_test -e POSTGRES_DB=nebula_test postgres:14
36+
databased:
37+
docker run --rm -d -p 2345:5432 -e POSTGRES_PASSWORD=password -e POSTGRES_USER=nebula_test -e POSTGRES_DB=nebula_test --name nebula_test_db postgres:14
38+
sleep 1
39+
40+
database-stop:
41+
docker stop nebula_test_db || true
3842

3943
models:
4044
sqlboiler --no-tests psql
4145

4246
migrate-up:
43-
migrate -database 'postgres://nebula:password@localhost:5432/nebula?sslmode=disable' -path pkg/db/migrations up
47+
migrate -database 'postgres://nebula_test:password@localhost:2345/nebula_test?sslmode=disable' -path pkg/db/migrations up
4448

4549
migrate-down:
46-
migrate -database 'postgres://nebula:password@localhost:5432/nebula?sslmode=disable' -path pkg/db/migrations down
50+
migrate -database 'postgres://nebula_test:password@localhost:2345/nebula_test?sslmode=disable' -path pkg/db/migrations down
4751

4852
.PHONY: all clean test format tools models migrate-up migrate-down

README.md

Lines changed: 69 additions & 34 deletions
Large diffs are not rendered by default.

cmd/nebula/cmd.go

Lines changed: 97 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package main
22

33
import (
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

3030
var 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

4854
func 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

Comments
 (0)