holepunchto / hyperdht

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

stream from node.lookup() doesn't match the documented interface #72

Closed Nuhvi closed 2 years ago

Nuhvi commented 2 years ago

Calling node.lookup doesn't return the object described here: https://github.com/hyperswarm/dht#const-stream--nodelookuptopic-options

It returns a Query instance from the dht-rpc and I can't find the described interface there either.

mafintosh commented 2 years ago

Ah the query IS a stream. Use like you would any nodejs stream or async iterator

mafintosh commented 2 years ago

The wording could be better, (feel free to improve :)) but the "looks like this" part describes the data returned.

Nuhvi commented 2 years ago

I couldn't get any chunks with on('data'), however this works:

await stream.finished();
stream.closestNodes

Which are the public functions on Query, so I will leave it at that until I find a use for any other API.

mafintosh commented 2 years ago

It emits data, end, close. If you data was emitted the stream was prob empty.

Nuhvi commented 2 years ago

Well, how to send data?

All I have is another nod e that is announcing:


      const node = new DHT({ keyPair });
      node.announce(topic);
``

So if that doesn't result in data, I am not sure what does?
mafintosh commented 2 years ago

See the tests, it returns the data of nodes that are already announced.

mafintosh commented 2 years ago

For example this one, https://github.com/hyperswarm/dht/blob/master/test/announces.js#L36-L39

Nuhvi commented 2 years ago

I didn't wait for the announced stream to finish.

This work fine:

      await node.announce(topic, keyPair).finished();