NPM NOT USING LATEST :( :( :( trying to fix this.

This commit is contained in:
Mark Nadal 2015-09-11 23:05:01 -07:00
parent 0d336a46cc
commit 7192374ab8
6 changed files with 50 additions and 7 deletions

2
gun.js
View File

@ -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){

View File

@ -658,7 +658,8 @@ ref.on(function(data){
<p>
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.
</p>
<p>
Gun also establishes and repairs server to server communication across geographically separated machines,

View File

@ -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);
}, {});
});
});
});
// 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.

View File

@ -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 ) })

View File

@ -1,6 +1,6 @@
{
"name": "gun",
"version": "0.2.0-alpha-4",
"version": "0.2.1",
"description": "Graph engine",
"main": "index.js",
"scripts": {

29
test/nts.html Normal file
View File

@ -0,0 +1,29 @@
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="../gun.js"></script>
<script src="../lib/nts.js"></script>
</head>
<body>
<div id="now" style="text-align: center; font-size: 10vmin; line-height: 95vh;">
Hello!
</div>
<script>
var gun = Gun('http://localhost:8080/gun');
var $now = $('#now');
window.frame = function(cb){
var requestAnimationFrame = window.requestAnimationFrame || function(cb){setTimeout(cb,0)}
requestAnimationFrame(cb);
}
window.frame(function frame(){
//window.frame(frame);
var d = new Date()
var s = d.getFullYear() + '/' + (d.getMonth() + 1) + '/' + d.getDate() + '/' +
(d.getHours() + 1) + ':' + d.getSeconds() + '.' + d.getMilliseconds();
$now.text(s);
});
</script>
</body>
</html>