Closed derpsteb closed 6 years ago
With current version (0.11.2) I'm getting:
i am ready
71a9a8e
I'm running demo/node-server.js
and demo/node-client.js
.
Yeah. But see what happens when not running both programms but only node-client.js. You still get the ready print but no connected nodes.
Interesting idea, haven't done that, will take a look after some sleep :)
Sure, thank you.
I observer the same behavior with bittorrent-dht
:
(function(){
var DHT;
DHT = require('bittorrent-dht');
global.dht = new DHT({
nodes: [{
host: '127.0.0.1',
port: 16881
}]
});
global.dht.on("ready", () => {
console.log("i am ready");
});
}).call(this);
In fact, it seems to fire ready
whenever each bootstrap is processed. Processed means either success or failure, so if specified bootstrap node is not available, ready
event is fired too as there is nothing left to wait and waiting forever doesn't make much sense anyway.
Also note that if you try to interact with the network afterwards (like making a lookup) it should try specified bootstrap nodes again.
Not sure this is a perfect behavior, but it seems reasonable.
Great. Thank you very much for the explanation. Did you gather that information by reading the source code or did you use some kind of debugging tool? Just asking so I can hopefully answer those kind of questions by myself in the future :D
Both, but debugger is definitely very useful, this is how I use it:
1) Open Chromium
2) Go to chrome://inspect
3) Click Open dedicated DevTools for Node
4) node --inspect-brk demo/node-client.js
--inspect-brk
means it will wait for connection from debugger (Chromium in this case) and will pause on the first line of code, so you can press F8
(Linux) to run it. Whenever debugger
statement of other breakpoint is reached you'll be able to inspect local variables and stacktrace.
That seems like a very handy tool. Thank you very much again for the tips.
I am not sure if this intended so I am asking to clarify or correct my understanding:
According to https://github.com/webtorrent/bittorrent-dht#dhtonready-function---- the 'ready'-event is supposed to fire when a sufficient (I suppose >= 1) amount of bootstrap nodes are known and connected to the current node. If the bootstrap option is set to false the event is fired right away.
When running the demo code of this repo the ready event is fired even though no bootstrap node was found yet. Is this a bug or just me not understanding what is going on?