mirror of
https://github.com/amark/gun.git
synced 2025-06-05 21:56:51 +00:00
goodbye experiment
This commit is contained in:
parent
3ec7d81f85
commit
b3e59d243e
3
gun.js
3
gun.js
@ -886,6 +886,7 @@
|
|||||||
if(!at.gun){
|
if(!at.gun){
|
||||||
at.gun = gun;
|
at.gun = gun;
|
||||||
}
|
}
|
||||||
|
this.to.next(at);
|
||||||
if(get = at.get){
|
if(get = at.get){
|
||||||
if(tmp = get[_soul]){
|
if(tmp = get[_soul]){
|
||||||
tmp = (root.get(tmp)._);
|
tmp = (root.get(tmp)._);
|
||||||
@ -966,7 +967,7 @@
|
|||||||
proxy.at.on('in', proxy.at);
|
proxy.at.on('in', proxy.at);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(cat.ack){
|
if(cat.ack >= 0){
|
||||||
if(!obj_has(cat, 'put')){ // u !== cat.put instead?
|
if(!obj_has(cat, 'put')){ // u !== cat.put instead?
|
||||||
//if(u !== cat.put){
|
//if(u !== cat.put){
|
||||||
return;
|
return;
|
||||||
|
38
lib/bye.js
Normal file
38
lib/bye.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
if(typeof window !== "undefined"){
|
||||||
|
var Gun = window.Gun;
|
||||||
|
} else {
|
||||||
|
var Gun = require('../gun');
|
||||||
|
}
|
||||||
|
|
||||||
|
Gun.on('opt', function(ctx){
|
||||||
|
this.to.next(ctx);
|
||||||
|
if(ctx.once){ return }
|
||||||
|
ctx.on('in', function(msg){
|
||||||
|
if(!msg.peer || !msg.BYE){ return this.to.next(msg) }
|
||||||
|
var peer = msg.peer();
|
||||||
|
(peer.bye = peer.bye || []).push(msg.BYE);
|
||||||
|
})
|
||||||
|
ctx.on('bye', function(peer){
|
||||||
|
if(!peer.bye){ return }
|
||||||
|
var gun = ctx.gun;
|
||||||
|
Gun.obj.map(peer.bye, function(data){
|
||||||
|
Gun.obj.map(data, function(put, soul){
|
||||||
|
gun.get(soul).put(put);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
peer.bye = [];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Gun.chain.bye = function(){
|
||||||
|
var gun = this, bye = gun.chain(), root = gun.back(-1), put = bye.put;
|
||||||
|
bye.put = function(data){
|
||||||
|
gun.back(function(at){
|
||||||
|
if(!at.get){ return }
|
||||||
|
var tmp = data;
|
||||||
|
(data = {})[at.get] = tmp;
|
||||||
|
});
|
||||||
|
root.on('out', {BYE: data});
|
||||||
|
}
|
||||||
|
return bye;
|
||||||
|
}
|
11
lib/file.js
11
lib/file.js
@ -40,6 +40,7 @@ Gun.on('opt', function(ctx){
|
|||||||
//setTimeout(function(){
|
//setTimeout(function(){
|
||||||
if(!lex || !(soul = lex[Gun._.soul])){ return }
|
if(!lex || !(soul = lex[Gun._.soul])){ return }
|
||||||
//if(0 >= at.cap){ return }
|
//if(0 >= at.cap){ return }
|
||||||
|
if(Gun.obj.is(soul)){ return match(at) }
|
||||||
var field = lex['.'];
|
var field = lex['.'];
|
||||||
data = disk[soul] || u;
|
data = disk[soul] || u;
|
||||||
if(data && field){
|
if(data && field){
|
||||||
@ -74,4 +75,14 @@ Gun.on('opt', function(ctx){
|
|||||||
if(1 < tmp){ flush() }
|
if(1 < tmp){ flush() }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function match(at){
|
||||||
|
var rgx = at.get['#'], has = at.get['.'];
|
||||||
|
Gun.obj.map(disk, function(node, soul, put){
|
||||||
|
if(!Gun.text.match(soul, rgx)){ return }
|
||||||
|
if(has){ node = Gun.state.to(node, has) }
|
||||||
|
(put = {})[soul] = node;
|
||||||
|
ctx.on('in', {put: put, '@': at['#']});
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
@ -9,7 +9,7 @@ Gun.chain.open = function(cb, opt, at){
|
|||||||
opt.doc = opt.doc || {};
|
opt.doc = opt.doc || {};
|
||||||
opt.ids = opt.ids || {};
|
opt.ids = opt.ids || {};
|
||||||
return this.on(function(data, key){
|
return this.on(function(data, key){
|
||||||
delete (data = Gun.obj.copy(data))._;
|
delete ((data = Gun.obj.copy(data))||{})._;
|
||||||
clearTimeout(opt.to);
|
clearTimeout(opt.to);
|
||||||
opt.to = setTimeout(function(){
|
opt.to = setTimeout(function(){
|
||||||
cb(opt.doc);
|
cb(opt.doc);
|
||||||
|
@ -6,5 +6,6 @@
|
|||||||
try{require('./ws');}catch(e){require('./wsp/server');}
|
try{require('./ws');}catch(e){require('./wsp/server');}
|
||||||
require('./verify');
|
require('./verify');
|
||||||
require('./file');
|
require('./file');
|
||||||
|
require('./bye');
|
||||||
module.exports = Gun;
|
module.exports = Gun;
|
||||||
}());
|
}());
|
||||||
|
@ -12,4 +12,7 @@ Gun.chain.on = function(a,b,c){
|
|||||||
return this.open(b,c);
|
return this.open(b,c);
|
||||||
}
|
}
|
||||||
return _on.call(this, a,b,c);
|
return _on.call(this, a,b,c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Gun.chain.bye || require('gun/lib/bye');
|
||||||
|
Gun.chain.onDisconnect = Gun.chain.bye;
|
22
lib/uws.js
22
lib/uws.js
@ -18,17 +18,20 @@ Gun.on('opt', function mount(ctx){
|
|||||||
|
|
||||||
ws.web = new WebSocket.Server(ws);
|
ws.web = new WebSocket.Server(ws);
|
||||||
|
|
||||||
ws.web.on('connection', function(peer){
|
ws.web.on('connection', function(wire){
|
||||||
peer.upgradeReq = peer.upgradeReq || {};
|
wire.upgradeReq = wire.upgradeReq || {};
|
||||||
peer.url = url.parse(peer.upgradeReq.url||'', true);
|
wire.url = url.parse(wire.upgradeReq.url||'', true);
|
||||||
peer.id = peer.id || Gun.text.random(6);
|
wire.id = wire.id || Gun.text.random(6);
|
||||||
opt.peers[peer.id] = {wire: peer};
|
var peer = opt.peers[wire.id] = {wire: wire};
|
||||||
peer.on('message', function(msg){
|
peer.wire = function(){ return peer };
|
||||||
|
ctx.on('hi', peer);
|
||||||
|
wire.on('message', function(msg){
|
||||||
//console.log("MESSAGE", msg);
|
//console.log("MESSAGE", msg);
|
||||||
receive(msg, peer, ctx); // diff: peer is wire.
|
receive(msg, wire, ctx); // diff: wire is wire.
|
||||||
});
|
});
|
||||||
peer.on('close', function(){
|
wire.on('close', function(){
|
||||||
Gun.obj.del(opt.peers, peer.id);
|
ctx.on('bye', peer);
|
||||||
|
Gun.obj.del(opt.peers, wire.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -73,6 +76,7 @@ Gun.on('opt', function mount(ctx){
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
msg.peer = wire.peer;
|
||||||
ctx.on('in', msg);
|
ctx.on('in', msg);
|
||||||
}
|
}
|
||||||
function open(peer, as){
|
function open(peer, as){
|
||||||
|
22
lib/ws.js
22
lib/ws.js
@ -16,17 +16,20 @@ Gun.on('opt', function mount(ctx){
|
|||||||
|
|
||||||
ws.web = new WebSocket.Server(ws);
|
ws.web = new WebSocket.Server(ws);
|
||||||
|
|
||||||
ws.web.on('connection', function(peer){
|
ws.web.on('connection', function(wire){
|
||||||
peer.upgradeReq = peer.upgradeReq || {};
|
wire.upgradeReq = wire.upgradeReq || {};
|
||||||
peer.url = url.parse(peer.upgradeReq.url||'', true);
|
wire.url = url.parse(wire.upgradeReq.url||'', true);
|
||||||
peer.id = peer.id || Gun.text.random(6);
|
wire.id = wire.id || Gun.text.random(6);
|
||||||
opt.peers[peer.id] = {wire: peer};
|
var peer = opt.peers[wire.id] = {wire: wire};
|
||||||
peer.on('message', function(msg){
|
wire.peer = function(){ return peer };
|
||||||
|
ctx.on('hi', peer);
|
||||||
|
wire.on('message', function(msg){
|
||||||
//console.log("MESSAGE", msg);
|
//console.log("MESSAGE", msg);
|
||||||
receive(msg, peer, ctx); // diff: peer is wire.
|
receive(msg, wire, ctx); // diff: wire is wire.
|
||||||
});
|
});
|
||||||
peer.on('close', function(){
|
wire.on('close', function(){
|
||||||
Gun.obj.del(opt.peers, peer.id);
|
ctx.on('bye', peer);
|
||||||
|
Gun.obj.del(opt.peers, wire.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -71,6 +74,7 @@ Gun.on('opt', function mount(ctx){
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
msg.peer = wire.peer;
|
||||||
ctx.on('in', msg);
|
ctx.on('in', msg);
|
||||||
}
|
}
|
||||||
function open(peer, as){
|
function open(peer, as){
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gun",
|
"name": "gun",
|
||||||
"version": "0.8.3",
|
"version": "0.8.4",
|
||||||
"description": "Graph engine",
|
"description": "Graph engine",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"browser": "gun.min.js",
|
"browser": "gun.min.js",
|
||||||
|
@ -105,7 +105,7 @@ describe("Sync all data from one server to another!", function(){
|
|||||||
test.async();
|
test.async();
|
||||||
var raw = require('fs').readFileSync(env.i+'alldata');
|
var raw = require('fs').readFileSync(env.i+'alldata');
|
||||||
var json = JSON.parse(raw);
|
var json = JSON.parse(raw);
|
||||||
var graph = json.graph;
|
var graph = json;
|
||||||
console.log("Bob's graph on disk:", json);
|
console.log("Bob's graph on disk:", json);
|
||||||
|
|
||||||
if(!graph.a1 || graph.a1.a !== 1){
|
if(!graph.a1 || graph.a1.a !== 1){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user