Skip to content

Commit e3d031e

Browse files
committed
Sync: fix implementation and document
1 parent e6a4f10 commit e3d031e

File tree

8 files changed

+775
-666
lines changed

8 files changed

+775
-666
lines changed

docs/src/specification/check.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ RepoCommandRes
3030
However, fetched objects or segments are still inserted into the repo.
3131
Only the objects with ``insert_num=0`` are not inserted.
3232

33-
* For each ``ObjectResult`` contained in the ``RepoCommandRes``, the status code can be one of the following:
33+
* For each ``ObjStatus`` contained in the ``RepoCommandRes``, the status code can be one of the following:
3434

3535
* ``ROGER``: The whole command is received and the operation on this object will be started in the future.
3636
* ``MALFORMED``: If the object has wrong parameter.

docs/src/specification/delete.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Repo deletion process makes use of the :doc:`../misc_pkgs/pub_sub`.
88
1. The repo subscribes to the topic ``/<repo_name>/delete``.
99

1010
2. The client publishes a message to the topic ``/<repo_name>/delete``.
11-
The message payload is ``RepoCommandParam`` containing one or more ``ObjectParam`` with the following fields:
11+
The message payload is ``RepoCommandParam`` containing one or more ``ObjParam`` with the following fields:
1212

1313
* ``name``: either a Data packet name, or a name prefix of Data packets.
1414
* ``start_block_id`` (Optional): inclusive start segment number.
@@ -40,12 +40,12 @@ Delete status check
4040

4141
The client can use the :doc:`check` protocol to check the progress of an deletion process.
4242
The deletion check response message payload is ``RepoCommandRes`` containing zero or more
43-
``ObjectResult`` with the following fields:
43+
``ObjStatus`` with the following fields:
4444

4545
* ``status_code``: status code, as defined on :doc:`check`.
4646
Both the command itself and objects has a status code.
4747
* ``name``: the name of object to delete.
4848
* ``delete_num``: number of Data packets deleted by the repo so far.
49-
* The number of ``ObjectResult`` in the result should be either:
49+
* The number of ``ObjStatus`` in the result should be either:
5050
* =0, which means the command is malformed or not allowed.
51-
* equals to the number of ``ObjectParam`` in the deletion command.
51+
* equals to the number of ``ObjParam`` in the deletion command.

docs/src/specification/encoding.rst

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,42 @@ Most repo commands and status reports are Data packets whose Content contains
55
``RepoCommandParam`` or ``RepoCommandRes`` structure.
66
These Data are issued via Pub-Sub protocol.
77
Each ``RepoCommandParam`` and ``RepoCommandRes`` contains
8-
multiple ``ObjectParam`` and ``ObjectResult``, resp.
8+
multiple ``ObjParam`` and ``ObjStatus``, resp.
99
These structures are defined as follows:
1010

1111
.. code-block:: abnf
1212
13-
ObjectParam =
13+
ObjParam =
1414
Name
1515
[ForwardingHint]
1616
[StartBlockId]
1717
[EndBlockId]
1818
[RegisterPrefix]
1919
20-
ObjectResult =
20+
SyncParam =
21+
SyncPrefix
22+
[RegisterPrefix]
23+
[DataNameDedupe]
24+
[Reset]
25+
26+
ObjStatus =
2127
Name
2228
StatusCode
2329
[InsertNum]
2430
[DeleteNum]
2531
32+
SyncStatus =
33+
Name
34+
StatusCode
35+
2636
RepoCommandParam =
27-
1 * (OBJECT-PARAM-TYPE TLV-LENGTH ObjectParam)
37+
0* (OBJECT-PARAM-TYPE TLV-LENGTH ObjParam)
38+
0* (SYNC-PARAM-TYPE TLV-LENGTH SyncParam)
2839
2940
RepoCommandRes =
3041
StatusCode
31-
0 * (OBJECT-RESULT-TYPE TLV-LENGTH ObjectResult)
42+
0* (OBJECT-RESULT-TYPE TLV-LENGTH ObjStatus)
43+
0* (SYNC-RESULT-TYPE TLV-LENGTH SyncStatus)
3244
3345
RepoStatQuery =
3446
RequestNo
@@ -41,6 +53,12 @@ These structures are defined as follows:
4153
4254
RegisterPrefix = REGISTER-PREFIX-TYPE TLV-LENGTH Name
4355
56+
SyncPrefix = SYNC-PREFIX-TYPE TLV-LENGTH Name
57+
58+
DataNameDedupe = SYNC-DATA-NAME-DEDUPE-TYPE TLV-LENGTH ; TLV-LENGTH = 0
59+
60+
Reset = SYNC-RESET-TYPE TLV-LENGTH ; TLV-LENGTH = 0
61+
4462
StatusCode = STATUS-CODE-TYPE TLV-LENGTH NonNegativeInteger
4563
4664
InsertNum = INSERT-NUM-TYPE TLV-LENGTH NonNegativeInteger
@@ -51,29 +69,39 @@ These structures are defined as follows:
5169
5270
The type number assignments are as follows:
5371

