blob: bd99fb1b9fc4c2b17bb1a5e7caffc956214cae86 [file] [log] [blame]
Yingdi Yuf93e6ba2014-08-15 10:20:16 -07001===============
2Design Document
3===============
4
5Terminology
6===========
7
8User
9 an user which participates in the synchronization.
10 An user is uniquely identified by a namespace, e.g., ``/ndn/ucla/alice``.
11
12Session
13 an instance of a user in the synchronization group.
14 A session is uniquely identified by the namespace of the user and a sessionId:
15
16 /<user_namespace>/[SessionId]
17
18 The sessionId is encoded as `NDN-TLV nonNegativeInteger
19 <http://named-data.net/doc/ndn-tlv/tlv.html#non-negative-integer-encoding>`_.
20 A user can publish the data packets to synchronize under the session namespace.
21
22 A user may have more than one sessions in a synchronization group.
23 For example, one may join the synchronization through two sessions,
24 one from his mobile phone and the other from his laptop.
25 Each session is handled independently, even when two sessions belong to the same user.
26
27Entity
28 the process who runs a session.
29 It could be a chatroom process running on end host machine.
30
31Sequence Number
32 Data packets published in the same session are indexed by continuous sequence numbers starting
33 from 0.
34
35 /<user_namespace>/[SessionId]/[SeqNo]
36
37 The sequence number is encoded as `NDN-TLV nonNegativeInteger
38 <http://named-data.net/doc/ndn-tlv/tlv.html#non-negative-integer-encoding>`_.
39 The latest status of a session is represented by its largest sequence number.
40
41Synchronization Group
42 consists of several sessions which synchronize their latest status with each other.
43 A sync group has its own namespace under which sessions publish their status updates.
44 The namespace is constructed by concatenating a multicast prefix and the group name
45 (as one component).
46 For now, the multicast prefix is temporarily defined as
47
48 /ndn/broadcast/[AppName]
49
50 e.g., ``/ndn/broadcast/ChronoChat``.
51 And a sync group name is defined as
52
53 /ndn/broadcast/[AppName]/[GroupName]
54
55 e.g., ``/ndn/broadcast/ChronoChat/letschat``.
56 It is recommended to make group name unique.
57 When two sync groups accidentally use the same group name,
58 they may interfere each other's synchronization process.
59 Eventually, this problem should not exist when sync-interests can be authenticated.
60
61Data Structure
62==============
63
64Sync Tree
65 a data structure which represents the knowledge of the sync group.
66
67A sync tree has two levels: root and leaves.
68Each leaf represents a session and is supposed to contain the latest sequence number of the session.
69Leaves are ordered according to `Canonical Order
70<http://named-data.net/doc/ndn-tlv/name.html#canonical-order>`_).
71
72The sync tree is summarized by a root digest.
73Suppose that *n* leaves are canonically ordered and
74that the session name and sequence number of the *i*-th node is denoted by *N*\ :sub:`i`\ and
75*S*\ :sub:`i`\, the root digest is calculated as:
76
77 digest = H(H(N\ :sub:`0`\ | S\ :sub:`0`\ ) | H(N\ :sub:`1`\ | S\ :sub:`1`\ ) | ... | H(N\ :sub:`n-1`\ | S\ :sub:`n-1`\ ))
78
79Entities synchronize the their knowledge about the sync group in terms of exchanging the root digest
80of their sync tree.
81
82Security Assumption
83===================
84
85We first assume that routing prevents malicious attacker from the multicast group,
86i.e., malicious attackers cannot receive sync-interests.
87
88Trust model is left to the upper layer applications.
89
90Knowledge Synchronization
91=========================
92
93Normal Case
94-----------
95
96An entity keeps an outstanding **sync-interest** which carries the current root digest of its sync
97tree:
98
99 /ndn/broadcast/[AppName]/[GroupName]/[Digest]
100
101With SHA-256 hash function, the digest is a 32-byte name component.
102When the tree is empty, the digest is
103``e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855``,
104which is a digest with empty input.
105
106The sync-interest will multicast to all entities in the sync group.
107When every entity has the same knowledge, the root digest of their sync trees should be the same.
108The sync-interests will be aggregated in the network, and their forwarding states in routers
109constitute a multicast tree.
110
111Once an entity changes its status (i.e., sequence number is updated), it should generate a data
112packet, called **sync-reply**, which contains its session name and the latest sequence number.
113The sync-reply will be forwarded back to all the entities.
114These entities will update their knowledge set and the root digest of their sync trees,
115and express a sync-interest with the new root digest.
116
117The name of a sync-reply extends the sync-interest name by one name component ``Nonce``.
118In case that the actual size of a sync-reply exceeds the network layer packet size limit,
119a sync-reply needs to be broken into multiple segments.
120Any pair of {prefix, seqNo} should not be splited into two segments.
121Therefore, the sync-reply name could be:
122
123 /<sync-interest>/[Nonce]/[SegmentNo]
124
125``SegmentNo`` follows the definition specified in `NDN naming convention
126<http://named-data.net/wp-content/uploads/2014/08/ndn-tr-22-ndn-memo-naming-conventions.pdf>`__.
127
128
129
130Recovery
131--------
132
133An entity may receive a sync-interest with a digest that is different from the entity's current
134root digest.
135The received digest could fall into either of two cases: old digest or unknown digest.
136
137To tell whether the received digest is an old one,
138each entity should keep a log about how its root digest changes over time.
139If the received digest can be found from the log, it must be the old digest.
140With the log, the receiving entity can tell which sessions have changed the states since the state
141represented by the old digest, therefore it can put the latest sequence number of these sessions
142into sync-reply.
143Therefore the size of sync-reply is roughly determined by the number of sessions in a sync group.
144
145Unrecognized digest will happen when both sender and receiver of the sync-interest have some state
146updates that the other side does not have
147(e.g., two sessions generate state updates at the same time;
148or an entity has not received some state updates yet).
149When receiving an unrecognized digest, an entity should set a delay response timer
150(0, *T*\ :sub:`delay_response`\ ] ms
151(**What is the value of** *T*\ :sub:`delay_response`\ **? 200?**).
152If the missing state updates are received during this time and updated root digest matches the
153pending incoming interest, the delay response timer will be canceled.
154If no missing state update is received during this time,
155the entity should try to help the sync-interest sender to recover the knowledge set by returning
156its complete knowledge set (or ignore the interest if its knowledge set is empty).
157
158
159Simultaneous Update
160-------------------
161
162In some cases, two sessions may generate updates at the same time.
163Some entities in the sync group may receive the update from one session,
164while the rest entities may receive the update from the other session.
165As a result, entities in the same sync group have different knowledge sets.
166This case is equivalent to the unknown digest discussed above
167and can be recovered with a complete knowledge set.
168Note that ``Exclude`` selector is not used in this case.
169
170Reset Sync Group
171----------------
172
173Sync group needs to be reset periodically in order to clean up inactive sessions.
174All active sessions should join the sync group again after resetting.
175
176Reset signal is expressed as a **reset-interest**.
177
178 /ndn/broadcast/[AppName]/[GroupName]/reset
179
180Reset-interest is expected to time out. Reset-interest should be sent out in two cases:
181
1821. When a new session joins the sync group, the entity running the new session should
183 send out a reset-interest.
1842. Each entity, once receiving a reset-interest, should restart a timer
185 (*T*\ :sub:`reset`\ , *T*\ :sub:`reset`\ + *T*\ :sub:`random`\] seconds
186 (**What is the value of** *T*\ :sub:`reset`\ **? 600?**
187 **What is the value of** *T*\ :sub:`random`\ **? 60?**),
188 the entity should send out a reset-interest when the timer expires.
189
190Reset-interest will multicast to all entities in the sync group.
191Once receiving a reset interest, an entity should
192
1931. reset its own sync tree but still keep using its latest sequence number;
1942. express a sync-interest ``/ndn/broadcast/[AppName]/[GroupName]/[EmptyInputDigest]`` (``mustBeFresh`` =true);
1953. start a delay response timer (0, *T*\ :sub:`delay_response`\ ] ms.
196
197When the a state update is received before the timer expires,
198the entity should update its sync tree and express a sync-interest with the new root digest.
199The entity should reset the delay response timer until it makes the first sync-reply which contains
200its own sequence number.
201
202The ``InterestLifetime`` of reset-interest is set to 10 seconds.
203If the interval between two reset-interests is less than 10 seconds, they will be aggregated.
204Otherwise, the latest reset-interest will suppress the previous reset-interest.
205
206Sync Reply Format
207=================
208
209The content of sync reply is defined as a TLV block.
210::
211
212 SyncReply ::= SYNC-REPLY-TYPE TLV-LENGTH
213 StateLeaf+
214
215 StateLeaf ::= STATE-LEAF-TYPE TLV-LENGTH
216 Name
217 Seq
218
219 Seq ::= SEQ-TYPE TLV-LENGTH
220 nonNegativeInteger
221
222
223Type Code Assignment
224--------------------
225
226+------------------+----------------+----------------------+
227| Type | Assigned code | Assigned code (hex) |
228+==================+================+======================+
229| SYNC-REPLY-TYPE | 128 | 0x80 |
230+------------------+----------------+----------------------+
231| STATE-LEAF-TYPE | 129 | 0x81 |
232+------------------+----------------+----------------------+
233| SEQ-TYPE | 130 | 0x82 |
234+------------------+----------------+----------------------+