Socket
Socket
Sign inDemoInstall

@libp2p/pubsub-peer-discovery

Package Overview
Dependencies
7
Maintainers
6
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libp2p/pubsub-peer-discovery

A libp2p module that uses pubsub for mdns like peer discovery


Version published
Weekly downloads
19K
increased by341.29%
Maintainers
6
Created
Weekly downloads
 

Changelog

Source

10.0.2 (2023-12-04)

Bug Fixes

  • update deps (#130) (3470fc5)

Readme

Source

libp2p.io Discuss codecov CI

A libp2p module that uses pubsub for mdns like peer discovery

About

When the discovery module is started by libp2p it subscribes to the discovery pubsub topic(s)

It will immediately broadcast your peer data via pubsub and repeat the broadcast on the configured interval

Security Considerations

It is worth noting that this module does not include any message signing for broadcasts. The reason for this is that libp2p-pubsub supports message signing and enables it by default, which means the message you received has been verified to be from the originator, so we can trust that the peer information we have received is indeed from the peer who owns it. This doesn't mean the peer can't falsify its own records, but this module isn't currently concerned with that scenario.

Requirements

This module MUST be used on a libp2p node that is running Pubsub. If Pubsub does not exist, or is not running, this module will not work.

To run a PubSub service, include a pubsub implementation in your services map such as @chainsafe/libp2p-gossipsub.

For more information see the docs on customizing libp2p.

Example - Usage in js-libp2p

See the js-libp2p configuration docs for how to include this module as a peer discovery module in js-libp2p.

If you are only interested in listening to the global pubsub topic the minimal configuration for using this with libp2p is:

import { createLibp2p } from 'libp2p'
import { websockets } from '@libp2p/websockets'
import { yamux } from '@chainsafe/libp2p-yamux'
import { noise } from '@chainsafe/libp2p-noise'
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { pubsubPeerDiscovery } from '@libp2p/pubsub-peer-discovery'
import { identify } from 'libp2p/identify'

const node = await createLibp2p({
  transports: [
    websockets()
  ], // Any libp2p transport(s) can be used
  streamMuxers: [
    yamux()
  ],
  connectionEncryption: [
    noise()
  ],
  peerDiscovery: [
    pubsubPeerDiscovery()
  ],
  services: {
    pubsub: gossipsub(),
    identify: identify()
  }
})

Example - Customizing Pubsub Peer Discovery

There are a few options you can use to customize Pubsub Peer Discovery. You can see the detailed options below.

// ... Other imports from above
import PubSubPeerDiscovery from '@libp2p/pubsub-peer-discovery'

// Custom topics
const topics = [
  `myApp._peer-discovery._p2p._pubsub`, // It's recommended but not required to extend the global space
  '_peer-discovery._p2p._pubsub' // Include if you want to participate in the global space
]

const node = await createLibp2p({
  // ...
  peerDiscovery: [
    pubsubPeerDiscovery({
      interval: 10000,
      topics: topics, // defaults to ['_peer-discovery._p2p._pubsub']
      listenOnly: false
    })
  ]
})

Options

NameTypeDescription
intervalnumberHow often (in ms), after initial broadcast, your node should broadcast your peer data. Default (10000ms)
topicsArray<string>An Array of topic strings. If set, the default topic will not be used and must be included explicitly here
listenOnlybooleanIf true it will not broadcast peer data. Dont set this unless you have a specific reason to. Default (false)

Default Topic

The default pubsub topic the module subscribes to is _peer-discovery._p2p._pubsub, which is also set on PubsubPeerDiscovery.TOPIC.

Install

$ npm i @libp2p/pubsub-peer-discovery

Browser <script> tag

Loading this module through a script tag will make it's exports available as Libp2pPubsubPeerDiscovery in the global namespace.

<script src="https://unpkg.com/@libp2p/pubsub-peer-discovery/dist/index.min.js"></script>

API Docs

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Keywords

FAQs

Last updated on 04 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc