{"_id":"@atek-cloud/network","_rev":"6-c11333dcb3dad8ce5c4d7bfb4c3fe3f9","name":"@atek-cloud/network","dist-tags":{"latest":"0.0.5"},"versions":{"0.0.1":{"name":"@atek-cloud/network","version":"0.0.1","description":"Atek's networking protocol (uses Hyperswarm)","main":"dist/index.js","type":"module","scripts":{"build":"tsc --project tsconfig.json","test":"ava -s test/*.ts"},"keywords":[],"author":{"name":"Paul Frazee","email":"pfrazee@gmail.com"},"license":"MIT","dependencies":{"@hyperswarm/dht":"5.0.0-rc.6","@types/bl":"^5.0.1","@types/streamx":"^2.9.1","agent-base":"^6.0.2","bl":"^5.0.0","hi-base32":"^0.5.1","it-pipe":"^1.1.0","it-to-stream":"^1.0.0","libp2p-mplex":"^0.10.4","multistream-select":"^2.0.1","pump":"^3.0.0"},"devDependencies":{"@types/node":"^16.6.2","@types/node-fetch":"^2.5.12","ava":"^3.15.0","node-fetch":"^3.0.0","ts-node":"^10.2.1","typescript":"^4.3.5"},"ava":{"extensions":{"ts":"module"},"nonSemVerExperiments":{"configurableModuleFormat":true},"nodeArguments":["--loader=ts-node/esm"]},"directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/atek-cloud/network.git"},"bugs":{"url":"https://github.com/atek-cloud/network/issues"},"homepage":"https://github.com/atek-cloud/network#readme","gitHead":"81b43a22e8dc59faf8f18953b90ddc652eeec526","_id":"@atek-cloud/network@0.0.1","_nodeVersion":"16.1.0","_npmVersion":"7.11.2","dist":{"integrity":"sha512-FS8DyLZYpFHoPnizB8M8ChNqc1j+rGiasffS76ynf4pFNb+4C5qiYSMXI9g6HGQdedQNZuNFXr6D/W4JtbJ2GQ==","shasum":"e82d14bc8ab695c13050694c365b186296cc0ece","tarball":"https://registry.npmjs.org/@atek-cloud/network/-/network-0.0.1.tgz","fileCount":21,"unpackedSize":46118,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDYeK4vjIVhF+yhofSQrIE25ND7eMpJl7r5U8po4pI98AIhAKpRlY5L/XxzSkYON3BT8+omMIzw3wybK7ePX+iZ/Xeq"}]},"_npmUser":{"name":"pfrazee","email":"pfrazee@gmail.com"},"maintainers":[{"name":"pfrazee","email":"pfrazee@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/network_0.0.1_1634401118559_0.6763039479677246"},"_hasShrinkwrap":false},"0.0.2":{"name":"@atek-cloud/network","version":"0.0.2","description":"Atek's networking protocol (uses Hyperswarm)","main":"dist/index.js","type":"module","scripts":{"build":"tsc --project tsconfig.json","test":"ava -s test/*.ts"},"keywords":[],"author":{"name":"Paul Frazee","email":"pfrazee@gmail.com"},"license":"MIT","dependencies":{"@hyperswarm/dht":"5.0.0-rc.12","@types/bl":"^5.0.1","@types/streamx":"^2.9.1","agent-base":"^6.0.2","bl":"^5.0.0","hi-base32":"^0.5.1","it-pipe":"^1.1.0","it-to-stream":"^1.0.0","libp2p-mplex":"^0.10.4","multistream-select":"^2.0.1","pump":"^3.0.0"},"devDependencies":{"@types/node":"^16.6.2","@types/node-fetch":"^2.5.12","ava":"^3.15.0","node-fetch":"^3.0.0","ts-node":"^10.2.1","typescript":"^4.3.5"},"ava":{"extensions":{"ts":"module"},"nonSemVerExperiments":{"configurableModuleFormat":true},"nodeArguments":["--loader=ts-node/esm"]},"directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/atek-cloud/network.git"},"bugs":{"url":"https://github.com/atek-cloud/network/issues"},"homepage":"https://github.com/atek-cloud/network#readme","gitHead":"e8adebc784e24a9b1d267eff8380de8500e12b59","_id":"@atek-cloud/network@0.0.2","_nodeVersion":"16.1.0","_npmVersion":"7.11.2","dist":{"integrity":"sha512-mXrv4wAf5EuV0hbDEWKlZrV0NQskRBf0QT3Zbn746qq64hLlNIaGiMMz80FM0KkD/+tZlxRS/N8HzgFvwvhuQQ==","shasum":"1186cc0e086511a5847bde3641f852ceb1b86bed","tarball":"https://registry.npmjs.org/@atek-cloud/network/-/network-0.0.2.tgz","fileCount":18,"unpackedSize":35505,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD5lV8QhbU69o9SPaSQKjBPZC6e/bslwDRUmvut+NlrqQIhALiPxlLOKu2OB92hTiOG4FXGJcomPQ18WVRXlqQ2dAsr"}]},"_npmUser":{"name":"pfrazee","email":"pfrazee@gmail.com"},"maintainers":[{"name":"pfrazee","email":"pfrazee@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/network_0.0.2_1634411930834_0.5739203963637598"},"_hasShrinkwrap":false},"0.0.3":{"name":"@atek-cloud/network","version":"0.0.3","description":"Atek's networking protocol (uses Hyperswarm)","main":"dist/index.js","type":"module","scripts":{"build":"tsc --project tsconfig.json","test":"ava -s test/*.ts"},"keywords":[],"author":{"name":"Paul Frazee","email":"pfrazee@gmail.com"},"license":"MIT","dependencies":{"@hyperswarm/dht":"5.0.0-rc.12","@types/bl":"^5.0.1","@types/streamx":"^2.9.1","agent-base":"^6.0.2","bl":"^5.0.0","hi-base32":"^0.5.1","it-pipe":"^1.1.0","it-to-stream":"^1.0.0","libp2p-mplex":"^0.10.4","multistream-select":"^2.0.1","pump":"^3.0.0"},"devDependencies":{"@types/node":"^16.6.2","@types/node-fetch":"^2.5.12","ava":"^3.15.0","node-fetch":"^3.0.0","ts-node":"^10.2.1","typescript":"^4.3.5"},"ava":{"extensions":{"ts":"module"},"nonSemVerExperiments":{"configurableModuleFormat":true},"nodeArguments":["--loader=ts-node/esm"]},"directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/atek-cloud/network.git"},"bugs":{"url":"https://github.com/atek-cloud/network/issues"},"homepage":"https://github.com/atek-cloud/network#readme","gitHead":"d40ebb67ec6378ad6e632adaef76d0d1699c9733","_id":"@atek-cloud/network@0.0.3","_nodeVersion":"16.1.0","_npmVersion":"7.11.2","dist":{"integrity":"sha512-crBmIJs+avcaZMrfoW57ivDQUe0POLwzqJ3pic4BfAr7o++l7LmOrzrL7dHB9olzZhHNb1HmCMv73VRrrj/GsA==","shasum":"48608204fa9c48ba173482fae257ae24b984f850","tarball":"https://registry.npmjs.org/@atek-cloud/network/-/network-0.0.3.tgz","fileCount":18,"unpackedSize":35643,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD+oitwwBt2UoqlfzWjlCac23wo05734u6FcLQfDZ9O9AIhAN1To4dquG47jcvINUJw0ktv8LIa3Jiqp0cq8qB+j2Ax"}]},"_npmUser":{"name":"pfrazee","email":"pfrazee@gmail.com"},"maintainers":[{"name":"pfrazee","email":"pfrazee@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/network_0.0.3_1634416206408_0.33909376529887725"},"_hasShrinkwrap":false},"0.0.4":{"name":"@atek-cloud/network","version":"0.0.4","description":"Atek's networking protocol (uses Hyperswarm)","main":"dist/index.js","type":"module","scripts":{"build":"tsc --project tsconfig.json","test":"ava -s test/*.ts --timeout=5m"},"keywords":[],"author":{"name":"Paul Frazee","email":"pfrazee@gmail.com"},"license":"MIT","dependencies":{"@hyperswarm/dht":"5.0.0-rc.12","@types/streamx":"^2.9.1","agent-base":"^6.0.2","hi-base32":"^0.5.1","pump":"^3.0.0"},"devDependencies":{"@types/node":"^16.6.2","@types/node-fetch":"^2.5.12","ava":"^3.15.0","node-fetch":"^3.0.0","ts-node":"^10.2.1","typescript":"^4.3.5"},"ava":{"extensions":{"ts":"module"},"nonSemVerExperiments":{"configurableModuleFormat":true},"nodeArguments":["--loader=ts-node/esm"]},"directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/atek-cloud/network.git"},"bugs":{"url":"https://github.com/atek-cloud/network/issues"},"homepage":"https://github.com/atek-cloud/network#readme","gitHead":"586758318d55a2073c24af2aa03e8f5102110b0a","_id":"@atek-cloud/network@0.0.4","_nodeVersion":"16.1.0","_npmVersion":"7.11.2","dist":{"integrity":"sha512-hfWaeEkWDPlxlVdpSclmBzJEK6cpYmH4X8xXpASco8rsM+sR5bikqtWECeEiJwkcM33BFHBtr4907aYTrFcusg==","shasum":"09feb89e76541ed3e8398286c53dc5027f1c4348","tarball":"https://registry.npmjs.org/@atek-cloud/network/-/network-0.0.4.tgz","fileCount":15,"unpackedSize":31832,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH5OQ9eGvugbQY4BvYmnQhZKENCYola7pb5oAmkIuZSzAiEA+fTrQSqs8dUXB+Ut51LmRfbTznxWyl8J0gazJUSMndI="}]},"_npmUser":{"name":"pfrazee","email":"pfrazee@gmail.com"},"maintainers":[{"name":"pfrazee","email":"pfrazee@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/network_0.0.4_1634669610384_0.9555762956024281"},"_hasShrinkwrap":false},"0.0.5":{"name":"@atek-cloud/network","version":"0.0.5","description":"Atek's networking protocol (uses Hyperswarm)","main":"dist/index.js","type":"module","scripts":{"build":"tsc --project tsconfig.json","test":"ava -s test/*.ts --timeout=5m"},"keywords":[],"author":{"name":"Paul Frazee","email":"pfrazee@gmail.com"},"license":"MIT","dependencies":{"@hyperswarm/dht":"5.0.0-rc.12","@types/streamx":"^2.9.1","agent-base":"^6.0.2","hi-base32":"^0.5.1","pump":"^3.0.0"},"devDependencies":{"@types/node":"^16.6.2","@types/node-fetch":"^2.5.12","ava":"^3.15.0","node-fetch":"^3.0.0","ts-node":"^10.2.1","typescript":"^4.3.5"},"ava":{"extensions":{"ts":"module"},"nonSemVerExperiments":{"configurableModuleFormat":true},"nodeArguments":["--loader=ts-node/esm"]},"directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/atek-cloud/network.git"},"bugs":{"url":"https://github.com/atek-cloud/network/issues"},"homepage":"https://github.com/atek-cloud/network#readme","gitHead":"10e11a1bf904727e1aa5109b8ac8cf40a24d0f90","_id":"@atek-cloud/network@0.0.5","_nodeVersion":"16.1.0","_npmVersion":"7.11.2","dist":{"integrity":"sha512-Rl51HV6AdR2jRQn6+f27YtRc3HH+L/ijRXkw3dBFA7XcmvGVAN0ZNRRxH3OuoYbs3gUx6R2hH1vhkU2tQYOjhA==","shasum":"3af198d39b1a2eaecebe01ff68788a2796209d29","tarball":"https://registry.npmjs.org/@atek-cloud/network/-/network-0.0.5.tgz","fileCount":15,"unpackedSize":29857,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhzGbjCRA9TVsSAnZWagAACi0QAILsryM9CVWuq1692AdH\nh6heZE9cKMifZJVMivM7c1itEDuRMWMer4HnpFr2yHxoz18hzG9S+ZZ9G5Wl\nh2hUNwBvI8Dhsw7uwMiq3lNcY+/mnl16pOb6cHO2+o1O1E1oMmQgKEBUJZCn\nlUFdrmag2n+Tgvb2DWzdVCXIZWfGc5IVktSCbb8YXDUd063MrlPLuUSsu4d5\nKR230KssUcikUQ54lMR87BN1ktwwmQBc5KLquzVrvCYUzIvSSZXzgcVoRQQ7\nZhjlyw9ssC4rVMtTLXnHfujb65g+W0r5nvtOb3W795S2dHAY0dXq1a1ZS1Yx\nWEswhkQSjdxASSKHaLmboqnCR/wmOysLuIs0KVY6rl99ZUGSJpT6IIg0eKGi\nK+oVA/czEKNLuWp5Zh7eWD0BEAi1KMmJRCcey9vSI5mOlGCy76SM+4BaeGtj\nmEejfvjM2eJ6aUYR6bHyx1r/fyP+0t/f8oi6AidS/nib9LEGXl0donsKCzSw\nMrgmZzJh38OL+bLfApmua6bOL+uXCG9NCrZOqyedVK4/pSGRalbQjzzJUXvk\n4WCHd01LDU24NTnZc/N0JNZT5vb/+jSfpXYvDQlid/Zau/JAmUAtPp6n3T6B\n5SDMs10jtFsvlMp8iPvKcpxMg+ID8e2mHz1/l+60lNRMbEOelfnfPaamayS4\nhYlo\r\n=bnAk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCGnwIA4EPDv62OC3P/a/nvaq0JEllcAk/Khj8JgUd3NwIhAMoguPV80B0EUtQCjINtB3XcTZpFmsja+dJb6s6IapBZ"}]},"_npmUser":{"name":"pfrazee","email":"pfrazee@gmail.com"},"maintainers":[{"name":"pfrazee","email":"pfrazee@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/network_0.0.5_1635429167736_0.23632830770587598"},"_hasShrinkwrap":false}},"time":{"created":"2021-10-16T16:18:38.515Z","0.0.1":"2021-10-16T16:18:38.744Z","modified":"2022-04-04T16:03:03.195Z","0.0.2":"2021-10-16T19:18:51.134Z","0.0.3":"2021-10-16T20:30:06.560Z","0.0.4":"2021-10-19T18:53:30.554Z","0.0.5":"2021-10-28T13:52:47.841Z"},"maintainers":[{"name":"pfrazee","email":"pfrazee@gmail.com"}],"description":"Atek's networking protocol (uses Hyperswarm)","homepage":"https://github.com/atek-cloud/network#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/atek-cloud/network.git"},"author":{"name":"Paul Frazee","email":"pfrazee@gmail.com"},"bugs":{"url":"https://github.com/atek-cloud/network/issues"},"license":"MIT","readme":"# Atek Network\n\n```\nnpm i @atek-cloud/network\n```\n\nAtek's networking protocol. Uses [Hyperswarm](https://github.com/hyperswarm) for the connections layer.\n\nIncludes APIs for transmitting HTTP traffic, which is Atek's preferred protocol.\n\n```js\nimport * as AtekNet from '@atek-cloud/network'\n\nawait AtekNet.setup()\n\n// create a new node which listens for connections\nconst node1 = new AtekNet.Node(AtekNet.createKeypair())\nawait node1.listen()\n\n// set a protocol handler\nnode1.setProtocolHandler((stream, socket) => {\n  console.log('New connection from', socket.remotePublicKey)\n  stream.write('Hello there')\n  stream.end()\n})\n\n// create a second node and connect it to the first node\nconst node2 = new AtekNet.Node(AtekNet.createKeypair())\nconst sock = await node2.connect(node1.keyPair.publicKey)\n\nsock.stream.on('data', (chunk) => console.log(chunk.toString())) // => 'Hello there'\n```\n\nGlossary for the API:\n\n- `node` A network node identified by a keypair. May (or may not) listen for connections or connect to other nodes. Will identify itself by its public key to all connected nodes.\n- `socket` A connection to a peer.\n\nQuick overview:\n\n- `setup()` Must be called before using AtekNet.\n- `createKeypair()` Create a keypair to identify Atek nodes. If you plan to reuse the keypair, you should store it somewhere safe.\n- `new Node(keypair)` Create a new Atek node.\n- `node.listen()` Start listening for incoming connections.\n- `node.setProtocolHandler(handler)` Add an incoming-requests handler.\n- `node.connect(remotePublicKey) => socket` Create a connection the node identified by the given public key.\n- `http.createProxy(node, port)` Create an HTTP 1.1 handler on the given node and route its traffic to `localhost:${port}`.\n- `http.createAgent(node)` Create an agent for initiating HTTP connections over the Atek network.\n\n## HTTP APIs\n\nThe module includes tooling to send and receive HTTP traffic. On the receiving side, you create a proxy which routes to a localhost port. On the sending side, you create a NodeJS HTTP agent which will route all requests to `http://{pubkey-base32}.atek.app` over the Atek network.\n\n```js\nimport http from 'http'\nimport * as AtekNet from '@atek-cloud/network'\n\nawait AtekNet.setup()\n\n// create our HTTP server\nconst httpServer = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    host: req.headers.host,\n    remote: req.headers['atek-remote-public-key'],\n    url: req.url,\n    data: 'Hello World!'\n  }));\n});\nhttpServer.listen(8080)\n\n// create our Atek server node\nconst node1 = new AtekNet.Node(AtekNet.createKeypair())\nawait node1.listen()\n\nAtekNet.http.createProxy(node1, 8080) // proxy the 'http/1.1' protocol to our http server\n\n// create another atek node and an http agent\nconst node2 = new AtekNet.Node(AtekNet.createKeypair())\nconst agent = AtekNet.http.createAgent(node2)\n\n// send an HTTP GET request using our agent\nhttp.get(node1.httpUrl, {agent}, (res) => {\n  res.setEncoding('utf8');\n  let rawData = '';\n  res.on('data', (chunk) => { rawData += chunk; });\n  res.on('end', () => {\n    console.log(rawData)\n  })\n})\n```\n\n## API\n\n### `createKeypair(): KeyPair`\n\nCreate a new keypair. A keypair is used to identify Atek nodes.\n\n### `new Node(keyPair: KeyPair)`\n\nCreate a new network node using the given keypair.\n\n### `atekNode.keyPair: KeyPair`\n\n### `atekNode.isListening: boolean`\n\n### `atekNode.publicKeyB32: string`\n\n### `atekNode.httpHostname: string`\n\n### `atekNode.httpUrl: string`\n\n### `atekNode.connect(remotePublicKey: Buffer) => Promise<AtekSocket>`\n\nEstablish a connection to the given public key.\n\n### `atekNode.listen() => Promise<void>`\n\nAnnounce the node on the Hyperswarm DHT and begin accepting connections.\n\n### `atekNode.close() => Promise<void>`\n\nStop listening and close all existing connections.\n\n### `atekNode.setProtocolHandler (handler: AtekNodeProtocolHandler)`\n\nSet a handler for incoming connections.\n\nHandler should match this signature:\n\n```\ninterface AtekNodeProtocolHandler {\n  (stream: Duplex, socket: AtekSocket): void|Promise<void>\n}\n```\n\n### `atekNode.removeProtocolHandler ()`\n\nRemove the handler.\n\n### `atekNode.on(\"connection\", socket: AtekSocket)`\n\nEmitted when an incoming connection is created.\n\n### `AtekSocket`\n\nThe class used for sockets/connections between nodes.\n\n### `atekSocket.remotePublicKey: Buffer`\n\n### `atekSocket.remotePublicKeyB32: string`\n\n### `atekSocket.close(): Promise<void>`\n\nClose the socket.\n\n### `http.createProxy(node: Node, port: number)`\n\nCreates a handler on the `node` for the `http/1.1` protocol and proxies all requests to `localhost:${port}`. Requests will have the `Atek-Remote-Public-Key` header set to the base32-encoded public key of the connecting node.\n\n### `http.createAgent(node: Node): Agent`\n\nCreates a NodeJS \"http agent\" which routes all requests to `http://{pubkey-base32}.atek.app` over the Atek network.\n\n## Notable Changes\n\n### 0.0.4 - Drop libp2p modules\n\nPreviously we used [LibP2P Mplex](https://github.com/libp2p/js-libp2p-mplex) for multiplexing on the connection and [LibP2P Multistream Select](https://github.com/multiformats/js-multistream-select) for protocol negotiation. These tools were used for performance and protocol-negotiation, respectively.\n\nThe Hyperswarm team committed to two updates which will make those modules unnecessary:\n\n- [dht#56 Cache handshake information for quick-connect of additional sockets](https://github.com/hyperswarm/dht/issues/56). This will lead to fast subsequent connections between peers, making the muxer less important.\n- [dht#57 Add userData to handshake](https://github.com/hyperswarm/dht/issues/57). This can be used to provide protocol metadata.\n\nAs of 0.0.4's release, these updates haven't landed yet but I wanted to drop the wire-protocol behaviors in expectation of them. When dht#56 lands, we'll get a perf bump (especially with HTTP proxies). When dht#57 lands, we'll re-add some of the protocol negotiation features to this module.\n\n## License\n\nMIT","readmeFilename":"README.md"}