holepunchto / hyperdht

The DHT powering Hyperswarm
https://docs.holepunch.to
MIT License
323 stars 46 forks source link

Node can be connected to by its defaultKeyPair.publicKey, even if `node.listening` is empty. #70

Closed Nuhvi closed 2 years ago

Nuhvi commented 2 years ago

While testing I realized, I can connect to a node by its defaultKeyPair, even if there are no listening servers (node1.listening.size === 0, is that intended behavior? can I expect that to persist in the future, because if so, then I will expect the defaultKeyPair to be accessible as well, as a way to pass the node address, without running a server first?

    const node1 = new DHT()
    // const server = node1.createServer();
    // await server.listen();

    const node2 = new DHT()
    const secretSocket = node2.connect(node1.defaultKeyPair.publicKey)

    expect(secretSocket.remotePublicKey).to.eql(node1.defaultKeyPair.publicKey)
    expect(node1.defaultKeyPair.publicKey).to.not.eql(node2.defaultKeyPair.publicKey)
    expect(secretSocket.publicKey).to.eql(node2.defaultKeyPair.publicKey)

    node1.destroy()
    node2.destroy()
mafintosh commented 2 years ago

Not sure what you mean, can you make a runnable gist to illustrate?

Nuhvi commented 2 years ago

My band, I mistook the noise connection having the publicKey and remotePublicKey as a proxy of being correctly opened, but if I wait for on('open') without a running server, a Could not find peer error is thrown, as expected.