git ssb

3+

ev / decent



Commit 645217d99c57cf97d45d14bceb62bf988559caed

depend on decent-ws

Ev Bogue committed on 5/22/2018, 7:59:21 PM
Parent: b5f3c11f9e0e43e79da1e0146bd5f9357360d53c

Files changed

.gitignorechanged
bin.jschanged
package-lock.jsonchanged
package.jsonchanged
plugins/ws/.travis.ymldeleted
plugins/ws/index.jsdeleted
plugins/ws/json-api.jsdeleted
.gitignoreView
@@ -1,3 +1,4 @@
1 +build/index.html
12 build/ssp
23 build/build.js
34 node_modules
bin.jsView
@@ -30,9 +30,9 @@
3030 .use(require('ssb-links'))
3131 .use(require('ssb-ebt'))
3232 .use(require('scuttlebot/plugins/invite'))
3333 .use(require('scuttlebot/plugins/local'))
34- .use(require('./plugins/ws'))
34 + .use(require('decent-ws'))
3535 .use({
3636 name: 'serve',
3737 version: '1.0.0',
3838 init: function (sbot) {
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 227490 bytes
New file size: 215219 bytes
package.jsonView
@@ -3,14 +3,16 @@
33 "version": "4.4.2",
44 "description": "A decent(tralized) network for communication and development",
55 "scripts": {
66 "start": "node bin server",
7 + "ssb": "node bin server --appname=ssb",
78 "build": "mkdir -p build && browserify node_modules/minbase/index.js | indexhtmlify > build/index.html",
89 "fonts": "git clone ssb://%XoC0EPXVomSYODRk0g9w6iGuD/vPCjinTVVW6Dz1hEQ=.sha256 build/ssp"
910 },
1011 "author": "Ev Bogue",
1112 "license": "MIT",
1213 "dependencies": {
14 + "decent-ws": "^1.0.0",
1315 "deep-extend": "^0.5.0",
1416 "emoji-server": "^1.0.0",
1517 "minbase": "^3.5.1",
1618 "multiblob-http": "^0.3.1",
@@ -30,8 +32,9 @@
3032 "ssb-ebt": "^5.1.4",
3133 "ssb-friends": "^2.4.0",
3234 "ssb-keys": "^7.0.13",
3335 "ssb-links": "^3.0.0",
36 + "ssb-names": "^3.1.1",
3437 "ssb-query": "^2.0.0",
3538 "ssb-ref": "^2.9.1",
3639 "stack": "^0.1.0",
3740 "yargs": "^11.0.0"
plugins/ws/.travis.ymlView
@@ -1,4 +1,0 @@
1-language: node_js
2-node_js:
3- - 0.6
4- - 0.8
plugins/ws/index.jsView
@@ -1,111 +1,0 @@
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 JSONApi = require('./json-api')
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-var READ_AND_ADD = [ //except for add, of course
19- 'get',
20- 'getLatest',
21- 'createLogStream',
22- 'createUserStream',
23-
24- 'createHistoryStream',
25- 'getAddress',
26-
27- 'links',
28-
29- 'blobs.add',
30- 'blobs.size',
31- 'blobs.has',
32- 'blobs.get',
33- 'blobs.changes',
34- 'blobs.createWants',
35-
36- 'add',
37-
38- 'query.read',
39- 'links2.read'
40-]
41-
42-
43-exports.name = 'ws'
44-exports.version = '1.0.0'
45-exports.manifest = {
46- getAddress: 'sync'
47-}
48-
49-function toId(id) {
50- if (typeof id !== 'string') {
51- return '@' + id.toString('base64') + '.ed25519' // isn't this available somewhere else?
52- } else throw new Error('toId() called on string. todo: clean this your mess.')
53-}
54-
55-exports.init = function (sbot, config) {
56-
57- var port
58- if(config.ws)
59- port = config.ws.port
60- if(!port)
61- port = 1024+(~~(Math.random()*(65536-1024)))
62-
63- var layers = []
64- var server = http.createServer(JSONApi(sbot, layers)).listen(port)
65-
66- function _auth (id, cb) {
67- cb(null, {allow: READ_AND_ADD, deny: null})
68- }
69-
70- var ms = MultiServer([
71- [
72- WS({server: server, port: port, host: config.host || 'localhost'}),
73- SHS({
74- keys: toSodiumKeys(config.keys),
75- appKey: (config.caps && new Buffer(config.caps.shs, "base64")) || cap,
76- auth: function (id, cb) {
77- sbot.auth(toId(id), function (err, allowed) {
78- if(err || allowed) cb(err, allowed)
79- else _auth(id, cb)
80- })
81- },
82- timeout: config.timeout
83- })
84- ]
85- ])
86-
87- var close = ms.server(function (stream) {
88- var manifest = sbot.getManifest()
89- var rpc = muxrpc({}, manifest)(sbot, stream.auth)
90- rpc.id = toId(stream.remote)
91- pull(stream, rpc.createStream(), stream)
92- })
93-
94- //close when the server closes.
95- sbot.close.hook(function (fn, args) {
96- close()
97- fn.apply(this, args)
98- })
99-
100- return {
101- getAddress: function () {
102- return ms.stringify()
103- },
104- use: function (handler) {
105- layers.push(handler)
106- }
107-
108- }
109-}
110-
111-
plugins/ws/json-api.jsView
@@ -1,55 +1,0 @@
1-'use strict'
2-var ref = require('ssb-ref')
3-var Stack = require('stack')
4-var BlobsHttp = require('multiblob-http')
5-var pull = require('pull-stream')
6-var URL = require('url')
7-var Emoji = require('emoji-server')
8-
9-function send(res, obj) {
10- res.writeHead(200, {'Content-Type': 'application/json'})
11- res.end(JSON.stringify(obj, null, 2))
12-}
13-
14-module.exports = function (sbot, layers) {
15- var prefix = '/blobs'
16- return Stack(
17- function (req, res, next) {
18- Stack.compose.apply(null, layers)(req, res, next)
19- },
20- Emoji('/img/emoji'),
21- //blobs are served over CORS, so you can get blobs from any pub.
22- function (req, res, next) {
23- res.setHeader('Access-Control-Allow-Origin', '*')
24- res.setHeader("Access-Control-Allow-Headers",
25- "Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since");
26- res.setHeader("Access-Control-Allow-Methods", "GET", "HEAD");
27- next()
28- },
29- function (req, res, next) {
30- var id
31- try { id = decodeURIComponent(req.url.substring(5)) }
32- catch (_) { id = req.url.substring(5) }
33- console.log(req.url, id)
34- if(req.url.substring(0, 5) !== '/msg/' || !ref.isMsg(id)) return next()
35-
36- sbot.get(id, function (err, msg) {
37- if(err) return next(err)
38- send(res, {key: id, value: msg})
39- })
40- },
41- function (req, res, next) {
42- if(!(req.method === "GET" || req.method == 'HEAD')) return next()
43-
44- var u = URL.parse('http://makeurlparseright.com'+req.url)
45- var hash = decodeURIComponent(u.pathname.substring((prefix+'/get/').length))
46- //check if we don't already have this, tell blobs we want it, if necessary.
47- sbot.blobs.has(hash, function (err, has) {
48- if(has) next()
49- else sbot.blobs.want(hash, function (err, has) { next() })
50- })
51- },
52- BlobsHttp(sbot.blobs, prefix)
53- )
54-}
55-

Built with git-ssb-web