Discovery not working?
NodeGuy opened this issue · 3 comments
NodeGuy commented
I tried modifying the P2P example from issue #36 to make use of discovery:
index1.js
var th = require('telehash'),
fs = require('fs');
var ENDPOINT_FILE = process.env.ENDPOINT;
th.load({id:ENDPOINT_FILE}, function (e,mesh) {
if (e) throw e;
console.log(mesh.uri());
mesh.discover(true);
mesh.accept = function (from) {
console.log("INCOMING:", from.hashname);
var link = mesh.link(from),
chan = link.stream();
chan.write("Hello?");
var i = 0;
setInterval(function () {
chan.write("Test #"+(++i));
}, 5e3);
chan.on('data', function (d) {
console.log("DATA:", d.toString());
});
};
});
index2.js
var th = require('telehash'),
fs = require('fs');
var ENDPOINT_FILE = process.env.ENDPOINT;
th.load({id:ENDPOINT_FILE}, function (e,mesh) {
if (e) throw e;
console.log(mesh.uri());
mesh.discover(true);
mesh.accept = function (from) {
console.log("INCOMING:", from.hashname);
mesh.link(from);
};
mesh.stream(function (from, args, accept){
var chan = accept();
chan.on('data', function (d) {
d = d.toString();
console.log("ECHO:", d);
chan.write(d.toUpperCase());
});
});
});
Nothing happens, in particular no "INCOMING" messages are logged. Is there something I should be doing differently?
paralin commented
Yeah, same here. Any help?
rynomad commented
rynomad commented
thoroughly fixed and example added (./examples/echo) in 0.4.0
Note: due to async crypto and handshakes, must create stream INSIDE the link.status handler (i.e once handshaking has completed and the link is fully up).