Skip to content

Instantly share code, notes, and snippets.

@ralphtheninja
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralphtheninja/a41fcaad4e0827b8e70d to your computer and use it in GitHub Desktop.
Save ralphtheninja/a41fcaad4e0827b8e70d to your computer and use it in GitHub Desktop.
calling rpc.add on data
{
"type": "sys-stat",
"text": {
"os": {
"type": "Linux",
"arch": "x64",
"platform": "linux",
"loadavg": [0.41845703125,0.587890625,0.6923828125]
},
"process": {
"memory": 40370176,
"memoryInfo": {
"rss": 40370176,
"vsize": 4081443667968
},
"cpu": 0,
"cpuInfo": {
"pcpu": 0,
"pcpuUser": 0,
"pcpuSystem": 0,
"cpuTime": 0
}
}
}
}
├── after@0.8.1
├─┬ chalk@0.5.1
│ ├── ansi-styles@1.1.0
│ ├── escape-string-regexp@1.0.2
│ ├─┬ has-ansi@0.1.0
│ │ └── ansi-regex@0.2.1
│ ├─┬ strip-ansi@0.3.0
│ │ └── ansi-regex@0.2.1
│ └── supports-color@0.2.0
├── osenv@0.1.0
├─┬ rc@0.6.0
│ ├── deep-extend@0.2.11
│ ├── ini@1.3.2
│ ├── minimist@0.0.10
│ └── strip-json-comments@0.1.3
├─┬ readable-stream@1.0.33
│ ├── core-util-is@1.0.1
│ ├── inherits@2.0.1
│ ├── isarray@0.0.1
│ └── string_decoder@0.10.31
├─┬ scuttlebot@2.3.2
│ ├── bash-color@0.0.3
│ ├── broadcast-stream@0.0.0
│ ├─┬ connect@3.3.4
│ │ ├─┬ debug@2.1.1
│ │ │ └── ms@0.6.2
│ │ ├─┬ finalhandler@0.3.3
│ │ │ ├── escape-html@1.0.1
│ │ │ └─┬ on-finished@2.2.0
│ │ │ └── ee-first@1.1.0
│ │ ├── parseurl@1.3.0
│ │ └── utils-merge@1.0.0
│ ├─┬ cont@1.0.1
│ │ ├── continuable@1.1.8
│ │ ├─┬ continuable-para@1.2.0
│ │ │ ├── continuable-hash@0.1.4
│ │ │ └── continuable-list@0.1.6
│ │ └── continuable-series@1.2.0
│ ├── daemonize2@0.4.2
│ ├── explain-error@1.0.1
│ ├── graphmitter@1.3.0
│ ├── ip@0.3.2
│ ├─┬ level-memview@0.0.0
│ │ ├─┬ level-live-stream@1.4.9
│ │ │ ├─┬ pull-level@1.1.12
│ │ │ │ ├─┬ level-post@1.0.4
│ │ │ │ │ ├── buffer-equal@0.0.1
│ │ │ │ │ ├── defined@0.0.0
│ │ │ │ │ └── string-range@1.2.2
│ │ │ │ ├─┬ pull-window@2.1.2
│ │ │ │ │ ├── looper@2.0.0
│ │ │ │ │ └── pull-core@1.0.0
│ │ │ │ └─┬ stream-to-pull-stream@1.3.1
│ │ │ │ └── pull-core@1.0.0
│ │ │ └─┬ pull-stream-to-stream@1.2.6
│ │ │ └── pull-core@1.1.0
│ │ ├─┬ pull-level@1.2.0
│ │ │ ├─┬ level-post@1.0.4
│ │ │ │ ├── buffer-equal@0.0.1
│ │ │ │ ├── defined@0.0.0
│ │ │ │ └── string-range@1.2.2
│ │ │ ├─┬ pull-window@2.1.2
│ │ │ │ ├── looper@2.0.0
│ │ │ │ └── pull-core@1.0.0
│ │ │ └─┬ stream-to-pull-stream@1.3.1
│ │ │ └── pull-core@1.0.0
│ │ └─┬ pull-stream@2.26.0
│ │ └── pull-core@1.0.0
│ ├── map-merge@1.1.0
│ ├── minimist@1.1.0
│ ├─┬ mkdirp@0.5.0
│ │ └── minimist@0.0.8
│ ├─┬ multiblob@1.4.1
│ │ ├── blake2s@1.0.1
│ │ ├── pull-defer@0.1.1
│ │ ├─┬ pull-glob@1.0.1
│ │ │ ├─┬ pull-fs@1.1.4
│ │ │ │ └─┬ pull-split@0.1.2
│ │ │ │ └─┬ pull-through@1.0.14
│ │ │ │ └── looper@3.0.0
│ │ │ └─┬ pull-stream@2.20.1
│ │ │ └── pull-core@1.0.0
│ │ └─┬ pull-stream@2.26.0
│ │ └── pull-core@1.0.0
│ ├── multicb@1.1.0
│ ├─┬ muxrpc@3.3.1
│ │ ├── packet-stream@0.4.4
│ │ ├── pull-goodbye@0.0.1
│ │ └─┬ pull-stream@2.26.0
│ │ └── pull-core@1.0.0
│ ├─┬ nomnom@1.8.0
│ │ ├─┬ chalk@0.4.0
│ │ │ ├── ansi-styles@1.0.0
│ │ │ ├── has-color@0.1.7
│ │ │ └── strip-ansi@0.1.1
│ │ └── underscore@1.6.0
│ ├── non-private-ip@1.1.0
│ ├─┬ pull-cat@1.1.5
│ │ └── pull-core@1.0.0
│ ├─┬ pull-inactivity@2.1.1
│ │ ├── pull-abortable@4.0.0
│ │ └─┬ pull-stream@2.26.0
│ │ └── pull-core@1.0.0
│ ├── pull-many@1.0.5
│ ├─┬ pull-pushable@1.1.4
│ │ └─┬ pull-stream@2.18.3
│ │ └── pull-core@1.0.0
│ ├─┬ pull-serializer@0.3.1
│ │ └─┬ pull-split@0.1.2
│ │ └─┬ pull-through@1.0.14
│ │ ├── looper@3.0.0
│ │ └─┬ pull-stream@2.20.1
│ │ └── pull-core@1.0.0
│ ├─┬ pull-stream@2.24.1
│ │ └── pull-core@1.0.0
│ ├─┬ pull-stream-to-stream@1.3.0
│ │ └── pull-core@1.1.0
│ ├── pull-stringify@1.2.2
│ ├─┬ pull-ws-server@1.1.2
│ │ ├─┬ pull-ws@2.1.0
│ │ │ └── pull-core@1.1.0
│ │ └─┬ ws@0.5.0 (git://github.com/dominictarr/ws.git#590d0ea0d62b0c533cd6f26ff0e3f31f946a80db)
│ │ ├── nan@1.4.3
│ │ ├── options@0.0.6
│ │ └── ultron@1.0.1
│ ├─┬ rc@0.5.5
│ │ ├── deep-extend@0.2.11
│ │ ├── ini@1.3.3
│ │ ├── minimist@0.0.10
│ │ └── strip-json-comments@0.1.3
│ ├─┬ secure-scuttlebutt@8.0.0
│ │ ├── blake2s@1.0.1
│ │ ├── deep-equal@0.2.2
│ │ ├── eccjs@0.3.0 (git://github.com/dominictarr/eccjs.git#586f6d47507184a2efe84684ed0a30605cbc43a5)
│ │ ├── hexpp@1.1.3
│ │ ├─┬ level@0.18.0
│ │ │ ├─┬ level-packager@0.18.0
│ │ │ │ └─┬ levelup@0.18.6
│ │ │ │ ├── bl@0.8.2
│ │ │ │ ├─┬ deferred-leveldown@0.2.0
│ │ │ │ │ └── abstract-leveldown@0.12.4
│ │ │ │ ├── errno@0.1.1
│ │ │ │ ├── prr@0.0.0
│ │ │ │ ├── semver@2.3.2
│ │ │ │ └── xtend@3.0.0
│ │ │ └─┬ leveldown@0.10.4
│ │ │ ├── bindings@1.2.1
│ │ │ └── nan@1.6.2
│ │ ├─┬ level-sublevel@6.4.4
│ │ │ ├─┬ bytewise@0.7.1
│ │ │ │ └─┬ bops@0.1.1
│ │ │ │ ├── base64-js@0.0.2
│ │ │ │ └── to-utf8@0.0.1
│ │ │ ├─┬ levelup@0.19.0
│ │ │ │ ├── bl@0.8.2
│ │ │ │ ├─┬ deferred-leveldown@0.2.0
│ │ │ │ │ └── abstract-leveldown@0.12.4
│ │ │ │ ├── errno@0.1.1
│ │ │ │ ├── prr@0.0.0
│ │ │ │ ├── semver@2.3.2
│ │ │ │ └── xtend@3.0.0
│ │ │ ├─┬ pull-stream@2.21.0
│ │ │ │ └── pull-core@1.0.0
│ │ │ ├── typewiselite@1.0.0
│ │ │ └── xtend@4.0.0
│ │ ├── ltgt@2.0.0
│ │ ├── monotonic-timestamp@0.0.9
│ │ ├─┬ pull-level@1.2.0
│ │ │ ├─┬ level-post@1.0.4
│ │ │ │ ├── buffer-equal@0.0.1
│ │ │ │ ├── defined@0.0.0
│ │ │ │ └── string-range@1.2.2
│ │ │ ├─┬ pull-window@2.1.2
│ │ │ │ ├── looper@2.0.0
│ │ │ │ └── pull-core@1.0.0
│ │ │ └─┬ stream-to-pull-stream@1.3.1
│ │ │ └── pull-core@1.0.0
│ │ ├─┬ pull-paramap@1.1.1
│ │ │ └─┬ pull-stream@2.20.1
│ │ │ └── pull-core@1.0.0
│ │ ├─┬ pull-switch@2.0.0
│ │ │ └─┬ pull-stream@2.18.3
│ │ │ └── pull-core@1.0.0
│ │ └── ssb-msgs@1.0.0
│ ├─┬ ssb-config@1.0.0
│ │ └─┬ rc@0.6.0
│ │ ├── deep-extend@0.2.11
│ │ ├── ini@1.3.3
│ │ ├── minimist@0.0.10
│ │ └── strip-json-comments@0.1.3
│ ├── ssb-msg-schemas@1.0.0
│ ├── ssb-msgs@2.0.0
│ ├─┬ ssbplug-phoenix@2.3.7
│ │ ├─┬ base-emoji@0.3.0
│ │ │ └── bitparser@0.1.1
│ │ ├── blake2s@1.0.1
│ │ ├── dom-walk@0.1.1
│ │ ├── eccjs@0.3.0 (git://github.com/dominictarr/eccjs.git#586f6d47507184a2efe84684ed0a30605cbc43a5)
│ │ ├── emoji-named-characters@1.0.2
│ │ ├── form-data-set@1.1.1
│ │ ├─┬ global@4.2.1
│ │ │ ├── min-document@2.14.0
│ │ │ └── process@0.5.2
│ │ ├─┬ hash-router@0.4.0
│ │ │ ├── routes@0.2.0
│ │ │ └─┬ xtend@2.0.6
│ │ │ ├── is-object@0.1.2
│ │ │ └─┬ object-keys@0.2.0
│ │ │ ├── foreach@2.0.5
│ │ │ ├── indexof@0.0.1
│ │ │ └── is@0.2.7
│ │ ├─┬ hyperscript@1.4.4
│ │ │ ├── browser-split@0.0.0
│ │ │ ├─┬ class-list@0.1.1
│ │ │ │ └── indexof@0.0.1
│ │ │ └── html-element@1.3.0
│ │ ├── marked@0.3.2 (git://github.com/clehner/marked#8af8ae018ba452b5c7f936a474dbce265f2ae732)
│ │ ├── nicedate@0.0.0
│ │ ├─┬ once@1.3.1
│ │ │ └── wrappy@1.0.1
│ │ ├─┬ phoenix-api@4.0.4
│ │ │ └─┬ pull-level@1.2.0
│ │ │ ├─┬ level-post@1.0.4
│ │ │ │ ├── buffer-equal@0.0.1
│ │ │ │ ├── defined@0.0.0
│ │ │ │ └── string-range@1.2.2
│ │ │ ├─┬ pull-window@2.1.2
│ │ │ │ ├── looper@2.0.0
│ │ │ │ └── pull-core@1.0.0
│ │ │ └─┬ stream-to-pull-stream@1.3.1
│ │ │ └── pull-core@1.0.0
│ │ ├── phoenix-router@1.0.0
│ │ ├── pretty-date@0.2.0
│ │ ├── pull-merge@1.0.2
│ │ ├─┬ raw-body@1.3.3
│ │ │ ├── bytes@1.0.0
│ │ │ └── iconv-lite@0.4.7
│ │ ├─┬ request@2.47.0
│ │ │ ├── aws-sign2@0.5.0
│ │ │ ├── bl@0.9.4
│ │ │ ├── caseless@0.6.0
│ │ │ ├─┬ combined-stream@0.0.7
│ │ │ │ └── delayed-stream@0.0.5
│ │ │ ├── forever-agent@0.5.2
│ │ │ ├─┬ form-data@0.1.4
│ │ │ │ ├── async@0.9.0
│ │ │ │ └── mime@1.2.11
│ │ │ ├─┬ hawk@1.1.1
│ │ │ │ ├── boom@0.4.2
│ │ │ │ ├── cryptiles@0.2.2
│ │ │ │ ├── hoek@0.9.1
│ │ │ │ └── sntp@0.2.4
│ │ │ ├─┬ http-signature@0.10.1
│ │ │ │ ├── asn1@0.1.11
│ │ │ │ ├── assert-plus@0.1.5
│ │ │ │ └── ctype@0.5.3
│ │ │ ├── json-stringify-safe@5.0.0
│ │ │ ├── mime-types@1.0.2
│ │ │ ├── node-uuid@1.4.2
│ │ │ ├── oauth-sign@0.4.0
│ │ │ ├── qs@2.3.3
│ │ │ ├── stringstream@0.0.4
│ │ │ ├─┬ tough-cookie@0.12.1
│ │ │ │ └── punycode@1.3.2
│ │ │ └── tunnel-agent@0.4.0
│ │ ├─┬ ssb-channel@1.0.2
│ │ │ └── ssb-address@1.0.0
│ │ ├─┬ ssb-domain-auth@1.0.0
│ │ │ └── ssb-address@1.0.0
│ │ ├─┬ ssb-keys@0.3.1
│ │ │ ├── eccjs@0.3.0 (git://github.com/dominictarr/eccjs.git#586f6d47507184a2efe84684ed0a30605cbc43a5)
│ │ │ └── hmac@1.0.1
│ │ ├── ssb-manifest@1.0.0
│ │ ├── stack@0.1.0
│ │ ├── stack-assets-builder@1.0.3
│ │ ├── stack-assets-static@1.0.0
│ │ ├─┬ stringify@3.0.0
│ │ │ └─┬ html-minifier@0.6.9
│ │ │ ├─┬ change-case@2.1.6
│ │ │ │ ├── camel-case@1.1.1
│ │ │ │ ├── constant-case@1.1.0
│ │ │ │ ├── dot-case@1.1.1
│ │ │ │ ├── is-lower-case@1.1.1
│ │ │ │ ├── is-upper-case@1.1.1
│ │ │ │ ├── lower-case@1.1.2
│ │ │ │ ├── param-case@1.1.1
│ │ │ │ ├── pascal-case@1.1.0
│ │ │ │ ├── path-case@1.1.1
│ │ │ │ ├── sentence-case@1.1.2
│ │ │ │ ├── snake-case@1.1.1
│ │ │ │ ├── swap-case@1.1.0
│ │ │ │ ├── title-case@1.1.0
│ │ │ │ ├── upper-case@1.1.2
│ │ │ │ └── upper-case-first@1.1.0
│ │ │ ├─┬ clean-css@2.2.23
│ │ │ │ └── commander@2.2.0
│ │ │ ├─┬ cli@0.6.5
│ │ │ │ ├── exit@0.1.2
│ │ │ │ └─┬ glob@3.2.11
│ │ │ │ ├── inherits@2.0.1
│ │ │ │ └─┬ minimatch@0.3.0
│ │ │ │ ├── lru-cache@2.5.0
│ │ │ │ └── sigmund@1.0.0
│ │ │ ├── relateurl@0.2.6
│ │ │ └─┬ uglify-js@2.4.16
│ │ │ ├── async@0.2.10
│ │ │ ├─┬ optimist@0.3.7
│ │ │ │ └── wordwrap@0.0.2
│ │ │ ├─┬ source-map@0.1.34
│ │ │ │ └── amdefine@0.1.0
│ │ │ └── uglify-to-browserify@1.0.2
│ │ ├── suggest-box@1.1.2
│ │ ├── through@2.3.6
│ │ ├─┬ value-event@3.2.0
│ │ │ ├─┬ dom-delegator@10.0.0
│ │ │ │ ├── cuid@1.2.4
│ │ │ │ ├─┬ data-set@3.1.0
│ │ │ │ │ └── weakmap-shim@1.0.0
│ │ │ │ ├── individual@2.0.0
│ │ │ │ ├── inherits@2.0.1
│ │ │ │ └── weakmap-shim@1.1.0
│ │ │ └── xtend@2.2.0
│ │ ├─┬ websocket-stream@1.1.1
│ │ │ ├─┬ duplexify@3.2.0
│ │ │ │ └── end-of-stream@1.0.0
│ │ │ ├─┬ ws@0.4.32
│ │ │ │ ├── commander@2.1.0
│ │ │ │ ├── nan@1.0.0
│ │ │ │ ├── options@0.0.6
│ │ │ │ └── tinycolor@0.0.1
│ │ │ └── xtend@4.0.0
│ │ └── xtend@3.0.0
│ └─┬ stream-to-pull-stream@1.6.1
│ └── pull-core@1.0.0
├─┬ split@0.3.3
│ └── through@2.3.6
├─┬ ssb-config@1.0.0
│ └─┬ non-private-ip@1.1.0
│ └── ip@0.3.2
├─┬ ssb-keys@0.4.1
│ ├── blake2s@1.0.1
│ ├── deep-equal@0.2.2
│ ├── eccjs@0.3.0 (git://github.com/dominictarr/eccjs.git#586f6d47507184a2efe84684ed0a30605cbc43a5)
│ ├── hmac@1.0.1
│ └─┬ mkdirp@0.5.0
│ └── minimist@0.0.8
├─┬ tape@3.5.0
│ ├── deep-equal@0.2.2
│ ├── defined@0.0.0
│ ├─┬ glob@3.2.11
│ │ └─┬ minimatch@0.3.0
│ │ ├── lru-cache@2.5.0
│ │ └── sigmund@1.0.0
│ ├── inherits@2.0.1
│ ├── object-inspect@0.4.0
│ ├── resumer@0.0.0
│ └── through@2.3.6
├─┬ through2@0.6.3
│ └── xtend@4.0.0
└─┬ usage@0.5.0
├── bindings@1.2.1
└── nan@1.3.0
// This snippet works if you run it like 'node rpc-add.js' but crashes
// if you require it and call rpcAdd(data, cb)
var fs = require('fs')
var join = require('path').join
var ssbKeys = require('ssb-keys')
var config = require('ssb-config')
var manifestFile = join(config.path, 'manifest.json')
var manifest = JSON.parse(fs.readFileSync(manifestFile))
var rpc = require('scuttlebot/client')(config, manifest, function (err) {
if (err) throw err
})
var keys = ssbKeys.loadOrCreateSync(join(config.path, 'secret'))
function rpcAdd(data, cb) {
rpc.auth(ssbKeys.signObj(keys, {
role: 'client',
ts: Date.now(),
public: keys.public
}), function (err) {
if (err) return cb(err)
rpc.add(data, cb)
})
}
module.exports = rpcAdd
if (!module.parent) {
var data = require('./data.json')
rpcAdd(data, function (err) {
console.log('back from rpcAdd')
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment