Overview
Comment: | Initial response handling |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
7b363d498568c677b8e54d4064476458 |
User & Date: | js on 2021-03-06 22:25:49 |
Other Links: | manifest | tags |
Context
2021-03-06
| ||
22:28 | Fix leftover IO and missing rescue check-in: e71ccf3e48 user: js tags: trunk | |
22:25 | Initial response handling check-in: 7b363d4985 user: js tags: trunk | |
21:34 | Add receive loop check-in: 8c89490d20 user: js tags: trunk | |
Changes
Modified src/query.cr from [8a39ec595d] to [43e4044197].
1 2 3 4 5 6 7 8 9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | - + + + | require "./dns_class" require "./rr_type" module AsyncDNS class Query getter domain : String getter dns_class : DNSClass getter rr_type : RRType |
Modified src/resolver.cr from [e371b89446] to [aab61a4f26].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | + + + + + + + + + + + | require "socket" require "./query" require "./response" require "./rr" require "./settings" # TODO: Cancel timer # TODO: TCP module AsyncDNS class Resolver @v6_sock : UDPSocket? @v4_sock : UDPSocket? getter settings : Settings enum Error NO_NAME_SERVER INVALID_REPLY TRUNCATED SERVER_INVALID_FORMAT SERVER_FAILURE SERVER_NAME_ERROR SERVER_NOT_IMPLEMENTED SERVER_REFUSED UNKNOWN end private class Context getter query : Query getter id : UInt16 getter settings : Settings getter block : Response | Error -> |
︙ | |||
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | + - - + | # QNAME @query.domain.split('.').each do |component| if component.bytesize > 63 || io.size + component.bytesize > 512 raise ArgumentError.new("Domain component too long") end io.write_bytes(component.bytesize.to_u8) io << component end # QTYPE io.write_bytes(@query.rr_type.to_u16, IO::ByteFormat::BigEndian) # QCLASS io.write_bytes(@query.dns_class.to_u16, IO::ByteFormat::BigEndian) @raw_data = io.to_slice end end def initialize @settings = Settings.new @queries = Hash(UInt16, Context).new @tcp_queries = Hash(Socket, Context).new end def resolve(query : Query, &block : Response | Error ->) : Nil |
︙ | |||
90 91 92 93 94 95 96 | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | - | private def send(context : Context) : Nil @queries[context.id] = context ns = context.settings.nameservers[context.ns_index] context.used_ns = used_ns = Socket::IPAddress.new(ns, 53) |
︙ | |||
120 121 122 123 124 125 126 | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | spawn do buf = Bytes.new(0x10000) until sock.closed? begin len, addr = sock.receive(buf) rescue ex : IO::Error |