-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running private DHTs #22
Comments
You need to call const dht = require('@hyperswam/dht')
const node = dht({
ephemeral: true,
// make ourselves the bootstrap node
bootstrap: []
})
node.listen()
node.on('listening', () => {
const { address, port } = node.address()
console.log(`listening on ${address}:${port}`)
}) |
Thank you @davidmarkclements It looks like it is not required to call const node = dht()
node.on('listening', () => {
console.log('this fires')
}) |
Yeah we should address that with either docs or alter behaviour - @mafintosh what do you think? |
One more thing: I'm expecting these two to not connect at all, but they do: import crypto from 'crypto'
import hyperswarm, { Hyperswarm } from 'hyperswarm'
const topic = crypto.randomBytes(32)
const swx = hyperswarm({ bootstrap: [], ephemeral: true })
const swy = hyperswarm({ bootstrap: [], ephemeral: true })
swx.on('connection', socket => {
socket.write('a')
})
swy.on('connection', socket => {
socket.on('data', console.log)
})
swx.join(topic, { lookup: false, announce: true })
swy.join(topic, { lookup: true, announce: false }) |
Hyperswarm uses MDNS for discovering peers on the local network. That might be how the two are finding each other. |
We just released local discovery through the DHT yesterday.
|
I see now, thanks!! I thought hyperswarm only worked with dht-rpc. But I guess it's not possible to disable mdns completely: Well, if mdns is already working then that means this module acts a little bit differently than its predecessor (discovery-swarm). In discovery-swarm, you receive a connection event for all the different types of connections. What I'm actually trying to figure out is how to deal with duplicates. I'm creating a noise-peer socket to authenticate the other end when I receive the connection, but destroying a socket (e.g., throwing 'already connected') starts an infinite reconnection loop. This of course only happens when a peer has both the announce and lookup flags set. My workaround is to make a Swarm either an initiator or non-initiator, but not both. But what I really would love to achieve is:
sw.on('connection', socket => {
const secure = noise(socket, initiator, {
pattern: 'XX',
staticKeyPair: keys,
onstatickey: (remoteKey, done) => {
const hex = remoteKey.toString('hex')
if (remoteKeys.has(hex)) {
return done(new Error('already connected'))
}
remoteKeys.add(hex)
sockets.set(secure, hex)
if (onconnect) {
onconnect(hex)
}
if (onupdate) {
onupdate(remoteKeys)
}
done(null)
}
}) |
Here is my naive attempt to disable multicast completely: https://github.com/tetsuo/discovery/commit/116c74c846467996f74545253d4965f33059bd12 sadly |
During V5 exploration, DHT does not seem to fire the listen event when bootstrapped.
do one need to create two nodes before the first actually listen ? |
@sallespro sorry missed your comment. You need at least one none ephemeral DHT running for a server to announce itself (listen) |
I have been struggling all day today to get my private bootstrap DHT to work. This issue is the only place I can find more detailed documentation about it, but it is still not working. I have my bootstrap server code, bootstrap.js: import DHT from "@hyperswarm/dht"
const bootstrap = DHT.bootstrapper(10001, "127.0.0.1", { ephemeral: true, bootstrap: [], announceLocalAddress: true })
bootstrap.on('listening', () => {
console.log(bootstrap.localAddress())
})
bootstrap.on('connection', () => {
console.log("Got a connection??") // This never fires
}) Then my server & client code, test.js: import Hyperswarm from "hyperswarm"
const swarm = new Hyperswarm({ bootstrap: ["127.0.0.1:10001" ], ephemeral: true, announceLocalAddress: true })
swarm.on("connection", ()=> {
console.log("connected!")
})
const topic = Buffer.alloc(32).fill('hello world')
const discovery = swarm.join(topic)
await discovery.flushed()
I'm running two instances of Any direction is greatly appreciated! |
README says:
But
dht({ bootstrap: [] })
never fires alistening
event.Can you show an example for running a private bootstrap node?
The text was updated successfully, but these errors were encountered: