protocol-quic 0.0.3 → 0.0.5

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 (50) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +4 -2
  3. data/ext/ruby-protocol-quic-lock.yml +2 -2
  4. data/ext/source/Ruby/Protocol/QUIC/Address.cpp +122 -0
  5. data/ext/source/{Protocol → Ruby/Protocol}/QUIC/Address.hpp +5 -5
  6. data/ext/source/Ruby/Protocol/QUIC/Client.cpp +161 -0
  7. data/ext/source/{Protocol → Ruby/Protocol}/QUIC/Client.hpp +3 -3
  8. data/ext/source/Ruby/Protocol/QUIC/Configuration.cpp +74 -0
  9. data/ext/source/{Protocol → Ruby/Protocol}/QUIC/Configuration.hpp +3 -3
  10. data/ext/source/Ruby/Protocol/QUIC/Connection.cpp +50 -0
  11. data/ext/source/{Protocol → Ruby/Protocol}/QUIC/Connection.hpp +4 -4
  12. data/ext/source/Ruby/Protocol/QUIC/Dispatcher.cpp +194 -0
  13. data/ext/source/{Protocol → Ruby/Protocol}/QUIC/Dispatcher.hpp +3 -3
  14. data/ext/source/Ruby/Protocol/QUIC/PacketHeader.cpp +59 -0
  15. data/ext/source/{Protocol → Ruby/Protocol}/QUIC/PacketHeader.hpp +4 -4
  16. data/ext/source/Ruby/Protocol/QUIC/Reference.hpp +35 -0
  17. data/ext/source/Ruby/Protocol/QUIC/Server.cpp +169 -0
  18. data/ext/source/{Protocol → Ruby/Protocol}/QUIC/Server.hpp +3 -3
  19. data/ext/source/Ruby/Protocol/QUIC/Socket.cpp +118 -0
  20. data/ext/source/{Protocol → Ruby/Protocol}/QUIC/Socket.hpp +4 -4
  21. data/ext/source/Ruby/Protocol/QUIC/Stream.cpp +100 -0
  22. data/ext/source/{Protocol → Ruby/Protocol}/QUIC/Stream.hpp +4 -4
  23. data/ext/source/Ruby/Protocol/QUIC/TLS/ClientContext.cpp +61 -0
  24. data/ext/source/{Protocol → Ruby/Protocol}/QUIC/TLS/ClientContext.hpp +3 -3
  25. data/ext/source/Ruby/Protocol/QUIC/TLS/Context.cpp +116 -0
  26. data/ext/source/{Protocol → Ruby/Protocol}/QUIC/TLS/Context.hpp +3 -3
  27. data/ext/source/Ruby/Protocol/QUIC/TLS/ServerContext.cpp +61 -0
  28. data/ext/source/{Protocol → Ruby/Protocol}/QUIC/TLS/ServerContext.hpp +3 -3
  29. data/ext/source/Ruby/Protocol/QUIC.cpp +36 -0
  30. data/ext/source/{Protocol → Ruby/Protocol}/QUIC.hpp +1 -1
  31. data/ext/teapot.rb +1 -1
  32. data/lib/protocol/quic/version.rb +1 -1
  33. data/lib/protocol/quic.rb +1 -1
  34. data.tar.gz.sig +0 -0
  35. metadata +28 -28
  36. metadata.gz.sig +0 -0
  37. data/ext/source/Protocol/QUIC/Address.cpp +0 -122
  38. data/ext/source/Protocol/QUIC/Client.cpp +0 -157
  39. data/ext/source/Protocol/QUIC/Configuration.cpp +0 -74
  40. data/ext/source/Protocol/QUIC/Connection.cpp +0 -50
  41. data/ext/source/Protocol/QUIC/Dispatcher.cpp +0 -190
  42. data/ext/source/Protocol/QUIC/PacketHeader.cpp +0 -59
  43. data/ext/source/Protocol/QUIC/Reference.hpp +0 -31
  44. data/ext/source/Protocol/QUIC/Server.cpp +0 -165
  45. data/ext/source/Protocol/QUIC/Socket.cpp +0 -103
  46. data/ext/source/Protocol/QUIC/Stream.cpp +0 -96
  47. data/ext/source/Protocol/QUIC/TLS/ClientContext.cpp +0 -61
  48. data/ext/source/Protocol/QUIC/TLS/Context.cpp +0 -116
  49. data/ext/source/Protocol/QUIC/TLS/ServerContext.cpp +0 -61
  50. data/ext/source/Protocol/QUIC.cpp +0 -36
