fieldnotes 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fieldnotes/dns.rb +26 -1
- data/lib/fieldnotes/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 27817e1f4e717e5f7a608fbb693af125382bf7586bca6fcb624bb1c5255f2063
|
|
4
|
+
data.tar.gz: a8d23cbde0b053e558e290703df8d4ad7e6da8626e2e4b2d95f9d2fee30ae23e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d88d5b8836d6258533da8971a111f4b34b9226d4ac05cae1bf1cce76e3035331d4d0fa8d0753387b6f6af0ee199bd572415e178fab9a2641c9240083e7a06138
|
|
7
|
+
data.tar.gz: c1f1e5922146ad11dc7709c8624175f55dd7d42ca61e0f31f8a197ca5e7d5dab10667c92f7075875dabaada63b7164996b1c0ad578073476e6d2c996a9a0722a
|
data/lib/fieldnotes/dns.rb
CHANGED
|
@@ -50,8 +50,33 @@ module FieldNotes
|
|
|
50
50
|
out.force_encoding("UTF-8")
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
WIRE_MAX = 255
|
|
54
|
+
|
|
55
|
+
# Raw payload bytes that still fit one name: a name is limited to 255 bytes on the wire, and the
|
|
56
|
+
# zone plus the dots between labels are fixed costs. Cutting the message at 1200 characters
|
|
57
|
+
# produced names that could not be sent at all.
|
|
58
|
+
def self.payload_budget(zone = ZONE, max_label = 63)
|
|
59
|
+
clean = zone.to_s.sub(/\A\./, "")
|
|
60
|
+
wire = WIRE_MAX - (clean.empty? ? 0 : clean.bytesize + 1)
|
|
61
|
+
wire.downto(1) do |b32|
|
|
62
|
+
labels = [(b32 + max_label - 1) / max_label, 1].max
|
|
63
|
+
return (b32 * 5) / 8 if b32 + labels - 1 <= wire
|
|
64
|
+
end
|
|
65
|
+
0
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Cut to a byte budget without splitting a character: byteslice may land inside a multi-byte
|
|
69
|
+
# sequence, and scrub drops the broken tail.
|
|
70
|
+
def self.truncate_bytes(text, limit)
|
|
71
|
+
raw = text.to_s.encode(Encoding::UTF_8)
|
|
72
|
+
return raw if raw.bytesize <= limit
|
|
73
|
+
|
|
74
|
+
raw.byteslice(0, limit).to_s.scrub("")
|
|
75
|
+
end
|
|
76
|
+
|
|
53
77
|
def self.encode_name(from, msg, zone: ZONE)
|
|
54
|
-
|
|
78
|
+
text = "#{from.to_s[0, 40]}|#{msg.to_s[0, 1200]}"
|
|
79
|
+
payload = b32encode(truncate_bytes(text, payload_budget(zone)))
|
|
55
80
|
"#{payload.scan(/.{1,63}/).join('.')}.#{zone}"
|
|
56
81
|
end
|
|
57
82
|
|
data/lib/fieldnotes/version.rb
CHANGED