Skip to content

Commit 8143b5f

Browse files
committed
LVS: Fix temporary tag IDs
1 parent 02e70bc commit 8143b5f

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

docs/src/lvs/binary-format.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ Every node has an integer ID, which equals to the index it occurs in the LVS mod
101101
In current compiler implemented in python-ndn, it is ``0`` to indicate that the first Node is the root,
102102
but there is no guarantee in future and a checker should not rely on this convention.
103103

104-
Every pattern edge is also assigned with a number.
105-
If the number is lower than ``NamedPatternCnt``, then it is a named pattern edge.
106-
If it is larger than or equal to ``NamedPatternCnt``, then it is a temporary named pattern ``_``.
104+
Every pattern edge is also assigned with a number, which starts from ``1``.
105+
If the number is lower than or equal to ``NamedPatternCnt``, then it is a named pattern edge.
106+
If it is larger than ``NamedPatternCnt``, then it is a temporary named pattern ``_``.
107107
Note that since TLV encoding does not support negative numbers, we use ``NamedPatternCnt`` to differentiate temporary and normal named patterns.
108108
A checker does not need to tell whether a pattern edge is named or not,
109-
if it only checks the signature validity, since every temporary pattern edge is assigned with a different tag.
109+
if it only checks the signature validity, since every occurrence of a temporary pattern edge is assigned with a different tag.
110110
Tag symbol information is only needed if the checker needs the name identifiers of named patterns.
111111

112112
``TagSymbol`` describes the identifiers for each named pattern edge.
113-
It is ununsed and can be safely discarded if a checker does not dump error reason after verification fails.
113+
It is unused and can be safely discarded if a checker does not dump error reason after verification fails.
114114
The TLV-Type is still marked as critical for sanity check reason expressed in the next section.
115115

116116
Node
@@ -119,13 +119,13 @@ Node
119119
``NodeId`` always equal to the index it occurs in the LVS model, starting from ``0``.
120120

121121
``RuleName`` is the identifier used to identify this node in the original LVS schema.
122-
It is ununsed if a checker does not dump error reason after verification fails.
122+
It is unused if a checker does not dump error reason after verification fails.
123123

124124
``ValueEdge`` and ``PatternEdge`` are edges to children under its subtree.
125125
A ``ValueEdge`` requests an exact match; a ``PatternEdge`` specifies a match of a constraint set,
126126
and assigns the component value to the corresponding pattern variable.
127127
A checker must always check ``ValueEdge`` for exact matches before it uses ``PatternEdge`` to match.
128-
When multiple ``PatternEdge`` can match, the first one occuring in the file should hit.
128+
When multiple ``PatternEdge`` can match, the first one occurring in the file should hit.
129129

130130
``SignConstraint`` indicates zero or more node IDs.
131131
When a packet name matches the current node, the signing key should match one of the nodes specified by ``SignConstraint``.
@@ -164,7 +164,7 @@ The following sanity checks are recommended but not required.
164164

165165
- After the application finishes providing user functions, check all user functions used in the programs are given.
166166

167-
+ If the implementation chooses not to do so, it should let the verifcation fail whenever an unknown user function is triggered.
167+
+ If the implementation chooses not to do so, it should let the verification fail whenever an unknown user function is triggered.
168168

169169
- After the application finishes providing trust anchors, check all roots of signing constraint are provided with a trust anchor.
170170

@@ -173,7 +173,7 @@ The following sanity checks are recommended but not required.
173173
* (a) specified as a signing constraint of another node, and
174174
* (b) a node without any signing constraint attached to it
175175

176-
+ If the implementation chooses not to do so, it should let the verifcation fail whenever reaches a leaf node without sign constraint.
176+
+ If the implementation chooses not to do so, it should let the verification fail whenever reaches a leaf node without sign constraint.
177177

178178
- *[Optional]* No unreachable nodes from the tree root. (python-ndn does not check this)
179179

docs/src/lvs/demonstration.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ Therefore, no rule replication is needed.
6565
Generating tree
6666
~~~~~~~~~~~~~~~
6767

68+
.. warning::
69+
The figures in this page are out-of-dated. Unfortunately I am not able to fix them now.
70+
Please check with the actual result of code.
71+
More specifically, note the following things:
72+
73+
- There is a ``#KEY`` branch attach to the root, which is omitted in the figure.
74+
- Temporary pattern edges do not share tag IDs.
75+
6876
.. image:: /_static/lvs-ptree.svg
6977
:align: center
7078
:width: 100%

src/ndn/app_support/light_versec/compiler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class Compiler:
7878
named_pats: dict[str, str]
7979
node_pool: list[bny.Node]
8080
rule_node_ids: dict[str, list[int]]
81+
temp_tag_index: int = 0
8182

8283
@dataclass
8384
class RuleChain:
@@ -292,7 +293,9 @@ def _generate_node(self, depth: int, context: list[RuleChain], parent: Optional[
292293
edge.tag = tag
293294
else:
294295
# TLV integer is required to be unsigned, so we use maximum named pattern + x for temporary pattern -x
295-
edge.tag = len(self.named_pats) - tag
296+
self.temp_tag_index += 1
297+
edge.tag = self.temp_tag_index
298+
# edge.tag = len(self.named_pats) - tag
296299
edge.cons_sets = next(pm[1] for pm in p_moves if pm[2] == pm_str)
297300
edge.dest = self._generate_node(depth + 1, new_context, node.id, previous_tags | {tag})
298301
node.p_edges.append(edge)
@@ -323,6 +326,7 @@ def compile(self) -> bny.LvsModel:
323326
sorted_rep_rules = list(self.rep_rules.items())
324327
sorted_rep_rules.sort(key=lambda tup: tup[0])
325328
rule_chains = sum([v for (k, v) in sorted_rep_rules], start=[])
329+
self.temp_tag_index = len(self.named_pats)
326330
start_node = self._generate_node(0, rule_chains, None, set())
327331
self._fix_signing_references()
328332
ret = bny.LvsModel()

0 commit comments

Comments
 (0)