Overview
Comment: | Add the various resource records |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
e473ea9c633945789f5b2de67eb66c44 |
User & Date: | js on 2021-03-03 23:39:43 |
Other Links: | manifest | tags |
Context
2021-03-04
| ||
01:03 | Initial work on sending a query check-in: baf27b579c user: js tags: trunk | |
2021-03-03
| ||
23:39 | Add the various resource records check-in: e473ea9c63 user: js tags: trunk | |
01:29 | Parse resolv.conf check-in: 070b3339e0 user: js tags: trunk | |
Changes
Modified src/resolver.cr from [fe98c6126e] to [e7d4d87a8a].
1 2 3 4 5 6 7 8 9 10 11 12 | require "./settings" module AsyncDNS class Resolver getter :settings setter :settings def initialize @settings = Settings.new end end end | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 | require "./rr" require "./settings" module AsyncDNS class Resolver getter :settings setter :settings def initialize @settings = Settings.new end end end |
Added src/rr.cr version [c7ffec3a5e].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 35 36 37 38 39 40 41 42 43 44 45 46 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | require "socket" module AsyncDNS abstract struct RR property :name, :class, :type, :ttl def initialize(@name : String, @class : DNSClass, @type : RRType, @ttl : Int32) end struct A < RR property :address def initialize(name, @address : Socket::IPAddress, ttl) super(name, DNSClass::IN, RRType::A, ttl) end end struct AAAA < RR property :address def initialize(name, @address : Socket::IPAddress, ttl) super(name, DNSClass::IN, RRType::AAAA, ttl) end end struct CNAME < RR property :alias def initialize(name, @alias : String, ttl) super(name, DNSClass::IN, RRType::CNAME, ttl) end end struct HINFO < RR property :cpu, :os def initialize(name, @cpu : String, @os : String, ttl) super(name, DNSClass::IN, RRType::HINFO, ttl) end end struct MX < RR property :preference, :mx def initialize(name, @preference : UInt16, @mx : String, ttl) super(name, DNSClass::IN, RRType::MX, ttl) end end struct NS < RR property :authority def initialize(name, @authority : String, ttl) super(name, DNSClass::IN, RRType::NS, ttl) end end struct PTR < RR property :domain def initialize(name, @domain : String, ttl) super(name, DNSClass::IN, RRType::PTR, ttl) end end struct RP < RR property :mailbox, :domain def initialize(name, @mailbox : String, @domain : String, ttl) super(name, DNSClass::IN, RRType::RP, ttl) end end struct SOA < RR property :primary_ns, :responsible, :serial, :refresh, :retry, :expire, :min_ttl def initialize(name, @primary_ns : String, @responsible : String, @serial : UInt32, @refresh : UInt32, @retry : UInt32, @expire : UInt32, @min_ttl : UInt32) super(name, DNSClass::IN, RRType::SOA, ttl) end end struct SRV < RR property :prio, :weight, :target, :port def initialize(name, @prio : UInt16, @weight : UInt16, @target : String, @port : UInt16, ttl) super(name, DNSClass::IN, RRType::SRV, ttl) end end struct TXT < RR property :text def initialize(name, @text : Array(String), ttl) super(name, DNSClass::IN, RRType::TXT) end end end end |
Modified src/settings.cr from [9091c56abc] to [24fadd9f43].
|
| < < < < | 1 2 3 4 5 6 7 8 9 10 | module AsyncDNS class Settings @local_domain : String? property static_hosts, nameservers, local_domain, search_domains, uses_tcp getter timeout, max_attempts, abs_num_dots def timeout=(timeout) raise ArgumentError.new("timeout must be positive") if timeout < 0 |
︙ | ︙ | |||
36 37 38 39 40 41 42 43 | @nameservers = [] of String @search_domains = [] of String @timeout = Time::Span.new(seconds: 2) @max_attempts = 3 @abs_num_dots = 1 @uses_tcp = false @reload_period = Time::Span.new(seconds: 2) | > | > > | > > > | | | > > | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | @nameservers = [] of String @search_domains = [] of String @timeout = Time::Span.new(seconds: 2) @max_attempts = 3 @abs_num_dots = 1 @uses_tcp = false @reload_period = Time::Span.new(seconds: 2) @last_reload = Time::Span.zero reload end def reload return if Time.monotonic - @last_reload < @reload_period {% if flag?(:haiku) %} parse_hosts "/system/settings/network/hosts" parse_resolv_conf "/system/settings/network/resolv.conf" {% elsif flag?(:unix) %} parse_hosts "/etc/hosts" parse_resolv_conf "/etc/resolv.conf" {% else %} {% raise "Your OS is not supported by AsyncDNS" %} {% end %} @last_reload = Time.monotonic end def parse_hosts(path) @static_hosts.clear File.each_line(path, chomp: true) do |line| pos = line.index('#') |
︙ | ︙ |
Modified tests/example.cr from [4658a8dbd9] to [b547c51298].
1 2 3 4 5 | require "../src/asyncdns" AsyncDNS::Query.new("crystal-lang.org", AsyncDNS::DNSClass::IN, AsyncDNS::RRType::A) | | | | < < < < < < > | 1 2 3 4 5 6 7 8 9 | require "../src/asyncdns" AsyncDNS::Query.new("crystal-lang.org", AsyncDNS::DNSClass::IN, AsyncDNS::RRType::A) resolver = AsyncDNS::Resolver.new AsyncDNS::RR::A.new("crystal-lang.org", Socket::IPAddress.new("127.0.0.1", 0), 1234) |