7581ae20 by Jabis Sevón

mem overwrite

1 parent 1e8ca0f0
1 (function() { 1 (function() {
2 var Gun = typeof window !== "undefined" ? window.Gun : require("gun/gun"); 2 var Gun = typeof window !== "undefined" ? window.Gun : Gun ? Gun : require("gun/gun");
3 Gun.on('opt', function(ctx){
4 this.to.next(ctx);
5 var opt = ctx.opt;
6 //if(ctx.once){ return }
7
8 var graph = ctx.graph, acks = {}, count = 0, to;
9 var disk = {};
10
11 ctx.on("put", function(at) {
12 this.to.next(at);
13 Gun.graph.is(at.put, null, null);
14 if (!at["@"]) {
15 acks[at["#"]] = true;
16 } // only ack non-acks.
17 count += 1;
18 if (count >= (opt.batch || 10000)) {
19 return flush();
20 }
21 if (to) {
22 return;
23 }
24 to = setTimeout(flush, opt.wait || 1);
25 var id = at['#']
26 ctx.on('in', {"@": id, ok:1})
27 });
28 ctx.on('get', function(at){
29 console.log("get at",at,disk);
30 this.to.next(at);
31 var lex = at.get, soul, data, opt, u;
32 //setTimeout(function(){
33 if(!lex || !(soul = lex['#'])){console.log("solex",soul,lex['#']); return }
34 //if(0 >= at.cap){ return }
35 var field = lex['.'];
36 data = disk[soul] || u;
37 if(data && field){
38 data = Gun.state.to(data, field);
39 }
40 ctx.on('in', {'@': at['#'], put: Gun.graph.node(data)});
41 //},11);
42 });
43
44 var map = function(val, key, node, soul){
45 disk[soul] = Gun.state.to(node, key, disk[soul]);
46 }
3 47
4 Gun.on("opt", function(ctx) { 48 var wait;
49 var flush = function(){
50 console.log("flushing",to);
51 if(wait){ return }
52 wait = true;
53 clearTimeout(to);
54 to = false;
55 var ack = acks;
56 acks = {};
57 wait = false;
58 var tmp = count;
59 count = 0;
60 console.log("ack",ack);
61 Gun.obj.map(ack, function(yes, id){
62
63 ctx.on('in', {
64 '@': id,
65 err: 0,
66 ok: 1 // lel, hacks
67 });
68 });
69 if(1 < tmp){ flush() }
70
71 }
72 });
73 /* Gun.on("opt", function(ctx) {
5 this.to.next(ctx); 74 this.to.next(ctx);
6 var opt = ctx.opt; 75 var opt = ctx.opt;
7 if (ctx.once) { 76 if (ctx.once) {
...@@ -28,7 +97,6 @@ ...@@ -28,7 +97,6 @@
28 } 97 }
29 to = setTimeout(flush, opt.wait || 1); 98 to = setTimeout(flush, opt.wait || 1);
30 }); 99 });
31
32 ctx.on("put", function(at) { 100 ctx.on("put", function(at) {
33 this.to.next(at); 101 this.to.next(at);
34 Gun.graph.is(at.put, null, null); 102 Gun.graph.is(at.put, null, null);
...@@ -46,9 +114,8 @@ ...@@ -46,9 +114,8 @@
46 var id = at['#'] 114 var id = at['#']
47 ctx.on('in', {"@": id, ok:1}) 115 ctx.on('in', {"@": id, ok:1})
48 }); 116 });
49
50 ctx.on("get", function(at) { 117 ctx.on("get", function(at) {
51 // this.to.next(at); //What does this do? 118 this.to.next(at); //What does this do?
52 var lex = at.get, 119 var lex = at.get,
53 soul, 120 soul,
54 data, 121 data,
...@@ -76,5 +143,5 @@ ...@@ -76,5 +143,5 @@
76 var ack = acks; 143 var ack = acks;
77 acks = {}; 144 acks = {};
78 }; 145 };
79 }); 146 });*/
80 })(); 147 })();
......
...@@ -7,10 +7,11 @@ ...@@ -7,10 +7,11 @@
7 const fs = require("fs"); 7 const fs = require("fs");
8 const url = require("url"); 8 const url = require("url");
9 const Gun = require("gun/gun"); // do not load storage adaptors by default 9 const Gun = require("gun/gun"); // do not load storage adaptors by default
10 require("gun/sea");
11 require("gun/lib/then");
12 require("./gun-ws.js"); // required to allow external websockets into gun constructor 10 require("./gun-ws.js"); // required to allow external websockets into gun constructor
13 require("./mem.js"); // disable to allow file writing for debug 11 require("./mem.js"); // disable to allow file writing for debug
12 require("gun/sea");
13
14 const SEA = Gun.SEA;
14 const http = require("http"); 15 const http = require("http");
15 const https = require("https"); 16 const https = require("https");
16 const WebSocket = require("ws"); 17 const WebSocket = require("ws");
...@@ -91,6 +92,15 @@ server.on("upgrade", async function(request, socket, head) { ...@@ -91,6 +92,15 @@ server.on("upgrade", async function(request, socket, head) {
91 }) 92 })
92 }) 93 })
93 } 94 }
95 console.log("gunsea",Gun.SEA);
96 SEA.throw = 1;
97 /*Gun.on('opt',function(ctx){
98 if(ctx.once) return;
99 ctx.on('in',function(msg){
100 console.log(msg);
101 this.to.next(msg);
102 })
103 })*/
94 var g = gun.gun = Gun({ 104 var g = gun.gun = Gun({
95 peers: [], // should we use self as peer? 105 peers: [], // should we use self as peer?
96 localStorage: false, 106 localStorage: false,
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!