Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin 1 Years worth of Merges... #1116

Merged
merged 234 commits into from
Aug 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
234 commits
Select commit Hold shift + click to select a range
f42ab34
tmp for hn issue
amark Mar 10, 2020
637b664
Merge branch 'master' into manhattan
amark Mar 10, 2020
09dbdc5
log top to stats
amark Mar 12, 2020
6223e1a
test for guntest peer
amark Mar 12, 2020
babb126
try big messages
amark Mar 12, 2020
fc6c0f4
parse time?
amark Mar 13, 2020
c220269
what bin/node is 11ms?
amark Mar 13, 2020
cd3aa76
be normal for hnoon
amark Mar 13, 2020
2eee188
tolerate 0.5s
amark Mar 13, 2020
31c8a23
try 3s for hnoon?
amark Mar 13, 2020
09fa9ea
stop empty gets
amark Mar 13, 2020
d91330b
tmp for guntest
amark Mar 13, 2020
c74d632
back to normal
amark Mar 13, 2020
0e837fa
check hash time
amark Mar 14, 2020
d45d6c4
back to normal in hear
amark Mar 14, 2020
5323a30
screen / upload / play / pause
amark Mar 21, 2020
cc64880
Merge branch 'dev' into manhattan
amark Mar 22, 2020
407af2d
Merge branch 'master' into manhattan
amark Apr 9, 2020
eae8930
merge latest npm release into manhattan
amark Apr 9, 2020
9d1307f
merge master 0.2020.421 into manhattan manually
amark Apr 23, 2020
0bedff8
WIP
amark May 14, 2020
2c3ee08
manually merge from master
amark May 19, 2020
1cc49cc
gatling
amark May 24, 2020
38fa0df
Merge branch 'master' into manhattan
amark Jun 14, 2020
39ed5a6
Update upload.html
amark Jun 14, 2020
3c956c2
work in progress...
amark Jun 17, 2020
4e61f11
Merge branch 'master' into manhattan
amark Jun 18, 2020
74714e6
yson panic chat basic
amark Jun 19, 2020
1468829
after `.put(` walk
amark Jul 25, 2020
cdca331
restructure acks
amark Aug 30, 2020
69c476e
messy but 2 units passing!
amark Sep 6, 2020
921000a
put recursive once on map
amark Sep 11, 2020
356a971
basics
amark Sep 13, 2020
bac0e5b
have NTS use DAM + fix other utils
amark Sep 15, 2020
6545113
Rewrote nts
finwo Sep 16, 2020
cf4e198
Allow passing test cli args.
diatche Sep 17, 2020
dfee16a
Merge pull request #1009 from diatche/patch-2
amark Sep 18, 2020
a930ae9
Merge pull request #1008 from finwo/manhattan-nts
amark Sep 18, 2020
2d72ebd
put back scan & once tweak
amark Sep 18, 2020
ed495de
PANIC user paste OK
amark Sep 19, 2020
b4c11f2
manhattan sea
amark Sep 19, 2020
1fb7088
Merge branch 'manhattan' of http://github.com/amark/gun into manhattan
amark Sep 19, 2020
8a18a54
stub out nts for now
amark Sep 19, 2020
c1c80ff
AXE tweak
amark Sep 19, 2020
9d3e071
tweak for quick first prod testing
amark Sep 19, 2020
87c7de9
tweak for first in-prod testing
amark Sep 19, 2020
0bea0a0
tweak
amark Sep 19, 2020
095688b
tweak
amark Sep 19, 2020
7264d12
sketchy in-prod debug attempt
amark Sep 19, 2020
be35790
caught it? maybe? now restore
amark Sep 19, 2020
9d25eb9
Create download-log.html
amark Sep 20, 2020
bcf6e90
stub out yson test prod?
amark Sep 20, 2020
40ecbda
ugh, gotta see what is going on
amark Sep 20, 2020
5d11aaa
move dl
amark Sep 20, 2020
e95625e
gonna stop doing commit messages for in-prod test/tweaks/debugging
amark Sep 20, 2020
bc31765
a
amark Sep 20, 2020
2b90e09
p
amark Sep 20, 2020
4e55fa1
squelch
amark Sep 20, 2020
af7918a
console stats
amark Sep 20, 2020
c5f5d8f
stats
amark Sep 20, 2020
eea79db
stop travis
amark Sep 20, 2020
93accb1
restore yson
amark Sep 20, 2020
f10f7e5
ahhh no file access without sudo
amark Sep 20, 2020
4b0f0f3
mem
amark Sep 20, 2020
0bcd573
no stub
amark Sep 20, 2020
e0390eb
fix axe
amark Sep 23, 2020
1dd6fbc
bump
amark Sep 23, 2020
fd600db
back to in-prod testing, isolate/stub out code
amark Sep 24, 2020
6d56aaa
stub all out for 17K ? CPU ? test
amark Sep 25, 2020
5ef549a
stub dup gc
amark Sep 26, 2020
e56ebf7
ugh main stub
amark Sep 26, 2020
45e2bcc
does this stop url format blocking?
amark Sep 26, 2020
1c09767
re-add dup
amark Sep 28, 2020
c099b7c
no top :(
amark Sep 28, 2020
e99c5c9
will this work?
amark Sep 29, 2020
836212b
get ack stats?
amark Oct 1, 2020
3af021c
a map chain may ask for data not a root soul chain
amark Oct 22, 2020
dc95cd1
move proper logic into .get(
amark Oct 23, 2020
d640d83
how 2019 compat?
amark Oct 25, 2020
a128892
a couple more!
amark Oct 28, 2020
359d90e
more tests passing! :D :)
amark Nov 1, 2020
b19856b
even more! SO EXCITING :D
amark Nov 1, 2020
a85ccf7
Am I alive?
amark Nov 1, 2020
f16876c
wow I can't believe it works like this
amark Nov 5, 2020
ff8604e
THANK YOU @rogowski !!!!!!
amark Dec 22, 2020
f0d847d
Create trace.html
rogowski Jan 4, 2021
bdaf098
@rogowski is a super star :) :) :)
amark Jan 4, 2021
b24778a
Update trace.js
rogowski Jan 4, 2021
4221c24
Update trace.html
rogowski Jan 4, 2021
5f19570
@rogowski approved of these trace changes :)
amark Jan 5, 2021
4b656ad
Update trace.html
rogowski Jan 7, 2021
f321b5e
Update trace.js
rogowski Jan 7, 2021
f0b0c73
2 steps backwards, 1 step forward?
amark Jan 15, 2021
f133160
Merge branch 'manhattan' of http://github.com/amark/gun into manhattan
amark Jan 15, 2021
fb08fe2
back where we ( @rogowski ) started :P
amark Jan 17, 2021
07042bf
YAYAYAYAYAYAYAY past where we started at!
amark Jan 17, 2021
6708a18
safer to have it here
amark Jan 17, 2021
cc4f92f
slight tweak? Let's see how long it lasts.
amark Jan 17, 2021
3f12e37
merge checks we left out during consolidation
amark Jan 17, 2021
bb2e12b
ugly common.js for @rogowski
amark Jan 19, 2021
9904565
slightly better
amark Jan 19, 2021
fadada2
amazing map discovery + don't clear on not found if data exists
amark Jan 20, 2021
790bec8
onto next test...
amark Jan 20, 2021
d4b66bc
all caught up!!! Now update tests from graphify to statedisk
amark Jan 20, 2021
1001d5a
Update common.js
rogowski Jan 21, 2021
ea58796
easy to debug & fix thanks to @rogowski 's test upgrades & trace!
amark Jan 22, 2021
fa7c9bd
hmm, IDK if we should support this anymore?
amark Jan 23, 2021
817af6b
support once chaining?
amark Jan 23, 2021
77e310b
check if listener order is earlier than write
amark Jan 24, 2021
c6e230d
in-process message passing needs to clean itself of flags for now
amark Jan 24, 2021
dcd6fc5
ack to chains that can't be reached
amark Jan 27, 2021
e16f982
call sub chains on clear/empty WIP
amark Jan 30, 2021
cc1a03e
call sub chains clear/empty OK!
amark Jan 30, 2021
5a05ada
into unlink. Clean/refactor later.
amark Jan 31, 2021
9a5b824
oh that was nice
amark Feb 18, 2021
e13ce8e
self check not needed?
amark Feb 19, 2021
d2f8d40
test was poorly constructed?
amark Mar 5, 2021
e2350f6
refactor unlink to cleaner logic
amark Mar 6, 2021
843011d
Will you blame me for this? Special case, maybe later move to cleaner…
amark Mar 11, 2021
4743aef
use stun's run id instead.
amark Mar 11, 2021
5f652a0
cleaner unlink logic
amark Mar 13, 2021
68519cb
better map, link, and unlink logic.
amark Mar 23, 2021
fa5f925
unstub relay
amark Mar 23, 2021
70ad201
refactor unlink
amark Apr 8, 2021
84ebb59
invert
amark Apr 10, 2021
5814a75
if prev value would have caused unlink, do not unlink again.
amark Apr 10, 2021
3b1509f
w000h00! Best unlink so far.
amark Apr 14, 2021
0da0144
woops, fix unlinking nested
amark Apr 20, 2021
b203ddf
unsubscribe nested maps (working, tho possible perf regression? check)
amark Apr 22, 2021
0fc71b0
put check soul
amark Apr 23, 2021
deeaccb
add default uuid
amark Apr 23, 2021
1c6bd00
improved browser peer retry logic, let devices sleep, etc.
amark Apr 24, 2021
1af945c
Chaining API unit tests passing!
amark Apr 24, 2021
6e0c5bc
merge new panic tests into here to test
amark May 10, 2021
2cb414c
add panic utils
amark May 10, 2021
ad3ecf6
fix long streaming timeout/expiry issue, update examples
amark May 11, 2021
8591d34
yield generating test data
amark May 11, 2021
7da46d1
yeah, adapter errors (like out of storage) should not affect sync/net…
amark May 15, 2021
4e29530
git glitch?
amark May 15, 2021
177eab0
some mid debugging fixes but maybe scary changes, hopefully safe to r…
amark May 29, 2021
cb93229
SEA unit tests passing!!! Needed quite a few fixes on async write que…
amark Jun 1, 2021
3318e45
optionally make auth async
amark Jun 3, 2021
8b299a0
revise/correct set
amark Jun 3, 2021
9722219
Fix reverse boundary check
amark Jun 7, 2021
0e8e9d7
Add extra tests, catch bad guy, obliterate bug.
amark Jun 7, 2021
fd5e618
chat app with emoji examples
amark Jun 7, 2021
af5da57
handle empty string keyed objects
amark Jun 8, 2021
305191a
starting lex support
amark Jun 12, 2021
ab8b1bb
tweak for lex
amark Jun 12, 2021
4a022da
woops! lexical alphabetical oopsies. That was bad.
amark Jun 13, 2021
a45a17a
upload either way
amark Jun 22, 2021
5c3603c
debug
amark Jun 22, 2021
ed70e33
start
amark Jun 22, 2021
9d4f395
fix
amark Jun 22, 2021
47ce51c
fix
amark Jun 22, 2021
ca4196b
clean + feature
amark Jun 22, 2021
c2ad1af
update dependencies in package.json (#1086)
i001962 Jul 1, 2021
3c9727b
rad lex once map once
amark Jul 2, 2021
e783695
Merge branch 'manhattan' of http://github.com/amark/gun into manhattan
amark Jul 2, 2021
c42d2bc
axe polyfill for now
amark Jul 2, 2021
8e696e2
oops log
amark Jul 2, 2021
61a2b86
oops maybe without this it crashed the peer
amark Jul 2, 2021
13c13c7
what on earth happened to my browser/OS? "unplug & plug it back in" r…
amark Jul 5, 2021
2ee79f4
oh, don't memory leak req/res asks. :/ duh!
amark Jul 7, 2021
4d92aa6
no accidental #soul.""
amark Jul 8, 2021
ead5893
ugh, still have to sort :(, really should polyfill weakmap then
amark Jul 8, 2021
4f41129
oops, pluck needs new object to go into
amark Jul 8, 2021
fe65f99
oops, make sure soul is passed
amark Jul 8, 2021
7478b67
updating deprecated functions
rogowski Jul 9, 2021
188bb77
begin AXE. Next: load balance!
amark Jul 11, 2021
99bc6b5
Merge branch 'manhattan' of http://github.com/amark/gun into manhattan
amark Jul 11, 2021
03f939e
Update sea.js
amark Jul 11, 2021
1c55091
keys are dangerous!
amark Jul 12, 2021
5d57749
AXE round robin load balance
amark Jul 16, 2021
55e040b
better ash hash checking
amark Jul 21, 2021
805aaa7
lS reuse in-mem reply chunking
amark Jul 21, 2021
3e64d4d
state machine!!!
amark Jul 22, 2021
b413cb2
RAD needs to pass cache misses.
amark Jul 25, 2021
9703441
updating deprecated functions (#1088)
i001962 Jul 28, 2021
590ba4a
Bring SEA.certify into manhattan branch (#1092)
rococtz Jul 28, 2021
8c060cb
fix rad, make get() hookable
amark Jul 30, 2021
e153491
Merge branch 'manhattan' of http://github.com/amark/gun into manhattan
amark Jul 30, 2021
662e375
rad browser tests seem to be passing!
amark Jul 30, 2021
6d44f82
reverse user random side, add err, update styles, + more
amark Aug 1, 2021
1532016
fix pack/max, update dom
amark Aug 3, 2021
7abab81
paste!
amark Aug 3, 2021
fd1bd50
of course it'll dedup cause it just called track on hear, fix
amark Aug 4, 2021
f1f5795
📦 Adding the hub feature to this branch & improvements. (#1102)
noctisatrae Aug 4, 2021
8a89e5b
Update axe.js
amark Aug 5, 2021
9735a2c
Merge branch 'manhattan' of http://github.com/amark/gun into manhattan
amark Aug 5, 2021
e25d53a
🦅 Wrap everything in a try & catch for error handling… (#1105)
noctisatrae Aug 6, 2021
69613e2
probs better this way, safer
amark Aug 7, 2021
8b2fd90
moved test/axe tests to test/panic/axe.
rogowski Aug 7, 2021
5d77c2a
New test: axe load balance.
rogowski Aug 7, 2021
7b32d01
axe test: webrtc data balance(fix paths and file renamed).
rogowski Aug 7, 2021
806b427
test axe: renaming webrtc file.
rogowski Aug 7, 2021
886d6aa
axe test: separating webrtc test for data_balance.
rogowski Aug 7, 2021
17da891
axe test: test only with the relay(without webrtc).
rogowski Aug 7, 2021
b20c156
Update sea.js
mmalmi Aug 8, 2021
3efa02f
Update gun.js
mmalmi Aug 8, 2021
7222112
Update upload.js
amark Aug 8, 2021
fed500d
Merge branch 'manhattan' of http://github.com/amark/gun into manhattan
amark Aug 8, 2021
d3dd54d
merge, update stun
amark Aug 8, 2021
333dd74
SEA.certify wire logic + unit tests (#1110)
mimiza Aug 10, 2021
69f8ce3
merge @mimiza 's SEA.certify! Thank you.
amark Aug 10, 2021
f2c8c9a
ack err
amark Aug 10, 2021
a8fdeea
axe tests using puppeteer.
rogowski Aug 11, 2021
55ea510
Merge branch 'manhattan' of github.com:/amark/gun into manhattan
rogowski Aug 11, 2021
11c36fc
change stun system
amark Aug 13, 2021
5d26f34
Merge branch 'manhattan' of http://github.com/amark/gun into manhattan
amark Aug 13, 2021
1c7c9a1
~20lines
amark Aug 14, 2021
7f5f51d
put use parent soul link if need
amark Aug 14, 2021
675504f
handle errors
amark Aug 15, 2021
b246bfa
finally seems fixed
amark Aug 17, 2021
b0879f0
cb not to
amark Aug 18, 2021
6564800
relay
amark Aug 19, 2021
b8dc921
nasty bug! Don't crash, tho need to find what causes it
amark Aug 19, 2021
252e42d
undo local changes/notes to self
amark Aug 19, 2021
7d34a29
deprecation warnings
amark Aug 19, 2021
2cb642b
"old" data to test against
amark Aug 21, 2021
e300a12
oops, forgot I played with ascii
amark Aug 21, 2021
4f310d9
debug
amark Aug 21, 2021
e6b097a
in-prod check: sites
amark Aug 21, 2021
1cb5414
in-prod isolate
amark Aug 21, 2021
1fe4d3e
gotta find this, by stubbing out
amark Aug 21, 2021
a7ab172
where?
amark Aug 21, 2021
6f764a6
will this work?
amark Aug 21, 2021
eebc028
clearly not, lol what's the point then? maybe like this
amark Aug 21, 2021
823c7d0
and again
amark Aug 21, 2021
b88a232
must we?
amark Aug 21, 2021
1e7dc31
USE THIS MANHATTAN VERSION
amark Aug 21, 2021
824319a
Merge branch 'master' into manhattan
amark Aug 21, 2021
cdca88e
clean
amark Aug 22, 2021
c3f0558
better panic hints
amark Aug 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: node_js
branches:
except:
- debug
- manhattan
node_js:
- 10
cache:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.2020.x

`>0.2020.520` may break in-process `gun1` `gun2` message passing. Check `test/common.js` "Check multi instance message passing" for a hint and/or complain on community chat.

- No breaking changes to core API.
- Storage adapter `put` event breaking change (temporary?), RAD is official now and storage adapters should be RAD plugins instead of GUN adapters.
- GUN soul format changed from being a random UUID to being a more predictable graph path (of where initially created) to support even better offline behavior. This means `null`ing & replacing an object will not create a new but re-merge.
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: node examples/http.js
web: node --inspect examples/http.js
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description": "Javascript, Offline-First Javascript Graph Database Server Peer",
"env": {
"NPM_CONFIG_PRODUCTION": {
"description": "If you don't want to serve the Gun landing page, set to \"true\".",
"description": "If you do not want default features, set to \"true\".",
"value": "false"
},
"PEERS": {
Expand Down
316 changes: 32 additions & 284 deletions axe.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,300 +25,48 @@

;USE(function(module){

var AXE = USE('./root'), Gun = (AXE.window||{}).Gun || USE('./gun', 1);
var AXE = USE('./root'), Gun = (AXE.window||'').Gun || USE('./gun', 1);
(Gun.AXE = AXE).GUN = AXE.Gun = Gun;
var ST = 0;

Gun.on('opt', function(at){
start(at);
this.to.next(at); // make sure to call the "next" middleware adapter.
});
if(!Gun.window){ try{ USE('./lib/axe', 1) }catch(e){} }
Gun.on('opt', function(at){ start(at) ; this.to.next(at) }); // make sure to call the "next" middleware adapter.

function start(at){
if(at.axe){ return }
var opt = at.opt, peers = opt.peers;
function start(root){
if(root.axe){ return }
var opt = root.opt, peers = opt.peers;
if(false === opt.axe){ return }
if((typeof process !== "undefined") && 'false' === ''+(process.env||{}).AXE){ return }
var axe = at.axe = {}, tmp;
// 1. If any remembered peers or from last cache or extension
// 2. Fallback to use hard coded peers from dApp
// 3. Or any offered peers.
//if(Gun.obj.empty(p)){
// Gun.obj.map(['http://localhost:8765/gun'/*, 'https://guntest.herokuapp.com/gun'*/], function(url){
// p[url] = {url: url, axe: {}};
// });
//}
// Our current hypothesis is that it is most optimal
// to take peers in a common network, and align
// them in a line, where you only have left and right
// peers, so messages propagate left and right in
// a linear manner with reduced overlap, and
// with one common superpeer (with ready failovers)
// in case the p2p linear latency is high.
// 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 || 9876 || Infinity;
var mesh = opt.mesh = opt.mesh || Gun.Mesh(at);
console.log("AXE enabled.");

function verify(dht, msg) {
var S = (+new Date);
var puts = Object.keys(msg.put);
var soul = puts[0]; /// TODO: verify all souls in puts. Copy the msg only with subscribed souls?
var subs = dht(soul);
if (!subs) { return; }
var tmp = [];
Gun.obj.map(subs.split(','), function(pid) {
if (pid in peers) {
tmp.push(pid);
mesh.say(msg, peers[pid]);
}
});
/// Only connected peers in the tmp array.
if (opt.super) {
dht(soul, tmp.join(','));
}
console.STAT && console.STAT(S, +new Date - S, 'axe verify');
}
function route(get){ var tmp;
if(!get){ return }
if('string' != typeof (tmp = get['#'])){ return }
return tmp;
}
// TODO: AXE NEEDS TO BE CHECKED FOR NEW CODE SYSTEM!!!!!!!!!!

var Rad = (Gun.window||{}).Radix || USE('./lib/radix', 1);
at.opt.dht = Rad();
at.on('in', input);
function input(msg){
var to = this.to, peer = (msg._||'').via; // warning! mesh.leap could be buggy!
var dht = opt.dht;
var routes = axe.routes || (axe.routes = {}); // USE RAD INSTEAD! TMP TESTING!
var get = msg.get, hash, tmp;
//if(get && opt.super && peer){
if(get && opt.super && peer && (tmp = route(get))){
hash = tmp; //Gun.obj.hash(get); // USE RAD INSTEAD!
(routes[hash] || (routes[hash] = {}))[peer.id] = peer;
(peer.routes || (peer.routes = {}))[hash] = routes[hash];

/*if(soul = get['#']){ // SWITCH BACK TO USING DHT!
if(key = get['.']){

} else {

}
if (!peer.id) {console.log('[*** WARN] no peer.id %s', soul);}
var pids = joindht(dht, soul, peer.id);
if (pids) {
var dht = {};
dht[soul] = pids;
mesh.say({dht:dht}, opt.peers[peer.id]);
}
}*/
if((typeof process !== "undefined") && 'false' === ''+(process.env||'').AXE){ return }
if(!Gun.window){ return }
var axe = root.axe = {}, tmp, id;
tmp = peers[id = 'http://localhost:8765/gun'] = peers[id] || {};
tmp.id = tmp.url = id;
tmp.retry = tmp.retry || 0; // BUG: Check 0?
console.log("AXE enabled: Trying to find network via (1) local peer (2) last used peers (3) hard coded peers.");
var last = JSON.parse((localStorage||'')[(opt.file||'')+'axe/']||null) || {};
Object.keys(last.peers||'').forEach(function(key){
tmp = peers[id = key] = peers[id] || {};
tmp.id = tmp.url = id;
});
tmp = peers[id = 'https://gun-manhattan.herokuapp.com/gun'] = peers[id] || {};
tmp.id = tmp.url = id;

var mesh = opt.mesh = opt.mesh || Gun.Mesh(root); // DAM!
mesh.way = function(msg){
if(root.$ === msg.$ || (msg._||'').via){
mesh.say(msg, opt.peers);
return;
}
if((tmp = msg['@']) && (tmp = at.dup.s[tmp])){
tmp.ack = (tmp.ack || 0) + 1; // count remote ACKs to GET.
var at = (msg.$||'')._;
if(!at){ mesh.say(msg, opt.peers); return }
if(msg.get){
if(at.axe){ return } // don't ask for it again!
at.axe = {};
}
to.next(msg);

if (opt.rtc && msg.dht) {
Gun.obj.map(msg.dht, function(pids, soul) {
dht(soul, pids);
Gun.obj.map(pids.split(','), function(pid) {
/// TODO: here we can put an algorithm of who must connect?
if (!pid || pid in opt.peers || pid === opt.pid || opt.announce[pid]) { return; }
opt.announce[pid] = true; /// To try only one connection to the same peer.
opt.announce(pid);
});
});
}
};

//try{console.log(req.connection.remoteAddress)}catch(e){};
mesh.hear['opt'] = function(msg, peer){
if(msg.ok){ return opt.log(msg) }
var tmp = msg.opt;
if(!tmp){ return }
tmp = tmp.peers;
if(!tmp || !Gun.text.is(tmp)){ return }
if(axe.up[tmp] || 6 <= Object.keys(axe.up).length){ return }
var o = tmp; //{peers: tmp};
at.$.opt(o);
o = peers[tmp];
if(!o){ return }
o.retry = 9;
mesh.wire(o);
if(peer){ mesh.say({dam: 'opt', ok: 1, '@': msg['#']}, peer) }
}
setInterval(function(tmp){
if(!(tmp = at.stats && at.stats.stay)){ return }
(tmp.axe = tmp.axe || {}).up = Object.keys(axe.up||{});
},1000 * 60)
setTimeout(function(tmp){
if(!(tmp = at.stats && at.stats.stay)){ return }
Gun.obj.map((tmp.axe||{}).up, function(url){ mesh.hear.opt({opt: {peers: url}}) })
},1000);

if(at.opt.super){
var rotate = 0;
mesh.way = function(msg) {
if (msg.rtc) {
if (msg.rtc.to) {
/// Send announce to one peer only if the msg have 'to' attr
var peer = (peers) ? peers[msg.rtc.to] : null;
if (peer) { mesh.say(msg, peer); }
return;
}
}
if(msg.get){ mesh.say(msg, axe.up) } // always send gets up!
if(msg.get && (tmp = route(msg.get))){
var hash = tmp; //Gun.obj.hash(msg.get);
var routes = axe.routes || (axe.routes = {}); // USE RAD INSTEAD! TMP TESTING!
var peers = routes[hash];
function chat(peers, old){ // what about optimizing for directed peers?
if(!peers){ return chat(opt.peers) }
var S = (+new Date); // STATS!
var ids = Object.keys(peers); // TODO: BUG! THIS IS BAD PERFORMANCE!!!!
var meta = (msg._||yes);
clearTimeout(meta.lack);
var id, peer, c = 1; // opt. ?redundancy?
while((id = ids[meta.turn || 0]) && c--){ // TODO: This hits peers in order, not necessarily best for load balancing. And what about optimizing for directed peers?
peer = peers[id];
meta.turn = (meta.turn || 0) + 1;
if((old && old[id]) || false === mesh.say(msg, peer)){ ++c }
}
console.STAT && (ST = +new Date - S) > 9 && console.STAT(S, ST, 'axe chat');
//console.log("AXE:", Gun.obj.copy(msg), meta.turn, c, ids, opt.peers === peers);
if(0 < c){
if(peers === opt.peers){ return } // prevent infinite lack loop.
return meta.turn = 0, chat(opt.peers, peers)
}
var hash = msg['##'], ack = meta.ack || at.dup.s[msg['#']];
meta.lack = setTimeout(function(){
if(ack && hash && hash === msg['##']){ return }
if(meta.turn >= (axe.turns || 3)){ return } // variable for later! Also consider ACK based turn limit.
//console.log(msg['#'], "CONTINUE:", ack, hash, msg['##']);
chat(peers, old); // keep asking for data if there is mismatching hashes.
}, 25);
}
return chat(peers);
}
// TODO: PUTs need to only go to subs!
if(msg.put){
mesh.say(msg, axe.up); // always send gets up! Hope that mesh.say below dedups via DAM's check.
var S = (+new Date); // STATS!
var routes = axe.routes || (axe.routes = {}); // USE RAD INSTEAD! TMP TESTING!
var peers = {};
Gun.obj.map(msg.put, function(node, soul){
var hash = soul; //Gun.obj.hash({'#': soul});
var to = routes[hash];
if(!to){ return }
Gun.obj.to(to, peers);
});
console.STAT && (ST = +new Date - S) > 9 && console.STAT(S, ST, 'axe put');
mesh.say(msg, peers);
return;
}
mesh.say(msg, opt.peers); return; // TODO: DISABLE THIS!!! USE DHT!


if (!msg.put) { mesh.say(msg); return; }
//console.log('AXE HOOK!! ', msg);
verify(opt.dht, msg);
};
} else {
mesh.route = function(msg) {
if (msg.rtc) {
}
if (!msg.put) { mesh.say(msg); return; }
verify(opt.dht, msg);
/// Always send to superpeers?
Gun.obj.map(peers, function(peer) {
if (peer.url) {
mesh.say(msg, peer);
}
});
};
}
axe.up = {};
at.on('hi', function(peer){
this.to.next(peer);
if(!peer.url){ return }
axe.up[peer.id] = peer;
});
at.on('bye', function(peer){ this.to.next(peer);
if(peer.url){ delete axe.up[peer.id] }
var S = +new Date;
Gun.obj.map(peer.routes, function(route, hash){
delete route[peer.id];
if(Gun.obj.empty(route)){
delete axe.routes[hash];
}
});
console.STAT && console.STAT(S, +new Date - S, 'axe bye');
});

// 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?
var peers = Object.keys(axe.up);
if(!peers.length){ return }
mesh.say({dam: 'mob', mob: count, peers: peers}, peer);
//setTimeout(function(){ mesh.bye(peer) }, 9); // something with better perf? // UNCOMMENT WHEN WE ACTIVATE THIS FEATURE
});
at.on('bye', function(peer){
this.to.next(peer);
});

at.on('hi', function(peer){
this.to.next(peer);
// this code handles disconnecting from self & duplicates
setTimeout(function(){ // must wait
if(peer.pid !== opt.pid){
// this extra logic checks for duplicate connections between 2 peers.
if(!Gun.obj.map(axe.up, function(p){
if(peer.pid === p.pid && peer !== p){
return yes = true;
}
})){ return }
}
mesh.say({dam: '-'}, peer);
delete at.dup.s[peer.last];
}, Math.random() * 100);
});
mesh.hear['-'] = function(msg, peer){
mesh.bye(peer);
peer.url = '';
mesh.say(msg, opt.peers);
}
}

function joindht(dht, soul, pids) {
if (!pids || !soul || !dht) { return; }
var subs = dht(soul);
var tmp = subs ? subs.split(',') : [];
Gun.obj.map(pids.split(','), function(pid) {
if (pid && tmp.indexOf(pid) === -1) { tmp.push(pid); }
});
tmp = tmp.join(',');
dht(soul, tmp);
return tmp;
}

var empty = {}, yes = true, u;

module.exports = AXE;
Expand Down
File renamed without changes.
Loading