Skip to content

Instantly share code, notes, and snippets.

View Nuhvi's full-sized avatar

Nuh Nuhvi

View GitHub Profile
@Nuhvi
Nuhvi / hyperswarm-dht-record-max-size.js
Last active March 3, 2023 00:19
Hyperswarm record max size should be less than MTU
import DHT from '@hyperswarm/dht'
const MTU = 1500
const payloadSize = MTU / 2
const payload = random(payloadSize)
const dht = new DHT()
const mutablePutResponse = await dht.mutablePut(dht.defaultKeyPair, payload)
@Nuhvi
Nuhvi / hyperswarm-works-server.js
Last active March 4, 2023 19:50
hyperswarm works
// 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()
@Nuhvi
Nuhvi / hyperswarm-works-connect.js
Last active March 4, 2023 19:51
hyperswarm works
// Run https://gist.github.com/Nazeh/64edc0fa2d0920f55eb8b4df227c93c9
// on one machine, then run this code on another passing the publicKey
// logged from the server `node hyperswarm-works-connect.js <publicKey>`
// then you should be able to connect to your peer 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 publicKeyHex = process.argv[2]
@Nuhvi
Nuhvi / get_peers.js
Last active September 9, 2023 03:56
Mainline peer discovery
import DHT from 'bittorrent-dht'
const BOOTSTRAP = [
{ host: 'router.bittorrent.com', port: 6881 },
{ host: 'router.utorrent.com', port: 6881 },
{ host: 'dht.transmissionbt.com', port: 6881 },
{ host: 'router.nuh.dev', port: 6881 }
]
const infoHash = random()