git ssb

6+

Dominic / epidemic-broadcast-trees



Commit 78eb17e331e6158000fb02d94ece2aaa7b29de65

tidy

Dominic Tarr committed on 4/16/2017, 12:07:30 PM
Parent: b89be0e4eebccbafefdaea2b2ee1081fc8df5a1c

Files changed

state.jschanged
state.jsView
@@ -41,9 +41,9 @@
4141 //this is not a reduce, and it has side effects.
4242 exports.read = function (state) {
4343 if(state.ready == null) return state
4444 var _ready = state.ready
45- state.ready = null
45 + state.ready = null
4646 if(isMessage(_ready)) {
4747 if(state.remote.seq != null && Math.max(state.remote.seq, state.remote.req) +1 !== _ready.sequence) {
4848 throw new Error('out of order!')
4949 }
@@ -80,52 +80,33 @@
8080 exports.receiveMessage = function (state, msg) {
8181 if(!isMessage(msg)) throw new Error('expected a Message!')
8282 var _state = clone(state)
8383
84-// if(state.remote.tx === false) {
85-// console.log('received msg, when !tx')
86-// console.log(msg, state)
87-// }
88-//
8984 _state.remote.req = Math.max(state.remote.req || 0, msg.sequence)
85 + //not the same^
9086 _state.remote.seq = Math.max(state.remote.seq || 0, msg.sequence)
9187
92- if(state.remote.seq > msg.sequence) {
93-// console.log('receiveMessage', state, msg)
94-// throw new Error('remote sent out of order')
95- }
96- //we may have sent something to them
97- // _state.remote.seq = Math.max(msg.sequence, _state.remote.seq)
98-
9988 if(state.remote.tx == null)
10089 throw new Error('we received a message, when we where waiting for remote to send initial request')
10190
10291 var seq = state.local.seq
10392 if(isMessage(state.ready)) {
104- if(state.ready.sequence <= msg.sequence) {
93 + if(state.ready.sequence <= msg.sequence)
10594 state.ready = null
106- //throw new Error('about to send message we just received')
107- }
10895 }
10996 if(isOldMessage(state, msg)) {
11097 //we already know this, please shut up!
111- if(state.remote.tx) {
112- //let read move us out of tx mode,
113- //incase this note is overridden.
114- //_state.remote.tx = false
98 + //let read move us out of tx mode,
99 + if(state.remote.tx)
115100 _state.ready = -seq
116- }
117101 }
118102 else if(isNextRxMessage(state, msg)) {
119103 //since we now know they are ahead, stop transmitting to them
120104 if(state.ready != null)
121105 _state.ready = null
122106 _state.effect = msg
123107 if(state.remote.tx == false)
124108 state.ready = state.local.seq
125- //update local seq, instead of calling to append?
126- //so that we can handle the next incomming?
127- //what if an invalid message arrives? we should abort this receiver...
128109 }
129110 else {
130111 //this means something went really wrong
131112 _state.error = true
@@ -139,12 +120,8 @@
139120 var seq = state.local.seq
140121 var requested = note >= 0
141122 var _seq = Math.max(Math.abs(note), state.remote.seq)
142123
143-// if(state.local.tx != requested) {
144-// console.log('enable tx')
145-// }
146-//
147124 _state.local.tx = requested
148125 _state.remote.req = Math.max(_seq, _state.remote.req)
149126
150127 if(state.local.req == null) return _state
@@ -192,18 +169,13 @@
192169 _state.ready = null
193170
194171 if(state.local.seq > Math.max(state.remote.req,state.remote.seq))
195172 state.effect = Math.max(state.remote.req,state.remote.seq) + 1
196-// if(msg.sequence > state.remote.seq) {
197-// //console.log('can send!!', msg, state)
198-// state.ready = state.remote.seq + 1
199-// }
200173 }
201174 }
202175 else if(!state.local.tx) {
203176 //unless we know they are up to this, send a note
204177 if(msg.sequence > state.remote.req) {
205- //console.log('APPEND_TURN_OFF_R_TX', msg, state)
206178 _state.ready = state.remote.tx ? msg.sequence : -msg.sequence //SEND NOTE
207179 }
208180 else if(isNote(state.ready) && state.ready > 0)
209181 state.ready = msg.sequence //UPDATE NOTE
@@ -219,21 +191,11 @@
219191 var _state = clone(state)
220192 if (isNextTxMessage(state, msg)) {
221193 _state.ready = msg
222194 }
223- else {
224- //do nothing, it's an old message, so send no notes.
225- //we should only get here is we triggered a `get` effect
226- //but then changed state before it completed.
227- ;
228- }
229- if(!state.local.tx) //do nothing
230- //if we are not in sending state, just stop.
231- //otherwise, the next retrival will be triggered by READ
232- ;
195 + //if it's not the next message
196 + //we must have changed state while retriving this message
197 + //anyway, just get on with things
233198 return _state
234199 }
235200
236201
237-
238-
239-

Built with git-ssb-web