dname - refactoring efforts
This should effectively remove count and size and name should be the only thing representing a domain name.
Differences from the old dnames
dname
used to be a structure with various pointers and reference counting, now it is reducted to a mere pointer to bytes in memory. Since the domain name in the wire format has pretty much everything we need, the only complication could be frequent size calculation, which can be avoided in most cases. Still, it is a matter of simply jumping through labels. This reduction is both lightweight and works very nicely when altering a name label count (very frequent operation), for example looking up parents we need to chop leftmost labels several time. Old style API required to alloc or move memory around, new API allows you to just jump to next label and treat it as a domain name. There are other good examples and the point is to avoid memory allocation or copying as much as possible.
Proposed changes to API
See issue #11 (closed) for more reasoning and plans.
-
knot_dname_wire_check()
- check name on the wire sanity -
knot_dname_parse()
- wire_check + decompressing a name -
knot_dname_copy()
- copy a name -
knot_dname_copy_part()
- partial copy (N first labels) -
knot_dname_to_wire()
- write to wire as is (no decompression) -
knot_dname_unpack()
- write to wire + decompress -
knot_dname_to_str()
- classics -
knot_dname_from_str()
- parse from string (useful in config and stuff) -
knot_dname_to_lower()
- convert to lowercase MUST BE DECOMPRESSED -
knot_dname_size()
- calculate actual size (as is, no decompression) -
knot_dname_realsize()
- calculate full decompressed size -
knot_dname_is_sub()
- is is subdomain? -
knot_dname_is_wildcard()
- go figure -
knot_dname_matched_labels()
- count matching labels, base of align and subdomain checks -
knot_dname_replace_suffix()
- replace suffix, base ofknot_dname_cat
as it's basically replacing 0 labels at the end with a suffix -
knot_dname_free()
- free and set to NULL, still present but it shall be removed or replaced withmm_ctx
based API (later) -
knot_dname_cmp()
- compare two names canonicaly, converted to string inequality problem withknot_dname_lf
-
knot_dname_cmp_wire()
- same, but names may be compressed -
knot_dname_is_equal()
- faster check for equality -
knot_dname_cat()
- remains, but I don't like the usage much -
knot_dname_prefixlen()
- length of the first N labels -
knot_dname_labels()
- count labels -
knot_dname_align()
- align names end-to-end, useful in name compression -
knot_dname_lf()
- convert name to lookup format, allowing us to use string inequality for canonical ordering
Work to be done
Since the names are now not reference counted, different approach than dname table must be employed for sorting out duplicated. I propose reference counting of rdata since:
- node owner is looked up in zone tree for free in each insert, no dups there
- duplicate RDATA happens frequently in just several cases (NS, DNAME, CNAME...) but not only names may be duplicates!
- by sorting out whole RDATA duplicates one may do so selectively and saves a more memory in the long run