{"bugs":{"url":"https://github.com/hyperswarm/dht/issues"},"dist":{"shasum":"eab579d3e362f85461d391dfcb4981028437db86","tarball":"https://registry.npmjs.org/@hyperswarm/dht/-/dht-5.0.0-rc.0.tgz","fileCount":14,"integrity":"sha512-4mZAomDRtqzFSd6QjyoyKzU30iTvRAuJl2Kf+RXyY8vumLZ2cO6fk9R8LdnGqpH6/VXQ1UES1yNMO7NrXNzbyA==","signatures":[{"sig":"MEYCIQDSkYm6/05MF7cSruc6dhIH/NsFO2w78SGX/VIm6GIs3gIhAJLcWFYtJZ/K4IoiTmeKvvWSP34RSl4Xe3l9cC1sQOGl","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":63936,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgyyPjCRA9TVsSAnZWagAAFJUP/1xgfuVuXNqrathqymaF\nKAPC+ls5BZdvidhnlvo6pS3zKgBKsgqer5+N0MuUMR0sPlfuQxdy89aNEQXX\ntmcNDTb0a5fSHJlqGBfs67Cbi5xNOo7NPuiIqW9WwxUKRhwFkMenPTWzb9Gj\nGrIiAOrEYZdiHVe1IiWxh7S6QS2/2evGGatXrOK4RVMejcZ/bXFHqFq8jgdG\nxZoT/0MBaIoK18PmTQnQrZwBQXCO8wq54WlSDpLVJN2VGcafZsNuttsco+3b\nuBu/1AxL0SPbxqAHC2/uoYVFp7Cuqlqtej3KBQiho8iRIlamoXIND5HLx0bT\nPHAdtmDf9j6TrvQXLpDtcSim4lYih18dkf726z6OZKTp7Ec81KOWG6eSPpLS\n689hoEtoiMvzqGIrV8mPiJwwHHlux1LurL/ymuMDZhn9nvp9lA4pn7uScN7B\ndU9N2Ad4+ec4f2hc+PEM7nYvBc3F3Bm3Ew/eMqC5JAE7huTzqkuGg/gehWdZ\nhvhvi/vSr6GxmtPR1UXapKmE5w+yfeW9Yjk4A4Ct4X04lmKTXQh6R/faqXu8\nkAQ7KJLH+jEMh078dPPzt1Q8AwI7re6lyOm+zuUAoim7gBg6yJiuWsIkEgRj\nbeubVk6GWQg/DsPlLeuTUrnRQkJzed67xeMwSSMuDEUO3KpIqWVv1FOD3epk\nPMHI\r\n=TCCy\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","name":"@hyperswarm/dht","author":{"url":"@mafintosh","name":"Mathias Buus"},"readme":"# @hyperswarm/dht\n\nThe DHT powering the HyperSwarm network\n\n```\nnpm install @hyperswarm/dht@next\n```\n\nBuilt on top of [dht-rpc](https://github.com/mafintosh/dht-rpc).\n\nThe Hyperswarm DHT uses a series of hole punching techniques to make sure connectivity works on most networks,\nand is mainly used to facilitate finding and connecting to peers using end to end encrypted Noise streams.\n\n## NOTE: v5 Release Candidate\n\nNote that this is the README for the v5 release candidate.\nTo see the v4 documentation/code go to https://github.com/hyperswarm/dht/tree/v4\n\n## Usage\n\nTo try it out, first instantiate a DHT instance\n\n``` js\nconst DHT = require('@hyperswarm/dht')\nconst node = new DHT()\n```\n\nThen on one computer listen for connections\n\n``` js\n// create a server to listen for secure connections\nconst server = node.createServer()\n\nserver.on('connection', function (noiseSocket) {\n  // noiseSocket is E2E between you and the other peer\n  // pipe it somewhere like any duplex stream\n\n  console.log('Remote public key', noiseSocket.remotePublicKey)\n  console.log('Local public key', noiseSocket.publicKey) // same as keyPair.publicKey\n\n  process.stdin.pipe(noiseSocket).pipe(process.stdout)\n})\n\n// make a ed25519 keypair to listen on\nconst keyPair = DHT.keyPair()\n\n// this makes the server accept connections on this keypair\nawait server.listen(keyPair)\n```\n\nThen on another connect to the computer using the public key of the key-pair it is listening on\n\n``` js\n// publicKey here is keyPair.publicKey from above\nconst noiseSocket = anotherNode.connect(publicKey)\n\nnoiseSocket.on('open', function () {\n  // noiseSocket fully open with the other peer\n})\n\n// pipe it somewhere like any duplex stream\nprocess.stdin.pipe(noiseSocket).pipe(process.stdout)\n```\n\n## API\n\n#### `const node = new DHT([options])`\n\nCreate a new HyperSwarm DHT node.\n\nOptions include:\n\n```js\n{\n  // Optionally overwrite the default bootstrap servers\n  // Defaults to ['testnet1.hyperdht.org:49736', 'testnet2.hyperdht.org:49736', 'testnet3.hyperdht.org:49736']\n  bootstrap: ['host:port']\n}\n```\n\nSee [dht-rpc](https://github.com/mafintosh/dht-rpc) for more options as HyperDHT inherits from that.\n\n*Note:* The default bootstrap servers are publicly served on behalf of the commons. To run a fully private DHT, start two or more dht nodes with an empty bootstrap array (`new DHT({bootstrap:[]})`) and then use the addresses of those nodes as the `bootstrap` option in all other dht nodes.\n\n#### `keyPair = DHT.keyPair([salt])`\n\nUse this method to generate the required keypair for DHT operations.\n\nReturns an object with `{publicKey, secretKey}`. `publicKey` holds a public key buffer, `secretKey` holds a private key buffer.\n\nIf you pass any options they are forwarded to dht-rpc.\n\n#### `const stream = node.lookup(topic, [options])`\n\nLook for peers in the DHT on the given topic. Topic should be a 32 byte buffer (normally a hash of something).\n\nThe returned stream looks like this\n\n```js\n{\n  // The DHT id of the responding peer (hash of their address)\n  id: <node-id-of-the-dht-peer>,\n  // Who sent the response?\n  from: { host, port },\n  // What address they responded to (i.e. your address)\n  to: { host, port },\n  // List of peers announcing under this topic\n  peers: [ { publicKey, nodes: [{ host, port }, ...] } ]\n}\n```\n\nTo connect to the peers you should afterwards call `connect` with those public keys.\n\nIf you pass any options they are forwarded to dht-rpc.\n\n#### `const stream = node.announce(topic, keyPair, [nodes], [options])`\n\nAnnounce that you are listening on a key-pair to the DHT under a specific topic.\n\nWhen announcing you'll send a signed proof to peers that you own the key-pair and wish to announce under the specific topic. Optionally you can provide up to 3 nodes, indicating which DHT nodes you are \"close\" to in terms of XOR distance from the hash of your public key - this speeds up connects later on for other users.\n\nAn announce does a parallel lookup so the stream returned looks like the lookup stream.\n\nCreating a server using `dht.createServer` automatically announces itself periodically on the key-pair it is listening on. When announcing the server under a specific topic, you can access the nodes it is close to using `server.nodes`.\n\nIf you pass any options they are forwarded to dht-rpc.\n\n#### `await node.unannounce(topic, keyPair, [options])`\n\nUnannounce a key-pair.\n\nIf you pass any options they are forwarded to dht-rpc.\n\n#### `await node.destroy()`\n\nFully destroy this DHT node.\n\n#### `{ hash, closestNodes } = await node.immutablePut(value, [options])`\n\nStore an immutable value in the DHT. When successful, the hash of the value is returned.\n\nIf you pass any options they are forwarded to dht-rpc.\n\n#### `{ value, from, closestNodes } = await node.immutableGet(hash, [options])`\n\nFetch an immutable value from the DHT. When successful, it returns the value corresponding to the hash.\n\nIf you pass any options they are forwarded to dht-rpc.\n\n#### `await { seq, closestNodes } = node.mutablePut(keyPair, value, [options])`\n\nStore a mutable value in the DHT.\n\nIf you pass any options they are forwarded to dht-rpc.\n\n#### `await { seq, value, from, closestNodes } = node.mutableGet(publicKey, [options])`\n\nFetch a mutable value from the DHT.\n\nOptions:\n\n* `seq` - OPTIONAL, default `0`, a number which will only return values with corresponding `seq` values that are greater than or equal to the supplied `seq` option.\n* `latest` - OPTIONAL - default `false`, a boolean indicating whether the query should try to find the highest seq before returning, or just the first verified value larger than `options.seq` it sees.\n\nAny additional options you pass are forwarded to dht-rpc.\n\n## Additional API\n\nSee [dht-rpc](https://github.com/mafintosh/dht-rpc) for the additional APIs the DHT exposes.\n\n## CLI\n\nYou can start a DHT node in the command line, using the [@hyperswarm/cli](https://github.com/hyperswarm/cli) package:\n\n```sh\nnpm install -g @hyperswarm/cli\nhyperswarm-dht # runs a DHT node\n```\n\n## License\n\nMIT\n","gitHead":"60e76e3958264107c0bdc3dd62e67f6c5f0d5f2c","license":"MIT","scripts":{"lint":"standard","test":"standard && tape test/*.js"},"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"homepage":"https://github.com/hyperswarm/dht#readme","keywords":[],"repository":{"url":"git+https://github.com/hyperswarm/dht.git","type":"git"},"_npmVersion":"6.14.13","description":"The DHT powering the HyperSwarm stack","directories":{"lib":"lib","test":"test"},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"},{"name":"pfrazee","email":"pfrazee@gmail.com"},{"name":"davidmarkclements","email":"david.mark.clements@gmail.com"}],"_nodeVersion":"16.1.0","dependencies":{"xache":"^1.0.0","dht-rpc":"next","utp-native":"^2.4.0","record-cache":"^1.1.1","noise-protocol":"^3.0.1","compact-encoding":"^2.1.0","sodium-universal":"^3.0.4","noise-secret-stream":"^3.0.1"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"tape":"^5.2.2","standard":"^16.0.3"},"_npmOperationalInternal":{"tmp":"tmp/dht_5.0.0-rc.0_1623925730499_0.9684746224546037","host":"s3://npm-registry-packages"},"_id":"@hyperswarm/dht@5.0.0-rc.0","version":"5.0.0-rc.0"}