Last active
March 4, 2023 19:50
-
-
Save Nuhvi/64edc0fa2d0920f55eb8b4df227c93c9 to your computer and use it in GitHub Desktop.
hyperswarm works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run `node hyperswarm-works-server.js` on one machine, | |
// then pass the logged server's public key to your peer, | |
// once they connect using https://gist.github.com/Nazeh/501ff7b94c4c62a997b8315d3606fc92 | |
// they should be able to connect to you and start chatting. | |
// If not, run https://github.com/holepunchto/hyperswarm-doctor | |
// to check both of your networks, if both have randomized ports, holepunching won't work. | |
import DHT from '@hyperswarm/dht' | |
const node = new DHT() | |
// create a server to listen for secure connections | |
const server = node.createServer() | |
server.on('connection', function (socket) { | |
// socket is E2E encrypted between you and the other peer | |
console.log('Remote public key', socket.remotePublicKey.toString('hex')) | |
// pipe it somewhere like any duplex stream | |
process.stdin.pipe(socket).pipe(process.stdout) | |
}) | |
// make a ed25519 keypair to listen on | |
const keyPair = DHT.keyPair() | |
// this makes the server accept connections on this keypair | |
await server.listen(keyPair) | |
console.log("Listening on", server.address().publicKey.toString('hex')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment