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
b430667e
authored
2020-04-17 11:20:20 +0200
by
Lorenzo Mangani
Committed by
GitHub
2020-04-17 11:20:20 +0200
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Update server.js
1 parent
2dc3b673
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
6 deletions
server.js
server.js
View file @
b430667
...
...
@@ -8,6 +8,7 @@ const url = require('url');
var
rimraf
=
require
(
"rimraf"
);
const
Gun
=
require
(
'gun/gun'
);
require
(
'./gun-ws.js'
);
require
(
'./memdisk.js'
);
const
http
=
require
(
'http'
);
const
WebSocket
=
require
(
'ws'
);
var
server
=
http
.
createServer
();
...
...
@@ -15,9 +16,8 @@ var server = http.createServer();
// LRU with last used sockets
const
QuickLRU
=
require
(
'quick-lru'
);
var
evict
=
function
(
key
,
value
){
console
.
log
(
'!!!!!!!!!!!!!!! Garbage Collect'
,
key
);
var
uuid
=
value
.
gun
.
opt
().
_
.
opt
.
ws
.
uuid
;
if
(
uuid
)
rimraf
(
"/tmp/"
+
uuid
,
function
()
{
console
.
log
(
"Cleaned up ID"
,
uuid
);
});
console
.
log
(
'Garbage Collect'
,
key
);
if
(
key
)
rimraf
(
"/tmp/"
+
key
,
function
()
{
console
.
log
(
"Cleaned up ID"
,
key
);
});
}
const
lru
=
new
QuickLRU
({
maxSize
:
10
,
onEviction
:
evict
});
...
...
@@ -34,14 +34,12 @@ server.on('upgrade', async function (request, socket, head) {
// Create Node
console
.
log
(
'Create id'
,
pathname
);
// NOTE: Only works with lib/ws.js shim allowing a predefined WS as ws.web parameter in Gun constructor
var
uuid
=
Math
.
random
().
toString
(
36
).
substring
(
7
);
gun
.
server
=
new
WebSocket
.
Server
({
noServer
:
true
,
path
:
pathname
});
console
.
log
(
'set peer'
,
request
.
headers
.
host
+
pathname
);
gun
.
gun
=
new
Gun
({
peers
:[],
// should we use self as peer?
localStorage
:
false
,
uuid
:
uuid
,
file
:
"tmp/"
+
uuid
,
file
:
"tmp/"
+
pathname
,
multicast
:
false
,
ws
:
{
noServer
:
true
,
path
:
pathname
,
web
:
gun
.
server
},
web
:
gun
.
server
...
...
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