54-
+----------------------+----------------------------+--------------------------------+
55-
| type | Assigned number (decimal) | Assigned number (hexadecimal) |
56-
+======================+============================+================================+
57-
| START-BLOCK-ID-TYPE | 204 | 0xCC |
58-
+----------------------+----------------------------+--------------------------------+
59-
| END-BLOCK-ID-TYPE | 205 | 0xCD |
60-
+----------------------+----------------------------+--------------------------------+
61-
| REQUEST-NO-TYPE | 206 | 0xCE |
62-
+----------------------+----------------------------+--------------------------------+
63-
| STATUS-CODE-TYPE | 208 | 0xD0 |
64-
+----------------------+----------------------------+--------------------------------+
65-
| INSERT-NUM-TYPE | 209 | 0xD1 |
66-
+----------------------+----------------------------+--------------------------------+
67-
| DELETE-NUM-TYPE | 210 | 0xD2 |
68-
+----------------------+----------------------------+--------------------------------+
69-
| FORWARDING-HINT-TYPE | 211 | 0xD3 |
70-
+----------------------+----------------------------+--------------------------------+
71-
| REGISTER-PREFIX-TYPE | 212 | 0xD4 |
72-
+----------------------+----------------------------+--------------------------------+
73-
| OBJECT-PARAM-TYPE | 301 | 0x12D |
74-
+----------------------+----------------------------+--------------------------------+
75-
| OBJECT-RESULT-TYPE | 302 | 0x12E |
76-
+----------------------+----------------------------+--------------------------------+
72+
+----------------------------+----------------------------+--------------------------------+
73+
| type | Assigned number (decimal) | Assigned number (hexadecimal) |
74+
+============================+============================+================================+
75+
| START-BLOCK-ID-TYPE | 204 | 0xCC |
76+
+----------------------------+----------------------------+--------------------------------+
77+
| END-BLOCK-ID-TYPE | 205 | 0xCD |
78+
+----------------------------+----------------------------+--------------------------------+
79+
| REQUEST-NO-TYPE | 206 | 0xCE |
80+
+----------------------------+----------------------------+--------------------------------+
81+
| STATUS-CODE-TYPE | 208 | 0xD0 |
82+
+----------------------------+----------------------------+--------------------------------+
83+
| INSERT-NUM-TYPE | 209 | 0xD1 |
84+
+----------------------------+----------------------------+--------------------------------+
85+
| DELETE-NUM-TYPE | 210 | 0xD2 |
86+
+----------------------------+----------------------------+--------------------------------+
87+
| FORWARDING-HINT-TYPE | 211 | 0xD3 |
88+
+----------------------------+----------------------------+--------------------------------+
89+
| REGISTER-PREFIX-TYPE | 212 | 0xD4 |
90+
+----------------------------+----------------------------+--------------------------------+
91+
| OBJECT-PARAM-TYPE | 301 | 0x12D |
92+
+----------------------------+----------------------------+--------------------------------+
93+
| OBJECT-RESULT-TYPE | 302 | 0x12E |
94+
+----------------------------+----------------------------+--------------------------------+
95+
| SYNC-PARAM-TYPE | 401 | 0x191 |
96+
+----------------------------+----------------------------+--------------------------------+
97+
| SYNC-RESULT-TYPE | 402 | 0x192 |
98+
+----------------------------+----------------------------+--------------------------------+
99+
| SYNC-DATA-NAME-DEDUPE-TYPE | 403 | 0x193 |
100+
+----------------------------+----------------------------+--------------------------------+
101+
| SYNC-RESET-TYPE | 404 | 0x194 |
102+
+----------------------------+----------------------------+--------------------------------+
103+
| SYNC-PREFIX-TYPE | 405 | 0x195 |
104+
+----------------------------+----------------------------+--------------------------------+
77105

