<div dir="ltr">dear all<br><br>I use cachedb with redis backend.<br><br>try to preload redis using python.<br><br>```<br>import dns.message<br>import dns.rcode<br>import dns.flags<br>import struct<br>import time<br>import redis<br><br>def make_minimal_nxdomain(domain: str) -> bytes:<br>    q = dns.message.make_query(domain, 'A')<br>    r = dns.message.make_response(q)<br>    r.set_rcode(dns.rcode.NXDOMAIN)<br>    r.flags |= dns.flags.QR<br>    r.flags |= dns.flags.AA<br>    r.flags &= ~dns.flags.RD  # Clear RD<br>    r.flags &= ~dns.flags.RA  # Clear RA<br>    r.answer = []<br>    wire = r.to_wire()<br><br>    now = int(time.time())<br>    wire += struct.pack('>QQ', now, now + 31536000)  # 1 year<br>    return wire<br><br>def make_key(domain: str, qtype: int = 1, qclass: int = 1, secret_seed: str = "mysecretseed2025") -> str:<br>    """<br>    Generate Redis key using SHA256(secret_seed + wire_name + qtype + qclass)<br>    """<br>    import hashlib<br>    import struct<br><br>    if not domain.endswith('.'):<br>        domain += '.'<br>    labels = domain.rstrip('.').split('.')<br>    wire = b''.join(bytes([len(label)]) + label.encode() for label in labels) + b'\x00'<br>    qtype_n = struct.pack('!H', qtype)<br>    qclass_n = struct.pack('!H', qclass)<br>    data = wire + qtype_n + qclass_n + secret_seed.encode()<br>    return hashlib.sha256(data).hexdigest().upper()<br><br>if __name__ == '__main__':<br>    # Test domain<br>    domain = "<a href="http://tulisan.nggonku.xyz">tulisan.nggonku.xyz</a>"<br><br>    # Generate NXDOMAIN response<br>    response_wire = make_minimal_nxdomain(domain)<br>    print(f"Generated NXDOMAIN response for {domain}, {len(response_wire)} bytes")<br><br>    # Generate Redis key<br>    key = make_key(domain)<br>    print(f"Redis key: {key}")<br><br>    # Connect to Redis<br>    r = redis.Redis(host='127.0.0.1', port=6379, db=0, decode_responses=False)<br><br>    # Set in Redis<br>    r.set(key, response_wire)<br>    print(f"Loaded into Redis: {key}")<br><br>    # Optional: Verify<br>    print("\nVerifying from Redis...")<br>    retrieved = r.get(key)<br>    if retrieved:<br>        print(f"Retrieved {len(retrieved)} bytes")<br>        timestamp, expiry = struct.unpack('>QQ', retrieved[-16:])<br>        print(f"Timestamp: {time.ctime(timestamp)}")<br>        print(f"Expiry:    {time.ctime(expiry)}")<br>    else:<br>        print("Not found in Redis")<br>```<br><br>When I dig for my domain name (dig @<a href="http://127.0.0.1">127.0.0.1</a> <a href="http://tulisan.nggonku.xyz">tulisan.nggonku.xyz</a>) , I got this from unbound debug<br><br>```<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] info: 127.0.0.1 <a href="http://tulisan.nggonku.xyz">tulisan.nggonku.xyz</a>. A IN<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: udp request from ip4 127.0.0.1 port 41514 (len 16)<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: mesh_run: start<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: cachedb[module 0] operate: extstate:module_state_initial event:module_event_new<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: redis_lookup of BE0C12BF95D4BA92F06B0F3291977F068DE61AD2161DB013AAC4A6B999877A02<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: redis_lookup found 53 bytes<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: cachedb msg expired<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: cachedb msg adjusted down by -1<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] info: redis ;; ->>HEADER<<- opcode: QUERY, rcode: NXDOMAIN, id: 0<br>                                        ;; flags: qr aa ; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0 <br>                                        ;; QUESTION SECTION:<br>                                        <a href="http://tulisan.nggonku.xyz">tulisan.nggonku.xyz</a>.        IN        A<br>                                        <br>                                        ;; ANSWER SECTION:<br>                                        <br>                                        ;; AUTHORITY SECTION:<br>                                        <br>                                        ;; ADDITIONAL SECTION:<br>                                        ;; MSG SIZE  rcvd: 37<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: mesh_run: cachedb module exit state is module_wait_module<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: validator[module 1] operate: extstate:module_state_initial event:module_event_pass<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] info: validator operate: query <a href="http://tulisan.nggonku.xyz">tulisan.nggonku.xyz</a>. A IN<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: validator: pass to next module<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: mesh_run: validator module exit state is module_wait_module<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: iterator[module 2] operate: extstate:module_state_initial event:module_event_pass<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: process_request: new external request event<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] debug: iter_handle processing q with state INIT REQUEST STATE<br>Sep 10 17:22:05 unbound unbound[25748]: [25748:0] info: resolving <a href="http://tulisan.nggonku.xyz">tulisan.nggonku.xyz</a>. A IN<br><br>```<br><br>Looks like the message "content"  is right, but timestamp/ttl/expiry is wrong.<br>How to write good wire message?<br><br>-wowon-<br></div>