Welcome
Awesome Dat
Dat Applications
datproject/dat
datproject/dat-desktop
Community Applications
codeforscience/sciencefair
mafintosh/hyperirc
jondashkyle/soundcloud-archiver
mafintosh/hypervision
joehand/hypertweet
beakerbrowser/dat-photos-app
High-Level APIs
datproject/dat-node
datproject/dat-js
beakerbrowser/pauls-dat-api
beakerbrowser/node-dat-archive
Hosting & Dat Management
mafintosh/hypercore-archiver
datprotocol/hypercloud
beakerbrowser/hashbase
joehand/dat-now
mafintosh/hypercore-archiver-bot
joehand/hypercore-archiver-ws
datproject/dat-registry-api
datproject/dat-registry-client
Managing & Aggregating Dats
datproject/multidat
datproject/multidrive
jayrbolton/dat-pki
beakerbrowser/injestdb
Http Hosting
joehand/hyperdrive-http
beakerbrowser/dathttpd
Dat Link Utilties
datprotocol/dat-dns
joehand/dat-link-resolve
pfrazee/parse-dat-url
juliangruber/dat-encoding
Dat Utilities
joehand/dat-log
mafintosh/dat-ls
karissa/hyperhealth
joehand/hyperdrive-network-speed
File Imports & Exports
juliangruber/hyperdrive-import-files
mafintosh/mirror-folder
pfrazee/hyperdrive-staging-area
pfrazee/hyperdrive-to-zip-stream
Hypercore Tools
mafintosh/hyperpipe
Dat Core Modules
mafintosh/hyperdrive
mafintosh/hypercore
CLI Utilities
joehand/dat-doctor
joehand/dat-ignore
joehand/dat-json
Networking
karissa/hyperdiscovery
mafintosh/discovery-swarm
mafintosh/webrtc-swarm
joehand/dat-swarm-defaults
Lower level networking modules
maxogden/discovery-channel
mafintosh/dns-discovery
mafintosh/multicast-dns
webtorrent/bittorrent-dht
mafintosh/utp-native
mafintosh/signalhub
Storage
datproject/dat-storage
datproject/dat-secret-storage
Random Access
juliangruber/abstract-random-access
mafintosh/multi-random-access
mafintosh/random-access-file
mafintosh/random-access-memory
mafintosh/random-access-page-files
datproject/dat-http
substack/random-access-idb
Other Related Dat Project Modules
mafintosh/peer-network
mafintosh/hyperdht
Dat Project Organization Stuff
datproject/datproject.org
datproject/discussions
datproject/design
datproject/dat-elements
kriesse/dat-colors
kriesse/dat-icons
juliangruber/dat.json
Outdated
juliangruber/dat.haus
poga/hyperfeed
yoshuawuyts/normcore
yoshuawuyts/github-to-hypercore
poga/hyperspark
juliangruber/hypercore-index
juliangruber/hyperdrive-encoding
mafintosh/hyperdrive-http-server
joehand/hyperdrive-http
joehand/dat-push
joehand/dat-backup
joehand/archiver-server
joehand/archiver-api
poga/hyperdrive-ln
substack/hyperdrive-multiwriter
substack/hyperdrive-named-archives
substack/git-dat
CfABrigadePhiladelphia/jawn
maxogden/dat-archiver
juliangruber/hyperdrive-stats
karissa/hypercore-stats-server
mafintosh/hypercore-stats-ui
karissa/zip-to-hyperdrive
joehand/url-dat
joehand/tar-dat
joehand/hyperdrive-duplicate

dns-discovery

Discovery peers in a distributed system using regular dns and multicast dns.

npm install dns-discovery

build status

Usage

var discovery = require('dns-discovery')

var disc1 = discovery()
var disc2 = discovery()

disc1.on('peer', function (name, peer) {
  console.log(name, peer)
})

// announce an app
disc2.announce('test-app', 9090)

API

var disc = discovery([options])

Create a new discovery instance. Options include:

{
  server: 'discovery.example.com:9090', // put a centralized dns discovery server here
  ttl: someSeconds, // ttl for records in seconds. defaults to Infinity.
  limit: someLimit, // max number of records stored. defaults to 10000.
  multicast: true, // use multicast-dns. defaults to true.
  domain: 'my-domain.com', // top-level domain to use for records. defaults to dns-discovery.local
  socket: someUdpSocket, // use this udp socket as the client socket
  loopback: false // discover yourself over multicast
}

If you have more than one discovery server you can specify an array

{
  server: [
    'discovery.example.com:9090',
    'another.discovery.example.com'
  ]
}

disc.lookup(name, [callback])

Do a lookup for a specific app name. When new peers are discovered for this name peer events will be emitted

disc.on('peer', function (name, peer) {
  console.log(name) // app name this peer was discovered for
  console.log(peer) // {host: 'some-ip', port: somePort}
})

disc.announce(name, port, [options], [callback])

Announce a new port for a specific app name. Announce also does a lookup so you don't need to do that afterwards.

If you want to specify a public port (a port that is reachable from outside your firewall) you can set the publicPort: port option. This will announce the public port to your list of dns servers and use the other port over multicast.

You can also set impliedPort: true to announce the public port of the dns socket to the list of dns servers.

disc.unannounce(name, port, [options], [callback])

Stop announcing a port for an app. Has the same options as .announce

disc.listen([port], [callback])

Listen for dns records on a specific port. You only need to call this if you want to turn your peer into a discovery server that other peers can use to store peer objects on.

var server = discovery()
server.listen(9090, function () {
  var disc = discovery({server: 'localhost:9090'})
  disc.announce('test-app', 8080) // will announce this record to the above discovery server
})

You can setup a discovery server to announce records on the internet as multicast-dns only works on a local network. The port defaults to 53 which is the standard dns port. Additionally it tries to bind to 5300 to support networks that filter dns traffic.

disc.destroy([onclose])

Destroy the discovery instance. Will destroy the underlying udp socket as well.

CLI

There is a cli tool available as well

npm install -g dns-discovery
dns-discovery help

To announce a service do

# will announce test-app over multicast-dns
dns-discovery announce test-app --port=8080

To look it up

# will print services when they are found
dns-discovery lookup test-app

To run a discovery server

# listen for services and store them with a ttl of 30s
dns-discovery listen --port=9090 --ttl=30

And to announce to that discovery server (and over multicast-dns)

# replace example.com with the host of the server running the discovery server
dns-discovery announce test-app --server=example.com:9090 --port=9090

And finally to lookup using that discovery server (and multicast-dns)

dns-discovery lookup test-app --server=example.com:9090

You can use any other dns client to resolve the records as well. For example using dig.

# dig requires the discovery server to run on port 53
dig @discovery.example.com test-app SRV

License

MIT