git ssb

0+

Dominic / ssb-validate



Commit 51bc8f6b41ef93f18917bc07054c74c30412ad28

keep counts of total messages validated or queued

Dominic Tarr committed on 7/27/2017, 8:37:30 AM
Parent: 3ab042915e383de66498e28236438f61fa16b5fe

Files changed

index.jschanged
index.jsView
@@ -2,8 +2,10 @@
22 var ssbKeys = require('ssb-keys')
33
44 exports.initial = function () {
55 return {
6 + validated: 0,
7 + queued: 0,
68 queue: [],
79 feeds: {},
810 error: null
911 }
@@ -61,8 +63,9 @@
6163 return state
6264 state.feeds[msg.author] = state.feeds[msg.author] || {
6365 id: null, sequence: null, timestamp: null, queue: []
6466 }
67 + state.queued += 1
6568 state.feeds[msg.author].queue.push(msg)
6669 return state
6770 }
6871
@@ -89,23 +92,27 @@
8992 a.id = exports.id(msg)
9093 a.sequence = msg.sequence
9194 a.timestamp = msg.timestamp
9295 var q = state.feeds[msg.author].queue
96 + state.validated += q.length
97 + state.queued -= q.length
9398 while(q.length)
9499 state.queue.push(q.shift())
95100 }
96- else
101 + else {
97102 state.feeds[msg.author] = {id: exports.id(msg), sequence: msg.sequence, timestamp: msg.timestamp, queue: []}
98-
103 + }
99104 state.queue.push(msg)
105 + state.validated += 1
100106 return state
101107 }
102108
103109 exports.validate = function (state, feed) {
104110 if(!state.feeds[feed] || !state.feeds[feed].queue.length) {
105111 return state
106112 }
107113 var msg = state.feeds[feed].queue.pop()
114 + state.queued -= 1
108115 return exports.append(state, msg)
109116 }
110117
111118 //pass in your own timestamp, so it's completely deterministic

Built with git-ssb-web