Refactor: use wire-formatted byte arrays to represent names internally, no more strings
Farewell char *name !
In general, names in hnsd are now always represented as byte arrays, serialized in DNS wire format. That means (example):
<label 1 length> <label 1> <label 2 length> <label 2> 0x00
Even if we are just handling a single label like a TLD, we still store it like this. This means that full names are always max 255 bytes and single labels are always max 65 bytes (63 max label + 1 for length and + 1 for 0x00)
We only convert back to string ("presentation format") to print names out the log, and to pass to libunbound recursive.
For convention, variables called name can be assumed to be full names or possibly greater than one label. Variables named tld should just be a single label, but still prefixed with length and trailed by 0x00
TODO:
- [x] fix
RPrecord so it can be tested (record data should not be compressed) - [x] un-comment the invalid test cases imported from pdns and test for failure
[ ? ] add in the hsd integration tests from https://github.com/handshake-org/hnsd/pull/87 (or maybe that belongs in followup PR)
- Here is an benchmark and one of the possible solutions implemented: https://github.com/nodech/hnsd-misc-c/tree/master/namecpy-v-memcpy
Not sure why but when I compiled and ran this on my computer, the just_cpy method was way faster:
just_cpy: ops=10000, time=0.003070s, rate=3257328 ops/s 307 ns/op
name_cpy: ops=10000, time=0.004199s, rate=2381519 ops/s 419 ns/op
with -O2
just_cpy: ops=10000, time=0.000001s, rate=10000000000 ops/s 0 ns/op
name_cpy: ops=10000, time=0.000932s, rate=10729613 ops/s 93 ns/op