Skip to content

Instantly share code, notes, and snippets.

@millette
Last active August 25, 2018 01:29
Show Gist options
  • Save millette/de0a7151a45f60c11694465a4a77bc1a to your computer and use it in GitHub Desktop.
Save millette/de0a7151a45f60c11694465a4a77bc1a to your computer and use it in GitHub Desktop.
discodat
/*
First, in a new directory run:
npm init -y && npm install dns-discovery --save
Then copy index.js to that directory and run:
node index.js
*/
'use strict'
const dns = require('dns-discovery')
const DAT_DOMAIN = 'dat.local'
const DEFAULT_DISCOVERY = [
'discovery1.datprotocol.com',
'discovery2.datprotocol.com'
]
const opts = {
dns: {server: DEFAULT_DISCOVERY, domain: DAT_DOMAIN}
}
const disc1 = dns(opts)
const hash = 'ff8e8993826467c3e1a9a91bc8c598a631fa54a40ab6a487c0cb48e505f91924'
// .slice(0, 20)
disc1.on('peer', (name, { host, port }) => {
console.log('PEER', name, host, port)
})
disc1.on('listening', () => console.log('LISTENING'))
disc1.lookup(hash, (a, b, c) => {
console.log('a:', a)
console.log('b:', b)
console.log('c:', c)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment