Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

push

  • Loading branch information...
commit 688c5388a54cb86a8a5e77e7e45717894fff63ce 1 parent 5071917
Bob authored
Showing with 15,230 additions and 13,443 deletions.
  1. +17 −17 .project
  2. +12 −12 .settings/.jsdtscope
  3. +3 −3 .settings/org.eclipse.ltk.core.refactoring.prefs
  4. +42 −42 dump/README.md
  5. +17 −17 dump/client.js
  6. +32 −32 dump/lib/client.js
  7. +8 −8 dump/lib/config.js
  8. +441 −441 dump/lib/connection.js
  9. +149 −149 dump/lib/manager.js
  10. +238 −238 dump/lib/node.js
  11. +45 −45 dump/lib/os.js
  12. +299 −299 dump/lib/rpc.js
  13. +30 −30 dump/lib/sqlite.js
  14. +25 −25 dump/lib/utils.js
  15. +18 −18 dump/package.json
  16. +23 −23 dump/rpc-modules/server/namespace-modulename.js
  17. +1 −1  dump/server.js
  18. +652 −652 dump/test/console-data.keymaps
  19. +56 −56 dump/test/npm
  20. +39 −39 dump/test/sqlite.js
  21. +72 −72 dump/test/test-http-server.js
  22. +16 −16 dump/test/test-tpc-server.js
  23. +98 −98 dump/test/test.html
  24. +27 −27 dump/test/test.js
  25. +11 −0 lib/Modules/coundto500.js
  26. +11 −0 lib/Modules/reply.js
  27. +54 −20 lib/Modules/sysinfo.js
  28. +88 −0 lib/Modules/user.js
  29. +7 −0 lib/Modules/userinfo.js
  30. BIN  lib/VfE_html5.mp4
  31. +227 −0 lib/frontend-server.js
  32. +234 −0 lib/frontend-server.js~
  33. +53 −0 lib/frontend-socket.js
  34. +167 −140 lib/manager.js
  35. +663 −0 lib/mime.js
  36. +157 −155 lib/rpc.js
  37. +68 −67 lib/socket.js
  38. +41 −41 lib/{client.js → tcp-client.js}
  39. +42 −42 lib/{server.js → tcp-server.js}
  40. +425 −0 lib/utils-http.js
  41. +29 −26 lib/utils.js
  42. BIN  lib/weaver.mkv
  43. +56 −56 node_modules/.bin/node-inspector
  44. +1 −0  node_modules/.bin/uglifyjs
  45. +2 −2 node_modules/node-inspector/.gitignore
  46. +83 −83 node_modules/node-inspector/ChangeLog
  47. +56 −56 node_modules/node-inspector/bin/inspector.js
  48. +270 −270 node_modules/node-inspector/front-end/ApplicationCacheItemsView.js
  49. +70 −70 node_modules/node-inspector/front-end/AuditCategories.js
  50. +92 −92 node_modules/node-inspector/front-end/AuditFormatters.js
  51. +294 −294 node_modules/node-inspector/front-end/AuditLauncherView.js
  52. +114 −114 node_modules/node-inspector/front-end/AuditResultView.js
  53. +1,041 −1,041 node_modules/node-inspector/front-end/AuditRules.js
  54. +503 −503 node_modules/node-inspector/front-end/AuditsPanel.js
  55. +264 −264 node_modules/node-inspector/front-end/BottomUpProfileDataGridTree.js
  56. +658 −658 node_modules/node-inspector/front-end/BreakpointManager.js
  57. +397 −397 node_modules/node-inspector/front-end/BreakpointsSidebarPane.js
  58. +88 −88 node_modules/node-inspector/front-end/CSSCompletions.js
  59. +550 −550 node_modules/node-inspector/front-end/CSSStyleModel.js
  60. +185 −185 node_modules/node-inspector/front-end/CallStackSidebarPane.js
  61. +61 −61 node_modules/node-inspector/front-end/Callback.js
  62. +80 −80 node_modules/node-inspector/front-end/ChangesView.js
  63. +63 −63 node_modules/node-inspector/front-end/Checkbox.js
  64. +661 −661 node_modules/node-inspector/front-end/Color.js
  65. +86 −86 node_modules/node-inspector/front-end/ConsolePanel.js
  66. +1,109 −1,109 node_modules/node-inspector/front-end/ConsoleView.js
  67. +90 −90 node_modules/node-inspector/front-end/ContextMenu.js
  68. +200 −200 node_modules/node-inspector/front-end/CookieItemsView.js
  69. +210 −210 node_modules/node-inspector/front-end/CookieParser.js
  70. +205 −205 node_modules/node-inspector/front-end/CookiesTable.js
  71. +565 −565 node_modules/node-inspector/front-end/DOMAgent.js
  72. +72 −72 node_modules/node-inspector/front-end/DOMStorage.js
  73. +157 −157 node_modules/node-inspector/front-end/DOMStorageItemsView.js
  74. +79 −79 node_modules/node-inspector/front-end/DOMSyntaxHighlighter.js
  75. +1,465 −1,465 node_modules/node-inspector/front-end/DataGrid.js
  76. +121 −121 node_modules/node-inspector/front-end/Database.js
  77. +196 −196 node_modules/node-inspector/front-end/DatabaseQueryView.js
  78. +90 −90 node_modules/node-inspector/front-end/DatabaseTableView.js
  79. +359 −359 node_modules/node-inspector/front-end/Drawer.js
