From 7192374ab8018f748724e051350b5b8e1e7bb331 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 11 Sep 2015 23:05:01 -0700 Subject: [PATCH] NPM NOT USING LATEST :( :( :( trying to fix this. --- gun.js | 2 +- index.html | 3 ++- lib/nts.js | 14 +++++++++++--- lib/wsp.js | 7 ++++++- package.json | 2 +- test/nts.html | 29 +++++++++++++++++++++++++++++ 6 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 test/nts.html diff --git a/gun.js b/gun.js index ccea19ac..7a379f08 100644 --- a/gun.js +++ b/gun.js @@ -520,7 +520,7 @@ }); return function(cb, opt){ var gun = this, ctx = {}; - cb = cb || root.console.log.bind(root.console); + cb = cb || function(val, field){ root.console.log(field + ':', val) } opt = opt || {}; gun.on(function($, delta, on){ diff --git a/index.html b/index.html index 7c40cfaf..34748ce6 100644 --- a/index.html +++ b/index.html @@ -658,7 +658,8 @@ ref.on(function(data){

All conflict resolution happens locally in each peer using a deterministic algorithm. Such that eventual consistency is guaranteed across all writes within the mesh, - with fault tolerant retries built in at each step. Data integrity is now a breeze. + with fault tolerant retries built in at each step for at least once deliveries. + Data integrity is now a breeze.

Gun also establishes and repairs server to server communication across geographically separated machines, diff --git a/lib/nts.js b/lib/nts.js index 9ca4cc20..b6c63dd8 100644 --- a/lib/nts.js +++ b/lib/nts.js @@ -1,17 +1,25 @@ Gun.on('opt').event(function(gun, opt){ + if(!Gun.request){ return } var objectiveTimeOffset = 0; Gun.obj.map(opt.peers || gun.__.opt.peers, function(peer, url){ var NTS = {}; NTS.start = Gun.time.is(); - request(url, null, function(err, reply){ + console.log(url + '.nts'); + Gun.request(url + '.nts', null, function(err, reply){ + console.log("reply", err, reply); if(err || !reply || !reply.body){ - return console.log("Network Time Synchronization error", err, (reply || {}).body); + return console.log("Network Time Synchronization not supported", err, (reply || {}).body); } NTS.end = Gun.time.is(); NTS.latency = (NTS.end - NTS.start)/2; if(Gun.obj.has(reply.body, 'time')){ return } NTS.calc = reply.body.time + NTS.latency; objectiveTimeOffset += (objectiveTimeOffset - NTS.calc)/2; + console.log('NTS', NTS.latency, NTS.calc, objectiveTimeOffset); }, {}); }); -}); \ No newline at end of file +}); +// You need to figure out how to make me write tests for this! +// maybe we can do human based testing where we load a HTML that just +// prints out in BIG FONT the objectiveTime it thinks it is +// and we open it up on a couple devices. \ No newline at end of file diff --git a/lib/wsp.js b/lib/wsp.js index 73275156..b98d643b 100644 --- a/lib/wsp.js +++ b/lib/wsp.js @@ -91,7 +91,6 @@ // except for the ones that are listed in the message as having already been sending to. // all states, implemented with GET, are replied to the source that asked for it. function tran(req, cb){ - //Gun.log("gun.server", req); req.method = req.body? 'put' : 'get'; // put or get is based on whether there is a body or not req.url.key = req.url.pathname.replace(gun.server.regex,'').replace(/^\//i,'') || ''; if('get' == req.method){ return tran.get(req, cb) } @@ -102,6 +101,12 @@ var key = req.url.key , reply = {headers: {'Content-Type': tran.json}}; //console.log(req); + /* NTS HACK! SHOULD BE ITS OWN ISOLATED MODULE! + if(req && req.url && req.url.pathname && req.url.pathname.indexOf('gun.nts') >= 0){ + console.log("GOT IT"); + return cb({headers: reply.headers, body: {time: Gun.time.is() }}); + } + NTS END! SHOULD HAVE BEEN ITS OWN MODULE */ if(req && req.url && Gun.obj.has(req.url.query, '*')){ return gun.all(req.url.key + req.url.search, function(err, list){ cb({headers: reply.headers, body: (err? (err.err? err : {err: err || "Unknown error."}) : list || null ) }) diff --git a/package.json b/package.json index bd194ce8..8ba292d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gun", - "version": "0.2.0-alpha-4", + "version": "0.2.1", "description": "Graph engine", "main": "index.js", "scripts": { diff --git a/test/nts.html b/test/nts.html new file mode 100644 index 00000000..6251056d --- /dev/null +++ b/test/nts.html @@ -0,0 +1,29 @@ + + + + + + + + +

+ Hello! +
+ + + \ No newline at end of file