Merge branch 'master' of github.com:fraction/oasis into image-search

This commit is contained in:
Jacob Karlsson 2020-05-06 20:05:37 +02:00
commit c205826b48
3 changed files with 69 additions and 105 deletions

75
package-lock.json generated
View File

@ -305,15 +305,18 @@
"integrity": "sha512-Lnle0J8t+Z+jFg78GFFnGo+Fphxaco9K9SppeBDsI27QBRBumxeGAMeOg5wt6XbAuj5pQWmAEWWEwPz4PYGMHw=="
},
"@fraction/flotilla": {
"version": "github:Powersource/flotilla#8f0077d7501b595e66edf6b0625f2b7f823b5f3a",
"from": "github:Powersource/flotilla#add-meme-2",
"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-conn": "^0.16.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",
@ -611,9 +614,9 @@
"dev": true
},
"@types/lodash": {
"version": "4.14.149",
"resolved": false,
"integrity": "sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==",
"version": "4.14.150",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.150.tgz",
"integrity": "sha512-kMNLM5JBcasgYscD9x/Gvr6lTAv2NVgsKtet/hm93qMyf/D1pt+7jeEZklKJKxMVmXjxbRVQQGfqDSfipYCO6w==",
"dev": true
},
"@types/markdown-it": {
@ -736,9 +739,9 @@
}
},
"@types/supertest": {
"version": "2.0.8",
"resolved": "https://registry.npmjs.org/@types/supertest/-/supertest-2.0.8.tgz",
"integrity": "sha512-wcax7/ip4XSSJRLbNzEIUVy2xjcBIZZAuSd2vtltQfRK7kxhx5WMHbLHkYdxN3wuQCrwpYrg86/9byDjPXoGMA==",
"version": "2.0.9",
"resolved": "https://registry.npmjs.org/@types/supertest/-/supertest-2.0.9.tgz",
"integrity": "sha512-0BTpWWWAO1+uXaP/oA0KW1eOZv4hc0knhrWowV06Gwwz3kqQxNO98fUFM2e15T+PdPRmOouNFrYvaBgdojPJ3g==",
"dev": true,
"requires": {
"@types/superagent": "*"
@ -3867,9 +3870,9 @@
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"fsevents": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.2.tgz",
"integrity": "sha512-R4wDiBwZ0KzpgOWetKDug1FZcYhqYnUYKtfZYt4mD5SBz76q0KR4Q9o7GIPamsVPGmW3EYPPJ0dOOjvx32ldZA==",
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz",
"integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==",
"dev": true,
"optional": true
},
@ -8991,9 +8994,9 @@
}
},
"ssb-conn": {
"version": "0.16.2",
"resolved": "https://registry.npmjs.org/ssb-conn/-/ssb-conn-0.16.2.tgz",
"integrity": "sha512-KinjdF3tOMmlcjKK4bnTso0x6GYfL+9tE2gSacRDldaLui73nDLxSwjnSoE188wDXUEumJU0LvOff4AHm2XyLQ==",
"version": "0.17.0",
"resolved": "https://registry.npmjs.org/ssb-conn/-/ssb-conn-0.17.0.tgz",
"integrity": "sha512-GrEPQ3KSYDkc0k41Y14iRKXURUWYyBtO+D5PXZ2JfWhNUZByeuCkKkkSIFP1zU5u0eFleYQW7ST+LGCKET448w==",
"requires": {
"debug": "~4.1.1",
"has-network2": "0.0.1",
@ -10154,7 +10157,8 @@
},
"dependencies": {
"@babel/helpers": {
"version": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.8.4.tgz",
"version": "7.8.4",
"resolved": false,
"integrity": "sha512-VPbe7wcQ4chu4TDQjimHv/5tj73qz88o12EPkO2ValS2QiQS/1F2SsjyIGNnAD0vF/nZS6Cf9i+vW6HIlnaR8w==",
"requires": {
"@babel/template": "^7.8.3",
@ -10163,14 +10167,16 @@
}
},
"@babel/runtime": {
"version": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.7.tgz",
"version": "7.8.7",
"resolved": false,
"integrity": "sha512-+AATMUFppJDw6aiR5NVPHqIQBlV/Pj8wY/EZH+lmvRdUo9xBaz/rF3alAwFJQavvKfeOlPE7oaaDHVbcySbCsg==",
"requires": {
"regenerator-runtime": "^0.13.4"
}
},
"arrify": {
"version": "https://registry.npmjs.org/arrify/-/arrify-2.0.1.tgz",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/arrify/-/arrify-2.0.1.tgz",
"integrity": "sha512-3duEwti880xqi4eAMN8AyR4a0ByT90zoYdLlevfrvU43vb0YZwZVfxOgxWrLXXXpyugL0hNZc9G6BiB5B3nUug=="
},
"astral-regex": {
@ -10179,19 +10185,23 @@
"integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ=="
},
"callsites": {
"version": "https://registry.npmjs.org/callsites/-/callsites-2.0.0.tgz",
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/callsites/-/callsites-2.0.0.tgz",
"integrity": "sha1-BuuE8A7qQT2oav/vrL/7Ngk7PFA="
},
"color-name": {
"version": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
},
"esprima": {
"version": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
},
"globals": {
"version": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz",
"version": "11.12.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz",
"integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA=="
},
"is-fullwidth-code-point": {
@ -10209,7 +10219,8 @@
}
},
"ms": {
"version": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"regenerator-runtime": {
@ -10218,18 +10229,21 @@
"integrity": "sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA=="
},
"resolve": {
"version": "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz",
"version": "1.15.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz",
"integrity": "sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w==",
"requires": {
"path-parse": "^1.0.6"
}
},
"resolve-from": {
"version": "https://registry.npmjs.org/resolve-from/-/resolve-from-3.0.0.tgz",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-3.0.0.tgz",
"integrity": "sha1-six699nWiBvItuZTM17rywoYh0g="
},
"slice-ansi": {
"version": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-3.0.0.tgz",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-3.0.0.tgz",
"integrity": "sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==",
"requires": {
"ansi-styles": "^4.0.0",
@ -10272,7 +10286,8 @@
}
},
"type-fest": {
"version": "https://registry.npmjs.org/type-fest/-/type-fest-0.11.0.tgz",
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.11.0.tgz",
"integrity": "sha512-OdjXJxnCN1AvyLSzeKIgXTXxV+99ZuXl3Hpo9XpJAv9MBcHrrJOQ5kV7ypXOuQie+AmWG25hLbiKdwYTifzcfQ=="
},
"which": {
@ -11434,9 +11449,9 @@
}
},
"yargs-parser": {
"version": "18.1.1",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.1.tgz",
"integrity": "sha512-KRHEsOM16IX7XuLnMOqImcPNbLVXMNHYAoFc3BKR8Ortl5gzDbtXvvEoGx9imk5E+X1VeNKNlcHr8B8vi+7ipA==",
"version": "18.1.3",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz",
"integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==",
"requires": {
"camelcase": "^5.0.0",
"decamelize": "^1.2.0"

View File

@ -22,7 +22,7 @@
},
"dependencies": {
"@fraction/base16-css": "^1.1.0",
"@fraction/flotilla": "github:Powersource/flotilla#add-meme-2",
"@fraction/flotilla": "^5.2.0",
"@koa/router": "^8.0.0",
"debug": "^4.1.1",
"env-paths": "^2.2.0",
@ -59,13 +59,13 @@
"@types/koa-mount": "^4.0.0",
"@types/koa-static": "^4.0.1",
"@types/koa__router": "^8.0.2",
"@types/lodash": "^4.14.149",
"@types/lodash": "^4.14.150",
"@types/markdown-it": "^0.0.9",
"@types/mkdirp": "^1.0.0",
"@types/nodemon": "^1.19.0",
"@types/pull-stream": "^3.6.0",
"@types/sharp": "^0.24.0",
"@types/supertest": "^2.0.8",
"@types/supertest": "^2.0.9",
"@types/yargs": "^15.0.4",
"changelog-version": "^1.0.1",
"common-good": "^2.0.3",

View File

@ -11,18 +11,12 @@ const flotilla = require("@fraction/flotilla");
const ssbTangle = require("ssb-tangle");
const debug = require("debug")("oasis");
const path = require("path");
const pull = require("pull-stream");
const lodash = require("lodash");
const socketPath = path.join(ssbConfig.path, "socket");
const publicInteger = ssbConfig.keys.public.replace(".ed25519", "");
const remote = `unix:${socketPath}~noauth:${publicInteger}`;
// This is unnecessary when https://github.com/ssbc/ssb-config/pull/72 is merged
ssbConfig.connections.incoming.unix = [
{ scope: "device", transform: "noauth" },
];
/**
* @param formatter {string} input
* @param args {any[]} input
@ -110,18 +104,13 @@ const ensureConnection = (customConfig) => {
debug("Connection attempts to existing Scuttlebutt services failed");
log("Starting Scuttlebutt service");
// Start with the default SSB-Config object.
const server = flotilla(ssbConfig);
// Adjust with `customConfig`, which declares further preferences.
serverHandle = server(customConfig);
serverHandle = flotilla(customConfig);
// Give the server a moment to start. This is a race condition. :/
setTimeout(() => {
attemptConnection()
.then((ssb) => {
autoStagePeers({ ssb, config: customConfig });
resolve(ssb);
})
.then(resolve)
.catch((e) => {
throw new Error(e);
});
@ -136,60 +125,6 @@ const ensureConnection = (customConfig) => {
return pendingConnection;
};
const autoStagePeers = ({ ssb, config }) => {
// TODO: This does not start when Oasis is started in --offline mode, which
// is great, but if you start Oasis in --offline mode and select 'Start
// networking' then this doesn't come into play.
//
// The right place to fix this is in the scheduler, and this entire function
// should be replaced by: https://github.com/staltz/ssb-conn/pull/17
if (config.conn.autostart !== true) {
return;
}
const inProgress = {};
const maxHops = lodash.get(
ssbConfig,
"friends.hops",
lodash.get(ssbConfig, "friends.hops", 0)
);
const add = (address) => {
inProgress[address] = true;
return () => {
inProgress[address] = false;
};
};
ssb.friends.hops().then((hops) => {
pull(
ssb.conn.stagedPeers(),
pull.drain((x) => {
x.filter(([address, data]) => {
const notInProgress = inProgress[address] !== true;
const key = data.key;
const haveHops = typeof hops[key] === "number";
const hopValue = haveHops ? hops[key] : Infinity;
// Negative hops means blocked
const isNotBlocked = hopValue >= 0;
const withinHops = isNotBlocked && hopValue <= maxHops;
return notInProgress && withinHops;
}).forEach(([address, data]) => {
const done = add(address);
debug(
`Connecting to staged peer at ${
hops[data.key]
}/${maxHops} hops: ${address}`
);
ssb.conn.connect(address, data).then(done).catch(done);
});
})
);
});
};
module.exports = ({ offline }) => {
if (offline) {
log("Offline mode activated - not connecting to scuttlebutt peers or pubs");
@ -198,11 +133,25 @@ module.exports = ({ offline }) => {
);
}
const customConfig = {
conn: {
autostart: !offline,
},
};
// Make a copy of `ssbConfig` to avoid mutating.
const customConfig = JSON.parse(JSON.stringify(ssbConfig));
// This is unnecessary when https://github.com/ssbc/ssb-config/pull/72 is merged
customConfig.connections.incoming.unix = [
{ scope: "device", transform: "noauth" },
];
// Only change the config if `--offline` is true.
if (offline === true) {
lodash.set(customConfig, "conn.autostart", false);
}
// Use `conn.hops`, or default to `friends.hops`, or default to `0`.
lodash.set(
customConfig,
"conn.hops",
lodash.get(ssbConfig, "conn.hops", lodash.get(ssbConfig.friends.hops, 0))
);
/**
* This is "cooler", a tiny interface for opening or reusing an instance of