78106

79107
Status Code Definition

docs/src/specification/insert.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Repo insertion process makes use of the :doc:`../misc_pkgs/pub_sub`.
88
1. The repo subscribes to the topic ``/<repo_name>/insert``.
99

1010
2. The client publishes a message to the topic ``/<repo_name>/insert``.
11-
The message payload is ``RepoCommandParam`` containing one or more ``ObjectParam`` with the following fields:
11+
The message payload is ``RepoCommandParam`` containing one or more ``ObjParam`` with the following fields:
1212

1313
* ``name``: either a Data packet name, or a name prefix of segmented Data packets.
1414
* ``start_block_id`` (Optional): inclusive start segment number.
@@ -37,12 +37,12 @@ Insert status check
3737

3838
The client can use the :doc:`check` protocol to check the progress of an insertion process.
3939
The insertion check response message payload is ``RepoCommandRes`` containing zero or more
40-
``ObjectResult`` with the following fields:
40+
``ObjStatus`` with the following fields:
4141

4242
* ``status_code``: status code, as defined on :doc:`check`.
4343
Both the command itself and objects has a status code.
4444
* ``name``: the name of object to insert.
4545
* ``insert_num``: number of Data packets received by the repo so far.
46-
* The number of ``ObjectResult`` in the result should be either:
46+
* The number of ``ObjStatus`` in the result should be either:
4747
* =0, which means the command is malformed or not allowed.
48-
* equals to the number of ``ObjectParam`` in the insertion command.
48+
* equals to the number of ``ObjParam`` in the insertion command.

ndn_python_repo/clients/sync.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import sys
1111
sys.path.insert(1, os.path.join(sys.path[0], '..'))
1212

