Skip to content

Commit

Permalink
add back disable dht
Browse files Browse the repository at this point in the history
  • Loading branch information
countvonzero committed Sep 28, 2023
1 parent 3b1b118 commit f2efa7a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ expected to be ~1.5 GiB.
A new config `poet-request-timeout` has been added, that defines the timeout for requesting PoET proofs.
It defaults to 9 minutes so there is enough time to retry if the request fails.

Config option and flag `p2p-disable-legacy-discovery` and `disable-dht` have been dropped. DHT has been the
only p2p discovery mechanism since release v1.1.2.
Config option and flag `p2p-disable-legacy-discovery` is dropped. DHT has been the only p2p discovery
mechanism since release v1.1.2.

Support for old certificate sync protocol is dropped. This update is incompatible with v1.0.x series.

Expand Down
3 changes: 2 additions & 1 deletion p2p/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ for them if needed.
### Configuration for private node

Set min-peers to the number of peers in the config.
Set min-peers to the number of peers in the config and disable-dht.
low-peers and high-peers should not be lower than min-peers.

```json
Expand All @@ -67,6 +67,7 @@ low-peers and high-peers should not be lower than min-peers.
"min-peers": 1,
"low-peers": 10,
"high-peers": 20,
"disable-dht": true,
"bootnodes": [],
"direct": [
"/ip4/0.0.0.0/tcp/7513/p2p/12D3KooWRfy4Sj4rDHDuBaYw3Mg5d2puwiCyqBCWMziFquaGQ5g8"
Expand Down
33 changes: 22 additions & 11 deletions p2p/dhtdiscovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ func WithDir(path string) Opt {
}
}

func DisableDHT() Opt {
return func(d *Discovery) {
d.disableDht = true
}

Check warning on line 90 in p2p/dhtdiscovery/discovery.go

View check run for this annotation

Codecov / codecov/patch

p2p/dhtdiscovery/discovery.go#L87-L90

Added lines #L87 - L90 were not covered by tests
}

func New(h host.Host, opts ...Opt) (*Discovery, error) {
ctx, cancel := context.WithCancel(context.Background())
d := Discovery{
Expand All @@ -104,17 +110,20 @@ func New(h host.Host, opts ...Opt) (*Discovery, error) {
if len(d.bootnodes) == 0 {
d.logger.Warn("no bootnodes in the config")
}
err := d.newDht(ctx, h, d.public, d.server, d.dir)
if err != nil {
return nil, err
if !d.disableDht {
err := d.newDht(ctx, h, d.public, d.server, d.dir)
if err != nil {
return nil, err
}

Check warning on line 117 in p2p/dhtdiscovery/discovery.go

View check run for this annotation

Codecov / codecov/patch

p2p/dhtdiscovery/discovery.go#L116-L117

Added lines #L116 - L117 were not covered by tests
}
return &d, nil
}

type Discovery struct {
public bool
server bool
dir string
public bool
server bool
disableDht bool
dir string

logger *zap.Logger
eg errgroup.Group
Expand Down Expand Up @@ -180,11 +189,13 @@ func (d *Discovery) Start() {
func (d *Discovery) Stop() {
d.cancel()
d.eg.Wait()
if err := d.dht.Close(); err != nil {
d.logger.Error("error closing dht", zap.Error(err))
}
if err := d.datastore.Close(); err != nil {
d.logger.Error("error closing level datastore", zap.Error(err))
if !d.disableDht {
if err := d.dht.Close(); err != nil {
d.logger.Error("error closing dht", zap.Error(err))
}

Check warning on line 195 in p2p/dhtdiscovery/discovery.go

View check run for this annotation

Codecov / codecov/patch

p2p/dhtdiscovery/discovery.go#L194-L195

Added lines #L194 - L195 were not covered by tests
if err := d.datastore.Close(); err != nil {
d.logger.Error("error closing level datastore", zap.Error(err))
}

Check warning on line 198 in p2p/dhtdiscovery/discovery.go

View check run for this annotation

Codecov / codecov/patch

p2p/dhtdiscovery/discovery.go#L197-L198

Added lines #L197 - L198 were not covered by tests
}
}

Expand Down
1 change: 1 addition & 0 deletions p2p/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type Config struct {
DisableNatPort bool `mapstructure:"disable-natport"`
DisableConnectionManager bool `mapstructure:"disable-connection-manager"`
DisableResourceManager bool `mapstructure:"disable-resource-manager"`
DisableDHT bool `mapstructure:"disable-dht"`
Flood bool `mapstructure:"flood"`
Listen string `mapstructure:"listen"`
Bootnodes []string `mapstructure:"bootnodes"`
Expand Down
3 changes: 3 additions & 0 deletions p2p/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func Upgrade(h host.Host, opts ...Opt) (*Host, error) {
if cfg.PrivateNetwork {
dopts = append(dopts, discovery.Private())
}
if cfg.DisableDHT {
dopts = append(dopts, discovery.DisableDHT())
}

Check warning on line 137 in p2p/upgrade.go

View check run for this annotation

Codecov / codecov/patch

p2p/upgrade.go#L136-L137

Added lines #L136 - L137 were not covered by tests
if cfg.Bootnode {
dopts = append(dopts, discovery.Server())
} else {
Expand Down

0 comments on commit f2efa7a

Please sign in to comment.