Sorry, we could not display the entire diff because too many files (393) changed.
View
34 .project
@@ -1,17 +1,17 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>rpc-socket</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
- </natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>rpc-socket</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
+ </natures>
+</projectDescription>
View
24 .settings/.jsdtscope
@@ -1,12 +1,12 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path=""/>
- <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
- <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
- <attributes>
- <attribute name="hide" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="output" path=""/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path=""/>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
+ <attributes>
+ <attribute name="hide" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path=""/>
+</classpath>
View
6 .settings/org.eclipse.ltk.core.refactoring.prefs
@@ -1,3 +1,3 @@
-#Mon May 09 00:10:42 EDT 2011
-eclipse.preferences.version=1
-org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
+#Mon May 09 00:10:42 EDT 2011
+eclipse.preferences.version=1
+org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
View
84 dump/README.md
@@ -1,42 +1,42 @@
-JSON-RPC-Socket over many types of socket (TCP, WebSocket, HTTP).
-===
-
-So the idea behind this project is to create an easy to use JSON-RPC client and server setup.
-
-To build:
-
- NAN
-
-To run the tests:
-
- NAN
-
-
-Resources that are been used.
----
- - [nodejs.org](http://nodejs.org/)
-
-
-## What a node might look like.
-
- var node = {
- name : 'bobsNode',
- conn : [ {
- ip : '192.168.0.123',
- port : 43555,
- type : 'websocket'
- }, {
- ip : '192.168.0.123',
- port : 34434,
- type : 'http'
- } ],
- clients : [ 'jim', 'frank' ],
- nodes : [ 'jame', 'joe' ]
- };
-
-## ToDo List
- - connections.Client, is almost done.
- - connections.Server, Need to rewite the code for this method.
- - rpc, IM going to rewite this module to better fit heavy events.
-
-
+JSON-RPC-Socket over many types of socket (TCP, WebSocket, HTTP).
+===
+
+So the idea behind this project is to create an easy to use JSON-RPC client and server setup.
+
+To build:
+
+ NAN
+
+To run the tests:
+
+ NAN
+
+
+Resources that are been used.
+---
+ - [nodejs.org](http://nodejs.org/)
+
+
+## What a node might look like.
+
+ var node = {
+ name : 'bobsNode',
+ conn : [ {
+ ip : '192.168.0.123',
+ port : 43555,
+ type : 'websocket'
+ }, {
+ ip : '192.168.0.123',
+ port : 34434,
+ type : 'http'
+ } ],
+ clients : [ 'jim', 'frank' ],
+ nodes : [ 'jame', 'joe' ]
+ };
+
+## ToDo List
+ - connections.Client, is almost done.
+ - connections.Server, Need to rewite the code for this method.
+ - rpc, IM going to rewite this module to better fit heavy events.
+
+
View
34 dump/client.js
@@ -1,18 +1,18 @@
-var rpc = require('./lib/client');
-var args = process.argv;
-
-var name = args[args.indexOf('--name') + 1];
-var port = args[args.indexOf('--port') + 1];
-var host = args[args.indexOf('--host') + 1];
-var type = args[args.indexOf('--type') + 1];
-var help = args[args.indexOf('--help') + 1];
-
-if(port == 'node') {
- throw Error('port is missing try --port 8000')
-} else if(host == 'node') {
- throw Error('host is missing try --host 192.168.0.100')
-} else if(type == 'node') {
- throw Error('host is missing try --type websocket OR tcpsocket')
-}
-
+var rpc = require('./lib/client');
+var args = process.argv;
+
+var name = args[args.indexOf('--name') + 1];
+var port = args[args.indexOf('--port') + 1];
+var host = args[args.indexOf('--host') + 1];
+var type = args[args.indexOf('--type') + 1];
+var help = args[args.indexOf('--help') + 1];
+
+if(port == 'node') {
+ throw Error('port is missing try --port 8000')
+} else if(host == 'node') {
+ throw Error('host is missing try --host 192.168.0.100')
+} else if(type == 'node') {
+ throw Error('host is missing try --type websocket OR tcpsocket')
+}
+
var a = new rpc.Client(host, port, type)
View
64 dump/lib/client.js
@@ -1,33 +1,33 @@
-var rpc = require('./rpc');
-
-var utils = require('./utils');
-
-var os = require('./os');
-
-var connections = require('./connection');
-
-var config = require('./config');
-
-var keyGen = utils.keyGen
-
-/*-----------------------------------------------
- Client proto
- -----------------------------------------------*/
-var Client = exports.Client = function(name, type, ip, port) {
-
-
- this.id = keyGen()
-
- this.name = name;
- this.type = type;
- //
- this.ip = ip;
- this.port = port;
- //
- this.socket = null;
- this.active = true;
- //
- this.rpc = new rpc();
- this.os = new os(60);
-
+var rpc = require('./rpc');
+
+var utils = require('./utils');
+
+var os = require('./os');
+
+var connections = require('./connection');
+
+var config = require('./config');
+
+var keyGen = utils.keyGen
+
+/*-----------------------------------------------
+ Client proto
+ -----------------------------------------------*/
+var Client = exports.Client = function(name, type, ip, port) {
+
+
+ this.id = keyGen()
+
+ this.name = name;
+ this.type = type;
+ //
+ this.ip = ip;
+ this.port = port;
+ //
+ this.socket = null;
+ this.active = true;
+ //
+ this.rpc = new rpc();
+ this.os = new os(60);
+
};
View
16 dump/lib/config.js
@@ -1,9 +1,9 @@
-
-
-
-
-module.exports = {
- urls:{
- master:'http://master.com/init'
- }
+
+
+
+
+module.exports = {
+ urls:{
+ master:'http://master.com/init'
+ }
};
View
882 dump/lib/connection.js
@@ -1,442 +1,442 @@
-var net = require('net');
-
-var http = require('http');
-
-var events = require('events');
-
-var util = require('util');
-
-var WebSocketClient = require('websocket-client').WebSocket;
-
-var WebSocketServer = require("websocket-server");
-
-var utils = require('./utils');
-
-var keyGen = utils.keyGen;
-
-var httpResult = function(id, name, err, res) {
- this.id = name;
- this.name = name;
- this.err = err;
- this.result = res;
- return this;
-};
-
-/*******************************************************************************
- * Connection
- */
-var Connection = exports.Connection = function(socket) {
- events.EventEmitter.call(this);
-
- this.id = socket.__ID;
- // Keep track of what needs to be sent.
- this._quota = [];
- // is the socket still sending?
- this._isSending = false;
- // is the socket open?
- this._isOpen = false;
-
- this.socket = socket;
-
- this.on('write', this.write).on('_writeData', this._writeData);
-};
-
-// So will act like an event emitter
-util.inherits(Connection, events.EventEmitter);
-
-Connection.prototype.write = function(data) {
- this._quota.push(data);
- this.emit('_writeData');
- return this;
-};
-
-Connection.prototype._writeData = function() {
- var self = this;
- if (!this._isSending && this._quota.length >= 1) {
- var data = this._quota.shift();
-
- this._isSending = true;
- this.socket.write(data, function() {
- self._isSending = false;
- self.emit('_writeData');
- });
-
- }
- ;
-};
-
-/**
- *
- * @param port
- * "Port to bind to"
- * @param host
- * "Ip of the node to connect to"
- * @param type
- * "What type of connection is it? websocket or tcpsocket and tobe
- * httpsocket"
- * @param options
- * "Not used yet"
- * @returns this "So we can chain"
- */
-var Server = exports.Server = function(hosts, name, options) {
- events.EventEmitter.call(this);
-
- var self = this;
-
- // Keep track of what needs to be sent.
- this._quota = [];
- // is the socket still sending?
- this._isSending = false;
- // is the socket open?
- this._isOpen = false;
- this.sockets = {};
- this.servers = {};
- this.on('socket', function(socket) {
-
- if (!this.sockets.hasOwnProperty(socket.__ID)) {
- this.sockets[socket.__ID] = new Connection(socket);
- } else {
- throw new Error('Socket is already been used!');
- }
- }).on('socketData', function(id, data) {
- // maybe do some logging?
- this.emit('manager', id, data);
- }).on('socketClose', function(socket) {
- if (this.sockets.hasOwnProperty(socket.__ID)) {
- delete this.sockets[socket.__ID];
- } else {
- throw new Error('No such socket been closed!');
- }
- });
- // server events
- this.on('server', function(server) {
- if (!this.servers.hasOwnProperty(server.__ID)) {
- this.servers[server.__ID] = server;
- } else {
- throw new Error('Socket is already been used!');
- }
- }).on('serverClose', function(server) {
- if (this.servers.hasOwnProperty(server.__ID)) {
- delete this.servers[server.__ID];
- } else {
- throw new Error('No such socket been closed!');
- }
- });
-
- return this;
-};
-
-// So will act like an event emitter
-util.inherits(Server, events.EventEmitter);
-
-// PUBLICE METHODS----------------------
-
-// when ready connect. maybe not right away.
-Server.prototype.send = Server.prototype.write = function(id, data) {
-
- if (this.sockets.hasOwnProperty(id)) {
- this.sockets[id].write(data);
- } else {
- throw new Error('No socket with such id!');
- }
- return this;
-};
-
-Server.prototype.ws = function(port) {
- var self = this;
-
- var server = WebSocketServer.createServer();
-
- server.__ID = keyGen();
-
- server.on("connection", function(socket) {
- socket.__ID = keyGen();
-
- self.emit('socket', socket);
-
- socket.on("message", function(data) {
- self.emit('socketData', socket.__ID, data);
- }).on('close', function(data) {
- self.emit('socketClose', socket);
- });
- }).on("close", function(data) {
- self.emit('serverClose', server);
- });
- server.listen(port);
- this.emit('server', server);
-};
-
-Server.prototype.http = function(port, host) {
-
- var server = http.createServer();
- var self = this;
- server.on('request', function(request, response) {
- if (request.url.indexOf("favicon") >= 1) {
- response.writeHead(200, {
- 'Content-Type' : 'image/x-icon'
- });
- response.end("");
- return;
- } else if (request.method === "POST") {
-
- request.setEncoding('utf8');
-
- var data = [];
-
- if (!request.headers.hasOwnProperty('RPC-KEY-Node')) {
- var socket = {
- __ID : keyGen(),
- write : function() {
-
- }
- }
- response.writeHead(400, {
- 'Content-Type' : 'application/json',
- 'Connection' : 'close',
- 'RPC-KEY-Node' : keyGen()
- });
- response.end("");
- } else {
-
- request.on('data', function(chunk) {
- data.push(chunk);
- });
- request.on('end', function() {
- self.emit('socketData', socket.__ID, data);
- })
- }
- }
- }).listen(port, host || '127.0.0.1', function() {
- self.emit('server', server);
- });
-};
-
-Server.prototype.tcp = function(port) {
- var self = this;
- var server = net.createServer(function(socket) {
-
- socket.setEncoding('utf8');
- // set id.
- socket.__ID = keyGen();
-
- self.emit('socket', socket);
-
- socket.on('data', function(data) {
- self.emit('socketData', socket.__ID, data);
- }).on('close', function(data) {
- self.emit('socketClose', socket);
- });
- }).on("close", function(data) {
- self.emit('serverClose', server);
- });
-
- server.__ID = keyGen();
-
- server.listen(port);
- this.emit('server', server);
-
-};
-
-Server.prototype.broadcast = function(data) {
-
- var sockets = this.sockets;
- for ( var key in sockets) {
- sockets[key].write(data);
- }
- ;
-};
-
-Server.prototype.keys = function() {
- return Object.keys(this.sockets);
-};
-
-/**
- *
- * @param port
- * "Port to bind to"
- * @param host
- * "Ip of the node to connect to"
- * @param type
- * "What type of connection is it? websocket or tcpsocket and tobe
- * httpsocket"
- * @param options
- * "Not used yet"
- * @returns this "So we can chain"
- */
-var Client = exports.Client = function(hosts, name, options) {
- events.EventEmitter.call(this);
-
- var self = this;
-
- // Keep track of what needs to be sent.
- this._quota = [];
- // is the socket still sending?
- this._isSending = false;
- // is the socket open?
- this._isOpen = false;
- this.sockets = {};
-
-
- this.on('socket', function(socket) {
-
- if (!self.sockets.hasOwnProperty(socket.__ID)) {
- self.sockets[socket.__ID] = new Connection(socket);
- } else {
- throw new Error('Socket is already been used!');
- }
- }).on('socketData', function(id, data) {
- // maybe do some logging?
- this.emit('manager', id, data);
- }).on('socketClose', function(socket) {
- if (self.sockets.hasOwnProperty(socket.__ID)) {
- delete self.sockets[socket.__ID];
- } else {
- throw new Error('No such socket been closed!');
- }
- });
-
- return this;
-};
-
-// So will act like an event emitter
-util.inherits(Client, events.EventEmitter);
-
-// PUBLICE METHODS----------------------
-
-// when ready connect. maybe not right away.
-Client.prototype.send = Client.prototype.write = function(id, data) {
- console.log(id);
- if (this.sockets.hasOwnProperty(id)) {
- this.sockets[id].write(data);
- } else {
- throw new Error('No socket with such id!');
- }
- return this;
-};
-
-Client.prototype.ws = function(port, host) {
- var self = this;
-
- var socket = new WebSocketClient('ws://' + host + ':' + port + '/');
- // set the id.
- socket.__ID = keyGen();
- socket.on('open', function() {
- console.log(socket);
- self.emit('socket', socket);
- }).on('data', function(data) {
-
- console.log(data);
- self.emit('socketData', socket.__ID, data.toString('utf8'));
- }).on('close', function() {
- self.emit('close', socket);
- });
- return socket;
-};
-
-Client.prototype.poll = function(port, host) {
- var d = null;
- var c = null;
- var t = 0;
- var self = this;
- var socket = {
- write : function(data, callBack) {
- c = callBack;
- d = data;
- },
- __ID : keyGen()
- };
- var pollObject = {};
- var p = function() {
- self.http(port, host, d === null ? pollObject : d, function() {
- c === null ? null : c();
- c = null;
- d = null;
- p();
- });
- };
- p();
-
-};
-
-Client.prototype.http = function(port, host, data, url, callBack) {
- var self = this;
- if (typeof (url) === 'function') {
- callBack = url;
- url = 'http://' + host + ':' + port + '/rpc';
- }
-
- var httpClient = http.createClient(port, host);
-
- var request = httpClient.request('POST', url, {
- 'Time' : new Date(),
- 'Host' : host + ':' + port,
- 'X-Requested-With' : 'rpc-socket'
- });
-
- request.on('response', function(response) {
-
- var page = [];
-
- response.setEncoding('utf8');
-
- response.on('data', function(chunk) {
-
- page.push(chunk);
-
- });
-
- response.on('end', function() {
- callBack(page.join(''));
- });
- });
-
- request.end(JSON.stringify(data), 'utf8');
-};
-
-Client.prototype.tcp = function(port, host, callBack) {
- var self = this;
- var socket = net.Stream();
- // set the id.
- socket.__ID = keyGen();
-
- // set the encoding
- socket.setEncoding('utf8');
- // add the events
- socket.on('connect', function() {
- self.emit('socket', socket);
- }).on('data', function(data) {
- self.emit('socketData', socket.__ID, data);
- }).on('end', function() {
-
- }).on('timeout', function() {
-
- }).on('drain', function() {
-
- }).on('error', function() {
-
- }).on('close', function() {
- self.emit('socketClose', socket);
- }).connect(port, host, function() {
- // callBack(socket)
- });
-};
-
-Client.prototype.broadcast = function(data) {
-
- var sockets = this.sockets;
- for ( var key in sockets) {
- sockets[key].write(data);
- }
- ;
-};
-
-Client.prototype.keys = function() {
- return Object.keys(this.sockets);
-};
-
-// PUBLICE METHODS----------------------
-
-// when ready connect. maybe not right away.
-Client.prototype._writeData = function() {
-
+var net = require('net');
+
+var http = require('http');
+
+var events = require('events');
+
+var util = require('util');
+
+var WebSocketClient = require('websocket-client').WebSocket;
+
+var WebSocketServer = require("websocket-server");
+
+var utils = require('./utils');
+
+var keyGen = utils.keyGen;
+
+var httpResult = function(id, name, err, res) {
+ this.id = name;
+ this.name = name;
+ this.err = err;
+ this.result = res;
+ return this;
+};
+
+/*******************************************************************************
+ * Connection
+ */
+var Connection = exports.Connection = function(socket) {
+ events.EventEmitter.call(this);
+
+ this.id = socket.__ID;
+ // Keep track of what needs to be sent.
+ this._quota = [];
+ // is the socket still sending?
+ this._isSending = false;
+ // is the socket open?
+ this._isOpen = false;
+
+ this.socket = socket;
+
+ this.on('write', this.write).on('_writeData', this._writeData);
+};
+
+// So will act like an event emitter
+util.inherits(Connection, events.EventEmitter);
+
+Connection.prototype.write = function(data) {
+ this._quota.push(data);
+ this.emit('_writeData');
+ return this;
+};
+
+Connection.prototype._writeData = function() {
+ var self = this;
+ if (!this._isSending && this._quota.length >= 1) {
+ var data = this._quota.shift();
+
+ this._isSending = true;
+ this.socket.write(data, function() {
+ self._isSending = false;
+ self.emit('_writeData');
+ });
+
+ }
+ ;
+};
+
+/**
+ *
+ * @param port
+ * "Port to bind to"
+ * @param host
+ * "Ip of the node to connect to"
+ * @param type
+ * "What type of connection is it? websocket or tcpsocket and tobe
+ * httpsocket"
+ * @param options
+ * "Not used yet"
+ * @returns this "So we can chain"
+ */
+var Server = exports.Server = function(hosts, name, options) {
+ events.EventEmitter.call(this);
+
+ var self = this;
+
+ // Keep track of what needs to be sent.
+ this._quota = [];
+ // is the socket still sending?
+ this._isSending = false;
+ // is the socket open?
+ this._isOpen = false;
+ this.sockets = {};
+ this.servers = {};
+ this.on('socket', function(socket) {
+
+ if (!this.sockets.hasOwnProperty(socket.__ID)) {
+ this.sockets[socket.__ID] = new Connection(socket);
+ } else {
+ throw new Error('Socket is already been used!');
+ }
+ }).on('socketData', function(id, data) {
+ // maybe do some logging?
+ this.emit('manager', id, data);
+ }).on('socketClose', function(socket) {
+ if (this.sockets.hasOwnProperty(socket.__ID)) {
+ delete this.sockets[socket.__ID];
+ } else {
+ throw new Error('No such socket been closed!');
+ }
+ });
+ // server events
+ this.on('server', function(server) {
+ if (!this.servers.hasOwnProperty(server.__ID)) {
+ this.servers[server.__ID] = server;
+ } else {
+ throw new Error('Socket is already been used!');
+ }
+ }).on('serverClose', function(server) {
+ if (this.servers.hasOwnProperty(server.__ID)) {
+ delete this.servers[server.__ID];
+ } else {
+ throw new Error('No such socket been closed!');
+ }
+ });
+
+ return this;
+};
+
+// So will act like an event emitter
+util.inherits(Server, events.EventEmitter);
+
+// PUBLICE METHODS----------------------
+
+// when ready connect. maybe not right away.
+Server.prototype.send = Server.prototype.write = function(id, data) {
+
+ if (this.sockets.hasOwnProperty(id)) {
+ this.sockets[id].write(data);
+ } else {
+ throw new Error('No socket with such id!');
+ }
+ return this;
+};
+
+Server.prototype.ws = function(port) {
+ var self = this;
+
+ var server = WebSocketServer.createServer();
+
+ server.__ID = keyGen();
+
+ server.on("connection", function(socket) {
+ socket.__ID = keyGen();
+
+ self.emit('socket', socket);
+
+ socket.on("message", function(data) {
+ self.emit('socketData', socket.__ID, data);
+ }).on('close', function(data) {
+ self.emit('socketClose', socket);
+ });
+ }).on("close", function(data) {
+ self.emit('serverClose', server);
+ });
+ server.listen(port);
+ this.emit('server', server);
+};
+
+Server.prototype.http = function(port, host) {
+
+ var server = http.createServer();
+ var self = this;
+ server.on('request', function(request, response) {
+ if (request.url.indexOf("favicon") >= 1) {
+ response.writeHead(200, {
+ 'Content-Type' : 'image/x-icon'
+ });
+ response.end("");
+ return;
+ } else if (request.method === "POST") {
+
+ request.setEncoding('utf8');
+
+ var data = [];
+
+ if (!request.headers.hasOwnProperty('RPC-KEY-Node')) {
+ var socket = {
+ __ID : keyGen(),
+ write : function() {
+
+ }
+ }
+ response.writeHead(400, {
+ 'Content-Type' : 'application/json',
+ 'Connection' : 'close',
+ 'RPC-KEY-Node' : keyGen()
+ });
+ response.end("");
+ } else {
+
+ request.on('data', function(chunk) {
+ data.push(chunk);
+ });
+ request.on('end', function() {
+ self.emit('socketData', socket.__ID, data);
+ })
+ }
+ }
+ }).listen(port, host || '127.0.0.1', function() {
+ self.emit('server', server);
+ });
+};
+
+Server.prototype.tcp = function(port) {
+ var self = this;
+ var server = net.createServer(function(socket) {
+
+ socket.setEncoding('utf8');
+ // set id.
+ socket.__ID = keyGen();
+
+ self.emit('socket', socket);
+
+ socket.on('data', function(data) {
+ self.emit('socketData', socket.__ID, data);
+ }).on('close', function(data) {
+ self.emit('socketClose', socket);
+ });
+ }).on("close", function(data) {
+ self.emit('serverClose', server);
+ });
+
+ server.__ID = keyGen();
+
+ server.listen(port);
+ this.emit('server', server);
+
+};
+
+Server.prototype.broadcast = function(data) {
+
+ var sockets = this.sockets;
+ for ( var key in sockets) {
+ sockets[key].write(data);
+ }
+ ;
+};
+
+Server.prototype.keys = function() {
+ return Object.keys(this.sockets);
+};
+
+/**
+ *
+ * @param port
+ * "Port to bind to"
+ * @param host
+ * "Ip of the node to connect to"
+ * @param type
+ * "What type of connection is it? websocket or tcpsocket and tobe
+ * httpsocket"
+ * @param options
+ * "Not used yet"
+ * @returns this "So we can chain"
+ */
+var Client = exports.Client = function(hosts, name, options) {
+ events.EventEmitter.call(this);
+
+ var self = this;
+
+ // Keep track of what needs to be sent.
+ this._quota = [];
+ // is the socket still sending?
+ this._isSending = false;
+ // is the socket open?
+ this._isOpen = false;
+ this.sockets = {};
+
+
+ this.on('socket', function(socket) {
+
+ if (!self.sockets.hasOwnProperty(socket.__ID)) {
+ self.sockets[socket.__ID] = new Connection(socket);
+ } else {
+ throw new Error('Socket is already been used!');
+ }
+ }).on('socketData', function(id, data) {
+ // maybe do some logging?
+ this.emit('manager', id, data);
+ }).on('socketClose', function(socket) {
+ if (self.sockets.hasOwnProperty(socket.__ID)) {
+ delete self.sockets[socket.__ID];
+ } else {
+ throw new Error('No such socket been closed!');
+ }
+ });
+
+ return this;
+};
+
+// So will act like an event emitter
+util.inherits(Client, events.EventEmitter);
+
+// PUBLICE METHODS----------------------
+
+// when ready connect. maybe not right away.
+Client.prototype.send = Client.prototype.write = function(id, data) {
+ console.log(id);
+ if (this.sockets.hasOwnProperty(id)) {
+ this.sockets[id].write(data);
+ } else {
+ throw new Error('No socket with such id!');
+ }
+ return this;
+};
+
+Client.prototype.ws = function(port, host) {
+ var self = this;
+
+ var socket = new WebSocketClient('ws://' + host + ':' + port + '/');
+ // set the id.
+ socket.__ID = keyGen();
+ socket.on('open', function() {
+ console.log(socket);
+ self.emit('socket', socket);
+ }).on('data', function(data) {
+
+ console.log(data);
+ self.emit('socketData', socket.__ID, data.toString('utf8'));
+ }).on('close', function() {
+ self.emit('close', socket);
+ });
+ return socket;
+};
+
+Client.prototype.poll = function(port, host) {
+ var d = null;
+ var c = null;
+ var t = 0;
+ var self = this;
+ var socket = {
+ write : function(data, callBack) {
+ c = callBack;
+ d = data;
+ },
+ __ID : keyGen()
+ };
+ var pollObject = {};
+ var p = function() {
+ self.http(port, host, d === null ? pollObject : d, function() {
+ c === null ? null : c();
+ c = null;
+ d = null;
+ p();
+ });
+ };
+ p();
+
+};
+
+Client.prototype.http = function(port, host, data, url, callBack) {
+ var self = this;
+ if (typeof (url) === 'function') {
+ callBack = url;
+ url = 'http://' + host + ':' + port + '/rpc';
+ }
+
+ var httpClient = http.createClient(port, host);
+
+ var request = httpClient.request('POST', url, {
+ 'Time' : new Date(),
+ 'Host' : host + ':' + port,
+ 'X-Requested-With' : 'rpc-socket'
+ });
+
+ request.on('response', function(response) {
+
+ var page = [];
+
+ response.setEncoding('utf8');
+
+ response.on('data', function(chunk) {
+
+ page.push(chunk);
+
+ });
+
+ response.on('end', function() {
+ callBack(page.join(''));
+ });
+ });
+
+ request.end(JSON.stringify(data), 'utf8');
+};
+
+Client.prototype.tcp = function(port, host, callBack) {
+ var self = this;
+ var socket = net.Stream();
+ // set the id.
+ socket.__ID = keyGen();
+
+ // set the encoding
+ socket.setEncoding('utf8');
+ // add the events
+ socket.on('connect', function() {
+ self.emit('socket', socket);
+ }).on('data', function(data) {
+ self.emit('socketData', socket.__ID, data);
+ }).on('end', function() {
+
+ }).on('timeout', function() {
+
+ }).on('drain', function() {
+
+ }).on('error', function() {
+
+ }).on('close', function() {
+ self.emit('socketClose', socket);
+ }).connect(port, host, function() {
+ // callBack(socket)
+ });
+};
+
+Client.prototype.broadcast = function(data) {
+
+ var sockets = this.sockets;
+ for ( var key in sockets) {
+ sockets[key].write(data);
+ }
+ ;
+};
+
+Client.prototype.keys = function() {
+ return Object.keys(this.sockets);
+};
+
+// PUBLICE METHODS----------------------
+
+// when ready connect. maybe not right away.
+Client.prototype._writeData = function() {
+
};
View
298 dump/lib/manager.js
@@ -1,149 +1,149 @@
-var fs = require('fs');
-
-var rpc = require('./rpc');
-
-var utils = require('./utils');
-
-var util = require('util');
-var events = require('events');
-
-var os = require('./os');
-
-var connections = require('./connection');
-
-var config = require('./config');
-
-var keyGen = utils.keyGen;
-Object.prototype.clone = function() {
- var newObj = (this instanceof Array) ? [] : {};
- for (i in this) {
- if (i == 'clone')
- continue;
- if (this[i] && typeof this[i] == "object") {
- newObj[i] = this[i].clone();
- } else
- newObj[i] = this[i];
- }
- return newObj;
-};
-var createNode = function(info, socket) {
- this.name = info.name;
- this.conn = info.conn;
- this.clients = info.clients;
- this.socket = socket;
-};
-
-var node = {
- name : 'bobsNode',
- conn : [ {
- ip : '192.168.0.123',
- port : 43555,
- type : 'websocket'
- }, {
- ip : '192.168.0.123',
- port : 34434,
- type : 'http'
- } ],
- clients : [ 'jim', 'frank' ],
- nodes : [ 'jame', 'joe' ]
-};
-
-var Manager = exports.Manager = function() {
-
- events.EventEmitter.call(this);
- var self = this;
- // not used yet.
- this.routes = {};
-
- // if is a server this will be an object of servers.
- this.server = null;
- // An object of clients.
- this.client = null;
- this.rpc = new rpc();
-
- this.types = {
- client : null,
- server : null
- };
-
- // Attach some events
- this.on('unWrap', this.unWrap).on('wrap', this.wrap).on('rpc', this._rpc);
- this.build();
-
- //var s = this.types.client.ws(80, 'echo.websocket.org');
-
-};
-
-// So will act like an event emitter
-util.inherits(Manager, events.EventEmitter);
-
-// Next version this will come.
-Manager.prototype.send = function(type, id, data) {
- console.log(id);
- this.types[type].send(id, data);
-};
-// Next version this will come.
-Manager.prototype.broadcast = function(data) {
- this.types.client.broadcast(data);
- this.types.server.broadcast(data);
-};
-//
-Manager.prototype._rpc = function(type, id, routes, data) {
- var self = this;
- data.__ID = id;
- this.rpc.extend(data, function(result) {
- self.emit('wrap', type, id, routes, result);
- });
- return this;
-};
-/*******************************************************************************
- * Manager.build
- */
-Manager.prototype.build = function() {
-
- var client = this.types.client = new connections.Client([], 'someGreatName!', {});
- var self = this;
-
- client.on('manager', function(id, data) {
- self.emit('unWrap', 'client', id, data);
- });
-
- var server = this.types.server = new connections.Server([], 'someGreatName!', {});
- var self = this;
- setInterval(function timmer(){
- console.log(self)
- }, 1000);
- server.on('manager', function(id, data) {
- self.emit('unWrap', 'server', id, data);
- });
-};
-/*******************************************************************************
- * Manager.buildServer
- */
-Manager.prototype.buildServer = function() {
-
-};
-
-Manager.prototype.unWrap = function(type, id, data) {
- var a = data.split('$wrap$');
- for ( var i = a.length - 1; i >= 0; i--) {
- if (a[i] === '') {
- continue;
- }
- var aa = a[i].split('$wrapEnd$')[0];
- var data = JSON.parse(aa.split('$data$')[1].split('$dataEnd$')[0]);
- var routes = aa.split('$route$')[1].split('$routeEnd$')[0].split('|');
- this.emit('rpc', type, id, routes, data);// line was to long.
- }
-};
-Manager.prototype.wrap = function(type, id, routes, result) {
- var str = [];
- str.push('$wrap$');
-
- str.push('$route$' + routes.join('|') + '$routeEnd$');
-
- str.push('$data$' + JSON.stringify(result) + '$dataEnd$');
-
- str.push('$wrapEnd$');
- this.send(type, id, str.join(''));
-};
+var fs = require('fs');
+
+var rpc = require('./rpc');
+
+var utils = require('./utils');
+
+var util = require('util');
+var events = require('events');
+
+var os = require('./os');
+
+var connections = require('./connection');
+
+var config = require('./config');
+
+var keyGen = utils.keyGen;
+Object.prototype.clone = function() {
+ var newObj = (this instanceof Array) ? [] : {};
+ for (i in this) {
+ if (i == 'clone')
+ continue;
+ if (this[i] && typeof this[i] == "object") {
+ newObj[i] = this[i].clone();
+ } else
+ newObj[i] = this[i];
+ }
+ return newObj;
+};
+var createNode = function(info, socket) {
+ this.name = info.name;
+ this.conn = info.conn;
+ this.clients = info.clients;
+ this.socket = socket;
+};
+
+var node = {
+ name : 'bobsNode',
+ conn : [ {
+ ip : '192.168.0.123',
+ port : 43555,
+ type : 'websocket'
+ }, {
+ ip : '192.168.0.123',
+ port : 34434,
+ type : 'http'
+ } ],
+ clients : [ 'jim', 'frank' ],
+ nodes : [ 'jame', 'joe' ]
+};
+
+var Manager = exports.Manager = function() {
+
+ events.EventEmitter.call(this);
+ var self = this;
+ // not used yet.
+ this.routes = {};
+
+ // if is a server this will be an object of servers.
+ this.server = null;
+ // An object of clients.
+ this.client = null;
+ this.rpc = new rpc();
+
+ this.types = {
+ client : null,
+ server : null
+ };
+
+ // Attach some events
+ this.on('unWrap', this.unWrap).on('wrap', this.wrap).on('rpc', this._rpc);
+ this.build();
+
+ //var s = this.types.client.ws(80, 'echo.websocket.org');
+
+};
+
+// So will act like an event emitter
+util.inherits(Manager, events.EventEmitter);
+
+// Next version this will come.
+Manager.prototype.send = function(type, id, data) {
+ console.log(id);
+ this.types[type].send(id, data);
+};
+// Next version this will come.
+Manager.prototype.broadcast = function(data) {
+ this.types.client.broadcast(data);
+ this.types.server.broadcast(data);
+};
+//
+Manager.prototype._rpc = function(type, id, routes, data) {
+ var self = this;
+ data.__ID = id;
+ this.rpc.extend(data, function(result) {
+ self.emit('wrap', type, id, routes, result);
+ });
+ return this;
+};
+/*******************************************************************************
+ * Manager.build
+ */
+Manager.prototype.build = function() {
+
+ var client = this.types.client = new connections.Client([], 'someGreatName!', {});
+ var self = this;
+
+ client.on('manager', function(id, data) {
+ self.emit('unWrap', 'client', id, data);
+ });
+
+ var server = this.types.server = new connections.Server([], 'someGreatName!', {});
+ var self = this;
+ setInterval(function timmer(){
+ console.log(self)
+ }, 1000);
+ server.on('manager', function(id, data) {
+ self.emit('unWrap', 'server', id, data);
+ });
+};
+/*******************************************************************************
+ * Manager.buildServer
+ */
+Manager.prototype.buildServer = function() {
+
+};
+
+Manager.prototype.unWrap = function(type, id, data) {
+ var a = data.split('$wrap$');
+ for ( var i = a.length - 1; i >= 0; i--) {
+ if (a[i] === '') {
+ continue;
+ }
+ var aa = a[i].split('$wrapEnd$')[0];
+ var data = JSON.parse(aa.split('$data$')[1].split('$dataEnd$')[0]);
+ var routes = aa.split('$route$')[1].split('$routeEnd$')[0].split('|');
+ this.emit('rpc', type, id, routes, data);// line was to long.
+ }
+};
+Manager.prototype.wrap = function(type, id, routes, result) {
+ var str = [];
+ str.push('$wrap$');
+
+ str.push('$route$' + routes.join('|') + '$routeEnd$');
+
+ str.push('$data$' + JSON.stringify(result) + '$dataEnd$');
+
+ str.push('$wrapEnd$');
+ this.send(type, id, str.join(''));
+};
View
476 dump/lib/node.js
@@ -1,239 +1,239 @@
-var http = require('http');
-
-var net = require('net');
-
-var ws = require("websocket-server");
-
-var rpc = require('./rpc');
-
-var utils = require('./utils');
-
-var os = require('./os');
-
-var connections = require('./connection');
-
-var config = require('./config');
-
-var keyGen = utils.keyGen
-
-var clientTmpl = function(ip, wtire, message) {
- this.ip = ip;
- this.write = wtire;
- this.message = message;
- this.info = null;
-}
-var node = module.exports = function(name ,type, ip, port) {
- //
- this.name = name;
- this.type = type;
- this.ip = ip;
- this.port = port;
- //
- this.routeServerPort = 43098;
- //
- this.promises = {}
- //
- this.server = null;
- this.routeServer = null;
- //
- this.nodeList = {};
- this.clientList = {};
- this.clients = {};
- //
- var self = this;
- //
-
- this.write = function(data, callBack) {
- if(data.hasOwnProperty('id') && data.hasOwnProperty('method')) {
- if(!self.promises.hasOwnProperty(data.id)) {
- self.promises[data.id] = callBack
- write(data)
- } else {
- throw Error('Same id been used for a client write.')
- }
- }
- }
- //
- this.rpc = new rpc();
- this.os = new os(60);
- //
- this.buildRpc()
- //
- this.build()
-
-};
-node.prototype.build = function() {
- var self = this;
- if(this.type == 'socket') {
- this.server = new connections.socketServer(this.port, this.ip, function(conn) {
-
- conn.message = function(data) {
- if(data.hasOwnProperty('result') && data.hasOwnProperty('id') && self.promises.hasOwnProperty(data.id)) {
-
- self.promises[data.id](data)
- delete self.promises[data.id];
- return;
- }
- console.log(data)
- self.rpc.extend(data, function(result) {
- conn.write(result)
- })
- };
- conn.end = function() {
-
- if(self.clients[conn.ip].hasOwnProperty('name')) {
-
- delete self.clientList[self.clients[conn.ip].name];
- }
-
- delete self.clients[conn.ip]
- };
- self.clients[conn.ip] = conn;
-
- console.log(self)
- })
- }
-}
-node.prototype.buildBackHaul = function() {
-
-
-
-
- this.routeServer = new connections.socketServer(this.routeServerPort, this.ip, function(conn) {
-
- conn.message = function(data) {
-
- };
- conn.end = function() {
-
- };
-
- })
-}
-node.prototype.buildRpc = function() {
- var self = this;
- this.rpc.on('client', {
- 'logon': function(key, name, client) {
- if(!(key && name && client && client.ip)) {
- this.error({
- error:'Missing param',
- code:3
- }).send()
- } else {
- if(key == config.auth.key) {
- if(!self.clientList.hasOwnProperty(name)) {
-
- self.clientList[name] = client;
- self.clients[client.ip].name = name;
- this.result({
- name:self.name,
- os:self.os
- }).send()
- } else {
- this.error({
- error:'Name taken.',
- code:0
- }).send()
- }
- } else {
-
- this.error({
- error:'Key wrong',
- code:1
- }).send()
- }
- }
- },
- 'logoff': function(name) {
- if(!(key && name && client)) {
- this.error({
- error:'Missing param',
- code:3
- }).send()
- } else {
- if(self.clientList.hasOwnProperty(name)) {
- delete self.clientList[name];
- this.result(true).send();
- } else {
- this.error({
- error:'Name not registered.',
- code:2
- }).send();
- }
- }
- },
- 'active': function(name) {
- if(!(name)) {
- this.error({
- error:'Missing param',
- code:3
- }).send()
- } else {
- if(self.clientList.hasOwnProperty(name)) {
- self.clientList[name].active = true;
- this.result(true).send();
- } else {
- this.error({
- error:'Name not registered.',
- code:2
- }).send();
- }
- }
- },
- 'notActive': function(name) {
- if(!(name)) {
- this.error({
- error:'Missing param',
- code:3
- }).send()
- } else {
- if(self.clientList.hasOwnProperty(name)) {
- self.clientList[name].active = false;
- this.result(true).send();
- } else {
- this.error({
- error:'Name not registered.',
- code:2
- }).send();
- }
- }
- },
- 'clientList': function(name) {
- if(!(name)) {
- this.error({
- error:'Missing param',
- code:3
- }).send()
- } else {
- if(self.clientList.hasOwnProperty(name)) {
- this.result(clientList).send();
- } else {
- this.error({
- error:'Name not registered.',
- code:2
- }).send();
- }
- }
-
- },
- 'nodeList': function(name) {
- if(!(name)) {
- this.error({
- error:'Missing param',
- code:3
- }).send()
- } else {
- if(self.clientList.hasOwnProperty(name)) {
- this.result(nodeList).send();
- } else {
- this.error({
- error:'Name not registered.',
- code:2
- }).send();
- }
- }
- }
- });
-
-
+var http = require('http');
+
+var net = require('net');
+
+var ws = require("websocket-server");
+
+var rpc = require('./rpc');
+
+var utils = require('./utils');
+
+var os = require('./os');
+
+var connections = require('./connection');
+
+var config = require('./config');
+
+var keyGen = utils.keyGen
+
+var clientTmpl = function(ip, wtire, message) {
+ this.ip = ip;
+ this.write = wtire;
+ this.message = message;
+ this.info = null;
+}
+var node = module.exports = function(name ,type, ip, port) {
+ //
+ this.name = name;
+ this.type = type;
+ this.ip = ip;
+ this.port = port;
+ //
+ this.routeServerPort = 43098;
+ //
+ this.promises = {}
+ //
+ this.server = null;
+ this.routeServer = null;
+ //
+ this.nodeList = {};
+ this.clientList = {};
+ this.clients = {};
+ //
+ var self = this;
+ //
+
+ this.write = function(data, callBack) {
+ if(data.hasOwnProperty('id') && data.hasOwnProperty('method')) {
+ if(!self.promises.hasOwnProperty(data.id)) {
+ self.promises[data.id] = callBack
+ write(data)
+ } else {
+ throw Error('Same id been used for a client write.')
+ }
+ }
+ }
+ //
+ this.rpc = new rpc();
+ this.os = new os(60);
+ //
+ this.buildRpc()
+ //
+ this.build()
+
+};
+node.prototype.build = function() {
+ var self = this;
+ if(this.type == 'socket') {
+ this.server = new connections.socketServer(this.port, this.ip, function(conn) {
+
+ conn.message = function(data) {
+ if(data.hasOwnProperty('result') && data.hasOwnProperty('id') && self.promises.hasOwnProperty(data.id)) {
+
+ self.promises[data.id](data)
+ delete self.promises[data.id];
+ return;
+ }
+ console.log(data)
+ self.rpc.extend(data, function(result) {
+ conn.write(result)
+ })
+ };
+ conn.end = function() {
+
+ if(self.clients[conn.ip].hasOwnProperty('name')) {
+
+ delete self.clientList[self.clients[conn.ip].name];
+ }
+
+ delete self.clients[conn.ip]
+ };
+ self.clients[conn.ip] = conn;
+
+ console.log(self)
+ })
+ }
+}
+node.prototype.buildBackHaul = function() {
+
+
+
+
+ this.routeServer = new connections.socketServer(this.routeServerPort, this.ip, function(conn) {
+
+ conn.message = function(data) {
+
+ };
+ conn.end = function() {
+
+ };
+
+ })
+}
+node.prototype.buildRpc = function() {
+ var self = this;
+ this.rpc.on('client', {
+ 'logon': function(key, name, client) {
+ if(!(key && name && client && client.ip)) {
+ this.error({
+ error:'Missing param',
+ code:3
+ }).send()
+ } else {
+ if(key == config.auth.key) {
+ if(!self.clientList.hasOwnProperty(name)) {
+
+ self.clientList[name] = client;
+ self.clients[client.ip].name = name;
+ this.result({
+ name:self.name,
+ os:self.os
+ }).send()
+ } else {
+ this.error({
+ error:'Name taken.',
+ code:0
+ }).send()
+ }
+ } else {
+
+ this.error({
+ error:'Key wrong',
+ code:1
+ }).send()
+ }
+ }
+ },
+ 'logoff': function(name) {
+ if(!(key && name && client)) {
+ this.error({
+ error:'Missing param',
+ code:3
+ }).send()
+ } else {
+ if(self.clientList.hasOwnProperty(name)) {
+ delete self.clientList[name];
+ this.result(true).send();
+ } else {
+ this.error({
+ error:'Name not registered.',
+ code:2
+ }).send();
+ }
+ }
+ },
+ 'active': function(name) {
+ if(!(name)) {
+ this.error({
+ error:'Missing param',
+ code:3
+ }).send()
+ } else {
+ if(self.clientList.hasOwnProperty(name)) {
+ self.clientList[name].active = true;
+ this.result(true).send();
+ } else {
+ this.error({
+ error:'Name not registered.',
+ code:2
+ }).send();
+ }
+ }
+ },
+ 'notActive': function(name) {
+ if(!(name)) {
+ this.error({
+ error:'Missing param',
+ code:3
+ }).send()
+ } else {
+ if(self.clientList.hasOwnProperty(name)) {
+ self.clientList[name].active = false;
+ this.result(true).send();
+ } else {
+ this.error({
+ error:'Name not registered.',
+ code:2
+ }).send();
+ }
+ }
+ },
+ 'clientList': function(name) {
+ if(!(name)) {
+ this.error({
+ error:'Missing param',
+ code:3
+ }).send()
+ } else {
+ if(self.clientList.hasOwnProperty(name)) {
+ this.result(clientList).send();
+ } else {
+ this.error({
+ error:'Name not registered.',
+ code:2
+ }).send();
+ }
+ }
+
+ },
+ 'nodeList': function(name) {
+ if(!(name)) {
+ this.error({
+ error:'Missing param',
+ code:3
+ }).send()
+ } else {
+ if(self.clientList.hasOwnProperty(name)) {
+ this.result(nodeList).send();
+ } else {
+ this.error({
+ error:'Name not registered.',
+ code:2
+ }).send();
+ }
+ }
+ }
+ });
+
+
};
View
90 dump/lib/os.js
@@ -1,46 +1,46 @@
-var os = require('os');
-
-var OS = module.exports = function(updateTime) {
-
- this.cpus = os.cpus();
- this.hostname = os.hostname();
- this.type = os.type();
- this.release = os.release();
- this.uptime = os.uptime();
- this.loadavg = os.loadavg();
- this.totalmem = os.totalmem();
- this.freemem = os.freemem();
- this.timer = typeof(updateTime) == 'number' ? updateTime * 1000 : false;
-
-
- this.timerUpdate()
-
- var self = this;
- var oldTimer = updateTime;
- this.stop = function(){
- if(oldTimer && this.timer){
- this.timer = false;
- }
- }
- this.start = function(){
- if(oldTimer && !this.timer){
- this.timer = oldTimer;
- }
- }
-};
-OS.prototype.timerUpdate = function() {
- var self = this;
- if(self.timer) {
- setTimeout( function() {
- self.update();
- self.timerUpdate()
- },this.timer)
- }
-}
-OS.prototype.update = function() {
- console.log('OS.TIMMER')
- this.uptime = os.uptime();
- this.loadavg = os.loadavg();
- this.totalmem = os.totalmem();
- this.freemem = os.freemem();
+var os = require('os');
+
+var OS = module.exports = function(updateTime) {
+
+ this.cpus = os.cpus();
+ this.hostname = os.hostname();
+ this.type = os.type();
+ this.release = os.release();
+ this.uptime = os.uptime();
+ this.loadavg = os.loadavg();
+ this.totalmem = os.totalmem();
+ this.freemem = os.freemem();
+ this.timer = typeof(updateTime) == 'number' ? updateTime * 1000 : false;
+
+
+ this.timerUpdate()
+
+ var self = this;
+ var oldTimer = updateTime;
+ this.stop = function(){
+ if(oldTimer && this.timer){
+ this.timer = false;
+ }
+ }
+ this.start = function(){
+ if(oldTimer && !this.timer){
+ this.timer = oldTimer;
+ }
+ }
+};
+OS.prototype.timerUpdate = function() {
+ var self = this;
+ if(self.timer) {
+ setTimeout( function() {
+ self.update();
+ self.timerUpdate()
+ },this.timer)
+ }
+}
+OS.prototype.update = function() {
+ console.log('OS.TIMMER')
+ this.uptime = os.uptime();
+ this.loadavg = os.loadavg();
+ this.totalmem = os.totalmem();
+ this.freemem = os.freemem();
};
View
598 dump/lib/rpc.js
@@ -1,300 +1,300 @@
-var fs = require('fs');
-
-var util = require('util');
-
-var events = require('events');
-
-var config = require('./config');
-
-var utils = require('./utils');
-
-var keyGen = utils.keyGen
-
-var promise = {};
-
-var Rpc = module.exports = function() {
-
- var self = this;
- this.counter = 0;
- this.functions = {};
- this.emitter = new (require("events")).EventEmitter;
- this.emitter.on('handleRequest', function(message, id, callBack) {
-
- if (!(message.method && message.params)) {
- return callBack({
- 'result' : null,
- 'error' : INVALID_REQUEST,
- 'id' : id
- })
- }
-
- if (!self.functions.hasOwnProperty(message.method)) {
- return callBack({
- 'result' : null,
- 'error' : METHOD_NOT_ALLOWED,
- 'id' : id
- })
- }
-
- var method = self.functions[message.method];
- // message.params.push(connId);
- this.counter++;
- var result = {
- id : id,
- result : null,
- error : null
- };
- var obj = {
- id : id,
- result : function(r) {
- result.result = r;
- return this;
- },
- error : function(e) {
- result.error = e;
- return this;
- },
- send : function() {
- if (result.error !== null) {
- callBack(result)
- return true;
- } else if (result.result !== null) {
- callBack(result)
- return true;
- } else {
- return false;
- }
- }
- }
- method.apply(obj, message.params);
- });
- this.on('list', function() {
- var list = [];
- for ( var key in self.functions) {
- list.push(key)
- }
- this.result(list).send()
- })
- return this;
-}
-Rpc.prototype.on = function(mod, object) {
-
- if (typeof (object) === 'object') {
-
- var funcs = [];
-
- for ( var funcName in object) {
- var funcObj = object[funcName];
- if (typeof (funcObj) == 'function') {
- this.functions[mod + '.' + funcName] = funcObj;
- funcs.push(funcName);
- }
- }
-
- console.log('RPC' + 'exposing module: ' + mod + ' [funs: ' + funcs.join(', ') + ']' + 'pass');
-
- } else if (typeof (object) == 'function') {
-
- this.functions[mod] = object;
-
- }
-
- return this;
-}
-Rpc.prototype.expose = function(message, callBack) {
-
- // log('RPC', 'exposing ' + name + ' ', 'pass');
-
- this.functions[name] = func;
-
- return this;
-};
-Rpc.prototype.extend = function(data, callBack) {
-
- if (data.hasOwnProperty('id') && data.hasOwnProperty('__ID') && data.hasOwnProperty('method') && data.hasOwnProperty('params')) {
-
- this.emitter.emit('handleRequest', data, data.id, callBack);
- }
-
- return this;
-};
-Rpc.prototype.fireEvent = function(method, params, callBack) {
- var id = keyGen()
- var encoded = {
- 'method' : method,
- 'params' : params,
- 'id' : id
- };
- this.emitter.emit('handleRequest', encoded, id, callBack);
- return this;
-}
-
-// ==========new rpc==========//
-
-var Exposed = function(message, info, send) {
- // Hidding it for now but need to move into own file.
-
- events.EventEmitter.call(this);
-
- var hasSent = false;
- this.setartTime = new Date().getTime();
- this.id = message.id;
- this.method = message.method;
- this.params = message.params;
- this.info = info;
- this.result = [];
- this.error = [];
- ;
-
- //
- this.on('send', function send() {
- if (hasSent) {
- throw new Error('should not sent twice.')
- }
- send({
- id : this.id,
- result : this.result,
- error : this.error
- })
- });
- //
- this.on('result', this.pushResult);
- this.on('error', this.pushError);
- return this;
-};
-
-// So will act like an event emitter
-util.inherits(Exposed, events.EventEmitter);
-
-Exposed.prototype.send = function() {
- this.emit('send')
-};
-Exposed.prototype.pushResult = function(data) {
- this.result.push(data)
- return this;
-};
-Exposed.prototype.pushError = function(msg, code) {
- this.error.push({
- message : msg,
- code : code || 1000
- })
- return this;
-};
-
-var rpc = function() {
-
- var self = this;
- this.counter = 0;
-
- this.functions = {};
- var METHOD_NOT_ALLOWED = "Method Not Allowed";
- var INVALID_REQUEST = "Invalid Request";
- this.on('handleRequest', this._handleRequest).on('applyFunc', this._applyFunc)
- this.on('trigger', this.trigger)
-
- this.expose('list', function() {
- var list = [];
- for ( var key in self.functions) {
- list.push(key);
- }
- this.pushResult(list).send();
- });
-};
-
-// So will act like an event emitter
-util.inherits(rpc, events.EventEmitter);
-
-rpc.prototype.Exposed = Exposed
-
-rpc.prototype._handleRequest = function(message, info, callBack) {
-
- if (!message.hasOwnProperty('id')) {
- return callBack({
- 'result' : null,
- 'error' : {
- 'message' : METHOD_NOT_ALLOWED,
- 'code' : 1001
- },
- 'id' : null
- });
- }
- if (!(message.hasOwnProperty('method') && typeof (message.method) === 'string' && message.hasOwnProperty('params'))) {
- return callBack({
- 'result' : null,
- 'error' : {
- 'message' : METHOD_NOT_ALLOWED,
- 'code' : 1002
- },
- 'id' : message.id
- });
- }
-
- if (!this.functions.hasOwnProperty(message.method)) {
- return callBack({
- 'result' : null,
- 'error' : {
- 'message' : INVALID_REQUEST,
- 'code' : 1003
- },
- 'id' : message.id
- });
- }
-
- var exsosed = new this.Exposed(message, info, callBack);
-
- var method = this.functions[message.method];
- // message.params.push(connId);
- this.counter++;
- this.emit('applyFunc', method, exsosed);
-
-};
-//
-rpc.prototype._applyFunc = function(method, exsosed) {
- try {
- method.apply(exsosed, exsosed.info().params);
-
- } catch (err) {
- console.log(err)
- throw new Error('Got a error calling function ' + exsosed.info().method)
- }
-}
-//
-rpc.prototype.expose = function(mod, object) {
- if (typeof (object) === 'object') {
-
- var funcs = [];
-
- for ( var funcName in object) {
- var funcObj = object[funcName];
- if (typeof (funcObj) == 'function') {
- this.functions[mod + '.' + funcName] = funcObj;
- funcs.push(funcName);
- }
- }
-
- this.log('RPC' + 'exposing module: ' + mod + ' [funs: ' + funcs.join(', ') + ']' + 'pass');
-
- } else if (typeof (object) == 'function') {
-
- this.functions[mod] = object;
-
- }
-
- return this;
-}