git ssb


4+

Dominic / epidemic-broadcast-trees



Tree: 23ba81085dd83343c92fd95d407f0116d636a19a

Files: 23ba81085dd83343c92fd95d407f0116d636a19a / notes.txt

2656 bytesRaw
1 OUR_SEQ, THEIR_SEQ, THEM_RECV, US_RECV
2
3 onRecieveValidMessage: //after we have processed the message.
4 if(OUR_SEQ > THEIR_SEQ && THEM_RECV)
5 send(msg)
6 else if(OUR_SEQ < THEIR_SEQ && US_RECV)
7 send({id: msg.author, seq: msg.sequence}) //OPTIONAL, don't have to do this every time
8 onReceiveMessage:
9 if(OUR_SEQ > msg.sequence)
10 send({id: msg.author, seq: - OUR_SEQ}) //tell them to stop sending.
11 //else, validate the message and continue.
12 onRecieveNote:
13 if(note.seq < 0 && THEM_RECV) {
14 THEM_RECV = false //they have asked us to stop sending this feed to them.
15 }
16 if(Math.abs(note.seq) > OUR_SEQ) {
17 US_RECV = true
18 send({id: note.id, seq: OUR_SEQ})
19 }
20
21 onBeginReplication:
22 for(var id in feeds)
23 send({id: id, seq: feed[id].seq})
24
25 //okay I feel satisfied that is the correct logic
26 //but how do I make this FSM pull?
27
28 //I know, functional style state
29
30 //For each peer, for each feed keep the state of:
31
32 remote = {requested: Seq, sent: Seq, ready: msg|null, sending: bool, receiving: bool} //sending to, receiving from
33
34 //also keep a map of local = {id: seq}
35 //then I think all events can be handled sync
36
37 READ:
38 if ready!= null, the puller takes `ready` then sets it to `null`
39 if ready was a msg, this also triggers retriving the next msg, if this feed.sent < local[id]
40 if ready was a note, it's just sent without triggering anything.
41
42 RECEIVE_MSG: //receive a message from this peer, before it's validated.
43 remote.requested = msg.sequence //always remember they are up to this sequence.
44
45 if(msg.seq <= local[msg.author]) //if we already know about this message
46 if(remote.receiving) {
47 remote.ready = {id, seq: - local[id]} //tell them we do not need this feed.
48 remote.receiving = false
49 }
50 if(!remote.receiving) {
51 we have asked them to stop sending, but they havn't got the note yet.
52 anyway, remember they know this sequence.
53 remote.requested = msg.sequence
54 }
55 else if(remote.sending) {
56 this is an error, they should never send to us if we are sending.
57 if this ever happens it's a programmer error. maybe should tell them to top sending?
58 you might receive a
59 }
60 RECEIVE_NOTE:
61 if(remote.sending) {
62 if(note.seq < 0) //stop sending
63 remote.sending = false, remote.ready = null, remote.requested = abs(note.seq)
64 }
65 else if(!remote.receiving) {
66 if(abs(note.seq) > local[id]) //if this is the fastest peer for this feed, ask them to send.
67
68
69 }
70
71
72
73

Built with git-ssb-web