@10p.io/webtransport-quiche 0.0.0-stage → 20.73.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.
- package/LICENSE +39 -0
- package/LICENSE.chromium +27 -0
- package/LICENSE.envoy +207 -0
- package/README.md +21 -2
- package/lib/clientsocket.js +80 -0
- package/lib/index.js +37 -0
- package/lib/resolve-binary.js +20 -0
- package/lib/serversocket.js +86 -0
- package/lib/socket.js +144 -0
- package/lib/types.ts +32 -0
- package/lib/utils.js +12 -0
- package/package.json +36 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
This packages uses the libraries abseil, boringssl, quiche and zlib,
|
|
2
|
+
these fall under their respective license.
|
|
3
|
+
|
|
4
|
+
Portions of the code of this package, e.g. the platform implementation for libquiche,
|
|
5
|
+
are taken from the Chromium project and libquiche and envoy project.
|
|
6
|
+
Basically for files taken from the Chromium project and libquiche the modfied BSD 3-Clause (see LICENSE.chromium) applies, where for the files taken from the envoy a Apache 2.0 (LICENSE.envoy) applies.
|
|
7
|
+
|
|
8
|
+
For all new files (except FAILS logo) and modifications of the original files the following
|
|
9
|
+
BSD 3-Clause license applies:
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Redistribution and use in source and binary forms, with or without
|
|
13
|
+
modification, are permitted provided that the following conditions are
|
|
14
|
+
met:
|
|
15
|
+
|
|
16
|
+
(1) Redistributions of source code must retain the above copyright
|
|
17
|
+
notice, this list of conditions and the following disclaimer.
|
|
18
|
+
|
|
19
|
+
(2) Redistributions in binary form must reproduce the above copyright
|
|
20
|
+
notice, this list of conditions and the following disclaimer in
|
|
21
|
+
the documentation and/or other materials provided with the
|
|
22
|
+
distribution.
|
|
23
|
+
|
|
24
|
+
(3)The name of the authors, FAILS or contributing organizations
|
|
25
|
+
(company, organsations etc.) may not be used to
|
|
26
|
+
endorse or promote products derived from this software without
|
|
27
|
+
specific prior written permission.
|
|
28
|
+
|
|
29
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
30
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
31
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
32
|
+
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
33
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
34
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
35
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
36
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
37
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
38
|
+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
39
|
+
POSSIBILITY OF SUCH DAMAGE.
|
package/LICENSE.chromium
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright 2015 The Chromium Authors. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Redistribution and use in source and binary forms, with or without
|
|
4
|
+
// modification, are permitted provided that the following conditions are
|
|
5
|
+
// met:
|
|
6
|
+
//
|
|
7
|
+
// * Redistributions of source code must retain the above copyright
|
|
8
|
+
// notice, this list of conditions and the following disclaimer.
|
|
9
|
+
// * Redistributions in binary form must reproduce the above
|
|
10
|
+
// copyright notice, this list of conditions and the following disclaimer
|
|
11
|
+
// in the documentation and/or other materials provided with the
|
|
12
|
+
// distribution.
|
|
13
|
+
// * Neither the name of Google Inc. nor the names of its
|
|
14
|
+
// contributors may be used to endorse or promote products derived from
|
|
15
|
+
// this software without specific prior written permission.
|
|
16
|
+
//
|
|
17
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
18
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
19
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
20
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
21
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
22
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
23
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
24
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
25
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/LICENSE.envoy
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner].
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
© 2022 GitHub, Inc.
|
|
204
|
+
Terms
|
|
205
|
+
Privacy
|
|
206
|
+
Security
|
|
207
|
+
Status
|
package/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @10p.io/webtransport-quiche
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[`@fails-components/webtransport-transport-http3-quiche`](https://github.com/fails-components/webtransport) 1.6.3 の JS をそのまま持ち、
|
|
4
|
+
`lib/index.js` だけを差し替えて `webtransport.node` を platform 別 package (`@10p.io/webtransport-quiche-<platform>-<arch>`) から読む。
|
|
5
|
+
|
|
6
|
+
upstream は install script (`prebuild-install`) で GitHub Release から binary を取るため、依存の install script を走らせない
|
|
7
|
+
bun / pnpm では binary が入らない。この package は install script を持たず、binary は `optionalDependencies` で届く。
|
|
8
|
+
|
|
9
|
+
planx (cli) は npm alias で upstream の名前に差し込む:
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
"@fails-components/webtransport-transport-http3-quiche": "npm:@10p.io/webtransport-quiche@0.0.0-PLACEHOLDER"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 版を上げる
|
|
16
|
+
|
|
17
|
+
1. root `package.json` の upstream (`@fails-components/webtransport*`) を上げる
|
|
18
|
+
2. `scripts/webtransport-quiche/checksums.json` を新しい Release の tarball の sha256 に置き換える
|
|
19
|
+
3. 本 package と 5 つの platform package の `version` / `optionalDependencies`、cli の alias を同じ版にする
|
|
20
|
+
4. platform package 5 つ → 本 package の順に `nx run <project>:deploy`
|
|
21
|
+
|
|
22
|
+
設計: `projects/docs/design/feat/20261023_webtransport-quiche-platform-packages.md`
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createSocket } from 'node:dgram'
|
|
2
|
+
import { lookup } from 'node:dns/promises'
|
|
3
|
+
|
|
4
|
+
import { logger } from './utils.js'
|
|
5
|
+
import { Http3WebTransportSocket } from './socket.js'
|
|
6
|
+
|
|
7
|
+
const log = logger(`webtransport:Http3WebTransportClientSocket(${process.pid})`)
|
|
8
|
+
|
|
9
|
+
export class Http3WebTransportClientSocket extends Http3WebTransportSocket {
|
|
10
|
+
/**
|
|
11
|
+
* @param {import('../../../main/lib/types.js').HttpWebTransportInit} args
|
|
12
|
+
*/
|
|
13
|
+
constructor(args) {
|
|
14
|
+
super(args)
|
|
15
|
+
let port = args?.port
|
|
16
|
+
if (typeof port === 'undefined') port = 443
|
|
17
|
+
this.port = Number(port)
|
|
18
|
+
this.host = args?.host || 'localhost'
|
|
19
|
+
this.localPort = args?.localPort
|
|
20
|
+
this.forceIpv6 = args?.forceIpv6 || false
|
|
21
|
+
/** @type {import('../../../main/lib/session.js').HttpClient} */
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
this.jsobj = undefined // the transport will set this
|
|
24
|
+
|
|
25
|
+
this.args = args
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
init() {
|
|
29
|
+
lookup(this.host)
|
|
30
|
+
.then((result) => {
|
|
31
|
+
this.address = result
|
|
32
|
+
this.cobj.setHostname({
|
|
33
|
+
...this.args,
|
|
34
|
+
serveraddress: result.address,
|
|
35
|
+
port: Number(this.args.port)
|
|
36
|
+
})
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
delete this.args
|
|
39
|
+
this.socketInt = createSocket({
|
|
40
|
+
type: result.family === 4 ? 'udp4' : 'udp6',
|
|
41
|
+
ipv6Only: this.forceIpv6
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
this.socketInt.on('error', (evt) => {
|
|
45
|
+
this.jsobj.onClientError({ errorcode: 100, error: evt.toString() })
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
this.socketInt.on('close', () => {
|
|
49
|
+
//
|
|
50
|
+
})
|
|
51
|
+
this.socketInt.on('message', (msg, rinfo) => {
|
|
52
|
+
this.cobj.recvPaket({
|
|
53
|
+
msg,
|
|
54
|
+
rinfo,
|
|
55
|
+
selfaddress: this.socketInt.address()
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
this.socketInt.bind(this.localPort)
|
|
59
|
+
setImmediate(() => this.cobj.onCanWrite())
|
|
60
|
+
})
|
|
61
|
+
.catch((error) => {
|
|
62
|
+
log('Problem client:', error)
|
|
63
|
+
// hostname not known
|
|
64
|
+
this.jsobj.onClientError({
|
|
65
|
+
errorcode: 100,
|
|
66
|
+
error: 'Problem resolving hostname'
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
closeClient() {
|
|
72
|
+
process.nextTick(() => {
|
|
73
|
+
// TODO call close on all sessions
|
|
74
|
+
this.cobj.closeClientInt()
|
|
75
|
+
// close socket after sending close frames
|
|
76
|
+
this.socketInt.close()
|
|
77
|
+
this.closed = true
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { existsSync } from 'fs'
|
|
2
|
+
import { createRequire } from 'module'
|
|
3
|
+
import * as url from 'url'
|
|
4
|
+
import { arch, platform } from 'node:process'
|
|
5
|
+
import { logger } from './utils.js'
|
|
6
|
+
import { resolveBinary } from './resolve-binary.js'
|
|
7
|
+
|
|
8
|
+
const log = logger(`webtransport:native(${process?.pid})`)
|
|
9
|
+
const require = createRequire(import.meta.url)
|
|
10
|
+
|
|
11
|
+
export const binaryPath = resolveBinary({
|
|
12
|
+
platform,
|
|
13
|
+
arch,
|
|
14
|
+
dirname: url.fileURLToPath(new URL('.', import.meta.url)),
|
|
15
|
+
exists: existsSync,
|
|
16
|
+
resolve: (id) => require.resolve(id)
|
|
17
|
+
})
|
|
18
|
+
log('load webtransport binary:', binaryPath)
|
|
19
|
+
|
|
20
|
+
export const wtrouter = require(binaryPath)
|
|
21
|
+
export const quicheInit = wtrouter.quicheInit
|
|
22
|
+
|
|
23
|
+
let quicheInited = false
|
|
24
|
+
|
|
25
|
+
export const checkQuicheInit = function (args) {
|
|
26
|
+
if (!quicheInited) {
|
|
27
|
+
quicheInit({
|
|
28
|
+
quicheLogVerbose: args?.quicheLogVerbose ? args.quicheLogVerbose : -1
|
|
29
|
+
})
|
|
30
|
+
quicheInited = true
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const Http3WebTransportClient = wtrouter.Http3WebTransportClient
|
|
35
|
+
export const Http3WebTransportServer = wtrouter.Http3WebTransportServer
|
|
36
|
+
export { Http3WebTransportClientSocket } from './clientsocket.js'
|
|
37
|
+
export { Http3WebTransportServerSocket } from './serversocket.js'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as path from 'path'
|
|
2
|
+
|
|
3
|
+
export function resolveBinary({ platform, arch, dirname, exists, resolve }) {
|
|
4
|
+
const pkg = `@10p.io/webtransport-quiche-${platform}-${arch}/webtransport.node`
|
|
5
|
+
try {
|
|
6
|
+
return resolve(pkg)
|
|
7
|
+
} catch (error) {
|
|
8
|
+
if (error?.code !== 'MODULE_NOT_FOUND') throw error
|
|
9
|
+
}
|
|
10
|
+
const local = [
|
|
11
|
+
path.join(dirname, `../build_${platform}_${arch}/Release/webtransport.node`),
|
|
12
|
+
path.join(dirname, '../build/Release/webtransport.node')
|
|
13
|
+
]
|
|
14
|
+
const found = local.find((p) => exists(p))
|
|
15
|
+
if (found) return found
|
|
16
|
+
throw new Error(
|
|
17
|
+
`webtransport.node が見つからない (${platform}-${arch}): ${[pkg, ...local].join(', ')}。` +
|
|
18
|
+
`optionalDependencies の ${pkg.split('/webtransport.node')[0]} が入っているか確認する`
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createSocket } from 'node:dgram'
|
|
2
|
+
import { lookup } from 'node:dns/promises'
|
|
3
|
+
|
|
4
|
+
import { logger } from './utils.js'
|
|
5
|
+
import { Http3WebTransportSocket } from './socket.js'
|
|
6
|
+
|
|
7
|
+
const log = logger(`webtransport:Http3WebTransportServerSocket(${process.pid})`)
|
|
8
|
+
|
|
9
|
+
export class Http3WebTransportServerSocket extends Http3WebTransportSocket {
|
|
10
|
+
/**
|
|
11
|
+
* @param {import('../../../main/lib/types.js').Http3QuicheServerWebTransportInit|undefined} args
|
|
12
|
+
*/
|
|
13
|
+
constructor(args) {
|
|
14
|
+
super(args)
|
|
15
|
+
let port = args?.port
|
|
16
|
+
if (typeof port === 'undefined') port = 443
|
|
17
|
+
this.port = Number(port)
|
|
18
|
+
this.host = args?.host || 'localhost'
|
|
19
|
+
/** @type {import('../../../main/lib/session.js').HttpServer} */
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
this.jsobj = undefined // the transport will set this
|
|
22
|
+
|
|
23
|
+
/** @type {import('node:dns').LookupAddress|undefined} */
|
|
24
|
+
this.address = undefined
|
|
25
|
+
|
|
26
|
+
this.socketOptions = args?.quicheNodeSocketOptions ?? {}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
init() {
|
|
30
|
+
lookup(this.host)
|
|
31
|
+
.then((result) => {
|
|
32
|
+
this.address = result
|
|
33
|
+
this.socketInt = createSocket({
|
|
34
|
+
...{
|
|
35
|
+
type: result.family === 4 ? 'udp4' : 'udp6',
|
|
36
|
+
reuseAddr: true
|
|
37
|
+
},
|
|
38
|
+
...this.socketOptions
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
this.socketInt.on('listening', () => {
|
|
42
|
+
const addr = this.socketInt.address()
|
|
43
|
+
const retObj = {
|
|
44
|
+
port: addr?.port,
|
|
45
|
+
host: addr?.address
|
|
46
|
+
}
|
|
47
|
+
this.jsobj.onServerListening(retObj)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
this.socketInt.on('error', (error) => {
|
|
51
|
+
this.jsobj.onServerError(error)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
this.socketInt.on('close', () => {
|
|
55
|
+
this.jsobj.onServerClose()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
this.socketInt.on('message', (msg, rinfo) => {
|
|
59
|
+
// console.log('srv msg', msg, rinfo)
|
|
60
|
+
const haschlos = this.cobj.recvPaket({
|
|
61
|
+
msg,
|
|
62
|
+
rinfo,
|
|
63
|
+
selfaddress: this.socketInt.address()
|
|
64
|
+
})
|
|
65
|
+
if (!this.chlosSched && haschlos) {
|
|
66
|
+
setImmediate(this.doProcessBufferedChlos)
|
|
67
|
+
this.chlosSched = true
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
this.socketInt.bind(this.port, this.address?.address)
|
|
71
|
+
this.cobj.onCanWrite()
|
|
72
|
+
})
|
|
73
|
+
.catch((error) => {
|
|
74
|
+
log('Problem server:', error)
|
|
75
|
+
// hostname not known
|
|
76
|
+
this.jsobj.onServerError(error)
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
stopServer() {
|
|
81
|
+
this.cobj.destroy()
|
|
82
|
+
this.socketInt.close()
|
|
83
|
+
this.closed = true
|
|
84
|
+
// TODO call close on all sessions
|
|
85
|
+
}
|
|
86
|
+
}
|
package/lib/socket.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { X509Certificate, createVerify } from 'node:crypto'
|
|
2
|
+
import { logger } from './utils.js'
|
|
3
|
+
import { rootCertificates } from 'node:tls'
|
|
4
|
+
const log = logger(`webtransport:Http3WebTransportSocket(${process.pid})`)
|
|
5
|
+
|
|
6
|
+
globalThis.FAILSsetTimeoutAlarm = (
|
|
7
|
+
/** @type {{ fireJS: () => void; }} */ alarm,
|
|
8
|
+
/** @type {number} */ delay
|
|
9
|
+
) => {
|
|
10
|
+
if (delay < 1) {
|
|
11
|
+
return { immediate: setImmediate(alarm.fireJS.bind(alarm)) }
|
|
12
|
+
}
|
|
13
|
+
return { timeout: setTimeout(alarm.fireJS.bind(alarm), delay) }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
globalThis.FAILSclearTimeoutAlarm = (
|
|
17
|
+
/** @type {{ timeout: string | number | NodeJS.Timeout | undefined; immediate: NodeJS.Immediate | undefined; }} */ obj
|
|
18
|
+
) => {
|
|
19
|
+
if (obj.timeout) clearTimeout(obj.timeout)
|
|
20
|
+
if (obj.immediate) clearImmediate(obj.immediate)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function convertToPem(/** @type {ArrayBuffer} */ cert) {
|
|
24
|
+
return (
|
|
25
|
+
'-----BEGIN CERTIFICATE-----\n' +
|
|
26
|
+
Buffer.from(new Uint8Array(cert)).toString('base64') +
|
|
27
|
+
'\n-----END CERTIFICATE-----\n'
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
globalThis.FAILSVerifyProof = (
|
|
32
|
+
/** @type {{ certs: ArrayBuffer[]; hostname: string; server_config?: string; signature?: string; }} */ obj
|
|
33
|
+
) => {
|
|
34
|
+
try {
|
|
35
|
+
console.warn(
|
|
36
|
+
'Non serverCertificateHashes certificate verification is an experimental feature for webtransport node client and not covered by tests and thus may be broken (DO NOT USE IN PRODUCTION)'
|
|
37
|
+
)
|
|
38
|
+
if (obj.certs.length < 1) return false
|
|
39
|
+
const pem = convertToPem(obj.certs[0])
|
|
40
|
+
const leafcert = new X509Certificate(pem)
|
|
41
|
+
if (!leafcert.checkHost(obj.hostname)) return false
|
|
42
|
+
|
|
43
|
+
if (obj.server_config) {
|
|
44
|
+
if (!obj.signature) return false
|
|
45
|
+
const verify = createVerify('SHA256')
|
|
46
|
+
verify.write(obj.server_config)
|
|
47
|
+
verify.end()
|
|
48
|
+
if (!verify.verify(leafcert.publicKey, obj.signature, 'hex')) return false
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const curdate = new Date()
|
|
52
|
+
|
|
53
|
+
if (
|
|
54
|
+
new Date(leafcert.validFrom) > curdate ||
|
|
55
|
+
new Date(leafcert.validTo) < curdate
|
|
56
|
+
)
|
|
57
|
+
return false
|
|
58
|
+
|
|
59
|
+
let curcert = leafcert
|
|
60
|
+
for (let certnum = 1; certnum < obj.certs.length; certnum++) {
|
|
61
|
+
const nextpem = convertToPem(obj.certs[certnum])
|
|
62
|
+
const nextcert = new X509Certificate(nextpem)
|
|
63
|
+
|
|
64
|
+
if (
|
|
65
|
+
new Date(nextcert.validFrom) > curdate ||
|
|
66
|
+
new Date(nextcert.validTo) < curdate
|
|
67
|
+
)
|
|
68
|
+
return false
|
|
69
|
+
|
|
70
|
+
if (!curcert.checkIssued(nextcert)) return false
|
|
71
|
+
if (!curcert.verify(nextcert.publicKey)) return false
|
|
72
|
+
curcert = nextcert
|
|
73
|
+
}
|
|
74
|
+
// curcert must be one of the rootCertificates
|
|
75
|
+
|
|
76
|
+
if (
|
|
77
|
+
!rootCertificates.some((rootCA) => {
|
|
78
|
+
const testCert = new X509Certificate(rootCA)
|
|
79
|
+
if (curcert.checkIssued(testCert)) {
|
|
80
|
+
if (!curcert.verify(testCert.publicKey)) return false
|
|
81
|
+
else return true
|
|
82
|
+
} else return false
|
|
83
|
+
})
|
|
84
|
+
)
|
|
85
|
+
return false
|
|
86
|
+
} catch (error) {
|
|
87
|
+
log('VerifyProof error:', error)
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
return true
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export class Http3WebTransportSocket {
|
|
94
|
+
/**
|
|
95
|
+
* @param {import('../../../main/lib/types.js').HttpWebTransportInit|undefined} args
|
|
96
|
+
*/
|
|
97
|
+
// eslint-disable-next-line no-unused-vars
|
|
98
|
+
constructor(args) {
|
|
99
|
+
/** @type {import('node:dgram').Socket} */
|
|
100
|
+
// @ts-ignore
|
|
101
|
+
this.socketInt = undefined // the transport will set this
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
this.cobj = undefined // the transport will set this
|
|
104
|
+
this.chlosSched = false
|
|
105
|
+
this.packetSendCB = this.packetSendCB.bind(this)
|
|
106
|
+
this.doProcessBufferedChlos = this.doProcessBufferedChlos.bind(this)
|
|
107
|
+
this.blocked = false
|
|
108
|
+
this.closed = false
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
doProcessBufferedChlos() {
|
|
112
|
+
this.cobj.processBufferedChlos()
|
|
113
|
+
this.chlosSched = false
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @param {import('./types').UDPServerSocketSend} args
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
sendPacket({ msg, offset, length, port, address }) {
|
|
121
|
+
if (this.closed) return true
|
|
122
|
+
this.socketInt.send(
|
|
123
|
+
msg, // It seems that we need a copy, so maybe a js side buffer is a better choice, we copy now on c++ side
|
|
124
|
+
offset,
|
|
125
|
+
length,
|
|
126
|
+
port,
|
|
127
|
+
address,
|
|
128
|
+
this.packetSendCB
|
|
129
|
+
)
|
|
130
|
+
const blocked = this.socketInt.getSendQueueCount() > 0
|
|
131
|
+
this.blocked = this.blocked || blocked
|
|
132
|
+
return blocked
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
packetSendCB() {
|
|
136
|
+
if (
|
|
137
|
+
!this.closed &&
|
|
138
|
+
this.socketInt.getSendQueueCount() === 0 &&
|
|
139
|
+
this.blocked
|
|
140
|
+
) {
|
|
141
|
+
this.cobj.onCanWrite()
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
package/lib/types.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
WebTransportOptions
|
|
3
|
+
} from '../../../main/lib/dom'
|
|
4
|
+
|
|
5
|
+
export interface UDPServerSocketSend {
|
|
6
|
+
msg: Uint8Array
|
|
7
|
+
offset: number
|
|
8
|
+
length: number
|
|
9
|
+
port:number
|
|
10
|
+
address: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Logger {
|
|
14
|
+
(formatter: any, ...args: any[]): void
|
|
15
|
+
error: (formatter: any, ...args: any[]) => void
|
|
16
|
+
trace: (formatter: any, ...args: any[]) => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type QUICHE_LOG_OFF = -1
|
|
20
|
+
export type QUICHE_LOG_INFO = 0
|
|
21
|
+
export type QUICHE_LOG_WARNING = 1
|
|
22
|
+
export type QUICHE_LOG_ERROR = 2
|
|
23
|
+
export type QUICHE_LOG_FATAL = 3
|
|
24
|
+
export type QUICHE_LOG = QUICHE_LOG_OFF | QUICHE_LOG_INFO | QUICHE_LOG_WARNING | QUICHE_LOG_ERROR | QUICHE_LOG_FATAL
|
|
25
|
+
|
|
26
|
+
export interface HttpWebTransportInit extends WebTransportOptions {
|
|
27
|
+
host: string
|
|
28
|
+
port: string | number
|
|
29
|
+
quicheLogVerbose?: QUICHE_LOG
|
|
30
|
+
forceIpv6?: boolean
|
|
31
|
+
localPort?: number
|
|
32
|
+
}
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import debug from 'debug'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} name
|
|
5
|
+
* @returns {import('./types').Logger}
|
|
6
|
+
*/
|
|
7
|
+
export function logger(name) {
|
|
8
|
+
return Object.assign(debug(name), {
|
|
9
|
+
error: debug(`${name}:error`),
|
|
10
|
+
trace: process?.env.DEBUG_TRACE ? debug(`${name}:trace`) : () => {}
|
|
11
|
+
})
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@10p.io/webtransport-quiche",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "20.73.0",
|
|
4
|
+
"author": "Nozomu Miyamoto",
|
|
5
|
+
"description": "@fails-components/webtransport-transport-http3-quiche 1.6.3 that loads webtransport.node from per-platform optionalDependencies (no install script)",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"node": "./lib/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"license": "BSD-3-Clause",
|
|
13
|
+
"files": [
|
|
14
|
+
"lib",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"LICENSE.chromium",
|
|
17
|
+
"LICENSE.envoy",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"debug": "^4.3.4"
|
|
22
|
+
},
|
|
23
|
+
"optionalDependencies": {
|
|
24
|
+
"@10p.io/webtransport-quiche-darwin-arm64": "20.73.0",
|
|
25
|
+
"@10p.io/webtransport-quiche-darwin-x64": "20.73.0",
|
|
26
|
+
"@10p.io/webtransport-quiche-linux-x64": "20.73.0",
|
|
27
|
+
"@10p.io/webtransport-quiche-linux-arm64": "20.73.0",
|
|
28
|
+
"@10p.io/webtransport-quiche-win32-x64": "20.73.0"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">= 20"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/nontangent/x_x_machina/tree/develop/packages/@10p.io/webtransport-quiche",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/nontangent/x_x_machina.git"
|
|
37
|
+
}
|
|
38
|
+
}
|