Skip to content

Commit

Permalink
More work toward a sane client.
Browse files Browse the repository at this point in the history
  • Loading branch information
jspark311 committed Mar 7, 2016
1 parent e056094 commit e5c0319
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions lib/transports/Telehash.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,29 +145,34 @@ function mTransport(options) {
client_link = options.link;
console.log('\nLINK contents: ' + JSON.stringify(client_link)+'\n');
client_link.on('status',
function(up) {
client_stream = client_link.stream();
connect_state = true;
that.send('connected', connect_state);
client_stream.on('data',
function(dat) {
var tmp_buf = new Buffer(dat, 'utf8')
console.log('Data coming from stream: ' + dat);
that.send('data', tmp_buf);
}
);
function(err) {
if (err) {
client_stream = client_link.stream();
connect_state = true;
that.send('connected', connect_state);
client_stream.on('data',
function(dat) {
var tmp_buf = new Buffer(dat, 'utf8')
console.log('Data coming from stream: ' + dat);
that.send('data', tmp_buf);
}
);

that.send('log', {
body: 'Telehash client became connected.',
verbosity: 6
});
that.send('log', {
body: 'Telehash client became connected.',
verbosity: 6
});
}
else {
connect_state = true;
that.send('log', {
body: 'Telehash client became disconnected. '+err,
verbosity: 4
});
}
}
);
}
else if (options && options.uri) {
// We have been given a URI to follow...

}
};


Expand Down Expand Up @@ -263,7 +268,6 @@ function mTransportFactory() {

this.startRouter = function(err, id_data) {
router_id = id_data;

th.mesh(
{
id: router_id,
Expand All @@ -284,38 +288,38 @@ function mTransportFactory() {
);
}



this.interface_spec = {
type: 'mTransportFactory',
name: 'TelehashFactory',
schema: {
inputs: {
'connect' : {
label: "Connect",
args: [ { label: 'Remote Address', type: 'string' },
args: [ { label: 'Hashname', type: 'string' },
{ label: 'ID File', type: 'string', def: DEFAULT_CLIENT_ID_PATH } ],
func: function(me, data) {
if (data.length > 0) {
var address = data.shift();
var _hashname = data.shift();
var _keyfile = (data.length > 0) ? data.shift() : DEFAULT_CLIENT_ID_PATH;
me.send('log', {
body: 'Attempting connection to ' + address + " with keyfile " + _keyfile,
if (me.router_mesh) {
me.send('log', {
body: 'Attempting connection to ' + _hashname + " with keyfile " + _keyfile,
verbosity: 4
});
var nu_inst = new net.mTransport();
//loadKeyData(nu_inst, _keyfile, callback)
nu_inst.once('connect',
function () {
var instance = new mTransport(nu_inst);
me.send('connected', instance);
}
);
});
var nu_link = me.router_mesh.link(_hashname);
me.send('connected', new mTransport({link: nu_link}));
}
else {
me.send('log', {
body: 'Cannot establish connection to ' + _hashname + ' without an active router.',
verbosity: 4
});
}
}
else {
me.send('log', {
body: 'Unspecified address.',
verbosity: 2
body: 'Unspecified address.',
verbosity: 2
});
}
},
Expand Down

0 comments on commit e5c0319

Please sign in to comment.