Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Unified daemons into one #23

Merged
merged 28 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
95ab706
include nodepomf submodule, bump submodule versions
neuroscr Dec 30, 2019
b51e4fc
improve log msg
neuroscr Dec 30, 2019
ba5967c
unify it
neuroscr Dec 30, 2019
b56c6f1
unified config file and nodepomf dialect
neuroscr Dec 30, 2019
e9631a8
unfied config
neuroscr Dec 30, 2019
8659f72
add overlay variables
neuroscr Dec 30, 2019
1b43219
pass next for 404s
neuroscr Dec 30, 2019
b465483
Unified version
neuroscr Dec 30, 2019
8e6da48
bump server version to fix config path
neuroscr Dec 30, 2019
4be14c8
Merge branch 'master' of https://github.com/loki-project/loki-messeng…
neuroscr Dec 30, 2019
8255bde
move sqlite3 bump into repo
neuroscr Dec 30, 2019
f2c7054
update travis to expect a unified set up
neuroscr Dec 30, 2019
2187176
set port to be the unified default
neuroscr Dec 30, 2019
4d42996
update tests to be unified
neuroscr Dec 30, 2019
eb0864c
Merge branch 'unified' of https://github.com/neuroscr/loki-messenger-…
neuroscr Dec 30, 2019
7f9dfa2
create missing directory, make NPOMF_UPLOAD_DIRECTORY absolute outsid…
neuroscr Dec 30, 2019
96b1f09
only call static builder once, include fs, style fixes
neuroscr Dec 30, 2019
26cb43e
disable redis for unit tests
neuroscr Dec 30, 2019
76b3bdc
add back preflight
neuroscr Dec 30, 2019
2197c2e
minor improvements and debug
neuroscr Dec 30, 2019
f9d31d4
fix dockerfile for newer package.json in nodepomf
neuroscr Dec 31, 2019
6ef0b0d
merged config mods correctly
neuroscr Jan 6, 2020
17b9ec9
fix spacing in logging
neuroscr Jan 6, 2020
a175c05
make getUsers handle usernames and ids
neuroscr Jan 6, 2020
d12cd6d
convert instructions to unified
neuroscr Jan 14, 2020
759fe42
bump submodule versions
neuroscr Jan 14, 2020
d23da14
run unit-tests, make sure local node-modules don't interfere
neuroscr Jan 14, 2020
61d8551
Merge branch 'unified' of https://github.com/neuroscr/loki-messenger-…
neuroscr Jan 14, 2020
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
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "server"]
path = server
url = https://gitgud.io/Sapphire/Tavrn/sapphire-platform-server.git
#[submodule "nodepomf"]
# path = nodepomf
# url = https://github.com/odilitime/nodepomf.git
[submodule "docker/wait-for-it"]
path = docker/wait-for-it
url = https://github.com/vishnubob/wait-for-it.git
[submodule "nodepomf"]
path = nodepomf
url = https://github.com/odilitime/nodepomf.git
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ node_js:
before_script:
- npm install
- cp loki_template.ini loki.ini
- cp server/config.sample.json server/config.json
- cd nodepomf && npm install && cd ..
- cd server && npm install && cd ..
cache: npm
19 changes: 14 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,31 @@ WORKDIR /usr/src/app

COPY package.json /usr/src/app/package.json
COPY package-lock.json /usr/src/app/package-lock.json
RUN npm i
RUN npm ci

COPY *.js /usr/src/app/
COPY dialects/ dialects/
COPY logic/ logic/
COPY models/ models/
COPY test/ test/

COPY loki_template.ini loki.ini
# set up nodepomf
COPY nodepomf/ nodepomf/
WORKDIR /usr/src/app/nodepomf
RUN npm ci
RUN npm test
WORKDIR /usr/src/app

# we do need proxy-admin
# set up platform
COPY server/ server/
# RUN git submodule update --init --recursive
WORKDIR /usr/src/app/server
RUN npm i
RUN npm ci
RUN npm test

WORKDIR /usr/src/app

COPY config.json config.json
COPY loki_template.ini loki.ini

