ractor_dns 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ractor_dns/active_zone/railtie.rb +2 -4
- data/lib/ractor_dns/active_zone/zone.rb +25 -0
- data/lib/ractor_dns/active_zone/zone_collection.rb +38 -0
- data/lib/ractor_dns/active_zone.rb +5 -2
- data/lib/ractor_dns/server.rb +10 -4
- data/lib/ractor_dns/transaction.rb +1 -1
- data/lib/ractor_dns/version.rb +1 -1
- data/lib/ractor_dns/zone_collection.rb +20 -2
- data/lib/ractor_dns.rb +3 -5
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0b9397d08074bb1438ea182c5ff2087b56718ebd9cbe18b65005c524a392e06
|
4
|
+
data.tar.gz: 4da6a40911f678aefd63ba7619fac3039a69ec320433a3a7c3ead4876974fe68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 071aaf6b4cf3fee5a7c1270cce98e96f4bbaa781cd8da1c1d4cb9ddc6e006116938e9637ecc452b6f5e95ff19f4b25b9cda805ad482091234cc6cef28373bf5b
|
7
|
+
data.tar.gz: a35e0277b777380d862f45d3d9b9e21745d751c4b7af1828b3cbcb079708e423e1efcd5d45eed2c00af2b9ca4919ab2d415d9982fd652e7559d476f31ee4baf8
|
@@ -1,7 +1,5 @@
|
|
1
1
|
class RactorDNS::ActiveZone::Railtie < Rails::Railtie
|
2
|
-
|
3
|
-
if ActiveZone.provider.is_a? RactorDNS::ActiveZone
|
4
|
-
ActiveZone.provider.start(here: true)
|
5
|
-
end
|
2
|
+
config.to_prepare do
|
3
|
+
ActiveZone.provider.start if ActiveZone.provider.is_a? RactorDNS::ActiveZone
|
6
4
|
end
|
7
5
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class RactorDNS::ActiveZone::Zone < ActiveZone::Provider::Zone
|
2
|
+
def persist!
|
3
|
+
t = RactorDNS::Transaction.new do |zc|
|
4
|
+
zc[name] = resources.map(&:to_h)
|
5
|
+
end
|
6
|
+
|
7
|
+
provider.zones.transact t
|
8
|
+
|
9
|
+
@persisted = true
|
10
|
+
changes_applied
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete!
|
14
|
+
t = RactorDNS::Transaction.new do |zc|
|
15
|
+
zc.delete(name)
|
16
|
+
end
|
17
|
+
provider.zones.transact t
|
18
|
+
@persisted = false
|
19
|
+
freeze
|
20
|
+
end
|
21
|
+
|
22
|
+
def provider
|
23
|
+
@@provider
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class RactorDNS::ActiveZone::ZoneCollection < ActiveZone::Provider::ZoneCollection
|
2
|
+
def find(name)
|
3
|
+
RactorDNS::ActiveZone::Zone.new(resources: provider.zones[name], name: name, persisted: true) if provider.zones[name]
|
4
|
+
end
|
5
|
+
|
6
|
+
def each(&block)
|
7
|
+
if block_given?
|
8
|
+
provider.zones.to_h.keys.filter { |el| @set ? @set.include?(el.name) : true }.each do |zk|
|
9
|
+
block.call(RactorDNS::ActiveZone::Zone.new(resources: provider.zones[zk], name: zk, persisted: true))
|
10
|
+
end
|
11
|
+
else
|
12
|
+
to_enum(:each)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def destroy_all
|
17
|
+
each do |z|
|
18
|
+
z.destroy
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_by(attributes = {})
|
23
|
+
each do |z|
|
24
|
+
broken = false
|
25
|
+
attributes.each do |k, v|
|
26
|
+
if v != z[k]
|
27
|
+
broken = true
|
28
|
+
break
|
29
|
+
end
|
30
|
+
end
|
31
|
+
return z if !broken
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def [](n)
|
36
|
+
RactorDNS::ActiveZone::Zone.new(resources: provider.zones.to_h.values[n], persisted: true, name: provider.zones.to_h.keys[n])
|
37
|
+
end
|
38
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class RactorDNS::ActiveZone
|
1
|
+
class RactorDNS::ActiveZone < ActiveZone::Provider
|
2
2
|
attr_accessor :server
|
3
3
|
def initialize(name: "ns.ractordns.local", ttl: 300, ip: "0.0.0.0", server: nil, port: 8053, cpu_count: 8, zones:)
|
4
4
|
@server = server.presence || RactorDNS::Server.new(
|
@@ -12,4 +12,7 @@ class RactorDNS::ActiveZone
|
|
12
12
|
delegate_missing_to :server
|
13
13
|
end
|
14
14
|
|
15
|
-
require "ractor_dns/active_zone/railtie" if defined?(Rails::Railtie)
|
15
|
+
require "ractor_dns/active_zone/railtie" if defined?(Rails::Railtie)
|
16
|
+
|
17
|
+
require_relative "active_zone/zone" if defined?(ActiveZone::Provider)
|
18
|
+
require_relative "active_zone/zone_collection" if defined?(ActiveZone::Provider)
|
data/lib/ractor_dns/server.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
module RactorDNS
|
2
2
|
class Server
|
3
|
-
attr_reader :authority, :ractor, :zones, :cpu_count, :port
|
3
|
+
attr_reader :authority, :ractor, :zones, :cpu_count, :port, :started
|
4
4
|
|
5
5
|
def initialize(authority:, cpu_count:, zones:, port: 8053)
|
6
6
|
@authority = authority
|
7
7
|
@cpu_count = cpu_count
|
8
8
|
@zones = ZoneCollection.new(zones)
|
9
9
|
@port = port
|
10
|
+
@started = false
|
11
|
+
@threads = []
|
10
12
|
end
|
11
13
|
|
12
14
|
def start(here = false)
|
15
|
+
return if @started
|
13
16
|
@pipe = Ractor.new do
|
14
17
|
loop do
|
15
18
|
recv = Ractor.recv
|
@@ -51,8 +54,9 @@ module RactorDNS
|
|
51
54
|
end
|
52
55
|
|
53
56
|
@zones.start
|
54
|
-
|
57
|
+
|
55
58
|
if here
|
59
|
+
|
56
60
|
start_main_loop
|
57
61
|
else
|
58
62
|
@threads = @cpu_count.times.map do |i|
|
@@ -65,6 +69,8 @@ module RactorDNS
|
|
65
69
|
at_exit do
|
66
70
|
stop
|
67
71
|
end
|
72
|
+
|
73
|
+
@started = true
|
68
74
|
end
|
69
75
|
|
70
76
|
def stop
|
@@ -72,8 +78,8 @@ module RactorDNS
|
|
72
78
|
@threads.each do |t|
|
73
79
|
t.kill
|
74
80
|
end
|
75
|
-
@pipe
|
76
|
-
@zones
|
81
|
+
@pipe&.send(:stop)
|
82
|
+
@zones&.stop
|
77
83
|
rescue Ractor::ClosedError
|
78
84
|
nil
|
79
85
|
end
|
data/lib/ractor_dns/version.rb
CHANGED
@@ -2,7 +2,6 @@ module RactorDNS
|
|
2
2
|
class ZoneCollection
|
3
3
|
def initialize(obj = {})
|
4
4
|
@obj = obj
|
5
|
-
start
|
6
5
|
end
|
7
6
|
|
8
7
|
def start
|
@@ -62,6 +61,9 @@ module RactorDNS
|
|
62
61
|
end
|
63
62
|
|
64
63
|
def transact(transaction)
|
64
|
+
if !transaction.is_a? RactorDNS::Transaction
|
65
|
+
raise "#{transaction.to_s} is not a transaction"
|
66
|
+
end
|
65
67
|
@queue.send([:transact, Ractor.make_shareable(transaction)])
|
66
68
|
@queue.take
|
67
69
|
end
|
@@ -73,6 +75,16 @@ module RactorDNS
|
|
73
75
|
def stop
|
74
76
|
@queue.send([:stop, nil])
|
75
77
|
end
|
78
|
+
|
79
|
+
def inspect
|
80
|
+
begin
|
81
|
+
to_h.inspect
|
82
|
+
rescue
|
83
|
+
"Unable to inspect, try starting the server"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
alias_method :to_s, :inspect
|
76
88
|
end
|
77
89
|
|
78
90
|
class FrozenZoneCollection
|
@@ -88,10 +100,16 @@ module RactorDNS
|
|
88
100
|
if name.nil?
|
89
101
|
return nil
|
90
102
|
end
|
103
|
+
|
91
104
|
if name.is_a? RRs::Name
|
92
105
|
name = name.to_a
|
93
106
|
end
|
94
|
-
|
107
|
+
|
108
|
+
if name.length > 1
|
109
|
+
@obj.dig(name.join(".")).presence || search(name.drop(1))
|
110
|
+
else
|
111
|
+
@obj.dig(name)
|
112
|
+
end
|
95
113
|
end
|
96
114
|
end
|
97
115
|
end
|
data/lib/ractor_dns.rb
CHANGED
@@ -13,8 +13,9 @@ require "async/io/udp_socket"
|
|
13
13
|
|
14
14
|
loader = Zeitwerk::Loader.for_gem
|
15
15
|
loader.inflector = RactorDNS::Inflector.new
|
16
|
-
loader.ignore("#{__dir__}/ractor_dns/active_zone.rb")
|
17
|
-
loader.ignore("#{__dir__}/ractor_dns/active_zone/**/*")
|
16
|
+
loader.ignore("#{__dir__}/ractor_dns/active_zone.rb") if !defined?(ActiveZone)
|
17
|
+
loader.ignore("#{__dir__}/ractor_dns/active_zone/**/*") if !defined?(ActiveZone)
|
18
|
+
loader.ignore("#{__dir__}/ractor_dns/active_zone/railtie.rb") if !defined?(Rails::Railtie)
|
18
19
|
loader.ignore("#{__dir__}/ractor_dns/railtie.rb")
|
19
20
|
loader.ignore("#{__dir__}/ractor_dns/version.rb")
|
20
21
|
loader.setup
|
@@ -23,6 +24,3 @@ module RactorDNS
|
|
23
24
|
class Error < StandardError; end
|
24
25
|
end
|
25
26
|
|
26
|
-
loader.eager_load
|
27
|
-
|
28
|
-
require "ractor_dns/active_zone" if defined?(ActiveZone)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ractor_dns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- reesericci
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -81,6 +81,8 @@ files:
|
|
81
81
|
- lib/ractor_dns.rb
|
82
82
|
- lib/ractor_dns/active_zone.rb
|
83
83
|
- lib/ractor_dns/active_zone/railtie.rb
|
84
|
+
- lib/ractor_dns/active_zone/zone.rb
|
85
|
+
- lib/ractor_dns/active_zone/zone_collection.rb
|
84
86
|
- lib/ractor_dns/inflector.rb
|
85
87
|
- lib/ractor_dns/server.rb
|
86
88
|
- lib/ractor_dns/transaction.rb
|