axe doc music dht :)

This commit is contained in:
Mark Nadal 2019-12-06 16:24:12 -08:00
parent d2c4e7c8e8
commit 1cd0c08ab0
4 changed files with 1297 additions and 46 deletions

29
axe.js
View File

@ -60,6 +60,20 @@
// with one common superpeer (with ready failovers) // with one common superpeer (with ready failovers)
// 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.
/*
AXE should have a couple of threshold items...
let's pretend there is a variable max peers connected
mob = 10000
if we get more peers than that...
we should start sending those peers a remote command
that they should connect to this or that other peer
and then once they (or before they do?) drop them from us.
sake of the test... gonna set that peer number to 1.
The mob threshold might be determined by other factors,
like how much RAM or CPU stress we have.
*/
opt.mob = opt.mob || Infinity;
var mesh = opt.mesh = opt.mesh || Gun.Mesh(at); var mesh = opt.mesh = opt.mesh || Gun.Mesh(at);
console.log("AXE enabled."); console.log("AXE enabled.");
@ -256,7 +270,7 @@
this.to.next(peer); this.to.next(peer);
if(!peer.url){ return } if(!peer.url){ return }
axe.up[peer.id] = peer; axe.up[peer.id] = peer;
}) });
at.on('bye', function(peer){ this.to.next(peer); at.on('bye', function(peer){ this.to.next(peer);
if(peer.url){ delete axe.up[peer.id] } if(peer.url){ delete axe.up[peer.id] }
Gun.obj.map(peer.routes, function(route, hash){ Gun.obj.map(peer.routes, function(route, hash){
@ -266,6 +280,19 @@
} }
}); });
}); });
// handle rebalancing a mob of peers:
at.on('hi', function(peer){
this.to.next(peer);
if(peer.url){ return } // I am assuming that if we are wanting to make an outbound connection to them, that we don't ever want to drop them unless our actual config settings change.
var count = Object.keys(opt.peers).length;
if(opt.mob >= count){ return } // TODO: Make dynamic based on RAM/CPU also. Or possibly even weird stuff like opt.mob / axe.up length?
mesh.say({dam: 'mob', mob: count, peers: Object.keys(axe.up)}, peer);
setTimeout(function(){ mesh.bye(peer) }, 9); // something with better perf?
});
at.on('bye', function(peer){
this.to.next(peer);
});
} }
function joindht(dht, soul, pids) { function joindht(dht, soul, pids) {

View File

@ -32,12 +32,17 @@
<script src="../../gun/lib/meta.js"></script> <script src="../../gun/lib/meta.js"></script>
<script src="../../gun/lib/normalize.js"></script> <script src="../../gun/lib/normalize.js"></script>
<script async src="../../gun/lib/fun.js"></script> <script async src="../../gun/lib/fun.js"></script>
<script async src="../../gun/lib/music.js"></script>
<!-- script async src="https://edide.io/music.lib"></script -->
<script> <script>
var gun = Gun('https://guntest.herokuapp.com/gun'); var gun = Gun(['https://guntest.herokuapp.com/gun', 'http://localhost:8765/gun']);
;(window.onhashchange = function(){ ;(window.onhashchange = function(){
var file = (location.hash||'').slice(1); var file = (location.hash||'').slice(1);
var S = +new Date; var S = +new Date;
$('#page').empty();
gun.get('test/gun/docs/'+file).get('what').map().on(function render(data, i){ gun.get('test/gun/docs/'+file).get('what').map().on(function render(data, i){
if(window.LOCK){ return } if(window.LOCK){ return }
var p = $('#page').children().get(i); var p = $('#page').children().get(i);
@ -60,6 +65,7 @@ meta.edit({
use: function(eve){ use: function(eve){
console.log('on'); console.log('on');
}, on: function(eve){ }, on: function(eve){
if($(eve.target).closest('p').length){ return }
var edit = this; var edit = this;
setTimeout(function(){ meta.flip(false) },1); setTimeout(function(){ meta.flip(false) },1);
var doc = $('#page').attr('contenteditable', 'true'); var doc = $('#page').attr('contenteditable', 'true');
@ -71,10 +77,10 @@ meta.edit({
if(eve.which != 13){ return } if(eve.which != 13){ return }
eve.preventDefault(); eve.preventDefault();
var r = window.getSelection().getRangeAt(0); var r = window.getSelection().getRangeAt(0);
var c = r.commonAncestorContainer; var c = r.commonAncestorContainer, p;
r.deleteContents(); r.deleteContents();
c.splitText(r.startOffset); var p = c.splitText? $(c.splitText(r.startOffset)).parent() : $(c);
var p = $(c).parent(), n = $("<"+p.get(0).tagName+">"), f; var n = $("<"+p.get(0).tagName+">"), f;
p.contents().each(function(){ p.contents().each(function(){
if(this === c){ return f = true } if(this === c){ return f = true }
if(!f){ return } if(!f){ return }
@ -131,9 +137,9 @@ meta.edit({
;(function(){ ;(function(){
meta.edit({name: "Layout", combo: ['E','L']}); meta.edit({name: "Layout", combo: ['L']});
meta.edit({name: "Fill", combo: ['E','L','F'], meta.edit({name: "Fill", combo: ['L','F'],
use: function(eve){}, use: function(eve){},
on: function(eve){ on: function(eve){
var on = meta.tap(); var on = meta.tap();
@ -144,13 +150,13 @@ meta.edit({
up: function(eve){} up: function(eve){}
}); });
meta.edit({name: "Add", combo: ['E','L','A']}); meta.edit({name: "Add", combo: ['L','A']});
meta.edit({name: "Row", combo: ['E','L','A', 'R'], meta.edit({name: "Row", combo: ['L','A', 'R'],
on: function(eve){ on: function(eve){
meta.tap().append('<div style="min-height: 9em; padding: 2%;">'); meta.tap().append('<div style="min-height: 9em; padding: 2%;">');
} }
}); });
meta.edit({name: "Columns", combo: ['E','L','A','C'], meta.edit({name: "Columns", combo: ['L','A','C'],
on: function(eve){ on: function(eve){
var on = meta.tap().addClass('center'), tmp, c; var on = meta.tap().addClass('center'), tmp, c;
var html = '<div class="unit col" style="min-height: 9em; padding: 2%;"></div>'; var html = '<div class="unit col" style="min-height: 9em; padding: 2%;"></div>';
@ -161,7 +167,7 @@ meta.edit({
}) })
} }
}); });
meta.edit({name: "Text", combo: ['A','T'], meta.edit({name: "Text", combo: ['L','A','T'],
on: function(eve){ on: function(eve){
var tag = $('<p>text</p>'); var tag = $('<p>text</p>');
meta.tap().append(tag); meta.tap().append(tag);
@ -169,6 +175,59 @@ meta.edit({
} }
}); });
}());
;(function(){
var song = {};
// TODO:
// 1. Manually OR automatically load music.js API, dependencies, and modules. - FINE for now
// 2. only export music API, not meta, not dom, not mouselock system, not UI/html, etc. better module isolation and export.
// 3. `var wave = Wave('a').play()` // also on `Music.now`
// defaults... instrument: pure tones, volume curve: |\_ , speed curve: 0.5
// 4. `wave.blur(0.5).itch(0.5);`
// 5. wave.long(2); // how long in seconds each note plays, optionally: wave.pace(60) is bpm
// 6. wave.loud(0.5); // 0% to 100% volume loudness of device output.
// 7. wave.vary(0.5); // slows down or speeds up wiggle per harmonic
// 8:
// wave structure, does ToneJS allow us to change the sine wave smoothness/type continuously or is it a pre-fixed type?
// wave structure: /\/\/, |_|, /|/, \|\| do some research with ToneJS whether these are dynamic or fixed
// wave.itch(); // changes the shape of the wiggle from smooth sine to square or triangle
// wave.blur(220hz); // blur may not apply/work on pure notes other than filtering them.
meta.edit({name: "Music", combo: ['M']});
meta.edit({name: "Play", combo: ['M','P'],
on: function(eve){
// TODO: We still need to add to meta API ability to change name.
if(song.play){
music.stop();
song.play = false;
return;
}
song.play = true;
music.stop();
setTimeout(function(){
song.now = music.play($('#page').text());
},250);
}
});
meta.edit({name: "Blur", combo: ['M','B'],
on: function(eve){
$(document).on('mousemove.tmp', function(eve){
var x = eve.pageX;
song.now.blur(x);
});
},
up: function(){
$(document).off('.tmp');
}
});
$(document).on('keydown', function(eve){
music.play(String.fromCharCode(eve.which));
});
}()); }());
</script> </script>
</body> </body>

1175
lib/music.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,12 @@ var superpeer3 = Gun(AXE({shard: 's~z'}));
via the browser, so they all go to superpeer1.com via the browser, so they all go to superpeer1.com
then 2/3 of them should get sharded to superpeer2 & superpeer3 then 2/3 of them should get sharded to superpeer2 & superpeer3
first all connect to:
..s1-----s2--s3
./\.\.
b1.b2.b3
then be load balanced to:
..s1--s2--s3 ..s1--s2--s3
./....|....\. ./....|....\.
b1....b2....b3 b1....b2....b3
@ -101,12 +107,12 @@ describe("Put ACK", function(){
var peers = [], i = env.config.servers; var peers = [], i = env.config.servers;
while(i--){ while(i--){
var tmp = (env.config.port + (i + 1)); var tmp = (env.config.port + (i + 1));
if(port != tmp){ // ignore ourselves //if(port != tmp){ // ignore ourselves
peers.push('http://'+ env.config.IP + ':' + tmp + '/gun'); peers.push('http://'+ env.config.IP + ':' + tmp + '/gun');
} //}
} }
console.log(port, " connect to ", peers); console.log(port, " connect to ", peers);
var gun = Gun({file: env.i+'data', peers: peers, web: server}); var gun = Gun({file: env.i+'data', peers: peers, web: server, mob: 1});
global.gun = gun; global.gun = gun;
server.listen(port, function(){ server.listen(port, function(){
test.done(); test.done();
@ -129,6 +135,15 @@ describe("Put ACK", function(){
try{ indexedDB.deleteDatabase('radata') }catch(e){} try{ indexedDB.deleteDatabase('radata') }catch(e){}
var env = test.props; var env = test.props;
var gun = Gun('http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun'); var gun = Gun('http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun');
// SOME NEXT TEST HERE LOL
var mesh = gun.back('opt.mesh');
mesh.hear['mob'] = function(msg, peer){
// TODO: NOTE, code AXE DHT to aggressively drop new peers AFTER superpeer sends this rebalance/disconnect message that contains some other superpeers.
console.log("we got a message!", msg);
try{ peer.wire.close(); }catch(e){ console.log("err:", e) }
}
console.log("connected to who superpeer(s)?", gun._.opt.peers); console.log("connected to who superpeer(s)?", gun._.opt.peers);
window.gun = gun; window.gun = gun;
window.ref = gun.get('test'); window.ref = gun.get('test');
@ -137,41 +152,16 @@ describe("Put ACK", function(){
return Promise.all(tests); return Promise.all(tests);
}); });
return; it("Got Load Balanced to Different Peer", function(){
return; var tests = [], i = 0;
return; browsers.each(function(browser, id){
return; tests.push(browser.run(function(test){
return;
return;
return;
return;
it("Alice", function(){ console.log("...");
return alice.run(function(test){
test.async();
console.log("I AM ALICE");
console.log(gun._.opt.peers);
gun.get('not-dave').put({hello: 'world'}, function(ack){
if(ack.err){
alice_start_did_not_save;
}
test.done();
});
});
});
it("Dave", function(){ }, {i: i += 1, config: config}));
return dave.run(function(test){
console.log("I AM DAVE");
console.log(gun._.opt.peers);
});
});
it("Carl", function(){
return carl.run(function(test){
console.log("I AM CARL");
console.log(global.gun);
}); });
return Promise.all(tests);
}); });
it("All finished!", function(done){ it("All finished!", function(done){