epidemic-broadcast-trees
Advanced tools
Comparing version 5.0.2 to 5.0.3
@@ -114,2 +114,8 @@ | ||
function isAhead(seq1, seq2) { | ||
if(seq2 === -1) return false | ||
if(seq2 == null) return true | ||
if(seq1 > seq2) return true | ||
} | ||
exports.append = function (state, msg) { | ||
@@ -124,2 +130,3 @@ //check if any peer requires this msg | ||
var rep = peer.replicating[msg.author] | ||
if(rep && rep.tx && rep.sent == msg.sequence - 1 && msg.sequence > peer.clock[msg.author]) { | ||
@@ -130,5 +137,12 @@ peer.msgs.push(msg) | ||
//if we are ahead of this peer, and not in tx mode, let them know that. | ||
else if(rep && !rep.tx && msg.sequence > peer.clock[msg.author]) { | ||
else if( | ||
isAhead(msg.sequence, peer.clock[msg.author]) && | ||
( rep | ||
? !rep.tx && rep.sent != null | ||
: state.follows[msg.author] | ||
) | ||
) { | ||
peer.notes = peer.notes || {} | ||
peer.notes[msg.author] = ~msg.sequence | ||
} | ||
@@ -227,1 +241,7 @@ } | ||
{ | ||
"name": "epidemic-broadcast-trees", | ||
"description": "", | ||
"version": "5.0.2", | ||
"version": "5.0.3", | ||
"homepage": "https://github.com/dominictarr/epidemic-broadcast-trees", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -329,2 +329,23 @@ var test = require('tape') | ||
test('connects in sync then another message', function (t) { | ||
var state = { | ||
clock: { alice: 3, bob: 2}, | ||
follows: { alice: true, bob: true}, | ||
peers: {} | ||
} | ||
state = events.connect(state, {id: 'bob'}) | ||
state = events.peerClock(state, {id: 'bob', value:{alice: 3, bob: 2}}) | ||
t.deepEqual(state.peers.bob.clock, {alice: 3, bob: 2}) | ||
t.deepEqual(state.peers.bob.notes, {}) | ||
//receive empty clock | ||
state = events.notes(state, {id: 'bob', value: {}}) | ||
t.deepEqual(state.peers.bob.replicating, {}) | ||
state = events.append(state, {author: 'alice', sequence: 4, content: {}}) | ||
t.deepEqual(state.peers.bob.notes, {alice: ~4}) | ||
t.end() | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50007
1175