git ssb

1+

Dominic / secure-scuttlebutt



Commit 5f4e5cc3e56c96ddb795f9c1966bc83775100b01

remove unneeded/unused files

Dominic Tarr committed on 1/14/2019, 2:04:10 AM
Parent: 8b4c9dd6a9b3f306a2c3137cab8c6bfd353928e3

Files changed

create.jschanged
index.jschanged
test/add.jschanged
test/end-to-end.jschanged
test/feed.jschanged
test/history.jschanged
test/links.jschanged
test/log.jschanged
test/mesages-by-type.jschanged
test/msg-encoding.jschanged
test/validation.jschanged
test/write-stream.jschanged
defaults.jsdeleted
plugin.jsdeleted
create.jsView
@@ -1,7 +1,152 @@
1-var SSB = require('./')
1+'use strict'
22
3+var join = require('path').join
4+var EventEmitter = require('events')
5+
6+var pull = require('pull-stream')
7+var ref = require('ssb-ref')
8+var ssbKeys = require('ssb-keys')
9+
10+var u = require('./util')
11+
12+function isString (s) {
13+ return typeof s === 'string'
14+}
15+
16+function errorCB (err) {
17+ if (err) throw err
18+}
19+
320 module.exports = function (path, opts, keys) {
4- opts = opts || require('./defaults')
5- return SSB(null, opts, keys, path)
21+ //_ was legacy db. removed that, but for backwards compatibilty reasons do not change interface
22+ if(!path) throw new Error('path must be provided')
23+
24+ keys = keys || ssbKeys.generate()
25+
26+ var db = require('./db')(join(opts.path || path, 'flume'), keys, opts)
27+
28+ // UGLY HACK, but...
29+ // fairly sure that something up the stack expects ssb to be an event emitter.
30+ db.__proto__ = new EventEmitter() // eslint-disable-line
31+
32+ db.opts = opts
33+
34+ var _get = db.get
35+
36+ db.get = function (key, cb) {
37+ let isPrivate = false
38+ let unbox
39+ if (typeof key === 'object') {
40+ isPrivate = key.private === true
41+ unbox = key.unbox
42+ key = key.id
43+ }
44+
45+ if (ref.isMsg(key)) {
46+ return db.keys.get(key, function (err, data) {
47+ if (err) return cb(err)
48+
49+ if (isPrivate && unbox) {
50+ data = db.unbox(data, unbox)
51+ }
52+
53+ let result
54+
55+ if (isPrivate) {
56+ result = data.value
57+ } else {
58+ result = u.originalValue(data.value)
59+ }
60+
61+ cb(null, result)
62+ })
63+ } else if (ref.isMsgLink(key)) {
64+ var link = ref.parseLink(key)
65+ return db.get({
66+ id: link.link,
67+ private: true,
68+ unbox: link.query.unbox.replace(/\s/g, '+')
69+ }, cb)
70+ } else if (Number.isInteger(key)) {
71+ _get(key, cb) // seq
72+ } else {
73+ throw new Error('ssb-db.get: key *must* be a ssb message id or a flume offset')
74+ }
75+ }
76+
77+ db.add = function (msg, cb) {
78+ db.queue(msg, function (err, data) {
79+ if (err) cb(err)
80+ else db.flush(function () { cb(null, data) })
81+ })
82+ }
83+
84+ db.createFeed = function (keys) {
85+ if (!keys) keys = ssbKeys.generate()
86+ function add (content, cb) {
87+ // LEGACY: hacks to support add as a continuable
88+ if (!cb) { return function (cb) { add(content, cb) } }
89+
90+ db.append({ content: content, keys: keys }, cb)
91+ }
92+ return {
93+ add: add,
94+ publish: add,
95+ id: keys.id,
96+ keys: keys
97+ }
98+ }
99+
100+ db.createRawLogStream = function (opts) {
101+ return db.stream(opts)
102+ }
103+
104+ // pull in the features that are needed to pass the tests
105+ // and that sbot, etc uses but are slow.
106+ require('./extras')(db, opts, keys)
107+
108+ // writeStream - used in (legacy) replication.
109+ db.createWriteStream = function (cb) {
110+ cb = cb || errorCB
111+ return pull(
112+ pull.asyncMap(function (data, cb) {
113+ db.queue(data, function (err, msg) {
114+ if (err) {
115+ db.emit('invalid', err, msg)
116+ }
117+ setImmediate(cb)
118+ })
119+ }),
120+ pull.drain(null, function (err) {
121+ if (err) return cb(err)
122+ db.flush(cb)
123+ })
124+ )
125+ }
126+
127+ // should be private
128+ db.createHistoryStream = db.clock.createHistoryStream
129+
130+ // called with [id, seq] or "<id>:<seq>"
131+ db.getAtSequence = function (seqid, cb) {
132+ // will NOT expose private plaintext
133+ db.clock.get(isString(seqid) ? seqid.split(':') : seqid, function (err, value) {
134+ if (err) cb(err)
135+ else cb(null, u.originalData(value))
136+ })
137+ }
138+
139+ db.getVectorClock = function (_, cb) {
140+ if (!cb) cb = _
141+ db.last.get(function (err, h) {
142+ if (err) return cb(err)
143+ var clock = {}
144+ for (var k in h) { clock[k] = h[k].sequence }
145+ cb(null, clock)
146+ })
147+ }
148+
149+ return db
6150 }
7151
152+
index.jsView
@@ -1,152 +1,181 @@
1-'use strict'
1+//var SecretStack = require('secret-stack')
2+var create = require('./create')
3+var ssbKeys = require('ssb-keys')
4+var path = require('path')
5+var osenv = require('osenv')
6+var mkdirp = require('mkdirp')
7+var rimraf = require('rimraf')
8+var mdm = require('mdmanifest')
9+var valid = require('./lib/validators')
10+var pkg = require('./package.json')
211
3-var join = require('path').join
4-var EventEmitter = require('events')
12+function isString(s) { return 'string' === typeof s }
13+function isObject(o) { return 'object' === typeof o }
14+function isFunction (f) { return 'function' === typeof f }
15+// create SecretStack definition
16+var fs = require('fs')
17+var manifest = mdm.manifest(fs.readFileSync(path.join(__dirname, 'api.md'), 'utf-8'))
518
6-var pull = require('pull-stream')
7-var ref = require('ssb-ref')
8-var ssbKeys = require('ssb-keys')
19+manifest.seq = 'async'
20+manifest.usage = 'sync'
21+manifest.clock = 'async'
22+manifest.version = 'sync'
923
10-var u = require('./util')
24+module.exports = {
25+ manifest: manifest,
26+ permissions: {
27+ master: {allow: null, deny: null},
28+ anonymous: {allow: ['createHistoryStream'], deny: null}
29+ },
30+ init: function (api, opts) {
1131
12-function isString (s) {
13- return typeof s === 'string'
14-}
32+ // .temp: use a /tmp data directory
33+ // (useful for testing)
34+ if(opts.temp) {
35+ var name = isString(opts.temp) ? opts.temp : ''+Date.now()
36+ opts.path = path.join(osenv.tmpdir(), name)
37+ rimraf.sync(opts.path)
38+ }
1539
16-function errorCB (err) {
17- if (err) throw err
18-}
40+ // load/create secure scuttlebutt data directory
41+ mkdirp.sync(opts.path)
1942
20-module.exports = function (_, opts, keys, path) {
21- //_ was legacy db. removed that, but for backwards compatibilty reasons do not change interface
22- if(!path) throw new Error('path must be provided')
43+ if(!opts.keys)
44+ opts.keys = ssbKeys.generate('ed25519', opts.seed && Buffer.from(opts.seed, 'base64'))
2345
24- keys = keys || ssbKeys.generate()
46+ if(!opts.path)
47+ throw new Error('opts.path *must* be provided, or use opts.temp=name to create a test instance')
2548
26- var db = require('./db')(join(opts.path || path, 'flume'), keys, opts)
49+ // main interface
50+ var ssb = create(opts.path, opts, opts.keys)
51+ //treat the main feed as remote, because it's likely handled like that by others.
52+ var feed = ssb.createFeed(opts.keys, {remote: true})
53+ var _close = api.close
54+ var close = function (arg, cb) {
55+ if('function' === typeof arg) cb = arg
56+ // override to close the SSB database
57+ ssb.close(function (err) {
58+ if (err) throw err
59+ console.log("fallback to close")
60+ _close(cb) //multiserver doesn't take a callback on close.
61+ })
62+ }
2763
28- // UGLY HACK, but...
29- // fairly sure that something up the stack expects ssb to be an event emitter.
30- db.__proto__ = new EventEmitter() // eslint-disable-line
64+ function since () {
65+ var plugs = {}
66+ var sync = true
67+ for(var k in ssb) {
68+ if(ssb[k] && isObject(ssb[k]) && isFunction(ssb[k].since)) {
69+ plugs[k] = ssb[k].since.value
70+ sync = sync && (plugs[k] === ssb.since.value)
71+ }
72+ }
73+ return {
74+ since: ssb.since.value,
75+ plugins: plugs,
76+ sync: sync,
77+ }
78+ }
79+ var self
80+ return self = {
81+ id : feed.id,
82+ keys : opts.keys,
3183
32- db.opts = opts
84+ ready : function () {
85+ return ssb.ready.value
86+ },
3387
34- var _get = db.get
88+ progress : function () {
89+ return ssb.progress
90+ },
3591
36- db.get = function (key, cb) {
37- let isPrivate = false
38- let unbox
39- if (typeof key === 'object') {
40- isPrivate = key.private === true
41- unbox = key.unbox
42- key = key.id
43- }
92+ status : function () {
93+ return {progress: self.progress(), db: ssb.status, sync: since() }
94+ },
4495
45- if (ref.isMsg(key)) {
46- return db.keys.get(key, function (err, data) {
47- if (err) return cb(err)
96+ version : function () {
97+ return pkg.version
98+ },
4899
49- if (isPrivate && unbox) {
50- data = db.unbox(data, unbox)
51- }
100+ //temporary!
101+ _flumeUse :
102+ function (name, flumeview) {
103+ ssb.use(name, flumeview)
104+ return ssb[name]
105+ },
52106
53- let result
107+ // usage : valid.sync(usage, 'string?|boolean?'),
108+ close : close,
54109
55- if (isPrivate) {
56- result = data.value
57- } else {
58- result = u.originalValue(data.value)
59- }
110+ publish : valid.async(feed.add, 'string|msgContent'),
111+ add : valid.async(ssb.add, 'msg'),
112+ queue : valid.async(ssb.queue, 'msg'),
113+ get : valid.async(ssb.get, 'msgLink|number|object'),
60114
61- cb(null, result)
62- })
63- } else if (ref.isMsgLink(key)) {
64- var link = ref.parseLink(key)
65- return db.get({
66- id: link.link,
67- private: true,
68- unbox: link.query.unbox.replace(/\s/g, '+')
69- }, cb)
70- } else if (Number.isInteger(key)) {
71- _get(key, cb) // seq
72- } else {
73- throw new Error('ssb-db.get: key *must* be a ssb message id or a flume offset')
115+ post : ssb.post,
116+ addMap : ssb.addMap,
117+
118+ since : since,
119+
120+ getPublicKey : ssb.getPublicKey,
121+ latest : ssb.latest,
122+ getLatest : valid.async(ssb.getLatest, 'feedId'),
123+ latestSequence : valid.async(ssb.latestSequence, 'feedId'),
124+ createFeed : ssb.createFeed,
125+ whoami : function () { return { id: feed.id } },
126+ query : ssb.query,
127+ createFeedStream : valid.source(ssb.createFeedStream, 'readStreamOpts?'),
128+ createHistoryStream : valid.source(ssb.createHistoryStream, ['createHistoryStreamOpts'], ['feedId', 'number?', 'boolean?']),
129+ createLogStream : valid.source(ssb.createLogStream, 'readStreamOpts?'),
130+ createUserStream : valid.source(ssb.createUserStream, 'createUserStreamOpts'),
131+ links : valid.source(ssb.links, 'linksOpts'),
132+ sublevel : ssb.sublevel,
133+ messagesByType : valid.source(ssb.messagesByType, 'string|messagesByTypeOpts'),
134+ createWriteStream : ssb.createWriteStream,
135+ getVectorClock : ssb.getVectorClock,
136+ getAtSequence : ssb.getAtSequence,
137+ addUnboxer : ssb.addUnboxer,
138+ box : ssb.box,
74139 }
75140 }
141+}
76142
77- db.add = function (msg, cb) {
78- db.queue(msg, function (err, data) {
79- if (err) cb(err)
80- else db.flush(function () { cb(null, data) })
81- })
82- }
83143
84- db.createFeed = function (keys) {
85- if (!keys) keys = ssbKeys.generate()
86- function add (content, cb) {
87- // LEGACY: hacks to support add as a continuable
88- if (!cb) { return function (cb) { add(content, cb) } }
89144
90- db.append({ content: content, keys: keys }, cb)
91- }
92- return {
93- add: add,
94- publish: add,
95- id: keys.id,
96- keys: keys
97- }
98- }
99145
100- db.createRawLogStream = function (opts) {
101- return db.stream(opts)
102- }
103146
104- // pull in the features that are needed to pass the tests
105- // and that sbot, etc uses but are slow.
106- require('./extras')(db, opts, keys)
107147
108- // writeStream - used in (legacy) replication.
109- db.createWriteStream = function (cb) {
110- cb = cb || errorCB
111- return pull(
112- pull.asyncMap(function (data, cb) {
113- db.queue(data, function (err, msg) {
114- if (err) {
115- db.emit('invalid', err, msg)
116- }
117- setImmediate(cb)
118- })
119- }),
120- pull.drain(null, function (err) {
121- if (err) return cb(err)
122- db.flush(cb)
123- })
124- )
125- }
126148
127- // should be private
128- db.createHistoryStream = db.clock.createHistoryStream
129149
130- // called with [id, seq] or "<id>:<seq>"
131- db.getAtSequence = function (seqid, cb) {
132- // will NOT expose private plaintext
133- db.clock.get(isString(seqid) ? seqid.split(':') : seqid, function (err, value) {
134- if (err) cb(err)
135- else cb(null, u.originalData(value))
136- })
137- }
138150
139- db.getVectorClock = function (_, cb) {
140- if (!cb) cb = _
141- db.last.get(function (err, h) {
142- if (err) return cb(err)
143- var clock = {}
144- for (var k in h) { clock[k] = h[k].sequence }
145- cb(null, clock)
146- })
147- }
148151
149- return db
150-}
151152
152153
154+
155+
156+
157+
158+
159+
160+
161+
162+
163+
164+
165+
166+
167+
168+
169+
170+
171+
172+
173+
174+
175+
176+
177+
178+
179+
180+
181+
test/add.jsView
@@ -76,5 +76,5 @@
7676 })
7777 })
7878 }
7979
80-if (!module.parent) { module.exports(require('../defaults')) }
80+if (!module.parent) { module.exports({}) }
test/end-to-end.jsView
@@ -170,5 +170,5 @@
170170 })
171171 })
172172 }
173173
174-if (!module.parent) { module.exports(require('../defaults')) }
174+if (!module.parent) { module.exports({}) }
test/feed.jsView
@@ -158,5 +158,5 @@
158158 })
159159 })
160160 }
161161
162-if (!module.parent) { module.exports(require('../defaults')) }
162+if (!module.parent) { module.exports({}) }
test/history.jsView
@@ -192,5 +192,5 @@
192192 )
193193 })
194194 }
195195
196-if (!module.parent) { module.exports(require('../defaults')) }
196+if (!module.parent) { module.exports({}) }
test/links.jsView
@@ -131,5 +131,5 @@
131131 })
132132 })
133133 }
134134
135-if (!module.parent) { module.exports(require('../defaults')) }
135+if (!module.parent) { module.exports({}) }
test/log.jsView
@@ -137,5 +137,5 @@
137137 })
138138 })
139139 }
140140
141-if (!module.parent) { module.exports(require('../defaults')) }
141+if (!module.parent) { module.exports({}) }
test/mesages-by-type.jsView
@@ -76,5 +76,5 @@
7676 })
7777 })
7878 }
7979
80-if (!module.parent) { module.exports(require('../defaults')) }
80+if (!module.parent) { module.exports({}) }
test/msg-encoding.jsView
@@ -80,5 +80,5 @@
8080 })
8181 })
8282 }
8383
84-if (!module.parent) { module.exports(require('../defaults')) }
84+if (!module.parent) { module.exports({}) }
test/validation.jsView
@@ -168,5 +168,5 @@
168168 )
169169 })
170170 }
171171
172-if (!module.parent) { module.exports(require('../defaults')) }
172+if (!module.parent) { module.exports(require('../')) }
test/write-stream.jsView
@@ -67,5 +67,5 @@
6767 )
6868 })
6969 }
7070
71-if (!module.parent) { module.exports(require('../defaults')) }
71+if (!module.parent) { module.exports({}) }
defaults.jsView
@@ -1,1 +1,0 @@
1-
plugin.jsView
@@ -1,186 +1,0 @@
1-//var SecretStack = require('secret-stack')
2-var create = require('./create')
3-var ssbKeys = require('ssb-keys')
4-var path = require('path')
5-var osenv = require('osenv')
6-var mkdirp = require('mkdirp')
7-var rimraf = require('rimraf')
8-var mdm = require('mdmanifest')
9-//var cmdAliases = require('./lib/cli-cmd-aliases')
10-var valid = require('./lib/validators')
11-//var apidocs = require('./lib/apidocs.js')
12-var pkg = require('./package.json')
13-
14-function isString(s) { return 'string' === typeof s }
15-function isObject(o) { return 'object' === typeof o }
16-function isFunction (f) { return 'function' === typeof f }
17-// create SecretStack definition
18-var fs = require('fs')
19-var manifest = mdm.manifest(fs.readFileSync(path.join(__dirname, 'api.md'), 'utf-8'))
20-
21-manifest.seq = 'async'
22-manifest.usage = 'sync'
23-manifest.clock = 'async'
24-manifest.version = 'sync'
25-
26-console.log('manifest', manifest)
27-
28-module.exports = {
29- manifest: manifest,
30- permissions: {
31- master: {allow: null, deny: null},
32- anonymous: {allow: ['createHistoryStream'], deny: null}
33- },
34- init: function (api, opts) {
35-
36- // .temp: use a /tmp data directory
37- // (useful for testing)
38- if(opts.temp) {
39- var name = isString(opts.temp) ? opts.temp : ''+Date.now()
40- opts.path = path.join(osenv.tmpdir(), name)
41- rimraf.sync(opts.path)
42- }
43-
44- // load/create secure scuttlebutt data directory
45- mkdirp.sync(opts.path)
46-
47- if(!opts.keys)
48- opts.keys = ssbKeys.generate('ed25519', opts.seed && Buffer.from(opts.seed, 'base64'))
49-
50- if(!opts.path)
51- throw new Error('opts.path *must* be provided, or use opts.temp=name to create a test instance')
52-
53- // main interface
54- var ssb = create(opts.path, opts, opts.keys)
55- //treat the main feed as remote, because it's likely handled like that by others.
56- var feed = ssb.createFeed(opts.keys, {remote: true})
57- var _close = api.close
58- var close = function (arg, cb) {
59- if('function' === typeof arg) cb = arg
60- // override to close the SSB database
61- ssb.close(function (err) {
62- if (err) throw err
63- console.log("fallback to close")
64- _close(cb) //multiserver doesn't take a callback on close.
65- })
66- }
67-
68- function since () {
69- var plugs = {}
70- var sync = true
71- for(var k in ssb) {
72- if(ssb[k] && isObject(ssb[k]) && isFunction(ssb[k].since)) {
73- plugs[k] = ssb[k].since.value
74- sync = sync && (plugs[k] === ssb.since.value)
75- }
76- }
77- return {
78- since: ssb.since.value,
79- plugins: plugs,
80- sync: sync,
81- }
82- }
83- var self
84- return self = {
85- id : feed.id,
86- keys : opts.keys,
87-
88- ready : function () {
89- return ssb.ready.value
90- },
91-
92- progress : function () {
93- return ssb.progress
94- },
95-
96- status : function () {
97- return {progress: self.progress(), db: ssb.status, sync: since() }
98- },
99-
100- version : function () {
101- return pkg.version
102- },
103-
104- //temporary!
105- _flumeUse :
106- function (name, flumeview) {
107- ssb.use(name, flumeview)
108- return ssb[name]
109- },
110-
111- // usage : valid.sync(usage, 'string?|boolean?'),
112- close : close,
113-
114- publish : valid.async(feed.add, 'string|msgContent'),
115- add : valid.async(ssb.add, 'msg'),
116- queue : valid.async(ssb.queue, 'msg'),
117- get : valid.async(ssb.get, 'msgLink|number|object'),
118-
119- post : ssb.post,
120- addMap : ssb.addMap,
121-
122- since : since,
123-
124- getPublicKey : ssb.getPublicKey,
125- latest : ssb.latest,
126- getLatest : valid.async(ssb.getLatest, 'feedId'),
127- latestSequence : valid.async(ssb.latestSequence, 'feedId'),
128- createFeed : ssb.createFeed,
129- whoami : function () { return { id: feed.id } },
130- query : ssb.query,
131- createFeedStream : valid.source(ssb.createFeedStream, 'readStreamOpts?'),
132- createHistoryStream : valid.source(ssb.createHistoryStream, ['createHistoryStreamOpts'], ['feedId', 'number?', 'boolean?']),
133- createLogStream : valid.source(ssb.createLogStream, 'readStreamOpts?'),
134- createUserStream : valid.source(ssb.createUserStream, 'createUserStreamOpts'),
135- links : valid.source(ssb.links, 'linksOpts'),
136- sublevel : ssb.sublevel,
137- messagesByType : valid.source(ssb.messagesByType, 'string|messagesByTypeOpts'),
138- createWriteStream : ssb.createWriteStream,
139- getVectorClock : ssb.getVectorClock,
140- getAtSequence : ssb.getAtSequence,
141- addUnboxer : ssb.addUnboxer,
142- box : ssb.box,
143- }
144- }
145-}
146-
147-/*
148-// live help RPC method
149-function usage (cmd) {
150- var path = (cmd||'').split('.')
151- if ((path[0] && apidocs[path[0]]) || (cmd && apidocs[cmd])) {
152- // return usage for the plugin
153- cmd = path.slice(1).join('.')
154- return mdm.usage(apidocs[path[0]], cmd, { prefix: path[0] })
155- }
156- if (!cmd) {
157- // return usage for all docs
158- return Object.keys(apidocs).map(function (name) {
159- if (name == '_')
160- return mdm.usage(apidocs[name], null, { nameWidth: 20 })
161-
162- var text = mdm.usage(apidocs[name], null, { prefix: name, nameWidth: 20 })
163- return text.slice(text.indexOf('Commands:') + 10) // skip past the toplevel summary, straight to the cmd list
164- }).join('\n\n')
165- }
166- // toplevel cmd usage
167- cmd = cmdAliases[cmd] || cmd
168- return mdm.usage(apidocs._, cmd)
169-}
170-*/
171-
172-//function createSsbServer() {
173-// return SecretStack({
174-// //this is just the default app key.
175-// //it can be overridden by passing a appKey as option
176-// //when creating a SsbServer instance.
177-// appKey: require('./lib/ssb-cap')
178-// })
179-// .use(SSB)
180-//}
181-//module.exports = createSsbServer()
182-//module.exports.createSsbServer = createSsbServer
183-
184-
185-
186-

Built with git-ssb-web