ractor_dns 0.3.0 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abb60858b1f6214730ce4d5ac169dc4b03151b94e610575df0b39469f3d81ff7
4
- data.tar.gz: f7cad7e86501e3e194428284ecfa26f86033f3e63654a4cc4782b604d837d564
3
+ metadata.gz: '02339e90260e10f1dd8e76901a10e02e3435fa2e9b0cdde87fd0099a8cb250f4'
4
+ data.tar.gz: cd6d4423d563ce281960bf77659262ffe221e17b84b10f993f5b43ead544584b
5
5
  SHA512:
6
- metadata.gz: b79a3b762b5996b967787f5fdfc1164d5f08cd110c5fc96418dcfd1500d3280d64501f2cea21c2a1c00e3191b351ba9834abe046e6a43459d5b4501379119dac
7
- data.tar.gz: a627088137a11008814c51b95e665798937ca2aac1182d5f7f79ca5c85f2f5040075eb4203a54dddb65f55a4d73171b50fc5016cc2a0d01c5a8ff52975d88cf5
6
+ metadata.gz: 4628cf0965ad76b018466ef3ecba44ef9d1939d5a7c97513d4eb1947e8ef35240a7985afd65fb1169ff4bc31f8ece340ad34027712e0da346709976c4ae8825c
7
+ data.tar.gz: 02a18d6559b4133de18a2115d77cd131c9fb72be31dfec27d06fbe27599e164830da419a66029bd078c5a18497de73c443fb923dfe6caeb602ebafda913385d9
data/README.md CHANGED
@@ -6,15 +6,51 @@ RactorDNS is a work-in-progress concurrent DNS server built with Ruby 3.0 Ractor
6
6
 
7
7
  Install the gem and add to the application's Gemfile by executing:
8
8
 
9
- bundle add ractor_dns
9
+ ```bash
10
+ bundle add ractor_dns
11
+ ```
10
12
 
11
13
  If bundler is not being used to manage dependencies, install the gem by executing:
12
14
 
13
- gem install ractor_dns
15
+ ```bash
16
+ gem install ractor_dns
17
+ ```
14
18
 
15
19
  ## Usage
16
20
 
17
- TODO: Write usage instructions here
21
+ ### Creating a server
22
+
23
+ ```ruby
24
+ server = RactorDNS::Server.new(
25
+ port: 8053,
26
+ authority: ["ns.ractordns.local", 300, RRs::IN::A.new("1.1.1.1")],
27
+ cpu_count: 12,
28
+ zones: {
29
+ "google.com" => [
30
+ {
31
+ name: "google.com",
32
+ ttl: 300,
33
+ rr: RRs::IN::A.new("8.8.8.8")
34
+ },
35
+ {
36
+ name: "test.google.com",
37
+ ttl: 300,
38
+ rr: RRs::IN::A.new("1.1.1.1")
39
+ }
40
+ ]
41
+ }
42
+ )
43
+ ```
44
+
45
+ ### Updating zones
46
+
47
+ ```ruby
48
+ transaction = RactorDNS::Transaction.new do |zones|
49
+ zones["google.com"][0][:rr] = RRs::IN::A.new("2.2.2.2")
50
+ end
51
+
52
+ server.zones.transact transaction
53
+ ```
18
54
 
19
55
  ## Development
20
56
 
@@ -1,6 +1,6 @@
1
1
  class RactorDNS::ActiveZone
2
2
  attr_accessor :server
3
- def initialize(name: "ns.ractordns.local", ttl: 300, ip: "0.0.0.0", server: nil, port: 53, cpu_count: 8, zones:)
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(
5
5
  port:,
6
6
  authority: [name, ttl, RRs::IN::A.new(ip)],
@@ -2,10 +2,10 @@ module RactorDNS
2
2
  class Server
3
3
  attr_reader :authority, :ractor, :zones, :cpu_count, :port
4
4
 
5
- def initialize(authority:, cpu_count:, zones:, port: 53)
5
+ def initialize(authority:, cpu_count:, zones:, port: 8053)
6
6
  @authority = authority
7
7
  @cpu_count = cpu_count
8
- @zones = zones
8
+ @zones = ZoneCollection.new(zones)
9
9
  @port = port
10
10
  end
11
11
 
@@ -23,10 +23,10 @@ module RactorDNS
23
23
  end
24
24
  end
25
25
 
26
- @resolvers = @cpu_count.times.map do
26
+ @resolvers = (@cpu_count ^ 2).times.map do
27
27
  Ractor.new(@pipe, @authority) do |pipe, authority|
28
28
  loop do
29
- data, zone_h = pipe.take
29
+ data, zone_h = Ractor.recv
30
30
 
31
31
  break if data == :stop && zone_h.nil?
32
32
 
@@ -49,16 +49,16 @@ module RactorDNS
49
49
  end
50
50
  end
51
51
  end
52
-
53
- @endpoint = Async::IO::Endpoint.udp('0.0.0.0', @port)
54
52
 
55
53
  @zones.start
56
54
 
57
55
  if here
58
56
  start_main_loop
59
57
  else
60
- @thread = Thread.new do
61
- start_main_loop
58
+ @threads = @cpu_count.times.map do |i|
59
+ Thread.new do
60
+ start_main_loop
61
+ end
62
62
  end
63
63
  end
64
64
 
@@ -69,7 +69,9 @@ module RactorDNS
69
69
 
70
70
  def stop
71
71
  begin
72
- @thread.kill
72
+ @threads.each do |t|
73
+ t.kill
74
+ end
73
75
  @pipe.send(:stop)
74
76
  @zones.stop
75
77
  rescue Ractor::ClosedError
@@ -77,14 +79,16 @@ module RactorDNS
77
79
  end
78
80
  end
79
81
 
80
- def start_main_loop
82
+ def start_main_loop(i = rand(0...@resolvers.length))
81
83
  Async do
82
- @endpoint.bind do |socket|
83
- loop do
84
- data, address = socket.recvfrom(1024)
85
- @pipe.send([data, @zones.freeze])
86
- _, encoded = Ractor.select(*@resolvers)
87
- socket.send(encoded, 0, address)
84
+ @cpu_count.times do
85
+ Async::IO::Endpoint.udp('0.0.0.0', @port).bind do |socket|
86
+ loop do
87
+ data, address = socket.recvfrom(1024)
88
+ @resolvers[i].send([data, @zones.freeze])
89
+ encoded = @resolvers[i].take
90
+ socket.send(encoded, 0, address)
91
+ end
88
92
  end
89
93
  end
90
94
  end
@@ -1,3 +1,3 @@
1
1
  module RactorDNS
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.0"
3
3
  end
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.3.0
4
+ version: 0.5.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-19 00:00:00.000000000 Z
11
+ date: 2024-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport