1 % JSON Domain Format as Implemented by Pdns-Pipe-Nmc
7 `DomObj` either a `String` containing a dotted quad (see Note below),
8 or a JSON `Map`, with the following attributes, all optional:
10 | Key | Type | Comment |
11 |-------------|---------------------------------------|--------------------------------------------|
12 | service | Array(SrvObj) | Located two levels above pos. |
13 | ip | Array(String) | Dotted quad format "1.2.3.4" |
14 | ip6 | Array(String) | Semicolon format "DEAD::BEEF" |
15 | tor | String | Onion name |
17 | freenet | String | |
18 | alias | String | Nullifies other attributes |
19 | translate | String | Nullifies other attributes |
20 | email | String | Used in `SOA` |
21 | loc | String | Format suitable for `LOC` |
22 | info | JsonObj | Currently unspecified |
23 | ns | Array(String) | Domain names as in `NS` |
24 | delegate | String | Replaces current object |
25 | import | Array(String) | "Deep" merges into current obj. |
26 | map | Map(String:DomObj) | Tree of subdomain objects |
27 | fingerprint | Array(String) | |
28 | tls | Map(String:Map(String:Array(TlsObj))) | Outer `Map` by `Protocol`, inner by `Port` |
29 | ds | Array(DsObj) | |
33 * Any attribute specified as `Array(String)` may be present in the
34 JSON document as a plain `String`, which is interpreted the same way
35 as an `Array` containing a single `String` element.
36 * If `DomObj` is a `String`, it is interpreted as an IPv4 address.
37 In other words, string `"1.2.3.4"` is the same as the Map
38 `"{\"ip\":\"1.2.3.4\"}"`. Such "shorthand" DomObj can be present at
39 the top level or as a value in the `"map"` attribute.
43 `SrvObj` is a heterogenous Array of fixed size containing 6 elements:
45 | N | Type | Meaning |
46 |---|--------|----------|
47 | 0 | String | Service |
48 | 1 | String | Protocol |
49 | 2 | Int | Priority |
52 | 5 | String | Hostname |
56 * `Service` and `Protocol` are two elements of the domain name, without
58 * `SrvObj` with Service `"smtp"`, Protocol `"tcp"` and Port `25` is also
59 interpteted as an `MX` DNS resource.
60 * When lookup is performed for `SRV` records at fqdn
61 `"_serv._proto.sub.dom.bit"`, domain object for `"sub.dom.bit"` must be
62 fetched, and in this object, `SrvObj`s for the Service `"serv"` and
63 Protocol `"proto"` selected from its `"service"` attribute.
67 `TlsObj` is a heterogenous Array of fixed size containing 3 elements:
69 | N | Type | Meaning |
70 |---|--------|-------------------------------------------------------|
71 | 0 | Int | Match type - 0:Exact, 1:SHA-256, 2:SHA-512 |
72 | 1 | String | Match value - certificate or hash of it as hex string |
73 | 2 | Int | Include subdomains - 0:No, 1:Yes |
77 `DsObj` is a heterogenous Array of fixed size containing 4 elements:
79 | N | Type | Meaning |
80 |---|--------|--------------------------|
82 | 1 | Int | Key Algorithm |
83 | 2 | Int | Hash Type |
84 | 3 | String | Hash Value as hex string |
86 ## Data Interpretation
88 Assuming a query is performed for
89 `sdN`++"."++{...}++"."++`sd2`++"."++`sd1`++"."++`dom`++".bit"
90 (`sdX` list possibly being empty), the lookup process starts by
91 querying the database for the object corresponding to `dom`.
92 Technically, it is easiest to populate a "seed" DomObj with a
93 single attribute `"import"` the value of which corresponds to the
94 `dom` name in the Namecoin namespace, which is `"d/" ++ dom`.
95 This domain object is then transformed by the following
98 1. Value of the element of the `"map"` attribute with the key `""`
99 (empty string) is recursively merged into the base domain. The
100 `""` element of the `"map"` is removed from the result.
101 2. If attribute `"import"` does not exist in the resulting object,
102 recursion stops, and step 3 is performed on the result
103 If attribute `"import"` exists in the resulting object, lookup is
104 is performed for the values of this attribute, and fetched objects
105 are recursively merged into the base domain. The `"import"` attribute
106 is removed from the result. Then the result is passed as base
108 3. If subdomain chain is empty, recursion stops, and step 4 is
109 performed on the result. If subdomain chain is not empty, next
110 element is taken out of the chain, and the `"map"` is looked
111 up for the element with the name matching the subdomain element.
112 The value of this element of the `"map"` is passed as base domain
113 to step 1. If matching element does not exist, lookup is considered
115 4. Domain object with all `""` map elements and all `"import"` data
116 merged is "normalized" by removal of attributes that are nullified
117 by the presence of other attributes.
119 Note that the process involves recursion nested to three levels.
123 When a domain object `sub` needs merging into a domain object `base`,
124 the following rules are applied:
126 * Of `String` and other "scalar" attributes, one is chosen, the value
127 from the `base` taking precedence.
128 * On `Array` attribtes, `union` operation is performed. (Of equal
129 elements, only one copy is left.)
130 * On `Map` attributes, recursive merge is performed. On the top level,
131 elemens with keys that are only present in either `base` or `sub`
132 object are all put into result. The values of the elements that are
133 present in both `base` and `sub` are merged according to the rules
134 applicable to their type.