13-
from ..command import RepoCommandParam, SyncParam
13+
from ..command import RepoCommandParam, SyncParam, EmbName
1414
from ..utils import PubSub
1515
import logging
1616
from ndn.app import NDNApp
@@ -46,8 +46,8 @@ async def join_sync(self, sync_prefix: NonStrictName, register_prefix: NonStrict
4646
# construct insert cmd msg
4747
cmd_param = RepoCommandParam()
4848
cmd_sync = SyncParam()
49-
cmd_sync.sync_prefix = sync_prefix
50-
cmd_sync.register_prefix = register_prefix
49+
cmd_sync.sync_prefix = EmbName.from_name(sync_prefix)
50+
cmd_sync.register_prefix = EmbName.from_name(register_prefix)
5151
cmd_sync.data_name_dedupe = data_name_dedupe
5252
cmd_sync.reset = reset
5353

@@ -67,7 +67,7 @@ async def leave_sync(self, sync_prefix: NonStrictName) -> bytes:
6767
# construct insert cmd msg
6868
cmd_param = RepoCommandParam()
6969
cmd_sync = SyncParam()
70-
cmd_sync.sync_prefix = sync_prefix
70+
cmd_sync.sync_prefix = EmbName.from_name(sync_prefix)
7171
cmd_param.sync_groups = [cmd_sync]
7272
cmd_param_bytes = bytes(cmd_param.encode())
7373

ndn_python_repo/command/repo_commands.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@
44
55
@Date 2019-11-01
66
"""
7+
8+
from typing import TypeVar
79
import ndn.encoding as enc
810

9-
__all__ = ['RepoTypeNumber', 'EmbName', 'ObjParam', 'SyncParam', 'SyncStatus', 'RepoCommandParam', 'ObjStatus', 'RepoCommandRes',
10-
'RepeatedNames', 'RepoStatCode', 'RepoStatQuery']
11+
__all__ = [
12+
"RepoTypeNumber",
13+
"EmbName",
14+
"ObjParam",
15+
"SyncParam",
16+
"SyncStatus",
17+
"RepoCommandParam",
18+
"ObjStatus",
19+
"RepoCommandRes",
20+
"RepeatedNames",
21+
"RepoStatCode",
22+
"RepoStatQuery",
23+
]
1124

1225

1326
class RepoTypeNumber:
@@ -26,6 +39,8 @@ class RepoTypeNumber:
2639
SYNC_RESULT = 402
2740
SYNC_DATA_NAME_DEDUPE = 403
2841
SYNC_RESET = 404
42+
SYNC_PREFIX = 405
43+
2944

3045
class RepoStatCode:
3146
# 100 has not been used by previous code, but defined and documented.
@@ -43,9 +58,18 @@ class RepoStatCode:
4358
NOT_FOUND = 404
4459

4560

61+
TEmbName = TypeVar('TEmbName', bound='EmbName')
62+
63+
4664
class EmbName(enc.TlvModel):
4765
name = enc.NameField()
4866

67+
@staticmethod
68+
def from_name(name: enc.NonStrictName) -> TEmbName:
69+
ret = EmbName()
70+
ret.name = name
71+
return ret
72+
4973

5074
class ObjParam(enc.TlvModel):
5175
name = enc.NameField()
@@ -54,17 +78,21 @@ class ObjParam(enc.TlvModel):
5478
end_block_id = enc.UintField(RepoTypeNumber.END_BLOCK_ID)
5579
register_prefix = enc.ModelField(RepoTypeNumber.REGISTER_PREFIX, EmbName)
5680

81+
5782
class SyncParam(enc.TlvModel):
58-
sync_prefix = enc.NameField()
59-
register_prefix = enc.NameField()
83+
sync_prefix = enc.ModelField(RepoTypeNumber.SYNC_PREFIX, EmbName)
84+
register_prefix = enc.ModelField(RepoTypeNumber.REGISTER_PREFIX, EmbName)
6085
data_name_dedupe = enc.BoolField(RepoTypeNumber.SYNC_DATA_NAME_DEDUPE)
6186
reset = enc.BoolField(RepoTypeNumber.SYNC_RESET)
6287
# forwarding_hint = enc.ModelField(RepoTypeNumber.FORWARDING_HINT, enc.Links)
6388
# sync_prefix = enc.ModelField(RepoTypeNumber.REGISTER_PREFIX, EmbName)
6489

90+
6591
class RepoCommandParam(enc.TlvModel):
6692
objs = enc.RepeatedField(enc.ModelField(RepoTypeNumber.OBJECT_PARAM, ObjParam))
67-
sync_groups = enc.RepeatedField(enc.ModelField(RepoTypeNumber.SYNC_PARAM, SyncParam))
93+
sync_groups = enc.RepeatedField(
94+
enc.ModelField(RepoTypeNumber.SYNC_PARAM, SyncParam)
95+
)
6896

6997

7098
class RepoStatQuery(enc.TlvModel):
@@ -81,12 +109,14 @@ class ObjStatus(enc.TlvModel):
81109
class SyncStatus(enc.TlvModel):
82110
name = enc.NameField()
83111
status_code = enc.UintField(RepoTypeNumber.STATUS_CODE)
84-
insert_num = enc.UintField(RepoTypeNumber.INSERT_NUM)
112+
85113

86114
class RepoCommandRes(enc.TlvModel):
87115
status_code = enc.UintField(RepoTypeNumber.STATUS_CODE)
88116
objs = enc.RepeatedField(enc.ModelField(RepoTypeNumber.OBJECT_RESULT, ObjStatus))
89-
sync_groups = enc.RepeatedField(enc.ModelField(RepoTypeNumber.SYNC_RESULT, ObjStatus))
117+
sync_groups = enc.RepeatedField(
118+
enc.ModelField(RepoTypeNumber.SYNC_RESULT, SyncStatus)
119+
)
90120

91121

92122
class RepeatedNames(enc.TlvModel):

0 commit comments

Comments
 (0)