Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Jabis Sevón
/
gun-multiserver
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
7581ae20
authored
2020-05-01 02:00:25 +0200
by
Jabis Sevón
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
mem overwrite
1 parent
1e8ca0f0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
8 deletions
mem.js
server.js
mem.js
View file @
7581ae2
(
function
()
{
var
Gun
=
typeof
window
!==
"undefined"
?
window
.
Gun
:
require
(
"gun/gun"
);
var
Gun
=
typeof
window
!==
"undefined"
?
window
.
Gun
:
Gun
?
Gun
:
require
(
"gun/gun"
);
Gun
.
on
(
'opt'
,
function
(
ctx
){
this
.
to
.
next
(
ctx
);
var
opt
=
ctx
.
opt
;
//if(ctx.once){ return }
var
graph
=
ctx
.
graph
,
acks
=
{},
count
=
0
,
to
;
var
disk
=
{};
ctx
.
on
(
"put"
,
function
(
at
)
{
this
.
to
.
next
(
at
);
Gun
.
graph
.
is
(
at
.
put
,
null
,
null
);
if
(
!
at
[
"@"
])
{
acks
[
at
[
"#"
]]
=
true
;
}
// only ack non-acks.
count
+=
1
;
if
(
count
>=
(
opt
.
batch
||
10000
))
{
return
flush
();
}
if
(
to
)
{
return
;
}
to
=
setTimeout
(
flush
,
opt
.
wait
||
1
);
var
id
=
at
[
'#'
]
ctx
.
on
(
'in'
,
{
"@"
:
id
,
ok
:
1
})
});
ctx
.
on
(
'get'
,
function
(
at
){
console
.
log
(
"get at"
,
at
,
disk
);
this
.
to
.
next
(
at
);
var
lex
=
at
.
get
,
soul
,
data
,
opt
,
u
;
//setTimeout(function(){
if
(
!
lex
||
!
(
soul
=
lex
[
'#'
])){
console
.
log
(
"solex"
,
soul
,
lex
[
'#'
]);
return
}
//if(0 >= at.cap){ return }
var
field
=
lex
[
'.'
];
data
=
disk
[
soul
]
||
u
;
if
(
data
&&
field
){
data
=
Gun
.
state
.
to
(
data
,
field
);
}
ctx
.
on
(
'in'
,
{
'@'
:
at
[
'#'
],
put
:
Gun
.
graph
.
node
(
data
)});
//},11);
});
var
map
=
function
(
val
,
key
,
node
,
soul
){
disk
[
soul
]
=
Gun
.
state
.
to
(
node
,
key
,
disk
[
soul
]);
}
Gun
.
on
(
"opt"
,
function
(
ctx
)
{
var
wait
;
var
flush
=
function
(){
console
.
log
(
"flushing"
,
to
);
if
(
wait
){
return
}
wait
=
true
;
clearTimeout
(
to
);
to
=
false
;
var
ack
=
acks
;
acks
=
{};
wait
=
false
;
var
tmp
=
count
;
count
=
0
;
console
.
log
(
"ack"
,
ack
);
Gun
.
obj
.
map
(
ack
,
function
(
yes
,
id
){
ctx
.
on
(
'in'
,
{
'@'
:
id
,
err
:
0
,
ok
:
1
// lel, hacks
});
});
if
(
1
<
tmp
){
flush
()
}
}
});
/* Gun.on("opt", function(ctx) {
this.to.next(ctx);
var opt = ctx.opt;
if (ctx.once) {
...
...
@@ -28,7 +97,6 @@
}
to = setTimeout(flush, opt.wait || 1);
});
ctx.on("put", function(at) {
this.to.next(at);
Gun.graph.is(at.put, null, null);
...
...
@@ -46,9 +114,8 @@
var id = at['#']
ctx.on('in', {"@": id, ok:1})
});
ctx.on("get", function(at) {
//
this.to.next(at); //What does this do?
this.to.next(at); //What does this do?
var lex = at.get,
soul,
data,
...
...
@@ -76,5 +143,5 @@
var ack = acks;
acks = {};
};
});
});
*/
})();
...
...
server.js
View file @
7581ae2
...
...
@@ -7,10 +7,11 @@
const
fs
=
require
(
"fs"
);
const
url
=
require
(
"url"
);
const
Gun
=
require
(
"gun/gun"
);
// do not load storage adaptors by default
require
(
"gun/sea"
);
require
(
"gun/lib/then"
);
require
(
"./gun-ws.js"
);
// required to allow external websockets into gun constructor
require
(
"./mem.js"
);
// disable to allow file writing for debug
require
(
"gun/sea"
);
const
SEA
=
Gun
.
SEA
;
const
http
=
require
(
"http"
);
const
https
=
require
(
"https"
);
const
WebSocket
=
require
(
"ws"
);
...
...
@@ -91,6 +92,15 @@ server.on("upgrade", async function(request, socket, head) {
})
})
}
console
.
log
(
"gunsea"
,
Gun
.
SEA
);
SEA
.
throw
=
1
;
/*Gun.on('opt',function(ctx){
if(ctx.once) return;
ctx.on('in',function(msg){
console.log(msg);
this.to.next(msg);
})
})*/
var
g
=
gun
.
gun
=
Gun
({
peers
:
[],
// should we use self as peer?
localStorage
:
false
,
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment