Skip to content

Commit

Permalink
feat(p2p): add p2p advertising option (#862)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Tsitrin <[email protected]>
  • Loading branch information
srene and mtsitrin authored May 16, 2024
1 parent 70d9460 commit 977019f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func DefaultConfig(home, chainId string) *NodeConfig {
BootstrapRetryTime: 30 * time.Second,
ListenAddress: DefaultListenAddress,
BootstrapNodes: "",
AdvertisingEnabled: true,
},
}

Expand Down
2 changes: 2 additions & 0 deletions config/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type P2PConfig struct {
GossipedBlocksCacheSize int `mapstructure:"p2p_gossiped_blocks_cache_size"`
// Time interval a node tries to bootstrap again, in case no nodes connected
BootstrapRetryTime time.Duration `mapstructure:"p2p_bootstrap_retry_time"`
// Param used to enable the advertisement of the node to be part of the P2P network in the DHT
AdvertisingEnabled bool `mapstructure:"p2p_advertising_enabled"`
}

// Validate P2PConfig
Expand Down
3 changes: 3 additions & 0 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ p2p_gossiped_blocks_cache_size = {{ .P2PConfig.GossipedBlocksCacheSize }}
# time interval to check if no p2p nodes are connected to bootstrap again
p2p_bootstrap_retry_time = "{{ .P2PConfig.BootstrapRetryTime }}"
# set to false to disable advertising the node to the P2P network
p2p_advertising_enabled= "{{ .P2PConfig.AdvertisingEnabled }}"
#celestia config example:
# da_config = "{\"base_url\":\"http:\/\/127.0.0.1:26658\",\"timeout\":5000000000,\"gas_prices\":0.1,\"auth_token\":\"TOKEN\",\"backoff\":{\"initial_delay\":6000000000,\"max_delay\":6000000000,\"growth_factor\":2},\"retry_attempts\":4,\"retry_delay\":3000000000}"
# Avail config example:
Expand Down
8 changes: 5 additions & 3 deletions p2p/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,11 @@ func (c *Client) peerDiscovery(ctx context.Context) error {
return err
}

err = c.advertise(ctx)
if err != nil {
return err
if c.conf.AdvertisingEnabled {
err = c.advertise(ctx)
if err != nil {
return err
}
}

err = c.findPeers(ctx)
Expand Down

0 comments on commit 977019f

Please sign in to comment.