mirror of
https://github.com/amark/gun.git
synced 2025-06-24 23:12:32 +00:00
commit
f263b4d066
31
axe.js
31
axe.js
@ -47,11 +47,11 @@
|
|||||||
// 1. If any remembered peers or from last cache or extension
|
// 1. If any remembered peers or from last cache or extension
|
||||||
// 2. Fallback to use hard coded peers from dApp
|
// 2. Fallback to use hard coded peers from dApp
|
||||||
// 3. Or any offered peers.
|
// 3. Or any offered peers.
|
||||||
if(Gun.obj.empty(p)){
|
//if(Gun.obj.empty(p)){
|
||||||
Gun.obj.map(['http://localhost:8765/gun'/*, 'https://guntest.herokuapp.com/gun'*/], function(url){
|
// Gun.obj.map(['http://localhost:8765/gun'/*, 'https://guntest.herokuapp.com/gun'*/], function(url){
|
||||||
p[url] = {url: url, axe: {}};
|
// p[url] = {url: url, axe: {}};
|
||||||
});
|
// });
|
||||||
}
|
//}
|
||||||
// Our current hypothesis is that it is most optimal
|
// Our current hypothesis is that it is most optimal
|
||||||
// to take peers in a common network, and align
|
// to take peers in a common network, and align
|
||||||
// them in a line, where you only have left and right
|
// them in a line, where you only have left and right
|
||||||
@ -61,6 +61,25 @@
|
|||||||
// in case the p2p linear latency is high.
|
// in case the p2p linear latency is high.
|
||||||
// Or there could be plenty of other better options.
|
// Or there could be plenty of other better options.
|
||||||
console.log("axe", at.opt);
|
console.log("axe", at.opt);
|
||||||
|
if(at.opt.super){
|
||||||
|
function verify(msg, send, at) {
|
||||||
|
var peers = Object.keys(p), puts = Object.keys(msg.put), i, j, peer;
|
||||||
|
var soul = puts[0]; /// TODO: verify all souls in puts. Copy the msg only with subscribed souls?
|
||||||
|
for (i=0; i < peers.length; ++i) {
|
||||||
|
peer = p[peers[i]];
|
||||||
|
//if (peer.url) {console.log('AXE do not reject superpeers'); send(msg, peer); continue;} /// always send to superpeers?
|
||||||
|
if (!peer.id) {console.log('AXE peer without id: ', peer); continue;}
|
||||||
|
if (!Gun.subscribe[soul] || !Gun.subscribe[soul][peer.id]) { console.log('AXE SAY reject msg to peer: %s, soul: %s', peer.id, soul); continue; }
|
||||||
|
send(msg, peer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AXE.say = function(msg, send, at) {
|
||||||
|
if (!msg.put) { send(msg); return; }
|
||||||
|
console.log('AXE HOOK!! ', msg);
|
||||||
|
verify(msg, send, at);
|
||||||
|
};
|
||||||
|
/// TODO: remove peer from all Gun.subscribe. On `mesh.bye` event?
|
||||||
|
}
|
||||||
if(at.opt.super){
|
if(at.opt.super){
|
||||||
at.on('in', USE('./lib/super', 1), at);
|
at.on('in', USE('./lib/super', 1), at);
|
||||||
} else {
|
} else {
|
||||||
@ -77,4 +96,4 @@
|
|||||||
module.exports = AXE;
|
module.exports = AXE;
|
||||||
})(USE, './axe');
|
})(USE, './axe');
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
40
examples/axe.html
Normal file
40
examples/axe.html
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0" />
|
||||||
|
<title>Testing AXE</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<script src="../gun.js"></script>
|
||||||
|
<!-- <script src="../axe.js"></script> -->
|
||||||
|
<!-- <script src="../sea.js"></script> -->
|
||||||
|
<script>
|
||||||
|
var pid = location.hash.slice(1);
|
||||||
|
|
||||||
|
var opt = ({
|
||||||
|
peers: [`${location.origin}/gun`]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (pid) { opt.pid = pid; }
|
||||||
|
|
||||||
|
Gun.on('opt', function(ctx) {
|
||||||
|
this.to.next(ctx);
|
||||||
|
ctx.on('hi', function(opt) {
|
||||||
|
console.log('HI!! PEER', new Date(), opt.pid);
|
||||||
|
});
|
||||||
|
if (pid) {
|
||||||
|
ctx.on('out', function(msg) {
|
||||||
|
msg.pid = pid;
|
||||||
|
this.to.next(msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var gun = Gun(opt);
|
||||||
|
//var user = gun.user();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -2,12 +2,16 @@ console.log("If module not found, install express globally `npm i express -g`!")
|
|||||||
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765;
|
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765;
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var Gun = require('..');
|
var Gun = require('..');
|
||||||
|
require('../axe');
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
app.use(Gun.serve);
|
app.use(Gun.serve);
|
||||||
app.use(express.static(__dirname));
|
app.use(express.static(__dirname));
|
||||||
|
|
||||||
var server = app.listen(port);
|
var server = app.listen(port);
|
||||||
Gun({ file: 'data.json', web: server });
|
var gun = Gun({ file: 'data', web: server });
|
||||||
|
|
||||||
|
global.Gun = Gun; /// make global to `node --inspect` - debug only
|
||||||
|
global.gun = gun; /// make global to `node --inspect` - debug only
|
||||||
|
|
||||||
console.log('Server started on port ' + port + ' with /gun');
|
console.log('Server started on port ' + port + ' with /gun');
|
||||||
|
3
gun.js
3
gun.js
@ -1941,6 +1941,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// add hook for AXE?
|
// add hook for AXE?
|
||||||
|
if (Gun.AXE && opt && opt.super) { Gun.AXE.say(msg, mesh.say, this); return; }
|
||||||
mesh.say(msg);
|
mesh.say(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2210,4 +2211,4 @@
|
|||||||
var noop = function(){};
|
var noop = function(){};
|
||||||
})(USE, './adapters/websocket');
|
})(USE, './adapters/websocket');
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
10
lib/super.js
10
lib/super.js
@ -12,10 +12,18 @@
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
subscribe(soul, peer, msg);
|
||||||
}
|
}
|
||||||
to.next(msg);
|
to.next(msg);
|
||||||
}
|
}
|
||||||
|
/// Store the subscribes
|
||||||
|
Gun.subscribe = {}; /// TODO: use Rad instead of plain object?
|
||||||
|
function subscribe(soul, peer, msg) {
|
||||||
|
if (!peer.id) { console.log('super jump peer without id: ', peer, msg); return; } /// TODO: this occurs in first subscription. Use peer reference or peer.wire.id?
|
||||||
|
Gun.subscribe[soul] = Gun.subscribe[soul] || {};
|
||||||
|
Gun.subscribe[soul][peer.id] = 1;
|
||||||
|
}
|
||||||
var empty = {}, u;
|
var empty = {}, u;
|
||||||
if(Gun.window){ return }
|
if(Gun.window){ return }
|
||||||
try{module.exports = input}catch(e){}
|
try{module.exports = input}catch(e){}
|
||||||
}());
|
}());
|
||||||
|
4
sea.js
4
sea.js
@ -1065,7 +1065,7 @@
|
|||||||
// if there is a request to read data from us, then...
|
// if there is a request to read data from us, then...
|
||||||
var soul = msg.get['#'];
|
var soul = msg.get['#'];
|
||||||
if(soul){ // for now, only allow direct IDs to be read.
|
if(soul){ // for now, only allow direct IDs to be read.
|
||||||
if(soul !== 'string'){ return to.next(msg) } // do not handle lexical cursors.
|
if(typeof soul !== 'string'){ return to.next(msg) } // do not handle lexical cursors.
|
||||||
if('alias' === soul){ // Allow reading the list of usernames/aliases in the system?
|
if('alias' === soul){ // Allow reading the list of usernames/aliases in the system?
|
||||||
return to.next(msg); // yes.
|
return to.next(msg); // yes.
|
||||||
} else
|
} else
|
||||||
@ -1230,4 +1230,4 @@
|
|||||||
var noop = {};
|
var noop = {};
|
||||||
|
|
||||||
})(USE, './index');
|
})(USE, './index');
|
||||||
}());
|
}());
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
// if there is a request to read data from us, then...
|
// if there is a request to read data from us, then...
|
||||||
var soul = msg.get['#'];
|
var soul = msg.get['#'];
|
||||||
if(soul){ // for now, only allow direct IDs to be read.
|
if(soul){ // for now, only allow direct IDs to be read.
|
||||||
if(soul !== 'string'){ return to.next(msg) } // do not handle lexical cursors.
|
if(typeof soul !== 'string'){ return to.next(msg) } // do not handle lexical cursors.
|
||||||
if('alias' === soul){ // Allow reading the list of usernames/aliases in the system?
|
if('alias' === soul){ // Allow reading the list of usernames/aliases in the system?
|
||||||
return to.next(msg); // yes.
|
return to.next(msg); // yes.
|
||||||
} else
|
} else
|
||||||
@ -77,7 +77,7 @@
|
|||||||
// potentially parallel async operations!!!
|
// potentially parallel async operations!!!
|
||||||
var check = {}, each = {}, u;
|
var check = {}, each = {}, u;
|
||||||
each.node = function(node, soul){
|
each.node = function(node, soul){
|
||||||
if(Gun.obj.empty(node, '_')){ return check['node'+soul] = 0 } // ignore empty updates, don't reject them.
|
//if(Gun.obj.empty(node, '_')){ return check['node'+soul] = 0 } // ignore empty updates, don't reject them. @amark, removing this line solves issue #616. 2018-10-02
|
||||||
Gun.obj.map(node, each.way, {soul: soul, node: node});
|
Gun.obj.map(node, each.way, {soul: soul, node: node});
|
||||||
};
|
};
|
||||||
each.way = function(val, key){
|
each.way = function(val, key){
|
||||||
@ -226,4 +226,4 @@
|
|||||||
}
|
}
|
||||||
var noop = {};
|
var noop = {};
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ function Mesh(ctx){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// add hook for AXE?
|
// add hook for AXE?
|
||||||
|
if (Gun.AXE && opt && opt.super) { Gun.AXE.say(msg, mesh.say, this); return; }
|
||||||
mesh.say(msg);
|
mesh.say(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,5 +229,3 @@ Mesh.hash = function(s){ // via SO
|
|||||||
Object.keys = Object.keys || function(o){ return map(o, function(v,k,t){t(k)}) }
|
Object.keys = Object.keys || function(o){ return map(o, function(v,k,t){t(k)}) }
|
||||||
|
|
||||||
try{ module.exports = Mesh }catch(e){}
|
try{ module.exports = Mesh }catch(e){}
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user