Code Monkey home page Code Monkey logo

js-libp2p-mdns's Introduction

@libp2p/mdns

libp2p.io Discuss codecov CI

Node.js libp2p mDNS discovery implementation for peer discovery

Table of contents

Install

$ npm i @libp2p/mdns

Usage

import { MDNS } from '@libp2p/mdns'

const mdns = new MDNS(options)

mdns.on('peer', (peerData) => {
  console.log('Found a peer in the local network', peerData.id.toString(), peerData.multiaddrs)
})

// Broadcast for 20 seconds
mdns.start()
setTimeout(() => mdns.stop(), 20 * 1000)
  • options
    • peerId - PeerId to announce
    • multiaddrs - multiaddrs to announce
    • broadcast - (true/false) announce our presence through mDNS, default false
    • interval - query interval, default 10 * 1000 (10 seconds)
    • serviceTag - name of the service announce , default 'ipfs.local`
    • compat - enable/disable compatibility with go-libp2p-mdns, default true

MDNS messages

A query is sent to discover the IPFS nodes on the local network

{
  type: 'query',
  questions: [ { name: 'ipfs.local', type: 'PTR' } ]
}

When a query is detected, each IPFS node sends an answer about itself

    [ { name: 'ipfs.local',
        type: 'PTR',
        class: 'IN',
        ttl: 120,
        data: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK.ipfs.local' },
      { name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK.ipfs.local',
        type: 'SRV',
        class: 'IN',
        ttl: 120,
        data:
         { priority: 10,
           weight: 1,
           port: '20002',
           target: 'LAPTOP-G5LJ7VN9' } },
      { name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK.ipfs.local',
        type: 'TXT',
        class: 'IN',
        ttl: 120,
        data: ['QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK'] },
      { name: 'LAPTOP-G5LJ7VN9',
        type: 'A',
        class: 'IN',
        ttl: 120,
        data: '127.0.0.1' },
      { name: 'LAPTOP-G5LJ7VN9',
        type: 'AAAA',
        class: 'IN',
        ttl: 120,
        data: '::1' } ]

API Docs

License

Licensed under either of

Contribute

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.

js-libp2p-mdns's People

Contributors

daviddias avatar jacobheun avatar achingbrain avatar semantic-release-bot avatar web3-bot avatar nunofmn avatar greenkeeperio-bot avatar vasco-santos avatar dignifiedquire avatar richardschneider avatar alanshaw avatar victorb avatar richardlitt avatar dependabot[bot] avatar wemeetagain avatar dependabot-preview[bot] avatar dirkmc avatar emersion avatar libp2p-mgmt-read-write[bot] avatar rennokki avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.