Comparing version 0.6.7 to 0.6.8
70
index.js
var net = require('net'); | ||
var tls = require('tls'); | ||
var http = require('http'); | ||
@@ -31,9 +32,27 @@ var EventEmitter = require('events').EventEmitter; | ||
var client = null; | ||
var self = this; | ||
if (params.port) { | ||
stream = net.createConnection(params.port, params.host); | ||
stream.remoteAddress = params.host || '127.0.0.1'; | ||
stream.remotePort = params.port; | ||
} | ||
params.host = params.host || '127.0.0.1'; | ||
if (params.key) { | ||
var options = { key: params.key, cert: params.cert }; | ||
stream = tls.connect(params.port, params.host, options, function() { | ||
attachDnode(); | ||
}); | ||
} | ||
else { | ||
stream = net.createConnection(params.port, params.host); | ||
stream.on('connect', function() { | ||
attachDnode(); | ||
}); | ||
} | ||
} else { | ||
attachDnode(); | ||
} | ||
stream.remoteAddress = params.host; | ||
stream.remotePort = params.port; | ||
var args = arguments; | ||
if (params.reconnect) { | ||
@@ -71,6 +90,5 @@ stream.on('error', (function (err) { | ||
var args = arguments; | ||
stream.on('connect', (function () { | ||
client = createClient(this.proto, stream); | ||
function attachDnode() { | ||
client = createClient(self.proto, stream); | ||
@@ -82,3 +100,3 @@ client.end = function () { | ||
this.stack.forEach(function (middleware) { | ||
self.stack.forEach(function (middleware) { | ||
middleware.call(client.instance, client.remote, client); | ||
@@ -103,3 +121,3 @@ }); | ||
client.start(); | ||
}).bind(this)); | ||
}; | ||
@@ -114,7 +132,24 @@ return this; | ||
if (params.port) { | ||
server = net.createServer(); | ||
server.listen( | ||
params.port, params.host, | ||
this.emit.bind(this, 'ready') | ||
); | ||
params.host = params.host || '127.0.0.1'; | ||
if (params.key) { | ||
var options = { | ||
key: params.key, | ||
cert: params.cert, | ||
ca: params.ca, | ||
requestCert: params.requestCert, | ||
rejectUnauthorized: params.rejectUnauthorized | ||
}; | ||
server = tls.createServer(options); | ||
server.listen( | ||
params.port, params.host, | ||
this.emit.bind(this, 'ready') | ||
); | ||
} | ||
else { | ||
server = net.createServer(); | ||
server.listen( | ||
params.port, params.host, | ||
this.emit.bind(this, 'ready') | ||
); | ||
} | ||
} | ||
@@ -135,3 +170,6 @@ else if (server && server instanceof http.Server | ||
var clients = {}; | ||
server.on('connection', (function (stream) { | ||
var listenFor = server instanceof tls.Server | ||
? 'secureConnection' | ||
: 'connection' ; | ||
server.on(listenFor, (function (stream) { | ||
var client = createClient(this.proto, stream); | ||
@@ -138,0 +176,0 @@ clients[client.id] = client; |
{ | ||
"name" : "dnode", | ||
"version" : "0.6.7", | ||
"version" : "0.6.8", | ||
"description" : "freestyle RPC like a boss", | ||
@@ -19,3 +19,3 @@ "main" : "./index.js", | ||
"directories" : { | ||
"lib" : "./lib", | ||
"lib" : ".", | ||
"examples" : "./examples" | ||
@@ -28,4 +28,5 @@ }, | ||
"browserify" : ">=0.2.9", | ||
"dnode-protocol" : ">=0.0.5" | ||
"dnode-protocol" : ">=0.0.7" | ||
}, | ||
"bundleDependencies" : [ "dnode-protocol" ], | ||
"browserify" : { | ||
@@ -32,0 +33,0 @@ "name" : "dnode", |
var dnode = require('dnode'); | ||
var assert = require('assert'); | ||
exports._id = function (assert) { | ||
exports._id = function () { | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -5,0 +6,0 @@ |
@@ -1,5 +0,5 @@ | ||
var DNode = require('dnode'); | ||
var sys = require('sys'); | ||
var dnode = require('dnode'); | ||
var assert = require('assert'); | ||
exports['bidirectional'] = function (assert) { | ||
exports['bidirectional'] = function () { | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -9,3 +9,3 @@ | ||
var server = DNode(function (client) { | ||
var server = dnode(function (client) { | ||
this.timesX = function (n,f) { | ||
@@ -23,3 +23,3 @@ assert.equal(n, 3, "timesX's n == 3"); | ||
server.on('ready', function () { | ||
DNode({ | ||
dnode({ | ||
x : function (f) { | ||
@@ -37,3 +37,3 @@ counts.x ++; | ||
}); | ||
server.once('close', function () { | ||
@@ -40,0 +40,0 @@ assert.equal(counts.timesX, 1, 'timesX called once'); |
@@ -1,10 +0,11 @@ | ||
var DNode = require('dnode'); | ||
var dnode = require('dnode'); | ||
var EventEmitter = require('events').EventEmitter; | ||
var sys = require('sys'); | ||
var util = require('util'); | ||
var assert = require('assert'); | ||
exports.broadcast = function (assert) { | ||
exports.broadcast = function () { | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
var em = new EventEmitter; | ||
var server = DNode(function (client,conn) { | ||
var server = dnode(function (client,conn) { | ||
conn.on('ready', function () { | ||
@@ -26,3 +27,3 @@ em.on('message', client.message); | ||
server.on('ready', function () { | ||
DNode({ | ||
dnode({ | ||
name : '#0', | ||
@@ -36,3 +37,3 @@ message : function (msg) { recv[0].push(msg) }, | ||
DNode({ | ||
dnode({ | ||
name : '#1', | ||
@@ -46,3 +47,3 @@ message : function (msg) { recv[1].push(msg) }, | ||
DNode({ | ||
dnode({ | ||
name : '#2', | ||
@@ -61,3 +62,3 @@ message : function (msg) { recv[2].push(msg) }, | ||
assert.equal( | ||
sys.inspect(recv[0]), | ||
util.inspect(recv[0]), | ||
"[ '#0 says: hello!', '#1 says: hey', '#2 says: wowsy' ]", | ||
@@ -67,9 +68,9 @@ "#0 didn't get the right messages" | ||
assert.equal( | ||
sys.inspect(recv[0]), | ||
sys.inspect(recv[1]), | ||
util.inspect(recv[0]), | ||
util.inspect(recv[1]), | ||
"#1 didn't get the messages" | ||
); | ||
assert.equal( | ||
sys.inspect(recv[0]), | ||
sys.inspect(recv[2]), | ||
util.inspect(recv[0]), | ||
util.inspect(recv[2]), | ||
"#2 didn't get the messages" | ||
@@ -76,0 +77,0 @@ ); |
@@ -1,15 +0,13 @@ | ||
var DNode = require('dnode'); | ||
var sys = require('sys'); | ||
var dnode = require('dnode'); | ||
var util = require('util'); | ||
var assert = require('assert'); | ||
exports['circular refs'] = function (assert) { | ||
exports['circular refs'] = function () { | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
var server = DNode({ | ||
var server = dnode({ | ||
sendObj : function (ref, f) { | ||
assert.equal(ref.a, 1); | ||
assert.equal(ref.b, 2); | ||
assert.equal( | ||
sys.inspect(ref.c), | ||
sys.inspect(ref) | ||
); | ||
assert.eql(ref.c, ref); | ||
@@ -23,3 +21,3 @@ ref.d = ref.c; | ||
server.on('ready', function () { | ||
DNode.connect(port, function (remote, conn) { | ||
dnode.connect(port, function (remote, conn) { | ||
var obj = { a : 1, b : 2 }; | ||
@@ -31,10 +29,4 @@ obj.c = obj; | ||
assert.equal(ref.b, 2); | ||
assert.equal( | ||
sys.inspect(ref.c), | ||
sys.inspect(ref) | ||
); | ||
assert.equal( | ||
sys.inspect(ref.d), | ||
sys.inspect(ref) | ||
); | ||
assert.eql(ref.c, ref); | ||
assert.eql(ref.d, ref); | ||
conn.end(); | ||
@@ -41,0 +33,0 @@ server.close(); |
@@ -1,7 +0,8 @@ | ||
var DNode = require('dnode'); | ||
var dnode = require('dnode'); | ||
var assert = require('assert'); | ||
exports.double = function (assert) { | ||
exports.double = function () { | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
var server = DNode({ | ||
var server = dnode({ | ||
z : function (f, g, h) { | ||
@@ -17,3 +18,3 @@ f(10, function (x) { | ||
server.on('ready', function () { | ||
DNode.connect(port, function (remote, conn) { | ||
dnode.connect(port, function (remote, conn) { | ||
remote.z( | ||
@@ -20,0 +21,0 @@ function (x,f) { f(x * 2) }, |
@@ -1,6 +0,6 @@ | ||
var DNode = require('dnode'); | ||
var dnode = require('dnode'); | ||
var EventEmitter = require('events').EventEmitter; | ||
var sys = require('sys'); | ||
var assert = require('assert'); | ||
exports['event emitter test'] = function (assert) { | ||
exports['event emitter test'] = function () { | ||
var emitted = false; | ||
@@ -13,3 +13,3 @@ var ev = new EventEmitter; | ||
assert.equal(b, 2); | ||
assert.equal(sys.inspect(c), sys.inspect([3,4])); | ||
assert.eql(c, [3,4]); | ||
emitted = true; | ||
@@ -46,5 +46,5 @@ }); | ||
var server = DNode(Server).listen(port); | ||
var server = dnode(Server).listen(port); | ||
server.on('ready', function () { | ||
DNode.connect(port, function (remote, conn) { | ||
dnode.connect(port, function (remote, conn) { | ||
remote.pass('test1', ev); | ||
@@ -51,0 +51,0 @@ var test2_calls = 0; |
@@ -1,9 +0,10 @@ | ||
var DNode = require('dnode'); | ||
var dnode = require('dnode'); | ||
var sys = require('sys'); | ||
var assert = require('assert'); | ||
exports.errors = function (assert) { | ||
exports.errors = function () { | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
var errors = { server : [], client : [] }; | ||
var server = DNode(function (remote, conn) { | ||
var server = dnode(function (remote, conn) { | ||
conn.on('error', function (err) { | ||
@@ -46,3 +47,3 @@ errors.server.push(err); | ||
server.on('ready', function () { | ||
var client = DNode(function (client, conn) { | ||
var client = dnode(function (client, conn) { | ||
conn.on('error', function (err) { | ||
@@ -49,0 +50,0 @@ errors.client.push(err); |
@@ -1,4 +0,5 @@ | ||
var DNode = require('dnode'); | ||
var dnode = require('dnode'); | ||
var assert = require('assert'); | ||
exports['nested'] = function (assert) { | ||
exports['nested'] = function () { | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -8,7 +9,7 @@ | ||
var server1 = DNode({ | ||
var server1 = dnode({ | ||
timesTen : function (n,reply) { reply(n * 10) } | ||
}).listen(port); | ||
var server2 = DNode({ | ||
var server2 = dnode({ | ||
timesTwenty : function (n,reply) { reply(n * 20) } | ||
@@ -22,4 +23,4 @@ }).listen(port + 1); | ||
server2.on('ready', function () { | ||
DNode.connect(port, function (remote1, conn1) { | ||
DNode.connect(port + 1, function (remote2, conn2) { | ||
dnode.connect(port, function (remote1, conn1) { | ||
dnode.connect(port + 1, function (remote2, conn2) { | ||
moo.on('hi', function (x) { | ||
@@ -26,0 +27,0 @@ remote1.timesTen(x, function (res) { |
@@ -1,4 +0,5 @@ | ||
var DNode = require('dnode'); | ||
var dnode = require('dnode'); | ||
var assert = require('assert'); | ||
exports['object ref tests'] = function (assert) { | ||
exports['object ref tests'] = function () { | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -8,3 +9,3 @@ | ||
var server = DNode({ | ||
var server = dnode({ | ||
getObject : function (f) { f(obj) }, | ||
@@ -14,3 +15,3 @@ }).listen(port); | ||
server.on('ready', function () { | ||
DNode.connect(port, function (remote, conn) { | ||
dnode.connect(port, function (remote, conn) { | ||
remote.getObject(function (rObj) { | ||
@@ -17,0 +18,0 @@ assert.equal(rObj.a, 1); |
@@ -1,8 +0,8 @@ | ||
var DNode = require('dnode'); | ||
var sys = require('sys'); | ||
var dnode = require('dnode'); | ||
var assert = require('assert'); | ||
exports.refs = function (assert) { | ||
exports.refs = function () { | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
var server = DNode({ | ||
var server = dnode({ | ||
a : 1, | ||
@@ -13,15 +13,9 @@ b : 2, | ||
server.on('ready', function () { | ||
DNode.connect(port, function (remote, conn) { | ||
dnode.connect(port, function (remote, conn) { | ||
conn.end(); | ||
server.close(); | ||
assert.equal( | ||
remote.a, 1, | ||
'remote.a != 1, a = ' + sys.inspect(remote.a) | ||
); | ||
assert.equal( | ||
remote.b, 2, | ||
'remote.b != 2, b = ' + sys.inspect(remote.b) | ||
); | ||
assert.equal(remote.a, 1); | ||
assert.equal(remote.b, 2); | ||
}); | ||
}); | ||
}; |
@@ -1,28 +0,34 @@ | ||
var DNode = require('dnode') | ||
, sys = require('sys') | ||
var dnode = require('dnode') | ||
var assert = require('assert'); | ||
var util = require('util'); | ||
exports.simple = function (assert) { | ||
exports.simple = function () { | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
var server = DNode({ | ||
var server = dnode({ | ||
timesTen : function (n,reply) { | ||
assert.equal(n.number, 5); | ||
reply(n.number * 10); | ||
} | ||
, print : function (n,reply) { | ||
assert.strictEqual(n[0],1) | ||
assert.strictEqual(n[1],2) | ||
assert.strictEqual(n[2],3) | ||
assert.strictEqual(n[3],n) | ||
reply(sys.inspect(n)); | ||
} | ||
}, | ||
print : function (n,reply) { | ||
assert.strictEqual(n[0],1); | ||
assert.strictEqual(n[1],2); | ||
assert.strictEqual(n[2],3); | ||
assert.strictEqual(n[3],n); | ||
reply(n); | ||
}, | ||
}).listen(port); | ||
server.on('ready', function () { | ||
DNode.connect(port, function (remote, conn) { | ||
dnode.connect(port, function (remote, conn) { | ||
assert.equal(conn.stream.remoteAddress, '127.0.0.1'); | ||
var args = [1,2,3] | ||
args.push(args) | ||
remote.print(args, function (m) { | ||
assert.eql( | ||
util.inspect(m), | ||
util.inspect(args) | ||
); | ||
conn.end(); | ||
@@ -29,0 +35,0 @@ server.close(); |
var dnode = require('dnode'); | ||
var assert = require('assert'); | ||
exports.simple = function (assert) { | ||
exports.simple = function () { | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -6,0 +6,0 @@ |
@@ -1,25 +0,26 @@ | ||
var DNode = require('dnode') | ||
, sys = require('sys') | ||
var dnode = require('dnode') | ||
var util = require('util'); | ||
var assert = require('assert'); | ||
exports.simple = function (assert) { | ||
exports.simple = function () { | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
var server = DNode({ | ||
var server = dnode({ | ||
timesTen : function (n,reply) { | ||
assert.equal(n.number, 5); | ||
reply(n.number * 10); | ||
} | ||
, print : function (n,reply) { | ||
console.log(n); | ||
}, | ||
print : function (n,reply) { | ||
reply(sys.inspect(n)); | ||
} | ||
}, | ||
}).listen(port); | ||
server.on('ready', function () { | ||
DNode.connect(port, function (remote, conn) { | ||
dnode.connect(port, function (remote, conn) { | ||
assert.equal(conn.stream.remoteAddress, '127.0.0.1'); | ||
var args = { | ||
number: 5 | ||
, func: function hello(){} | ||
} | ||
number : 5, | ||
func : function () {}, | ||
}; | ||
remote.timesTen(args, function (m) { | ||
@@ -26,0 +27,0 @@ assert.equal(m, 50, '5 * 10 == 50'); |
var dnode = require('dnode'); | ||
var assert = require('assert'); | ||
exports.simple = function (assert) { | ||
exports.simple = function () { | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -5,0 +6,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132408
57
3115
5
7
Updateddnode-protocol@>=0.0.7