Skip to content

Commit

Permalink
add: keep ENR crawl option
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-tra committed Nov 22, 2023
1 parent 0578b5a commit 0bca573
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
28 changes: 19 additions & 9 deletions cmd/nebula/cmd_crawl.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ var crawlConfig = &config.Crawl{
WriteWorkerCount: 10,
CrawlLimit: 0,
PersistNeighbors: false,
CheckExposed: false,
FilePathUdgerDB: "",
Network: string(config.NetworkIPFS),
BootstrapPeers: cli.NewStringSlice(),
Protocols: cli.NewStringSlice(string(kaddht.ProtocolDHT)),
AddrTrackTypeStr: "public",
AddrDialTypeStr: "public",
KeepENR: false,
CheckExposed: false,
}

// CrawlCommand contains the crawl sub-command configuration.
Expand Down Expand Up @@ -138,14 +139,6 @@ var CrawlCommand = &cli.Command{
Value: crawlConfig.PersistNeighbors,
Destination: &crawlConfig.PersistNeighbors,
},
&cli.BoolFlag{
Name: "check-exposed",
Usage: "Whether to check if the Kubo API is exposed. Checking also includes crawling the API.",
EnvVars: []string{"NEBULA_CRAWL_CHECK_EXPOSED"},
Value: crawlConfig.CheckExposed,
Destination: &crawlConfig.CheckExposed,
Category: flagCategoryNetwork,
},
&cli.StringFlag{
Name: "addr-track-type",
Usage: "Which type addresses should be stored to the database (private, public, any)",
Expand All @@ -167,6 +160,22 @@ var CrawlCommand = &cli.Command{
Value: crawlConfig.Network,
Destination: &crawlConfig.Network,
},
&cli.BoolFlag{
Name: "check-exposed",
Usage: "IPFS/AMINO: Whether to check if the Kubo API is exposed. Checking also includes crawling the API.",
EnvVars: []string{"NEBULA_CRAWL_CHECK_EXPOSED"},
Value: crawlConfig.CheckExposed,
Destination: &crawlConfig.CheckExposed,
Category: flagCategoryNetwork,
},
&cli.BoolFlag{
Name: "keep-enr",
Usage: "ETHEREUM_CONSENSUS: Whether to keep the full ENR.",
EnvVars: []string{"NEBULA_CRAWL_KEEP_ENR"},
Value: crawlConfig.KeepENR,
Destination: &crawlConfig.KeepENR,
Category: flagCategoryNetwork,
},
},
}

Expand Down Expand Up @@ -227,6 +236,7 @@ func CrawlAction(c *cli.Context) error {
BootstrapPeerStrs: cfg.BootstrapPeers.Value(),
AddrDialType: cfg.AddrDialType(),
AddrTrackType: cfg.AddrTrackType(),
KeepENR: crawlConfig.KeepENR,
}

// init the crawl driver
Expand Down
9 changes: 6 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@ type Crawl struct {
// Whether to persist all k-bucket entries
PersistNeighbors bool

// Whether to check if the Kubo API is exposed
CheckExposed bool

// File path to the udger datbase
FilePathUdgerDB string

Expand All @@ -202,6 +199,12 @@ type Crawl struct {

// Which type of addresses should Nebula try to dial (private, public, both)
AddrDialTypeStr string

// Whether to check if the Kubo API is exposed
CheckExposed bool

// Whether to keep the full enr record alongside all parsed kv-pairs
KeepENR bool
}

func (c *Crawl) AddrTrackType() AddrType {
Expand Down
5 changes: 5 additions & 0 deletions pkg/discv5/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
type CrawlerConfig struct {
DialTimeout time.Duration
AddrDialType config.AddrType
KeepENR bool
}

type Crawler struct {
Expand Down Expand Up @@ -112,6 +113,10 @@ func (c *Crawler) PeerProperties(node *enode.Node) json.RawMessage {
properties["opstack_version"] = enrEntryOpStack.Version
}

if c.cfg.KeepENR {
properties["enr"] = node.String()
}

data, err := json.Marshal(properties)
if err != nil {
log.WithError(err).WithField("properties", properties).Warnln("Could not marshal peer properties")
Expand Down
2 changes: 2 additions & 0 deletions pkg/discv5/driver_crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,14 @@ type CrawlDriverConfig struct {
BootstrapPeerStrs []string
AddrDialType config.AddrType
AddrTrackType config.AddrType
KeepENR bool
}

func (cfg *CrawlDriverConfig) CrawlerConfig() *CrawlerConfig {
return &CrawlerConfig{
DialTimeout: cfg.DialTimeout,
AddrDialType: cfg.AddrDialType,
KeepENR: cfg.KeepENR,
}
}

Expand Down

0 comments on commit 0bca573

Please sign in to comment.