git ssb

1+

Dominic / ssb-examples



Commit e3c2f9ccb59199e10f8713228e8dfdd4f5390777

initial

Dominic Tarr committed on 2/3/2017, 6:31:00 AM

Files changed

LICENSEadded
README.mdadded
package.jsonadded
scan.jsadded
LICENSEView
@@ -1,0 +1,22 @@
1 +Copyright (c) 2017 'Dominic Tarr'
2 +
3 +Permission is hereby granted, free of charge,
4 +to any person obtaining a copy of this software and
5 +associated documentation files (the "Software"), to
6 +deal in the Software without restriction, including
7 +without limitation the rights to use, copy, modify,
8 +merge, publish, distribute, sublicense, and/or sell
9 +copies of the Software, and to permit persons to whom
10 +the Software is furnished to do so,
11 +subject to the following conditions:
12 +
13 +The above copyright notice and this permission notice
14 +shall be included in all copies or substantial portions of the Software.
15 +
16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
20 +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
README.mdView
@@ -1,0 +1,10 @@
1 +# ssb-examples
2 +
3 +various scripts that do things with ssb.
4 +
5 +I normally write things here when I am experimenting with ssb, but may be useful for other people trying things!
6 +
7 +
8 +## License
9 +
10 +MIT
package.jsonView
@@ -1,0 +1,22 @@
1 +{
2 + "name": "ssb-examples",
3 + "description": "",
4 + "version": "0.0.0",
5 + "homepage": "https://github.com/dominictarr/ssb-examples",
6 + "repository": {
7 + "type": "git",
8 + "url": "git://github.com/dominictarr/ssb-examples.git"
9 + },
10 + "dependencies": {
11 + "pull-paramap": "^1.2.1",
12 + "pull-stream": "^3.5.0",
13 + "ssb-client": "^4.4.0",
14 + "ssb-msgs": "^5.2.0"
15 + },
16 + "devDependencies": {},
17 + "scripts": {
18 + "test": "set -e; for t in test/*.js; do node $t; done"
19 + },
20 + "author": "'Dominic Tarr' <dominic.tarr@gmail.com> (http://dominictarr.com)",
21 + "license": "MIT"
22 +}
scan.jsView
@@ -1,0 +1,47 @@
1 +//connect to every peer known to the local pub, and group by error types
2 +
3 +var pull = require('pull-stream')
4 +var paramap = require('pull-paramap')
5 +
6 +function clean (message) {
7 + var m = /.*E[A-Z]+/.exec(message)
8 + return m ? m[0] : message
9 +}
10 +
11 +require('ssb-client')(function (err, sbot) {
12 + var obj = {}, total = 0, errors = 0
13 + sbot.gossip.peers(function (e, ary) {
14 + var result = {success: []}
15 + pull(
16 + pull.values(ary),
17 + paramap(function (e, cb) {
18 + var addr = [e.host, e.port, e.key].join(':')
19 + console.error('connecting', e.host, e.key)
20 + sbot.gossip.connect(e, function (err, data) {
21 + console.error('connected', e.host, e.key, err && err.message)
22 + console.error(data)
23 + console.error(++total, err ? ++errors : errors)
24 + if(err) {
25 + var _err = clean(err.message)
26 + result[_err] = result[_err] || []
27 + result[_err].push(addr)
28 + console.error('ERROR', JSON.stringify(_err), addr)
29 +// console.error(result)
30 + }
31 + else
32 + result.success.push(addr)
33 + obj[addr] = err ? err.message : true
34 + cb()
35 + })
36 + }),
37 + pull.drain(null, function () {
38 + console.log(JSON.stringify(result, null, 2))
39 + sbot.close()
40 + })
41 + )
42 +
43 + })
44 +})
45 +
46 +
47 +

Built with git-ssb-web