a5927ea8 by Jabis Sevón

merge marks multigun patch

1 parent b2c715bd
![image](https://user-images.githubusercontent.com/1423657/79577881-b6ae2480-80c5-11ea-925c-8d69c2168613.png)
![image](https://user-images.githubusercontent.com/1423657/80729669-deab7800-8b08-11ea-88a5-13cdbcaee38c.png)
# GunDB MultiSocket
Single `HTTP/S` server providing `WebSocket` Path based routing to ephemeral [GunDB](https://gun.eco) instances in mesh isolation.
#### Gun MultiSocket
Single `HTTP/S` server providing multiple ephemeral [GunDB](https://gun.eco) `WebSocket` instances with path based routing and mesh isolation.
### Notes
* uses its own [mem](https://github.com/meething/gundb-multisocket/blob/master/mem.js) storage adaptor to avoid any disk writes
......
......@@ -22,8 +22,8 @@
return;
}
to = setTimeout(flush, opt.wait || 1);
//var id = at['#']
//ctx.on('in', {"@": id, ok:1})
// var id = at['#']
// ctx.on('in', {"@": id, ok:1})
});
ctx.on('get', function(at){
//console.log("get at",at,disk);
......
......@@ -9,7 +9,7 @@
},
"dependencies": {
"express": "^4.17.1",
"gun": "^0.2020.401",
"gun": "^0.2020.430",
"quick-lru": "^5.1.0"
},
"engines": {
......
......@@ -4,11 +4,12 @@
* MIT Licensed (C) QXIP 2020
*/
var no = require('gun/lib/nomem')(); // no-memory storage adapter for RAD
const fs = require("fs");
const url = require("url");
const Gun = require("gun/gun"); // do not load storage adaptors by default
require("./gun-ws.js"); // required to allow external websockets into gun constructor
require("./mem.js"); // disable to allow file writing for debug
const Gun = require("gun"); // load defaults
//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");
require("gun/lib/then");
const SEA = Gun.SEA;
......@@ -17,10 +18,9 @@ const https = require("https");
const WebSocket = require("ws");
var debug = process.env.DEBUG || false;
var config = {};
config.options = {
}
if (!process.env.hasOwnProperty('SSL')||process.env.SSL == false) {
var server = http.createServer();
server.listen(process.env.PORT || 8767);
......@@ -50,6 +50,7 @@ server.on("upgrade", async function(request, socket, head) {
var gun = { gun: false, server: false };
if (pathname) {
let roomname = pathname.split("").slice(1).join("");
console.log("roomname",roomname);
if (lru.has(pathname)) {
// Existing Node
if (debug) console.log("Recycle id", pathname);
......@@ -65,7 +66,7 @@ server.on("upgrade", async function(request, socket, head) {
if(debug) console.log("stored sig ",sig,"to pathname",pathname);
}
//console.log("gunsea",Gun.SEA);
SEA.throw = 1;
//SEA.throw = 1;
/*Gun.on('opt',function(ctx){
if(ctx.once) return;
ctx.on('in',function(msg){
......@@ -82,34 +83,34 @@ server.on("upgrade", async function(request, socket, head) {
ws: { noServer: true, path: pathname, web: gun.server },
web: gun.server
});
gun.server = gun.gun.back('opt.ws.web'); // this is the websocket server
lru.set(pathname, gun);
let obj = {roomname:roomname,creator:creator,socket:{}};
if(sig) {
let user = g.user();
user.create(roomname,sig,async function(ack){
console.log("We've got create ack",ack);
if(ack.err){ console.log("error in user.create",ack.err); }
let auth = await new Promise ((res,rej)=>{
return user.auth(roomname,sig,res);
});
user.create(roomname,sig,async function(dack){
console.log("We've got create ack",dack,roomname,sig);
if(dack.err){ console.log("error in user.create",dack.err); }
user.auth(roomname,sig,function(auth){
if(auth.err){ console.log('error in auth',auth.err); }
console.log("auth",auth);
console.log("auth",auth,roomname,sig);
Object.assign(obj,{
pub:ack.pub,
pub:dack.pub,
passwordProtected:true
})
let roomnode = user.get(roomname).put(obj);
let putnode = g.get('rtcmeeting').get(roomname).put(roomnode);
let rack= await putnode.then();
console.log("room created",rack);
let putnode = g.get('rtcmeeting').get(roomname);
let rack= putnode.put(roomnode);
console.log("room created");
rack.once(Gun.log);
});
});
} else {
;(async ()=>{
Object.assign(obj,{passwordProtected:false});
let roomnode = g.get("rtcmeeting").get(roomname).put(obj);
let rack = await roomnode.then();
let roomnode = g.get("rtcmeeting").get(roomname).put(obj,function(rack){
console.log("room created",rack);
})()
});
}
}
}
......@@ -120,6 +121,7 @@ server.on("upgrade", async function(request, socket, head) {
gun.server.emit("connection", ws, request);
});
} else {
if (debug) console.log("destroying socket", pathname);
socket.destroy();
}
});
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!