From 87f4f85e885f9ecb4c6bfff7151fa614da315e57 Mon Sep 17 00:00:00 2001 From: Sridatta Thatipamala Date: Mon, 18 Apr 2011 14:54:14 -0700 Subject: [PATCH 1/4] Switched from timestamp call signatures to 10 char random strings. --- lib/nowServerLib.js | 4 ++-- lib/nowUtil.js | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/nowServerLib.js b/lib/nowServerLib.js index 0ea0873..347fd64 100644 --- a/lib/nowServerLib.js +++ b/lib/nowServerLib.js @@ -109,7 +109,7 @@ var nowCore = { constructRemoteFunction: function(client, fqn) { nowUtil.debug("constructRemoteFunction", fqn); var remoteFn = function() { - var callId = fqn+ "_"+ new Date().getTime(); + var callId = fqn+ "_"+ nowUtil.generateRandomString(10); nowUtil.debug("executeRemoteFunction", fqn + ", " + callId); @@ -117,7 +117,7 @@ var nowCore = { for(var i in theArgs){ if(typeof theArgs[i] === 'function'){ - var closureId = "closure" + "_" + theArgs[i].name + "_" + new Date().getTime(); + var closureId = "closure" + "_" + theArgs[i].name + "_" + nowUtil.generateRandomString(10); nowCore.closures[closureId] = theArgs[i]; theArgs[i] = {type: 'function', fqn: closureId}; } diff --git a/lib/nowUtil.js b/lib/nowUtil.js index 2363ecb..3ea307a 100644 --- a/lib/nowUtil.js +++ b/lib/nowUtil.js @@ -337,7 +337,7 @@ }, debug: function(func, msg){ - // console.log(func + ": " + msg); + //console.log(func + ": " + msg); }, error: function(err){ @@ -516,14 +516,24 @@ } } + }, + + generateRandomString: function(length){ + var charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + var randomString = ''; + for (var i = 0; i < length; i++) { + var randomPoz = Math.floor(Math.random() * charSet.length); + randomString += charSet.substring(randomPoz,randomPoz+1); + } + return randomString; } }; if('window' in this) { - window.nowUtil = nowUtil; if(!('JSON' in window)){ + console.log("Using this PoS non-native JSON shim"); JSON={}; (function(){"use strict";function f(n){return n<10?'0'+n:n;} if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+ From 613e379cd35349d212444d698a0267897dcabde5 Mon Sep 17 00:00:00 2001 From: Sridatta Thatipamala Date: Thu, 21 Apr 2011 16:06:29 -0700 Subject: [PATCH 2/4] Fixed bug in wrap.js with binding functions properly --- lib/nowServerLib.js | 2 +- lib/wrap.js | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/nowServerLib.js b/lib/nowServerLib.js index 347fd64..048abaf 100644 --- a/lib/nowServerLib.js +++ b/lib/nowServerLib.js @@ -60,7 +60,7 @@ var nowCore = { // Create proxy object - nowCore.proxies[client.sessionId] = proxy.wrap(nowCore.constructClientScopeStore(client), scope); + nowCore.proxies[client.sessionId] = proxy.wrap(nowCore.constructClientScopeStore(client), scope, client.sessionId); nowCore.scopes[client.sessionId] = scope; nowCore.clientGroups[client.sessionId] = []; diff --git a/lib/wrap.js b/lib/wrap.js index 9649c24..4730c70 100644 --- a/lib/wrap.js +++ b/lib/wrap.js @@ -1,22 +1,26 @@ var Proxy = require('node-proxy'); -exports.wrap = function (store, sessions) { +exports.wrap = function (store, sessions, clientId) { var taint = {}; var taintedFqns = {}; var set = store ? (store.set || store.save).bind(store) : null; var theProxy = Proxy.create({ get : function (recv, name) { - if (name === 'toJSON' && !sessions.hasOwnProperty(name)) { - return function () { return sessions } - } - else { - var returnObj = wrapRoot(name, sessions[name], '["'+name+'"]', theProxy); - if(typeof returnObj === 'function' && sessions.hasOwnProperty(name)){ - returnObj = returnObj.bind({now: theProxy}) - } - return returnObj; - } + if (name === 'toJSON' && !sessions.hasOwnProperty(name)) { + return function () { return sessions; }; + } + else { + var returnObj = wrapRoot(name, sessions[name], '["'+name+'"]', theProxy); + if(typeof returnObj === 'function' && sessions.hasOwnProperty(name)){ + if(clientId){ + returnObj = returnObj.bind({now: theProxy, user:{clientId: clientId}}); + } else { + returnObj = returnObj.bind({now: theProxy}); + } + } + return returnObj; + } }, set : function (recv, name, value) { sessions[name] = value; From 64cac0e5e20d9e3fbfae542db4ef507ddde2639a Mon Sep 17 00:00:00 2001 From: Sridatta Thatipamala Date: Thu, 21 Apr 2011 19:30:15 -0700 Subject: [PATCH 3/4] Closures identified with random string rather than timestamp --- lib/now.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/now.js b/lib/now.js index 2c9617a..4caacd7 100644 --- a/lib/now.js +++ b/lib/now.js @@ -118,7 +118,7 @@ var nowCore = { nowUtil.debug("constructRemoteFunction", fqn); var remoteFn = function(){ - var callId = fqn+ "_"+ new Date().getTime(); + var callId = fqn+ "_"+ nowUtil.generateRandomString(10); nowUtil.debug("executeRemoteFunction", fqn + ", " + callId); @@ -126,7 +126,7 @@ var nowCore = { for(var i in theArgs){ if(typeof theArgs[i] === 'function' && theArgs.hasOwnProperty(i)){ - var closureId = "closure" + "_" + theArgs[i].name + "_" + new Date().getTime(); + var closureId = "closure" + "_" + theArgs[i].name + "_" + nowUtil.generateRandomString(10); nowCore.closures[closureId] = theArgs[i]; theArgs[i] = {type: 'function', fqn: closureId}; } From 780db6c8e92189d963cd7d443a65eb80b11c3413 Mon Sep 17 00:00:00 2001 From: Sridatta Thatipamala Date: Thu, 21 Apr 2011 19:33:24 -0700 Subject: [PATCH 4/4] npm version is at 0.5.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a5b550b..e7e0e60 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "now", "description": "An easy to use real-time RPC library", - "version": "0.5.1", + "version": "0.5.2", "homepage": "http://nowjs.com", "repository": "git://github.com/Flotype/now.git", "author": "Flotype Inc. ",