From c993adc01aef3efddfb8fe50fa32aaf8853345d9 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Sun, 22 Nov 2020 10:06:35 -0800 Subject: [PATCH] Merge flotilla source code into Oasis Problem: I thought it would be a good idea to keep our SSB stack in another module but it just creates friction and adds another layer to our stack that has to be independently upgraded and versioned. Solution: Merge the @fraction/flotilla source code into Oasis so that we don't have to maintain two separate projects. --- package-lock.json | 34 ---------------------- package.json | 25 +++++++++++++++- src/ssb/flotilla.js | 55 ++++++++++++++++++++++++++++++++++++ src/{ssb.js => ssb/index.js} | 3 +- 4 files changed, 81 insertions(+), 36 deletions(-) create mode 100644 src/ssb/flotilla.js rename src/{ssb.js => ssb/index.js} (99%) diff --git a/package-lock.json b/package-lock.json index d687e20..e39f475 100644 --- a/package-lock.json +++ b/package-lock.json @@ -253,40 +253,6 @@ "resolved": "https://registry.npmjs.org/@fraction/base16-css/-/base16-css-1.1.0.tgz", "integrity": "sha512-Lnle0J8t+Z+jFg78GFFnGo+Fphxaco9K9SppeBDsI27QBRBumxeGAMeOg5wt6XbAuj5pQWmAEWWEwPz4PYGMHw==" }, - "@fraction/flotilla": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@fraction/flotilla/-/flotilla-5.2.0.tgz", - "integrity": "sha512-9uF6Zq/K/qpO54aWkpMK247YbNHok42NMchkBNN5TVIMK+tQKbNW3YR4xgUyUCmVExaO1L5Xk9vHcevg8Pa1NQ==", - "requires": { - "debug": "^4.1.1", - "lodash.shuffle": "^4.2.0", - "secret-stack": "^6.3.0", - "ssb-about": "^2.0.1", - "ssb-backlinks": "^1.0.0", - "ssb-blobs": "^1.2.2", - "ssb-config": "^3.4.4", - "ssb-conn": "^0.17.0", - "ssb-db": "^19.4.0", - "ssb-ebt": "^5.6.7", - "ssb-friends": "^4.1.4", - "ssb-invite": "^2.1.3", - "ssb-lan": "^0.2.0", - "ssb-logging": "^1.0.0", - "ssb-master": "^1.0.3", - "ssb-meme": "^1.0.4", - "ssb-no-auth": "^1.0.0", - "ssb-onion": "^1.0.0", - "ssb-ooo": "^1.3.1", - "ssb-plugins": "^1.0.2", - "ssb-query": "^2.4.3", - "ssb-replicate": "^1.3.0", - "ssb-room": "^1.2.2", - "ssb-search": "^1.2.1", - "ssb-tangle": "^1.0.1", - "ssb-unix-socket": "^1.0.0", - "ssb-ws": "^6.2.3" - } - }, "@koa/router": { "version": "8.0.8", "resolved": "https://registry.npmjs.org/@koa/router/-/router-8.0.8.tgz", diff --git a/package.json b/package.json index 2b14263..52f4914 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ }, "dependencies": { "@fraction/base16-css": "^1.1.0", - "@fraction/flotilla": "^5.2.0", "@koa/router": "^8.0.0", "debug": "^4.1.1", "env-paths": "^2.2.0", @@ -35,6 +34,7 @@ "koa-mount": "^4.0.0", "koa-static": "^5.0.0", "lodash": "^4.17.11", + "lodash.shuffle": "^4.2.0", "markdown-it": "^12.0.2", "open": "^7.0.3", "piexifjs": "^1.0.4", @@ -44,15 +44,38 @@ "pull-sort": "^1.0.2", "pull-stream": "^3.6.12", "require-style": "^1.1.0", + "secret-stack": "^6.3.0", "sharp": "^0.26.3", + "ssb-about": "^2.0.1", + "ssb-backlinks": "^1.0.0", + "ssb-blobs": "^1.2.2", "ssb-client": "^4.9.0", "ssb-config": "^3.4.4", + "ssb-conn": "^0.17.0", + "ssb-db": "^19.4.0", + "ssb-ebt": "^5.6.7", + "ssb-friends": "^4.1.4", + "ssb-invite": "^2.1.3", + "ssb-lan": "^0.2.0", + "ssb-logging": "^1.0.0", "ssb-markdown": "^6.0.7", + "ssb-master": "^1.0.3", + "ssb-meme": "^1.0.4", "ssb-mentions": "^0.5.2", "ssb-msgs": "^5.2.0", + "ssb-no-auth": "^1.0.0", + "ssb-onion": "^1.0.0", + "ssb-ooo": "^1.3.1", + "ssb-plugins": "^1.0.2", + "ssb-query": "^2.4.3", "ssb-ref": "^2.13.9", + "ssb-replicate": "^1.3.0", + "ssb-room": "^1.2.2", + "ssb-search": "^1.2.1", "ssb-tangle": "^1.0.1", "ssb-thread-schema": "^1.1.1", + "ssb-unix-socket": "^1.0.0", + "ssb-ws": "^6.2.3", "yargs": "^16.1.1" }, "devDependencies": { diff --git a/src/ssb/flotilla.js b/src/ssb/flotilla.js new file mode 100644 index 0000000..c6d5ee9 --- /dev/null +++ b/src/ssb/flotilla.js @@ -0,0 +1,55 @@ +const stack = require("secret-stack"); +const shuffle = require("lodash.shuffle"); +const debug = require("debug")("oasis"); +const ssbConfig = require("ssb-config"); + +const plugins = [ + // Authentication often hooked for authentication. + require("ssb-master"), + // Methods often used during init(). + require("ssb-db"), + // Method `replicate()` often hooked for improvements. + require("ssb-replicate"), + // Required by ssb-about, ssb-tangle, etc. + require("ssb-backlinks"), + // Required by ssb-room + require("ssb-conn"), + shuffle([ + require("ssb-about"), + require("ssb-blobs"), + require("ssb-ebt"), + require("ssb-friends"), + require("ssb-invite"), + require("ssb-lan"), + require("ssb-logging"), + require("ssb-no-auth"), + require("ssb-onion"), + require("ssb-ooo"), + require("ssb-plugins"), + require("ssb-query"), + require("ssb-room/tunnel/client"), + require("ssb-search"), + require("ssb-tangle"), + require("ssb-unix-socket"), + require("ssb-ws"), + require("ssb-meme"), + ]), +]; + +module.exports = (config) => { + const server = stack(); + + // TODO: Move this out of the main function. + const walk = (input) => { + if (Array.isArray(input)) { + input.forEach(walk); + } else { + debug(input.name || "???"); + server.use(input); + } + }; + + walk(plugins); + + return server({ ...ssbConfig, ...config }); +}; diff --git a/src/ssb.js b/src/ssb/index.js similarity index 99% rename from src/ssb.js rename to src/ssb/index.js index 3886a3c..2fd7107 100644 --- a/src/ssb.js +++ b/src/ssb/index.js @@ -7,12 +7,13 @@ const { promisify } = require("util"); const ssbClient = require("ssb-client"); const ssbConfig = require("ssb-config"); -const flotilla = require("@fraction/flotilla"); const ssbTangle = require("ssb-tangle"); const debug = require("debug")("oasis"); const path = require("path"); const lodash = require("lodash"); +const flotilla = require("./flotilla"); + const socketPath = path.join(ssbConfig.path, "socket"); const publicInteger = ssbConfig.keys.public.replace(".ed25519", ""); const remote = `unix:${socketPath}~noauth:${publicInteger}`;