nl 0.3.0 → 0.4.2

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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/Rakefile +7 -0
  4. data/lib/nl/async/dispatcher.rb +16 -16
  5. data/lib/nl/async/driver.rb +0 -2
  6. data/lib/nl/async/mailbox.rb +0 -2
  7. data/lib/nl/async/operation.rb +0 -2
  8. data/lib/nl/async.rb +0 -2
  9. data/lib/nl/attribute_set.rb +173 -0
  10. data/lib/nl/bitfield32.rb +86 -0
  11. data/lib/nl/blocking_transport.rb +12 -12
  12. data/lib/nl/connection.rb +7 -9
  13. data/lib/nl/datagram.rb +7 -9
  14. data/lib/nl/datatypes.rb +454 -0
  15. data/lib/nl/decoder.rb +4 -0
  16. data/lib/nl/endian.rb +9 -0
  17. data/lib/nl/exchange.rb +40 -18
  18. data/lib/nl/family.rb +50 -55
  19. data/lib/nl/genl/client.rb +105 -0
  20. data/lib/nl/genl/protocol.rb +59 -0
  21. data/lib/nl/genl/wire.rb +95 -0
  22. data/lib/nl/genl.rb +60 -62
  23. data/lib/nl/notification.rb +3 -6
  24. data/lib/nl/notification_router.rb +30 -23
  25. data/lib/nl/raw/client.rb +83 -0
  26. data/lib/nl/raw/protocol.rb +112 -0
  27. data/lib/nl/raw/wire.rb +147 -0
  28. data/lib/nl/raw.rb +104 -0
  29. data/lib/nl/sequence_allocator.rb +0 -2
  30. data/lib/nl/socket.rb +21 -5
  31. data/lib/nl/structured_payload.rb +61 -0
  32. data/lib/nl/sub_message.rb +94 -0
  33. data/lib/nl/version.rb +1 -1
  34. data/lib/nl.rb +5 -6
  35. data/sig/generated/nl/async/dispatcher.rbs +53 -0
  36. data/sig/generated/nl/async/driver.rbs +21 -0
  37. data/sig/generated/nl/async/mailbox.rbs +32 -0
  38. data/sig/generated/nl/async/operation.rbs +123 -0
  39. data/sig/generated/nl/async.rbs +9 -0
  40. data/sig/generated/nl/attribute_set.rbs +50 -0
  41. data/sig/generated/nl/bitfield32.rbs +41 -0
  42. data/sig/generated/nl/blocking_transport.rbs +33 -0
  43. data/sig/generated/nl/connection.rbs +26 -0
  44. data/sig/generated/nl/datagram.rbs +11 -0
  45. data/sig/generated/nl/datatypes.rbs +181 -0
  46. data/sig/generated/nl/decoder.rbs +38 -0
  47. data/sig/generated/nl/encoder.rbs +29 -0
  48. data/sig/generated/nl/endian.rbs +29 -0
  49. data/sig/generated/nl/error.rbs +27 -0
  50. data/sig/generated/nl/exchange.rbs +75 -0
  51. data/sig/generated/nl/family.rbs +89 -0
  52. data/sig/generated/nl/genl/client.rbs +74 -0
  53. data/sig/generated/nl/genl/protocol.rbs +37 -0
  54. data/sig/generated/nl/genl/wire.rbs +113 -0
  55. data/sig/generated/nl/genl.rbs +50 -0
  56. data/sig/generated/nl/notification.rbs +53 -0
  57. data/sig/generated/nl/notification_router.rbs +30 -0
  58. data/sig/generated/nl/raw/client.rbs +49 -0
  59. data/sig/generated/nl/raw/protocol.rbs +122 -0
  60. data/sig/generated/nl/raw/wire.rbs +151 -0
  61. data/sig/generated/nl/raw.rbs +70 -0
  62. data/sig/generated/nl/sequence_allocator.rbs +15 -0
  63. data/sig/generated/nl/socket.rbs +59 -0
  64. data/sig/generated/nl/structured_payload.rbs +25 -0
  65. data/sig/generated/nl/sub_message.rbs +74 -0
  66. data/sig/generated/nl/version.rbs +5 -0
  67. data/sig/generated/nl.rbs +2 -0
  68. metadata +48 -7
  69. data/lib/nl/core.rb +0 -94
  70. data/lib/nl/genl/connection.rb +0 -89
  71. data/lib/nl/protocols/genl.rb +0 -74
  72. data/lib/nl/protocols/raw.rb +0 -460
