git ssb

2+

ev / minsbot



Commit 68ebbe79904bf073bc8afdedfb5f6fff70fdc733

in-house decent-ws and load ssb-search

Ev Bogue committed on 2/10/2019, 6:15:17 PM
Parent: 3d269c98d409d84e87895f410008a8df9e94f15d

Files changed

bin.jschanged
package-lock.jsonchanged
package.jsonchanged
decent-ws/blob-server.jsadded
decent-ws/index.jsadded
decent-ws/package.jsonadded
decent-ws/readme.mdadded
bin.jsView
@@ -49,9 +49,10 @@
4949 .use(require('./plugins/local'))
5050 .use(require('./plugins/logging'))
5151 .use(require('./query'))
5252 .use(require('ssb-links'))
53- .use(require('decent-ws'))
53 + .use(require('ssb-search'))
54 + .use(require('./decent-ws'))
5455 .use(require('ssb-ebt'))
5556 .use({
5657 name: 'serve',
5758 version: '1.0.0',
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 140567 bytes
New file size: 141655 bytes
package.jsonView
@@ -70,8 +70,9 @@
7070 "ssb-keys": "7.0.16",
7171 "ssb-links": "3.0.3",
7272 "ssb-msgs": "5.2.0",
7373 "ssb-ref": "2.11.1",
74 + "ssb-search": "^1.1.2",
7475 "stack": "^0.1.0",
7576 "statistics": "3.3.0",
7677 "stream-to-pull-stream": "1.7.2",
7778 "tape": "^4.9.2",
decent-ws/blob-server.jsView
@@ -1,0 +1,22 @@
1 +var Stack = require('stack')
2 +var BlobsHttp = require('multiblob-http')
3 +var Emoji = require('emoji-server')
4 +
5 +module.exports = function (sbot, layers) {
6 + return Stack(
7 + function (req, res, next) {
8 + Stack.compose.apply(null, layers)(req, res, next)
9 + },
10 + Emoji('/img/emoji'),
11 + function (req, res, next) {
12 + if(!(req.method === "GET" || req.method == 'HEAD')) return next()
13 + var hash = req.url.substring(('/blobs/get/').length)
14 + sbot.blobs.has(hash, function (err, has) {
15 + if(has) next()
16 + else sbot.blobs.want(hash, function (err, has) { next() })
17 + })
18 + },
19 + BlobsHttp(sbot.blobs, '/blobs')
20 + )
21 +}
22 +
decent-ws/index.jsView
@@ -1,0 +1,108 @@
1 +var MultiServer = require('multiserver')
2 +var WS = require('multiserver/plugins/ws')
3 +var SHS = require('multiserver/plugins/shs')
4 +var http = require('http')
5 +var muxrpc = require('muxrpc')
6 +var pull = require('pull-stream')
7 +var blobServer = require('./blob-server')
8 +
9 +function toSodiumKeys(keys) {
10 + return {
11 + publicKey:
12 + new Buffer(keys.public.replace('.ed25519',''), 'base64'),
13 + secretKey:
14 + new Buffer(keys.private.replace('.ed25519',''), 'base64'),
15 + }
16 +}
17 +
18 +// you need to add manifest items that are allowed below to use them over websockets
19 +var READ_AND_ADD = [
20 + 'get',
21 + 'getLatest',
22 + 'createLogStream',
23 + 'createUserStream',
24 + 'createHistoryStream',
25 + 'getAddress',
26 + 'blobs.add',
27 + 'blobs.size',
28 + 'blobs.has',
29 + 'blobs.get',
30 + 'blobs.changes',
31 + 'blobs.createWants',
32 + 'add',
33 + 'links',
34 + 'query.read',
35 + 'backlinks.read',
36 + 'friends',
37 + 'search.query'
38 +]
39 +
40 +
41 +exports.name = 'ws'
42 +exports.version = '1.0.0'
43 +exports.manifest = {
44 + getAddress: 'sync'
45 +}
46 +
47 +function toId(id) {
48 + if (typeof id !== 'string') {
49 + return '@' + id.toString('base64') + '.ed25519' // isn't this available somewhere else?
50 + } else throw new Error('toId() called on string. todo: clean this your mess.')
51 +}
52 +
53 +exports.init = function (sbot, config) {
54 +
55 + var port
56 + if(config.ws)
57 + port = config.ws.port
58 + if(!port)
59 + port = 1024+(~~(Math.random()*(65536-1024)))
60 +
61 + var layers = []
62 + var server = http.createServer(blobServer(sbot, layers)).listen(port)
63 +
64 + function _auth (id, cb) {
65 + cb(null, {allow: READ_AND_ADD, deny: null})
66 + }
67 +
68 + var ms = MultiServer([
69 + [
70 + WS({server: server, port: port, host: config.host || 'localhost'}),
71 + SHS({
72 + keys: toSodiumKeys(config.keys),
73 + appKey: (config.caps && new Buffer(config.caps.shs, "base64")) || cap,
74 + auth: function (id, cb) {
75 + sbot.auth(toId(id), function (err, allowed) {
76 + if(err || allowed) cb(err, allowed)
77 + else _auth(id, cb)
78 + })
79 + },
80 + timeout: config.timeout
81 + })
82 + ]
83 + ])
84 +
85 + var close = ms.server(function (stream) {
86 + var manifest = sbot.getManifest()
87 + var rpc = muxrpc({}, manifest)(sbot, stream.auth)
88 + rpc.id = toId(stream.remote)
89 + pull(stream, rpc.createStream(), stream)
90 + })
91 +
92 + sbot.close.hook(function (fn, args) {
93 + close()
94 + fn.apply(this, args)
95 + })
96 +
97 + return {
98 + getAddress: function () {
99 + return ms.stringify()
100 + },
101 + use: function (handler) {
102 + layers.push(handler)
103 + }
104 +
105 + }
106 +}
107 +
108 +
decent-ws/package.jsonView
@@ -1,0 +1,50 @@
1 +{
2 + "_args": [
3 + [
4 + "decent-ws@1.0.4",
5 + "/home/ev/minsbot"
6 + ]
7 + ],
8 + "_from": "decent-ws@1.0.4",
9 + "_id": "decent-ws@1.0.4",
10 + "_inBundle": false,
11 + "_integrity": "sha512-p7qTBYZhBzLBhyaUCzduUG2co8HhFDidyXAW/NCUbtGE5aQh2JNphqn7BZMA0LdVL/hXW/seNzuVyqhMC4bBoA==",
12 + "_location": "/decent-ws",
13 + "_phantomChildren": {},
14 + "_requested": {
15 + "type": "version",
16 + "registry": true,
17 + "raw": "decent-ws@1.0.4",
18 + "name": "decent-ws",
19 + "escapedName": "decent-ws",
20 + "rawSpec": "1.0.4",
21 + "saveSpec": null,
22 + "fetchSpec": "1.0.4"
23 + },
24 + "_requiredBy": [
25 + "/"
26 + ],
27 + "_resolved": "https://registry.npmjs.org/decent-ws/-/decent-ws-1.0.4.tgz",
28 + "_spec": "1.0.4",
29 + "_where": "/home/ev/minsbot",
30 + "author": {
31 + "name": "Ev Bogue",
32 + "email": "ev@evbogue.com"
33 + },
34 + "bugs": {
35 + "url": "https://github.com/evbogue/decent-ws/issues"
36 + },
37 + "description": "websockets for decent",
38 + "homepage": "https://github.com/evbogue/decent-ws#readme",
39 + "license": "MIT",
40 + "main": "index.js",
41 + "name": "decent-ws",
42 + "repository": {
43 + "type": "git",
44 + "url": "git+ssh://git@github.com/evbogue/decent-ws.git"
45 + },
46 + "scripts": {
47 + "test": "echo \"Error: no test specified\" && exit 1"
48 + },
49 + "version": "1.0.4"
50 +}
decent-ws/readme.mdView
@@ -1,0 +1,14 @@
1 +# decent-ws
2 +
3 +This is a fork of `ssb-ws`. There are some key differences that should be noticed:
4 +
5 ++ connections are _not_ required to be friends to use websocket auth -- this may change in the future, but right now the decent culture is well, decent
6 ++ the MANIFEST has been modified for use with decent plugins
7 ++ JSONApi is removed
8 ++ CORS is only set once in multiblob-http
9 +
10 +Otherwise it's basically the same, but I had to fork because of these modifications.
11 +
12 +In the future I want to spend some time getting these changes into the main `ssb-ws` module, but right now I don't have time. If you want to figure out how to support the above changes inthe main `ssb-ws` module, pull-requests requested! -Ev
13 +
14 +MIT

Built with git-ssb-web