Commit 484aa4e616c9dcc5dc7d8e706228aaa005a374dd
implement a status() method
Dominic Tarr committed on 6/22/2017, 6:59:28 AMParent: fd6d70a30dab618ef7610aa8d4df18b38eed8c25
Files changed
api.md | changed |
index.js | changed |
plugins/gossip/index.js | changed |
plugins/replicate/legacy.js | changed |
api.md | ||
---|---|---|
@@ -359,5 +359,11 @@ | ||
359 | 359 … | to represent progress. Currently implemented are `migration` (legacy->flume) |
360 | 360 … | migration progress and `indexes` (index regeneration). |
361 | 361 … | |
362 | 362 … | |
363 … | +## status: sync | |
364 … | + | |
365 … | +returns an object reflecting the status of various ssb operations, | |
366 … | +such as db read activity, connection statuses, etc, etc. The purpose is to provide | |
367 … | +an overview of how ssb is working. | |
368 … | + | |
363 | 369 … | ## getVectorClock: async |
index.js | ||
---|---|---|
@@ -91,8 +91,12 @@ | ||
91 | 91 … | progress : function () { |
92 | 92 … | return ssb.progress |
93 | 93 … | }, |
94 | 94 … | |
95 … | + status : function () { | |
96 … | + return {db: ssb.status, sync: since() } | |
97 … | + }, | |
98 … | + | |
95 | 99 … | //temporary! |
96 | 100 … | _flumeUse : |
97 | 101 … | function (name, flumeview) { |
98 | 102 … | ssb.use(name, flumeview) |
plugins/gossip/index.js | ||
---|---|---|
@@ -48,8 +48,10 @@ | ||
48 | 48 … | var home = ref.parseAddress(server.getAddress()) |
49 | 49 … | |
50 | 50 … | var stateFile = AtomicFile(path.join(config.path, 'gossip.json')) |
51 | 51 … | |
52 … | + var status = {} | |
53 … | + | |
52 | 54 … | //Known Peers |
53 | 55 … | var peers = [] |
54 | 56 … | |
55 | 57 … | function getPeer(id) { |
@@ -57,8 +59,14 @@ | ||
57 | 59 … | return e && e.key === id |
58 | 60 … | }) |
59 | 61 … | } |
60 | 62 … | |
63 … | + server.status.hook(function (fn) { | |
64 … | + var _status = fn() | |
65 … | + _status.gossip = status | |
66 … | + return _status | |
67 … | + }) | |
68 … | + | |
61 | 69 … | server.close.hook(function (fn, args) { |
62 | 70 … | closed = true |
63 | 71 … | closeScheduler() |
64 | 72 … | for(var id in server.peers) |
@@ -191,8 +199,9 @@ | ||
191 | 199 … | //get current state |
192 | 200 … | |
193 | 201 … | server.on('rpc:connect', function (rpc, isClient) { |
194 | 202 … | var peer = getPeer(rpc.id) |
203 … | + status[rpc.id] = peer | |
195 | 204 … | //don't track clients that connect, but arn't considered peers. |
196 | 205 … | //maybe we should though? |
197 | 206 … | if(!peer) { |
198 | 207 … | if(rpc.id !== server.id) { |
@@ -227,8 +236,9 @@ | ||
227 | 236 … | ) |
228 | 237 … | } |
229 | 238 … | |
230 | 239 … | rpc.on('closed', function () { |
240 … | + delete status[rpc.id] | |
231 | 241 … | console.log('Disconnected', stringify(peer)) |
232 | 242 … | //track whether we have successfully connected. |
233 | 243 … | //or how many failures there have been. |
234 | 244 … | var since = peer.stateChange |
Built with git-ssb-web