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
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() |
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 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] |
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() |
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
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) |
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
import * as SlashURL from '@synonymdev/slashtags-url' | |
import Corestore from 'corestore' | |
import Hyperdrive from 'hyperdrive' | |
import Hyperswarm from 'hyperswarm' | |
import RAM from 'random-access-memory' | |
const swarm = new Hyperswarm() | |
const corestore = new Corestore(RAM) | |
swarm.on('connection', socket => corestore.replicate(socket)) |
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
import Hyperswarm from 'hyperswarm' | |
import Corestore from 'corestore' | |
import ProtomuxRPC from 'protomux-rpc' | |
import Protomux from 'protomux' | |
import RAM from 'random-access-memory' | |
import createTestnet from '@hyperswarm/testnet' | |
import Hypercore from 'hypercore' | |
const testnet = await createTestnet() |
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
import Hyperswarm from 'hyperswarm' | |
import Corestore from 'corestore' | |
import ProtomuxRPC from 'protomux-rpc' | |
import RAM from 'random-access-memory' | |
import createTestnet from '@hyperswarm/testnet' | |
const testnet = await createTestnet() | |
const swarm_A = new Hyperswarm(testnet) | |
const store_A = new Corestore(RAM) |
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
import Hypercore from 'hypercore'; | |
import Hyperbee from 'hyperbee'; | |
class Hyperstate extends Hypercore { | |
constructor(storage, key, opts) { | |
super(storage, key, opts); | |
this.state = {}; | |
this.opening = this._open(); | |
this.opening.catch(noop); |
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
import { SDK } from '@synonymdev/slashtags-sdk'; | |
const sdkA = await SDK.init({ | |
persist: false, // No storage needed for this demo | |
primaryKey: Buffer.from('a'.repeat(64)), // Keep primary key consistent | |
}); | |
console.log("Alice's DHT bootstrapped"); // Bootstrapping DHT takes some time. | |
const alice = sdkA.slashtag({ name: 'alice' }); | |
alice.listen(); |
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
// npm i [email protected] [email protected] | |
// Run `node create-hypercore.js` and pass the resulting key to https://gist.github.com/Nazeh/721368b93729dcfa00049c9de230f2ad | |
const Hypercore = require('hypercore'); | |
const Hyperswarm = require('hyperswarm'); | |
const createCore = async () => { | |
const core = new Hypercore('origin', { valueEncoding: 'json' }); | |
await core.ready(); | |
// Add blocks here if you want. |
NewerOlder