Skip to content
Browse files

update protocol in core

  • Loading branch information...
1 parent 0d63408 commit 492e17e927c899aafb148f560cd29d7fea3f7365 @dominictarr dominictarr committed
Showing with 14 additions and 14 deletions.
  1. +11 −11 index.js
  2. +1 −1 security.js
  3. +2 −2 util.js
View
22 index.js
@@ -23,11 +23,11 @@ function dutyOfSubclass() {
}
function validate (data) {
- var key = data[0], ts = data[2], source = data[3]
+ var ts = data[1], source = data[2]
if( !Array.isArray(data)
- || data.length < 4
- || 'string' !== typeof key
+// || data.length < 4
+// || 'string' !== typeof key
|| 'string' !== typeof source
|| 'number' !== typeof ts
)
@@ -64,16 +64,16 @@ var emit = EventEmitter.prototype.emit
sb.applyUpdate = dutyOfSubclass
sb.history = dutyOfSubclass
-sb.localUpdate = function (key, value) {
- this._update([key, value, timestamp(), this.id])
+sb.localUpdate = function (trx) {
+ this._update([trx, timestamp(), this.id])
return this
}
//checks whether this update is valid.
sb._update = function (update) {
- var ts = update[2]
- var source = update[3]
+ var ts = update[1]
+ var source = update[2]
//if this message is old for it's source,
//ignore it. it's out of order.
//each node must emit it's changes in order!
@@ -106,7 +106,7 @@ sb._update = function (update) {
// unnecessary messages are sent.
if(self.applyUpdate(update))
- emit.call(self, '_update', update)
+ emit.call(self, '_update', update) //write to stream.
}
@@ -118,7 +118,7 @@ sb._update = function (update) {
} else {
if(this._sign) {
//could make this async easily enough.
- update[4] = this._sign(update)
+ update[3] = this._sign(update)
}
didVerification(null, true)
}
@@ -192,8 +192,8 @@ sb.createStream = function (opts) {
d.emitData(update)
//really, this should happen before emitting.
- var ts = update[2]
- var source = update[3]
+ var ts = update[1]
+ var source = update[2]
sources[source] = ts
}
View
2 security.js
@@ -41,7 +41,7 @@ module.exports = function (keys,
verify: function (update, cb) {
var _update = update.slice()
var sig = _update.pop()
- var id = update[3]
+ var id = update[2]
var data = JSON.stringify(_update)
var key = keys[id]
if(!key) return cb(null, false)
View
4 util.js
@@ -6,7 +6,7 @@ function () {
}
exports.filter = function (update, sources) {
- var ts = update[2]
- var source = update[3]
+ var ts = update[1]
+ var source = update[2]
return (!sources || !sources[source] || sources[source] < ts)
}

0 comments on commit 492e17e

Please sign in to comment.
Something went wrong with that request. Please try again.