@@ -1,165 +0,0 @@
1
-
2
- #include "Server.hpp"
3
-
4
- #include "Dispatcher.hpp"
5
- #include "Configuration.hpp"
6
- #include "Connection.hpp"
7
- #include "TLS/ServerContext.hpp"
8
- #include "Socket.hpp"
9
- #include "Address.hpp"
10
- #include "PacketHeader.hpp"
11
-
12
- #include "Stream.hpp"
13
-
14
- #include <unordered_map>
15
-
16
- VALUE Protocol_QUIC_Server = Qnil;
17
-
18
- class RubyServer : public Protocol::QUIC::Server {
19
- public:
20
- VALUE self;
21
-
22
- private:
23
- VALUE _dispatcher;
24
- VALUE _configuration;
25
- VALUE _tls_context;
26
- VALUE _socket;
27
- VALUE _remote_address;
28
- std::unordered_map<Protocol::QUIC::StreamID, VALUE> _ruby_streams;
29
-
30
- public:
31
- RubyServer(VALUE self, VALUE dispatcher, VALUE configuration, VALUE tls_context, VALUE socket, VALUE remote_address, VALUE packet_header, VALUE ocid) : Protocol::QUIC::Server(*Protocol_QUIC_Dispatcher_get(dispatcher), *Protocol_QUIC_Configuration_get(configuration), *Protocol_QUIC_TLS_ServerContext_get(tls_context), *Protocol_QUIC_Socket_get(socket), *Protocol_QUIC_Address_get(remote_address), *Protocol_QUIC_PacketHeader_get(packet_header), nullptr), self(self), _dispatcher(dispatcher), _configuration(configuration), _tls_context(tls_context), _socket(socket), _remote_address(remote_address) {}
32
- virtual ~RubyServer() {}
33
-
34
- Protocol::QUIC::Stream * create_stream(Protocol::QUIC::StreamID stream_id) override
35
- {
36
- VALUE stream = rb_funcall(self, rb_intern("create_stream"), 1, RB_LL2NUM(stream_id));
37
- _ruby_streams[stream_id] = stream;
38
-
39
- return Protocol_QUIC_Stream_get(stream);
40
- }
41
-
42
- void disconnect() override
43
- {
44
- Protocol::QUIC::Server::disconnect();
45
- _ruby_streams.clear();
46
- }
47
-
48
- void stream_close(Protocol::QUIC::Stream * stream, std::int32_t flags, std::uint64_t error_code) override
49
- {
50
- auto stream_id = stream->stream_id();
51
- Protocol::QUIC::Server::stream_close(stream, flags, error_code);
52
- _ruby_streams.erase(stream_id);
53
- }
54
-
55
- void stream_reset(Protocol::QUIC::Stream * stream, std::size_t final_size, std::uint64_t error_code) override
56
- {
57
- auto stream_id = stream->stream_id();
58
- Protocol::QUIC::Server::stream_reset(stream, final_size, error_code);
59
- _ruby_streams.erase(stream_id);
60
- }
61
-
62
- void mark() {
63
- rb_gc_mark_movable(self);
64
- rb_gc_mark_movable(_dispatcher);
65
- rb_gc_mark_movable(_configuration);
66
- rb_gc_mark_movable(_tls_context);
67
- rb_gc_mark_movable(_socket);
68
- rb_gc_mark_movable(_remote_address);
69
-
70
- for (auto & [stream_id, ruby_stream] : _ruby_streams) {
71
- rb_gc_mark_movable(ruby_stream);
72
- }
73
- }
74
-
75
- void compact() {
76
- self = rb_gc_location(self);
77
- _dispatcher = rb_gc_location(_dispatcher);
78
- _configuration = rb_gc_location(_configuration);
79
- _tls_context = rb_gc_location(_tls_context);
80
- _socket = rb_gc_location(_socket);
81
- _remote_address = rb_gc_location(_remote_address);
82
-
83
- for (auto & [stream_id, ruby_stream] : _ruby_streams) {
84
- ruby_stream = rb_gc_location(ruby_stream);
85
- }
86
- }
87
- };
88
-
89
- static void Protocol_QUIC_Server_mark(void *data)
90
- {
91
- if (data) {
92
- reinterpret_cast<RubyServer *>(data)->mark();
93
- }
94
- }
95
-
96
- static void Protocol_QUIC_Server_compact(void *data)
97
- {
98
- if (data) {
99
- reinterpret_cast<RubyServer *>(data)->compact();
100
- }
101
- }
102
-
103
- static void Protocol_QUIC_Server_free(void *data)
104
- {
105
- if (data) {
106
- delete reinterpret_cast<Protocol::QUIC::Server *>(data);
107
- }
108
- }
109
-
110
- static size_t Protocol_QUIC_Server_size(const void *data) {
111
- return sizeof(RubyServer);
112
- }
113
-
114
- static const rb_data_type_t Protocol_QUIC_Server_type = {
115
- .wrap_struct_name = "Protocol::QUIC::Server",
116
- .function = {
117
- .dmark = Protocol_QUIC_Server_mark,
118
- .dfree = Protocol_QUIC_Server_free,
119
- .dsize = Protocol_QUIC_Server_size,
120
- .dcompact = Protocol_QUIC_Server_compact,
121
- },
122
- .parent = &Protocol_QUIC_Connection_type,
123
- .data = NULL,
124
- .flags = RUBY_TYPED_FREE_IMMEDIATELY,
125
- };
126
-
127
- Protocol::QUIC::Server * Protocol_QUIC_Server_get(VALUE self)
128
- {
129
- Protocol::QUIC::Server *server;
130
-
131
- TypedData_Get_Struct(self, Protocol::QUIC::Server, &Protocol_QUIC_Server_type, server);
132
-
133
- return server;
134
- }
135
-
136
- static VALUE Protocol_QUIC_Server_allocate(VALUE klass) {
137
- return TypedData_Wrap_Struct(klass, &Protocol_QUIC_Server_type, NULL);
138
- }
139
-
140
- // Dispatcher & dispatcher, Configuration & configuration, TLS::ServerContext & tls_context, Socket & socket, const Address & remote_address, const ngtcp2_pkt_hd & packet_header, ngtcp2_cid *ocid = nullptr
141
- static VALUE Protocol_QUIC_Server_initialize(VALUE self, VALUE dispatcher, VALUE configuration, VALUE tls_context, VALUE socket, VALUE remote_address, VALUE packet_header, VALUE ocid) {
142
- Protocol::QUIC::Server *server = new RubyServer(self, dispatcher, configuration, tls_context, socket, remote_address, packet_header, ocid);
143
-
144
- DATA_PTR(self) = server;
145
-
146
- return self;
147
- }
148
-
149
- static VALUE Protocol_QUIC_Server_send_packets(VALUE self) {
150
- Protocol::QUIC::Server *server = Protocol_QUIC_Server_get(self);
151
-
152
- server->send_packets();
153
-
154
- return Qnil;
155
- }
156
-
157
- void Init_Protocol_QUIC_Server(VALUE Protocol_QUIC) {
158
- Protocol_QUIC_Server =
159
- rb_define_class_under(Protocol_QUIC, "Server", rb_cObject);
160
-
161
- rb_define_alloc_func(Protocol_QUIC_Server, Protocol_QUIC_Server_allocate);
162
- rb_define_method(Protocol_QUIC_Server, "initialize", Protocol_QUIC_Server_initialize, 7);
163
-
164
- rb_define_method(Protocol_QUIC_Server, "send_packets", Protocol_QUIC_Server_send_packets, 0);
165
- }
@@ -1,103 +0,0 @@
1
- //
2
- // Socket.cpp
3
- // This file is part of the "Protocol::QUIC" project and released under the MIT License.
4
- //
5
- // Created by Samuel Williams on 27/4/2023.
6
- // Copyright, 2023, by Samuel Williams. All rights reserved.
7
- //
8
-
9
- #include "Socket.hpp"
10
- #include "Address.hpp"
11
-
12
- VALUE Protocol_QUIC_Socket = Qnil;
13
-
14
- static void Protocol_QUIC_Socket_free(void *data) {
15
- if (data) {
16
- delete reinterpret_cast<Protocol::QUIC::Socket *>(data);
17
- }
18
- }
19
-
20
- static size_t Protocol_QUIC_Socket_size(const void *data) {
21
- return sizeof(Protocol::QUIC::Socket);
22
- }
23
-
24
- const rb_data_type_t Protocol_QUIC_Socket_type = {
25
- .wrap_struct_name = "Protocol::QUIC::Socket",
26
- .function = {
27
- .dmark = NULL,
28
- .dfree = Protocol_QUIC_Socket_free,
29
- .dsize = Protocol_QUIC_Socket_size,
30
- },
31
- .data = NULL,
32
- .flags = RUBY_TYPED_FREE_IMMEDIATELY,
33
- };
34
-
35
- Protocol::QUIC::Socket * Protocol_QUIC_Socket_get(VALUE self)
36
- {
37
- Protocol::QUIC::Socket *socket;
38
-
39
- TypedData_Get_Struct(self, Protocol::QUIC::Socket, &Protocol_QUIC_Socket_type, socket);
40
-
41
- return socket;
42
- }
43
-
44
- VALUE Protocol_QUIC_Socket_allocate(VALUE klass) {
45
- return TypedData_Wrap_Struct(klass, &Protocol_QUIC_Socket_type, NULL);
46
- }
47
-
48
- static VALUE Protocol_QUIC_Socket_initialize(VALUE self, VALUE domain, VALUE type, VALUE protocol) {
49
- DATA_PTR(self) = new Protocol::QUIC::Socket(RB_NUM2INT(domain), RB_NUM2INT(type), RB_NUM2INT(protocol));
50
-
51
- return self;
52
- }
53
-
54
- static VALUE Protocol_QUIC_Socket_local_address(VALUE self) {
55
- auto socket = Protocol_QUIC_Socket_get(self);
56
- auto &address = socket->local_address();
57
-
58
- if (address) {
59
- return Protocol_QUIC_Address_wrap(Protocol_QUIC_Address, address);
60
- } else {
61
- return Qnil;
62
- }
63
- }
64
-
65
- static VALUE Protocol_QUIC_Socket_remote_address(VALUE self) {
66
- auto socket = Protocol_QUIC_Socket_get(self);
67
- auto &address = socket->remote_address();
68
-
69
- if (address) {
70
- return Protocol_QUIC_Address_wrap(Protocol_QUIC_Address, address);
71
- } else {
72
- return Qnil;
73
- }
74
- }
75
-
76
- static VALUE Protocol_QUIC_Socket_bind(VALUE self, VALUE address) {
77
- auto socket = Protocol_QUIC_Socket_get(self);
78
-
79
- return RTEST(
80
- socket->bind(*Protocol_QUIC_Address_get(address))
81
- );
82
- }
83
-
84
- static VALUE Protocol_QUIC_Socket_connect(VALUE self, VALUE address) {
85
- auto socket = Protocol_QUIC_Socket_get(self);
86
-
87
- return RTEST(
88
- socket->connect(*Protocol_QUIC_Address_get(address))
89
- );
90
- }
91
-
92
- void Init_Protocol_QUIC_Socket(VALUE Protocol_QUIC) {
93
- Protocol_QUIC_Socket = rb_define_class_under(Protocol_QUIC, "Socket", rb_cObject);
94
-
95
- rb_define_alloc_func(Protocol_QUIC_Socket, Protocol_QUIC_Socket_allocate);
96
- rb_define_method(Protocol_QUIC_Socket, "initialize", Protocol_QUIC_Socket_initialize, 3);
97
-
98
- rb_define_method(Protocol_QUIC_Socket, "local_address", Protocol_QUIC_Socket_local_address, 0);
99
- rb_define_method(Protocol_QUIC_Socket, "remote_address", Protocol_QUIC_Socket_remote_address, 0);
100
-
101
- rb_define_method(Protocol_QUIC_Socket, "bind", Protocol_QUIC_Socket_bind, 1);
102
- rb_define_method(Protocol_QUIC_Socket, "connect", Protocol_QUIC_Socket_connect, 1);
103
- }
@@ -1,96 +0,0 @@
1
- //
2
- // Stream.cpp
3
- // This file is part of the "Protocol::QUIC" project and released under the MIT License.
4
- //
5
- // Created by Samuel Williams on 27/4/2023.
6
- // Copyright, 2023, by Samuel Williams. All rights reserved.
7
- //
8
-
9
- #include "Stream.hpp"
10
- #include "Connection.hpp"
11
- #include <Protocol/QUIC/BufferedStream.hpp>
12
-
13
- VALUE Protocol_QUIC_Stream = Qnil;
14
-
15
- class RubyStream : public Protocol::QUIC::BufferedStream {
16
- public:
17
- VALUE self;
18
-
19
- private:
20
- VALUE _connection;
21
- public:
22
- RubyStream(VALUE self, VALUE connection, VALUE stream_id) : Protocol::QUIC::BufferedStream(*Protocol_QUIC_Connection_get(connection), RB_NUM2LL(stream_id)), self(self), _connection(connection) {}
23
-
24
- virtual ~RubyStream() {}
25
-
26
- void mark() {
27
- rb_gc_mark_movable(self);
28
- rb_gc_mark_movable(_connection);
29
- }
30
-
31
- void compact() {
32
- self = rb_gc_location(self);
33
- _connection = rb_gc_location(_connection);
34
- }
35
- };
36
-
37
- static void Protocol_QUIC_Stream_mark(void *data) {
38
- if (data) {
39
- reinterpret_cast<RubyStream *>(data)->mark();
40
- }
41
- }
42
-
43
- static void Protocol_QUIC_Stream_compact(void *data) {
44
- if (data) {
45
- reinterpret_cast<RubyStream *>(data)->compact();
46
- }
47
- }
48
-
49
- static void Protocol_QUIC_Stream_free(void *data) {
50
- if (data) {
51
- delete reinterpret_cast<RubyStream *>(data);
52
- }
53
- }
54
-
55
- static size_t Protocol_QUIC_Stream_size(const void *data) {
56
- return sizeof(RubyStream);
57
- }
58
-
59
- const rb_data_type_t Protocol_QUIC_Stream_type = {
60
- .wrap_struct_name = "Protocol::QUIC::Stream",
61
- .function = {
62
- .dmark = Protocol_QUIC_Stream_mark,
63
- .dfree = Protocol_QUIC_Stream_free,
64
- .dsize = Protocol_QUIC_Stream_size,
65
- .dcompact = Protocol_QUIC_Stream_compact,
66
- },
67
- .data = NULL,
68
- .flags = RUBY_TYPED_FREE_IMMEDIATELY,
69
- };
70
-
71
- Protocol::QUIC::Stream * Protocol_QUIC_Stream_get(VALUE self)
72
- {
73
- Protocol::QUIC::Stream *address;
74
-
75
- TypedData_Get_Struct(self, Protocol::QUIC::Stream, &Protocol_QUIC_Stream_type, address);
76
-
77
- return address;
78
- }
79
-
80
- VALUE Protocol_QUIC_Stream_allocate(VALUE klass) {
81
- return TypedData_Wrap_Struct(klass, &Protocol_QUIC_Stream_type, NULL);
82
- }
83
-
84
- static VALUE Protocol_QUIC_Stream_initialize(VALUE self, VALUE connection, VALUE stream_id) {
85
- DATA_PTR(self) = new RubyStream(self, connection, stream_id);
86
-
87
- return self;
88
- }
89
-
90
- void Init_Protocol_QUIC_Stream(VALUE Protocol_QUIC) {
91
- Protocol_QUIC_Stream =
92
- rb_define_class_under(Protocol_QUIC, "Stream", rb_cObject);
93
-
94
- rb_define_alloc_func(Protocol_QUIC_Stream, Protocol_QUIC_Stream_allocate);
95
- rb_define_method(Protocol_QUIC_Stream, "initialize", Protocol_QUIC_Stream_initialize, 2);
96
- }
@@ -1,61 +0,0 @@
1
- //
2
- // ClientContext.cpp
3
- // This file is part of the "Protocol::QUIC" project and released under the MIT License.
4
- //
5
- // Created by Samuel Williams on 27/4/2023.
6
- // Copyright, 2023, by Samuel Williams. All rights reserved.
7
- //
8
-
9
- #include "ClientContext.hpp"
10
- #include "Context.hpp"
11
-
12
- VALUE Protocol_QUIC_TLS_ClientContext = Qnil;
13
-
14
- static void Protocol_QUIC_TLS_ClientContext_free(void *data) {
15
- if (data) {
16
- delete reinterpret_cast<Protocol::QUIC::TLS::ClientContext *>(data);
17
- }
18
- }
19
-
20
- static size_t Protocol_QUIC_TLS_ClientContext_size(const void *data) {
21
- return sizeof(Protocol::QUIC::TLS::ClientContext);
22
- }
23
-
24
- static const rb_data_type_t Protocol_QUIC_TLS_ClientContext_type = {
25
- .wrap_struct_name = "Protocol::QUIC::TLS::ClientContext",
26
- .function = {
27
- .dmark = NULL,
28
- .dfree = Protocol_QUIC_TLS_ClientContext_free,
29
- .dsize = Protocol_QUIC_TLS_ClientContext_size,
30
- },
31
- .parent = &Protocol_QUIC_TLS_Context_type,
32
- .data = NULL,
33
- .flags = RUBY_TYPED_FREE_IMMEDIATELY,
34
- };
35
-
36
- Protocol::QUIC::TLS::ClientContext * Protocol_QUIC_TLS_ClientContext_get(VALUE self)
37
- {
38
- Protocol::QUIC::TLS::ClientContext *data;
39
-
40
- TypedData_Get_Struct(self, Protocol::QUIC::TLS::ClientContext, &Protocol_QUIC_TLS_ClientContext_type, data);
41
-
42
- return data;
43
- }
44
-
45
- static VALUE Protocol_QUIC_TLS_ClientContext_allocate(VALUE klass) {
46
- return TypedData_Wrap_Struct(klass, &Protocol_QUIC_TLS_ClientContext_type, NULL);
47
- }
48
-
49
- static VALUE Protocol_QUIC_TLS_ClientContext_initialize(VALUE self) {
50
- DATA_PTR(self) = new Protocol::QUIC::TLS::ClientContext();
51
-
52
- return self;
53
- }
54
-
55
- void Init_Protocol_QUIC_TLS_ClientContext(VALUE Protocol_QUIC_TLS) {
56
- Protocol_QUIC_TLS_ClientContext =
57
- rb_define_class_under(Protocol_QUIC_TLS, "ClientContext", Protocol_QUIC_TLS_Context);
58
-
59
- rb_define_alloc_func(Protocol_QUIC_TLS_ClientContext, Protocol_QUIC_TLS_ClientContext_allocate);
60
- rb_define_method(Protocol_QUIC_TLS_ClientContext, "initialize", Protocol_QUIC_TLS_ClientContext_initialize, 0);
61
- }
@@ -1,116 +0,0 @@
1
- //
2
- // Context.cpp
3
- // This file is part of the "Protocol::QUIC" project and released under the MIT License.
4
- //
5
- // Created by Samuel Williams on 27/4/2023.
6
- // Copyright, 2023, by Samuel Williams. All rights reserved.
7
- //
8
-
9
- #include "Context.hpp"
10
-
11
- #include "ClientContext.hpp"
12
- #include "ServerContext.hpp"
13
-
14
- VALUE Protocol_QUIC_TLS_Context = Qnil;
15
-
16
- static void Protocol_QUIC_TLS_Context_free(void *data) {
17
- if (data) {
18
- delete reinterpret_cast<Protocol::QUIC::TLS::Context *>(data);
19
- }
20
- }
21
-
22
- static size_t Protocol_QUIC_TLS_Context_size(const void *data) {
23
- return sizeof(Protocol::QUIC::TLS::Context);
24
- }
25
-
26
- const rb_data_type_t Protocol_QUIC_TLS_Context_type = {
27
- .wrap_struct_name = "Protocol::QUIC::TLS::Context",
28
- .function = {
29
- .dmark = NULL,
30
- .dfree = Protocol_QUIC_TLS_Context_free,
31
- .dsize = Protocol_QUIC_TLS_Context_size,
32
- },
33
- .data = NULL,
34
- .flags = RUBY_TYPED_FREE_IMMEDIATELY,
35
- };
36
-
37
- Protocol::QUIC::TLS::Context * Protocol_QUIC_TLS_Context_get(VALUE self)
38
- {
39
- Protocol::QUIC::TLS::Context *tls_context;
40
-
41
- TypedData_Get_Struct(self, Protocol::QUIC::TLS::Context, &Protocol_QUIC_TLS_Context_type, tls_context);
42
-
43
- return tls_context;
44
- }
45
-
46
- static VALUE Protocol_QUIC_TLS_Context_allocate(VALUE klass) {
47
- return TypedData_Wrap_Struct(klass, &Protocol_QUIC_TLS_Context_type, NULL);
48
- }
49
-
50
- static VALUE Protocol_QUIC_TLS_Context_initialize(VALUE self) {
51
- DATA_PTR(self) = new Protocol::QUIC::TLS::Context();
52
-
53
- return self;
54
- }
55
-
56
- static VALUE Protocol_QUIC_TLS_Context_add_protocol(VALUE self, VALUE name) {
57
- StringValue(name);
58
-
59
- Protocol::QUIC::TLS::Context *tls_context;
60
- TypedData_Get_Struct(self, Protocol::QUIC::TLS::Context, &Protocol_QUIC_TLS_Context_type, tls_context);
61
-
62
- tls_context->add_protocol(
63
- std::string(RSTRING_PTR(name), RSTRING_LEN(name))
64
- );
65
-
66
- return self;
67
- }
68
-
69
- static VALUE Protocol_QUIC_TLS_Context_load_certificate_file(VALUE self, VALUE path) {
70
- StringValue(path);
71
-
72
- auto tls_context = Protocol_QUIC_TLS_Context_get(self);
73
- tls_context->load_certificate_file(RSTRING_PTR(path));
74
-
75
- return self;
76
- }
77
-
78
- static VALUE Protocol_QUIC_TLS_Context_load_private_key_file(VALUE self, VALUE path) {
79
- StringValue(path);
80
-
81
- auto tls_context = Protocol_QUIC_TLS_Context_get(self);
82
- tls_context->load_private_key_file(RSTRING_PTR(path));
83
-
84
- return self;
85
- }
86
-
87
- static VALUE Protocol_QUIC_TLS_Context_protocols(VALUE self) {
88
- Protocol::QUIC::TLS::Context *tls_context;
89
- TypedData_Get_Struct(self, Protocol::QUIC::TLS::Context, &Protocol_QUIC_TLS_Context_type, tls_context);
90
-
91
- VALUE protocols = rb_ary_new();
92
-
93
- for (auto & protocol : tls_context->protocols()) {
94
- rb_ary_push(protocols, rb_str_new(protocol.data(), protocol.size()));
95
- }
96
-
97
- return protocols;
98
- }
99
-
100
- void Init_Protocol_QUIC_TLS_Context(VALUE Protocol_QUIC) {
101
- VALUE Protocol_QUIC_TLS = rb_define_module_under(Protocol_QUIC, "TLS");
102
-
103
- Protocol_QUIC_TLS_Context =
104
- rb_define_class_under(Protocol_QUIC_TLS, "Context", rb_cObject);
105
-
106
- rb_define_alloc_func(Protocol_QUIC_TLS_Context, Protocol_QUIC_TLS_Context_allocate);
107
- rb_define_method(Protocol_QUIC_TLS_Context, "initialize", Protocol_QUIC_TLS_Context_initialize, 0);
108
-
109
- rb_define_method(Protocol_QUIC_TLS_Context, "add_protocol", Protocol_QUIC_TLS_Context_add_protocol, 1);
110
- rb_define_method(Protocol_QUIC_TLS_Context, "load_certificate_file", Protocol_QUIC_TLS_Context_load_certificate_file, 1);
111
- rb_define_method(Protocol_QUIC_TLS_Context, "load_private_key_file", Protocol_QUIC_TLS_Context_load_private_key_file, 1);
112
- rb_define_method(Protocol_QUIC_TLS_Context, "protocols", Protocol_QUIC_TLS_Context_protocols, 0);
113
-
114
- Init_Protocol_QUIC_TLS_ClientContext(Protocol_QUIC_TLS);
115
- Init_Protocol_QUIC_TLS_ServerContext(Protocol_QUIC_TLS);
116
- }
@@ -1,61 +0,0 @@
1
- //
2
- // ServerContext.cpp
3
- // This file is part of the "Protocol::QUIC" project and released under the MIT License.
4
- //
5
- // Created by Samuel Williams on 27/4/2023.
6
- // Copyright, 2023, by Samuel Williams. All rights reserved.
7
- //
8
-
9
- #include "ServerContext.hpp"
10
- #include "Context.hpp"
11
-
12
- VALUE Protocol_QUIC_TLS_ServerContext = Qnil;
13
-
14
- static void Protocol_QUIC_TLS_ServerContext_free(void *data) {
15
- if (data) {
16
- delete reinterpret_cast<Protocol::QUIC::TLS::ServerContext *>(data);
17
- }
18
- }
19
-
20
- static size_t Protocol_QUIC_TLS_ServerContext_size(const void *data) {
21
- return sizeof(Protocol::QUIC::TLS::ServerContext);
22
- }
23
-
24
- static const rb_data_type_t Protocol_QUIC_TLS_ServerContext_type = {
25
- .wrap_struct_name = "Protocol::QUIC::TLS::ServerContext",
26
- .function = {
27
- .dmark = NULL,
28
- .dfree = Protocol_QUIC_TLS_ServerContext_free,
29
- .dsize = Protocol_QUIC_TLS_ServerContext_size,
30
- },
31
- .parent = &Protocol_QUIC_TLS_Context_type,
32
- .data = NULL,
33
- .flags = RUBY_TYPED_FREE_IMMEDIATELY,
34
- };
35
-
36
- Protocol::QUIC::TLS::ServerContext * Protocol_QUIC_TLS_ServerContext_get(VALUE self)
37
- {
38
- Protocol::QUIC::TLS::ServerContext *data;
39
-
40
- TypedData_Get_Struct(self, Protocol::QUIC::TLS::ServerContext, &Protocol_QUIC_TLS_ServerContext_type, data);
41
-
42
- return data;
43
- }
44
-
45
- static VALUE Protocol_QUIC_TLS_ServerContext_allocate(VALUE klass) {
46
- return TypedData_Wrap_Struct(klass, &Protocol_QUIC_TLS_ServerContext_type, NULL);
47
- }
48
-
49
- static VALUE Protocol_QUIC_TLS_ServerContext_initialize(VALUE self) {
50
- DATA_PTR(self) = new Protocol::QUIC::TLS::ServerContext();
51
-
52
- return self;
53
- }
54
-
55
- void Init_Protocol_QUIC_TLS_ServerContext(VALUE Protocol_QUIC_TLS) {
56
- Protocol_QUIC_TLS_ServerContext =
57
- rb_define_class_under(Protocol_QUIC_TLS, "ServerContext", Protocol_QUIC_TLS_Context);
58
-
59
- rb_define_alloc_func(Protocol_QUIC_TLS_ServerContext, Protocol_QUIC_TLS_ServerContext_allocate);
60
- rb_define_method(Protocol_QUIC_TLS_ServerContext, "initialize", Protocol_QUIC_TLS_ServerContext_initialize, 0);
61
- }
@@ -1,36 +0,0 @@
1
- #include "QUIC.hpp"
2
-
3
- #include "QUIC/Connection.hpp"
4
- #include "QUIC/TLS/Context.hpp"
5
-
6
- #include "QUIC/Address.hpp"
7
- #include "QUIC/Dispatcher.hpp"
8
- #include "QUIC/Configuration.hpp"
9
- #include "QUIC/PacketHeader.hpp"
10
- #include "QUIC/Socket.hpp"
11
-
12
- #include "QUIC/Server.hpp"
13
- #include "QUIC/Client.hpp"
14
- #include "QUIC/Stream.hpp"
15
-
16
- VALUE Protocol_QUIC = Qnil;
17
-
18
- void Init_Protocol_QUIC(void)
19
- {
20
- VALUE Protocol = rb_define_module("Protocol");
21
- Protocol_QUIC = rb_define_module_under(Protocol, "QUIC");
22
-
23
- Init_Protocol_QUIC_TLS_Context(Protocol_QUIC);
24
-
25
- Init_Protocol_QUIC_Address(Protocol_QUIC);
26
- Init_Protocol_QUIC_Dispatcher(Protocol_QUIC);
27
- Init_Protocol_QUIC_Configuration(Protocol_QUIC);
28
- Init_Protocol_QUIC_PacketHeader(Protocol_QUIC);
29
- Init_Protocol_QUIC_Socket(Protocol_QUIC);
30
-
31
- Init_Protocol_QUIC_Connection(Protocol_QUIC);
32
- Init_Protocol_QUIC_Server(Protocol_QUIC);
33
- Init_Protocol_QUIC_Client(Protocol_QUIC);
34
-
35
- Init_Protocol_QUIC_Stream(Protocol_QUIC);
36
- }