@@ -0,0 +1,94 @@
1
+ require_relative 'structured_payload'
2
+
3
+ module Nl
4
+ module Selector
5
+ class MissingSelectorValueError < StandardError
6
+ attr_reader :scope, :index
7
+
8
+ def initialize(scope, index)
9
+ @scope = scope
10
+ @index = index
11
+ super()
12
+ end
13
+ end
14
+
15
+ class UnknownSelectorValueError < StandardError
16
+ attr_reader :value
17
+
18
+ def initialize(value)
19
+ @value = value
20
+ super()
21
+ end
22
+ end
23
+
24
+ module Reference
25
+ def select(context, formats)
26
+ value = read(context)
27
+ formats.fetch(value) do
28
+ return yield(value) if block_given?
29
+ raise UnknownSelectorValueError.new(value)
30
+ end
31
+ end
32
+ end
33
+
34
+ Local = Data.define(:index) do
35
+ include Reference
36
+
37
+ def read(context)
38
+ context.fetch_local(index)
39
+ end
40
+ end
41
+
42
+ External = Data.define(:index) do
43
+ include Reference
44
+
45
+ def read(context)
46
+ context.fetch_external(index)
47
+ end
48
+ end
49
+
50
+ class State
51
+ def initialize(local_count, external)
52
+ @local = Array.new(local_count)
53
+ @external = external
54
+ end
55
+
56
+ def set_local(index, value)
57
+ @local[index] = value
58
+ end
59
+
60
+ def fetch_local(index)
61
+ fetch(@local, index) { raise MissingSelectorValueError.new(:local, index) }
62
+ end
63
+
64
+ def fetch_external(index)
65
+ fetch(@external, index) { raise MissingSelectorValueError.new(:external, index) }
66
+ end
67
+
68
+ def fetch(values, key)
69
+ value = values[key]
70
+ value.nil? ? yield : value
71
+ end
72
+ end
73
+ end
74
+
75
+ # A selector-specific payload containing an optional fixed header followed by
76
+ # an optional set of Netlink attributes.
77
+ class SubMessage
78
+ include StructuredPayload
79
+ end
80
+
81
+ # An unrecognized selector-specific payload retained without interpretation.
82
+ class RawSubMessage < SubMessage
83
+ attr_reader :payload, :nlattr_type_flags
84
+
85
+ def initialize(payload, nlattr_type_flags:)
86
+ @payload = payload
87
+ @nlattr_type_flags = nlattr_type_flags
88
+ end
89
+
90
+ def encode(encoder, external_selectors: [])
91
+ encoder.put_string(payload)
92
+ end
93
+ end
94
+ end
data/lib/nl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nl
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.2'
3
3
  end
data/lib/nl.rb CHANGED
@@ -1,13 +1,12 @@
1
1
  require_relative 'nl/error'
2
- require_relative 'nl/core'
2
+ require_relative 'nl/bitfield32'
3
+ require_relative 'nl/raw/wire'
4
+ require_relative 'nl/structured_payload'
5
+ require_relative 'nl/sub_message'
3
6
  require_relative 'nl/notification'
4
7
  require_relative 'nl/connection'
5
8
  require_relative 'nl/family'
9
+ require_relative 'nl/raw'
6
10
  require_relative 'nl/genl'
7
11
  require_relative 'nl/socket'
8
12
  require_relative 'nl/version'
