telehash/telehash-js

Discovery not working?

NodeGuy opened this issue · 3 comments

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?

Yeah, same here. Any help?

Hey folks. sorry for the delay. I just pushed some commits to branch 0.3.30, though be warned I'm still in the process of tackling #37. Once I get the reconnect working smoothly I'll publish to npm but for now see if this helps:

npm install git+https://github.com/telehash/telehash-js#0.3.30

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).