Giter Club home page Giter Club logo

telehash-js's Introduction

Overview

Build Status

telehash

This module presents a simple high-level API for using telehash v3 for both node and browserify.

The browser crypto that powers this is only possible thanks to the incredible work done by the team behind Forge, Tom Wu, and the Sanford Javascript Crypto Library.

Router

Telehash apps usually need one or more mesh routers to assist in establishing p2p links. You can run your own router via npm start, manually via node bin/router.js, or just router if you did an npm install -g. The JSON object from the router output can be passed in to the mesh.link({...}) function (shown below) or stored in your own links.json locally.

Library Interface

Local Endpoint Identity Generation

To create a new hashname:

var th = require("telehash");
th.generate(function(err, endpoint){
  if(err) return console.log("endpoint generation failed",err);
  // endpoint contains a `keys:{}`, `secrets:{}`, and `hashname:"..."`
});

Mesh Creation

Needs an endpoint id object from a previously run generate() to initialize from:

var th = require("telehash");
var id = {"keys":{"1a":"akndnx5kbansip6xphxymwckpqkjj26fcm"},"secrets":{"1a":"ksxslm5mmtymnbph7nvxergb7oy3r35u"},"hashname":"5uegloufcyvnf34jausszmsabbfbcrg6fyxpcqzhddqxeefuapvq"};

var mesh = th.mesh({id:id});

A second argument can be passed and will be called after the mesh is fully initialized, and return any startup errors:

th.mesh({id:id}, function(err, mesh){
  if(err) return console.log("mesh failed to initialize",err);
  // use mesh.* now
  console.log(mesh.uri());
});

The args passed in to the mesh may include:

  • id - An endpoint id object previously generated
  • links - An object in the mesh json format that will be auto-loaded

In node, the id and links can be strings pointing to local filenames that will be auto-loaded. In the browser they can be string keys to localStorage. Those locations will also be generated and kept in sync for any changes.

Establishing Links

A link can be created with just a hashname (this requires a router to assist):

var link = mesh.link(hashname);
// will be called when link status changes, err is undefined when link is up
link.status(function(err){
  if(err) {
    console.log('disconnected',err);
    return;
  }
  console.log('connected');
  // can do any other link.* methods
});

A link can also be establish directly (no router required):

var link = mesh.link({keys:{},paths:{}});

The .link({args}) will also take an argument of "jwt":"..." to include a JWT in the link request for identifying/authorizing the sender.

Accepting/Authorizing Links

When an incoming link is requested the local app must decide if it accepts that link. By default all unknown links/senders are ignored and never responded to in order to protect the privacy of the recipient.

To process incoming link requests:

mesh.accept = function(from){};

The accept function will always be called with a from object that includes the hashname of the sender and any additional details about the request including keys, paths, and all handshake types received as hset.

To authorize/accept the request, simply perform a mesh.link(from) and it will respond and create the link.

Routing

By default every endpoint will assist with routing between any of the active links in its mesh in order to maximize connectivity, but this requires the routing endpoint to be connected to both which may not always be the case.

One or more links can be dedicated routers for all other link requests, and/or any link can be used as a router for another:

mesh.router(link); // any link can be used as a default router
mesh.link({...,router:true}); // another way to set a link as a default router from the start

link.router(link); // just one link can be used as a router for another
mesh.link({...,paths:[{type:'peer',hn:'linked'}]}); // including a peer path to an already-linked hashname will automatically use it as a router

Whenever a default router is added, it will also be advertised to other links as a peer path for this endpoint.

Discovery Mode

Discovery mode enables any network transport to send un-encrypted announcements to any other endpoints that are available locally only. This can be used to automatically establish a link to a local peer when there is no other mechanism to exchange keys, such as when they are offline.

It is important to note that this should be used sparingly, as anything on a local network will be made aware of the sending hashname. While this is generally very low risk, it should not be left on by default except in special cases.

mesh.discover(true); // to enable
mesh.discover(false); // to disable (default)

While discover is enabled, mesh.accept will be called for all discovered local endpoints.

Optional args and a callback (to know once discovery is enabled on all the transports) can be passed in:

mesh.discover({args},done);

The args can include:

  • jwt - a JWT to include in the announcement to help identify the sender
  • custom per-transport discovery options may be passed in

Extensions

Most functionality is added by extending the core library to support additional channels and expose more methods. The built-in extensions live in the ext folder, but additional ones can be added by the app.

  • path - check and synchronize all network paths on a link:
link.ping(function(err, latency){
  // error if it failed
  // latency is number of milliseconds if it succeeded (may be 0)
});
  • stream - native duplex Stream creation, also supports streaming objects
link.stream(); // returns a new duplex stream to this link, optional args are sent to the link during creation
fs.createReadStream(filein).pipe(link.stream()); // can be used as a pipe
// to receive incoming streams
mesh.stream(function(link, args, cbAccept){
  // link is who it came from
  // args is set if any were given by the sender
  // call cbAccept(err); to cancel
  // cbAccept() returns a duplex stream
  cbAccept().pipe(fs.createWriteStream(fileout));
});
  • chat - send and receive one-to-one or group chat messages

draft implementation, works but is minimal

// create or set args.id and args.leader to join a new chat
mesh.chat(args, profile, function(err, chat){
  chat.inbox; // incoming message stream
  chat.outbox; // stream to send messages
  chat.profiles; // hn->profile
  chat.messages; // cache/index by message id
  chat.log; // ordered known chat history ["id2", "id1", ...]
  chat.join(link); // leader can use to accept/invite others
});

// set handler for when invited to a chat
mesh.invited(function(link, profile){});

Extension Backing API

Extensions typically involve:

  • handling one or more channel types
  • adding one or more methods to a created mesh instance
  • adding one or more methods to every link instance within a mesh
  • providing a transport

Using an interface like:

var ext = require('ext');
ext.name; // unique string name for debugging
telehash.add(ext); // just does telehash.extensions[ext.name] = ext;
mesh.extend(ext,cb); // or per mesh, auto-run for all .extensions
// calls:
if(ext.mesh) ext.mesh(mesh, cb(err));
if(ext.link) ext.link(link, cb(err));

Transports

A mesh will use all available transports to establish and maintain a link.

Transport Backing API

All transports are implemented as an extension that exposes the functionality of:

  • turnin a path into a pipe, pipe has a path (if any)
  • incoming packets with a pipe
  • outgoing packets to a pipe
  • pipe event of keepalive, closed, and changed
  • return available source paths
  • enable discovery mode

Using an interface like:

var tpx = require('telehash-x');
// mesh.receive = function(packet,pipe){ };
tpx.mesh(mesh,function(err, tp){
  tp.pipe(path, function(pipe){
    pipe.path; // current json object (if addressable)
    pipe.on('keepalive', function(){}) // adds callback, return false to unregister, called on all events
    pipe.send(packet)
  });
  var paths = tp.paths(); // return array of current addressible paths, if any
  tp.discover({packet:packet}, cb); // enables/disables discovery mode, will create new pipes for incoming, cb when done
});

##Debugging

Telehash-js uses the 'debug' module for debug statements. to enable debugging of a particular code portion, set the DEBUG environment variable to a comma seperated list of module names.

~$ DEBUG=Link,Mesh node router.js

Available debug labels: -Link, class for mesh to mesh communication over best available connection -Pipe, class wrapper for single connections -Mesh, class for Telehash mesh nodes -Peer, peer routing channels -Path, path iscovery channels -Stream, streaming channels -Hanshake, incoming handshake processing -Receive, incoming packet processing

telehash-js's People

Contributors

dvanduzer avatar maurycyp avatar quartzjer avatar rynomad avatar s-k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

telehash-js's Issues

Stacktrace in log - 'send called w/ no packet, dropping Error'

Starting up today (with current version) I got this in the log