9
-
10
- module Nl
11
- include Core
12
- include Genl
13
- end
@@ -0,0 +1,53 @@
1
+ # Generated from lib/nl/async/dispatcher.rb with RBS::Inline
2
+
3
+ module Nl
4
+ module Async
5
+ # Owns the single receive loop for a socket and routes replies by sequence.
6
+ class Dispatcher
7
+ class Pending < Data
8
+ attr_reader exchange(): untyped
9
+
10
+ attr_reader endpoint(): untyped
11
+
12
+ attr_reader reply_class(): untyped
13
+
14
+ attr_reader sink(): untyped
15
+
16
+ def self.new: (untyped exchange, untyped endpoint, untyped reply_class, untyped sink) -> instance
17
+ | (exchange: untyped, endpoint: untyped, reply_class: untyped, sink: untyped) -> instance
18
+
19
+ def self.members: () -> [ :exchange, :endpoint, :reply_class, :sink ]
20
+
21
+ def members: () -> [ :exchange, :endpoint, :reply_class, :sink ]
22
+ end
23
+
24
+ def initialize: (untyped socket, protocol: untyped, notifications: untyped, ?executor: untyped) -> untyped
25
+
26
+ def exchange: (untyped endpoint, untyped kind, untyped request_class, untyped reply_class, untyped args) ?{ (?) -> untyped } -> untyped
27
+
28
+ def exchange_async: (untyped endpoint, untyped kind, untyped request_class, untyped reply_class, untyped args, ?stream_capacity: untyped) -> untyped
29
+
30
+ def async_capable?: () -> true
31
+
32
+ def receive_notification: (untyped endpoint, ?timeout: untyped) -> untyped
33
+
34
+ def close: () -> untyped
35
+
36
+ private def receive_loop: () -> untyped
37
+
38
+ private def fail_receive_loop: (untyped error) -> untyped
39
+
40
+ private def dispatch_datagram: (untyped buffer) -> untyped
41
+
42
+ private def dispatch_outcome: (untyped key, untyped pending, untyped outcome) -> untyped
43
+
44
+ private def complete_pending: (untyped key, untyped pending, untyped value) -> untyped
45
+
46
+ private def discard: (untyped key) -> untyped
47
+
48
+ private def fail_pending: (untyped key, untyped error) -> untyped
49
+
50
+ private def fail_all: (untyped error) -> untyped
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,21 @@
1
+ # Generated from lib/nl/async/driver.rb with RBS::Inline
2
+
3
+ module Nl
4
+ module Async
5
+ module Drivers
6
+ class Thread
7
+ def start: () ?{ (?) -> untyped } -> untyped
8
+
9
+ def stop: (untyped task) -> untyped
10
+ end
11
+
12
+ class Fiber
13
+ def start: () ?{ (?) -> untyped } -> untyped
14
+
15
+ def stop: (untyped _task) -> untyped
16
+ end
17
+ end
18
+
19
+ def self.driver: (untyped name) -> untyped
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ # Generated from lib/nl/async/mailbox.rb with RBS::Inline
2
+
3
+ module Nl
4
+ module Async
5
+ # A thread-safe, scheduler-aware, single-consumer mailbox.
6
+ class Mailbox
7
+ class FullError < StandardError
8
+ end
9
+
10
+ def initialize: (?capacity: untyped) -> untyped
11
+
12
+ # Adds a value without executing consumer code.
13
+ # @rbs (untyped) -> bool
14
+ def push: (untyped) -> bool
15
+
16
+ # Adds a completion/error event even when the value capacity is full.
17
+ def push_terminal: (untyped value) -> untyped
18
+
19
+ private def push_value: (untyped value, enforce_capacity: untyped) -> untyped
20
+
21
+ # Removes the next value, suspending through the current thread or Fiber scheduler if empty.
22
+ # @rbs (?timeout: Numeric?) -> untyped
23
+ def pop: (?timeout: Numeric?) -> untyped
24
+
25
+ def close: () -> untyped
26
+
27
+ def closed?: () -> untyped
28
+
29
+ def empty?: () -> untyped
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,123 @@
1
+ # Generated from lib/nl/async/operation.rb with RBS::Inline
2
+
3
+ module Nl
4
+ module Async
5
+ module Events
6
+ class Item < Data
7
+ attr_reader value(): untyped
8
+
9
+ def self.new: (untyped value) -> instance
10
+ | (value: untyped) -> instance
11
+
12
+ def self.members: () -> [ :value ]
13
+
14
+ def members: () -> [ :value ]
15
+ end
16
+
17
+ class Done < Data
18
+ def self.new: () -> instance
19
+ | () -> instance
20
+
21
+ def self.members: () -> [ ]
22
+
23
+ def members: () -> [ ]
24
+ end
25
+
26
+ class Error < Data
27
+ attr_reader exception(): untyped
28
+
29
+ def self.new: (untyped exception) -> instance
30
+ | (exception: untyped) -> instance
31
+
32
+ def self.members: () -> [ :exception ]
33
+
34
+ def members: () -> [ :exception ]
35
+ end
36
+ end
37
+
38
+ class ConcurrentConsumptionError < StandardError
39
+ end
40
+
41
+ class StreamOverflowError < StandardError
42
+ end
43
+
44
+ # Future for the result of an already-started, single-reply operation.
45
+ # @rbs generic out Result
46
+ class Future[out Result]
47
+ def self.build: (?mailbox: untyped, ?on_close: untyped) -> untyped
48
+
49
+ def initialize: (mailbox: untyped, on_close: untyped) -> untyped
50
+
51
+ # @rbs (?timeout: Numeric?) -> Result
52
+ def await: (?timeout: Numeric?) -> Result
53
+
54
+ alias value await
55
+
56
+ def ready?: () -> bool
57
+
58
+ # Stops local delivery. The dispatcher still drains the Netlink exchange.
59
+ def close: () -> nil
60
+
61
+ private def settle_done: (untyped value) -> untyped
62
+
63
+ private def settle_failed: (untyped error) -> untyped
64
+
65
+ private def terminal_result: () -> untyped
66
+
67
+ class Sink
68
+ def initialize: (untyped mailbox) -> untyped
69
+
70
+ def succeed: (untyped value) -> untyped
71
+
72
+ def finish: () -> untyped
73
+
74
+ def fail: (untyped exception) -> untyped
75
+ end
76
+ end
77
+
78
+ # Single-pass consumer handle for a multipart Netlink operation.
79
+ # @rbs generic out Item
80
+ class Stream[out Item]
81
+ include Enumerable[Item]
82
+
83
+ def self.build: (?mailbox: untyped, ?on_close: untyped) -> untyped
84
+
85
+ def initialize: (mailbox: untyped, on_close: untyped) -> untyped
86
+
87
+ # @rbs () { (Item) -> void } -> self
88
+ # | () -> Enumerator[Item, self]
89
+ def each: () { (Item) -> void } -> self
90
+ | () -> Enumerator[Item, self]
91
+
92
+ # @rbs (?timeout: Numeric?) -> Item
93
+ def next: (?timeout: Numeric?) -> Item
94
+
95
+ # Stops local delivery. The dispatcher still drains the Netlink exchange.
96
+ def close: () -> nil
97
+
98
+ def closed?: () -> bool
99
+
100
+ private def current_state: () -> untyped
101
+
102
+ private def open?: () -> untyped
103
+
104
+ private def claim_consumer!: () -> untyped
105
+
106
+ private def mark_completed: () -> untyped
107
+
108
+ private def mark_failed: (untyped error) -> untyped
109
+
110
+ private def terminal_result: (?next_item: untyped) -> untyped
111
+
112
+ class Sink
113
+ def initialize: (untyped mailbox) -> untyped
114
+
115
+ def push: (untyped value) -> untyped
116
+
117
+ def finish: () -> untyped
118
+
119
+ def fail: (untyped exception) -> untyped
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,9 @@
1
+ # Generated from lib/nl/async.rb with RBS::Inline
2
+
3
+ module Nl
4
+ # Asynchronous request handling support.
5
+ module Async
6
+ class UnavailableError < StandardError
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,50 @@
1
+ # Generated from lib/nl/attribute_set.rb with RBS::Inline
2
+
3
+ module Nl
4
+ class AttributeSet
5
+ class Attribute < Struct[untyped]
6
+ attr_accessor value(): untyped
7
+
8
+ def self.new: (?untyped value) -> instance
9
+ | (?value: untyped) -> instance
10
+ end
11
+
12
+ class Attribute
13
+ MULTI: bool
14
+
15
+ ORDER: untyped
16
+
17
+ SELECTOR_SLOT: untyped
18
+
19
+ def self.multi?: () -> untyped
20
+
21
+ def self.decode: (untyped decoder, ?context: untyped, ?nlattr_type_flags: untyped) -> untyped
22
+
23
+ def encode: (untyped encoder, ?context: untyped) -> untyped
24
+ end
25
+
26
+ def initialize: (untyped attributes) -> untyped
27
+
28
+ def []: (untyped type) -> untyped
29
+
30
+ def <<: (untyped attr) -> untyped
31
+
32
+ SELECTOR_NAMES: untyped
33
+
34
+ private def encode1: (untyped encoder, untyped attr, untyped context) -> untyped
35
+
36
+ def encode: (untyped encoder, ?external_selectors: untyped) -> untyped
37
+
38
+ private def selector_name: (untyped error) -> untyped
39
+
40
+ private def self.decode1: (untyped decoder, untyped context) -> untyped
41
+
42
+ def self.decode: (untyped decoder, ?external_selectors: untyped) -> untyped
43
+
44
+ def self.build_attributes: (?untyped params, ?external_selectors: untyped, **untyped keywords) -> untyped
45
+
46
+ private def self.coerce: (untyped datatype, untyped value, untyped context) -> untyped
47
+
48
+ private def self.selector_name: (untyped error) -> untyped
49
+ end
50
+ end
@@ -0,0 +1,41 @@
1
+ # Generated from lib/nl/bitfield32.rb with RBS::Inline
2
+
3
+ module Nl
4
+ # A 32-bit value paired with a mask selecting the meaningful bits.
5
+ class Bitfield32
6
+ UINT32_RANGE: untyped
7
+
8
+ # A 32-bit flags
9
+ # @return [Integer]
10
+ attr_reader value: Integer
11
+
12
+ # A 32-bit mask selecting the meaningful bits
13
+ # @return [Integer]
14
+ attr_reader selector: Integer
15
+
16
+ # @param [Integer] value
17
+ # @param [Integer] selector
18
+ # @rbs (Integer value, Integer selector) -> void
19
+ def initialize: (Integer value, Integer selector) -> void
20
+
21
+ # Returns 1 or 0 for a selected bit, or nil for an unselected bit.
22
+ # @param [Integer] index Bits are indexed from the least significant bit, starting at zero.
23
+ # @return [0, 1, nil]
24
+ # @rbs (Integer index) -> (0 | 1 | nil)
25
+ def []: (Integer index) -> (0 | 1 | nil)
26
+
27
+ # Selects and sets or clears a bit. Assigning nil unselects it.
28
+ # @param [Integer] index Bits are indexed from the least significant bit, starting at zero.
29
+ # @param [0, 1, nil] state
30
+ # @rbs (Integer index, (0 | 1 | nil) state) -> (0 | 1 | nil)
31
+ def []=: (Integer index, 0 | 1 | nil state) -> (0 | 1 | nil)
32
+
33
+ # Converts a bit index to a bit mask
34
+ # @rbs (Integer index) -> Integer
35
+ private def bit_mask: (Integer index) -> Integer
36
+
37
+ # Validates if an Integer fits in uint32
38
+ # @rbs (Integer integer, Symbol name) -> void
39
+ private def validate_uint32: (Integer integer, Symbol name) -> void
40
+ end
41
+ end
@@ -0,0 +1,33 @@
1
+ # Generated from lib/nl/blocking_transport.rb with RBS::Inline
2
+
3
+ module Nl
4
+ # Drives one exchange at a time with blocking socket operations.
5
+ class BlockingTransport
6
+ class ConcurrentOperationError < StandardError
7
+ end
8
+
9
+ class UnexpectedSequenceError < StandardError
10
+ attr_reader expected: untyped
11
+
12
+ attr_reader actual: untyped
13
+
14
+ def initialize: (untyped expected, untyped actual) -> untyped
15
+ end
16
+
17
+ def initialize: (untyped socket, protocol: untyped, notifications: untyped) -> untyped
18
+
19
+ def exchange: (untyped endpoint, untyped kind, untyped request_class, untyped reply_class, untyped args) -> untyped
20
+
21
+ def async_capable?: () -> false
22
+
23
+ def receive_notification: (untyped endpoint, ?timeout: untyped) -> untyped
24
+
25
+ def close: () -> void
26
+
27
+ private def receive: (untyped endpoint, untyped expected_key, untyped reply_class) -> untyped
28
+
29
+ private def receive_notifications: () -> untyped
30
+
31
+ private def receive_datagram: () -> untyped
32
+ end
33
+ end
@@ -0,0 +1,26 @@
1
+ # Generated from lib/nl/connection.rb with RBS::Inline
2
+
3
+ module Nl
4
+ # Owns one Netlink socket and the facilities shared by families using it.
5
+ class Connection
6
+ DEFAULT_NOTIFICATION_CAPACITY: ::Integer
7
+
8
+ def initialize: (protocol: untyped, ?executor: untyped, ?notification_capacity: untyped) -> untyped
9
+
10
+ def exchange: () -> untyped
11
+
12
+ def exchange_async: () -> untyped
13
+
14
+ def async_capable?: () -> untyped
15
+
16
+ def register_notifications: (untyped endpoint, untyped classes) -> untyped
17
+
18
+ def add_memberships: (untyped group_ids) -> untyped
19
+
20
+ def drop_memberships: (untyped group_ids) -> untyped
21
+
22
+ def receive_notification: (untyped endpoint, ?timeout: untyped) -> untyped
23
+
24
+ def close: () -> untyped
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ # Generated from lib/nl/datagram.rb with RBS::Inline
2
+
3
+ module Nl
4
+ # Splits Netlink datagrams into aligned header/payload frames.
5
+ module Datagram
6
+ # @rbs (IO::Buffer buffer) { (Raw::NlMsgHdr, IO::Buffer) -> void } -> nil
7
+ # | (IO::Buffer buffer) -> Enumerator[[Raw::NlMsgHdr, IO::Buffer], nil]
8
+ def self.each_frame: (IO::Buffer buffer) { (Raw::NlMsgHdr, IO::Buffer) -> void } -> nil
9
+ | (IO::Buffer buffer) -> Enumerator[[ Raw::NlMsgHdr, IO::Buffer ], nil]
10
+ end
11
+ end