Commit 5ff620983521663cf40839a68c657acd4624443c
implement "donotwant"
Dominic Tarr committed on 5/3/2017, 5:30:05 AMParent: d4788fe732ab3479153ddfa85296129389822e89
Files changed
state.js | changed |
state.js | |||
---|---|---|---|
@@ -15,8 +15,13 @@ | |||
15 | 15 … | return !isInitRx(state) && | |
16 | 16 … | state.local.seq > Math.max(state.remote.seq, state.remote.req) && state.local.tx | |
17 | 17 … | } | |
18 | 18 … | ||
19 … | +function toSeq (n) { | ||
20 … | + //return Math.abs(n) | ||
21 … | + return n < 0 ? ~n : n | ||
22 … | +} | ||
23 … | + | ||
19 | 24 … | //actually, want to be able to initialize this in receive mode or not. | |
20 | 25 … | exports.init = function (local) { | |
21 | 26 … | if(!Number.isInteger(local)) | |
22 | 27 … | throw new Error('local must be integer') | |
@@ -49,9 +54,9 @@ | |||
49 | 54 … | } | |
50 | 55 … | state.remote.seq = _ready.sequence | |
51 | 56 … | state.local.req = Math.max(state.local.req, _ready.sequence) | |
52 | 57 … | } else { | |
53 | - state.local.req = Math.abs(_ready) | ||
58 … | + state.local.req = toSeq(_ready) | ||
54 | 59 … | state.remote.tx = _ready >= 0 | |
55 | 60 … | } | |
56 | 61 … | if(canSend(state)) { | |
57 | 62 … | state.effect = Math.max(state.remote.seq, state.remote.req) + 1 | |
@@ -75,9 +80,8 @@ | |||
75 | 80 … | msg.sequence === Math.max(state.remote.seq, state.remote.req) + 1 | |
76 | 81 … | ) | |
77 | 82 … | } | |
78 | 83 … | ||
79 | - | ||
80 | 84 … | exports.receiveMessage = function (state, msg) { | |
81 | 85 … | if(!isMessage(msg)) throw new Error('expected a Message!') | |
82 | 86 … | var _state = clone(state) | |
83 | 87 … | ||
@@ -96,9 +100,9 @@ | |||
96 | 100 … | if(isOldMessage(state, msg)) { | |
97 | 101 … | //we already know this, please shut up! | |
98 | 102 … | //let read move us out of tx mode, | |
99 | 103 … | if(state.remote.tx) | |
100 | - _state.ready = -seq | ||
104 … | + _state.ready = -(seq + 1) | ||
101 | 105 … | } | |
102 | 106 … | else if(isNextRxMessage(state, msg)) { | |
103 | 107 … | //since we now know they are ahead, stop transmitting to them | |
104 | 108 … | if(state.ready != null) | |
@@ -118,9 +122,9 @@ | |||
118 | 122 … | if(!isNote(note)) throw new Error('expected note!') | |
119 | 123 … | var _state = clone(state) | |
120 | 124 … | var seq = state.local.seq | |
121 | 125 … | 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) | ||
123 | 127 … | ||
124 | 128 … | _state.local.tx = requested | |
125 | 129 … | _state.remote.req = Math.max(_seq, _state.remote.req) | |
126 | 130 … | ||
@@ -172,11 +176,12 @@ | |||
172 | 176 … | state.effect = Math.max(state.remote.req,state.remote.seq) + 1 | |
173 | 177 … | } | |
174 | 178 … | } | |
175 | 179 … | 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 | ||
179 | 184 … | } | |
180 | 185 … | else if(isNote(state.ready) && state.ready > 0) | |
181 | 186 … | state.ready = msg.sequence //UPDATE NOTE | |
182 | 187 … | else | |
@@ -197,5 +202,4 @@ | |||
197 | 202 … | //anyway, just get on with things | |
198 | 203 … | return _state | |
199 | 204 … | } | |
200 | 205 … | ||
201 | - |
Built with git-ssb-web