local path add {"type":"http","http":"http://10.2.2.83:42424"}
self http {"type":"http","http":"http://10.2.2.83:42424"}
adding new path 0 {"type":"http","http":"http://208.68.164.253:42424"}
ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 http {"type":"http","http":"http://208.68.164.253:42424"}
adding new path 1 {"type":"ipv4","ip":"208.68.164.253","port":42424}
ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 ipv4 {"type":"ipv4","ip":"208.68.164.253","port":42424}
adding new path 2 {"type":"ipv6","ip":"2605:da00:5222:5269:230:48ff:fe35:6572","port":42424}
ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 ipv6 {"type":"ipv6","ip":"2605:da00:5222:5269:230:48ff:fe35:6572","port":42424}
local path add {"type":"ipv4","ip":"10.2.2.83","port":42424}
self ipv4 {"type":"ipv4","ip":"10.2.2.83","port":42424}
local path add {"type":"ipv6","ip":"fe80::b6b6:76ff:fe86:67cb","port":42424}
self ipv6 {"type":"ipv6","ip":"fe80::b6b6:76ff:fe86:67cb","port":42424}
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 90 lan,,, undefined
LINKTRY ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
new unreliable channel ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 link 2
SEND link {"seed":true,"see":[],"bridges":[],"type":"link","c":2} undefined
alive failthrough undefined []
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 460 http,,, ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 2 ipv4,208.68.164.253,42424, undefined
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 460 ipv4,208.68.164.253,42424, ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 460 ipv6,2605:da00:5222:5269:230:48ff:fe35:6572,42424, ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
seek starting with [] 0
SEEK LOOP []
>>>> Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 90 88 ipv4,10.2.2.83,42424,
>>>> Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 90 88 ipv4,10.2.2.83,42424,
>>>> Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 90 88 ipv4,10.2.2.83,42424,
>>>> Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 460 1 ipv4,208.68.164.253,42424,
inOpen verified ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 undefined
alive failthrough 1402041397323 []
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 460 http,,, ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 460 ipv4,208.68.164.253,42424, ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 460 ipv6,2605:da00:5222:5269:230:48ff:fe35:6572,42424, ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 460 ipv4,208.68.164.253,42424, ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
new line e799463b6bb49a89876ccae77e0938b4 1e06274ed2506ed9d203837f6d626d28
>>>> Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 332 0 ipv4,208.68.164.253,42424,
LINEIN undefined {"paths":[{"type":"http","http":"http://208.68.164.253:42424"},{"type":"ipv4","ip":"208.68.164.253","port":42424},{"type":"ipv6","ip":"2605:da00:5222:5269:230:48ff:fe35:6572","port":42424},{"type":"ipv6","ip":"fe80::230:48ff:fe35:6572","port":42424}],"type":"path","c":61} 0
new unreliable channel ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 path 61
adding new path 3 {"type":"ipv6","ip":"fe80::230:48ff:fe35:6572","port":42424}
ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 ipv6 {"type":"ipv6","ip":"fe80::230:48ff:fe35:6572","port":42424}
SEND path {"path":{"type":"http","http":"http://208.68.164.253:42424"},"c":61} undefined
line sending ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 e799463b6bb49a89876ccae77e0938b4
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 128 http,,, ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
SEND path {"path":{"type":"ipv4","ip":"208.68.164.253","port":42424},"c":61} undefined
line sending ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 e799463b6bb49a89876ccae77e0938b4
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 126 ipv4,208.68.164.253,42424, ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
SEND path {"path":{"type":"ipv6","ip":"2605:da00:5222:5269:230:48ff:fe35:6572","port":42424},"c":61} undefined
line sending ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 e799463b6bb49a89876ccae77e0938b4
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 150 ipv6,2605:da00:5222:5269:230:48ff:fe35:6572,42424, ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
SEND path {"path":{"type":"ipv6","ip":"fe80::230:48ff:fe35:6572","port":42424},"c":61} undefined
line sending ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 e799463b6bb49a89876ccae77e0938b4
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 136 ipv6,fe80::230:48ff:fe35:6572,42424, ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
pathSync ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
new unreliable channel ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 path 4
SEND path {"type":"path","c":4} undefined
line sending ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 e799463b6bb49a89876ccae77e0938b4
<<<< Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 81 ipv4,208.68.164.253,42424, ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
>>>> Fri Jun 06 2014 09:56:37 GMT+0200 (SAST) 125 0 ipv4,208.68.164.253,42424,
LINEIN path {"path":{"type":"ipv4","ip":"105.236.57.244","port":42424},"c":4} 0
updating public ipv4 undefined {"type":"ipv4","ip":"105.236.57.244","port":42424}
local path add {"type":"ipv4","ip":"105.236.57.244","port":42424}
self ipv4 {"type":"ipv4","ip":"105.236.57.244","port":42424}
pathSync best ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 {"type":"ipv4","ip":"208.68.164.253","port":42424}
SEND link {"seed":true,"see":[],"bridges":[],"type":"link","c":2} undefined
line sending ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 e799463b6bb49a89876ccae77e0938b4
<<<< Fri Jun 06 2014 09:56:38 GMT+0200 (SAST) 115 ipv4,208.68.164.253,42424, ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
>>>> Fri Jun 06 2014 09:56:38 GMT+0200 (SAST) 302 0 ipv4,208.68.164.253,42424,
LINEIN link {"seed":true,"see":["7766e761afb226d7b398379ea1bf12c53dc02580c683b173568b0c6cc3a09c00,3a,105.236.57.244,42424","0ecedc9f49472737b9285c0e10066fd860983bb5aa3a04e1f0acc3d3b3c5e348,1a,105.236.57.244,46076"],"bridges":["http","ipv4","ipv6"],"c":2} 0
LINKUP ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949
adding new path 0 {"type":"ipv4","ip":"105.236.57.244","port":46076}
0ecedc9f49472737b9285c0e10066fd860983bb5aa3a04e1f0acc3d3b3c5e348 ipv4 {"type":"ipv4","ip":"105.236.57.244","port":46076}
LINKTRY 0ecedc9f49472737b9285c0e10066fd860983bb5aa3a04e1f0acc3d3b3c5e348
new unreliable channel 0ecedc9f49472737b9285c0e10066fd860983bb5aa3a04e1f0acc3d3b3c5e348 link 1
SEND link {"seed":true,"see":[""],"bridges":["ipv4"],"type":"link","c":1} undefined
alive failthrough undefined [ 'ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949' ]
send called w/ no packet, dropping Error
    at Object.self.send (/home/alanz/mysrc/github/telehash/node-telehash/node_modules/telehash-js/thjs.js:52:64)
    at /home/alanz/mysrc/github/telehash/node-telehash/node_modules/telehash-js/thjs.js:628:12
    at Array.forEach (native)
    at Object.hn.send (/home/alanz/mysrc/github/telehash/node-telehash/node_modules/telehash-js/thjs.js:627:14)
    at Object.chan.send (/home/alanz/mysrc/github/telehash/node-telehash/node_modules/telehash-js/thjs.js:1007:8)
    at Object.raw (/home/alanz/mysrc/github/telehash/node-telehash/node_modules/telehash-js/thjs.js:1029:10)
    at Object.hn.link (/home/alanz/mysrc/github/telehash/node-telehash/node_modules/telehash-js/thjs.js:759:20)
    at /home/alanz/mysrc/github/telehash/node-telehash/node_modules/telehash-js/thjs.js:1523:61
    at Array.forEach (native)
    at inLink (/home/alanz/mysrc/github/telehash/node-telehash/node_modules/telehash-js/thjs.js:1520:50)