EXPOSE 8080
ENTRYPOINT ["pm2-runtime", "overlay_server.js"]
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ Manual set up instructions (without attachment support) may look like:
git submodule init
git submodule update
cp loki_template.ini loki.ini
# edit loki.ini
# edit loki.ini (set your first moderator key)
# could edit config.json if you wanted but most people don't need to touch it
npm i -g pm2
npm i
pm2 start overlay_server.js --watch --name "overlay"
cd server
cd nodepomf
npm i
cp config.sample.json config.json
# edit config.json
pm2 start app.js --watch --name "platform"
cd ../server
npm i
cd ..
pm2 start overlay_server.js --watch --name "lmps"
```
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let user_access = {};

const updateUserAccess = () => {
if (!updateFromDisk()) {
console.log('no config file');
console.log('overlay:::config.js - no loki.ini config file');
return;
}
console.log('config', disk_config);
Expand Down
44 changes: 44 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"pomf": {
"provider": "nodepomf-internal",
"provider_url": "http://127.0.0.1:7070/upload"
},
"web": {
"port": 7070,
"listen": "127.0.0.1",
"mounts": [
{
"destination": "",
"dialect": "appdotnet_official"
},
{
"destination": "/stream/0",
"dialect": "appdotnet_official"
},
{
"destination": "",
"dialect": "../dialects/token/dialect.loki_tokens"
},
{
"destination": "",
"dialect": "../dialects/moderation/dialect.loki_moderation"
},
{
"destination": "",
"dialect": "../dialects/nodepomf/dialect.loki_nodepomf"
}
]
},
"admin": {
"listen": "127.0.0.1",
"port": 3000,
"modKey": "CHANGE_ME"
},
"database": {
"default": {
"type": "memory",
"options": {
}
}
}
}
66 changes: 44 additions & 22 deletions dialects/moderation/dialect_moderation_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,51 @@ const getUser = (userid) => {
});
};

const getUsers = (userids) => {
return new Promise((res, rej) => {
let results = [];
let requests = 0;
let responses = 0;
let next200 = userids.splice(0, 200);
while(next200.length) {
requests++;

// allow them to overlap
cache.getUsers(next200, {}, (users, err) => {
if (err) {
return rej(err);
}
results = results.concat(users);
responses++;
if (requests === responses) {
return res(results);
}
});
next200 = userids.splice(0, 200);
const getUsers = async (userids) => {
const count = userids.length;
let results = [];
let next200 = userids.splice(0, 200);
const promises = [];
while(next200.length) {

// partition next200
const [intList, userList] = next200.reduce((result, user) => {
const isUsername = user[0] === '@';
result[isUsername ? 1 : 0].push(isUsername ? user.substr(1) : user)
return result
}, [[], []]);

// handle integer lookups
if (intList.length) {
promises.push(new Promise( (resolve, reject) => {
cache.getUsers(intList, {}, (users, err) => {
if (err) {
return reject(err);
}
results = results.concat(users);
return resolve(results);
});
}));
}
});

// handle username lookups
userList.forEach(username => {
promises.push(new Promise((resolve, reject) => {
cache.getUserID(username, (userObj, err) => {
if (err) {
return reject(err);
}
results = results.concat([userObj]);
return resolve(results);
});
}));
});

next200 = userids.splice(0, 200);
}
// console.log('getUsers awaiting', promises.length, 'promises for', count, 'user object lookups');
await Promise.all(promises);
return results; // array of model constructors
};

const validGlobal = (token, res, cb) => {
Expand Down
87 changes: 87 additions & 0 deletions dialects/nodepomf/dialect.loki_nodepomf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const overlay = require('../../lib.overlay');
const http = require('http');
const pathUtil = require('path');
const fs = require('fs');
const express = require('express');
const lokinet = require('loki-launcher/lokinet');

module.exports = (app, prefix) => {
// set cache based on dispatcher object
cache = app.dispatcher.cache;
const utilties = overlay.setup(cache, app.dispatcher);
const { storage, logic, config, dialect } = utilties;

// start server
if (process.env.NPOMF_DB_FILENAME === undefined) {
process.env.NPOMF_DB_FILENAME = './databases/pomf_files.db';
}
var dir = pathUtil.dirname(process.env.NPOMF_DB_FILENAME)
if (!fs.existsSync(dir)) {
console.log('creating nodepomf database directory', dir);
lokinet.mkDirByPathSync(dir);
}

if (process.env.NPOMF_MAX_UPLOAD_SIZE === undefined) {
process.env.NPOMF_MAX_UPLOAD_SIZE = 1000000; // 10mb
}
// Loki messenger requires this to be an absolute URL
// I think it's better to fix messenger
// it's just a better server ux, if it doesn't have know it's public virtual hosting names
if (process.env.NPOMF_FILE_URL === undefined) {
process.env.NPOMF_FILE_URL = '/f'; // public url for downloading files
}
//process.env.NPOMF_PORT = 4000;
// we write uploaded fiels to ./files
// this seems to break the upload though...
// upload is relative to cwd
// download is relative to nodepomf/
//process.env.NPOMF_UPLOAD_DIRECTORY = '../files';
var fileUploadPath = process.env.NPOMF_UPLOAD_DIRECTORY ? process.env.NPOMF_UPLOAD_DIRECTORY : 'files'
// console.log('relative? download path', fileUploadPath)
// make sure it's an absolute path
if (fileUploadPath[0] !== '/') {
fileUploadPath = pathUtil.join(process.cwd(), fileUploadPath);
}
// console.log('absolute path', fileUploadPath)
if (!fs.existsSync(fileUploadPath)) {
console.log('creating nodepomf files directory', fileUploadPath);
lokinet.mkDirByPathSync(fileUploadPath);
}

const nodepomf = require('../../nodepomf/app');

app.use(prefix + '/upload', function(req, res) {
// fix up URL
req.url = prefix + '/upload';
nodepomf(req, res);
});
// NPOMF_UPLOAD_DIRECTORY is broken
/*
app.use(prefix + '/f', function(req, res) {
req.url = prefix + '/f' + req.url;
nodepomf(req, res);
});
*/

app.use(prefix + '/f', express.static(fileUploadPath));

// only pass through /f requests
/*
app.get(prefix + '/f', function(req, res) {
// redirect file from 127.0.0.1:4000

const url = 'http://127.0.0.1:4000/f/';

const request = http.get(url, function(response) {
const contentType = response.headers['content-type'];
//console.log(contentType);
res.setHeader('Content-Type', contentType);
response.pipe(res);
});

request.on('error', function(e){
console.error(e);
});
});
*/
}
2 changes: 1 addition & 1 deletion dialects/token/dialect_tokens_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getChallengeHandler = async (req, res) => {

const passes = await logic.passesWhitelist(pubKey);
if (!passes) {
console.log('get_challenge ', pubKey, 'not whitelisted');
console.log('get_challenge', pubKey, 'not whitelisted');
return res.status(401).type('application/json').end(JSON.stringify({
error: 'not allowed',
}));
Expand Down
Loading