@fails-components/webtransport-transport-http3-quiche 1.6.3 → 1.6.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fails-components/webtransport-transport-http3-quiche",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "description": "A component to add webtransport support (server and client) to node.js, transport using libquiche",
5
5
  "exports": {
6
6
  ".": {
@@ -44,7 +44,7 @@
44
44
  "prebuild-install": "^7.1.1"
45
45
  },
46
46
  "devDependencies": {
47
- "@babel/core": "^7.17.10",
47
+ "@babel/core": "^7.29.6",
48
48
  "@babel/eslint-parser": "^7.17.0",
49
49
  "@babel/plugin-syntax-import-attributes": "^7.23.3",
50
50
  "@types/node": "^24.0.1",
@@ -84,7 +84,7 @@ namespace quic
84
84
  const std::string& cert_sct, const std::string& signature,
85
85
  const ProofVerifyContext* context, std::string* error_details,
86
86
  std::unique_ptr<ProofVerifyDetails>* details,
87
- std::unique_ptr<ProofVerifierCallback> callback) {
87
+ std::unique_ptr<ProofVerifierCallback> callback) override {
88
88
  auto env = envg_->getEnv();
89
89
  Napi::HandleScope scope(env);
90
90
 
@@ -114,10 +114,10 @@ namespace quic
114
114
 
115
115
  QuicAsyncStatus VerifyCertChain(
116
116
  const std::string& hostname, const uint16_t port,
117
- const std::vector<std::string>& certs, const std::string& ocsp_response,
117
+ const std::vector<absl::string_view>& certs, const std::string& ocsp_response,
118
118
  const std::string& cert_sct, const ProofVerifyContext* context,
119
119
  std::string* error_details, std::unique_ptr<ProofVerifyDetails>* details,
120
- uint8_t* out_alert, std::unique_ptr<ProofVerifierCallback> callback) {
120
+ uint8_t* out_alert, std::unique_ptr<ProofVerifierCallback> callback) override {
121
121
  auto env = envg_->getEnv();
122
122
  Napi::HandleScope scope(env);
123
123
 
@@ -609,7 +609,8 @@ namespace quic
609
609
  wtsessionobj->init(
610
610
  static_cast<WebTransportSession *>(wtsession));
611
611
  getJS()->processNewClientSession(wtsessionobj);
612
- auto visitor = std::make_unique<Http3WTSession::Visitor>(wtsessionobj);
612
+ auto visitor = std::make_unique<Http3WTSession::Visitor>(wtsessionobj,
613
+ static_cast<Http3ClientSession *>(session_.get()));
613
614
  static_cast<Http3ClientSession *>(session_.get())->AddVisitor(id, visitor.get());
614
615
  wtsession->SetVisitor(std::move(visitor));
615
616
  }
@@ -38,6 +38,12 @@ namespace quic
38
38
  drop_response_body_(drop_response_body),
39
39
  enable_web_transport_(enable_web_transport) {}
40
40
 
41
+ Http3ClientSession::~Http3ClientSession() {
42
+ for (auto itty = svisitors_.begin(); itty != svisitors_.end(); itty++) {
43
+ (*itty).second->RemoveVisitorRemoveVisitor();
44
+ }
45
+ }
46
+
41
47
  std::unique_ptr<QuicSpdyClientStream>
42
48
  Http3ClientSession::CreateClientStream()
43
49
  {
@@ -16,11 +16,12 @@
16
16
 
17
17
  #include "quiche/quic/core/http/quic_spdy_client_session.h"
18
18
  #include "src/http3clientstream.h"
19
+ #include "src/http3wtsessionvisitor.h"
19
20
 
20
21
  namespace quic
21
22
  {
22
23
 
23
- class Http3ClientSession : public QuicSpdyClientSession
24
+ class Http3ClientSession : public QuicSpdyClientSession, public Http3WTSession::VisitorRemoveVisitor
24
25
  {
25
26
  public:
26
27
  Http3ClientSession(const QuicConfig &config,
@@ -35,6 +36,7 @@ namespace quic
35
36
  const QuicServerId &server_id,
36
37
  QuicCryptoClientConfig *crypto_config,
37
38
  bool drop_response_body, bool enable_web_transport);
39
+ ~Http3ClientSession();
38
40
 
39
41
  std::unique_ptr<QuicSpdyClientStream> CreateClientStream() override;
40
42
  WebTransportHttp3VersionSet LocallySupportedWebTransportVersions()
@@ -42,10 +44,15 @@ namespace quic
42
44
  HttpDatagramSupport LocalHttpDatagramSupport() override;
43
45
 
44
46
  void OnCanCreateNewOutgoingStream(bool unidirectional) override;
45
- void AddVisitor(const WebTransportSessionId id, webtransport::SessionVisitor *visitor) {
47
+ void AddVisitor(const WebTransportSessionId id, Http3WTSession::Visitor *visitor) {
46
48
  svisitors_.try_emplace(id, visitor);
47
49
  }
48
50
 
51
+ void RemoveVisitor(Http3WTSession::Visitor* visitor) override {
52
+ absl::erase_if(svisitors_,
53
+ [&](const auto& pair) { return pair.second == visitor; });
54
+ }
55
+
49
56
  void set_on_interim_headers(
50
57
  std::function<void(const quiche::HttpHeaderBlock &)> on_interim_headers)
51
58
  {
@@ -56,7 +63,7 @@ namespace quic
56
63
  std::function<void(const quiche::HttpHeaderBlock &)> on_interim_headers_;
57
64
  const bool drop_response_body_;
58
65
  const bool enable_web_transport_;
59
- absl::flat_hash_map<QuicStreamId, webtransport::SessionVisitor *> svisitors_;
66
+ absl::flat_hash_map<QuicStreamId, Http3WTSession::Visitor *> svisitors_;
60
67
  };
61
68
 
62
69
  } // namespace quic
@@ -11,6 +11,7 @@
11
11
  #include "src/http3server.h"
12
12
  #include "src/http3dispatcher.h"
13
13
  #include "src/http3wtsessionvisitor.h"
14
+ #include "src/http3serversession.h"
14
15
  #include "quiche/quic/core/quic_default_packet_writer.h"
15
16
  #include "quiche/quic/core/quic_default_connection_helper.h"
16
17
  #include "quiche/quic/core/quic_default_clock.h"
@@ -607,7 +608,7 @@ namespace quic
607
608
  Http3WTSession *wtsession = new Http3WTSession();
608
609
  wtsession->init(session);
609
610
  response->visitor =
610
- std::make_unique<Http3WTSession::Visitor>(wtsession);
611
+ std::make_unique<Http3WTSession::Visitor>(wtsession, nullptr);
611
612
  processNewSession(static_cast<Http3WTSession *>(wtsession), path, peer_address,
612
613
  headerValue, userDataValue);
613
614
  (*prom)->resolve(std::move(response));
@@ -85,7 +85,7 @@ namespace quic
85
85
  wtsession->init(session);
86
86
  response->response_headers[":status"] = "200";
87
87
  response->visitor =
88
- std::make_unique<Http3WTSession::Visitor>(wtsession);
88
+ std::make_unique<Http3WTSession::Visitor>(wtsession, nullptr);
89
89
  server_->getJS()->processNewSession(static_cast<Http3WTSession *>(wtsession), path, peer_address.ToString(), nullptr, nullptr);
90
90
  promise->resolve(std::move(response));
91
91
  return promise;
@@ -17,12 +17,12 @@
17
17
  #include "quiche/quic/core/web_transport_interface.h"
18
18
  #include "quiche/common/http/http_header_block.h"
19
19
  #include "quiche/quic/platform/api/quic_socket_address.h"
20
+ #include "src/http3wtsessionvisitor.h"
20
21
 
21
22
  namespace quic
22
23
  {
23
24
 
24
25
  class Http3Server;
25
- class Http3EventLoop;
26
26
 
27
27
  template <typename T>
28
28
  class JSlikePromise
@@ -64,7 +64,7 @@ namespace quic
64
64
  struct WebTransportResponse
65
65
  {
66
66
  quiche::HttpHeaderBlock response_headers;
67
- std::unique_ptr<WebTransportVisitor> visitor;
67
+ std::unique_ptr<Http3WTSession::Visitor> visitor;
68
68
  };
69
69
 
70
70
  using WebTransportRespPromise = JSlikePromise<WebTransportResponse>;
@@ -42,7 +42,12 @@ namespace quic
42
42
  QUICHE_DCHECK(http3_server_backend_);
43
43
  }
44
44
 
45
- Http3ServerSession::~Http3ServerSession() { DeleteConnection(); }
45
+ Http3ServerSession::~Http3ServerSession() {
46
+ DeleteConnection();
47
+ for (auto itty = svisitors_.begin(); itty != svisitors_.end(); itty++) {
48
+ (*itty).second->RemoveVisitorRemoveVisitor();
49
+ }
50
+ }
46
51
 
47
52
  std::unique_ptr<QuicCryptoServerStreamBase>
48
53
  Http3ServerSession::CreateQuicCryptoServerStream(
@@ -29,11 +29,12 @@
29
29
  // #include "quic/tools/quic_backend_response.h"
30
30
  #include "src/http3serverbackend.h"
31
31
  #include "src/http3serverstream.h" // todo
32
+ #include "src/http3wtsessionvisitor.h"
32
33
 
33
34
  namespace quic
34
35
  {
35
36
 
36
- class Http3ServerSession : public QuicServerSessionBase
37
+ class Http3ServerSession : public QuicServerSessionBase, public Http3WTSession::VisitorRemoveVisitor
37
38
  {
38
39
  public:
39
40
  // Takes ownership of |connection|.
@@ -54,10 +55,15 @@ namespace quic
54
55
  void OnStreamFrame(const QuicStreamFrame &frame) override;
55
56
 
56
57
  void OnCanCreateNewOutgoingStream(bool unidirectional) override;
57
- void AddVisitor(const WebTransportSessionId id, webtransport::SessionVisitor *visitor) {
58
+ void AddVisitor(const WebTransportSessionId id, Http3WTSession::Visitor *visitor) {
58
59
  svisitors_.try_emplace(id, visitor);
59
60
  }
60
61
 
62
+ void RemoveVisitor(Http3WTSession::Visitor* visitor) override {
63
+ absl::erase_if(svisitors_,
64
+ [&](const auto& pair) { return pair.second == visitor; });
65
+ }
66
+
61
67
  protected:
62
68
  // QuicSession methods:
63
69
  QuicSpdyStream *CreateIncomingStream(QuicStreamId id) override;
@@ -91,7 +97,7 @@ namespace quic
91
97
  }
92
98
 
93
99
  Http3ServerBackend *http3_server_backend_; // Not owned.
94
- absl::flat_hash_map<QuicStreamId, webtransport::SessionVisitor *> svisitors_;
100
+ absl::flat_hash_map<QuicStreamId, Http3WTSession::Visitor *> svisitors_;
95
101
  };
96
102
 
97
103
  } // namespace quic
@@ -211,7 +211,8 @@ namespace quic
211
211
  {
212
212
  WriteHeaders(std::move(resp->response_headers), false, nullptr);
213
213
  if (resp->visitor != nullptr)
214
- {
214
+ {
215
+ resp->visitor->AddVisitorRemoveVisitor(static_cast<Http3ServerSession *>(session()));
215
216
  static_cast<Http3ServerSession *>(session())->AddVisitor(id(), resp->visitor.get());
216
217
  web_transport()->SetVisitor(std::move(resp->visitor));
217
218
  }
@@ -11,6 +11,9 @@ namespace quic
11
11
  {
12
12
  // printf("Session ~Visitor %d %x %x\n", getpid(), this, session_);
13
13
  Http3WTSessionJS *sessobj = session_->getJS();
14
+ if (vrvis_) {
15
+ vrvis_->RemoveVisitor(this);
16
+ }
14
17
  if (sessobj) {
15
18
  sessobj->Unref();
16
19
  } else
@@ -50,12 +50,33 @@ namespace quic
50
50
  // need to be called immediately after new
51
51
  void init(WebTransportSession *session);
52
52
 
53
- class Visitor : public WebTransportVisitor
54
- {
55
- public:
56
- Visitor(Http3WTSession *session) : session_(session) {}
53
+ class Visitor;
54
+
55
+ class VisitorRemoveVisitor {
56
+ public:
57
+ virtual void RemoveVisitor(Http3WTSession::Visitor* visitor) = 0;
58
+ };
59
+
60
+ class Visitor : public WebTransportVisitor {
61
+ public:
62
+ Visitor(Http3WTSession* session, VisitorRemoveVisitor* vrvis)
63
+ : session_(session), vrvis_(vrvis) {
64
+ /* printf(
65
+ "Session created Visitor %d %x %x\n", getpid(), this, session_);*/
66
+ }
67
+
68
+ ~Visitor();
69
+
70
+ void AddVisitorRemoveVisitor(VisitorRemoveVisitor *vrvis) {
71
+ if (vrvis_) {
72
+ vrvis_->RemoveVisitor(this);
73
+ }
74
+ vrvis_ = vrvis;
75
+ }
57
76
 
58
- ~Visitor();
77
+ void RemoveVisitorRemoveVisitor() {
78
+ vrvis_ = nullptr;
79
+ }
59
80
 
60
81
  void OnSessionReady() override;
61
82
 
@@ -68,19 +89,18 @@ namespace quic
68
89
 
69
90
  void OnDatagramReceived(absl::string_view datagram) override;
70
91
 
71
- void OnCanCreateNewOutgoingBidirectionalStream() override
72
- {
73
- // unclear how we can stich this together?
74
- session_->TrySendingBidirectionalStreams();
75
- }
92
+ void OnCanCreateNewOutgoingBidirectionalStream() override {
93
+ // unclear how we can stich this together?
94
+ session_->TrySendingBidirectionalStreams();
95
+ }
76
96
 
77
- void OnCanCreateNewOutgoingUnidirectionalStream() override
78
- {
79
- session_->TrySendingUnidirectionalStreams();
80
- }
97
+ void OnCanCreateNewOutgoingUnidirectionalStream() override {
98
+ session_->TrySendingUnidirectionalStreams();
99
+ }
81
100
 
82
- protected:
83
- Http3WTSession *session_;
101
+ protected:
102
+ Http3WTSession* session_;
103
+ VisitorRemoveVisitor* vrvis_;
84
104
  };
85
105
 
86
106
  bool
@@ -146,7 +166,6 @@ namespace quic
146
166
  }
147
167
 
148
168
  webtransport::DatagramStatus writeDatagramInt(char *buffer, size_t len, Napi::ObjectReference *bufferhandle);
149
-
150
169
  WebTransportSession *session_;
151
170
  bool echo_stream_opened_ = false;
152
171