Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pubsub configuration #404

Merged
merged 6 commits into from
Aug 19, 2019
Merged

fix: pubsub configuration #404

merged 6 commits into from
Aug 19, 2019

Conversation

a1300
Copy link
Contributor

@a1300 a1300 commented Aug 15, 2019

This PR fixes issue #401 and adds the following new pubsub configuration options:

  • emitSelf (boolean)
  • signMessages (boolean)
  • strictSigning (boolean)

@jacobheun I wasn't sure if I should add tests for this bug fix because it seemed to me that this repository isn't testing if configuration is correctly passed to the Modules. Should I add some tests?

Thanks!

Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, some tests in ./test/pubsub.node.js to verify that toggling emitSelf works as expected would be great.

Thanks for updating the example as well!

examples/pubsub/README.md Outdated Show resolved Hide resolved
@a1300
Copy link
Contributor Author

a1300 commented Aug 16, 2019

@jacobheun Ok, I will soon add some tests!

@a1300
Copy link
Contributor Author

a1300 commented Aug 16, 2019

@jacobheun quick question: Do you want that I test the toggling of emitSelf with both libp2p-gossipsub and libp2p-floodsub?

@jacobheun
Copy link
Contributor

@a1300 1 implementation is fine, ultimately we're just verifying that it's getting the configuration. Those modules should handle more in depth testing for themselves.

@jacobheun
Copy link
Contributor

Even just testing that a mock Pubsub implementation is getting the right options would be sufficient.

@a1300
Copy link
Contributor Author

a1300 commented Aug 17, 2019

@jacobheun I am currently writing the tests, and I wondered if the following is not a bug on its own:

The following code is the config that defines the default properties of the PubSub config:

  // Pubsub config
  pubsub: s('object?', {
    // Pubsub defaults
    enabled: true,
    emitSelf: true,
    signMessages: true,
    strictSigning: true
  })

If I now create a Bundle with only a subset of the options above then I would expect that the default values would be set, but they aren't.

const bundle = new libp2p({
  modules: {
    transport: [ TCP ],
    streamMuxer: [ Mplex ],
    connEncryption: [ SECIO ],
    peerDiscovery: [ MulticastDNS ],
    pubsub: Gossipsub
  },
  config: {
    peerDiscovery: {
      mdns: {
        interval: 2000,
        enabled: true
      }
   },
   pubsub: {
      enabled: true,
      emitSelf: true
    }
  }
}

The PubSub implementation is getting called only with:

{
  enabled: true,
  emitSelf: true
}

But I would expect that it would be called with:

{
  enabled: true,
  emitSelf: true,
  signMessages: true,
  strictSigning: true
}

Is this a bug or expected behavior? Thanks!

@jacobheun
Copy link
Contributor

It's expected, but not ideal. The config needs some improvements. Right now it's validating an optional object and not their sub properties. If any object is supplied it uses that and doesn't do any copying of the default properties. Ideally we'd get the defaults populated, while avoiding making the config too strict. The reason for this is that if we add a new config option in the future to pubsub or another module, we need to avoid libp2p config validation from throwing an error, so that it doesn't have to be updated to use the latest pubsub.

I'll create a ticket to track improving the config, don't worry about it for this, you may just need to be verbose with configuration for some of the tests. (Note: Both existing pubsub modules do properly add defaults for the missing values, so we are catching it there as we should be).

a1300 and others added 6 commits August 19, 2019 14:30
License: MIT
Signed-off-by: Matthias Knopp <matthias-knopp@gmx.net>
License: MIT
Signed-off-by: Matthias Knopp <matthias-knopp@gmx.net>
License: MIT
Signed-off-by: Matthias Knopp <matthias-knopp@gmx.net>
License: MIT
Signed-off-by: Matthias Knopp <matthias-knopp@gmx.net>
Co-Authored-By: Jacob Heun <jacobheun@gmail.com>
License: MIT
Signed-off-by: Matthias Knopp <matthias-knopp@gmx.net>
@a1300
Copy link
Contributor Author

a1300 commented Aug 19, 2019

@jacobheun please review the tests 🙂

@jacobheun
Copy link
Contributor

@a1300 looks good! I ran the example as well and everything looks good there too. Thanks for the PR!

@jacobheun jacobheun merged commit b0f124b into libp2p:master Aug 19, 2019
@a1300 a1300 deleted the add_pubsub_config branch August 19, 2019 15:35
maschad pushed a commit to maschad/js-libp2p that referenced this pull request Jun 21, 2023
The `Providers` component takes a `ProvidersInit` object, but there's not actually a way to provide it with one from the `KadDHT` constructor. This means users aren't able to override the defaults for how long provider records are valid for and how frequently to clean up expired provider records.

Co-authored-by: Alex Potsides <alex@achingbrain.net>
maschad pushed a commit to maschad/js-libp2p that referenced this pull request Jun 21, 2023
## [6.1.0](libp2p/js-libp2p-kad-dht@v6.0.4...v6.1.0) (2022-12-07)

### Features

* allow passing ProvidersInit in KadDHT constructor ([libp2p#404](libp2p/js-libp2p-kad-dht#404)) ([e64af85](libp2p/js-libp2p-kad-dht@e64af85))

### Bug Fixes

* treat /dns, /dns4, and /dns6 addrs as public ([libp2p#406](libp2p/js-libp2p-kad-dht#406)) ([e27747a](libp2p/js-libp2p-kad-dht@e27747a)), closes [libp2p#377](libp2p/js-libp2p-kad-dht#377)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants