Permalink
Browse files

v0.0.6

  • Loading branch information...
1 parent 68f0060 commit f969f9269c0c4366891e43e39fb9918b5fc06068 Tim committed Dec 10, 2011
Showing with 392 additions and 1,381 deletions.
  1. +72 −38 README.md
  2. +0 −6 bin/rpc-socket
  3. +0 −8 example/master-config.json
  4. +0 −34 example/modules/test.js
  5. +0 −14 example/modules/test2.js
  6. +0 −34 example/servent-load.js
  7. +0 −38 example/servent.js
  8. +0 −8 example/slave-config.json
  9. +24 −35 index.js
  10. +0 −24 lib/auth.js
  11. +5 −4 lib/exposed.js
  12. +0 −13 lib/io.js
  13. +0 −109 lib/manager.js
  14. +0 −18 lib/master.js
  15. +0 −209 lib/peer.js
  16. +277 −258 lib/rpc.js
  17. +0 −227 lib/servent.js
  18. +0 −15 lib/slave.js
  19. +0 −148 lib/socket.js
  20. +12 −70 lib/utils.js
  21. +2 −2 package.json
  22. +0 −69 test/rpc-run-test.js
View
110 README.md
@@ -1,38 +1,72 @@
-RPC-Socket
-=============
-
-This is a project that I have been working on for a bit. it's still under heavy development but is coming along.
-
-TODO
--------
-
-So a few things i still want to add.
-
-* Nothing as we speak, I'm still thinking.
-
-
-Install
-------------
-
-A few ways of installing.
-
-
-### NPM
-
-Yeah so to install is real easy.
-
- npm install rpc-socket
-
-or to access the rpc-socket executable install globally:
-
- npm install -g rpc-socket
-
-
-### GIT
-
-You might want to download and move to a folder of your choise and test it out.
-
-
- cd /path/to/your/folder
- git clone git://github.com/FLYBYME/rpc-socket.git
- cd rpc-socket
+RPC-Socket
+=============
+
+This is a project that I have been working on for a bit. it's still under heavy development but is coming along.
+
+TODO
+-------
+
+So a few things i still want to add.
+
+* Nothing as we speak, I'm still thinking.
+
+
+Install
+------------
+
+A few ways of installing.
+
+
+### NPM
+
+Yeah so to install is real easy.
+
+ npm install rpc-socket
+
+or to access the rpc-socket executable install globally:
+
+ npm install -g rpc-socket
+
+
+### GIT
+
+You might want to download and move to a folder of your choise and test it out.
+
+
+ cd /path/to/your/folder
+ git clone git://github.com/FLYBYME/rpc-socket.git
+ cd rpc-socket
+
+
+### Basic usage.
+
+
+```javascript
+
+ var cp = require('child_process');
+ var p = require('../lib/protocols/process')
+ var numCPUs = require('os').cpus().length;
+
+ if(process.send) {
+
+ (new p(process)).invoke('test', [3454545], function(err, result) {
+ //console.log('Error: ', err)
+ //console.log('Result: ', result)
+
+ });
+ } else {
+ var j = 0;
+ var callBack = function(err, result) {
+ console.log('Error: ', err)
+ console.log('Result: ', result);
+ if(++j === numCPUs) {
+ process.exit(0);
+ }
+ }
+ for(var i = 0; i < numCPUs; i++) {
+ (new p(cp.fork(__filename))).expose('test', function(a) {
+ this.send('a', a);
+ }).invoke('list', [], callBack);
+ }
+ }
+```
View
@@ -1,6 +0,0 @@
-#!/usr/bin/env node
-process.on('uncaughtException', function (err) {
- console.log('Caught exception: ' + err);
-});
-var fs=require("fs"),utils=require("./lib/utils"),Master=require("./lib/master"),Rpc=require("./lib/rpc"),Slave=require("./lib/slave"),Io=require("./lib/io"),logger=utils.logger,args=process.argv;args.shift();args.shift();for(var config={},i=args.length-1;i>=0;i--){var arg=args[i].split("="),key=arg[0],val=arg[1];key==="-config"&&(config.config=val)}if(!config.config)throw" ERROR: Should be something like: node app -config=/path/to/config.json";
-fs.readFile(config.config,function(f,g){if(f)throw" ERROR: No such file: "+config.config+" Should be something like: node app -config=/path/to/config.json";config=JSON.parse(g);for(var c=config.type,d=config.port,e=config.host,a=config.modules,h=config.baseDir,b=a.length-1;b>=0;b--)a[b]=h+"/"+a[b];c==="master"?new Master(d,e,a):c==="slave"?new Slave(d,e,a):c==="io"&&new Io(d,e,a)});
@@ -1,8 +0,0 @@
-{
- "salt": "asdfsdasd",
- "modules": ["test"],
- "baseDir": "/home/dev/rpc-socket/example/modules",
- "port": 8000,
- "host": "localhost",
- "type": "master"
-}
View
@@ -1,34 +0,0 @@
-var Test = function() {
-
-}
-
-Test.prototype.foo = function(a, b) {
- return a + b;
-}
-Test.prototype.bar = function(a, b, callBack) {
- callBack(a + b);
-}
-var test = new Test()
-
-module.exports = function(rpc) {
- var ticker = 0;
- rpc.expose('test', {
- foo : function(a, b) {
- this.set('foo', test.foo(a, b));
- this.send();
- },
- bar : function(a, b) {
- var exposed = this;
- test.bar(a, b, function(err, result) {
- exposed.send('bar', result);
- })
- },
- deepCallBack : function(depth) {
- var exposed = this;
-
- exposed.set('deepCallBack', true);
- exposed.send('tikker', ticker++);
-
- }
- })
-}
View
@@ -1,14 +0,0 @@
-module.exports = function(rpc) {
- var counter = 0;
- rpc.expose('test2', {
- count : function(a) {
- //console.log(this)
- var exposed = this
-
- exposed.push({
- error : 'failed login' + (++counter),
- a : a
- }).send()
- }
- })
-}
View
@@ -1,34 +0,0 @@
-var port = 8888
-var Servent = require('../lib/servent')
-var servent = new Servent();
-
-servent.on('listening', function() {
- /**
- * If we arent on our default port then we weren't
- * the first node, so connect to that one
- */
- if(servent.address().port !== port) {
- servent.connect(port);
-
- }
-});
-/**
- * First bind to our default port, if we can't then use
- * an ephemeral port instead
- */
-servent.on('error', function(err) {
- if(err.code === 'EADDRINUSE') {
- servent.listen(0);
- }
-});
-servent.on('rpc', function(rpc) {
-
- var count = 0
- for(var i = 50; i >= 0; i--) {
- servent.broadcastRpc('list', [], function(err, result) {
- console.log('list return count: ' + count++)
- })
- };
-
-});
-servent.listen(port);
View
@@ -1,38 +0,0 @@
-var port = 8888
-var Servent = require('../lib/servent')
-var servent = new Servent();
-
-servent.on('listening', function() {
- /**
- * If we arent on our default port then we weren't
- * the first node, so connect to that one
- */
- if(servent.address().port !== port) {
- servent.connect(port, '208.53.183.73');
-
- }
-});
-/**
- * First bind to our default port, if we can't then use
- * an ephemeral port instead
- */
-servent.on('error', function(err) {
- if(err.code === 'EADDRINUSE') {
- servent.listen(0, '208.53.183.73');
- }
-});
-servent.on('rpc', function(rpc) {
-
- rpc.expose('private', function() {
-
- })
-});
-servent.on('peer', function(peer) {
- peer.rpc.makeCall('list', [], function(err, result) {
- //console.log(arguments)
- })
-});
-servent.expose('test', function() {
-
-})
-servent.listen(port, '208.53.183.73');
@@ -1,8 +0,0 @@
-{
- "salt": "asdfsdasd",
- "modules": ["test"],
- "baseDir": "/home/dev/rpc-socket/example/modules",
- "port": 8000,
- "host": "localhost",
- "type": "slave"
-}
View
@@ -1,35 +1,24 @@
-/*
- *
- *
- */
-module.exports.Master = require('./lib/master');
-/*
- *
- *
- */
-module.exports.Rpc = require('./lib/rpc');
-/*
- *
- *
- */
-module.exports.Slave = require('./lib/slave');
-/*
- *
- *
- */
-module.exports.Io = require('./lib/io');
-/*
- *
- *
- */
-module.exports.Servent = require('./lib/servent');
-/*
- *
- *
- */
-module.exports.Manager = require('./lib/manager');
-/*
- *
- *
- */
-module.exports.version = '0.0.5';
+/*
+ *
+ *
+ */
+module.exports.Stack = require('./lib/stack');
+/*
+ *
+ *
+ */
+module.exports.RpcModule = require('./lib/rpc').RpcModule;
+/*
+ *
+ *
+ */
+module.exports.protocols = {
+ Io : require('./lib/protocols/socket.io'),
+ Process : require('./lib/protocols/process'),
+ Socket : require('./lib/protocols/socket')
+};
+/*
+ *
+ *
+ */
+module.exports.version = '0.0.6';
View
@@ -1,24 +0,0 @@
-var crypto = require('crypto');
-
-var SaltLength = 9;
-
-var Auth = function(key) {
- this._salt = salt
- this._active = {}
-}
-
-Auth.prototype.register = function() {
-
-}
-Auth.prototype.login = function(hash, password, callBack) {
- var ourHash = md5(password + this._salt)
- if(ourHash === hash) {
- callBack()
- }
-}
-function md5(string) {
- return crypto.createHash('md5').update(string).digest('hex');
-}
-
-module.exports = Auth;
-;
View
@@ -1,14 +1,15 @@
var events = require('events')
-var Exposed = module.exports = function(data, id, callBack, info) {
+var Exposed = module.exports = function(data, rpc) {
//
this.id = data.id
this.method = data.method
this.params = data.params
- this.socketId = id
+ this.socketId = rpc.id
//
- this.callBack = callBack;
-
+ this.callBack = function(data) {
+ rpc.write(data)
+ };
//
this.result = {}
this.err = {}
View
@@ -1,13 +0,0 @@
-var Rpc = require('./rpc');
-//
-var Io = module.exports = function(port, host, modules) {
-
- var server = require('socket.io').listen(port).sockets;
-
- server.on('connection', function(socket) {
- var a = new Rpc(socket);
- for(var i = modules.length - 1; i >= 0; i--) {
- require(modules[i])(a)
- };
- })
-}
Oops, something went wrong.

0 comments on commit f969f92

Please sign in to comment.