git ssb

6+

Dominic / epidemic-broadcast-trees



Commit 5ff620983521663cf40839a68c657acd4624443c

implement "donotwant"

Dominic Tarr committed on 5/3/2017, 5:30:05 AM
Parent: d4788fe732ab3479153ddfa85296129389822e89

Files changed

state.jschanged
state.jsView
@@ -15,8 +15,13 @@
1515 return !isInitRx(state) &&
1616 state.local.seq > Math.max(state.remote.seq, state.remote.req) && state.local.tx
1717 }
1818
19 +function toSeq (n) {
20 + //return Math.abs(n)
21 + return n < 0 ? ~n : n
22 +}
23 +
1924 //actually, want to be able to initialize this in receive mode or not.
2025 exports.init = function (local) {
2126 if(!Number.isInteger(local))
2227 throw new Error('local must be integer')
@@ -49,9 +54,9 @@
4954 }
5055 state.remote.seq = _ready.sequence
5156 state.local.req = Math.max(state.local.req, _ready.sequence)
5257 } else {
53- state.local.req = Math.abs(_ready)
58 + state.local.req = toSeq(_ready)
5459 state.remote.tx = _ready >= 0
5560 }
5661 if(canSend(state)) {
5762 state.effect = Math.max(state.remote.seq, state.remote.req) + 1
@@ -75,9 +80,8 @@
7580 msg.sequence === Math.max(state.remote.seq, state.remote.req) + 1
7681 )
7782 }
7883
79-
8084 exports.receiveMessage = function (state, msg) {
8185 if(!isMessage(msg)) throw new Error('expected a Message!')
8286 var _state = clone(state)
8387
@@ -96,9 +100,9 @@
96100 if(isOldMessage(state, msg)) {
97101 //we already know this, please shut up!
98102 //let read move us out of tx mode,
99103 if(state.remote.tx)
100- _state.ready = -seq
104 + _state.ready = -(seq + 1)
101105 }
102106 else if(isNextRxMessage(state, msg)) {
103107 //since we now know they are ahead, stop transmitting to them
104108 if(state.ready != null)
@@ -118,9 +122,9 @@
118122 if(!isNote(note)) throw new Error('expected note!')
119123 var _state = clone(state)
120124 var seq = state.local.seq
121125 var requested = note >= 0
122- var _seq = Math.max(Math.abs(note), state.remote.seq)
126 + var _seq = Math.max(toSeq(note), state.remote.seq)
123127
124128 _state.local.tx = requested
125129 _state.remote.req = Math.max(_seq, _state.remote.req)
126130
@@ -172,11 +176,12 @@
172176 state.effect = Math.max(state.remote.req,state.remote.seq) + 1
173177 }
174178 }
175179 else if(!state.local.tx) {
176- //unless we know they are up to this, send a note
177- if(msg.sequence > state.remote.req) {
178- _state.ready = state.remote.tx ? msg.sequence : -msg.sequence //SEND NOTE
180 + //if we don't know they are up to this, and they havn't
181 + //asked us to not send anything (-1) then send a note.
182 + if(msg.sequence > state.remote.req && state.remote.req != 0) {
183 + _state.ready = state.remote.tx ? msg.sequence : -(msg.sequence+1) //SEND NOTE
179184 }
180185 else if(isNote(state.ready) && state.ready > 0)
181186 state.ready = msg.sequence //UPDATE NOTE
182187 else
@@ -197,5 +202,4 @@
197202 //anyway, just get on with things
198203 return _state
199204 }
200205
201-

Built with git-ssb-web