new unreliable channel ce9d2cfccf34345b1c1a1c5b6c72cb0cf625ec88cdc64b54921303b26a655949 peer 6
SEND peer {"peer":"0ecedc9f49472737b9285c0e10066fd860983bb5aa3a04e1f0acc3d3b3c5e348","paths":[{"type":"ipv4","ip":"105.236.57.244","port"

Question about browser implementation.

I have browserfied the source, but I am having trouble getting computers to link to one another. Do you need to have more than one encryption type enabled? Though it is noted that cs2a is supported in the browser, it seemed like having it in the browserfied js was causing an issues, so I took it out.

Provide example for telehash-http

Could you please provide example of using telehash-http transport to create a link between two meshes?
API is a bit tricky, it's not very clear when we should bind the http-server and how to use http-client to connect to it.
Thanks.

Over usage examples (udp, tcp) would be also super-helpful.

Discovery not working?

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?

telehash and bluetooth

I am planning to use telehash to mesh a bunch of devices that uses Bluetooth (not LE) as its physical link and establish links and pass messages between them. Could I get some guidance on what I will need to do for discovering nodes. If I cannot use uriBeacon, what is the alternative?

Thanks,
Sunil

Do not add transports to default extensions

By running this simple mesh node creates 3 listening sockets: two for TCP and one for UDP:

var th = require("telehash");

th.generate(function(err, id) {
  th.mesh({id: id}, function(err, mesh) {
    console.log(mesh);
  });
});

That's because of the transport extensions added by default on module load.

I could unload them by calling:

delete th.extensions.udp4;
delete th.extensions.tcp4;
delete th.extensions.http;

but it looks ugly as for me. (Also little bug: extensions should be an object.)
Should it be the option to disable default extensions without manually removing them?

Receiving on stream

I have two code snippets below. 1.js accepts the stream from 2.js, and outputs the message written to it by 2. 1 tries to send a message to 2 as well, but for some reason this is failing. Eyeballing this against the echo.js example, I have no clue what I'm missing. I suspect it has to do with the fact that it is the client that created the stream. I tried adding a stream handler to 2.js but this didn't resolve the problem. I'm guessing I'm probably making a small error somewhere but it's escaping me.

1.js

th.load({id: id}, function(e, mesh) {
  mesh.discover(true);
  mesh.accept = function(from) {
    mesh.link(from);
    console.log("INCOMING:", from.hashname);
  };

  mesh.stream(function(link, args, accept) {
    console.log("INCOMING STREAM");
    var chan = accept();

    chan.on('data', function(d) {
      try {
        var msg = JSON.parse(d);
      } catch (e) {
        return console.log('Error parsing', d);
      }
      console.log("MSG", msg);
    });

    chan.write(JSON.stringify({a: "reply"}));
  });
});

2.js

mesh({id: id}, function(e, mesh) {
  mesh.discover(true);
  mesh.accept = function(from) {
    console.log('mesh.accept');
    var link = mesh.link(from);
    var chan = link.stream();

    chan.on('data', function(d) {
      console.log('data?');
      console.log(d.toString());
    });

    chan.write(JSON.stringify({}));
  };
});

echo example - recovery from failure

I have a question about recovery from tcp socket errors. Using the echo example, run client.js and server.js.

If you abruptly restart client.js, server.js is able to recover from and a new stream is created. But, if you restart server.js, no new stream is ever created, despite client reconnecting.

I'm unclear on why they behave differently. I suspect that in client.js, that the link.stream() breaks once server restarts, and for some reason a new link status event isn't emitted. So no new link.stream() call occurs.

What changes would need to be made to the code to have both client and server able to recover from a restart?

Uncaught TypeError on browserified telehash.generate()

Hi,

I've been trying to get telehash-js to work in the browser without success.
After browserifying the source and running the example, I get the following error on telehash.generate():

TypeError: sodium.crypto_box_keypair is not a function
in bundle.js:32074

Of course I don't have any problem running this in node. This might be me missing something, but I've been stuck for a few days so I figured I might ask.

Thank you for your great work! it's very exciting stuff.

while-loop prevents extensions from loading

The below code executes fine if you comment out the while/if statements. But, execute it as is and Mesh never executes its callback. Tracing this back through the library, it appears that this is because some of the extensions do not fully initialize. In the case of UDP, I observed that it never executes cbExt, because its socket.bind never executes its callback. I suspect that something similar is also happening with the other socket-binding libraries but I haven't dug into it.

var i = 100;
var mesh = {};
var link = {};
var chan = {};
var lock = false;

while (i > 0) {
  if (!lock) {
    lock = true;
    console.log('mesh', (1001 - i))
    Mesh({id: id}, function(e, _mesh) {
      if(e) return console.log("mesh failed to initialize",e);
      mesh = _mesh;
      mesh.discover(true);
      mesh.accept = function(from) {
        console.log('mesh.accept');
        link = mesh.link(from);
        link.on('status', function() {
          chan = link.stream();
          chan.on('data', function(d) {
            console.log('INCOMING', d.toString());
            disconnect();
            i -= 1;
            lock = false;
          });
          chan.write('fubar');
        });
      }
    });
  }
}

dedup is not defined

When peers link though a router, the router will crash:

ReferenceError: dedup is not defined
    at Object.receive_channel [as channel] (/Users/yangzhang/Projects/test-telehash/node_modules/telehash/lib/util/receive.js:50:10)
    at Mesh_receive [as receive] (/Users/yangzhang/Projects/test-telehash/node_modules/telehash/lib/mesh.class.js:265:20)
    at /Users/yangzhang/Projects/test-telehash/node_modules/telehash/node_modules/telehash-udp4/index.js:35:12
    at Object.tp.pipe (/Users/yangzhang/Projects/test-telehash/node_modules/telehash/node_modules/telehash-udp4/index.js:52:21)
    at Socket.receive (/Users/yangzhang/Projects/test-telehash/node_modules/telehash/node_modules/telehash-udp4/index.js:34:8)
    at Socket.emit (events.js:110:17)
    at UDP.onMessage (dgram.js:472:8)

Issue running on ubuntu

Hi
So I had problems getting libSodium to work as it kept throwing
error while loading shared libraries: libsodium.so.4 when I tried to run seed.js

I eventually worked around this by doing a separate sodium standard build that put the file into /usr/local/lib

But now I am recieving
CS3a failed to load { [Error: Cannot find module './tobuffer'] code: 'MODULE_NOT_FOUND' }

Is there a file missing from the CS3a module?

Thanks

P2P example for README?

I've gotten a bit stuck following the current README.

  1. I generated an endpoint ("id") to play with, storing it to a file for reuse
  2. I've instantiated a mesh and am logging it's link URI thing as the documentation does
  3. (I've also found the currently-undocumented telehash.load helper that does the above for me)
  4. Now what?

The documentation says I need a "router to assist" if I want to connect to a hashname.

I remembered that v2 used seeds and whatnot, but I don't see https://github.com/quartzjer/telehash-seeds/ as a dependency and passing that to telehash.load({id:"endpoint.json", links:"seeds.json"}) doesn't work as the links wants a CommonJS module rather than JSON [for starters]. I also see some hints that Telehash might be doing private meshes by default now, and/or that it's using blockname for DHT perhaps instead of seeds — but blockname's documentation makes it sound like it's a way to store backup DNS A records in Bitcoin so I'm a little lost down this path. What is a router, and do I need a Bitcoin wallet/client/??? to use Telehash in this way, but what does backup IPv4 host mappings have to do with Telehash hashnames and/or keys…?

Backing up to this README again, it looks like the other alternative is that I can connect directly, if I have endpoint/id-reminiscent information. Not sure about "paths" here though… I've already logged this URI thing as the first/only thing after instantiating(/starting?) my own mesh, so it seems important, but gets no further mention in the docs here. I guess I need the public keys from the file generated in step 1 above, and maybe the URI for paths? But paths is an {} instead of a [] so I'm not sure how I should pass it based on the docs.


This is as far as I've got today; and I'm guessing as I continue to UTSL in conjunction with the spec, things will gradually become clearer. But, while they were fresh, I wanted to document some things that were confusing to me and have slowed me down trying to play.

At this point, what I think would be helpful is if:

  • the telehash.org page had a "getting started" link — perhaps I just did the wrong thing by using telehash-js and one of the other implementations is a better place to start? But telehash-js looked fairly recently updated and I've been doing a lot of node.js stuff lately, so it seemed a reasonable place to start
  • this repo (if it is a good place to start) had a bit more fleshed out documentation, especially going to the point where a connection is made. I just checked and see now there is an examples directory, but the one example it has does a "same-process only" meshA.mesh(meshB) thing — at this point I have only a tentative understanding of what a Telehash mesh is in the abstract, or how its been encapsulated in this JS object I know have.
  • there were something of a standard Telehash "blinky" or "Hello, World" kick-the-tires tutorial milestone, in common across projects and maybe even featured prominently on the homepage. I really didn't have clear goal (beyond understanding this system better) when setting down to do this; I guess I was hoping to get some sort of tracer bullet "send over here, some evidence of its receipt happens" type communications working. Is there a public "echo server" or "numbers station" somewhere, that I should aiming to access as a first step? Or should I be trying to connect two of my own processes together? Will that work regardless of where in the world each bit of telehash app code is, or does it need to be on the same LAN [the link:// URL contains only a network ip address] or what?

In short, how do I get to a point where I know Telehash is "working", and then what are my options for remixing things from that point?

e3x native build problems, with fix to fall back to js-nacl (pure JS sodium)

using node v0.12.2
i encountered build problems such as:

/home/me/.node-gyp/0.12.2/deps/v8/include/v8.h:2114:8: note:   candidate expects 2 arguments, 3 provided
../sodium.cc:1257:71: error: no matching function for call to 'v8::Object::Set(NanIntern::FactoryBase<v8::String>::return_t, NanIntern::IntegerFactory<v8::Integer>::return_t, v8::PropertyAttribute)'
     target->Set(NanNew<String>(#NAME), NanNew<Integer>(NAME), ReadOnly)

after some modifications i was able to get my telehash example to run without errors (but didn't actually test its operation). it involved modifications in both telehash-js and c3x and i'm not sure exactly why this works but jer probably will:

in package.json i use:

        "e3x-cs3a": "latest",
        "telehash": "telehash/telehash-js"

in e3x-cs3a/node.js

exports = module.exports = require('./cs3a.js'); // load common module

// try compiled sodium, fall back to pure js one
try{
  if(process.env.PURE == 'true') throw new Error("pure requested");
  var sodium = require("sodium").api;
  exports.crypt(sodium);
}catch(E){
  console.warn("Native CS3a unavailable, using 'js-nacl'.");
  var nacl_factory = require("js-nacl");
  exports.crypt( nacl_factory.instantiate() );
}

in telehash/lib/mesh.js in generate()

...
    for (var csid in pairs) {
      var pair = pairs[csid];
      if (pair.key && pair.secret) { //not sure why but one of the pairs ends up nullish
          id.keys[csid] = base32.encode(pairs[csid].key);     
          id.secrets[csid] = base32.encode(pairs[csid].secret);
      }
    }
...

i think these are all the modifications i needed but i'm not sure if theyre correct

ws error: RangeError: out of range index

Windows 10, node v6.5.0, npm 3.10.5
The app is crashing in random times with this error:

Project\node_modules\telehash\node_modules\telehash-http\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws\l
ib\Receiver.js:323
    default: srcBuffer.copy(dstBuffer, dstOffset, 0, length); break;
                       ^

RangeError: out of range index
    at RangeError (native)
    at fastCopy (Project\node_modules\telehash\node_modules\telehash-http\node_modules\socket.io-client\node_modules\engine.io-client\
node_modules\ws\lib\Receiver.js:323:24)
    at Receiver.add (Project\node_modules\telehash\node_modules\telehash-http\node_modules\socket.io-client\node_modules\engine.io-cli
ent\node_modules\ws\lib\Receiver.js:84:3)
    at Socket.firstHandler (Project\node_modules\telehash\node_modules\telehash-http\node_modules\socket.io-client\node_modules\engine
.io-client\node_modules\ws\lib\WebSocket.js:678:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:543:20)

Chrome App

Build/use transport libs to take advantage of chrome native networks

Nodejs 5.X support

Install error log:

WARN engine [email protected]: wanted: {"node":"0.10.x","npm":">1.2.x"} (current: {"node":"5.1.1","npm":"3.5.1"})
WARN engine [email protected]: wanted: {"node":"0.10.x","npm":">1.2.x"} (current: {
> [email protected] install /home/simon/projects/node-magi-network/node_modules/ecc
> node-gyp rebuild

make: Entering directory '/home/simon/projects/node-magi-network/node_modules/ecc/build'
  CXX(target) Release/obj.target/native/src/main.o
In file included from ../src/main.cc:2:0:
../../nan/nan.h:324:27: error: redefinition of ‘template<class T> v8::Local<T> Nan::imp::NanEnsureHandleOrPersistent(const v8::Local<T>&)’
   NAN_INLINE v8::Local<T> NanEnsureHandleOrPersistent(const v8::Local<T> &val) 
                           ^
../../nan/nan.h:319:17: note: ‘template<class T> v8::Handle<T> Nan::imp::NanEnsureHandleOrPersistent(v8::Handle<T>&)’ previously declared here
   v8::Handle<T> NanEnsureHandleOrPersistent(const v8::Handle<T> &val) {
                 ^
../../nan/nan.h:344:27: error: redefinition of ‘template<class T> v8::Local<T> Nan::imp::NanEnsureLocal(v8::Handle<T>&)’
   NAN_INLINE v8::Local<T> NanEnsureLocal(const v8::Handle<T> &val) {
                           ^
../../nan/nan.h:334:27: note: ‘template<class T> v8::Local<T> Nan::imp::NanEnsureLocal(const v8::Local<T>&)’ previously declared here
   NAN_INLINE v8::Local<T> NanEnsureLocal(const v8::Local<T> &val) {
                           ^
../../nan/nan.h:757:13: error: ‘node::smalloc’ has not been declared
     , node::smalloc::FreeCallback callback
             ^
../../nan/nan.h:757:35: error: expected ‘,’ or ‘...’ before ‘callback’
     , node::smalloc::FreeCallback callback
                                   ^
../../nan/nan.h: In function ‘v8::Local<v8::Object> NanNewBufferHandle(char*, size_t, int)’:
../../nan/nan.h:761:50: error: ‘callback’ was not declared in this scope
         v8::Isolate::GetCurrent(), data, length, callback, hint);
                                                  ^
../../nan/nan.h:761:60: error: ‘hint’ was not declared in this scope
         v8::Isolate::GetCurrent(), data, length, callback, hint);
                                                            ^
../../nan/nan.h: In function ‘v8::Local<v8::Object> NanNewBufferHandle(const char*, uint32_t)’:
../../nan/nan.h:768:67: error: no matching function for call to ‘New(v8::Isolate*, const char*&, uint32_t&)’
     return node::Buffer::New(v8::Isolate::GetCurrent(), data, size);
                                                                   ^
In file included from ../../nan/nan.h:25:0,
                 from ../src/main.cc:2:
/home/simon/.node-gyp/5.1.1/include/node/node_buffer.h:31:40: note: candidate: v8::MaybeLocal<v8::Object> node::Buffer::New(v8::Isolate*, v8::Local<v8::String>, node::encoding) <near match>
 NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
                                        ^
/home/simon/.node-gyp/5.1.1/include/node/node_buffer.h:31:40: note:   conversion of argument 3 would be ill-formed:
In file included from ../src/main.cc:2:0:
../../nan/nan.h:768:67: error: invalid conversion from ‘uint32_t {aka unsigned int}’ to ‘node::encoding’ [-fpermissive]
     return node::Buffer::New(v8::Isolate::GetCurrent(), data, size);
                                                                   ^
In file included from ../../nan/nan.h:25:0,
                 from ../src/main.cc:2:
/home/simon/.node-gyp/5.1.1/include/node/node_buffer.h:43:40: note: candidate: v8::MaybeLocal<v8::Object> node::Buffer::New(v8::Isolate*, char*, size_t) <near match>
 NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
                                        ^
/home/simon/.node-gyp/5.1.1/include/node/node_buffer.h:43:40: note:   conversion of argument 2 would be ill-formed:
In file included from ../src/main.cc:2:0:
../../nan/nan.h:768:67: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
     return node::Buffer::New(v8::Isolate::GetCurrent(), data, size);
                                                                   ^
../../nan/nan.h: In function ‘v8::Local<v8::Object> NanNewBufferHandle(uint32_t)’:
../../nan/nan.h:772:29: error: could not convert ‘node::Buffer::New(v8::Isolate::GetCurrent(), ((size_t)size))’ from ‘v8::MaybeLocal<v8::Object>’ to ‘v8::Local<v8::Object>’
     return node::Buffer::New(v8::Isolate::GetCurrent(), size);
                             ^
../../nan/nan.h: In function ‘v8::Local<v8::Object> NanBufferUse(char*, uint32_t)’:
../../nan/nan.h:779:12: error: ‘Use’ is not a member of ‘node::Buffer’
     return node::Buffer::Use(v8::Isolate::GetCurrent(), data, size);
            ^
native.target.mk:91: recipe for target 'Release/obj.target/native/src/main.o' failed
make: *** [Release/obj.target/native/src/main.o] Error 1
make: Leaving directory '/home/simon/projects/node-magi-network/node_modules/ecc/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 4.2.5-1-ARCH
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/simon/projects/node-magi-network/node_modules/ecc
gyp ERR! node -v v5.1.1
gyp ERR! node-gyp -v v3.2.0
gyp ERR! not ok 
npm WARN install:[email protected] [email protected] install: `node-gyp rebuild`
npm WARN install:[email protected] Exit status 1

> [email protected] install /home/simon/projects/node-magi-network/node_modules/ecc-qj
> node-gyp rebuild

make: Entering directory '/home/simon/projects/node-magi-network/node_modules/ecc-qj/build'
  CXX(target) Release/obj.target/native/src/main.o
In file included from ../src/main.cc:2:0:
../../nan/nan.h:324:27: error: redefinition of ‘template<class T> v8::Local<T> Nan::imp::NanEnsureHandleOrPersistent(const v8::Local<T>&)’
   NAN_INLINE v8::Local<T> NanEnsureHandleOrPersistent(const v8::Local<T> &val) 
                           ^
../../nan/nan.h:319:17: note: ‘template<class T> v8::Handle<T> Nan::imp::NanEnsureHandleOrPersistent(v8::Handle<T>&)’ previously declared here
   v8::Handle<T> NanEnsureHandleOrPersistent(const v8::Handle<T> &val) {
                 ^
../../nan/nan.h:344:27: error: redefinition of ‘template<class T> v8::Local<T> Nan::imp::NanEnsureLocal(v8::Handle<T>&)’
   NAN_INLINE v8::Local<T> NanEnsureLocal(const v8::Handle<T> &val) {
                           ^
../../nan/nan.h:334:27: note: ‘template<class T> v8::Local<T> Nan::imp::NanEnsureLocal(const v8::Local<T>&)’ previously declared here
   NAN_INLINE v8::Local<T> NanEnsureLocal(const v8::Local<T> &val) {
                           ^
../../nan/nan.h:757:13: error: ‘node::smalloc’ has not been declared
     , node::smalloc::FreeCallback callback
             ^
../../nan/nan.h:757:35: error: expected ‘,’ or ‘...’ before ‘callback’
     , node::smalloc::FreeCallback callback
                                   ^
../../nan/nan.h: In function ‘v8::Local<v8::Object> NanNewBufferHandle(char*, size_t, int)’:
../../nan/nan.h:761:50: error: ‘callback’ was not declared in this scope
         v8::Isolate::GetCurrent(), data, length, callback, hint);
                                                  ^
../../nan/nan.h:761:60: error: ‘hint’ was not declared in this scope
         v8::Isolate::GetCurrent(), data, length, callback, hint);
                                                            ^
../../nan/nan.h: In function ‘v8::Local<v8::Object> NanNewBufferHandle(const char*, uint32_t)’:
../../nan/nan.h:768:67: error: no matching function for call to ‘New(v8::Isolate*, const char*&, uint32_t&)’
     return node::Buffer::New(v8::Isolate::GetCurrent(), data, size);
                                                                   ^
In file included from ../../nan/nan.h:25:0,
                 from ../src/main.cc:2:
/home/simon/.node-gyp/5.1.1/include/node/node_buffer.h:31:40: note: candidate: v8::MaybeLocal<v8::Object> node::Buffer::New(v8::Isolate*, v8::Local<v8::String>, node::encoding) <near match>
 NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
                                        ^
/home/simon/.node-gyp/5.1.1/include/node/node_buffer.h:31:40: note:   conversion of argument 3 would be ill-formed:
In file included from ../src/main.cc:2:0:
../../nan/nan.h:768:67: error: invalid conversion from ‘uint32_t {aka unsigned int}’ to ‘node::encoding’ [-fpermissive]
     return node::Buffer::New(v8::Isolate::GetCurrent(), data, size);
                                                                   ^
In file included from ../../nan/nan.h:25:0,
                 from ../src/main.cc:2:
/home/simon/.node-gyp/5.1.1/include/node/node_buffer.h:43:40: note: candidate: v8::MaybeLocal<v8::Object> node::Buffer::New(v8::Isolate*, char*, size_t) <near match>
 NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
                                        ^
/home/simon/.node-gyp/5.1.1/include/node/node_buffer.h:43:40: note:   conversion of argument 2 would be ill-formed:
In file included from ../src/main.cc:2:0:
../../nan/nan.h:768:67: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
     return node::Buffer::New(v8::Isolate::GetCurrent(), data, size);
                                                                   ^
../../nan/nan.h: In function ‘v8::Local<v8::Object> NanNewBufferHandle(uint32_t)’:
../../nan/nan.h:772:29: error: could not convert ‘node::Buffer::New(v8::Isolate::GetCurrent(), ((size_t)size))’ from ‘v8::MaybeLocal<v8::Object>’ to ‘v8::Local<v8::Object>’
     return node::Buffer::New(v8::Isolate::GetCurrent(), size);
                             ^
../../nan/nan.h: In function ‘v8::Local<v8::Object> NanBufferUse(char*, uint32_t)’:
../../nan/nan.h:779:12: error: ‘Use’ is not a member of ‘node::Buffer’
     return node::Buffer::Use(v8::Isolate::GetCurrent(), data, size);
            ^
native.target.mk:91: recipe for target 'Release/obj.target/native/src/main.o' failed
make: *** [Release/obj.target/native/src/main.o] Error 1
make: Leaving directory '/home/simon/projects/node-magi-network/node_modules/ecc-qj/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 4.2.5-1-ARCH
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/simon/projects/node-magi-network/node_modules/ecc-qj
gyp ERR! node -v v5.1.1
gyp ERR! node-gyp -v v3.2.0
gyp ERR! not ok 
npm WARN install:[email protected] [email protected] install: `node-gyp rebuild`
npm WARN install:[email protected] Exit status 1

> [email protected] install /home/simon/projects/node-magi-network/node_modules/subtle
> ./install.sh



> [email protected] install /home/simon/projects/node-magi-network/node_modules/subtle/node_modules/ecc-qj
> node-gyp rebuild

make: Entering directory '/home/simon/projects/node-magi-network/node_modules/subtle/node_modules/ecc-qj/build'
  CXX(target) Release/obj.target/native/src/main.o
In file included from ../src/main.cc:2:0:
../../nan/nan.h:324:27: error: redefinition of ‘template<class T> v8::Local<T> Nan::imp::NanEnsureHandleOrPersistent(const v8::Local<T>&)’
   NAN_INLINE v8::Local<T> NanEnsureHandleOrPersistent(const v8::Local<T> &val) 
                           ^
../../nan/nan.h:319:17: note: ‘template<class T> v8::Handle<T> Nan::imp::NanEnsureHandleOrPersistent(v8::Handle<T>&)’ previously declared here
   v8::Handle<T> NanEnsureHandleOrPersistent(const v8::Handle<T> &val) {
                 ^
../../nan/nan.h:344:27: error: redefinition of ‘template<class T> v8::Local<T> Nan::imp::NanEnsureLocal(v8::Handle<T>&)’
   NAN_INLINE v8::Local<T> NanEnsureLocal(const v8::Handle<T> &val) {
                           ^
../../nan/nan.h:334:27: note: ‘template<class T> v8::Local<T> Nan::imp::NanEnsureLocal(const v8::Local<T>&)’ previously declared here
   NAN_INLINE v8::Local<T> NanEnsureLocal(const v8::Local<T> &val) {
                           ^
../../nan/nan.h:757:13: error: ‘node::smalloc’ has not been declared
     , node::smalloc::FreeCallback callback
             ^
../../nan/nan.h:757:35: error: expected ‘,’ or ‘...’ before ‘callback’
     , node::smalloc::FreeCallback callback
                                   ^
../../nan/nan.h: In function ‘v8::Local<v8::Object> NanNewBufferHandle(char*, size_t, int)’:
../../nan/nan.h:761:50: error: ‘callback’ was not declared in this scope
         v8::Isolate::GetCurrent(), data, length, callback, hint);
                                                  ^
../../nan/nan.h:761:60: error: ‘hint’ was not declared in this scope
         v8::Isolate::GetCurrent(), data, length, callback, hint);
                                                            ^
../../nan/nan.h: In function ‘v8::Local<v8::Object> NanNewBufferHandle(const char*, uint32_t)’:
../../nan/nan.h:768:67: error: no matching function for call to ‘New(v8::Isolate*, const char*&, uint32_t&)’
     return node::Buffer::New(v8::Isolate::GetCurrent(), data, size);
                                                                   ^
In file included from ../../nan/nan.h:25:0,
                 from ../src/main.cc:2:
/home/simon/.node-gyp/5.1.1/include/node/node_buffer.h:31:40: note: candidate: v8::MaybeLocal<v8::Object> node::Buffer::New(v8::Isolate*, v8::Local<v8::String>, node::encoding) <near match>
 NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
                                        ^
/home/simon/.node-gyp/5.1.1/include/node/node_buffer.h:31:40: note:   conversion of argument 3 would be ill-formed:
In file included from ../src/main.cc:2:0:
../../nan/nan.h:768:67: error: invalid conversion from ‘uint32_t {aka unsigned int}’ to ‘node::encoding’ [-fpermissive]
     return node::Buffer::New(v8::Isolate::GetCurrent(), data, size);
                                                                   ^
In file included from ../../nan/nan.h:25:0,
                 from ../src/main.cc:2:
/home/simon/.node-gyp/5.1.1/include/node/node_buffer.h:43:40: note: candidate: v8::MaybeLocal<v8::Object> node::Buffer::New(v8::Isolate*, char*, size_t) <near match>
 NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
                                        ^
/home/simon/.node-gyp/5.1.1/include/node/node_buffer.h:43:40: note:   conversion of argument 2 would be ill-formed:
In file included from ../src/main.cc:2:0:
../../nan/nan.h:768:67: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
     return node::Buffer::New(v8::Isolate::GetCurrent(), data, size);
                                                                   ^
../../nan/nan.h: In function ‘v8::Local<v8::Object> NanNewBufferHandle(uint32_t)’:
../../nan/nan.h:772:29: error: could not convert ‘node::Buffer::New(v8::Isolate::GetCurrent(), ((size_t)size))’ from ‘v8::MaybeLocal<v8::Object>’ to ‘v8::Local<v8::Object>’
     return node::Buffer::New(v8::Isolate::GetCurrent(), size);
                             ^
../../nan/nan.h: In function ‘v8::Local<v8::Object> NanBufferUse(char*, uint32_t)’:
../../nan/nan.h:779:12: error: ‘Use’ is not a member of ‘node::Buffer’
     return node::Buffer::Use(v8::Isolate::GetCurrent(), data, size);
            ^
native.target.mk:91: recipe for target 'Release/obj.target/native/src/main.o' failed
make: *** [Release/obj.target/native/src/main.o] Error 1
make: Leaving directory '/home/simon/projects/node-magi-network/node_modules/subtle/node_modules/ecc-qj/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 4.2.5-1-ARCH
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/simon/projects/node-magi-network/node_modules/subtle/node_modules/ecc-qj
gyp ERR! node -v v5.1.1
gyp ERR! node-gyp -v v3.2.0
gyp ERR! not ok 
[email protected] /home/simon/projects/node-magi-network/node_modules/subtle
└─┬ [email protected]
  └── [email protected]  (git+https://github.com/rynomad/jsbn.git#bb522b0124f75424f89d49446c40a87111942c7b)

npm WARN [email protected] No repository field.
npm ERR! Linux 4.2.5-1-ARCH
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "git+https://github.com/rynomad/ecc.git"
npm ERR! node v5.1.1
npm ERR! npm  v3.5.1
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ecc-qj package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs ecc-qj
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls ecc-qj
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/simon/projects/node-magi-network/node_modules/subtle/npm-debug.log
[email protected] /home/simon/projects/node-magi-network
├── [email protected]  extraneous
└── [email protected]  extraneous

npm ERR! Linux 4.2.5-1-ARCH
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "--save" "telehash"
npm ERR! node v5.1.1
npm ERR! npm  v3.5.1
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `./install.sh`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script './install.sh'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the subtle package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     ./install.sh
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs subtle
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls subtle
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/simon/projects/node-magi-network/npm-debug.log

Bad line packet received - hex dump

Here is some hex logging of the bad line packet

The first one is the wire packet, the second is immediately after delineize, and logs the line id followd by packet length and hex dump of packet. It is obvious that the length is wrong

07:57:38:>>>>:recvTelex:208.68.164.253:42424 (460) 00013a6fb5bc1b0312e8d8715f3959720b68efd941ec5f9d8e1090f775ebd4c4d9804d4f648ac46ecbb8605a020a250ebd38275fe9c31f6498d1cdd349ebf9c932af6b993ab852b453b8174eb552fea3e2505b2f4f619a37db796695ca22d802a3e978b0e02d811a1c9fd5483f343b7cb0b8e0ff06d72f84039384b66c4b680aba6992dca6834a6db688c882f0c830c6ee1c1838b4407eadb5631cb239ff93d282e3ba099396ea657f519b2ef103dd7d647fcc72b548f9af27f4dd029b0553e140d6a44db8a63e3e422a6c0e72b37886b896326611a050a7a8fbed607fae16595705be849e28966f6672130308a7452b312ed01e08de7cca710cfb23dc6bf04babab15170941383f412bc432b463204be8eaeff2d0dfa85c4149888692425504515629c7ed95901d07d8edba0cbe1d6789f6a060731502ff8f557c878fe9e8d0086fc813ed5188321fc16051fde50bc6645d091332f33efb828960d476f02987dca6ff1410ae821f3fba939b70521bc324abd89945efb9003cd7283bda1535472a92ebc7f458ad5e4a0e839768e98ac1212ca0e4db6453279001e4ff713964f4b64f69938c5236f11cd76bd3475eda215c2fba1077a1ca85c71a803e9f322766159274e06b9d7c6aba545971
07:57:38:>>>>:crypt_deopenize_1a:inner 31e463916f3012a0a5016a2bc6f2c391 (413) 6c3258f8cc77b7f6e7eaf963b02b2121fb9a7eec724160b3a20450c90b4bd195742bc892b6793876583b0ee51a254f7955eebd14180f44290700ae5cdec67626931c8c947d252e627ce84a130adf753cabcb33f05a72e43b26930a960a47fcc9adea862a5af26bd2f15c81e4a3c33b910dd15b2435d6c14bfdfe42c72e93078b78a2386cd61414744a8a3264b4aacea222af54d698b5e5f7e74c2c0476882f30173103fcbd2817467ddbdc7f20ae1f40b91c949a19f036d6135f4f1b4ccaf73c54de5c329510df2034a1a8b02b904f0ba8672fd8ef2024b2e6083e37821075d16371fe02622405e382352e9167c81ffcbaba2586b83006dba9a8f8aec8c660ca194c1976613c6565248bac3b3c41df2e3ed2e2715faa4f901514bf92bf2d314bedd1abfb41ed46b5f4891dd0a7ee22892b55337ac6d5d6eee4883a4cbb258924399683cbb0e7e6a7bdf18bd70f50748994b6db0f52ba1b25328e2faa5c7db7c080124dd9dc4e0831c6574ede3bc9971557ff0b4bc1daa421b7d5d0c64579e2951c541934363c60e32ab0462e30de4d396ea6f01a62686e1c5307e7feb2
*** Exception: Data.Binary.Get.runGet at position 413: demandInput: not enough bytes

NAT Traversal

Hi,

I found your library while searching Google about NAT Traversal.
I need a Nodejs Library for NAT Traversal.

I could not find any documentation about NAT Traversal for Telehash.
Can I use your library for this purpose?
Thanks in advance.

Not able to install from npm

npm install telehash
npm WARN package.json [email protected] No repository field.
npm http GET https://registry.npmjs.org/telehash
npm http 304 https://registry.npmjs.org/telehash
npm http GET https://registry.npmjs.org/telehash/-/telehash-0.1.14.tgz
npm http 404 https://registry.npmjs.org/telehash/-/telehash-0.1.14.tgz
npm ERR! fetch failed https://registry.npmjs.org/telehash/-/telehash-0.1.14.tgz
npm ERR! Error: 404 Not Found
npm ERR! at WriteStream. (/usr/local/lib/node_modules/npm/lib/utils/fetch.js:57:12)
npm ERR! at WriteStream.EventEmitter.emit (events.js:117:20)
npm ERR! at fs.js:1596:14
npm ERR! at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:103:5
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this entire log,
npm ERR! including the npm and node versions, at:
npm ERR! http://github.com/isaacs/npm/issues

npm ERR! System Darwin 13.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "telehash"
npm ERR! cwd /Users/jibyjose/WorkSpace/Cryptocowd
npm ERR! node -v v0.10.23
npm ERR! npm -v 1.3.17
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/jibyjose/WorkSpace/Cryptocowd/npm-debug.log
npm ERR! not ok code 0

Stream.js example doesn't work?

If I try the example after cloning the source from Github, it works. If I try it from an npm install telehash then I get the following error:

bash-3.2$ node stream.js 
[Error: invalid public key data]
[Error: invalid public key data]

/Users/david/Documents/Toptal/clients/Eris-Industries/worker-hello-world/node_modules/telehash/examples/stream.js:9
meshA.mesh(meshB);
      ^
TypeError: Cannot call method 'mesh' of undefined
    at Object.<anonymous> (/Users/david/Documents/Toptal/clients/Eris-Industries/worker-hello-world/node_modules/telehash/examples/stream.js:9:7)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3

sug.bucket death

Got this crash tonight while running some tests to my remote server.

N.B. This was during the meetup http://www.meetup.com/SolidStateDepot/events/154226712/ so all bets may be off.

/root/services/node-telehash/node_modules/thjs/thjs.js:266
          if(self.capacity[sug.bucket]-- >= 0) ping(sug);
                          ^
TypeError: Cannot read property '252' of undefined
    at /root/services/node-telehash/node_modules/thjs/thjs.js:266:27
    at Array.forEach (native)
    at Object.callback (/root/services/node-telehash/node_modules/thjs/thjs.js:259:23)
    at Object.chan.receive (/root/services/node-telehash/node_modules/thjs/thjs.js:806:10)
    at Object.hn.receive (/root/services/node-telehash/node_modules/thjs/thjs.js:583:26)
    at Object.receive (/root/services/node-telehash/node_modules/thjs/thjs.js:420:10)
    at Socket.<anonymous> (/root/services/node-telehash/index.js:56:10)
    at Socket.EventEmitter.emit (events.js:98:17)
    at UDP.onMessage (dgram.js:437:8)

Router crashes with if(dupe(dupid)) return log.debug('dropping duplicate');

Trying to connect two peers

  1. I start th-router from .bin folder.
    - 09 09 2015 - 12 35 53
  2. Save "link" from its output into links.json file:
    [
    "link://192.168.0.100:42424?cs1a=aot5jpsln6cladvzaljdaanined72uxzom&cs2a=gcbacirqbudaskugjcdpodibaeaqkaadqiaq6abqqiaquaucaeaqbkml5k6356vowblycjv6dczqswejtbj7h6psfnerp6j3xkqvybka7fxw2k7njlob7pygamxztwyjatcigyzogp2hpvulaj3drpn7lpnsmbndqdya2xiguighswttv5y4avqelnjo7mkniihz37mylyjc7s5upoz4a2ygwq2hz2iz7k7pro7fxx3pyizyqw2o2zpfg7qf3h4h4ttm45sxp7z42qzal5ftunkhubgol2no7bigvaoqr4i5ojbxuhfnptojryfkqldmbllfe67bjvaihxlf6gvfzzpi7hewjeewns5ctycp4amykuqtmql73qdnabtsw6lxz55snbvfs7gebyb7rmcwclhnnozjk3bkiq52u2flcq7iom4ay4s2jc4swjyaclnzsuu42igayrqlbaicamaqaai&cs3a=x2w6lnsjbehbjbirgjirwcuppgjyw6xcsf7savyl7ffrwhcv3f2a"
    ]

I have this peer as "first":

var th = require("telehash");
var path=require("path");

th.generate(function(err, endpoint){
    if(err) return console.log("endpoint generation failed",err);
    // endpoint contains a `keys:{}`, `secrets:{}`, and `hashname:"..."`
    var id = endpoint;
    console.log("id", id.hashname);
    var mesh = th.mesh({id: id, links:path.resolve(__dirname, "./links.json")}, function(err, mesh){
          if(err) return console.log("mesh failed to initialize",err);
          // use mesh.* now
            console.log("mesh initialized");
        var routerlink = mesh.link("link://192.168.0.100:42424?cs1a=aot5jpsln6cladvzaljdaanined72uxzom&cs2a=gcbacirqbudaskugjcdpodibaeaqkaadqiaq6abqqiaquaucaeaqbkml5k6356vowblycjv6dczqswejtbj7h6psfnerp6j3xkqvybka7fxw2k7njlob7pygamxztwyjatcigyzogp2hpvulaj3drpn7lpnsmbndqdya2xiguighswttv5y4avqelnjo7mkniihz37mylyjc7s5upoz4a2ygwq2hz2iz7k7pro7fxx3pyizyqw2o2zpfg7qf3h4h4ttm45sxp7z42qzal5ftunkhubgol2no7bigvaoqr4i5ojbxuhfnptojryfkqldmbllfe67bjvaihxlf6gvfzzpi7hewjeewns5ctycp4amykuqtmql73qdnabtsw6lxz55snbvfs7gebyb7rmcwclhnnozjk3bkiq52u2flcq7iom4ay4s2jc4swjyaclnzsuu42igayrqlbaicamaqaai&cs3a=x2w6lnsjbehbjbirgjirwcuppgjyw6xcsf7savyl7ffrwhcv3f2a");
        mesh.router(routerlink);
        console.log(mesh.uri());
    });

    mesh.accept = function(from){
        console.log("accept from ",from);
        mesh.link(from);
    };
});

Start it:
- 09 09 2015 - 12 48 59

and second (here I'm trying to connect to first peer)

var th = require("telehash");
var path = require("path");

th.generate(function(err, endpoint){
    if(err) return console.log("endpoint generation failed",err);
    // endpoint contains a `keys:{}`, `secrets:{}`, and `hashname:"..."`
    var id = endpoint;
    console.log("id", id.hashname);
    var mesh = th.mesh({id: id, links:path.resolve(__dirname, "./links.json")}, function(err, mesh){
        if(err) return console.log("mesh failed to initialize",err);
        // use mesh.* now
        console.log("mesh initialized");
         //console.log(mesh);
        var routerlink = mesh.link("link://192.168.0.100:42424?cs1a=aot5jpsln6cladvzaljdaanined72uxzom&cs2a=gcbacirqbudaskugjcdpodibaeaqkaadqiaq6abqqiaquaucaeaqbkml5k6356vowblycjv6dczqswejtbj7h6psfnerp6j3xkqvybka7fxw2k7njlob7pygamxztwyjatcigyzogp2hpvulaj3drpn7lpnsmbndqdya2xiguighswttv5y4avqelnjo7mkniihz37mylyjc7s5upoz4a2ygwq2hz2iz7k7pro7fxx3pyizyqw2o2zpfg7qf3h4h4ttm45sxp7z42qzal5ftunkhubgol2no7bigvaoqr4i5ojbxuhfnptojryfkqldmbllfe67bjvaihxlf6gvfzzpi7hewjeewns5ctycp4amykuqtmql73qdnabtsw6lxz55snbvfs7gebyb7rmcwclhnnozjk3bkiq52u2flcq7iom4ay4s2jc4swjyaclnzsuu42igayrqlbaicamaqaai&cs3a=x2w6lnsjbehbjbirgjirwcuppgjyw6xcsf7savyl7ffrwhcv3f2a");
        mesh.router(routerlink);
        console.log(mesh.uri());
        //var link = mesh.link("dxhpiwde7s4uxwxc2e2aoo6gqrcrglfun4lkrenpjflzxkoswuza");
        var link = mesh.link("link://192.168.0.100:45820?cs1a=amokq7xcb3yfvv4abffao3jaqphay3zesu&cs2a=gcbacirqbudaskugjcdpodibaeaqkaadqiaq6abqqiaquaucaeaqblq2iq7o5rhsi4bs6i4fwts5iwztffp3gpqgycrunnaoblgy5bqqbi7hfsw73u4ip7scgv4u3g5v7oxdxifdylgzanbi3w4fm7fh6vy3fqfvyd4upv3p7orj7qe4lxzdoisgm6sjdhbq7w4fqdjd2dngvdlgf4tgqdgkspkkwdiye2tmxnyovs2bhbefbmweyshmghbaa5qye2etbif6xo7imcflwo2fp6czsrsqn4i5srvg3pwhxstglpwwnxdagdl2eynxmvc55xkoq6rbxflazcra72slkh3pkp23yrhldnyxgklftf75scf3sxm7u2cyw3p27bgex5o4mmlfedxlfz65lrpwmfrep6q634ifxdkphffzqizm7ktj74knh7oy442pqisye7slbqbr6rd6heicamaqaai&cs3a=lyvdwanvovg6gu2qxmhga2ki4tbnldm57igz7ve7j7b6kuo2la4q");
        // will be called when link status changes, err is undefined when link is up
        link.status(function(err){
            if(err) {
                console.log('disconnected',err);
                return;
            }
             console.log('connected');
             //mesh.router(link);
             // can do any other link.* methods
        });


    });

    mesh.accept = function(from){
        console.log("accept from ",from);
        mesh.link(from);
    };
});

Start it:

Log from second:
zeipt@debian:~/reps/MycelyPC2$ node ./app1
generated new id djx6k6yipaw2eiqzhd3ovpv2mtts5lytw3cl4k4jrvfpx43t6fwq
id djx6k6yipaw2eiqzhd3ovpv2mtts5lytw3cl4k4jrvfpx43t6fwq
mesh initialized
link://192.168.0.100:37595?cs1a=aj7utir2zifgafbsa7hu4vb476yh5my74a&cs2a=gcbacirqbudaskugjcdpodibaeaqkaadqiaq6abqqiaquaucaeaqbjzyfisqj5xuqwnbnnuxqqt75ln43fukue4cl5tvxwtkhmy6t3eshb3egnz6marv635anmj2q55uspa4iehunnnoiffnhdfqu2ss53b2soyw7pw443qksr4b3ehq7hzqcf74fqkn5nlsa4wvyx7rfjf4tswr7ptjh2vebhtuznpzerza6riubvv3uwxhp27quez43ny7tfxsajdemzlx7wplqo2n5psks3r25soapsyhwb7fv5imvq6pghx7b2x53prvkeeuavij2xh4yojhdxlivvc2mpklndzddbucadvgp7pds6omlpbodpk4tyi4jfzoflertgtu5jvizmbrvhouxtfilgjsuc5cuqc7exblc66btulgsxgb6z4hziff6hhqapno2c4lqbhdgvswugqv37ycamaqaai&cs3a=ojvsvqxlwsqgtlnitvxlkboj7kbejad5hbyf5fftwdbo4oxufb3q
Unhandled rejection Error: false
at Object.ensureErrorObject (/home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/e3x/node_modules/subtle/node_modules/polyfill-promise/node_modules/bluebird/js/main/util.js:261:20)
at Promise._rejectCallback (/home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/e3x/node_modules/subtle/node_modules/polyfill-promise/node_modules/bluebird/js/main/promise.js:465:22)
at Function.Promise.reject.Promise.rejected (/home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/e3x/node_modules/subtle/node_modules/polyfill-promise/node_modules/bluebird/js/main/promise.js:195:9)
at Object.x.send (/home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/e3x/e3x.js:150:35)
at Pipe.peer_send (/home/zeipt/reps/MycelyPC2/node_modules/telehash/ext/peer.js:56:16)
at Pipe. (/home/zeipt/reps/MycelyPC2/node_modules/telehash/ext/peer.js:62:17)
at Pipe.emit (events.js:106:17)
at Pipe_send as send
at /home/zeipt/reps/MycelyPC2/node_modules/telehash/lib/link.class.js:254:18
at tryCatcher (/home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/e3x/node_modules/subtle/node_modules/polyfill-promise/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/e3x/node_modules/subtle/node_modules/polyfill-promise/node_modules/bluebird/js/main/promise.js:503:31)
at Promise._settlePromiseAt (/home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/e3x/node_modules/subtle/node_modules/polyfill-promise/node_modules/bluebird/js/main/promise.js:577:18)
at Promise._settlePromises (/home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/e3x/node_modules/subtle/node_modules/polyfill-promise/node_modules/bluebird/js/main/promise.js:693:14)
at Async._drainQueue (/home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/e3x/node_modules/subtle/node_modules/polyfill-promise/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/e3x/node_modules/subtle/node_modules/polyfill-promise/node_modules/bluebird/js/main/async.js:133:10)
at Async.drainQueues (/home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/e3x/node_modules/subtle/node_modules/polyfill-promise/node_modules/bluebird/js/main/async.js:15:14)
tcp socket error { [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
connected
tcp closed
tcp closed

And here is log from "router":
dxhpiwde up
owwimcao>
djx6k6yi up
owwimcao>
/home/zeipt/reps/MycelyPC2/node_modules/telehash/lib/util/receive.js:52
if(dupe(dupid)) return log.debug('dropping duplicate');
^
TypeError: undefined is not a function
at Object.receive_channel as channel
at Mesh_receive as receive
at /home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/telehash-udp4/index.js:35:12
at Object.tp.pipe (/home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/telehash-udp4/index.js:52:21)
at Socket.receive (/home/zeipt/reps/MycelyPC2/node_modules/telehash/node_modules/telehash-udp4/index.js:34:8)
at Socket.emit (events.js:98:17)
at UDP.onMessage (dgram.js:440:8)

Else, mesh.link with hashname never works.

Operator Address Problem

Wello! I've been trying to find a fix for this for an hour or so. Whenever I go into the demo folder, run genkeys.js, then try to run operator.js, node gives me this little beauty:

/Users/McMini/Desktop/th/demo/operator.js:6
console.log("operator address is ", operator.address);
^
TypeError: Cannot read property 'address' of undefined
at Object. (/Users/McMini/Desktop/th/demo/operator.js:6:45)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3

jspm support

Hi,

I'm using jspm to manage my front-end dependencies as es6 modules and would like to be able to install telehash-js using using it as well.

However, right now telehash-js has github repositories as dependencies in its package.json, which throws off the jspm installer a bit.

One quick workaround offered by the developer behind jspm is to add registry: npm in the package.json of each github repo used as a dependency in telehash-js's package.json.

The more ideal solution in my opinion is simply to use the github repos' respective npm packages as dependencies instead. I did a quick check on npm and it looks like all of them exist as npm packages already, albeit some of them are a bit out-of-date.

Any thoughts? If the former solution is preferred, I can open some pull requests to make the necessary modifications to the github repos' package.json.

Thanks,
Lewis.

v3

Any ETA release for v3 of Telehash-js?

ecc? { [Error: Cannot find module 'ecc-qj'] code: 'MODULE_NOT_FOUND' }

I keep having this issue everytime i run anything with telehashv3.:
ecc? { [Error: Cannot find module 'ecc-qj'] code: 'MODULE_NOT_FOUND' }

I have the following installed:
pi@raspberrypi ~ $ node -v
v4.2.1
pi@raspberrypi ~ $ npm --version
2.14.7

I did npm install ecc but it didnt solve and when i do npm install ecc -qj i have the issue below

$ npm install ecc-qj
npm WARN package.json [email protected] No license field.
npm ERR! Linux 4.1.13-v7+
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "ecc-qj"
npm ERR! node v4.2.1
npm ERR! npm v2.14.7
npm ERR! code E404

npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/ecc-qj
npm ERR! 404
npm ERR! 404 'ecc-qj' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'telehash'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! Please include the following file with any support request:
npm ERR! /home/pi/node_modules/telehash/test/ext/npm-debug.log

problem of npm install

Hi, my npm version is 1.4.28 in Windows 7. When I try to command "npm install telehash", I got the error messages like below:

npm ERR! git clone https://github.com/quartzjer/ecc.git undefined
npm ERR! git clone https://github.com/quartzjer/ecc.git undefined
npm WARN optional dep failed, continuing ecc@git+https://github.com/quartzjer/ecc.git
npm WARN git config --get remote.origin.url returned wrong result (https://github.com/quartzjer/ecc.git) undefined
npm WARN git config --get remote.origin.url returned wrong result (https://github.com/quartzjer/ecc.git) undefined
npm ERR! git clone https://github.com/quartzjer/ursa.git undefined
npm ERR! git clone https://github.com/quartzjer/ursa.git undefined
npm WARN optional dep failed, continuing ursa@git+https://github.com/quartzjer/ursa.git
npm ERR! git clone https://github.com/quartzjer/ecc.git undefined
npm ERR! git clone https://github.com/quartzjer/ecc.git undefined
npm WARN optional dep failed, continuing ecc@git+https://github.com/quartzjer/ecc.git
npm ERR! git clone https://github.com/rynomad/jsbn.git undefined
npm ERR! git clone https://github.com/rynomad/jsbn.git undefined

How can I solve it? Thanks.

Need help getting closest infohash

Hey i see whois returns the instance that corresponds to to that infohash if it exists in network, what i am looking for is a method that is closest to an infohash. My idea is to have a distributed storage so each stored item will be stored on closest matching infohash instances.

Is there a method that returns the closest matching instance to an infohash.Help would be greatly appreciated.And i am putting it in issues here becoz i have no other means to contact you.

Can't reconnect to a peer?

Using the sample code and instructions in #36 (comment), I am able to get peer "test2" to connect to peer "test1" the first time. The test1 process has its mesh.accept handler called and I see the "INCOMING" log it generates.

However, if I kill the "test2" process and restart it, the still-running "test1" process does not seem to ever see it. The previous link instance it had doesn't seem to be doing anything anymore, but neither does the mesh.accept handler get triggered.

If I start a new processes "test3" with a new endpoint identity, the original "test1" process does see that come in and start communicating with it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.