diff --git a/.eslintrc.js b/.eslintrc.js index 010c02be11bcf4..6d7afd31fae5ee 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -258,6 +258,7 @@ module.exports = { 'no-void': 'error', 'no-whitespace-before-property': 'error', 'no-with': 'error', + 'object-curly-newline': 'error', 'object-curly-spacing': ['error', 'always'], 'one-var': ['error', { initialized: 'never' }], 'one-var-declaration-per-line': 'error', diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 47f7380d36ff9c..a0e26501434a4f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -39,7 +39,7 @@ /doc/api/net.md @nodejs/net /lib/dgram.js @nodejs/net /lib/dns.js @nodejs/net -/lib/net.js @nodejs/net @nodejs/quic +/lib/net.js @nodejs/net /lib/internal/dgram.js @nodejs/net /lib/internal/dns/* @nodejs/net /lib/internal/net.js @nodejs/net @@ -59,7 +59,7 @@ /lib/crypto.js @nodejs/crypto /lib/tls.js @nodejs/crypto @nodejs/net /src/node_crypto* @nodejs/crypto -/src/crypto/* @nodejs/crypto @nodejs/quic +/src/crypto/* @nodejs/crypto # http @@ -68,7 +68,7 @@ /lib/_http_* @nodejs/http @nodejs/net /lib/http.js @nodejs/http @nodejs/net /lib/https.js @nodejs/crypto @nodejs/net @nodejs/http -/src/node_http_common* @nodejs/http @nodejs/http2 @nodejs/quic @nodejs/net +/src/node_http_common* @nodejs/http @nodejs/http2 @nodejs/net /src/node_http_parser.cc @nodejs/http @nodejs/net # http2 @@ -80,15 +80,6 @@ /src/node_http2* @nodejs/http2 @nodejs/net /src/node_mem* @nodejs/http2 -# quic - -/deps/ngtcp2/ @nodejs/quic -/deps/nghttp3/ @nodejs/quic -/doc/api/quic.md @nodejs/quic -/lib/internal/quic/ @nodejs/quic -/src/node_bob* @nodejs/quic -/src/quic/ @nodejs/quic - # modules /doc/api/modules.md @nodejs/modules diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 2a021723e6f5df..d3e1e4339245af 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -14,7 +14,7 @@ env: FLAKY_TESTS: dontcare jobs: - build-windows-with-quic: + build-windows: if: github.event.pull_request.draft == false runs-on: windows-latest steps: @@ -28,4 +28,4 @@ jobs: - name: Environment Information run: npx envinfo - name: Build - run: ./vcbuild.bat experimental-quic + run: ./vcbuild.bat diff --git a/.github/workflows/test-asan.yml b/.github/workflows/test-asan.yml index 7df02293fb84a9..9e6192c32a37e9 100644 --- a/.github/workflows/test-asan.yml +++ b/.github/workflows/test-asan.yml @@ -37,4 +37,4 @@ jobs: - name: Build run: make build-ci -j2 V=1 - name: Test - run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions" + run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions -t 300" diff --git a/.github/workflows/test-linux.yml b/.github/workflows/test-linux.yml index 9d9b007b8f6f91..41968139816c38 100644 --- a/.github/workflows/test-linux.yml +++ b/.github/workflows/test-linux.yml @@ -29,19 +29,3 @@ jobs: run: make build-ci -j2 V=1 CONFIG_FLAGS="--error-on-warn" - name: Test run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions" - - test-linux-with-quic: - if: github.event.pull_request.draft == false - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ env.PYTHON_VERSION }} - uses: actions/setup-python@v2 - with: - python-version: ${{ env.PYTHON_VERSION }} - - name: Environment Information - run: npx envinfo - - name: Build - run: make build-ci -j2 V=1 CONFIG_FLAGS="--error-on-warn --experimental-quic" - - name: Test - run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions" diff --git a/.github/workflows/test-macos.yml b/.github/workflows/test-macos.yml index a476e6a08c5fc6..462e2ea35b478f 100644 --- a/.github/workflows/test-macos.yml +++ b/.github/workflows/test-macos.yml @@ -14,7 +14,7 @@ env: FLAKY_TESTS: dontcare jobs: - test-macOS-with-quic: + test-macOS: if: github.event.pull_request.draft == false runs-on: macos-latest steps: @@ -26,6 +26,6 @@ jobs: - name: Environment Information run: npx envinfo - name: Build - run: make build-ci -j2 V=1 CONFIG_FLAGS="--error-on-warn --experimental-quic" + run: make build-ci -j2 V=1 CONFIG_FLAGS="--error-on-warn" - name: Test run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions" diff --git a/BUILDING.md b/BUILDING.md index 6d9b26377de83f..44f56a5ba23854 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -218,10 +218,9 @@ Supported platforms and toolchains change with each major version of Node.js. This document is only valid for the current major version of Node.js. Consult previous versions of this document for older versions of Node.js: -* [Node.js 13](https://github.com/nodejs/node/blob/v13.x/BUILDING.md) +* [Node.js 14](https://github.com/nodejs/node/blob/v14.x/BUILDING.md) * [Node.js 12](https://github.com/nodejs/node/blob/v12.x/BUILDING.md) * [Node.js 10](https://github.com/nodejs/node/blob/v10.x/BUILDING.md) -* [Node.js 8](https://github.com/nodejs/node/blob/v8.x/BUILDING.md) ## Building Node.js on supported platforms diff --git a/CHANGELOG.md b/CHANGELOG.md index 838185a57b307e..4079b2f21294ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,8 @@ release. -15.7.0
+15.8.0
+15.7.0
15.6.0
15.5.1
15.5.0
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c9f8b61cd14430..8f75199a52cd8c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,24 +33,24 @@ See [details on our policy on Code of Conduct](./doc/guides/contributing/code-of By making a contribution to this project, I certify that: -* (a) The contribution was created in whole or in part by me and I - have the right to submit it under the open source license - indicated in the file; or - -* (b) The contribution is based upon previous work that, to the best - of my knowledge, is covered under an appropriate open source - license and I have the right under that license to submit that - work with modifications, whether created in whole or in part - by me, under the same open source license (unless I am - permitted to submit under a different license), as indicated - in the file; or - -* (c) The contribution was provided directly to me by some other - person who certified (a), (b) or (c) and I have not modified - it. - -* (d) I understand and agree that this project and the contribution - are public and that a record of the contribution (including all - personal information I submit with it, including my sign-off) is - maintained indefinitely and may be redistributed consistent with - this project or the open source license(s) involved. + (a) The contribution was created in whole or in part by me and I + have the right to submit it under the open source license + indicated in the file; or + + (b) The contribution is based upon previous work that, to the best + of my knowledge, is covered under an appropriate open source + license and I have the right under that license to submit that + work with modifications, whether created in whole or in part + by me, under the same open source license (unless I am + permitted to submit under a different license), as indicated + in the file; or + + (c) The contribution was provided directly to me by some other + person who certified (a), (b) or (c) and I have not modified + it. + + (d) I understand and agree that this project and the contribution + are public and that a record of the contribution (including all + personal information I submit with it, including my sign-off) is + maintained indefinitely and may be redistributed consistent with + this project or the open source license(s) involved. diff --git a/LICENSE b/LICENSE index 2d4040e537adad..a62f3ad825834e 100644 --- a/LICENSE +++ b/LICENSE @@ -1333,58 +1333,6 @@ The externally maintained libraries used by Node.js are: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -- ngtcp2, located at deps/ngtcp2, is licensed as follows: - """ - The MIT License - - Copyright (c) 2016 ngtcp2 contributors - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - """ - -- nghttp3, located at deps/nghttp3, is licensed as follows: - """ - The MIT License - - Copyright (c) 2019 nghttp3 contributors - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - """ - - node-inspect, located at deps/node-inspect, is licensed as follows: """ Copyright Node.js contributors. All rights reserved. diff --git a/README.md b/README.md index 563c5a54118f07..4528a77c292502 100644 --- a/README.md +++ b/README.md @@ -355,6 +355,8 @@ For information about the governance of the Node.js project, see **Luigi Pinca** <luigipinca@gmail.com> (he/him) * [lundibundi](https://github.com/lundibundi) - **Denys Otrishko** <shishugi@gmail.com> (he/him) +* [Lxxyx](https://github.com/Lxxyx) - +**Zijian Liu** <lxxyxzj@gmail.com> (he/him) * [mafintosh](https://github.com/mafintosh) - **Mathias Buus** <mathiasbuus@gmail.com> (he/him) * [mcollina](https://github.com/mcollina) - diff --git a/benchmark/compare.R b/benchmark/compare.R index 7a0c89af3de4c5..bd851e9876a4c3 100644 --- a/benchmark/compare.R +++ b/benchmark/compare.R @@ -35,14 +35,14 @@ if (!is.null(plot.filename)) { ggsave(plot.filename, p); } -# computes the shared standard error, as used in the welch t-test +# Computes the shared standard error, as used in Welch's t-test. welch.sd = function (old.rate, new.rate) { old.se.squared = var(old.rate) / length(old.rate) new.se.squared = var(new.rate) / length(new.rate) return(sqrt(old.se.squared + new.se.squared)) } -# calculate the improvement confidence interval. The improvement is calculated +# Calculate the improvement confidence interval. The improvement is calculated # by dividing by old.mu and not new.mu, because old.mu is what the mean # improvement is calculated relative to. confidence.interval = function (shared.se, old.mu, w, risk) { @@ -50,7 +50,7 @@ confidence.interval = function (shared.se, old.mu, w, risk) { return(sprintf("±%.2f%%", (interval / old.mu) * 100)) } -# Print a table with results +# Calculate the statistics table. statistics = ddply(dat, "name", function(subdat) { old.rate = subset(subdat, binary == "old")$rate; new.rate = subset(subdat, binary == "new")$rate; @@ -68,14 +68,14 @@ statistics = ddply(dat, "name", function(subdat) { "(***)" = "NA" ); - # Check if there is enough data to calculate the calculate the p-value + # Check if there is enough data to calculate the p-value. if (length(old.rate) > 1 && length(new.rate) > 1) { - # Perform a statistics test to see of there actually is a difference in + # Perform a statistical test to see if there actually is a difference in # performance. w = t.test(rate ~ binary, data=subdat); shared.se = welch.sd(old.rate, new.rate) - # Add user friendly stars to the table. There should be at least one star + # Add user-friendly stars to the table. There should be at least one star # before you can say that there is an improvement. confidence = ''; if (w$p.value < 0.001) { @@ -99,7 +99,7 @@ statistics = ddply(dat, "name", function(subdat) { }); -# Set the benchmark names as the row.names to left align them in the print +# Set the benchmark names as the row.names to left align them in the print. row.names(statistics) = statistics$name; statistics$name = NULL; @@ -108,7 +108,7 @@ print(statistics); cat("\n") cat(sprintf( "Be aware that when doing many comparisons the risk of a false-positive -result increases. In this case there are %d comparisons, you can thus +result increases. In this case, there are %d comparisons, you can thus expect the following amount of false-positive results: %.2f false positives, when considering a 5%% risk acceptance (*, **, ***), %.2f false positives, when considering a 1%% risk acceptance (**, ***), diff --git a/benchmark/compare.js b/benchmark/compare.js index 5c9cd03be3fdee..169948e006d660 100644 --- a/benchmark/compare.js +++ b/benchmark/compare.js @@ -56,7 +56,7 @@ for (const filename of benchmarks) { // queue.length = binary.length * runs * benchmarks.length // Print csv header -console.log('"binary", "filename", "configuration", "rate", "time"'); +console.log('"binary","filename","configuration","rate","time"'); const kStartOfQueue = 0; @@ -85,8 +85,8 @@ if (showProgress) { // Escape quotes (") for correct csv formatting conf = conf.replace(/"/g, '""'); - console.log(`"${job.binary}", "${job.filename}", "${conf}", ` + - `${data.rate}, ${data.time}`); + console.log(`"${job.binary}","${job.filename}","${conf}",` + + `${data.rate},${data.time}`); if (showProgress) { // One item in the subqueue has been completed. progress.completeConfig(data); diff --git a/benchmark/fixtures/coverage-many-branches.js b/benchmark/fixtures/coverage-many-branches.js new file mode 100644 index 00000000000000..9cb6360336e019 --- /dev/null +++ b/benchmark/fixtures/coverage-many-branches.js @@ -0,0 +1,115 @@ +'use strict'; + +// Exercise coverage of a class. Note, this logic is silly and exists solely +// to generate branch coverage code paths: +class CoveredClass { + constructor(x, y, opts) { + this.x = x; + this.y = y; + // Exercise coverage of nullish coalescing: + this.opts = opts ?? (Math.random() > 0.5 ? {} : undefined); + } + add() { + return this.x + this.y; + } + addSpecial() { + // Exercise coverage of optional chains: + if (this.opts?.special && this.opts?.special?.x && this.opts?.special?.y) { + return this.opts.special.x + this.opts.special.y; + } + return add(); + } + mult() { + return this.x * this.y; + } + multSpecial() { + if (this.opts?.special && this.opts?.special?.x && this.opts?.special?.y) { + return this.opts.special.x * this.opts.special.y; + } + return mult(); + } +} + +// Excercise coverage of functions: +function add(x, y) { + const mt = new CoveredClass(x, y); + return mt.add(); +} + +function addSpecial(x, y) { + let mt; + if (Math.random() > 0.5) { + mt = new CoveredClass(x, y); + } else { + mt = new CoveredClass(x, y, { + special: { + x: Math.random() * x, + y: Math.random() * y + } + }); + } + return mt.addSpecial(); +} + +function mult(x, y) { + const mt = new CoveredClass(x, y); + return mt.mult(); +} + +function multSpecial(x, y) { + let mt; + if (Math.random() > 0.5) { + mt = new CoveredClass(x, y); + } else { + mt = new CoveredClass(x, y, { + special: { + x: Math.random() * x, + y: Math.random() * y + } + }); + } + return mt.multSpecial(); +} + +for (let i = 0; i < parseInt(process.env.N); i++) { + const operations = ['add', 'addSpecial', 'mult', 'multSpecial']; + for (const operation of operations) { + // Exercise coverage of switch statements: + switch (operation) { + case 'add': + if (add(Math.random() * 10, Math.random() * 10) > 10) { + // Exercise coverage of ternary operations: + let r = addSpecial(Math.random() * 10, Math.random() * 10) > 10 ? + mult(Math.random() * 10, Math.random() * 10) : + add(Math.random() * 10, Math.random() * 10); + // Exercise && and || + if (r && Math.random() > 0.5 || Math.random() < 0.5) r++; + } + break; + case 'addSpecial': + if (addSpecial(Math.random() * 10, Math.random() * 10) > 10 && + add(Math.random() * 10, Math.random() * 10) > 10) { + let r = mult(Math.random() * 10, Math.random() * 10) > 10 ? + add(Math.random() * 10, Math.random() * 10) > 10 : + mult(Math.random() * 10, Math.random() * 10); + if (r && Math.random() > 0.5 || Math.random() < 0.5) r++; + } + break; + case 'mult': + if (mult(Math.random() * 10, Math.random() * 10) > 10) { + let r = multSpecial(Math.random() * 10, Math.random() * 10) > 10 ? + add(Math.random() * 10, Math.random() * 10) : + mult(Math.random() * 10, Math.random() * 10); + if (r && Math.random() > 0.5 || Math.random() < 0.5) r++; + } + break; + case 'multSpecial': + while (multSpecial(Math.random() * 10, Math.random() * 10) < 10) { + mult(Math.random() * 10, Math.random() * 10); + } + break; + default: + break; + } + } +} diff --git a/benchmark/process/coverage.js b/benchmark/process/coverage.js new file mode 100644 index 00000000000000..3dc0cbe52b4c0d --- /dev/null +++ b/benchmark/process/coverage.js @@ -0,0 +1,32 @@ +// This benchmark is meant to exercise a grab bag of code paths that would +// be expected to run slower under coverage. +'use strict'; + +const common = require('../common.js'); +const bench = common.createBenchmark(main, { + n: [1e5] +}); +const path = require('path'); +const { rmSync } = require('fs'); +const { spawnSync } = require('child_process'); +const tmpdir = require('../../test/common/tmpdir'); + +const coverageDir = path.join(tmpdir.path, `./cov-${Date.now()}`); + +function main({ n }) { + bench.start(); + const result = spawnSync(process.execPath, [ + require.resolve('../fixtures/coverage-many-branches'), + ], { + env: { + NODE_V8_COVERAGE: coverageDir, + N: n, + ...process.env + } + }); + bench.end(n); + rmSync(coverageDir, { recursive: true, force: true }); + if (result.status !== 0) { + throw new Error(result.stderr.toString('utf8')); + } +} diff --git a/configure.py b/configure.py index 8ed8524b26667e..096d40a13abe91 100755 --- a/configure.py +++ b/configure.py @@ -122,12 +122,6 @@ default=None, help='Turn compiler warnings into errors for node core sources.') -parser.add_argument('--experimental-quic', - action='store_true', - dest='experimental_quic', - default=None, - help='enable experimental quic support') - parser.add_argument('--gdb', action='store_true', dest='gdb', @@ -289,50 +283,6 @@ dest='shared_nghttp2_libpath', help='a directory to search for the shared nghttp2 DLLs') -shared_optgroup.add_argument('--shared-ngtcp2', - action='store_true', - dest='shared_ngtcp2', - default=None, - help='link to a shared ngtcp2 DLL instead of static linking') - -shared_optgroup.add_argument('--shared-ngtcp2-includes', - action='store', - dest='shared_ngtcp2_includes', - help='directory containing ngtcp2 header files') - -shared_optgroup.add_argument('--shared-ngtcp2-libname', - action='store', - dest='shared_ngtcp2_libname', - default='ngtcp2', - help='alternative lib name to link to [default: %(default)s]') - -shared_optgroup.add_argument('--shared-ngtcp2-libpath', - action='store', - dest='shared_ngtcp2_libpath', - help='a directory to search for the shared ngtcp2 DLLs') - -shared_optgroup.add_argument('--shared-nghttp3', - action='store_true', - dest='shared_nghttp3', - default=None, - help='link to a shared nghttp3 DLL instead of static linking') - -shared_optgroup.add_argument('--shared-nghttp3-includes', - action='store', - dest='shared_nghttp3_includes', - help='directory containing nghttp3 header files') - -shared_optgroup.add_argument('--shared-nghttp3-libname', - action='store', - dest='shared_nghttp3_libname', - default='nghttp3', - help='alternative lib name to link to [default: %(default)s]') - -shared_optgroup.add_argument('--shared-nghttp3-libpath', - action='store', - dest='shared_nghttp3_libpath', - help='a directory to search for the shared nghttp3 DLLs') - shared_optgroup.add_argument('--shared-openssl', action='store_true', dest='shared_openssl', @@ -1290,14 +1240,6 @@ def configure_node(o): else: o['variables']['debug_nghttp2'] = 'false' - if options.experimental_quic: - if options.shared_openssl: - raise Exception('QUIC requires a modified version of OpenSSL and ' - 'cannot be enabled when using --shared-openssl.') - o['variables']['experimental_quic'] = 1 - else: - o['variables']['experimental_quic'] = 'false' - o['variables']['node_no_browser_globals'] = b(options.no_browser_globals) o['variables']['node_shared'] = b(options.shared) @@ -1421,8 +1363,6 @@ def without_ssl_error(option): without_ssl_error('--openssl-fips') if options.openssl_default_cipher_list: without_ssl_error('--openssl-default-cipher-list') - if options.experimental_quic: - without_ssl_error('--experimental-quic') return if options.use_openssl_ca_store: diff --git a/deps/nghttp3/COPYING b/deps/nghttp3/COPYING deleted file mode 100644 index 37562ea58cd74c..00000000000000 --- a/deps/nghttp3/COPYING +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License - -Copyright (c) 2019 nghttp3 contributors - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deps/nghttp3/lib/includes/config.h b/deps/nghttp3/lib/includes/config.h deleted file mode 100644 index 0aee7749bae78e..00000000000000 --- a/deps/nghttp3/lib/includes/config.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Edited to match src/node.h. */ -#include - -#ifdef _WIN32 -#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED) -typedef intptr_t ssize_t; -# define _SSIZE_T_ -# define _SSIZE_T_DEFINED -#endif -#else // !_WIN32 -# include // size_t, ssize_t -#endif // _WIN32 - -#ifdef _MSC_VER -# include -# define __builtin_popcount __popcnt -#endif - -/* Define to 1 to enable debug output. */ -/* #undef DEBUGBUILD */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_ARPA_INET_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_STDDEF_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_UNISTD_H */ diff --git a/deps/nghttp3/lib/includes/nghttp3/nghttp3.h b/deps/nghttp3/lib/includes/nghttp3/nghttp3.h deleted file mode 100644 index 3ace46856b70cc..00000000000000 --- a/deps/nghttp3/lib/includes/nghttp3/nghttp3.h +++ /dev/null @@ -1,1801 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2018 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2017 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_H -#define NGHTTP3_H - -/* Define WIN32 when build target is Win32 API (borrowed from - libcurl) */ -#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) -# define WIN32 -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#if defined(_MSC_VER) && (_MSC_VER < 1800) -/* MSVC < 2013 does not have inttypes.h because it is not C99 - compliant. See compiler macros and version number in - https://sourceforge.net/p/predef/wiki/Compilers/ */ -# include -#else /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */ -# include -#endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */ -#include -#include -#include - -#include - -#ifdef NGHTTP3_STATICLIB -# define NGHTTP3_EXTERN -#elif defined(WIN32) -# ifdef BUILDING_NGHTTP3 -# define NGHTTP3_EXTERN __declspec(dllexport) -# else /* !BUILDING_NGHTTP3 */ -# define NGHTTP3_EXTERN __declspec(dllimport) -# endif /* !BUILDING_NGHTTP3 */ -#else /* !defined(WIN32) */ -# ifdef BUILDING_NGHTTP3 -# define NGHTTP3_EXTERN __attribute__((visibility("default"))) -# else /* !BUILDING_NGHTTP3 */ -# define NGHTTP3_EXTERN -# endif /* !BUILDING_NGHTTP3 */ -#endif /* !defined(WIN32) */ - -typedef ptrdiff_t nghttp3_ssize; - -/* NGHTTP3_ALPN_H3 is a serialized form of HTTP/3 ALPN protocol - identifier this library supports. Notice that the first byte is - the length of the following protocol identifier. */ -#define NGHTTP3_ALPN_H3 "\x5h3-29" - -typedef enum { - NGHTTP3_ERR_INVALID_ARGUMENT = -101, - NGHTTP3_ERR_NOBUF = -102, - NGHTTP3_ERR_INVALID_STATE = -103, - NGHTTP3_ERR_WOULDBLOCK = -104, - NGHTTP3_ERR_STREAM_IN_USE = -105, - NGHTTP3_ERR_PUSH_ID_BLOCKED = -106, - NGHTTP3_ERR_MALFORMED_HTTP_HEADER = -107, - NGHTTP3_ERR_REMOVE_HTTP_HEADER = -108, - NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING = -109, - NGHTTP3_ERR_TOO_LATE = -110, - NGHTTP3_ERR_QPACK_FATAL = -111, - NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE = -112, - NGHTTP3_ERR_IGNORE_STREAM = -113, - NGHTTP3_ERR_STREAM_NOT_FOUND = -114, - NGHTTP3_ERR_IGNORE_PUSH_PROMISE = -115, - NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED = -402, - NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR = -403, - NGHTTP3_ERR_QPACK_DECODER_STREAM_ERROR = -404, - NGHTTP3_ERR_H3_FRAME_UNEXPECTED = -408, - NGHTTP3_ERR_H3_FRAME_ERROR = -409, - NGHTTP3_ERR_H3_MISSING_SETTINGS = -665, - NGHTTP3_ERR_H3_INTERNAL_ERROR = -667, - NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM = -668, - NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR = -669, - NGHTTP3_ERR_H3_ID_ERROR = -670, - NGHTTP3_ERR_H3_SETTINGS_ERROR = -671, - NGHTTP3_ERR_H3_STREAM_CREATION_ERROR = -672, - NGHTTP3_ERR_FATAL = -900, - NGHTTP3_ERR_NOMEM = -901, - NGHTTP3_ERR_CALLBACK_FAILURE = -902 -} nghttp3_lib_error; - -#define NGHTTP3_H3_NO_ERROR 0x0100 -#define NGHTTP3_H3_GENERAL_PROTOCOL_ERROR 0x0101 -#define NGHTTP3_H3_INTERNAL_ERROR 0x0102 -#define NGHTTP3_H3_STREAM_CREATION_ERROR 0x0103 -#define NGHTTP3_H3_CLOSED_CRITICAL_STREAM 0x0104 -#define NGHTTP3_H3_FRAME_UNEXPECTED 0x0105 -#define NGHTTP3_H3_FRAME_ERROR 0x0106 -#define NGHTTP3_H3_EXCESSIVE_LOAD 0x0107 -#define NGHTTP3_H3_ID_ERROR 0x0108 -#define NGHTTP3_H3_SETTINGS_ERROR 0x0109 -#define NGHTTP3_H3_MISSING_SETTINGS 0x010a -#define NGHTTP3_H3_REQUEST_REJECTED 0x010b -#define NGHTTP3_H3_REQUEST_CANCELLED 0x010c -#define NGHTTP3_H3_REQUEST_INCOMPLETE 0x010d -#define NGHTTP3_H3_CONNECT_ERROR 0x010f -#define NGHTTP3_H3_VERSION_FALLBACK 0x0110 -#define NGHTTP3_QPACK_DECOMPRESSION_FAILED 0x0200 -#define NGHTTP3_QPACK_ENCODER_STREAM_ERROR 0x0201 -#define NGHTTP3_QPACK_DECODER_STREAM_ERROR 0x0202 - -/** - * @functypedef - * - * Custom memory allocator to replace malloc(). The |mem_user_data| - * is the mem_user_data member of :type:`nghttp3_mem` structure. - */ -typedef void *(*nghttp3_malloc)(size_t size, void *mem_user_data); - -/** - * @functypedef - * - * Custom memory allocator to replace free(). The |mem_user_data| is - * the mem_user_data member of :type:`nghttp3_mem` structure. - */ -typedef void (*nghttp3_free)(void *ptr, void *mem_user_data); - -/** - * @functypedef - * - * Custom memory allocator to replace calloc(). The |mem_user_data| - * is the mem_user_data member of :type:`nghttp3_mem` structure. - */ -typedef void *(*nghttp3_calloc)(size_t nmemb, size_t size, void *mem_user_data); - -/** - * @functypedef - * - * Custom memory allocator to replace realloc(). The |mem_user_data| - * is the mem_user_data member of :type:`nghttp3_mem` structure. - */ -typedef void *(*nghttp3_realloc)(void *ptr, size_t size, void *mem_user_data); - -/** - * @struct - * - * Custom memory allocator functions and user defined pointer. The - * |mem_user_data| member is passed to each allocator function. This - * can be used, for example, to achieve per-session memory pool. - * - * In the following example code, ``my_malloc``, ``my_free``, - * ``my_calloc`` and ``my_realloc`` are the replacement of the - * standard allocators ``malloc``, ``free``, ``calloc`` and - * ``realloc`` respectively:: - * - * void *my_malloc_cb(size_t size, void *mem_user_data) { - * return my_malloc(size); - * } - * - * void my_free_cb(void *ptr, void *mem_user_data) { my_free(ptr); } - * - * void *my_calloc_cb(size_t nmemb, size_t size, void *mem_user_data) { - * return my_calloc(nmemb, size); - * } - * - * void *my_realloc_cb(void *ptr, size_t size, void *mem_user_data) { - * return my_realloc(ptr, size); - * } - * - * void conn_new() { - * nghttp3_mem mem = {NULL, my_malloc_cb, my_free_cb, my_calloc_cb, - * my_realloc_cb}; - * - * ... - * } - */ -typedef struct { - /** - * An arbitrary user supplied data. This is passed to each - * allocator function. - */ - void *mem_user_data; - /** - * Custom allocator function to replace malloc(). - */ - nghttp3_malloc malloc; - /** - * Custom allocator function to replace free(). - */ - nghttp3_free free; - /** - * Custom allocator function to replace calloc(). - */ - nghttp3_calloc calloc; - /** - * Custom allocator function to replace realloc(). - */ - nghttp3_realloc realloc; -} nghttp3_mem; - -/** - * @function - * - * `nghttp3_mem_default` returns the default memory allocator which - * uses malloc/calloc/realloc/free. - */ -NGHTTP3_EXTERN const nghttp3_mem *nghttp3_mem_default(void); - -/** - * @struct - * - * nghttp3_vec is struct iovec compatible structure to reference - * arbitrary array of bytes. - */ -typedef struct { - /** - * base points to the data. - */ - uint8_t *base; - /** - * len is the number of bytes which the buffer pointed by base - * contains. - */ - size_t len; -} nghttp3_vec; - -struct nghttp3_rcbuf; - -/** - * @struct - * - * :type:`nghttp3_rcbuf` is the object representing reference counted - * buffer. The details of this structure are intentionally hidden - * from the public API. - */ -typedef struct nghttp3_rcbuf nghttp3_rcbuf; - -/** - * @function - * - * `nghttp3_rcbuf_incref` increments the reference count of |rcbuf| by - * 1. - */ -NGHTTP3_EXTERN void nghttp3_rcbuf_incref(nghttp3_rcbuf *rcbuf); - -/** - * @function - * - * `nghttp3_rcbuf_decref` decrements the reference count of |rcbuf| by - * 1. If the reference count becomes zero, the object pointed by - * |rcbuf| will be freed. In this case, application must not use - * |rcbuf| again. - */ -NGHTTP3_EXTERN void nghttp3_rcbuf_decref(nghttp3_rcbuf *rcbuf); - -/** - * @function - * - * `nghttp3_rcbuf_get_buf` returns the underlying buffer managed by - * |rcbuf|. - */ -NGHTTP3_EXTERN nghttp3_vec nghttp3_rcbuf_get_buf(const nghttp3_rcbuf *rcbuf); - -/** - * @function - * - * `nghttp3_rcbuf_is_static` returns nonzero if the underlying buffer - * is statically allocated, and 0 otherwise. This can be useful for - * language bindings that wish to avoid creating duplicate strings for - * these buffers. - */ -NGHTTP3_EXTERN int nghttp3_rcbuf_is_static(const nghttp3_rcbuf *rcbuf); - -/** - * @struct - * - * :type:`nghttp3_buf` is the variable size buffer. - */ -typedef struct { - /** - * begin points to the beginning of the buffer. - */ - uint8_t *begin; - /** - * end points to the one beyond of the last byte of the buffer - */ - uint8_t *end; - /** - * pos pointers to the start of data. Typically, this points to the - * point that next data should be read. Initially, it points to - * |begin|. - */ - uint8_t *pos; - /** - * last points to the one beyond of the last data of the buffer. - * Typically, new data is written at this point. Initially, it - * points to |begin|. - */ - uint8_t *last; -} nghttp3_buf; - -/** - * @function - * - * `nghttp3_buf_init` initializes empty |buf|. - */ -NGHTTP3_EXTERN void nghttp3_buf_init(nghttp3_buf *buf); - -/** - * @function - * - * `nghttp3_buf_free` frees resources allocated for |buf| using |mem| - * as memory allocator. buf->begin must be a heap buffer allocated by - * |mem|. - */ -NGHTTP3_EXTERN void nghttp3_buf_free(nghttp3_buf *buf, const nghttp3_mem *mem); - -/** - * @function - * - * `nghttp3_buf_left` returns the number of additional bytes which can - * be written to the underlying buffer. In other words, it returns - * buf->end - buf->last. - */ -NGHTTP3_EXTERN size_t nghttp3_buf_left(const nghttp3_buf *buf); - -/** - * @function - * - * `nghttp3_buf_len` returns the number of bytes left to read. In - * other words, it returns buf->last - buf->pos. - */ -NGHTTP3_EXTERN size_t nghttp3_buf_len(const nghttp3_buf *buf); - -/** - * @function - * - * `nghttp3_buf_reset` sets buf->pos and buf->last to buf->begin. - */ -NGHTTP3_EXTERN void nghttp3_buf_reset(nghttp3_buf *buf); - -/** - * @enum - * - * :type:`nghttp3_nv_flag` is the flags for header field name/value - * pair. - */ -typedef enum { - /** - * :enum:`NGHTTP3_NV_FLAG_NONE` indicates no flag set. - */ - NGHTTP3_NV_FLAG_NONE = 0, - /** - * :enum:`NGHTTP3_NV_FLAG_NEVER_INDEX` indicates that this - * name/value pair must not be indexed. Other implementation calls - * this bit as "sensitive". - */ - NGHTTP3_NV_FLAG_NEVER_INDEX = 0x01, - /** - * :enum:`NGHTTP3_NV_FLAG_NO_COPY_NAME` is set solely by - * application. If this flag is set, the library does not make a - * copy of header field name. This could improve performance. - */ - NGHTTP3_NV_FLAG_NO_COPY_NAME = 0x02, - /** - * :enum:`NGHTTP3_NV_FLAG_NO_COPY_VALUE` is set solely by - * application. If this flag is set, the library does not make a - * copy of header field value. This could improve performance. - */ - NGHTTP3_NV_FLAG_NO_COPY_VALUE = 0x04 -} nghttp3_nv_flag; - -/** - * @struct - * - * :type:`nghttp3_nv` is the name/value pair, which mainly used to - * represent header fields. - */ -typedef struct { - /** - * name is the header field name. - */ - uint8_t *name; - /** - * value is the header field value. - */ - uint8_t *value; - /** - * namelen is the length of the |name|, excluding terminating NULL. - */ - size_t namelen; - /** - * valuelen is the length of the |value|, excluding terminating - * NULL. - */ - size_t valuelen; - /** - * flags is bitwise OR of one or more of :type:`nghttp3_nv_flag`. - */ - uint8_t flags; -} nghttp3_nv; - -/* Generated by mkstatichdtbl.py */ -typedef enum { - NGHTTP3_QPACK_TOKEN__AUTHORITY = 0, - NGHTTP3_QPACK_TOKEN__PATH = 8, - NGHTTP3_QPACK_TOKEN_AGE = 43, - NGHTTP3_QPACK_TOKEN_CONTENT_DISPOSITION = 52, - NGHTTP3_QPACK_TOKEN_CONTENT_LENGTH = 55, - NGHTTP3_QPACK_TOKEN_COOKIE = 68, - NGHTTP3_QPACK_TOKEN_DATE = 69, - NGHTTP3_QPACK_TOKEN_ETAG = 71, - NGHTTP3_QPACK_TOKEN_IF_MODIFIED_SINCE = 74, - NGHTTP3_QPACK_TOKEN_IF_NONE_MATCH = 75, - NGHTTP3_QPACK_TOKEN_LAST_MODIFIED = 77, - NGHTTP3_QPACK_TOKEN_LINK = 78, - NGHTTP3_QPACK_TOKEN_LOCATION = 79, - NGHTTP3_QPACK_TOKEN_REFERER = 83, - NGHTTP3_QPACK_TOKEN_SET_COOKIE = 85, - NGHTTP3_QPACK_TOKEN__METHOD = 1, - NGHTTP3_QPACK_TOKEN__SCHEME = 9, - NGHTTP3_QPACK_TOKEN__STATUS = 11, - NGHTTP3_QPACK_TOKEN_ACCEPT = 25, - NGHTTP3_QPACK_TOKEN_ACCEPT_ENCODING = 27, - NGHTTP3_QPACK_TOKEN_ACCEPT_RANGES = 29, - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS = 32, - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_ORIGIN = 38, - NGHTTP3_QPACK_TOKEN_CACHE_CONTROL = 46, - NGHTTP3_QPACK_TOKEN_CONTENT_ENCODING = 53, - NGHTTP3_QPACK_TOKEN_CONTENT_TYPE = 57, - NGHTTP3_QPACK_TOKEN_RANGE = 82, - NGHTTP3_QPACK_TOKEN_STRICT_TRANSPORT_SECURITY = 86, - NGHTTP3_QPACK_TOKEN_VARY = 92, - NGHTTP3_QPACK_TOKEN_X_CONTENT_TYPE_OPTIONS = 94, - NGHTTP3_QPACK_TOKEN_X_XSS_PROTECTION = 98, - NGHTTP3_QPACK_TOKEN_ACCEPT_LANGUAGE = 28, - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_CREDENTIALS = 30, - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_METHODS = 35, - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_EXPOSE_HEADERS = 39, - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_REQUEST_HEADERS = 40, - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_REQUEST_METHOD = 41, - NGHTTP3_QPACK_TOKEN_ALT_SVC = 44, - NGHTTP3_QPACK_TOKEN_AUTHORIZATION = 45, - NGHTTP3_QPACK_TOKEN_CONTENT_SECURITY_POLICY = 56, - NGHTTP3_QPACK_TOKEN_EARLY_DATA = 70, - NGHTTP3_QPACK_TOKEN_EXPECT_CT = 72, - NGHTTP3_QPACK_TOKEN_FORWARDED = 73, - NGHTTP3_QPACK_TOKEN_IF_RANGE = 76, - NGHTTP3_QPACK_TOKEN_ORIGIN = 80, - NGHTTP3_QPACK_TOKEN_PURPOSE = 81, - NGHTTP3_QPACK_TOKEN_SERVER = 84, - NGHTTP3_QPACK_TOKEN_TIMING_ALLOW_ORIGIN = 89, - NGHTTP3_QPACK_TOKEN_UPGRADE_INSECURE_REQUESTS = 90, - NGHTTP3_QPACK_TOKEN_USER_AGENT = 91, - NGHTTP3_QPACK_TOKEN_X_FORWARDED_FOR = 95, - NGHTTP3_QPACK_TOKEN_X_FRAME_OPTIONS = 96, - /* Additional header fields for HTTP messaging validation */ - NGHTTP3_QPACK_TOKEN_HOST = 1000, - NGHTTP3_QPACK_TOKEN_CONNECTION, - NGHTTP3_QPACK_TOKEN_KEEP_ALIVE, - NGHTTP3_QPACK_TOKEN_PROXY_CONNECTION, - NGHTTP3_QPACK_TOKEN_TRANSFER_ENCODING, - NGHTTP3_QPACK_TOKEN_UPGRADE, - NGHTTP3_QPACK_TOKEN_TE, - NGHTTP3_QPACK_TOKEN__PROTOCOL, - NGHTTP3_QPACK_TOKEN_PRIORITY -} nghttp3_qpack_token; - -/** - * @struct - * - * nghttp3_qpack_nv represents header field name/value pair just like - * :type:`nghttp3_nv`. It is an extended version of - * :type:`nghttp3_nv` and has reference counted buffers and tokens - * which might be useful for applications. - */ -typedef struct { - /* The buffer containing header field name. NULL-termination is - guaranteed. */ - nghttp3_rcbuf *name; - /* The buffer containing header field value. NULL-termination is - guaranteed. */ - nghttp3_rcbuf *value; - /* nghttp3_qpack_token value for name. It could be -1 if we have no - token for that header field name. */ - int32_t token; - /* Bitwise OR of one or more of nghttp3_nv_flag. */ - uint8_t flags; -} nghttp3_qpack_nv; - -struct nghttp3_qpack_encoder; - -/** - * @struct - * - * :type:`nghttp3_qpack_encoder` is QPACK encoder. - */ -typedef struct nghttp3_qpack_encoder nghttp3_qpack_encoder; - -/** - * @function - * - * `nghttp3_qpack_encoder_new` initializes QPACK encoder. |pencoder| - * must be non-NULL pointer. |max_dtable_size| is the maximum dynamic - * table size. |max_blocked| is the maximum number of streams which - * can be blocked. |mem| is a memory allocator. This function - * allocates memory for :type:`nghttp3_qpack_encoder` itself and - * assigns its pointer to |*pencoder| if it succeeds. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP3_ERR_NOMEM` - * Out of memory. - */ -NGHTTP3_EXTERN int nghttp3_qpack_encoder_new(nghttp3_qpack_encoder **pencoder, - size_t max_dtable_size, - size_t max_blocked, - const nghttp3_mem *mem); - -/** - * @function - * - * `nghttp3_qpack_encoder_del` frees memory allocated for |encoder|. - * This function frees memory pointed by |encoder| itself. - */ -NGHTTP3_EXTERN void nghttp3_qpack_encoder_del(nghttp3_qpack_encoder *encoder); - -/** - * @function - * - * `nghttp3_qpack_encoder_encode` encodes the list of header fields - * |nva|. |nvlen| is the length of |nva|. |stream_id| is the - * identifier of the stream which this header fields belong to. This - * function writes header block prefix, encoded header fields, and - * encoder stream to |pbuf|, |rbuf|, and |ebuf| respectively. The - * last field of nghttp3_buf will be adjusted when data is written. - * An application should write |pbuf| and |rbuf| to the request stream - * in this order. - * - * The buffer pointed by |pbuf|, |rbuf|, and |ebuf| can be empty - * buffer. It is fine to pass a buffer initialized by - * nghttp3_buf_init(buf). This function allocates memory for these - * buffers as necessary. In particular, it frees and expands buffer - * if the current capacity of buffer is not enough. If begin field of - * any buffer is not NULL, it must be allocated by the same memory - * allocator passed to `nghttp3_qpack_encoder_new()`. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP3_ERR_NOMEM` - * Out of memory - * :enum:`NGHTTP3_ERR_QPACK_FATAL` - * |encoder| is in unrecoverable error state and cannot be used - * anymore. - */ -NGHTTP3_EXTERN int nghttp3_qpack_encoder_encode( - nghttp3_qpack_encoder *encoder, nghttp3_buf *pbuf, nghttp3_buf *rbuf, - nghttp3_buf *ebuf, int64_t stream_id, const nghttp3_nv *nva, size_t nvlen); - -/** - * @function - * - * `nghttp3_qpack_encoder_read_decoder` reads decoder stream. The - * buffer pointed by |src| of length |srclen| contains decoder stream. - * - * This function returns the number of bytes read, or one of the - * following negative error codes: - * - * :enum:`NGHTTP3_ERR_NOMEM` - * Out of memory - * :enum:`NGHTTP3_ERR_QPACK_FATAL` - * |encoder| is in unrecoverable error state and cannot be used - * anymore. - * :enum:`NGHTTP3_ERR_QPACK_DECODER_STREAM` - * |encoder| is unable to process input because it is malformed. - */ -NGHTTP3_EXTERN nghttp3_ssize nghttp3_qpack_encoder_read_decoder( - nghttp3_qpack_encoder *encoder, const uint8_t *src, size_t srclen); - -/** - * @function - * - * `nghttp3_qpack_encoder_set_max_dtable_size` sets max dynamic table - * size to |max_dtable_size|. - * - * This function returns the number of bytes read, or one of the - * following negative error codes: - * - * :enum:`NGHTTP3_ERR_INVALID_ARGUMENT` - * |max_dtable_size| exceeds the hard limit that decoder specifies. - */ -NGHTTP3_EXTERN int -nghttp3_qpack_encoder_set_max_dtable_size(nghttp3_qpack_encoder *encoder, - size_t max_dtable_size); - -/** - * @function - * - * `nghttp3_qpack_encoder_set_hard_max_dtable_size` sets hard maximum - * dynamic table size to |hard_max_dtable_size|. - * - * This function returns the number of bytes read, or one of the - * following negative error codes: - * - * TBD - */ -NGHTTP3_EXTERN int -nghttp3_qpack_encoder_set_hard_max_dtable_size(nghttp3_qpack_encoder *encoder, - size_t hard_max_dtable_size); - -/** - * @function - * - * `nghttp3_qpack_encoder_set_max_blocked` sets the number of streams - * which can be blocked to |max_blocked|. - * - * This function returns the number of bytes read, or one of the - * following negative error codes: - * - * TBD - */ -NGHTTP3_EXTERN int -nghttp3_qpack_encoder_set_max_blocked(nghttp3_qpack_encoder *encoder, - size_t max_blocked); - -/** - * @function - * - * `nghttp3_qpack_encoder_ack_header` tells |encoder| that header - * block for a stream denoted by |stream_id| was acknowledged by - * decoder. This function is provided for debugging purpose only. In - * HTTP/3, |encoder| knows acknowledgement of header block by reading - * decoder stream with `nghttp3_qpack_encoder_read_decoder()`. - */ -NGHTTP3_EXTERN void -nghttp3_qpack_encoder_ack_header(nghttp3_qpack_encoder *encoder, - int64_t stream_id); - -/** - * @function - * - * `nghttp3_qpack_encoder_add_insert_count` increments known received - * count of |encoder| by |n|. This function is provided for debugging - * purpose only. In HTTP/3, |encoder| increments known received count - * by reading decoder stream with - * `nghttp3_qpack_encoder_read_decoder()`. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP3_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP3_QPACK_DECODER_STREAM` - * |n| is too large. - */ -NGHTTP3_EXTERN int -nghttp3_qpack_encoder_add_insert_count(nghttp3_qpack_encoder *encoder, - uint64_t n); - -/** - * @function - * - * `nghttp3_qpack_encoder_ack_everything` tells |encoder| that all - * encoded header blocks are acknowledged. This function is provided - * for debugging purpose only. In HTTP/3, |encoder| knows this by - * reading decoder stream with `nghttp3_qpack_encoder_read_decoder()`. - */ -NGHTTP3_EXTERN void -nghttp3_qpack_encoder_ack_everything(nghttp3_qpack_encoder *encoder); - -/** - * @function - * - * `nghttp3_qpack_encoder_cancel_stream` tells |encoder| that stream - * denoted by |stream_id| is cancelled. This function is provided for - * debugging purpose only. In HTTP/3, |encoder| knows this by reading - * decoder stream with `nghttp3_qpack_encoder_read_decoder()`. - */ -NGHTTP3_EXTERN void -nghttp3_qpack_encoder_cancel_stream(nghttp3_qpack_encoder *encoder, - int64_t stream_id); - -/** - * @function - * - * `nghttp3_qpack_encoder_get_num_blocked` returns the number of - * streams which is potentially blocked at decoder side. - */ -NGHTTP3_EXTERN size_t -nghttp3_qpack_encoder_get_num_blocked(nghttp3_qpack_encoder *encoder); - -struct nghttp3_qpack_stream_context; - -/** - * @struct - * - * :type:`nghttp3_qpack_stream_context` is a decoder context for an - * individual stream. - */ -typedef struct nghttp3_qpack_stream_context nghttp3_qpack_stream_context; - -/** - * @function - * - * `nghttp3_qpack_stream_context_new` initializes stream context. - * |psctx| must be non-NULL pointer. |stream_id| is stream ID. |mem| - * is a memory allocator. This function allocates memory for - * :type:`nghttp3_qpack_stream_context` itself and assigns its pointer - * to |*psctx| if it succeeds. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP3_ERR_NOMEM` - * Out of memory. - */ -NGHTTP3_EXTERN int -nghttp3_qpack_stream_context_new(nghttp3_qpack_stream_context **psctx, - int64_t stream_id, const nghttp3_mem *mem); - -/** - * @function - * - * `nghttp3_qpack_stream_context_del` frees memory allocated for - * |sctx|. This function frees memory pointed by |sctx| itself. - */ -NGHTTP3_EXTERN void -nghttp3_qpack_stream_context_del(nghttp3_qpack_stream_context *sctx); - -/** - * @function - * - * `nghttp3_qpack_stream_context_get_ricnt` returns required insert - * count. - */ -NGHTTP3_EXTERN uint64_t -nghttp3_qpack_stream_context_get_ricnt(nghttp3_qpack_stream_context *sctx); - -struct nghttp3_qpack_decoder; - -/** - * @struct - * - * `nghttp3_qpack_decoder` is QPACK decoder. - */ -typedef struct nghttp3_qpack_decoder nghttp3_qpack_decoder; - -/** - * @function - * - * `nghttp3_qpack_decoder_new` initializes QPACK decoder. |pdecoder| - * must be non-NULL pointer. |max_dtable_size| is the maximum dynamic - * table size. |max_blocked| is the maximum number of streams which - * can be blocked. |mem| is a memory allocator. This function - * allocates memory for :type:`nghttp3_qpack_decoder` itself and - * assigns its pointer to |*pdecoder| if it succeeds. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP3_ERR_NOMEM` - * Out of memory. - */ -NGHTTP3_EXTERN int nghttp3_qpack_decoder_new(nghttp3_qpack_decoder **pdecoder, - size_t max_dtable_size, - size_t max_blocked, - const nghttp3_mem *mem); - -/** - * @function - * - * `nghttp3_qpack_decoder_del` frees memory allocated for |decoder|. - * This function frees memory pointed by |decoder| itself. - */ -NGHTTP3_EXTERN void nghttp3_qpack_decoder_del(nghttp3_qpack_decoder *decoder); - -/** - * @function - * - * `nghttp3_qpack_decoder_read_encoder` reads encoder stream. The - * buffer pointed by |src| of length |srclen| contains encoder stream. - * - * This function returns the number of bytes read, or one of the - * following negative error codes: - * - * :enum:`NGHTTP3_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP3_ERR_QPACK_FATAL` - * |decoder| is in unrecoverable error state and cannot be used - * anymore. - * :enum:`NGHTTP3_ERR_QPACK_ENCODER_STREAM` - * Could not interpret encoder stream instruction. - */ -NGHTTP3_EXTERN nghttp3_ssize nghttp3_qpack_decoder_read_encoder( - nghttp3_qpack_decoder *decoder, const uint8_t *src, size_t srclen); - -/** - * @function - * - * `nghttp3_qpack_decoder_get_icnt` returns insert count. - */ -NGHTTP3_EXTERN uint64_t -nghttp3_qpack_decoder_get_icnt(const nghttp3_qpack_decoder *decoder); - -/** - * @enum - * - * :type:`nghttp3_qpack_decode_flag` is a set of flags for decoder. - */ -typedef enum { - /** - * :enum:`NGHTTP3_QPACK_DECODE_FLAG_NONE` indicates that no flag - * set. - */ - NGHTTP3_QPACK_DECODE_FLAG_NONE, - /** - * :enum:`NGHTTP3_QPACK_DECODE_FLAG_EMIT` indicates that a header - * field is successfully decoded. - */ - NGHTTP3_QPACK_DECODE_FLAG_EMIT = 0x01, - /** - * :enum:`NGHTTP3_QPACK_DECODE_FLAG_FINAL` indicates that all header - * fields have been decoded. - */ - NGHTTP3_QPACK_DECODE_FLAG_FINAL = 0x02, - /** - * :enum:`NGHTTP3_QPACK_DECODE_FLAG_BLOCKED` indicates that decoding - * has been blocked. - */ - NGHTTP3_QPACK_DECODE_FLAG_BLOCKED = 0x04 -} nghttp3_qpack_decode_flag; - -/** - * @function - * - * `nghttp3_qpack_decoder_read_request` reads request stream. The - * request stream is given as the buffer pointed by |src| of length - * |srclen|. |sctx| is the stream context and it must be initialized - * by `nghttp3_qpack_stream_context_init()`. |*pflags| must be - * non-NULL pointer. |nv| must be non-NULL pointer. - * - * If this function succeeds, it assigns flags to |*pflags|. If - * |*pflags| has :enum:`NGHTTP3_QPACK_DECODE_FLAG_EMIT` set, a decoded - * header field is assigned to |nv|. If |*pflags| has - * :enum:`NGHTTP3_QPACK_DECODE_FLAG_FINAL` set, all header fields have - * been successfully decoded. If |*pflags| has - * :enum:`NGHTTP3_QPACK_DECODE_FLAG_BLOCKED` set, decoding is blocked - * due to required insert count. - * - * When a header field is decoded, an application receives it in |nv|. - * nv->name and nv->value are reference counted buffer, and their - * reference counts are already incremented for application use. - * Therefore, when application finishes processing the header field, - * it must call nghttp3_rcbuf_decref(nv->name) and - * nghttp3_rcbuf_decref(nv->value) or memory leak might occur. - * - * This function returns the number of bytes read, or one of the - * following negative error codes: - * - * :enum:`NGHTTP3_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP3_ERR_QPACK_FATAL` - * |decoder| is in unrecoverable error state and cannot be used - * anymore. - * :enum:`NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED` - * Could not interpret header block instruction. - * :enum:`NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE` - * Header field is too large. - */ -NGHTTP3_EXTERN nghttp3_ssize nghttp3_qpack_decoder_read_request( - nghttp3_qpack_decoder *decoder, nghttp3_qpack_stream_context *sctx, - nghttp3_qpack_nv *nv, uint8_t *pflags, const uint8_t *src, size_t srclen, - int fin); - -/** - * @function - * - * `nghttp3_qpack_decoder_write_decoder` writes decoder stream into - * |dbuf|. - * - * The caller must ensure that nghttp3_buf_left(dbuf) >= - * nghttp3_qpack_decoder_get_decoder_streamlen(decoder). - */ -NGHTTP3_EXTERN void -nghttp3_qpack_decoder_write_decoder(nghttp3_qpack_decoder *decoder, - nghttp3_buf *dbuf); - -/** - * @function - * - * `nghttp3_qpack_decoder_get_decoder_streamlen` returns the length of - * decoder stream. - */ -NGHTTP3_EXTERN size_t -nghttp3_qpack_decoder_get_decoder_streamlen(nghttp3_qpack_decoder *decoder); - -/** - * @function - * - * `nghttp3_qpack_decoder_cancel_stream` cancels header decoding for - * stream denoted by |stream_id|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP3_ERR_NOMEM` - * Out of memory. - * :enum:`NGHTTP3_ERR_QPACK_FATAL` - * Decoder stream overflow. - */ -NGHTTP3_EXTERN int -nghttp3_qpack_decoder_cancel_stream(nghttp3_qpack_decoder *decoder, - int64_t stream_id); - -/** - * @function - * - * `nghttp3_qpack_decoder_set_dtable_cap` sets |cap| as maximum - * dynamic table size. Normally, the maximum capacity is communicated - * in encoder stream. This function is provided for debugging and - * testing purpose. - */ -NGHTTP3_EXTERN void -nghttp3_qpack_decoder_set_dtable_cap(nghttp3_qpack_decoder *decoder, - size_t cap); - -/** - * @function - * - * `nghttp3_qpack_decoder_set_max_concurrent_streams` tells |decoder| - * the maximum number of concurrent streams that a remote endpoint can - * open, including both bidirectional and unidirectional streams which - * potentially receive QPACK encoded HEADERS frame. This value is - * used as a hint to limit the length of decoder stream. - */ -NGHTTP3_EXTERN void -nghttp3_qpack_decoder_set_max_concurrent_streams(nghttp3_qpack_decoder *decoder, - size_t max_concurrent_streams); - -/** - * @function - * - * `nghttp3_strerror` returns textual representation of |liberr| which - * should be one of error codes defined in :type:`nghttp3_lib_error`. - */ -NGHTTP3_EXTERN const char *nghttp3_strerror(int liberr); - -/** - * @function - * - * `nghttp3_err_infer_quic_app_error_code` returns a QUIC application - * error code which corresponds to |liberr|. - */ -NGHTTP3_EXTERN uint64_t nghttp3_err_infer_quic_app_error_code(int liberr); - -/** - * @functypedef - * - * :type:`nghttp3_debug_vprintf_callback` is a callback function - * invoked when the library outputs debug logging. The function is - * called with arguments suitable for ``vfprintf(3)`` - * - * The debug output is only enabled if the library is built with - * ``DEBUGBUILD`` macro defined. - */ -typedef void (*nghttp3_debug_vprintf_callback)(const char *format, - va_list args); - -/** - * @function - * - * `nghttp3_set_debug_vprintf_callback` sets a debug output callback - * called by the library when built with ``DEBUGBUILD`` macro defined. - * If this option is not used, debug log is written into standard - * error output. - * - * For builds without ``DEBUGBUILD`` macro defined, this function is - * noop. - * - * Note that building with ``DEBUGBUILD`` may cause significant - * performance penalty to libnghttp3 because of extra processing. It - * should be used for debugging purpose only. - * - * .. Warning:: - * - * Building with ``DEBUGBUILD`` may cause significant performance - * penalty to libnghttp3 because of extra processing. It should be - * used for debugging purpose only. We write this two times because - * this is important. - */ -NGHTTP3_EXTERN void nghttp3_set_debug_vprintf_callback( - nghttp3_debug_vprintf_callback debug_vprintf_callback); - -struct nghttp3_conn; -typedef struct nghttp3_conn nghttp3_conn; - -/** - * @functypedef - * - * :type:`nghttp3_acked_stream_data` is a callback function which is - * invoked when data sent on stream denoted by |stream_id| supplied - * from application is acknowledged by remote endpoint. The number of - * bytes acknowledged is given in |datalen|. - * - * The implementation of this callback must return 0 if it succeeds. - * Returning :enum:`NGHTTP3_ERR_CALLBACK_FAILURE` will return to the - * caller immediately. Any values other than 0 is treated as - * :enum:`NGHTTP3_ERR_CALLBACK_FAILURE`. - */ -typedef int (*nghttp3_acked_stream_data)(nghttp3_conn *conn, int64_t stream_id, - size_t datalen, void *conn_user_data, - void *stream_user_data); - -/** - * @functypedef - * - * :type:`nghttp3_conn_stream_close` is a callback function which is - * invoked when a stream identified by |stream_id| is closed. - * |app_error_code| indicates the reason of this closure. - * - * The implementation of this callback must return 0 if it succeeds. - * Returning :enum:`NGHTTP3_ERR_CALLBACK_FAILURE` will return to the - * caller immediately. Any values other than 0 is treated as - * :enum:`NGHTTP3_ERR_CALLBACK_FAILURE`. - */ -typedef int (*nghttp3_stream_close)(nghttp3_conn *conn, int64_t stream_id, - uint64_t app_error_code, - void *conn_user_data, - void *stream_user_data); - -/** - * @functypedef - * - * :type:`nghttp3_recv_data` is a callback function which is invoked - * when a part of request or response body on stream identified by - * |stream_id| is received. |data| points to the received data and - * its length is |datalen|. - * - * The application is responsible for increasing flow control credit - * by |datalen| bytes. - * - * The implementation of this callback must return 0 if it succeeds. - * Returning :enum:`NGHTTP3_ERR_CALLBACK_FAILURE` will return to the - * caller immediately. Any values other than 0 is treated as - * :enum:`NGHTTP3_ERR_CALLBACK_FAILURE`. - */ -typedef int (*nghttp3_recv_data)(nghttp3_conn *conn, int64_t stream_id, - const uint8_t *data, size_t datalen, - void *conn_user_data, void *stream_user_data); - -/** - * @functypedef - * - * :type:`nghttp3_deferred_consume` is a callback function which is - * invoked when the library consumed |consumed| bytes for a stream - * identified by |stream_id|. This callback is used to notify the - * consumed bytes for stream blocked by QPACK decoder. The - * application is responsible for increasing flow control credit by - * |consumed| bytes. - * - * The implementation of this callback must return 0 if it succeeds. - * Returning :enum:`NGHTTP3_ERR_CALLBACK_FAILURE` will return to the - * caller immediately. Any values other than 0 is treated as - * :enum:`NGHTTP3_ERR_CALLBACK_FAILURE`. - */ -typedef int (*nghttp3_deferred_consume)(nghttp3_conn *conn, int64_t stream_id, - size_t consumed, void *conn_user_data, - void *stream_user_data); - -typedef int (*nghttp3_begin_headers)(nghttp3_conn *conn, int64_t stream_id, - void *conn_user_data, - void *stream_user_data); - -typedef int (*nghttp3_recv_header)(nghttp3_conn *conn, int64_t stream_id, - int32_t token, nghttp3_rcbuf *name, - nghttp3_rcbuf *value, uint8_t flags, - void *conn_user_data, - void *stream_user_data); - -typedef int (*nghttp3_end_headers)(nghttp3_conn *conn, int64_t stream_id, - void *conn_user_data, - void *stream_user_data); - -typedef int (*nghttp3_begin_push_promise)(nghttp3_conn *conn, int64_t stream_id, - int64_t push_id, void *conn_user_data, - void *stream_user_data); - -typedef int (*nghttp3_recv_push_promise)(nghttp3_conn *conn, int64_t stream_id, - int64_t push_id, int32_t token, - nghttp3_rcbuf *name, - nghttp3_rcbuf *value, uint8_t flags, - void *conn_user_data, - void *stream_user_data); - -typedef int (*nghttp3_end_push_promise)(nghttp3_conn *conn, int64_t stream_id, - int64_t push_id, void *conn_user_data, - void *stream_user_data); - -/** - * @functypedef - * - * :type:`nghttp3_end_stream` is a callback function which is invoked - * when the receiving side of stream is closed. For server, this - * callback function is invoked when HTTP request is received - * completely. For client, this callback function is invoked when - * HTTP response is received completely. - * - * The implementation of this callback must return 0 if it succeeds. - * Returning :enum:`NGHTTP3_ERR_CALLBACK_FAILURE` will return to the - * caller immediately. Any values other than 0 is treated as - * :enum:`NGHTTP3_ERR_CALLBACK_FAILURE`. - */ -typedef int (*nghttp3_end_stream)(nghttp3_conn *conn, int64_t stream_id, - void *conn_user_data, void *stream_user_data); - -/** - * @functypedef - * - * :type:`nghttp3_cancel_push` is a callback function which is invoked - * when the push identified by |push_id| is cancelled by remote - * endpoint. If a stream has been bound to the push ID, |stream_id| - * contains the stream ID and |stream_user_data| points to the stream - * user data. Otherwise, |stream_id| is -1 and |stream_user_data| is - * NULL. - * - * The implementation of this callback must return 0 if it succeeds. - * Returning :enum:`NGHTTP3_ERR_CALLBACK_FAILURE` will return to the - * caller immediately. Any values other than 0 is treated as - * :enum:`NGHTTP3_ERR_CALLBACK_FAILURE`. - */ -typedef int (*nghttp3_cancel_push)(nghttp3_conn *conn, int64_t push_id, - int64_t stream_id, void *conn_user_data, - void *stream_user_data); - -/** - * @functypedef - * - * :type:`nghttp3_send_stop_sending` is a callback function which is - * invoked when the library asks application to send STOP_SENDING to - * the stream identified by |stream_id|. |app_error_code| indicates - * the reason for this action. - * - * The implementation of this callback must return 0 if it succeeds. - * Returning :enum:`NGHTTP3_ERR_CALLBACK_FAILURE` will return to the - * caller immediately. Any values other than 0 is treated as - * :enum:`NGHTTP3_ERR_CALLBACK_FAILURE`. - */ -typedef int (*nghttp3_send_stop_sending)(nghttp3_conn *conn, int64_t stream_id, - uint64_t app_error_code, - void *conn_user_data, - void *stream_user_data); - -/** - * @functypedef - * - * :type:`nghttp3_push_stream` is a callback function which is invoked - * when a push stream identified by |stream_id| is opened with - * |push_id|. - * - * The implementation of this callback must return 0 if it succeeds. - * Returning :enum:`NGHTTP3_ERR_CALLBACK_FAILURE` will return to the - * caller immediately. Any values other than 0 is treated as - * :enum:`NGHTTP3_ERR_CALLBACK_FAILURE`. - */ -typedef int (*nghttp3_push_stream)(nghttp3_conn *conn, int64_t push_id, - int64_t stream_id, void *conn_user_data); - -typedef struct { - nghttp3_acked_stream_data acked_stream_data; - nghttp3_stream_close stream_close; - nghttp3_recv_data recv_data; - nghttp3_deferred_consume deferred_consume; - nghttp3_begin_headers begin_headers; - nghttp3_recv_header recv_header; - nghttp3_end_headers end_headers; - nghttp3_begin_headers begin_trailers; - nghttp3_recv_header recv_trailer; - nghttp3_end_headers end_trailers; - nghttp3_begin_push_promise begin_push_promise; - nghttp3_recv_push_promise recv_push_promise; - nghttp3_end_push_promise end_push_promise; - nghttp3_cancel_push cancel_push; - nghttp3_send_stop_sending send_stop_sending; - nghttp3_push_stream push_stream; - nghttp3_end_stream end_stream; -} nghttp3_conn_callbacks; - -typedef struct { - uint64_t max_field_section_size; - uint64_t max_pushes; - size_t qpack_max_table_capacity; - size_t qpack_blocked_streams; -} nghttp3_conn_settings; - -NGHTTP3_EXTERN void -nghttp3_conn_settings_default(nghttp3_conn_settings *settings); - -NGHTTP3_EXTERN int -nghttp3_conn_client_new(nghttp3_conn **pconn, - const nghttp3_conn_callbacks *callbacks, - const nghttp3_conn_settings *settings, - const nghttp3_mem *mem, void *conn_user_data); - -NGHTTP3_EXTERN int -nghttp3_conn_server_new(nghttp3_conn **pconn, - const nghttp3_conn_callbacks *callbacks, - const nghttp3_conn_settings *settings, - const nghttp3_mem *mem, void *conn_user_data); - -NGHTTP3_EXTERN void nghttp3_conn_del(nghttp3_conn *conn); - -/** - * @function - * - * `nghttp3_conn_bind_control_stream` binds stream denoted by - * |stream_id| to outgoing unidirectional control stream. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP3_ERR_INVALID_STATE` - * Control stream has already corresponding stream ID. - * TBD - */ -NGHTTP3_EXTERN int nghttp3_conn_bind_control_stream(nghttp3_conn *conn, - int64_t stream_id); - -/** - * @function - * - * `nghttp3_conn_bind_qpack_streams` binds stream denoted by - * |qenc_stream_id| to outgoing QPACK encoder stream and stream - * denoted by |qdec_stream_id| to outgoing QPACK encoder stream. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP3_ERR_INVALID_STATE` - * QPACK encoder/decoder stream have already corresponding stream - * IDs. - * TBD - */ -NGHTTP3_EXTERN int nghttp3_conn_bind_qpack_streams(nghttp3_conn *conn, - int64_t qenc_stream_id, - int64_t qdec_stream_id); - -/** - * @function - * - * nghttp3_conn_read_stream reads data |src| of length |srclen| on - * stream identified by |stream_id|. It returns the number of bytes - * consumed. The "consumed" means that application can increase flow - * control credit (both stream and connection) of underlying QUIC - * connection by that amount. It does not include the amount of data - * carried by DATA frame which contains application data (excluding - * any control or QPACK unidirectional streams) . See - * type:`nghttp3_recv_data` to handle those bytes. If |fin| is - * nonzero, this is the last data from remote endpoint in this stream. - */ -NGHTTP3_EXTERN nghttp3_ssize nghttp3_conn_read_stream(nghttp3_conn *conn, - int64_t stream_id, - const uint8_t *src, - size_t srclen, int fin); - -/** - * @function - * - * `nghttp3_conn_writev_stream` stores stream data to send to |vec| of - * length |veccnt| and returns the number of nghttp3_vec object in - * which it stored data. It stores stream ID to |*pstream_id|. An - * application has to call `nghttp3_conn_add_write_offset` to inform - * |conn| of the actual number of bytes that underlying QUIC stack - * accepted. |*pfin| will be nonzero if this is the last data to - * send. If there is no stream to write data or send fin, this - * function returns 0, and -1 is assigned to |*pstream_id|. - */ -NGHTTP3_EXTERN nghttp3_ssize nghttp3_conn_writev_stream(nghttp3_conn *conn, - int64_t *pstream_id, - int *pfin, - nghttp3_vec *vec, - size_t veccnt); - -/** - * @function - * - * `nghttp3_conn_add_write_offset` tells |conn| the number of bytes - * |n| for stream denoted by |stream_id| QUIC stack accepted. - * - * If stream has no data to send but just sends fin (closing the write - * side of a stream), the number of bytes sent is 0. It is important - * to call this function even if |n| is 0 in this case. It is safe to - * call this function if |n| is 0. - * - * `nghttp3_conn_writev_stream` must be called before calling this - * function to get data to send, and those data must be fed into QUIC - * stack. - */ -NGHTTP3_EXTERN int nghttp3_conn_add_write_offset(nghttp3_conn *conn, - int64_t stream_id, size_t n); - -/** - * @function - * - * `nghttp3_conn_add_ack_offset` tells |conn| the number of bytes |n| - * for stream denoted by |stream_id| QUIC stack has acknowledged. - */ -NGHTTP3_EXTERN int nghttp3_conn_add_ack_offset(nghttp3_conn *conn, - int64_t stream_id, uint64_t n); - -/** - * @function - * - * `nghttp3_conn_block_stream` tells the library that stream - * identified by |stream_id| is blocked due to QUIC flow control. - */ -NGHTTP3_EXTERN int nghttp3_conn_block_stream(nghttp3_conn *conn, - int64_t stream_id); - -/** - * @function - * - * `nghttp3_conn_unblock_stream` tells the library that stream - * identified by |stream_id| which was blocked by QUIC flow control is - * unblocked. - */ -NGHTTP3_EXTERN int nghttp3_conn_unblock_stream(nghttp3_conn *conn, - int64_t stream_id); - -/** - * @function - * - * `nghttp3_conn_resume_stream` resumes stream identified by - * |stream_id| which was previously unable to provide data. - */ -NGHTTP3_EXTERN int nghttp3_conn_resume_stream(nghttp3_conn *conn, - int64_t stream_id); - -/** - * @function - * - * `nghttp3_conn_close_stream` closes stream identified by - * |stream_id|. |app_error_code| is the reason of the closure. - */ -NGHTTP3_EXTERN int nghttp3_conn_close_stream(nghttp3_conn *conn, - int64_t stream_id, - uint64_t app_error_code); - -/** - * @function - * - * `nghttp3_conn_reset_stream` must be called if stream identified by - * |stream_id| is reset by a remote endpoint. This is required in - * order to cancel QPACK stream. - */ -NGHTTP3_EXTERN int nghttp3_conn_reset_stream(nghttp3_conn *conn, - int64_t stream_id); - -typedef enum { - NGHTTP3_DATA_FLAG_NONE = 0x00, - /** - * ``NGHTTP3_DATA_FLAG_EOF`` indicates that all request or response - * body has been provided to the library. It also indicates that - * sending side of stream is closed unless - * :enum:`NGHTTP3_DATA_FLAG_NO_END_STREAM` is given at the same - * time. - */ - NGHTTP3_DATA_FLAG_EOF = 0x01, - /** - * ``NGHTTP3_DATA_FLAG_NO_END_STREAM`` indicates that sending side - * of stream is not closed even if NGHTTP3_DATA_FLAG_EOF is set. - * Usually this flag is used to send trailer fields with - * `nghttp3_conn_submit_trailers()`. If - * `nghttp3_conn_submit_trailers()` has been called, regardless of - * this flag, the submitted trailer fields are sent. - */ - NGHTTP3_DATA_FLAG_NO_END_STREAM = 0x02 -} nghttp3_data_flag; - -/** - * @function - * - * `nghttp3_conn_set_max_client_streams_bidi` tells |conn| the - * cumulative number of bidirectional streams that client can open. - */ -NGHTTP3_EXTERN void -nghttp3_conn_set_max_client_streams_bidi(nghttp3_conn *conn, - uint64_t max_streams); - -/** - * @function - * - * `nghttp3_conn_set_max_concurrent_streams` tells |conn| the maximum - * number of concurrent streams that a remote endpoint can open, - * including both bidirectional and unidirectional streams which - * potentially receive QPACK encoded HEADERS frame. This value is - * used as a hint to limit the internal resource consumption. - */ -NGHTTP3_EXTERN void -nghttp3_conn_set_max_concurrent_streams(nghttp3_conn *conn, - size_t max_concurrent_streams); - -/** - * @functypedef - * - * :type:`nghttp3_read_data_callback` is a callback function invoked - * when the library asks an application to provide stream data for a - * stream denoted by |stream_id|. - * - * The library provides |vec| of length |veccnt| to the application. - * The application should fill data and its length to |vec|. It has - * to return the number of the filled objects. The application must - * retain data until they are safe to free. It is notified by - * :type:`nghttp3_acked_stream_data` callback. - * - * If this is the last data to send (or there is no data to send - * because all data have been sent already), set - * :enum:`NGHTTP3_DATA_FLAG_EOF` to |*pflags|. - * - * If the application is unable to provide data temporarily, return - * :enum:`NGHTTP3_ERR_WOULDBLOCK`. When it is ready to provide - * data, call `nghttp3_conn_resume_stream()`. - * - * The callback should return the number of objects in |vec| that the - * application filled if it succeeds, or - * :enum:`NGHTTP3_ERR_CALLBACK_FAILURE`. - * - * TODO Add NGHTTP3_ERR_TEMPORAL_CALLBACK_FAILURE to reset just this - * stream. - */ -typedef nghttp3_ssize (*nghttp3_read_data_callback)( - nghttp3_conn *conn, int64_t stream_id, nghttp3_vec *vec, size_t veccnt, - uint32_t *pflags, void *conn_user_data, void *stream_user_data); - -/** - * @struct - * - * :type:`nghttp3_data_reader` specifies the way how to generate - * request or response body. - */ -typedef struct { - /** - * read_data is a callback function to generate body. - */ - nghttp3_read_data_callback read_data; -} nghttp3_data_reader; - -/** - * @function - * - * `nghttp3_conn_submit_request` submits HTTP request header fields - * and body on the stream identified by |stream_id|. |stream_id| must - * be a client initiated bidirectional stream. Only client can submit - * HTTP request. |nva| of length |nvlen| specifies HTTP request - * header fields. |dr| specifies a request body. If there is no - * request body, specify NULL. If |dr| is NULL, it implies the end of - * stream. |stream_user_data| is an opaque pointer attached to the - * stream. - */ -NGHTTP3_EXTERN int nghttp3_conn_submit_request( - nghttp3_conn *conn, int64_t stream_id, const nghttp3_nv *nva, size_t nvlen, - const nghttp3_data_reader *dr, void *stream_user_data); - -/** - * @function - * - * `nghttp3_conn_submit_push_promise` submits push promise on the - * stream identified by |stream_id|. |stream_id| must be a client - * initiated bidirectional stream. Only server can submit push - * promise. On success, a push ID is assigned to |*ppush_id|. |nva| - * of length |nvlen| specifies HTTP request header fields. In order - * to submit HTTP response, first call - * `nghttp3_conn_bind_push_stream()` and then - * `nghttp3_conn_submit_response()`. - */ -NGHTTP3_EXTERN int nghttp3_conn_submit_push_promise(nghttp3_conn *conn, - int64_t *ppush_id, - int64_t stream_id, - const nghttp3_nv *nva, - size_t nvlen); - -/** - * @function - * - * `nghttp3_conn_submit_info` submits HTTP non-final response header - * fields on the stream identified by |stream_id|. |nva| of length - * |nvlen| specifies HTTP response header fields. - */ -NGHTTP3_EXTERN int nghttp3_conn_submit_info(nghttp3_conn *conn, - int64_t stream_id, - const nghttp3_nv *nva, - size_t nvlen); - -/** - * @function - * - * `nghttp3_conn_submit_response` submits HTTP response header fields - * and body on the stream identified by |stream_id|. |nva| of length - * |nvlen| specifies HTTP response header fields. |dr| specifies a - * response body. If there is no response body, specify NULL. If - * |dr| is NULL, it implies the end of stream. - */ -NGHTTP3_EXTERN int nghttp3_conn_submit_response(nghttp3_conn *conn, - int64_t stream_id, - const nghttp3_nv *nva, - size_t nvlen, - const nghttp3_data_reader *dr); - -/** - * @function - * - * `nghttp3_conn_submit_trailers` submits HTTP trailer fields on the - * stream identified by |stream_id|. |nva| of length |nvlen| - * specifies HTTP trailer fields. Calling this function implies the - * end of stream. - */ -NGHTTP3_EXTERN int nghttp3_conn_submit_trailers(nghttp3_conn *conn, - int64_t stream_id, - const nghttp3_nv *nva, - size_t nvlen); - -/** - * @function - * - * `nghttp3_conn_bind_push_stream` binds the stream identified by - * |stream_id| to the push identified by |push_id|. |stream_id| must - * be a server initiated unidirectional stream. |push_id| must be - * obtained from `nghttp3_conn_submit_push_promise()`. To send - * response to this push, call `nghttp3_conn_submit_response()`. - */ -NGHTTP3_EXTERN int nghttp3_conn_bind_push_stream(nghttp3_conn *conn, - int64_t push_id, - int64_t stream_id); - -/** - * @function - * - * `nghttp3_conn_cancel_push` cancels the push identified by - * |push_id|. It is not possible to cancel the push after the - * response stream opens. In that case, send RESET_STREAM (if |conn| - * is server) or STOP_SENDING (if |conn| is client) on the underlying - * QUIC stream. - */ -NGHTTP3_EXTERN int nghttp3_conn_cancel_push(nghttp3_conn *conn, - int64_t push_id); - -/** - * @function - * - * `nghttp3_conn_set_stream_user_data` sets |stream_user_data| to the - * stream identified by |stream_id|. - */ -NGHTTP3_EXTERN int nghttp3_conn_set_stream_user_data(nghttp3_conn *conn, - int64_t stream_id, - void *stream_user_data); - -/** - * @function - * - * `nghttp3_conn_get_frame_payload_left` returns the number of bytes - * left to read current frame payload for a stream denoted by - * |stream_id|. If no such stream is found, it returns - * :enum:`NGHTTP3_ERR_STREAM_NOT_FOUND`. - */ -NGHTTP3_EXTERN int64_t nghttp3_conn_get_frame_payload_left(nghttp3_conn *conn, - int64_t stream_id); - -/** - * @macro - * - * :macro:`NGHTTP3_DEFAULT_URGENCY` is the default urgency level. - */ -#define NGHTTP3_DEFAULT_URGENCY 1 - -/** - * @macro - * - * :macro:`NGHTTP3_URGENCY_HIGH` is the highest urgency level. - */ -#define NGHTTP3_URGENCY_HIGH 0 - -/** - * @macro - * - * :macro:`NGHTTP3_URGENCY_LOW` is the lowest urgency level. - */ -#define NGHTTP3_URGENCY_LOW 7 - -/** - * @macro - * - * :macro:`NGHTTP3_URGENCY_LEVELS` is the number of urgency levels. - */ -#define NGHTTP3_URGENCY_LEVELS (NGHTTP3_URGENCY_LOW + 1) - -/** - * @struct - * - * :type:`nghttp3_pri` represents HTTP priority. - */ -typedef struct nghttp3_pri { - /** - * urgency is the urgency of a stream, it must be in - * [NGHTTP3_URGENCY_HIGH, NGHTTP3_URGENCY_LOW], inclusive, and 0 is - * the highest urgency. - */ - uint32_t urgency; - /** - * inc indicates that a content can be processed incrementally or - * not. If inc is 0, it cannot be processed incrementally. If inc - * is 1, it can be processed incrementally. Other value is not - * permitted. - */ - int inc; -} nghttp3_pri; - -/** - * @function - * - * `nghttp3_conn_get_stream_priority` stores stream priority of a - * stream denoted by |stream_id| into |*dest|. Only server can use - * this function. - * - * This function must not be called if |conn| is initialized as - * client. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP3_ERR_STREAM_NOT_FOUND` - * Stream not found. - */ -NGHTTP3_EXTERN int nghttp3_conn_get_stream_priority(nghttp3_conn *conn, - nghttp3_pri *dest, - int64_t stream_id); - -/** - * @function - * - * `nghttp3_conn_set_stream_priority` updates stream priority of a - * stream denoted by |stream_id| by the value pointed by |pri|. - * - * This function must not be called if |conn| is initialized as - * client. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP3_ERR_STREAM_NOT_FOUND` - * Stream not found. - * :enum:`NGHTTP3_ERR_NOMEM` - * Out of memory. - */ -NGHTTP3_EXTERN int nghttp3_conn_set_stream_priority(nghttp3_conn *conn, - int64_t stream_id, - const nghttp3_pri *pri); - -/** - * @function - * - * `nghttp3_conn_is_remote_qpack_encoder_stream` returns nonzero if a - * stream denoted by |stream_id| is QPACK encoder stream of a remote - * endpoint. - */ -NGHTTP3_EXTERN int -nghttp3_conn_is_remote_qpack_encoder_stream(nghttp3_conn *conn, - int64_t stream_id); - -/** - * @function - * - * `nghttp3_vec_len` returns the sum of length in |vec| of |cnt| - * elements. - */ -NGHTTP3_EXTERN size_t nghttp3_vec_len(const nghttp3_vec *vec, size_t cnt); - -/** - * @function - * - * `nghttp3_vec_empty` returns nonzero if |vec| of |cnt| elements has - * 0 length data. - */ -NGHTTP3_EXTERN int nghttp3_vec_empty(const nghttp3_vec *vec, size_t cnt); - -/** - * @function - * - * `nghttp3_vec_consume` removes first |len| bytes from |*pvec| of - * |*pcnt| elements. The adjusted vector and number of elements are - * stored in |*pvec| and |*pcnt| respectively. - */ -NGHTTP3_EXTERN void nghttp3_vec_consume(nghttp3_vec **pvec, size_t *pcnt, - size_t len); - -/** - * @function - * - * `nghttp3_check_header_name` returns nonzero if HTTP header field - * name |name| of length |len| is valid according to - * http://tools.ietf.org/html/rfc7230#section-3.2 - * - * Because this is a header field name in HTTP/3, the upper cased - * alphabet is treated as error. - */ -NGHTTP3_EXTERN int nghttp3_check_header_name(const uint8_t *name, size_t len); - -/** - * @function - * - * `nghttp3_check_header_value` returns nonzero if HTTP header field - * value |value| of length |len| is valid according to - * http://tools.ietf.org/html/rfc7230#section-3.2 - */ -NGHTTP3_EXTERN int nghttp3_check_header_value(const uint8_t *value, size_t len); - -/** - * @function - * - * `nghttp3_http_parse_priority` parses priority HTTP header field - * stored in the buffer pointed by |value| of length |len|. If it - * successfully processed header field value, it stores the result - * into |*dest|. This function just overwrites what it sees in the - * header field value and does not initialize any field in |*dest|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGHTTP3_ERR_INVALID_ARGUMENT` - * The function could not parse the provided value. - */ -NGHTTP3_EXTERN int nghttp3_http_parse_priority(nghttp3_pri *dest, - const uint8_t *value, - size_t len); - -/** - * @macro - * - * The age of :type:`nghttp3_info` - */ -#define NGHTTP3_VERSION_AGE 1 - -/** - * @struct - * - * This struct is what `nghttp3_version()` returns. It holds - * information about the particular nghttp3 version. - */ -typedef struct { - /** - * Age of this struct. This instance of nghttp3 sets it to - * :macro:`NGHTTP3_VERSION_AGE` but a future version may bump it and - * add more struct fields at the bottom - */ - int age; - /** - * the :macro:`NGHTTP3_VERSION_NUM` number (since age ==1) - */ - int version_num; - /** - * points to the :macro:`NGHTTP3_VERSION` string (since age ==1) - */ - const char *version_str; - /* -------- the above fields all exist when age == 1 */ -} nghttp3_info; - -/** - * @function - * - * Returns a pointer to a nghttp3_info struct with version information - * about the run-time library in use. The |least_version| argument - * can be set to a 24 bit numerical value for the least accepted - * version number and if the condition is not met, this function will - * return a ``NULL``. Pass in 0 to skip the version checking. - */ -NGHTTP3_EXTERN nghttp3_info *nghttp3_version(int least_version); - -#ifdef __cplusplus -} -#endif - -#endif /* NGHTTP3_H */ diff --git a/deps/nghttp3/lib/includes/nghttp3/version.h b/deps/nghttp3/lib/includes/nghttp3/version.h deleted file mode 100644 index 69d29e9f140c33..00000000000000 --- a/deps/nghttp3/lib/includes/nghttp3/version.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2016 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_VERSION_H -#define NGHTTP3_VERSION_H - -/** - * @macro - * - * Version number of the nghttp3 library release. - */ -#define NGHTTP3_VERSION "0.1.0-DEV" - -/** - * @macro - * - * Numerical representation of the version number of the nghttp3 - * library release. This is a 24 bit number with 8 bits for major - * number, 8 bits for minor and 8 bits for patch. Version 1.2.3 - * becomes 0x010203. - */ -#define NGHTTP3_VERSION_NUM 0x000100 - -#endif /* NGHTTP3_VERSION_H */ diff --git a/deps/nghttp3/lib/nghttp3_buf.c b/deps/nghttp3/lib/nghttp3_buf.c deleted file mode 100644 index aae075a73cc4be..00000000000000 --- a/deps/nghttp3/lib/nghttp3_buf.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_buf.h" - -void nghttp3_buf_init(nghttp3_buf *buf) { - buf->begin = buf->end = buf->pos = buf->last = NULL; -} - -void nghttp3_buf_wrap_init(nghttp3_buf *buf, uint8_t *src, size_t len) { - buf->begin = buf->pos = buf->last = src; - buf->end = buf->begin + len; -} - -void nghttp3_buf_free(nghttp3_buf *buf, const nghttp3_mem *mem) { - nghttp3_mem_free(mem, buf->begin); -} - -size_t nghttp3_buf_left(const nghttp3_buf *buf) { - return (size_t)(buf->end - buf->last); -} - -size_t nghttp3_buf_len(const nghttp3_buf *buf) { - return (size_t)(buf->last - buf->pos); -} - -size_t nghttp3_buf_cap(const nghttp3_buf *buf) { - return (size_t)(buf->end - buf->begin); -} - -void nghttp3_buf_reset(nghttp3_buf *buf) { buf->pos = buf->last = buf->begin; } - -int nghttp3_buf_reserve(nghttp3_buf *buf, size_t size, const nghttp3_mem *mem) { - uint8_t *p; - nghttp3_ssize pos_offset, last_offset; - - if ((size_t)(buf->end - buf->begin) >= size) { - return 0; - } - - pos_offset = buf->pos - buf->begin; - last_offset = buf->last - buf->begin; - - p = nghttp3_mem_realloc(mem, buf->begin, size); - if (p == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - buf->begin = p; - buf->end = p + size; - buf->pos = p + pos_offset; - buf->last = p + last_offset; - - return 0; -} - -void nghttp3_buf_swap(nghttp3_buf *a, nghttp3_buf *b) { - nghttp3_buf c = *a; - - *a = *b; - *b = c; -} - -void nghttp3_typed_buf_init(nghttp3_typed_buf *tbuf, const nghttp3_buf *buf, - nghttp3_buf_type type) { - tbuf->buf = *buf; - tbuf->type = type; -} diff --git a/deps/nghttp3/lib/nghttp3_buf.h b/deps/nghttp3/lib/nghttp3_buf.h deleted file mode 100644 index 493d81be315ba1..00000000000000 --- a/deps/nghttp3/lib/nghttp3_buf.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_BUF_H -#define NGHTTP3_BUF_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "nghttp3_mem.h" - -void nghttp3_buf_wrap_init(nghttp3_buf *buf, uint8_t *src, size_t len); - -/* - * nghttp3_buf_cap returns the capacity of the buffer. In other - * words, it returns buf->end - buf->begin. - */ -size_t nghttp3_buf_cap(const nghttp3_buf *buf); - -int nghttp3_buf_reserve(nghttp3_buf *buf, size_t size, const nghttp3_mem *mem); - -/* - * nghttp3_buf_swap swaps |a| and |b|. - */ -void nghttp3_buf_swap(nghttp3_buf *a, nghttp3_buf *b); - -typedef enum { - /* NGHTTP3_BUF_TYPE_PRIVATE indicates that memory is allocated for - this buffer only and should be freed after its use. */ - NGHTTP3_BUF_TYPE_PRIVATE, - /* NGHTTP3_BUF_TYPE_SHARED indicates that buffer points to shared - memory. */ - NGHTTP3_BUF_TYPE_SHARED, - /* NGHTTP3_BUF_TYPE_ALIEN indicates that the buffer points to a - memory which comes from outside of the library. */ - NGHTTP3_BUF_TYPE_ALIEN, -} nghttp3_buf_type; - -typedef struct { - nghttp3_buf buf; - nghttp3_buf_type type; -} nghttp3_typed_buf; - -void nghttp3_typed_buf_init(nghttp3_typed_buf *tbuf, const nghttp3_buf *buf, - nghttp3_buf_type type); - -void nghttp3_typed_buf_free(nghttp3_typed_buf *tbuf); - -#endif /* NGHTTP3_BUF_H */ diff --git a/deps/nghttp3/lib/nghttp3_conn.c b/deps/nghttp3/lib/nghttp3_conn.c deleted file mode 100644 index 3d10f393bf0ff0..00000000000000 --- a/deps/nghttp3/lib/nghttp3_conn.c +++ /dev/null @@ -1,3250 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_conn.h" - -#include -#include -#include - -#include "nghttp3_mem.h" -#include "nghttp3_macro.h" -#include "nghttp3_err.h" -#include "nghttp3_conv.h" -#include "nghttp3_http.h" - -/* - * conn_remote_stream_uni returns nonzero if |stream_id| is remote - * unidirectional stream ID. - */ -static int conn_remote_stream_uni(nghttp3_conn *conn, int64_t stream_id) { - if (conn->server) { - return (stream_id & 0x03) == 0x02; - } - return (stream_id & 0x03) == 0x03; -} - -static int conn_call_begin_headers(nghttp3_conn *conn, nghttp3_stream *stream) { - int rv; - - if (!conn->callbacks.begin_headers) { - return 0; - } - - rv = conn->callbacks.begin_headers(conn, stream->node.nid.id, conn->user_data, - stream->user_data); - if (rv != 0) { - /* TODO Allow ignore headers */ - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_end_headers(nghttp3_conn *conn, nghttp3_stream *stream) { - int rv; - - if (!conn->callbacks.end_headers) { - return 0; - } - - rv = conn->callbacks.end_headers(conn, stream->node.nid.id, conn->user_data, - stream->user_data); - if (rv != 0) { - /* TODO Allow ignore headers */ - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_begin_trailers(nghttp3_conn *conn, - nghttp3_stream *stream) { - int rv; - - if (!conn->callbacks.begin_trailers) { - return 0; - } - - rv = conn->callbacks.begin_trailers(conn, stream->node.nid.id, - conn->user_data, stream->user_data); - if (rv != 0) { - /* TODO Allow ignore headers */ - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_end_trailers(nghttp3_conn *conn, nghttp3_stream *stream) { - int rv; - - if (!conn->callbacks.end_trailers) { - return 0; - } - - rv = conn->callbacks.end_trailers(conn, stream->node.nid.id, conn->user_data, - stream->user_data); - if (rv != 0) { - /* TODO Allow ignore headers */ - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_begin_push_promise(nghttp3_conn *conn, - nghttp3_stream *stream, - int64_t push_id) { - int rv; - - if (!conn->callbacks.begin_push_promise) { - return 0; - } - - rv = conn->callbacks.begin_push_promise(conn, stream->node.nid.id, push_id, - conn->user_data, stream->user_data); - if (rv != 0) { - /* TODO Allow ignore headers */ - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_end_push_promise(nghttp3_conn *conn, - nghttp3_stream *stream, int64_t push_id) { - int rv; - - if (!conn->callbacks.end_push_promise) { - return 0; - } - - rv = conn->callbacks.end_push_promise(conn, stream->node.nid.id, push_id, - conn->user_data, stream->user_data); - if (rv != 0) { - /* TODO Allow ignore headers */ - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_end_stream(nghttp3_conn *conn, nghttp3_stream *stream) { - int rv; - - if (!conn->callbacks.end_stream) { - return 0; - } - - rv = conn->callbacks.end_stream(conn, stream->node.nid.id, conn->user_data, - stream->user_data); - if (rv != 0) { - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_cancel_push(nghttp3_conn *conn, int64_t push_id, - nghttp3_stream *stream) { - int rv; - - if (!conn->callbacks.cancel_push) { - return 0; - } - - rv = conn->callbacks.cancel_push( - conn, push_id, stream ? stream->node.nid.id : -1, conn->user_data, - stream ? stream->user_data : NULL); - if (rv != 0) { - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_send_stop_sending(nghttp3_conn *conn, - nghttp3_stream *stream, - uint64_t app_error_code) { - int rv; - - if (!conn->callbacks.send_stop_sending) { - return 0; - } - - rv = conn->callbacks.send_stop_sending(conn, stream->node.nid.id, - app_error_code, conn->user_data, - stream->user_data); - if (rv != 0) { - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_push_stream(nghttp3_conn *conn, int64_t push_id, - nghttp3_stream *stream) { - int rv; - - if (!conn->callbacks.push_stream) { - return 0; - } - - rv = conn->callbacks.push_stream(conn, push_id, stream->node.nid.id, - conn->user_data); - if (rv != 0) { - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_deferred_consume(nghttp3_conn *conn, - nghttp3_stream *stream, - size_t nconsumed) { - int rv; - - if (nconsumed == 0 || !conn->callbacks.deferred_consume) { - return 0; - } - - rv = conn->callbacks.deferred_consume(conn, stream->node.nid.id, nconsumed, - conn->user_data, stream->user_data); - if (rv != 0) { - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int ricnt_less(const nghttp3_pq_entry *lhsx, - const nghttp3_pq_entry *rhsx) { - nghttp3_stream *lhs = - nghttp3_struct_of(lhsx, nghttp3_stream, qpack_blocked_pe); - nghttp3_stream *rhs = - nghttp3_struct_of(rhsx, nghttp3_stream, qpack_blocked_pe); - - return lhs->qpack_sctx.ricnt < rhs->qpack_sctx.ricnt; -} - -static int cycle_less(const nghttp3_pq_entry *lhsx, - const nghttp3_pq_entry *rhsx) { - const nghttp3_tnode *lhs = nghttp3_struct_of(lhsx, nghttp3_tnode, pe); - const nghttp3_tnode *rhs = nghttp3_struct_of(rhsx, nghttp3_tnode, pe); - - if (lhs->cycle == rhs->cycle) { - return lhs->seq < rhs->seq; - } - - return rhs->cycle - lhs->cycle <= NGHTTP3_TNODE_MAX_CYCLE_GAP; -} - -static int conn_new(nghttp3_conn **pconn, int server, - const nghttp3_conn_callbacks *callbacks, - const nghttp3_conn_settings *settings, - const nghttp3_mem *mem, void *user_data) { - int rv; - nghttp3_conn *conn; - size_t i; - - conn = nghttp3_mem_calloc(mem, 1, sizeof(nghttp3_conn)); - if (conn == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - rv = nghttp3_map_init(&conn->streams, mem); - if (rv != 0) { - goto streams_init_fail; - } - - rv = nghttp3_map_init(&conn->pushes, mem); - if (rv != 0) { - goto pushes_init_fail; - } - - rv = nghttp3_qpack_decoder_init(&conn->qdec, - settings->qpack_max_table_capacity, - settings->qpack_blocked_streams, mem); - if (rv != 0) { - goto qdec_init_fail; - } - - rv = nghttp3_qpack_encoder_init(&conn->qenc, 0, 0, mem); - if (rv != 0) { - goto qenc_init_fail; - } - - nghttp3_pq_init(&conn->qpack_blocked_streams, ricnt_less, mem); - - for (i = 0; i < NGHTTP3_URGENCY_LEVELS; ++i) { - nghttp3_pq_init(&conn->sched[i].spq, cycle_less, mem); - } - - rv = nghttp3_idtr_init(&conn->remote.bidi.idtr, server, mem); - if (rv != 0) { - goto remote_bidi_idtr_init_fail; - } - - rv = nghttp3_gaptr_init(&conn->remote.uni.push_idtr, mem); - if (rv != 0) { - goto push_idtr_init_fail; - } - - conn->callbacks = *callbacks; - conn->local.settings = *settings; - nghttp3_conn_settings_default(&conn->remote.settings); - conn->mem = mem; - conn->user_data = user_data; - conn->next_seq = 0; - conn->server = server; - - *pconn = conn; - - return 0; - -push_idtr_init_fail: - nghttp3_idtr_free(&conn->remote.bidi.idtr); -remote_bidi_idtr_init_fail: - nghttp3_qpack_encoder_free(&conn->qenc); -qenc_init_fail: - nghttp3_qpack_decoder_free(&conn->qdec); -qdec_init_fail: - nghttp3_map_free(&conn->pushes); -pushes_init_fail: - nghttp3_map_free(&conn->streams); -streams_init_fail: - nghttp3_mem_free(mem, conn); - - return rv; -} - -int nghttp3_conn_client_new(nghttp3_conn **pconn, - const nghttp3_conn_callbacks *callbacks, - const nghttp3_conn_settings *settings, - const nghttp3_mem *mem, void *user_data) { - int rv; - - rv = conn_new(pconn, /* server = */ 0, callbacks, settings, mem, user_data); - if (rv != 0) { - return rv; - } - - (*pconn)->remote.uni.unsent_max_pushes = settings->max_pushes; - - return 0; -} - -int nghttp3_conn_server_new(nghttp3_conn **pconn, - const nghttp3_conn_callbacks *callbacks, - const nghttp3_conn_settings *settings, - const nghttp3_mem *mem, void *user_data) { - int rv; - - rv = conn_new(pconn, /* server = */ 1, callbacks, settings, mem, user_data); - if (rv != 0) { - return rv; - } - - return 0; -} - -static int free_push_promise(nghttp3_map_entry *ent, void *ptr) { - nghttp3_push_promise *pp = nghttp3_struct_of(ent, nghttp3_push_promise, me); - const nghttp3_mem *mem = ptr; - - nghttp3_push_promise_del(pp, mem); - - return 0; -} - -static int free_stream(nghttp3_map_entry *ent, void *ptr) { - nghttp3_stream *stream = nghttp3_struct_of(ent, nghttp3_stream, me); - - (void)ptr; - - nghttp3_stream_del(stream); - - return 0; -} - -void nghttp3_conn_del(nghttp3_conn *conn) { - size_t i; - - if (conn == NULL) { - return; - } - - nghttp3_buf_free(&conn->tx.qpack.ebuf, conn->mem); - nghttp3_buf_free(&conn->tx.qpack.rbuf, conn->mem); - - nghttp3_gaptr_free(&conn->remote.uni.push_idtr); - - nghttp3_idtr_free(&conn->remote.bidi.idtr); - - for (i = 0; i < NGHTTP3_URGENCY_LEVELS; ++i) { - nghttp3_pq_free(&conn->sched[i].spq); - } - - nghttp3_pq_free(&conn->qpack_blocked_streams); - - nghttp3_qpack_encoder_free(&conn->qenc); - nghttp3_qpack_decoder_free(&conn->qdec); - - nghttp3_map_each_free(&conn->pushes, free_push_promise, (void *)conn->mem); - nghttp3_map_free(&conn->pushes); - - nghttp3_map_each_free(&conn->streams, free_stream, NULL); - nghttp3_map_free(&conn->streams); - - nghttp3_mem_free(conn->mem, conn); -} - -nghttp3_ssize nghttp3_conn_read_stream(nghttp3_conn *conn, int64_t stream_id, - const uint8_t *src, size_t srclen, - int fin) { - nghttp3_stream *stream; - size_t bidi_nproc; - int rv; - - stream = nghttp3_conn_find_stream(conn, stream_id); - if (stream == NULL) { - /* TODO Assert idtr */ - /* QUIC transport ensures that this is new stream. */ - if (conn->server) { - if (nghttp3_client_stream_bidi(stream_id)) { - rv = nghttp3_idtr_open(&conn->remote.bidi.idtr, stream_id); - assert(rv == 0); - rv = nghttp3_conn_create_stream(conn, &stream, stream_id); - } else { - /* unidirectional stream */ - if (srclen == 0 && fin) { - return 0; - } - - rv = nghttp3_conn_create_stream(conn, &stream, stream_id); - } - if (rv != 0) { - return rv; - } - - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL; - stream->tx.hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL; - } else if (nghttp3_stream_uni(stream_id)) { - if (srclen == 0 && fin) { - return 0; - } - - rv = nghttp3_conn_create_stream(conn, &stream, stream_id); - if (rv != 0) { - return rv; - } - - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_INITIAL; - stream->tx.hstate = NGHTTP3_HTTP_STATE_RESP_INITIAL; - } else { - /* client doesn't expect to receive new bidirectional stream - from server. */ - return NGHTTP3_ERR_H3_STREAM_CREATION_ERROR; - } - } else if (conn->server) { - if (nghttp3_client_stream_bidi(stream_id)) { - if (stream->rx.hstate == NGHTTP3_HTTP_STATE_NONE) { - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL; - stream->tx.hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL; - } - } - } else if (nghttp3_stream_uni(stream_id) && - stream->type == NGHTTP3_STREAM_TYPE_PUSH) { - if (stream->rx.hstate == NGHTTP3_HTTP_STATE_NONE) { - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_INITIAL; - stream->tx.hstate = NGHTTP3_HTTP_STATE_RESP_INITIAL; - } - } - - if (srclen == 0 && !fin) { - return 0; - } - - if (nghttp3_stream_uni(stream_id)) { - return nghttp3_conn_read_uni(conn, stream, src, srclen, fin); - } - - if (fin) { - stream->flags |= NGHTTP3_STREAM_FLAG_READ_EOF; - } - return nghttp3_conn_read_bidi(conn, &bidi_nproc, stream, src, srclen, fin); -} - -static nghttp3_ssize conn_read_type(nghttp3_conn *conn, nghttp3_stream *stream, - const uint8_t *src, size_t srclen, - int fin) { - nghttp3_stream_read_state *rstate = &stream->rstate; - nghttp3_varint_read_state *rvint = &rstate->rvint; - nghttp3_ssize nread; - int64_t stream_type; - - assert(srclen); - - nread = nghttp3_read_varint(rvint, src, srclen, fin); - if (nread < 0) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - - if (rvint->left) { - return nread; - } - - stream_type = rvint->acc; - nghttp3_varint_read_state_reset(rvint); - - switch (stream_type) { - case NGHTTP3_STREAM_TYPE_CONTROL: - if (conn->flags & NGHTTP3_CONN_FLAG_CONTROL_OPENED) { - return NGHTTP3_ERR_H3_STREAM_CREATION_ERROR; - } - conn->flags |= NGHTTP3_CONN_FLAG_CONTROL_OPENED; - stream->type = NGHTTP3_STREAM_TYPE_CONTROL; - rstate->state = NGHTTP3_CTRL_STREAM_STATE_FRAME_TYPE; - break; - case NGHTTP3_STREAM_TYPE_PUSH: - if (conn->server) { - return NGHTTP3_ERR_H3_STREAM_CREATION_ERROR; - } - stream->type = NGHTTP3_STREAM_TYPE_PUSH; - rstate->state = NGHTTP3_PUSH_STREAM_STATE_PUSH_ID; - break; - case NGHTTP3_STREAM_TYPE_QPACK_ENCODER: - if (conn->flags & NGHTTP3_CONN_FLAG_QPACK_ENCODER_OPENED) { - return NGHTTP3_ERR_H3_STREAM_CREATION_ERROR; - } - conn->flags |= NGHTTP3_CONN_FLAG_QPACK_ENCODER_OPENED; - stream->type = NGHTTP3_STREAM_TYPE_QPACK_ENCODER; - break; - case NGHTTP3_STREAM_TYPE_QPACK_DECODER: - if (conn->flags & NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED) { - return NGHTTP3_ERR_H3_STREAM_CREATION_ERROR; - } - conn->flags |= NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED; - stream->type = NGHTTP3_STREAM_TYPE_QPACK_DECODER; - break; - default: - stream->type = NGHTTP3_STREAM_TYPE_UNKNOWN; - break; - } - - stream->flags |= NGHTTP3_STREAM_FLAG_TYPE_IDENTIFIED; - - return nread; -} - -static int conn_delete_stream(nghttp3_conn *conn, nghttp3_stream *stream); - -nghttp3_ssize nghttp3_conn_read_uni(nghttp3_conn *conn, nghttp3_stream *stream, - const uint8_t *src, size_t srclen, - int fin) { - nghttp3_ssize nread = 0; - nghttp3_ssize nconsumed = 0; - size_t push_nproc; - int rv; - - assert(srclen || fin); - - if (!(stream->flags & NGHTTP3_STREAM_FLAG_TYPE_IDENTIFIED)) { - if (srclen == 0 && fin) { - /* Ignore stream if it is closed before reading stream header. - If it is closed while reading it, return error, making it - consistent in our code base. */ - if (stream->rstate.rvint.left) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - - rv = conn_delete_stream(conn, stream); - assert(0 == rv); - - return 0; - } - nread = conn_read_type(conn, stream, src, srclen, fin); - if (nread < 0) { - return (int)nread; - } - if (!(stream->flags & NGHTTP3_STREAM_FLAG_TYPE_IDENTIFIED)) { - assert((size_t)nread == srclen); - return (nghttp3_ssize)srclen; - } - - src += nread; - srclen -= (size_t)nread; - - if (srclen == 0) { - return nread; - } - } - - switch (stream->type) { - case NGHTTP3_STREAM_TYPE_CONTROL: - if (fin) { - return NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM; - } - nconsumed = nghttp3_conn_read_control(conn, stream, src, srclen); - break; - case NGHTTP3_STREAM_TYPE_PUSH: - if (fin) { - stream->flags |= NGHTTP3_STREAM_FLAG_READ_EOF; - } - nconsumed = - nghttp3_conn_read_push(conn, &push_nproc, stream, src, srclen, fin); - break; - case NGHTTP3_STREAM_TYPE_QPACK_ENCODER: - if (fin) { - return NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM; - } - nconsumed = nghttp3_conn_read_qpack_encoder(conn, src, srclen); - break; - case NGHTTP3_STREAM_TYPE_QPACK_DECODER: - if (fin) { - return NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM; - } - nconsumed = nghttp3_conn_read_qpack_decoder(conn, src, srclen); - break; - case NGHTTP3_STREAM_TYPE_UNKNOWN: - nconsumed = (nghttp3_ssize)srclen; - - rv = conn_call_send_stop_sending(conn, stream, - NGHTTP3_H3_STREAM_CREATION_ERROR); - if (rv != 0) { - return rv; - } - break; - default: - /* unreachable */ - assert(0); - } - - if (nconsumed < 0) { - return nconsumed; - } - - return nread + nconsumed; -} - -static int frame_fin(nghttp3_stream_read_state *rstate, size_t len) { - return (int64_t)len >= rstate->left; -} - -nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn, - nghttp3_stream *stream, - const uint8_t *src, size_t srclen) { - const uint8_t *p = src, *end = src + srclen; - int rv; - nghttp3_stream_read_state *rstate = &stream->rstate; - nghttp3_varint_read_state *rvint = &rstate->rvint; - nghttp3_ssize nread; - size_t nconsumed = 0; - int busy = 0; - size_t len; - - assert(srclen); - - for (; p != end || busy;) { - busy = 0; - switch (rstate->state) { - case NGHTTP3_CTRL_STREAM_STATE_FRAME_TYPE: - assert(end - p > 0); - nread = nghttp3_read_varint(rvint, p, (size_t)(end - p), /* fin = */ 0); - if (nread < 0) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - if (rvint->left) { - return (nghttp3_ssize)nconsumed; - } - - rstate->fr.hd.type = rvint->acc; - nghttp3_varint_read_state_reset(rvint); - rstate->state = NGHTTP3_CTRL_STREAM_STATE_FRAME_LENGTH; - if (p == end) { - break; - } - /* Fall through */ - case NGHTTP3_CTRL_STREAM_STATE_FRAME_LENGTH: - assert(end - p > 0); - nread = nghttp3_read_varint(rvint, p, (size_t)(end - p), /* fin = */ 0); - if (nread < 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - if (rvint->left) { - return (nghttp3_ssize)nconsumed; - } - - rstate->left = rstate->fr.hd.length = rvint->acc; - nghttp3_varint_read_state_reset(rvint); - - if (!(conn->flags & NGHTTP3_CONN_FLAG_SETTINGS_RECVED)) { - if (rstate->fr.hd.type != NGHTTP3_FRAME_SETTINGS) { - return NGHTTP3_ERR_H3_MISSING_SETTINGS; - } - conn->flags |= NGHTTP3_CONN_FLAG_SETTINGS_RECVED; - } else if (rstate->fr.hd.type == NGHTTP3_FRAME_SETTINGS) { - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - - switch (rstate->fr.hd.type) { - case NGHTTP3_FRAME_CANCEL_PUSH: - if (rstate->left == 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - rstate->state = NGHTTP3_CTRL_STREAM_STATE_CANCEL_PUSH; - break; - case NGHTTP3_FRAME_SETTINGS: - /* SETTINGS frame might be empty. */ - if (rstate->left == 0) { - nghttp3_stream_read_state_reset(rstate); - break; - } - rstate->state = NGHTTP3_CTRL_STREAM_STATE_SETTINGS; - break; - case NGHTTP3_FRAME_GOAWAY: - if (rstate->left == 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - rstate->state = NGHTTP3_CTRL_STREAM_STATE_GOAWAY; - break; - case NGHTTP3_FRAME_MAX_PUSH_ID: - if (!conn->server) { - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - if (rstate->left == 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - rstate->state = NGHTTP3_CTRL_STREAM_STATE_MAX_PUSH_ID; - break; - case NGHTTP3_FRAME_DATA: - case NGHTTP3_FRAME_HEADERS: - case NGHTTP3_FRAME_PUSH_PROMISE: - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - default: - /* TODO Handle reserved frame type */ - busy = 1; - rstate->state = NGHTTP3_CTRL_STREAM_STATE_IGN_FRAME; - break; - } - break; - case NGHTTP3_CTRL_STREAM_STATE_CANCEL_PUSH: - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - assert(len > 0); - nread = nghttp3_read_varint(rvint, p, len, frame_fin(rstate, len)); - if (nread < 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - rstate->left -= nread; - if (rvint->left) { - return (nghttp3_ssize)nconsumed; - } - rstate->fr.cancel_push.push_id = rvint->acc; - nghttp3_varint_read_state_reset(rvint); - - if (conn->server) { - rv = nghttp3_conn_on_server_cancel_push(conn, &rstate->fr.cancel_push); - } else { - rv = nghttp3_conn_on_client_cancel_push(conn, &rstate->fr.cancel_push); - } - if (rv != 0) { - return rv; - } - - nghttp3_stream_read_state_reset(rstate); - break; - case NGHTTP3_CTRL_STREAM_STATE_SETTINGS: - for (; p != end;) { - if (rstate->left == 0) { - nghttp3_stream_read_state_reset(rstate); - break; - } - /* Read Identifier */ - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - assert(len > 0); - nread = nghttp3_read_varint(rvint, p, len, frame_fin(rstate, len)); - if (nread < 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - rstate->left -= nread; - if (rvint->left) { - rstate->state = NGHTTP3_CTRL_STREAM_STATE_SETTINGS_ID; - return (nghttp3_ssize)nconsumed; - } - rstate->fr.settings.iv[0].id = (uint64_t)rvint->acc; - nghttp3_varint_read_state_reset(rvint); - - /* Read Value */ - if (rstate->left == 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - len -= (size_t)nread; - if (len == 0) { - rstate->state = NGHTTP3_CTRL_STREAM_STATE_SETTINGS_VALUE; - break; - } - - nread = nghttp3_read_varint(rvint, p, len, frame_fin(rstate, len)); - if (nread < 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - rstate->left -= nread; - if (rvint->left) { - rstate->state = NGHTTP3_CTRL_STREAM_STATE_SETTINGS_VALUE; - return (nghttp3_ssize)nconsumed; - } - rstate->fr.settings.iv[0].value = (uint64_t)rvint->acc; - nghttp3_varint_read_state_reset(rvint); - - rv = - nghttp3_conn_on_settings_entry_received(conn, &rstate->fr.settings); - if (rv != 0) { - return rv; - } - } - break; - case NGHTTP3_CTRL_STREAM_STATE_SETTINGS_ID: - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - assert(len > 0); - nread = nghttp3_read_varint(rvint, p, len, frame_fin(rstate, len)); - if (nread < 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - rstate->left -= nread; - if (rvint->left) { - return (nghttp3_ssize)nconsumed; - } - rstate->fr.settings.iv[0].id = (uint64_t)rvint->acc; - nghttp3_varint_read_state_reset(rvint); - - if (rstate->left == 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - rstate->state = NGHTTP3_CTRL_STREAM_STATE_SETTINGS_VALUE; - - if (p == end) { - return (nghttp3_ssize)nconsumed; - } - /* Fall through */ - case NGHTTP3_CTRL_STREAM_STATE_SETTINGS_VALUE: - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - assert(len > 0); - nread = nghttp3_read_varint(rvint, p, len, frame_fin(rstate, len)); - if (nread < 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - rstate->left -= nread; - if (rvint->left) { - return (nghttp3_ssize)nconsumed; - } - rstate->fr.settings.iv[0].value = (uint64_t)rvint->acc; - nghttp3_varint_read_state_reset(rvint); - - rv = nghttp3_conn_on_settings_entry_received(conn, &rstate->fr.settings); - if (rv != 0) { - return rv; - } - - if (rstate->left) { - rstate->state = NGHTTP3_CTRL_STREAM_STATE_SETTINGS; - break; - } - - nghttp3_stream_read_state_reset(rstate); - break; - case NGHTTP3_CTRL_STREAM_STATE_GOAWAY: - /* TODO Not implemented yet */ - rstate->state = NGHTTP3_CTRL_STREAM_STATE_IGN_FRAME; - break; - case NGHTTP3_CTRL_STREAM_STATE_MAX_PUSH_ID: - /* server side only */ - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - assert(len > 0); - nread = nghttp3_read_varint(rvint, p, len, frame_fin(rstate, len)); - if (nread < 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - rstate->left -= nread; - if (rvint->left) { - return (nghttp3_ssize)nconsumed; - } - - if (conn->local.uni.max_pushes > (uint64_t)rvint->acc) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - conn->local.uni.max_pushes = (uint64_t)rvint->acc; - nghttp3_varint_read_state_reset(rvint); - - nghttp3_stream_read_state_reset(rstate); - break; - case NGHTTP3_CTRL_STREAM_STATE_IGN_FRAME: - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - p += len; - nconsumed += len; - rstate->left -= (int64_t)len; - - if (rstate->left) { - return (nghttp3_ssize)nconsumed; - } - - nghttp3_stream_read_state_reset(rstate); - break; - default: - /* unreachable */ - assert(0); - } - } - - return (nghttp3_ssize)nconsumed; -} - -nghttp3_ssize nghttp3_conn_read_push(nghttp3_conn *conn, size_t *pnproc, - nghttp3_stream *stream, const uint8_t *src, - size_t srclen, int fin) { - const uint8_t *p = src, *end = src ? src + srclen : src; - int rv; - nghttp3_stream_read_state *rstate = &stream->rstate; - nghttp3_varint_read_state *rvint = &rstate->rvint; - nghttp3_ssize nread; - size_t nconsumed = 0; - int busy = 0; - size_t len; - int64_t push_id; - - if (stream->pp && - (stream->pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_SENT_CANCEL)) { - *pnproc = srclen; - return (nghttp3_ssize)srclen; - } - - if (stream->flags & (NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED | - NGHTTP3_STREAM_FLAG_PUSH_PROMISE_BLOCKED)) { - *pnproc = 0; - - if (srclen == 0) { - return 0; - } - - rv = nghttp3_stream_buffer_data(stream, p, (size_t)(end - p)); - if (rv != 0) { - return rv; - } - return 0; - } - - for (; p != end || busy;) { - busy = 0; - switch (rstate->state) { - case NGHTTP3_PUSH_STREAM_STATE_PUSH_ID: - assert(end - p > 0); - nread = nghttp3_read_varint(rvint, p, (size_t)(end - p), fin); - if (nread < 0) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - if (rvint->left) { - goto almost_done; - } - - push_id = rvint->acc; - nghttp3_varint_read_state_reset(rvint); - - rv = nghttp3_conn_on_stream_push_id(conn, stream, push_id); - if (rv != 0) { - if (rv == NGHTTP3_ERR_IGNORE_STREAM) { - rstate->state = NGHTTP3_PUSH_STREAM_STATE_IGN_REST; - break; - } - return (nghttp3_ssize)rv; - } - - rstate->state = NGHTTP3_PUSH_STREAM_STATE_FRAME_TYPE; - - if (stream->flags & NGHTTP3_STREAM_FLAG_PUSH_PROMISE_BLOCKED) { - if (p != end) { - rv = nghttp3_stream_buffer_data(stream, p, (size_t)(end - p)); - if (rv != 0) { - return rv; - } - } - *pnproc = (size_t)(p - src); - return (nghttp3_ssize)nconsumed; - } - - if (end == p) { - goto almost_done; - } - - /* Fall through */ - case NGHTTP3_PUSH_STREAM_STATE_FRAME_TYPE: - assert(end - p > 0); - nread = nghttp3_read_varint(rvint, p, (size_t)(end - p), fin); - if (nread < 0) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - if (rvint->left) { - goto almost_done; - } - - rstate->fr.hd.type = rvint->acc; - nghttp3_varint_read_state_reset(rvint); - rstate->state = NGHTTP3_PUSH_STREAM_STATE_FRAME_LENGTH; - if (p == end) { - goto almost_done; - } - /* Fall through */ - case NGHTTP3_PUSH_STREAM_STATE_FRAME_LENGTH: - assert(end - p > 0); - nread = nghttp3_read_varint(rvint, p, (size_t)(end - p), fin); - if (nread < 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - if (rvint->left) { - goto almost_done; - } - - rstate->left = rstate->fr.hd.length = rvint->acc; - nghttp3_varint_read_state_reset(rvint); - - switch (rstate->fr.hd.type) { - case NGHTTP3_FRAME_DATA: - rv = nghttp3_stream_transit_rx_http_state( - stream, NGHTTP3_HTTP_EVENT_DATA_BEGIN); - if (rv != 0) { - return rv; - } - /* DATA frame might be empty. */ - if (rstate->left == 0) { - rv = nghttp3_stream_transit_rx_http_state( - stream, NGHTTP3_HTTP_EVENT_DATA_END); - assert(0 == rv); - - nghttp3_stream_read_state_reset(rstate); - break; - } - rstate->state = NGHTTP3_PUSH_STREAM_STATE_DATA; - break; - case NGHTTP3_FRAME_HEADERS: - rv = nghttp3_stream_transit_rx_http_state( - stream, NGHTTP3_HTTP_EVENT_HEADERS_BEGIN); - if (rv != 0) { - return rv; - } - if (rstate->left == 0) { - rv = nghttp3_stream_empty_headers_allowed(stream); - if (rv != 0) { - return rv; - } - - rv = nghttp3_stream_transit_rx_http_state( - stream, NGHTTP3_HTTP_EVENT_HEADERS_END); - assert(0 == rv); - - nghttp3_stream_read_state_reset(rstate); - break; - } - - switch (stream->rx.hstate) { - case NGHTTP3_HTTP_STATE_RESP_HEADERS_BEGIN: - rv = conn_call_begin_headers(conn, stream); - break; - case NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN: - rv = conn_call_begin_trailers(conn, stream); - break; - default: - /* Unreachable */ - assert(0); - } - - if (rv != 0) { - return rv; - } - - rstate->state = NGHTTP3_PUSH_STREAM_STATE_HEADERS; - break; - case NGHTTP3_FRAME_PUSH_PROMISE: - case NGHTTP3_FRAME_CANCEL_PUSH: - case NGHTTP3_FRAME_SETTINGS: - case NGHTTP3_FRAME_GOAWAY: - case NGHTTP3_FRAME_MAX_PUSH_ID: - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - default: - /* TODO Handle reserved frame type */ - busy = 1; - rstate->state = NGHTTP3_PUSH_STREAM_STATE_IGN_FRAME; - break; - } - break; - case NGHTTP3_PUSH_STREAM_STATE_DATA: - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - rv = nghttp3_conn_on_data(conn, stream, p, len); - if (rv != 0) { - return rv; - } - - p += len; - rstate->left -= (int64_t)len; - - if (rstate->left) { - goto almost_done; - } - - rv = nghttp3_stream_transit_rx_http_state(stream, - NGHTTP3_HTTP_EVENT_DATA_END); - assert(0 == rv); - - nghttp3_stream_read_state_reset(rstate); - break; - case NGHTTP3_PUSH_STREAM_STATE_HEADERS: - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - nread = nghttp3_conn_on_headers(conn, stream, NULL, p, len, - (int64_t)len == rstate->left); - if (nread < 0) { - return nread; - } - - p += nread; - nconsumed += (size_t)nread; - rstate->left -= nread; - - if (stream->flags & NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED) { - if (p != end && nghttp3_stream_get_buffered_datalen(stream) == 0) { - rv = nghttp3_stream_buffer_data(stream, p, (size_t)(end - p)); - if (rv != 0) { - return rv; - } - } - *pnproc = (size_t)(p - src); - return (nghttp3_ssize)nconsumed; - } - - if (rstate->left) { - goto almost_done; - } - - switch (stream->rx.hstate) { - case NGHTTP3_HTTP_STATE_RESP_HEADERS_BEGIN: - rv = nghttp3_http_on_response_headers(&stream->rx.http); - if (rv != 0) { - return rv; - } - - rv = conn_call_end_headers(conn, stream); - break; - case NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN: - rv = conn_call_end_trailers(conn, stream); - break; - default: - /* Unreachable */ - assert(0); - } - - if (rv != 0) { - return rv; - } - - rv = nghttp3_stream_transit_rx_http_state(stream, - NGHTTP3_HTTP_EVENT_HEADERS_END); - assert(0 == rv); - - nghttp3_stream_read_state_reset(rstate); - break; - case NGHTTP3_PUSH_STREAM_STATE_IGN_FRAME: - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - p += len; - nconsumed += len; - rstate->left -= (int64_t)len; - - if (rstate->left) { - goto almost_done; - } - - nghttp3_stream_read_state_reset(rstate); - break; - case NGHTTP3_PUSH_STREAM_STATE_IGN_REST: - nconsumed += (size_t)(end - p); - *pnproc = (size_t)(p - src); - return (nghttp3_ssize)nconsumed; - } - } - -almost_done: - if (fin) { - switch (rstate->state) { - case NGHTTP3_PUSH_STREAM_STATE_FRAME_TYPE: - if (rvint->left) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - rv = nghttp3_stream_transit_rx_http_state(stream, - NGHTTP3_HTTP_EVENT_MSG_END); - if (rv != 0) { - return rv; - } - break; - case NGHTTP3_PUSH_STREAM_STATE_IGN_REST: - break; - default: - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - } - - *pnproc = (size_t)(p - src); - return (nghttp3_ssize)nconsumed; -} - -static void conn_delete_push_promise(nghttp3_conn *conn, - nghttp3_push_promise *pp) { - int rv; - - rv = nghttp3_map_remove(&conn->pushes, (key_type)pp->node.nid.id); - assert(0 == rv); - - if (!conn->server && - !(pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_PUSH_ID_RECLAIMED)) { - ++conn->remote.uni.unsent_max_pushes; - } - - nghttp3_push_promise_del(pp, conn->mem); -} - -static int conn_delete_stream(nghttp3_conn *conn, nghttp3_stream *stream) { - int rv; - - if (nghttp3_stream_bidi_or_push(stream)) { - rv = nghttp3_http_on_remote_end_stream(stream); - if (rv != 0) { - return rv; - } - } - - rv = conn_call_deferred_consume(conn, stream, - nghttp3_stream_get_buffered_datalen(stream)); - if (rv != 0) { - return rv; - } - - if (conn->callbacks.stream_close) { - rv = conn->callbacks.stream_close(conn, stream->node.nid.id, - stream->error_code, conn->user_data, - stream->user_data); - if (rv != 0) { - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - } - - rv = nghttp3_map_remove(&conn->streams, (key_type)stream->node.nid.id); - - assert(0 == rv); - - if (stream->pp) { - assert(stream->type == NGHTTP3_STREAM_TYPE_PUSH); - - conn_delete_push_promise(conn, stream->pp); - } - - nghttp3_stream_del(stream); - - return 0; -} - -static int conn_process_blocked_stream_data(nghttp3_conn *conn, - nghttp3_stream *stream) { - nghttp3_buf *buf; - size_t nproc; - nghttp3_ssize nconsumed; - int rv; - size_t len; - - for (;;) { - len = nghttp3_ringbuf_len(&stream->inq); - if (len == 0) { - break; - } - buf = nghttp3_ringbuf_get(&stream->inq, 0); - if (nghttp3_stream_uni(stream->node.nid.id)) { - nconsumed = nghttp3_conn_read_push( - conn, &nproc, stream, buf->pos, nghttp3_buf_len(buf), - len == 1 && (stream->flags & NGHTTP3_STREAM_FLAG_READ_EOF)); - } else { - nconsumed = nghttp3_conn_read_bidi( - conn, &nproc, stream, buf->pos, nghttp3_buf_len(buf), - len == 1 && (stream->flags & NGHTTP3_STREAM_FLAG_READ_EOF)); - } - if (nconsumed < 0) { - return (int)nconsumed; - } - - buf->pos += nproc; - - rv = conn_call_deferred_consume(conn, stream, (size_t)nconsumed); - if (rv != 0) { - return 0; - } - - if (nghttp3_buf_len(buf) == 0) { - nghttp3_buf_free(buf, stream->mem); - nghttp3_ringbuf_pop_front(&stream->inq); - } - - if (stream->flags & NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED) { - break; - } - } - - if (!(stream->flags & NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED) && - (stream->flags & NGHTTP3_STREAM_FLAG_CLOSED)) { - assert(stream->qpack_blocked_pe.index == NGHTTP3_PQ_BAD_INDEX); - - rv = conn_delete_stream(conn, stream); - if (rv != 0) { - return rv; - } - } - - return 0; -} - -nghttp3_ssize nghttp3_conn_read_qpack_encoder(nghttp3_conn *conn, - const uint8_t *src, - size_t srclen) { - nghttp3_ssize nconsumed = - nghttp3_qpack_decoder_read_encoder(&conn->qdec, src, srclen); - nghttp3_stream *stream; - int rv; - - if (nconsumed < 0) { - return nconsumed; - } - - for (; !nghttp3_pq_empty(&conn->qpack_blocked_streams);) { - stream = nghttp3_struct_of(nghttp3_pq_top(&conn->qpack_blocked_streams), - nghttp3_stream, qpack_blocked_pe); - if (nghttp3_qpack_stream_context_get_ricnt(&stream->qpack_sctx) > - nghttp3_qpack_decoder_get_icnt(&conn->qdec)) { - break; - } - - nghttp3_conn_qpack_blocked_streams_pop(conn); - stream->qpack_blocked_pe.index = NGHTTP3_PQ_BAD_INDEX; - stream->flags &= (uint16_t)~NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED; - - rv = conn_process_blocked_stream_data(conn, stream); - if (rv != 0) { - return rv; - } - } - - return nconsumed; -} - -nghttp3_ssize nghttp3_conn_read_qpack_decoder(nghttp3_conn *conn, - const uint8_t *src, - size_t srclen) { - return nghttp3_qpack_encoder_read_decoder(&conn->qenc, src, srclen); -} - -static int conn_update_stream_priority(nghttp3_conn *conn, - nghttp3_stream *stream, uint8_t pri) { - if (stream->node.pri == pri) { - return 0; - } - - nghttp3_conn_unschedule_stream(conn, stream); - - stream->node.pri = pri; - - assert(nghttp3_stream_bidi_or_push(stream)); - - if (nghttp3_stream_require_schedule(stream)) { - return nghttp3_conn_schedule_stream(conn, stream); - } - - return 0; -} - -nghttp3_ssize nghttp3_conn_read_bidi(nghttp3_conn *conn, size_t *pnproc, - nghttp3_stream *stream, const uint8_t *src, - size_t srclen, int fin) { - const uint8_t *p = src, *end = src ? src + srclen : src; - int rv; - nghttp3_stream_read_state *rstate = &stream->rstate; - nghttp3_varint_read_state *rvint = &rstate->rvint; - nghttp3_ssize nread; - size_t nconsumed = 0; - int busy = 0; - size_t len; - nghttp3_push_promise *pp; - nghttp3_push_promise fake_pp = {{0}, {{0}, 0, {0}, 0, 0, 0}, {0}, NULL, -1, - 0}; - - if (stream->flags & NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED) { - *pnproc = 0; - - if (srclen == 0) { - return 0; - } - - rv = nghttp3_stream_buffer_data(stream, p, (size_t)(end - p)); - if (rv != 0) { - return rv; - } - return 0; - } - - for (; p != end || busy;) { - busy = 0; - switch (rstate->state) { - case NGHTTP3_REQ_STREAM_STATE_FRAME_TYPE: - assert(end - p > 0); - nread = nghttp3_read_varint(rvint, p, (size_t)(end - p), fin); - if (nread < 0) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - if (rvint->left) { - goto almost_done; - } - - rstate->fr.hd.type = rvint->acc; - nghttp3_varint_read_state_reset(rvint); - rstate->state = NGHTTP3_REQ_STREAM_STATE_FRAME_LENGTH; - if (p == end) { - goto almost_done; - } - /* Fall through */ - case NGHTTP3_REQ_STREAM_STATE_FRAME_LENGTH: - assert(end - p > 0); - nread = nghttp3_read_varint(rvint, p, (size_t)(end - p), fin); - if (nread < 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - if (rvint->left) { - goto almost_done; - } - - rstate->left = rstate->fr.hd.length = rvint->acc; - nghttp3_varint_read_state_reset(rvint); - - switch (rstate->fr.hd.type) { - case NGHTTP3_FRAME_DATA: - rv = nghttp3_stream_transit_rx_http_state( - stream, NGHTTP3_HTTP_EVENT_DATA_BEGIN); - if (rv != 0) { - return rv; - } - /* DATA frame might be empty. */ - if (rstate->left == 0) { - rv = nghttp3_stream_transit_rx_http_state( - stream, NGHTTP3_HTTP_EVENT_DATA_END); - assert(0 == rv); - - nghttp3_stream_read_state_reset(rstate); - break; - } - rstate->state = NGHTTP3_REQ_STREAM_STATE_DATA; - break; - case NGHTTP3_FRAME_HEADERS: - rv = nghttp3_stream_transit_rx_http_state( - stream, NGHTTP3_HTTP_EVENT_HEADERS_BEGIN); - if (rv != 0) { - return rv; - } - if (rstate->left == 0) { - rv = nghttp3_stream_empty_headers_allowed(stream); - if (rv != 0) { - return rv; - } - - rv = nghttp3_stream_transit_rx_http_state( - stream, NGHTTP3_HTTP_EVENT_HEADERS_END); - assert(0 == rv); - - nghttp3_stream_read_state_reset(rstate); - break; - } - - switch (stream->rx.hstate) { - case NGHTTP3_HTTP_STATE_REQ_HEADERS_BEGIN: - case NGHTTP3_HTTP_STATE_RESP_HEADERS_BEGIN: - rv = conn_call_begin_headers(conn, stream); - break; - case NGHTTP3_HTTP_STATE_REQ_TRAILERS_BEGIN: - case NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN: - rv = conn_call_begin_trailers(conn, stream); - break; - default: - /* Unreachable */ - assert(0); - } - - if (rv != 0) { - return rv; - } - - rstate->state = NGHTTP3_REQ_STREAM_STATE_HEADERS; - break; - case NGHTTP3_FRAME_PUSH_PROMISE: - if (conn->server) { - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - - if (rstate->left == 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - /* No stream->rx.hstate change with PUSH_PROMISE */ - - rstate->state = NGHTTP3_REQ_STREAM_STATE_PUSH_PROMISE_PUSH_ID; - break; - case NGHTTP3_FRAME_CANCEL_PUSH: - case NGHTTP3_FRAME_SETTINGS: - case NGHTTP3_FRAME_GOAWAY: - case NGHTTP3_FRAME_MAX_PUSH_ID: - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - default: - /* TODO Handle reserved frame type */ - busy = 1; - rstate->state = NGHTTP3_REQ_STREAM_STATE_IGN_FRAME; - break; - } - break; - case NGHTTP3_REQ_STREAM_STATE_DATA: - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - rv = nghttp3_conn_on_data(conn, stream, p, len); - if (rv != 0) { - return rv; - } - p += len; - rstate->left -= (int64_t)len; - - if (rstate->left) { - goto almost_done; - } - - rv = nghttp3_stream_transit_rx_http_state(stream, - NGHTTP3_HTTP_EVENT_DATA_END); - assert(0 == rv); - - nghttp3_stream_read_state_reset(rstate); - break; - case NGHTTP3_REQ_STREAM_STATE_PUSH_PROMISE_PUSH_ID: - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - nread = nghttp3_read_varint(rvint, p, (size_t)(end - p), - (int64_t)len == rstate->left); - if (nread < 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - p += nread; - nconsumed += (size_t)nread; - rstate->left -= nread; - if (rvint->left) { - goto almost_done; - } - - rstate->fr.push_promise.push_id = rvint->acc; - nghttp3_varint_read_state_reset(rvint); - - if (rstate->left == 0) { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - rv = nghttp3_conn_on_push_promise_push_id( - conn, rstate->fr.push_promise.push_id, stream); - if (rv != 0) { - if (rv == NGHTTP3_ERR_IGNORE_PUSH_PROMISE) { - rstate->state = NGHTTP3_REQ_STREAM_STATE_IGN_PUSH_PROMISE; - if (p == end) { - goto almost_done; - } - break; - } - - return rv; - } - - rstate->state = NGHTTP3_REQ_STREAM_STATE_PUSH_PROMISE; - - if (p == end) { - goto almost_done; - } - /* Fall through */ - case NGHTTP3_REQ_STREAM_STATE_PUSH_PROMISE: - pp = - nghttp3_conn_find_push_promise(conn, rstate->fr.push_promise.push_id); - - assert(pp); - - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - nread = nghttp3_conn_on_headers(conn, stream, pp, p, len, - (int64_t)len == rstate->left); - if (nread < 0) { - return nread; - } - - p += nread; - nconsumed += (size_t)nread; - rstate->left -= nread; - - if (stream->flags & NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED) { - if (p != end && nghttp3_stream_get_buffered_datalen(stream) == 0) { - rv = nghttp3_stream_buffer_data(stream, p, (size_t)(end - p)); - if (rv != 0) { - return rv; - } - } - *pnproc = (size_t)(p - src); - return (nghttp3_ssize)nconsumed; - } - - if (rstate->left) { - goto almost_done; - } - - rv = nghttp3_http_on_request_headers(&pp->http); - if (rv != 0) { - return rv; - } - - pp->flags |= NGHTTP3_PUSH_PROMISE_FLAG_RECVED; - - rv = conn_call_end_push_promise(conn, stream, pp->node.nid.id); - if (rv != 0) { - return rv; - } - - if (!pp->stream && (pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_CANCELLED)) { - if (pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_RECV_CANCEL) { - rv = conn_call_cancel_push(conn, pp->node.nid.id, pp->stream); - if (rv != 0) { - return rv; - } - } - - conn_delete_push_promise(conn, pp); - - nghttp3_stream_read_state_reset(rstate); - break; - } - - if (pp->stream) { - ++conn->remote.uni.unsent_max_pushes; - pp->flags |= NGHTTP3_PUSH_PROMISE_FLAG_PUSH_ID_RECLAIMED; - - if (!(pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_SENT_CANCEL)) { - assert(pp->stream->flags & NGHTTP3_STREAM_FLAG_PUSH_PROMISE_BLOCKED); - - rv = conn_call_push_stream(conn, pp->node.nid.id, pp->stream); - if (rv != 0) { - return rv; - } - - pp->stream->flags &= - (uint16_t)~NGHTTP3_STREAM_FLAG_PUSH_PROMISE_BLOCKED; - - rv = conn_process_blocked_stream_data(conn, pp->stream); - if (rv != 0) { - return rv; - } - } - } - - nghttp3_stream_read_state_reset(rstate); - break; - case NGHTTP3_REQ_STREAM_STATE_IGN_PUSH_PROMISE: - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - nread = nghttp3_conn_on_headers(conn, stream, &fake_pp, p, len, - (int64_t)len == rstate->left); - if (nread < 0) { - return nread; - } - - p += nread; - nconsumed += (size_t)nread; - rstate->left -= nread; - - if (stream->flags & NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED) { - if (p != end && nghttp3_stream_get_buffered_datalen(stream) == 0) { - rv = nghttp3_stream_buffer_data(stream, p, (size_t)(end - p)); - if (rv != 0) { - return rv; - } - } - *pnproc = (size_t)(p - src); - return (nghttp3_ssize)nconsumed; - } - - if (rstate->left) { - goto almost_done; - } - - nghttp3_stream_read_state_reset(rstate); - break; - case NGHTTP3_REQ_STREAM_STATE_HEADERS: - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - nread = nghttp3_conn_on_headers(conn, stream, NULL, p, len, - (int64_t)len == rstate->left); - if (nread < 0) { - return nread; - } - - p += nread; - nconsumed += (size_t)nread; - rstate->left -= nread; - - if (stream->flags & NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED) { - if (p != end && nghttp3_stream_get_buffered_datalen(stream) == 0) { - rv = nghttp3_stream_buffer_data(stream, p, (size_t)(end - p)); - if (rv != 0) { - return rv; - } - } - *pnproc = (size_t)(p - src); - return (nghttp3_ssize)nconsumed; - } - - if (rstate->left) { - goto almost_done; - } - - switch (stream->rx.hstate) { - case NGHTTP3_HTTP_STATE_REQ_HEADERS_BEGIN: - rv = nghttp3_http_on_request_headers(&stream->rx.http); - break; - case NGHTTP3_HTTP_STATE_RESP_HEADERS_BEGIN: - rv = nghttp3_http_on_response_headers(&stream->rx.http); - break; - case NGHTTP3_HTTP_STATE_REQ_TRAILERS_BEGIN: - case NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN: - rv = 0; - break; - default: - /* Unreachable */ - assert(0); - } - - if (rv != 0) { - return rv; - } - - switch (stream->rx.hstate) { - case NGHTTP3_HTTP_STATE_REQ_HEADERS_BEGIN: - /* Only server utilizes priority information to schedule - streams. */ - if (conn->server) { - rv = conn_update_stream_priority(conn, stream, stream->rx.http.pri); - if (rv != 0) { - return rv; - } - } - /* fall through */ - case NGHTTP3_HTTP_STATE_RESP_HEADERS_BEGIN: - rv = conn_call_end_headers(conn, stream); - break; - case NGHTTP3_HTTP_STATE_REQ_TRAILERS_BEGIN: - case NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN: - rv = conn_call_end_trailers(conn, stream); - break; - default: - /* Unreachable */ - assert(0); - } - - if (rv != 0) { - return rv; - } - - rv = nghttp3_stream_transit_rx_http_state(stream, - NGHTTP3_HTTP_EVENT_HEADERS_END); - assert(0 == rv); - - nghttp3_stream_read_state_reset(rstate); - break; - case NGHTTP3_REQ_STREAM_STATE_IGN_FRAME: - len = (size_t)nghttp3_min(rstate->left, (int64_t)(end - p)); - p += len; - nconsumed += len; - rstate->left -= (int64_t)len; - - if (rstate->left) { - goto almost_done; - } - - nghttp3_stream_read_state_reset(rstate); - break; - } - } - -almost_done: - if (fin) { - switch (rstate->state) { - case NGHTTP3_REQ_STREAM_STATE_FRAME_TYPE: - if (rvint->left) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - rv = nghttp3_stream_transit_rx_http_state(stream, - NGHTTP3_HTTP_EVENT_MSG_END); - if (rv != 0) { - return rv; - } - rv = conn_call_end_stream(conn, stream); - if (rv != 0) { - return rv; - } - break; - default: - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - } - - *pnproc = (size_t)(p - src); - return (nghttp3_ssize)nconsumed; -} - -int nghttp3_conn_on_data(nghttp3_conn *conn, nghttp3_stream *stream, - const uint8_t *data, size_t datalen) { - int rv; - - rv = nghttp3_http_on_data_chunk(stream, datalen); - if (rv != 0) { - return rv; - } - - if (!conn->callbacks.recv_data) { - return 0; - } - - rv = conn->callbacks.recv_data(conn, stream->node.nid.id, data, datalen, - conn->user_data, stream->user_data); - if (rv != 0) { - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -int nghttp3_conn_on_push_promise_push_id(nghttp3_conn *conn, int64_t push_id, - nghttp3_stream *stream) { - int rv; - nghttp3_gaptr *push_idtr = &conn->remote.uni.push_idtr; - nghttp3_push_promise *pp; - - if (conn->remote.uni.max_pushes <= (uint64_t)push_id) { - return NGHTTP3_ERR_H3_ID_ERROR; - } - - pp = nghttp3_conn_find_push_promise(conn, push_id); - if (pp) { - if ((pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_BOUND) || - (pp->stream_id != -1 && pp->stream_id != stream->node.nid.id)) { - return NGHTTP3_ERR_IGNORE_PUSH_PROMISE; - } - if (pp->stream) { - assert(pp->stream->flags & NGHTTP3_STREAM_FLAG_PUSH_PROMISE_BLOCKED); - /* Push unidirectional stream has already been received and - blocked */ - } else if (pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_CANCELLED) { - /* We will call begin_push_promise callback even if push is - cancelled */ - } else { - return NGHTTP3_ERR_H3_FRAME_ERROR; - } - - assert(pp->stream_id == -1); - - pp->stream_id = stream->node.nid.id; - pp->flags |= NGHTTP3_PUSH_PROMISE_FLAG_BOUND; - } else if (nghttp3_gaptr_is_pushed(push_idtr, (uint64_t)push_id, 1)) { - return NGHTTP3_ERR_IGNORE_PUSH_PROMISE; - } else { - rv = nghttp3_gaptr_push(push_idtr, (uint64_t)push_id, 1); - if (rv != 0) { - return rv; - } - - rv = nghttp3_conn_create_push_promise(conn, &pp, push_id, &stream->node); - if (rv != 0) { - return rv; - } - } - - rv = conn_call_begin_push_promise(conn, stream, push_id); - if (rv != 0) { - return rv; - } - - return 0; -} - -int nghttp3_conn_on_client_cancel_push(nghttp3_conn *conn, - const nghttp3_frame_cancel_push *fr) { - nghttp3_push_promise *pp; - nghttp3_gaptr *push_idtr = &conn->remote.uni.push_idtr; - int rv; - - if (conn->remote.uni.max_pushes <= (uint64_t)fr->push_id) { - return NGHTTP3_ERR_H3_ID_ERROR; - } - - pp = nghttp3_conn_find_push_promise(conn, fr->push_id); - if (pp == NULL) { - if (nghttp3_gaptr_is_pushed(push_idtr, (uint64_t)fr->push_id, 1)) { - /* push is already cancelled or server is misbehaving */ - return 0; - } - - /* We have not received PUSH_PROMISE yet */ - rv = nghttp3_gaptr_push(push_idtr, (uint64_t)fr->push_id, 1); - if (rv != 0) { - return rv; - } - - rv = nghttp3_conn_create_push_promise(conn, &pp, fr->push_id, NULL); - if (rv != 0) { - return rv; - } - - pp->flags |= NGHTTP3_PUSH_PROMISE_FLAG_RECV_CANCEL; - - /* cancel_push callback will be called after PUSH_PROMISE frame is - completely received. */ - - return 0; - } - - if (pp->stream) { - return 0; - } - - if (pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_RECVED) { - rv = conn_call_cancel_push(conn, pp->node.nid.id, pp->stream); - if (rv != 0) { - return rv; - } - - conn_delete_push_promise(conn, pp); - - return 0; - } - - pp->flags |= NGHTTP3_PUSH_PROMISE_FLAG_RECV_CANCEL; - - return 0; -} - -static nghttp3_pq *conn_get_sched_pq(nghttp3_conn *conn, nghttp3_tnode *tnode) { - uint32_t urgency = nghttp3_pri_uint8_urgency(tnode->pri); - - assert(urgency < NGHTTP3_URGENCY_LEVELS); - - return &conn->sched[urgency].spq; -} - -int nghttp3_conn_on_server_cancel_push(nghttp3_conn *conn, - const nghttp3_frame_cancel_push *fr) { - nghttp3_push_promise *pp; - nghttp3_stream *stream; - int rv; - - if (conn->local.uni.next_push_id <= fr->push_id) { - return NGHTTP3_ERR_H3_ID_ERROR; - } - - pp = nghttp3_conn_find_push_promise(conn, fr->push_id); - if (pp == NULL) { - return 0; - } - - stream = pp->stream; - - rv = conn_call_cancel_push(conn, fr->push_id, stream); - if (rv != 0) { - return rv; - } - - if (stream) { - rv = nghttp3_conn_close_stream(conn, stream->node.nid.id, - NGHTTP3_H3_REQUEST_CANCELLED); - if (rv != 0) { - assert(NGHTTP3_ERR_STREAM_NOT_FOUND != rv); - return rv; - } - return 0; - } - - nghttp3_tnode_unschedule(&pp->node, conn_get_sched_pq(conn, &pp->node)); - - conn_delete_push_promise(conn, pp); - - return 0; -} - -int nghttp3_conn_on_stream_push_id(nghttp3_conn *conn, nghttp3_stream *stream, - int64_t push_id) { - nghttp3_push_promise *pp; - int rv; - - if (nghttp3_gaptr_is_pushed(&conn->remote.uni.push_idtr, (uint64_t)push_id, - 1)) { - pp = nghttp3_conn_find_push_promise(conn, push_id); - if (pp) { - if (pp->stream) { - return NGHTTP3_ERR_H3_ID_ERROR; - } - pp->stream = stream; - stream->pp = pp; - - assert(!(pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_SENT_CANCEL)); - assert(!(pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_RECV_CANCEL)); - - if (pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_RECVED) { - ++conn->remote.uni.unsent_max_pushes; - pp->flags |= NGHTTP3_PUSH_PROMISE_FLAG_PUSH_ID_RECLAIMED; - - return conn_call_push_stream(conn, push_id, stream); - } - - stream->flags |= NGHTTP3_STREAM_FLAG_PUSH_PROMISE_BLOCKED; - - return 0; - } - - /* Push ID has been received, but pp is gone. This means that - push is cancelled or server is misbehaving. We have no - information to distinguish the two, so just cancel QPACK stream - just in case, and ask application to send STOP_SENDING and - ignore all frames in this stream. */ - rv = nghttp3_qpack_decoder_cancel_stream(&conn->qdec, stream->node.nid.id); - if (rv != 0) { - return rv; - } - rv = - conn_call_send_stop_sending(conn, stream, NGHTTP3_H3_REQUEST_CANCELLED); - if (rv != 0) { - return rv; - } - return NGHTTP3_ERR_IGNORE_STREAM; - } - - if (conn->remote.uni.max_pushes <= (uint64_t)push_id) { - return NGHTTP3_ERR_H3_ID_ERROR; - } - - rv = nghttp3_gaptr_push(&conn->remote.uni.push_idtr, (uint64_t)push_id, 1); - if (rv != 0) { - return rv; - } - - /* Don't know the associated stream of PUSH_PROMISE. It doesn't - matter because client sends nothing to this stream. */ - rv = nghttp3_conn_create_push_promise(conn, &pp, push_id, NULL); - if (rv != 0) { - return rv; - } - - pp->stream = stream; - stream->pp = pp; - stream->flags |= NGHTTP3_STREAM_FLAG_PUSH_PROMISE_BLOCKED; - - return 0; -} - -static nghttp3_ssize conn_decode_headers(nghttp3_conn *conn, - nghttp3_stream *stream, - nghttp3_push_promise *pp, - const uint8_t *src, size_t srclen, - int fin) { - nghttp3_ssize nread; - int rv; - nghttp3_qpack_decoder *qdec = &conn->qdec; - nghttp3_qpack_nv nv; - uint8_t flags; - nghttp3_buf buf; - nghttp3_recv_header recv_header = NULL; - nghttp3_http_state *http; - int request = 0; - int trailers = 0; - int ignore_pp = 0; - - if (pp) { - request = 1; - ignore_pp = pp->stream_id != stream->node.nid.id; - if (ignore_pp) { - http = NULL; - } else { - http = &pp->http; - } - } else { - switch (stream->rx.hstate) { - case NGHTTP3_HTTP_STATE_REQ_HEADERS_BEGIN: - request = 1; - /* Fall through */ - case NGHTTP3_HTTP_STATE_RESP_HEADERS_BEGIN: - recv_header = conn->callbacks.recv_header; - break; - case NGHTTP3_HTTP_STATE_REQ_TRAILERS_BEGIN: - request = 1; - /* Fall through */ - case NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN: - trailers = 1; - recv_header = conn->callbacks.recv_trailer; - break; - default: - /* Unreachable */ - assert(0); - } - http = &stream->rx.http; - } - - nghttp3_buf_wrap_init(&buf, (uint8_t *)src, srclen); - buf.last = buf.end; - - for (;;) { - nread = nghttp3_qpack_decoder_read_request(qdec, &stream->qpack_sctx, &nv, - &flags, buf.pos, - nghttp3_buf_len(&buf), fin); - - if (nread < 0) { - return (int)nread; - } - - buf.pos += nread; - - if (flags & NGHTTP3_QPACK_DECODE_FLAG_BLOCKED) { - if (conn->local.settings.qpack_blocked_streams <= - nghttp3_pq_size(&conn->qpack_blocked_streams)) { - return NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - } - - stream->flags |= NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED; - rv = nghttp3_conn_qpack_blocked_streams_push(conn, stream); - if (rv != 0) { - return rv; - } - break; - } - - if (flags & NGHTTP3_QPACK_DECODE_FLAG_FINAL) { - nghttp3_qpack_stream_context_reset(&stream->qpack_sctx); - break; - } - - if (nread == 0) { - break; - } - - if (flags & NGHTTP3_QPACK_DECODE_FLAG_EMIT) { - if (ignore_pp) { - nghttp3_rcbuf_decref(nv.name); - nghttp3_rcbuf_decref(nv.value); - - continue; - } - - assert(http); - - rv = nghttp3_http_on_header(http, stream->rstate.fr.hd.type, &nv, request, - trailers); - switch (rv) { - case NGHTTP3_ERR_MALFORMED_HTTP_HEADER: - break; - case NGHTTP3_ERR_REMOVE_HTTP_HEADER: - rv = 0; - break; - case 0: - if (pp) { - if (conn->callbacks.recv_push_promise) { - rv = conn->callbacks.recv_push_promise( - conn, stream->node.nid.id, pp->node.nid.id, nv.token, nv.name, - nv.value, nv.flags, conn->user_data, stream->user_data); - } - break; - } - if (recv_header) { - rv = recv_header(conn, stream->node.nid.id, nv.token, nv.name, - nv.value, nv.flags, conn->user_data, - stream->user_data); - } - break; - default: - /* Unreachable */ - assert(0); - } - - nghttp3_rcbuf_decref(nv.name); - nghttp3_rcbuf_decref(nv.value); - - if (rv != 0) { - return rv; - } - } - } - - return buf.pos - src; -} - -nghttp3_ssize nghttp3_conn_on_headers(nghttp3_conn *conn, - nghttp3_stream *stream, - nghttp3_push_promise *pp, - const uint8_t *src, size_t srclen, - int fin) { - if (srclen == 0 && !fin) { - return 0; - } - - return conn_decode_headers(conn, stream, pp, src, srclen, fin); -} - -int nghttp3_conn_on_settings_entry_received(nghttp3_conn *conn, - const nghttp3_frame_settings *fr) { - const nghttp3_settings_entry *ent = &fr->iv[0]; - nghttp3_conn_settings *dest = &conn->remote.settings; - int rv; - size_t max_table_capacity = SIZE_MAX; - size_t max_blocked_streams = SIZE_MAX; - - /* TODO Check for duplicates */ - switch (ent->id) { - case NGHTTP3_SETTINGS_ID_MAX_FIELD_SECTION_SIZE: - dest->max_field_section_size = ent->value; - break; - case NGHTTP3_SETTINGS_ID_QPACK_MAX_TABLE_CAPACITY: - dest->qpack_max_table_capacity = (size_t)ent->value; - max_table_capacity = - nghttp3_min(max_table_capacity, dest->qpack_max_table_capacity); - rv = nghttp3_qpack_encoder_set_hard_max_dtable_size(&conn->qenc, - max_table_capacity); - if (rv != 0) { - return rv; - } - rv = nghttp3_qpack_encoder_set_max_dtable_size(&conn->qenc, - max_table_capacity); - if (rv != 0) { - return rv; - } - break; - case NGHTTP3_SETTINGS_ID_QPACK_BLOCKED_STREAMS: - dest->qpack_blocked_streams = (size_t)ent->value; - max_blocked_streams = - nghttp3_min(max_blocked_streams, dest->qpack_blocked_streams); - rv = - nghttp3_qpack_encoder_set_max_blocked(&conn->qenc, max_blocked_streams); - if (rv != 0) { - return rv; - } - break; - default: - /* Ignore unknown settings ID */ - break; - } - - return 0; -} - -static int conn_stream_acked_data(nghttp3_stream *stream, int64_t stream_id, - size_t datalen, void *user_data) { - nghttp3_conn *conn = stream->conn; - int rv; - - if (!conn->callbacks.acked_stream_data) { - return 0; - } - - rv = conn->callbacks.acked_stream_data(conn, stream_id, datalen, - conn->user_data, user_data); - if (rv != 0) { - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -int nghttp3_conn_create_stream(nghttp3_conn *conn, nghttp3_stream **pstream, - int64_t stream_id) { - nghttp3_stream *stream; - int rv; - nghttp3_stream_callbacks callbacks = { - conn_stream_acked_data, - }; - - rv = nghttp3_stream_new(&stream, stream_id, conn->next_seq, &callbacks, - conn->mem); - if (rv != 0) { - return rv; - } - - stream->conn = conn; - - rv = nghttp3_map_insert(&conn->streams, &stream->me); - if (rv != 0) { - nghttp3_stream_del(stream); - return rv; - } - - ++conn->next_seq; - *pstream = stream; - - return 0; -} - -int nghttp3_conn_create_push_promise(nghttp3_conn *conn, - nghttp3_push_promise **ppp, - int64_t push_id, - nghttp3_tnode *assoc_tnode) { - nghttp3_push_promise *pp; - int rv; - - rv = nghttp3_push_promise_new(&pp, push_id, conn->next_seq, assoc_tnode, - conn->mem); - if (rv != 0) { - return rv; - } - - rv = nghttp3_map_insert(&conn->pushes, &pp->me); - if (rv != 0) { - nghttp3_push_promise_del(pp, conn->mem); - return rv; - } - - ++conn->next_seq; - *ppp = pp; - - return 0; -} - -nghttp3_stream *nghttp3_conn_find_stream(nghttp3_conn *conn, - int64_t stream_id) { - nghttp3_map_entry *me; - - me = nghttp3_map_find(&conn->streams, (key_type)stream_id); - if (me == NULL) { - return NULL; - } - - return nghttp3_struct_of(me, nghttp3_stream, me); -} - -nghttp3_push_promise *nghttp3_conn_find_push_promise(nghttp3_conn *conn, - int64_t push_id) { - nghttp3_map_entry *me; - - me = nghttp3_map_find(&conn->pushes, (key_type)push_id); - if (me == NULL) { - return NULL; - } - - return nghttp3_struct_of(me, nghttp3_push_promise, me); -} - -int nghttp3_conn_bind_control_stream(nghttp3_conn *conn, int64_t stream_id) { - nghttp3_stream *stream; - nghttp3_frame_entry frent; - int rv; - - assert(!conn->server || nghttp3_server_stream_uni(stream_id)); - assert(conn->server || nghttp3_client_stream_uni(stream_id)); - - if (conn->tx.ctrl) { - return NGHTTP3_ERR_INVALID_STATE; - } - - rv = nghttp3_conn_create_stream(conn, &stream, stream_id); - if (rv != 0) { - return rv; - } - - stream->type = NGHTTP3_STREAM_TYPE_CONTROL; - - conn->tx.ctrl = stream; - - rv = nghttp3_stream_write_stream_type(stream); - if (rv != 0) { - return rv; - } - - frent.fr.hd.type = NGHTTP3_FRAME_SETTINGS; - frent.aux.settings.local_settings = &conn->local.settings; - - return nghttp3_stream_frq_add(stream, &frent); -} - -int nghttp3_conn_bind_qpack_streams(nghttp3_conn *conn, int64_t qenc_stream_id, - int64_t qdec_stream_id) { - nghttp3_stream *stream; - int rv; - - assert(!conn->server || nghttp3_server_stream_uni(qenc_stream_id)); - assert(!conn->server || nghttp3_server_stream_uni(qdec_stream_id)); - assert(conn->server || nghttp3_client_stream_uni(qenc_stream_id)); - assert(conn->server || nghttp3_client_stream_uni(qdec_stream_id)); - - if (conn->tx.qenc || conn->tx.qdec) { - return NGHTTP3_ERR_INVALID_STATE; - } - - rv = nghttp3_conn_create_stream(conn, &stream, qenc_stream_id); - if (rv != 0) { - return rv; - } - - stream->type = NGHTTP3_STREAM_TYPE_QPACK_ENCODER; - - conn->tx.qenc = stream; - - rv = nghttp3_stream_write_stream_type(stream); - if (rv != 0) { - return rv; - } - - rv = nghttp3_conn_create_stream(conn, &stream, qdec_stream_id); - if (rv != 0) { - return rv; - } - - stream->type = NGHTTP3_STREAM_TYPE_QPACK_DECODER; - - conn->tx.qdec = stream; - - return nghttp3_stream_write_stream_type(stream); -} - -static nghttp3_ssize conn_writev_stream(nghttp3_conn *conn, int64_t *pstream_id, - int *pfin, nghttp3_vec *vec, - size_t veccnt, nghttp3_stream *stream) { - int rv; - nghttp3_ssize n; - - assert(veccnt > 0); - - /* If stream is blocked by read callback, don't attempt to fill - more. */ - if (!(stream->flags & NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED)) { - rv = nghttp3_stream_fill_outq(stream); - if (rv != 0) { - return rv; - } - } - - if (!nghttp3_stream_uni(stream->node.nid.id) && conn->tx.qenc && - !nghttp3_stream_is_blocked(conn->tx.qenc)) { - n = nghttp3_stream_writev(conn->tx.qenc, pfin, vec, veccnt); - if (n < 0) { - return n; - } - if (n) { - *pstream_id = conn->tx.qenc->node.nid.id; - return n; - } - } - - n = nghttp3_stream_writev(stream, pfin, vec, veccnt); - if (n < 0) { - return n; - } - /* We might just want to write stream fin without sending any stream - data. */ - if (n == 0 && *pfin == 0) { - return 0; - } - - *pstream_id = stream->node.nid.id; - - return n; -} - -nghttp3_ssize nghttp3_conn_writev_stream(nghttp3_conn *conn, - int64_t *pstream_id, int *pfin, - nghttp3_vec *vec, size_t veccnt) { - nghttp3_ssize ncnt; - nghttp3_stream *stream; - int rv; - - *pstream_id = -1; - *pfin = 0; - - if (veccnt == 0) { - return 0; - } - - if (conn->tx.ctrl && !nghttp3_stream_is_blocked(conn->tx.ctrl)) { - if (!(conn->flags & NGHTTP3_CONN_FLAG_MAX_PUSH_ID_QUEUED) && - conn->remote.uni.unsent_max_pushes > conn->remote.uni.max_pushes) { - rv = nghttp3_conn_submit_max_push_id(conn); - if (rv != 0) { - return rv; - } - } - - ncnt = - conn_writev_stream(conn, pstream_id, pfin, vec, veccnt, conn->tx.ctrl); - if (ncnt) { - return ncnt; - } - } - - if (conn->tx.qdec && !nghttp3_stream_is_blocked(conn->tx.qdec)) { - rv = nghttp3_stream_write_qpack_decoder_stream(conn->tx.qdec); - if (rv != 0) { - return rv; - } - - ncnt = - conn_writev_stream(conn, pstream_id, pfin, vec, veccnt, conn->tx.qdec); - if (ncnt) { - return ncnt; - } - } - - if (conn->tx.qenc && !nghttp3_stream_is_blocked(conn->tx.qenc)) { - ncnt = - conn_writev_stream(conn, pstream_id, pfin, vec, veccnt, conn->tx.qenc); - if (ncnt) { - return ncnt; - } - } - - stream = nghttp3_conn_get_next_tx_stream(conn); - if (stream == NULL) { - return 0; - } - - ncnt = conn_writev_stream(conn, pstream_id, pfin, vec, veccnt, stream); - if (ncnt < 0) { - return ncnt; - } - - if (nghttp3_stream_bidi_or_push(stream) && - !nghttp3_stream_require_schedule(stream)) { - nghttp3_conn_unschedule_stream(conn, stream); - } - - return ncnt; -} - -nghttp3_stream *nghttp3_conn_get_next_tx_stream(nghttp3_conn *conn) { - size_t i; - nghttp3_tnode *tnode; - nghttp3_pq *pq; - - for (i = 0; i < NGHTTP3_URGENCY_LEVELS; ++i) { - pq = &conn->sched[i].spq; - if (nghttp3_pq_empty(pq)) { - continue; - } - - tnode = nghttp3_struct_of(nghttp3_pq_top(pq), nghttp3_tnode, pe); - - if (tnode->nid.type == NGHTTP3_NODE_ID_TYPE_PUSH) { - return nghttp3_struct_of(tnode, nghttp3_push_promise, node)->stream; - } - - return nghttp3_struct_of(tnode, nghttp3_stream, node); - } - - return NULL; -} - -int nghttp3_conn_add_write_offset(nghttp3_conn *conn, int64_t stream_id, - size_t n) { - nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id); - int rv; - - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - rv = nghttp3_stream_add_outq_offset(stream, n); - if (rv != 0) { - return rv; - } - - stream->unscheduled_nwrite += n; - - if (!nghttp3_stream_bidi_or_push(stream)) { - return 0; - } - - if (!nghttp3_stream_require_schedule(stream)) { - nghttp3_conn_unschedule_stream(conn, stream); - return 0; - } - - if (stream->unscheduled_nwrite < NGHTTP3_STREAM_MIN_WRITELEN) { - return 0; - } - - return nghttp3_conn_schedule_stream(conn, stream); -} - -int nghttp3_conn_add_ack_offset(nghttp3_conn *conn, int64_t stream_id, - uint64_t n) { - nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id); - - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - return nghttp3_stream_add_ack_offset(stream, n); -} - -static int conn_submit_headers_data(nghttp3_conn *conn, nghttp3_stream *stream, - const nghttp3_nv *nva, size_t nvlen, - const nghttp3_data_reader *dr) { - int rv; - nghttp3_nv *nnva; - nghttp3_frame_entry frent; - - rv = nghttp3_nva_copy(&nnva, nva, nvlen, conn->mem); - if (rv != 0) { - return rv; - } - - frent.fr.hd.type = NGHTTP3_FRAME_HEADERS; - frent.fr.headers.nva = nnva; - frent.fr.headers.nvlen = nvlen; - - rv = nghttp3_stream_frq_add(stream, &frent); - if (rv != 0) { - nghttp3_nva_del(nnva, conn->mem); - return rv; - } - - if (dr) { - frent.fr.hd.type = NGHTTP3_FRAME_DATA; - frent.aux.data.dr = *dr; - - rv = nghttp3_stream_frq_add(stream, &frent); - if (rv != 0) { - return rv; - } - } - - if (nghttp3_stream_require_schedule(stream)) { - return nghttp3_conn_schedule_stream(conn, stream); - } - - return 0; -} - -static nghttp3_tnode *stream_get_dependency_node(nghttp3_stream *stream) { - if (stream->pp) { - assert(stream->type == NGHTTP3_STREAM_TYPE_PUSH); - return &stream->pp->node; - } - - return &stream->node; -} - -int nghttp3_conn_schedule_stream(nghttp3_conn *conn, nghttp3_stream *stream) { - /* Assume that stream stays on the same urgency level */ - int rv; - - rv = nghttp3_tnode_schedule(stream_get_dependency_node(stream), - conn_get_sched_pq(conn, &stream->node), - stream->unscheduled_nwrite); - if (rv != 0) { - return rv; - } - - stream->unscheduled_nwrite = 0; - - return 0; -} - -int nghttp3_conn_ensure_stream_scheduled(nghttp3_conn *conn, - nghttp3_stream *stream) { - if (nghttp3_tnode_is_scheduled(stream_get_dependency_node(stream))) { - return 0; - } - - return nghttp3_conn_schedule_stream(conn, stream); -} - -void nghttp3_conn_unschedule_stream(nghttp3_conn *conn, - nghttp3_stream *stream) { - nghttp3_tnode_unschedule(stream_get_dependency_node(stream), - conn_get_sched_pq(conn, &stream->node)); -} - -int nghttp3_conn_submit_request(nghttp3_conn *conn, int64_t stream_id, - const nghttp3_nv *nva, size_t nvlen, - const nghttp3_data_reader *dr, - void *stream_user_data) { - nghttp3_stream *stream; - int rv; - - assert(!conn->server); - assert(conn->tx.qenc); - - assert(nghttp3_client_stream_bidi(stream_id)); - - /* TODO Should we check that stream_id is client stream_id? */ - /* TODO Check GOAWAY last stream ID */ - if (nghttp3_stream_uni(stream_id)) { - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - stream = nghttp3_conn_find_stream(conn, stream_id); - if (stream != NULL) { - return NGHTTP3_ERR_STREAM_IN_USE; - } - - rv = nghttp3_conn_create_stream(conn, &stream, stream_id); - if (rv != 0) { - return rv; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_INITIAL; - stream->tx.hstate = NGHTTP3_HTTP_STATE_REQ_END; - stream->user_data = stream_user_data; - - nghttp3_http_record_request_method(stream, nva, nvlen); - - if (dr == NULL) { - stream->flags |= NGHTTP3_STREAM_FLAG_WRITE_END_STREAM; - } - - return conn_submit_headers_data(conn, stream, nva, nvlen, dr); -} - -int nghttp3_conn_submit_info(nghttp3_conn *conn, int64_t stream_id, - const nghttp3_nv *nva, size_t nvlen) { - nghttp3_stream *stream; - - /* TODO Verify that it is allowed to send info (non-final response) - now. */ - assert(conn->server); - assert(conn->tx.qenc); - - stream = nghttp3_conn_find_stream(conn, stream_id); - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - return conn_submit_headers_data(conn, stream, nva, nvlen, NULL); -} - -int nghttp3_conn_submit_response(nghttp3_conn *conn, int64_t stream_id, - const nghttp3_nv *nva, size_t nvlen, - const nghttp3_data_reader *dr) { - nghttp3_stream *stream; - - /* TODO Verify that it is allowed to send response now. */ - assert(conn->server); - assert(conn->tx.qenc); - - stream = nghttp3_conn_find_stream(conn, stream_id); - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - if (dr == NULL) { - stream->flags |= NGHTTP3_STREAM_FLAG_WRITE_END_STREAM; - } - - return conn_submit_headers_data(conn, stream, nva, nvlen, dr); -} - -int nghttp3_conn_submit_trailers(nghttp3_conn *conn, int64_t stream_id, - const nghttp3_nv *nva, size_t nvlen) { - nghttp3_stream *stream; - - /* TODO Verify that it is allowed to send trailer now. */ - assert(conn->tx.qenc); - - stream = nghttp3_conn_find_stream(conn, stream_id); - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - if (stream->flags & NGHTTP3_STREAM_FLAG_WRITE_END_STREAM) { - return NGHTTP3_ERR_INVALID_STATE; - } - - stream->flags |= NGHTTP3_STREAM_FLAG_WRITE_END_STREAM; - - return conn_submit_headers_data(conn, stream, nva, nvlen, NULL); -} - -int nghttp3_conn_submit_push_promise(nghttp3_conn *conn, int64_t *ppush_id, - int64_t stream_id, const nghttp3_nv *nva, - size_t nvlen) { - nghttp3_stream *stream; - int rv; - nghttp3_nv *nnva; - nghttp3_frame_entry frent; - int64_t push_id; - nghttp3_push_promise *pp; - - assert(conn->server); - assert(conn->tx.qenc); - assert(nghttp3_client_stream_bidi(stream_id)); - - stream = nghttp3_conn_find_stream(conn, stream_id); - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - if (conn->local.uni.max_pushes <= (uint64_t)conn->local.uni.next_push_id) { - return NGHTTP3_ERR_PUSH_ID_BLOCKED; - } - - push_id = conn->local.uni.next_push_id; - - rv = nghttp3_conn_create_push_promise(conn, &pp, push_id, &stream->node); - if (rv != 0) { - return rv; - } - - ++conn->local.uni.next_push_id; - - rv = nghttp3_nva_copy(&nnva, nva, nvlen, conn->mem); - if (rv != 0) { - return rv; - } - - frent.fr.hd.type = NGHTTP3_FRAME_PUSH_PROMISE; - frent.fr.push_promise.push_id = push_id; - frent.fr.push_promise.nva = nnva; - frent.fr.push_promise.nvlen = nvlen; - - rv = nghttp3_stream_frq_add(stream, &frent); - if (rv != 0) { - nghttp3_nva_del(nnva, conn->mem); - return rv; - } - - *ppush_id = push_id; - - if (nghttp3_stream_require_schedule(stream)) { - return nghttp3_conn_schedule_stream(conn, stream); - } - - return 0; -} - -int nghttp3_conn_bind_push_stream(nghttp3_conn *conn, int64_t push_id, - int64_t stream_id) { - nghttp3_push_promise *pp; - nghttp3_stream *stream; - int rv; - - assert(conn->server); - assert(nghttp3_server_stream_uni(stream_id)); - - pp = nghttp3_conn_find_push_promise(conn, push_id); - if (pp == NULL) { - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - assert(NULL == nghttp3_conn_find_stream(conn, stream_id)); - - rv = nghttp3_conn_create_stream(conn, &stream, stream_id); - if (rv != 0) { - return rv; - } - - stream->type = NGHTTP3_STREAM_TYPE_PUSH; - stream->pp = pp; - - pp->stream = stream; - - rv = nghttp3_stream_write_stream_type_push_id(stream); - if (rv != 0) { - return rv; - } - - return 0; -} - -int nghttp3_conn_cancel_push(nghttp3_conn *conn, int64_t push_id) { - if (conn->server) { - return nghttp3_conn_server_cancel_push(conn, push_id); - } - return nghttp3_conn_client_cancel_push(conn, push_id); -} - -int nghttp3_conn_server_cancel_push(nghttp3_conn *conn, int64_t push_id) { - nghttp3_push_promise *pp; - nghttp3_frame_entry frent; - int rv; - - assert(conn->tx.ctrl); - - pp = nghttp3_conn_find_push_promise(conn, push_id); - if (pp == NULL) { - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - if (!(pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_SENT_CANCEL)) { - frent.fr.hd.type = NGHTTP3_FRAME_CANCEL_PUSH; - frent.fr.cancel_push.push_id = push_id; - - rv = nghttp3_stream_frq_add(conn->tx.ctrl, &frent); - if (rv != 0) { - return rv; - } - - pp->flags |= NGHTTP3_PUSH_PROMISE_FLAG_SENT_CANCEL; - } - - if (pp->stream) { - /* CANCEL_PUSH will be sent, but it does not affect pushed stream. - Application should explicitly shutdown the stream. */ - return NGHTTP3_ERR_TOO_LATE; - } - - nghttp3_tnode_unschedule(&pp->node, conn_get_sched_pq(conn, &pp->node)); - - conn_delete_push_promise(conn, pp); - - return 0; -} - -int nghttp3_conn_client_cancel_push(nghttp3_conn *conn, int64_t push_id) { - nghttp3_push_promise *pp; - nghttp3_frame_entry frent; - int rv; - - pp = nghttp3_conn_find_push_promise(conn, push_id); - if (pp == NULL) { - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - if (pp->stream) { - return NGHTTP3_ERR_TOO_LATE; - } - - frent.fr.hd.type = NGHTTP3_FRAME_CANCEL_PUSH; - frent.fr.cancel_push.push_id = push_id; - - rv = nghttp3_stream_frq_add(conn->tx.ctrl, &frent); - if (rv != 0) { - return rv; - } - - if (pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_RECVED) { - conn_delete_push_promise(conn, pp); - return 0; - } - - pp->flags |= NGHTTP3_PUSH_PROMISE_FLAG_SENT_CANCEL; - - return 0; -} - -int nghttp3_conn_block_stream(nghttp3_conn *conn, int64_t stream_id) { - nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id); - - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - stream->flags |= NGHTTP3_STREAM_FLAG_FC_BLOCKED; - stream->unscheduled_nwrite = 0; - - if (nghttp3_stream_bidi_or_push(stream)) { - nghttp3_conn_unschedule_stream(conn, stream); - } - - return 0; -} - -int nghttp3_conn_unblock_stream(nghttp3_conn *conn, int64_t stream_id) { - nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id); - - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - stream->flags &= (uint16_t)~NGHTTP3_STREAM_FLAG_FC_BLOCKED; - - if (nghttp3_stream_bidi_or_push(stream) && - nghttp3_stream_require_schedule(stream)) { - return nghttp3_conn_ensure_stream_scheduled(conn, stream); - } - - return 0; -} - -int nghttp3_conn_resume_stream(nghttp3_conn *conn, int64_t stream_id) { - nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id); - - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - stream->flags &= (uint16_t)~NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED; - - if (nghttp3_stream_bidi_or_push(stream) && - nghttp3_stream_require_schedule(stream)) { - return nghttp3_conn_ensure_stream_scheduled(conn, stream); - } - - return 0; -} - -int nghttp3_conn_close_stream(nghttp3_conn *conn, int64_t stream_id, - uint64_t app_error_code) { - nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id); - - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - if (nghttp3_stream_uni(stream_id) && - stream->type != NGHTTP3_STREAM_TYPE_PUSH && - stream->type != NGHTTP3_STREAM_TYPE_UNKNOWN) { - return NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM; - } - - stream->error_code = app_error_code; - - nghttp3_conn_unschedule_stream(conn, stream); - - if (stream->qpack_blocked_pe.index == NGHTTP3_PQ_BAD_INDEX && - (conn->server || !stream->pp || - (stream->pp->flags & NGHTTP3_PUSH_PROMISE_FLAG_RECVED))) { - return conn_delete_stream(conn, stream); - } - - stream->flags |= NGHTTP3_STREAM_FLAG_CLOSED; - return 0; -} - -int nghttp3_conn_reset_stream(nghttp3_conn *conn, int64_t stream_id) { - nghttp3_stream *stream; - - stream = nghttp3_conn_find_stream(conn, stream_id); - if (stream) { - stream->flags |= NGHTTP3_STREAM_FLAG_RESET; - } - return nghttp3_qpack_decoder_cancel_stream(&conn->qdec, stream_id); -} - -int nghttp3_conn_qpack_blocked_streams_push(nghttp3_conn *conn, - nghttp3_stream *stream) { - assert(stream->qpack_blocked_pe.index == NGHTTP3_PQ_BAD_INDEX); - - return nghttp3_pq_push(&conn->qpack_blocked_streams, - &stream->qpack_blocked_pe); -} - -void nghttp3_conn_qpack_blocked_streams_pop(nghttp3_conn *conn) { - assert(!nghttp3_pq_empty(&conn->qpack_blocked_streams)); - nghttp3_pq_pop(&conn->qpack_blocked_streams); -} - -void nghttp3_conn_set_max_client_streams_bidi(nghttp3_conn *conn, - uint64_t max_streams) { - assert(conn->server); - assert(conn->remote.bidi.max_client_streams <= max_streams); - - conn->remote.bidi.max_client_streams = max_streams; -} - -void nghttp3_conn_set_max_concurrent_streams(nghttp3_conn *conn, - size_t max_concurrent_streams) { - nghttp3_qpack_decoder_set_max_concurrent_streams(&conn->qdec, - max_concurrent_streams); -} - -int nghttp3_conn_submit_max_push_id(nghttp3_conn *conn) { - nghttp3_frame_entry frent; - int rv; - - assert(conn->tx.ctrl); - assert(!(conn->flags & NGHTTP3_CONN_FLAG_MAX_PUSH_ID_QUEUED)); - - frent.fr.hd.type = NGHTTP3_FRAME_MAX_PUSH_ID; - /* The acutal push_id is set when frame is serialized */ - - rv = nghttp3_stream_frq_add(conn->tx.ctrl, &frent); - if (rv != 0) { - return rv; - } - - conn->flags |= NGHTTP3_CONN_FLAG_MAX_PUSH_ID_QUEUED; - - return 0; -} - -int nghttp3_conn_set_stream_user_data(nghttp3_conn *conn, int64_t stream_id, - void *stream_user_data) { - nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id); - - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - stream->user_data = stream_user_data; - - return 0; -} - -int64_t nghttp3_conn_get_frame_payload_left(nghttp3_conn *conn, - int64_t stream_id) { - nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id); - - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - return stream->rstate.left; -} - -int nghttp3_conn_get_stream_priority(nghttp3_conn *conn, nghttp3_pri *dest, - int64_t stream_id) { - nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id); - - assert(conn->server); - - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - dest->urgency = nghttp3_pri_uint8_urgency(stream->rx.http.pri); - dest->inc = nghttp3_pri_uint8_inc(stream->rx.http.pri); - - return 0; -} - -int nghttp3_conn_set_stream_priority(nghttp3_conn *conn, int64_t stream_id, - const nghttp3_pri *pri) { - nghttp3_stream *stream = nghttp3_conn_find_stream(conn, stream_id); - - assert(conn->server); - assert(pri->urgency < NGHTTP3_URGENCY_LEVELS); - assert(pri->inc == 0 || pri->inc == 1); - - if (stream == NULL) { - return NGHTTP3_ERR_STREAM_NOT_FOUND; - } - - stream->rx.http.pri = nghttp3_pri_to_uint8(pri); - - return conn_update_stream_priority(conn, stream, stream->rx.http.pri); -} - -int nghttp3_conn_is_remote_qpack_encoder_stream(nghttp3_conn *conn, - int64_t stream_id) { - nghttp3_stream *stream; - - if (!conn_remote_stream_uni(conn, stream_id)) { - return 0; - } - - stream = nghttp3_conn_find_stream(conn, stream_id); - return stream && stream->type == NGHTTP3_STREAM_TYPE_QPACK_ENCODER; -} - -void nghttp3_conn_settings_default(nghttp3_conn_settings *settings) { - memset(settings, 0, sizeof(nghttp3_conn_settings)); - settings->max_field_section_size = NGHTTP3_VARINT_MAX; -} - -int nghttp3_push_promise_new(nghttp3_push_promise **ppp, int64_t push_id, - uint64_t seq, nghttp3_tnode *assoc_tnode, - const nghttp3_mem *mem) { - nghttp3_push_promise *pp; - nghttp3_node_id nid; - - pp = nghttp3_mem_calloc(mem, 1, sizeof(nghttp3_push_promise)); - if (pp == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - nghttp3_tnode_init( - &pp->node, nghttp3_node_id_init(&nid, NGHTTP3_NODE_ID_TYPE_PUSH, push_id), - seq, NGHTTP3_DEFAULT_URGENCY); - - pp->me.key = (key_type)push_id; - pp->node.nid.id = push_id; - pp->http.status_code = -1; - pp->http.content_length = -1; - - if (assoc_tnode) { - assert(assoc_tnode->nid.type == NGHTTP3_NODE_ID_TYPE_STREAM); - - pp->stream_id = assoc_tnode->nid.id; - pp->flags |= NGHTTP3_PUSH_PROMISE_FLAG_BOUND; - } else { - pp->stream_id = -1; - } - - *ppp = pp; - - return 0; -} - -void nghttp3_push_promise_del(nghttp3_push_promise *pp, - const nghttp3_mem *mem) { - if (pp == NULL) { - return; - } - - nghttp3_tnode_free(&pp->node); - - nghttp3_mem_free(mem, pp); -} diff --git a/deps/nghttp3/lib/nghttp3_conn.h b/deps/nghttp3/lib/nghttp3_conn.h deleted file mode 100644 index 720b6102426acb..00000000000000 --- a/deps/nghttp3/lib/nghttp3_conn.h +++ /dev/null @@ -1,263 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_CONN_H -#define NGHTTP3_CONN_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "nghttp3_stream.h" -#include "nghttp3_map.h" -#include "nghttp3_qpack.h" -#include "nghttp3_tnode.h" -#include "nghttp3_idtr.h" -#include "nghttp3_gaptr.h" - -#define NGHTTP3_VARINT_MAX ((1ull << 62) - 1) - -/* NGHTTP3_QPACK_ENCODER_MAX_TABLE_CAPACITY is the maximum dynamic - table size for QPACK encoder. */ -#define NGHTTP3_QPACK_ENCODER_MAX_TABLE_CAPACITY 16384 - -/* NGHTTP3_QPACK_ENCODER_MAX_BLOCK_STREAMS is the maximum number of - blocked streams for QPACK encoder. */ -#define NGHTTP3_QPACK_ENCODER_MAX_BLOCK_STREAMS 100 - -typedef enum { - NGHTTP3_PUSH_PROMISE_FLAG_NONE = 0x00, - /* NGHTTP3_PUSH_PROMISE_FLAG_RECVED is set when PUSH_PROMISE is - completely received. */ - NGHTTP3_PUSH_PROMISE_FLAG_RECVED = 0x01, - /* NGHTTP3_PUSH_PROMISE_FLAG_RECV_CANCEL is set when push is - cancelled by server before receiving PUSH_PROMISE completely. - This flag should have no effect if push stream has already - opened. */ - NGHTTP3_PUSH_PROMISE_FLAG_RECV_CANCEL = 0x02, - /* NGHTTP3_PUSH_PROMISE_FLAG_SENT_CANCEL is set when push is - canceled by the local endpoint. */ - NGHTTP3_PUSH_PROMISE_FLAG_SENT_CANCEL = 0x04, - NGHTTP3_PUSH_PROMISE_FLAG_CANCELLED = NGHTTP3_PUSH_PROMISE_FLAG_RECV_CANCEL | - NGHTTP3_PUSH_PROMISE_FLAG_SENT_CANCEL, - /* NGHTTP3_PUSH_PROMISE_FLAG_PUSH_ID_RECLAIMED indicates that - unsent_max_pushes has been updated for this push ID. */ - NGHTTP3_PUSH_PROMISE_FLAG_PUSH_ID_RECLAIMED = 0x08, - /* NGHTTP3_PUSH_PROMISE_FLAG_BOUND is set if nghttp3_push_promise - object is bound to a stream where PUSH_PROMISE frame is received - first. nghttp3_push_promise object might be created before - receiving any PUSH_PROMISE when pushed stream is received before - it.*/ - NGHTTP3_PUSH_PROMISE_FLAG_BOUND = 0x10, -} nghttp3_push_promise_flag; - -struct nghttp3_push_promise; -typedef struct nghttp3_push_promise nghttp3_push_promise; - -struct nghttp3_push_promise { - nghttp3_map_entry me; - nghttp3_tnode node; - nghttp3_http_state http; - /* stream is server initiated unidirectional stream which fulfils - the push promise. */ - nghttp3_stream *stream; - /* stream_id is the stream ID where this PUSH_PROMISE is first - received. PUSH_PROMISE with same push ID is allowed to be sent - in the multiple streams. We ignore those duplicated PUSH_PROMISE - entirely because we don't see any value to add extra cost of - processing for it. Even ignoring those frame is not yet easy - because we have to decode the header blocks. Server push is - overly complex and there is no good use case after all. */ - int64_t stream_id; - /* flags is bitwise OR of zero or more of - nghttp3_push_promise_flag. */ - uint16_t flags; -}; - -typedef enum { - NGHTTP3_CONN_FLAG_NONE = 0x0000, - NGHTTP3_CONN_FLAG_SETTINGS_RECVED = 0x0001, - NGHTTP3_CONN_FLAG_CONTROL_OPENED = 0x0002, - NGHTTP3_CONN_FLAG_QPACK_ENCODER_OPENED = 0x0004, - NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED = 0x0008, - /* NGHTTP3_CONN_FLAG_MAX_PUSH_ID_QUEUED indicates that MAX_PUSH_ID - has been queued to control stream. */ - NGHTTP3_CONN_FLAG_MAX_PUSH_ID_QUEUED = 0x0010, -} nghttp3_conn_flag; - -struct nghttp3_conn { - nghttp3_conn_callbacks callbacks; - nghttp3_map streams; - nghttp3_map pushes; - nghttp3_qpack_decoder qdec; - nghttp3_qpack_encoder qenc; - nghttp3_pq qpack_blocked_streams; - struct { - nghttp3_pq spq; - } sched[NGHTTP3_URGENCY_LEVELS]; - const nghttp3_mem *mem; - void *user_data; - int server; - uint16_t flags; - uint64_t next_seq; - - struct { - nghttp3_conn_settings settings; - struct { - /* max_pushes is the number of push IDs that local endpoint can - issue. This field is used by server only. */ - uint64_t max_pushes; - /* next_push_id is the next push ID server uses. This field is - used by server only. */ - int64_t next_push_id; - } uni; - } local; - - struct { - struct { - nghttp3_idtr idtr; - /* max_client_streams is the cumulative number of client - initiated bidirectional stream ID the remote endpoint can - issue. This field is used on server side only. */ - uint64_t max_client_streams; - } bidi; - struct { - /* push_idtr tracks which push ID has been used by remote - server. This field is used by client only. */ - nghttp3_gaptr push_idtr; - /* unsent_max_pushes is the maximum number of push which the local - endpoint can accept. This limit is not yet notified to the - remote endpoint. This field is used by client only. */ - uint64_t unsent_max_pushes; - /* max_push is the maximum number of push which the local - endpoint can accept. This field is used by client only. */ - uint64_t max_pushes; - } uni; - nghttp3_conn_settings settings; - } remote; - - struct { - struct { - nghttp3_buf rbuf; - nghttp3_buf ebuf; - } qpack; - nghttp3_stream *ctrl; - nghttp3_stream *qenc; - nghttp3_stream *qdec; - } tx; -}; - -nghttp3_stream *nghttp3_conn_find_stream(nghttp3_conn *conn, int64_t stream_id); - -nghttp3_push_promise *nghttp3_conn_find_push_promise(nghttp3_conn *conn, - int64_t push_id); - -int nghttp3_conn_create_stream(nghttp3_conn *conn, nghttp3_stream **pstream, - int64_t stream_id); - -int nghttp3_conn_create_push_promise(nghttp3_conn *conn, - nghttp3_push_promise **ppp, - int64_t push_id, - nghttp3_tnode *assoc_tnode); - -nghttp3_ssize nghttp3_conn_read_bidi(nghttp3_conn *conn, size_t *pnproc, - nghttp3_stream *stream, const uint8_t *src, - size_t srclen, int fin); - -nghttp3_ssize nghttp3_conn_read_uni(nghttp3_conn *conn, nghttp3_stream *stream, - const uint8_t *src, size_t srclen, int fin); - -nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn, - nghttp3_stream *stream, - const uint8_t *src, size_t srclen); - -nghttp3_ssize nghttp3_conn_read_push(nghttp3_conn *conn, size_t *pnproc, - nghttp3_stream *stream, const uint8_t *src, - size_t srclen, int fin); - -nghttp3_ssize nghttp3_conn_read_qpack_encoder(nghttp3_conn *conn, - const uint8_t *src, - size_t srclen); - -nghttp3_ssize nghttp3_conn_read_qpack_decoder(nghttp3_conn *conn, - const uint8_t *src, - size_t srclen); - -int nghttp3_conn_on_push_promise_push_id(nghttp3_conn *conn, int64_t push_id, - nghttp3_stream *stream); - -int nghttp3_conn_on_client_cancel_push(nghttp3_conn *conn, - const nghttp3_frame_cancel_push *fr); - -int nghttp3_conn_on_server_cancel_push(nghttp3_conn *conn, - const nghttp3_frame_cancel_push *fr); - -int nghttp3_conn_on_stream_push_id(nghttp3_conn *conn, nghttp3_stream *stream, - int64_t push_id); - -int nghttp3_conn_on_data(nghttp3_conn *conn, nghttp3_stream *stream, - const uint8_t *data, size_t datalen); - -nghttp3_ssize nghttp3_conn_on_headers(nghttp3_conn *conn, - nghttp3_stream *stream, - nghttp3_push_promise *pp, - const uint8_t *data, size_t datalen, - int fin); - -int nghttp3_conn_on_settings_entry_received(nghttp3_conn *conn, - const nghttp3_frame_settings *fr); - -int nghttp3_conn_qpack_blocked_streams_push(nghttp3_conn *conn, - nghttp3_stream *stream); - -void nghttp3_conn_qpack_blocked_streams_pop(nghttp3_conn *conn); - -int nghttp3_conn_server_cancel_push(nghttp3_conn *conn, int64_t push_id); - -int nghttp3_conn_client_cancel_push(nghttp3_conn *conn, int64_t push_id); - -int nghttp3_conn_submit_max_push_id(nghttp3_conn *conn); - -int nghttp3_conn_schedule_stream(nghttp3_conn *conn, nghttp3_stream *stream); - -int nghttp3_conn_ensure_stream_scheduled(nghttp3_conn *conn, - nghttp3_stream *stream); - -void nghttp3_conn_unschedule_stream(nghttp3_conn *conn, nghttp3_stream *stream); - -/* - * nghttp3_conn_get_next_tx_stream returns next stream to send. It - * returns NULL if there is no such stream. - */ -nghttp3_stream *nghttp3_conn_get_next_tx_stream(nghttp3_conn *conn); - -int nghttp3_push_promise_new(nghttp3_push_promise **ppp, int64_t push_id, - uint64_t seq, nghttp3_tnode *assoc_tnode, - const nghttp3_mem *mem); - -void nghttp3_push_promise_del(nghttp3_push_promise *pp, const nghttp3_mem *mem); - -#endif /* NGHTTP3_CONN_H */ diff --git a/deps/nghttp3/lib/nghttp3_conv.c b/deps/nghttp3/lib/nghttp3_conv.c deleted file mode 100644 index 04bf6a0f298b3b..00000000000000 --- a/deps/nghttp3/lib/nghttp3_conv.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_conv.h" - -#include -#include - -#include "nghttp3_str.h" - -int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p) { - union { - char b[8]; - uint16_t n16; - uint32_t n32; - uint64_t n64; - } n; - - *plen = 1u << (*p >> 6); - - switch (*plen) { - case 1: - return (int64_t)*p; - case 2: - memcpy(&n, p, 2); - n.b[0] &= 0x3f; - return (int64_t)ntohs(n.n16); - case 4: - memcpy(&n, p, 4); - n.b[0] &= 0x3f; - return (int64_t)ntohl(n.n32); - case 8: - memcpy(&n, p, 8); - n.b[0] &= 0x3f; - return (int64_t)nghttp3_ntohl64(n.n64); - } - - assert(0); -} - -int64_t nghttp3_get_varint_fb(const uint8_t *p) { return *p & 0x3f; } - -size_t nghttp3_get_varint_len(const uint8_t *p) { return 1u << (*p >> 6); } - -uint8_t *nghttp3_put_uint64be(uint8_t *p, uint64_t n) { - n = nghttp3_htonl64(n); - return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n)); -} - -uint8_t *nghttp3_put_uint48be(uint8_t *p, uint64_t n) { - n = nghttp3_htonl64(n); - return nghttp3_cpymem(p, ((const uint8_t *)&n) + 2, 6); -} - -uint8_t *nghttp3_put_uint32be(uint8_t *p, uint32_t n) { - n = htonl(n); - return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n)); -} - -uint8_t *nghttp3_put_uint24be(uint8_t *p, uint32_t n) { - n = htonl(n); - return nghttp3_cpymem(p, ((const uint8_t *)&n) + 1, 3); -} - -uint8_t *nghttp3_put_uint16be(uint8_t *p, uint16_t n) { - n = htons(n); - return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n)); -} - -uint8_t *nghttp3_put_varint(uint8_t *p, int64_t n) { - uint8_t *rv; - if (n < 64) { - *p++ = (uint8_t)n; - return p; - } - if (n < 16384) { - rv = nghttp3_put_uint16be(p, (uint16_t)n); - *p |= 0x40; - return rv; - } - if (n < 1073741824) { - rv = nghttp3_put_uint32be(p, (uint32_t)n); - *p |= 0x80; - return rv; - } - assert(n < 4611686018427387904LL); - rv = nghttp3_put_uint64be(p, (uint64_t)n); - *p |= 0xc0; - return rv; -} - -size_t nghttp3_put_varint_len(int64_t n) { - if (n < 64) { - return 1; - } - if (n < 16384) { - return 2; - } - if (n < 1073741824) { - return 4; - } - assert(n < 4611686018427387904LL); - return 8; -} - -uint64_t nghttp3_ord_stream_id(int64_t stream_id) { - return (uint64_t)(stream_id >> 2) + 1; -} - -uint8_t nghttp3_pri_to_uint8(const nghttp3_pri *pri) { - return (uint8_t)((uint32_t)pri->inc << 7 | pri->urgency); -} diff --git a/deps/nghttp3/lib/nghttp3_conv.h b/deps/nghttp3/lib/nghttp3_conv.h deleted file mode 100644 index 6fae9fc9684a44..00000000000000 --- a/deps/nghttp3/lib/nghttp3_conv.h +++ /dev/null @@ -1,219 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_CONV_H -#define NGHTTP3_CONV_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#ifdef HAVE_ARPA_INET_H -# include -#endif /* HAVE_ARPA_INET_H */ - -#ifdef HAVE_NETINET_IN_H -# include -#endif /* HAVE_NETINET_IN_H */ - -#ifdef HAVE_BYTESWAP_H -# include -#endif /* HAVE_BYTESWAP_H */ - -#ifdef HAVE_ENDIAN_H -# include -#endif /* HAVE_ENDIAN_H */ - -#ifdef HAVE_SYS_ENDIAN_H -# include -#endif /* HAVE_SYS_ENDIAN_H */ - -#include - -#if defined HAVE_BSWAP_64 || HAVE_DECL_BSWAP_64 -# define nghttp3_bswap64 bswap_64 -#else /* !HAVE_BSWAP_64 */ -# define nghttp3_bswap64(N) \ - ((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32))) -#endif /* !HAVE_BSWAP_64 */ - -#if defined HAVE_BE64TOH || HAVE_DECL_BE64TOH -# define nghttp3_ntohl64(N) be64toh(N) -# define nghttp3_htonl64(N) htobe64(N) -#else /* !HAVE_BE64TOH */ -# if defined WORDS_BIGENDIAN -# define nghttp3_ntohl64(N) (N) -# define nghttp3_htonl64(N) (N) -# else /* !WORDS_BIGENDIAN */ -# define nghttp3_ntohl64(N) nghttp3_bswap64(N) -# define nghttp3_htonl64(N) nghttp3_bswap64(N) -# endif /* !WORDS_BIGENDIAN */ -#endif /* !HAVE_BE64TOH */ - -#if defined(WIN32) -/* Windows requires ws2_32 library for ntonl family of functions. We - define inline functions for those functions so that we don't have - dependency on that lib. */ - -# ifdef _MSC_VER -# define STIN static __inline -# else -# define STIN static inline -# endif - -STIN uint32_t htonl(uint32_t hostlong) { - uint32_t res; - unsigned char *p = (unsigned char *)&res; - *p++ = hostlong >> 24; - *p++ = (hostlong >> 16) & 0xffu; - *p++ = (hostlong >> 8) & 0xffu; - *p = hostlong & 0xffu; - return res; -} - -STIN uint16_t htons(uint16_t hostshort) { - uint16_t res; - unsigned char *p = (unsigned char *)&res; - *p++ = hostshort >> 8; - *p = hostshort & 0xffu; - return res; -} - -STIN uint32_t ntohl(uint32_t netlong) { - uint32_t res; - unsigned char *p = (unsigned char *)&netlong; - res = *p++ << 24; - res += *p++ << 16; - res += *p++ << 8; - res += *p; - return res; -} - -STIN uint16_t ntohs(uint16_t netshort) { - uint16_t res; - unsigned char *p = (unsigned char *)&netshort; - res = *p++ << 8; - res += *p; - return res; -} - -#endif /* WIN32 */ - -/* - * nghttp3_get_varint reads variable-length integer from |p|, and - * returns it in host byte order. The number of bytes read is stored - * in |*plen|. - */ -int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p); - -/* - * nghttp3_get_varint_fb reads first byte of encoded variable-length - * integer from |p|. - */ -int64_t nghttp3_get_varint_fb(const uint8_t *p); - -/* - * nghttp3_get_varint_len returns the required number of bytes to read - * variable-length integer starting at |p|. - */ -size_t nghttp3_get_varint_len(const uint8_t *p); - -/* - * nghttp3_put_uint64be writes |n| in host byte order in |p| in - * network byte order. It returns the one beyond of the last written - * position. - */ -uint8_t *nghttp3_put_uint64be(uint8_t *p, uint64_t n); - -/* - * nghttp3_put_uint48be writes |n| in host byte order in |p| in - * network byte order. It writes only least significant 48 bits. It - * returns the one beyond of the last written position. - */ -uint8_t *nghttp3_put_uint48be(uint8_t *p, uint64_t n); - -/* - * nghttp3_put_uint32be writes |n| in host byte order in |p| in - * network byte order. It returns the one beyond of the last written - * position. - */ -uint8_t *nghttp3_put_uint32be(uint8_t *p, uint32_t n); - -/* - * nghttp3_put_uint24be writes |n| in host byte order in |p| in - * network byte order. It writes only least significant 24 bits. It - * returns the one beyond of the last written position. - */ -uint8_t *nghttp3_put_uint24be(uint8_t *p, uint32_t n); - -/* - * nghttp3_put_uint16be writes |n| in host byte order in |p| in - * network byte order. It returns the one beyond of the last written - * position. - */ -uint8_t *nghttp3_put_uint16be(uint8_t *p, uint16_t n); - -/* - * nghttp3_put_varint writes |n| in |p| using variable-length integer - * encoding. It returns the one beyond of the last written position. - */ -uint8_t *nghttp3_put_varint(uint8_t *p, int64_t n); - -/* - * nghttp3_put_varint_len returns the required number of bytes to - * encode |n|. - */ -size_t nghttp3_put_varint_len(int64_t n); - -/* - * nghttp3_ord_stream_id returns the ordinal number of |stream_id|. - */ -uint64_t nghttp3_ord_stream_id(int64_t stream_id); - -/* - * NGHTTP3_PRI_INC_MASK is a bit mask to retrieve incremental bit from - * a value produced by nghttp3_pri_to_uint8. - */ -#define NGHTTP3_PRI_INC_MASK (1 << 7) - -/* - * nghttp3_pri_to_uint8 encodes |pri| into uint8_t variable. - */ -uint8_t nghttp3_pri_to_uint8(const nghttp3_pri *pri); - -/* - * nghttp3_pri_uint8_urgency extracts urgency from |PRI| which is - * supposed to be constructed by nghttp3_pri_to_uint8. - */ -#define nghttp3_pri_uint8_urgency(PRI) \ - ((uint32_t)((PRI) & ~NGHTTP3_PRI_INC_MASK)) - -/* - * nghttp3_pri_uint8_inc extracts inc from |PRI| which is supposed to - * be constructed by nghttp3_pri_to_uint8. - */ -#define nghttp3_pri_uint8_inc(PRI) (((PRI)&NGHTTP3_PRI_INC_MASK) != 0) - -#endif /* NGHTTP3_CONV_H */ diff --git a/deps/nghttp3/lib/nghttp3_debug.c b/deps/nghttp3/lib/nghttp3_debug.c deleted file mode 100644 index 4021b0dc469b66..00000000000000 --- a/deps/nghttp3/lib/nghttp3_debug.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2016 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_debug.h" - -#include - -#ifdef DEBUGBUILD - -static void nghttp3_default_debug_vfprintf_callback(const char *fmt, - va_list args) { - vfprintf(stderr, fmt, args); -} - -static nghttp3_debug_vprintf_callback static_debug_vprintf_callback = - nghttp3_default_debug_vfprintf_callback; - -void nghttp3_debug_vprintf(const char *format, ...) { - if (static_debug_vprintf_callback) { - va_list args; - va_start(args, format); - static_debug_vprintf_callback(format, args); - va_end(args); - } -} - -void nghttp3_set_debug_vprintf_callback( - nghttp3_debug_vprintf_callback debug_vprintf_callback) { - static_debug_vprintf_callback = debug_vprintf_callback; -} - -#else /* !DEBUGBUILD */ - -void nghttp3_set_debug_vprintf_callback( - nghttp3_debug_vprintf_callback debug_vprintf_callback) { - (void)debug_vprintf_callback; -} - -#endif /* !DEBUGBUILD */ diff --git a/deps/nghttp3/lib/nghttp3_debug.h b/deps/nghttp3/lib/nghttp3_debug.h deleted file mode 100644 index 01ed918414cfe5..00000000000000 --- a/deps/nghttp3/lib/nghttp3_debug.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2016 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_DEBUG_H -#define NGHTTP3_DEBUG_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#ifdef DEBUGBUILD -# define DEBUGF(...) nghttp3_debug_vprintf(__VA_ARGS__) -void nghttp3_debug_vprintf(const char *format, ...); -#else -# define DEBUGF(...) \ - do { \ - } while (0) -#endif - -#endif /* NGHTTP3_DEBUG_H */ diff --git a/deps/nghttp3/lib/nghttp3_err.c b/deps/nghttp3/lib/nghttp3_err.c deleted file mode 100644 index 23033d4640d622..00000000000000 --- a/deps/nghttp3/lib/nghttp3_err.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_err.h" - -const char *nghttp3_strerror(int liberr) { - switch (liberr) { - case NGHTTP3_ERR_INVALID_ARGUMENT: - return "ERR_INVALID_ARGUMENT"; - case NGHTTP3_ERR_NOBUF: - return "ERR_NOBUF"; - case NGHTTP3_ERR_INVALID_STATE: - return "ERR_INVALID_STATE"; - case NGHTTP3_ERR_WOULDBLOCK: - return "ERR_WOULDBLOCK"; - case NGHTTP3_ERR_STREAM_IN_USE: - return "ERR_STREAM_IN_USE"; - case NGHTTP3_ERR_PUSH_ID_BLOCKED: - return "ERR_PUSH_ID_BLOCKED"; - case NGHTTP3_ERR_MALFORMED_HTTP_HEADER: - return "ERR_MALFORMED_HTTP_HEADER"; - case NGHTTP3_ERR_REMOVE_HTTP_HEADER: - return "ERR_REMOVE_HTTP_HEADER"; - case NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING: - return "ERR_MALFORMED_HTTP_MESSAGING"; - case NGHTTP3_ERR_TOO_LATE: - return "ERR_TOO_LATE"; - case NGHTTP3_ERR_QPACK_FATAL: - return "ERR_QPACK_FATAL"; - case NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE: - return "ERR_QPACK_HEADER_TOO_LARGE"; - case NGHTTP3_ERR_IGNORE_STREAM: - return "ERR_IGNORE_STREAM"; - case NGHTTP3_ERR_STREAM_NOT_FOUND: - return "ERR_STREAM_NOT_FOUND"; - case NGHTTP3_ERR_IGNORE_PUSH_PROMISE: - return "ERR_IGNORE_PUSH_PROMISE"; - case NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED: - return "ERR_QPACK_DECOMPRESSION_FAILED"; - case NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR: - return "ERR_QPACK_ENCODER_STREAM_ERROR"; - case NGHTTP3_ERR_QPACK_DECODER_STREAM_ERROR: - return "ERR_QPACK_DECODER_STREAM_ERROR"; - case NGHTTP3_ERR_H3_FRAME_UNEXPECTED: - return "ERR_H3_FRAME_UNEXPECTED"; - case NGHTTP3_ERR_H3_FRAME_ERROR: - return "ERR_H3_FRAME_ERROR"; - case NGHTTP3_ERR_H3_MISSING_SETTINGS: - return "ERR_H3_MISSING_SETTINGS"; - case NGHTTP3_ERR_H3_INTERNAL_ERROR: - return "ERR_H3_INTERNAL_ERROR"; - case NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM: - return "ERR_CLOSED_CRITICAL_STREAM"; - case NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR: - return "ERR_H3_GENERAL_PROTOCOL_ERROR"; - case NGHTTP3_ERR_H3_ID_ERROR: - return "ERR_H3_ID_ERROR"; - case NGHTTP3_ERR_H3_SETTINGS_ERROR: - return "ERR_H3_SETTINGS_ERROR"; - case NGHTTP3_ERR_H3_STREAM_CREATION_ERROR: - return "ERR_H3_STREAM_CREATION_ERROR"; - case NGHTTP3_ERR_NOMEM: - return "ERR_NOMEM"; - case NGHTTP3_ERR_CALLBACK_FAILURE: - return "ERR_CALLBACK_FAILURE"; - default: - return "(unknown)"; - } -} - -uint64_t nghttp3_err_infer_quic_app_error_code(int liberr) { - switch (liberr) { - case 0: - return NGHTTP3_H3_NO_ERROR; - case NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED: - return NGHTTP3_QPACK_DECOMPRESSION_FAILED; - case NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR: - return NGHTTP3_QPACK_ENCODER_STREAM_ERROR; - case NGHTTP3_ERR_QPACK_DECODER_STREAM_ERROR: - return NGHTTP3_QPACK_DECODER_STREAM_ERROR; - case NGHTTP3_ERR_H3_FRAME_UNEXPECTED: - return NGHTTP3_H3_FRAME_UNEXPECTED; - case NGHTTP3_ERR_H3_FRAME_ERROR: - return NGHTTP3_H3_FRAME_ERROR; - case NGHTTP3_ERR_H3_MISSING_SETTINGS: - return NGHTTP3_H3_MISSING_SETTINGS; - case NGHTTP3_ERR_H3_INTERNAL_ERROR: - return NGHTTP3_H3_INTERNAL_ERROR; - case NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM: - return NGHTTP3_H3_CLOSED_CRITICAL_STREAM; - case NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR: - return NGHTTP3_H3_GENERAL_PROTOCOL_ERROR; - case NGHTTP3_ERR_H3_ID_ERROR: - return NGHTTP3_H3_ID_ERROR; - case NGHTTP3_ERR_H3_SETTINGS_ERROR: - return NGHTTP3_H3_SETTINGS_ERROR; - case NGHTTP3_ERR_H3_STREAM_CREATION_ERROR: - return NGHTTP3_H3_STREAM_CREATION_ERROR; - default: - return NGHTTP3_H3_GENERAL_PROTOCOL_ERROR; - } -} diff --git a/deps/nghttp3/lib/nghttp3_err.h b/deps/nghttp3/lib/nghttp3_err.h deleted file mode 100644 index 2fa914f86b189e..00000000000000 --- a/deps/nghttp3/lib/nghttp3_err.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_ERR_H -#define NGHTTP3_ERR_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#endif /* NGHTTP3_ERR_H */ diff --git a/deps/nghttp3/lib/nghttp3_frame.c b/deps/nghttp3/lib/nghttp3_frame.c deleted file mode 100644 index 479b794f9aebb9..00000000000000 --- a/deps/nghttp3/lib/nghttp3_frame.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2013 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_frame.h" - -#include - -#include "nghttp3_conv.h" -#include "nghttp3_str.h" - -uint8_t *nghttp3_frame_write_hd(uint8_t *p, const nghttp3_frame_hd *hd) { - p = nghttp3_put_varint(p, hd->type); - p = nghttp3_put_varint(p, hd->length); - return p; -} - -size_t nghttp3_frame_write_hd_len(const nghttp3_frame_hd *hd) { - return nghttp3_put_varint_len(hd->type) + nghttp3_put_varint_len(hd->length); -} - -uint8_t *nghttp3_frame_write_settings(uint8_t *p, - const nghttp3_frame_settings *fr) { - size_t i; - - p = nghttp3_frame_write_hd(p, &fr->hd); - - for (i = 0; i < fr->niv; ++i) { - p = nghttp3_put_varint(p, (int64_t)fr->iv[i].id); - p = nghttp3_put_varint(p, (int64_t)fr->iv[i].value); - } - - return p; -} - -size_t nghttp3_frame_write_settings_len(int64_t *ppayloadlen, - const nghttp3_frame_settings *fr) { - size_t payloadlen = 0; - size_t i; - - for (i = 0; i < fr->niv; ++i) { - payloadlen += nghttp3_put_varint_len((int64_t)fr->iv[i].id) + - nghttp3_put_varint_len((int64_t)fr->iv[i].value); - } - - *ppayloadlen = (int64_t)payloadlen; - - return nghttp3_put_varint_len(NGHTTP3_FRAME_SETTINGS) + - nghttp3_put_varint_len((int64_t)payloadlen) + payloadlen; -} - -uint8_t *nghttp3_frame_write_cancel_push(uint8_t *p, - const nghttp3_frame_cancel_push *fr) { - p = nghttp3_frame_write_hd(p, &fr->hd); - p = nghttp3_put_varint(p, fr->push_id); - - return p; -} - -size_t -nghttp3_frame_write_cancel_push_len(int64_t *ppayloadlen, - const nghttp3_frame_cancel_push *fr) { - size_t payloadlen = nghttp3_put_varint_len(fr->push_id); - - *ppayloadlen = (int64_t)payloadlen; - - return nghttp3_put_varint_len(NGHTTP3_FRAME_CANCEL_PUSH) + - nghttp3_put_varint_len((int64_t)payloadlen) + payloadlen; -} - -uint8_t *nghttp3_frame_write_max_push_id(uint8_t *p, - const nghttp3_frame_max_push_id *fr) { - p = nghttp3_frame_write_hd(p, &fr->hd); - p = nghttp3_put_varint(p, fr->push_id); - - return p; -} - -size_t -nghttp3_frame_write_max_push_id_len(int64_t *ppayloadlen, - const nghttp3_frame_max_push_id *fr) { - size_t payloadlen = nghttp3_put_varint_len(fr->push_id); - - *ppayloadlen = (int64_t)payloadlen; - - return nghttp3_put_varint_len(NGHTTP3_FRAME_MAX_PUSH_ID) + - nghttp3_put_varint_len((int64_t)payloadlen) + payloadlen; -} - -int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen, - const nghttp3_mem *mem) { - size_t i; - uint8_t *data = NULL; - size_t buflen = 0; - nghttp3_nv *p; - - if (nvlen == 0) { - *pnva = NULL; - - return 0; - } - - for (i = 0; i < nvlen; ++i) { - /* + 1 for null-termination */ - if ((nva[i].flags & NGHTTP3_NV_FLAG_NO_COPY_NAME) == 0) { - buflen += nva[i].namelen + 1; - } - if ((nva[i].flags & NGHTTP3_NV_FLAG_NO_COPY_VALUE) == 0) { - buflen += nva[i].valuelen + 1; - } - } - - buflen += sizeof(nghttp3_nv) * nvlen; - - *pnva = nghttp3_mem_malloc(mem, buflen); - - if (*pnva == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - p = *pnva; - data = (uint8_t *)(*pnva) + sizeof(nghttp3_nv) * nvlen; - - for (i = 0; i < nvlen; ++i) { - p->flags = nva[i].flags; - - if (nva[i].flags & NGHTTP3_NV_FLAG_NO_COPY_NAME) { - p->name = nva[i].name; - p->namelen = nva[i].namelen; - } else { - if (nva[i].namelen) { - memcpy(data, nva[i].name, nva[i].namelen); - } - p->name = data; - p->namelen = nva[i].namelen; - data[p->namelen] = '\0'; - nghttp3_downcase(p->name, p->namelen); - data += nva[i].namelen + 1; - } - - if (nva[i].flags & NGHTTP3_NV_FLAG_NO_COPY_VALUE) { - p->value = nva[i].value; - p->valuelen = nva[i].valuelen; - } else { - if (nva[i].valuelen) { - memcpy(data, nva[i].value, nva[i].valuelen); - } - p->value = data; - p->valuelen = nva[i].valuelen; - data[p->valuelen] = '\0'; - data += nva[i].valuelen + 1; - } - - ++p; - } - return 0; -} - -void nghttp3_nva_del(nghttp3_nv *nva, const nghttp3_mem *mem) { - nghttp3_mem_free(mem, nva); -} - -void nghttp3_frame_headers_free(nghttp3_frame_headers *fr, - const nghttp3_mem *mem) { - if (fr == NULL) { - return; - } - - nghttp3_nva_del(fr->nva, mem); -} - -void nghttp3_frame_push_promise_free(nghttp3_frame_push_promise *fr, - const nghttp3_mem *mem) { - if (fr == NULL) { - return; - } - - nghttp3_nva_del(fr->nva, mem); -} diff --git a/deps/nghttp3/lib/nghttp3_frame.h b/deps/nghttp3/lib/nghttp3_frame.h deleted file mode 100644 index be333e950909e4..00000000000000 --- a/deps/nghttp3/lib/nghttp3_frame.h +++ /dev/null @@ -1,214 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2013 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_FRAME_H -#define NGHTTP3_FRAME_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "nghttp3_buf.h" - -typedef enum { - NGHTTP3_FRAME_DATA = 0x00, - NGHTTP3_FRAME_HEADERS = 0x01, - NGHTTP3_FRAME_CANCEL_PUSH = 0x03, - NGHTTP3_FRAME_SETTINGS = 0x04, - NGHTTP3_FRAME_PUSH_PROMISE = 0x05, - NGHTTP3_FRAME_GOAWAY = 0x07, - NGHTTP3_FRAME_MAX_PUSH_ID = 0x0d, -} nghttp3_frame_type; - -typedef struct { - int64_t type; - int64_t length; -} nghttp3_frame_hd; - -typedef struct { - nghttp3_frame_hd hd; -} nghttp3_frame_data; - -typedef struct { - nghttp3_frame_hd hd; - nghttp3_nv *nva; - size_t nvlen; -} nghttp3_frame_headers; - -typedef struct { - nghttp3_frame_hd hd; - int64_t push_id; -} nghttp3_frame_cancel_push; - -#define NGHTTP3_SETTINGS_ID_MAX_FIELD_SECTION_SIZE 0x06 -#define NGHTTP3_SETTINGS_ID_QPACK_MAX_TABLE_CAPACITY 0x01 -#define NGHTTP3_SETTINGS_ID_QPACK_BLOCKED_STREAMS 0x07 - -typedef struct { - uint64_t id; - uint64_t value; -} nghttp3_settings_entry; - -typedef struct { - nghttp3_frame_hd hd; - size_t niv; - nghttp3_settings_entry iv[1]; -} nghttp3_frame_settings; - -typedef struct { - nghttp3_frame_hd hd; - nghttp3_nv *nva; - size_t nvlen; - int64_t push_id; -} nghttp3_frame_push_promise; - -typedef struct { - nghttp3_frame_hd hd; - int64_t stream_id; -} nghttp3_frame_goaway; - -typedef struct { - nghttp3_frame_hd hd; - int64_t push_id; -} nghttp3_frame_max_push_id; - -typedef union { - nghttp3_frame_hd hd; - nghttp3_frame_data data; - nghttp3_frame_headers headers; - nghttp3_frame_cancel_push cancel_push; - nghttp3_frame_settings settings; - nghttp3_frame_push_promise push_promise; - nghttp3_frame_goaway goaway; - nghttp3_frame_max_push_id max_push_id; -} nghttp3_frame; - -/* - * nghttp3_frame_write_hd writes frame header |hd| to |dest|. This - * function assumes that |dest| has enough space to write |hd|. - * - * This function returns |dest| plus the number of bytes written. - */ -uint8_t *nghttp3_frame_write_hd(uint8_t *dest, const nghttp3_frame_hd *hd); - -/* - * nghttp3_frame_write_hd_len returns the number of bytes required to - * write |hd|. hd->length must be set. - */ -size_t nghttp3_frame_write_hd_len(const nghttp3_frame_hd *hd); - -/* - * nghttp3_frame_write_settings writes SETTINGS frame |fr| to |dest|. - * This function assumes that |dest| has enough space to write |fr|. - * - * This function returns |dest| plus the number of bytes written. - */ -uint8_t *nghttp3_frame_write_settings(uint8_t *dest, - const nghttp3_frame_settings *fr); - -/* - * nghttp3_frame_write_settings_len returns the number of bytes - * required to write |fr|. fr->hd.length is ignored. This function - * stores payload length in |*ppayloadlen|. - */ -size_t nghttp3_frame_write_settings_len(int64_t *pppayloadlen, - const nghttp3_frame_settings *fr); - -/* - * nghttp3_frame_write_cancel_push writes CANCEL_PUSH frame |fr| to - * |dest|. This function assumes that |dest| has enough space to - * write |fr|. - * - * This function returns |dest| plus the number of bytes written. - */ -uint8_t *nghttp3_frame_write_cancel_push(uint8_t *dest, - const nghttp3_frame_cancel_push *fr); - -/* - * nghttp3_frame_write_cancel_push_len returns the number of bytes - * required to write |fr|. fr->hd.length is ignored. This function - * stores payload length in |*ppayloadlen|. - */ -size_t nghttp3_frame_write_cancel_push_len(int64_t *ppayloadlen, - const nghttp3_frame_cancel_push *fr); - -/* - * nghttp3_frame_write_max_push_id writes MAX_PUSH_ID frame |fr| to - * |dest|. This function assumes that |dest| has enough space to - * write |fr|. - * - * This function returns |dest| plus the number of bytes written. - */ -uint8_t *nghttp3_frame_write_max_push_id(uint8_t *dest, - const nghttp3_frame_max_push_id *fr); - -/* - * nghttp3_frame_write_max_push_id_len returns the number of bytes - * required to write |fr|. fr->hd.length is ignored. This function - * stores payload length in |*ppayloadlen|. - */ -size_t nghttp3_frame_write_max_push_id_len(int64_t *ppayloadlen, - const nghttp3_frame_max_push_id *fr); - -/* - * nghttp3_nva_copy copies name/value pairs from |nva|, which contains - * |nvlen| pairs, to |*nva_ptr|, which is dynamically allocated so - * that all items can be stored. The resultant name and value in - * nghttp2_nv are guaranteed to be NULL-terminated even if the input - * is not null-terminated. - * - * The |*pnva| must be freed using nghttp3_nva_del(). - * - * This function returns 0 if it succeeds or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen, - const nghttp3_mem *mem); - -/* - * nghttp3_nva_del frees |nva|. - */ -void nghttp3_nva_del(nghttp3_nv *nva, const nghttp3_mem *mem); - -/* - * nghttp3_frame_headers_free frees memory allocated for |fr|. It - * assumes that fr->nva is created by nghttp3_nva_copy() or NULL. - */ -void nghttp3_frame_headers_free(nghttp3_frame_headers *fr, - const nghttp3_mem *mem); - -/* - * nghttp3_frame_push_promise_free frees memory allocated for |fr|. - * It assumes that fr->nva is created by nghttp3_nva_copy() or NULL. - */ -void nghttp3_frame_push_promise_free(nghttp3_frame_push_promise *fr, - const nghttp3_mem *mem); - -#endif /* NGHTTP3_FRAME_H */ diff --git a/deps/nghttp3/lib/nghttp3_gaptr.c b/deps/nghttp3/lib/nghttp3_gaptr.c deleted file mode 100644 index 1faabbf09f8604..00000000000000 --- a/deps/nghttp3/lib/nghttp3_gaptr.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_gaptr.h" - -#include -#include - -#include "nghttp3_macro.h" - -int nghttp3_gaptr_init(nghttp3_gaptr *gaptr, const nghttp3_mem *mem) { - int rv; - nghttp3_range range = {0, UINT64_MAX}; - - rv = nghttp3_ksl_init(&gaptr->gap, nghttp3_ksl_range_compar, - sizeof(nghttp3_range), mem); - if (rv != 0) { - return rv; - } - - rv = nghttp3_ksl_insert(&gaptr->gap, NULL, &range, NULL); - if (rv != 0) { - nghttp3_ksl_free(&gaptr->gap); - return rv; - } - - gaptr->mem = mem; - - return 0; -} - -void nghttp3_gaptr_free(nghttp3_gaptr *gaptr) { - if (gaptr == NULL) { - return; - } - - nghttp3_ksl_free(&gaptr->gap); -} - -int nghttp3_gaptr_push(nghttp3_gaptr *gaptr, uint64_t offset, size_t datalen) { - int rv; - nghttp3_range k, m, l, r, q = {offset, offset + datalen}; - nghttp3_ksl_it it; - - it = nghttp3_ksl_lower_bound_compar(&gaptr->gap, &q, - nghttp3_ksl_range_exclusive_compar); - - for (; !nghttp3_ksl_it_end(&it);) { - k = *(nghttp3_range *)nghttp3_ksl_it_key(&it); - m = nghttp3_range_intersect(&q, &k); - if (!nghttp3_range_len(&m)) { - break; - } - - if (nghttp3_range_eq(&k, &m)) { - nghttp3_ksl_remove(&gaptr->gap, &it, &k); - continue; - } - nghttp3_range_cut(&l, &r, &k, &m); - if (nghttp3_range_len(&l)) { - nghttp3_ksl_update_key(&gaptr->gap, &k, &l); - - if (nghttp3_range_len(&r)) { - rv = nghttp3_ksl_insert(&gaptr->gap, &it, &r, NULL); - if (rv != 0) { - return rv; - } - } - } else if (nghttp3_range_len(&r)) { - nghttp3_ksl_update_key(&gaptr->gap, &k, &r); - } - nghttp3_ksl_it_next(&it); - } - return 0; -} - -uint64_t nghttp3_gaptr_first_gap_offset(nghttp3_gaptr *gaptr) { - nghttp3_ksl_it it = nghttp3_ksl_begin(&gaptr->gap); - return ((nghttp3_range *)nghttp3_ksl_it_key(&it))->begin; -} - -nghttp3_ksl_it nghttp3_gaptr_get_first_gap_after(nghttp3_gaptr *gaptr, - uint64_t offset) { - nghttp3_range q = {offset, offset + 1}; - return nghttp3_ksl_lower_bound_compar(&gaptr->gap, &q, - nghttp3_ksl_range_exclusive_compar); -} - -int nghttp3_gaptr_is_pushed(nghttp3_gaptr *gaptr, uint64_t offset, - size_t datalen) { - nghttp3_range q = {offset, offset + datalen}; - nghttp3_ksl_it it = nghttp3_ksl_lower_bound_compar( - &gaptr->gap, &q, nghttp3_ksl_range_exclusive_compar); - nghttp3_range m = - nghttp3_range_intersect(&q, (nghttp3_range *)nghttp3_ksl_it_key(&it)); - return nghttp3_range_len(&m) == 0; -} diff --git a/deps/nghttp3/lib/nghttp3_gaptr.h b/deps/nghttp3/lib/nghttp3_gaptr.h deleted file mode 100644 index 6972b404432377..00000000000000 --- a/deps/nghttp3/lib/nghttp3_gaptr.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_GAPTR_H -#define NGHTTP3_GAPTR_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "nghttp3_mem.h" -#include "nghttp3_range.h" -#include "nghttp3_ksl.h" - -/* - * nghttp3_gaptr maintains the gap in the range [0, UINT64_MAX). - */ -typedef struct { - /* gap maintains the range of offset which is not received - yet. Initially, its range is [0, UINT64_MAX). */ - nghttp3_ksl gap; - /* mem is custom memory allocator */ - const nghttp3_mem *mem; -} nghttp3_gaptr; - -/* - * nghttp3_gaptr_init initializes |gaptr|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_gaptr_init(nghttp3_gaptr *gaptr, const nghttp3_mem *mem); - -/* - * nghttp3_gaptr_free frees resources allocated for |gaptr|. - */ -void nghttp3_gaptr_free(nghttp3_gaptr *gaptr); - -/* - * nghttp3_gaptr_push adds new data of length |datalen| at the stream - * offset |offset|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory - */ -int nghttp3_gaptr_push(nghttp3_gaptr *gaptr, uint64_t offset, size_t datalen); - -/* - * nghttp3_gaptr_first_gap_offset returns the offset to the first gap. - * If there is no gap, it returns UINT64_MAX. - */ -uint64_t nghttp3_gaptr_first_gap_offset(nghttp3_gaptr *gaptr); - -/* - * nghttp3_gaptr_get_first_gap_after returns the iterator pointing to - * the first gap which overlaps or comes after |offset|. - */ -nghttp3_ksl_it nghttp3_gaptr_get_first_gap_after(nghttp3_gaptr *gaptr, - uint64_t offset); - -/* - * nghttp3_gaptr_is_pushed returns nonzero if range [offset, offset + - * datalen) is completely pushed into this object. - */ -int nghttp3_gaptr_is_pushed(nghttp3_gaptr *gaptr, uint64_t offset, - size_t datalen); - -#endif /* NGHTTP3_GAPTR_H */ diff --git a/deps/nghttp3/lib/nghttp3_http.c b/deps/nghttp3/lib/nghttp3_http.c deleted file mode 100644 index dc84c16b5d88e6..00000000000000 --- a/deps/nghttp3/lib/nghttp3_http.c +++ /dev/null @@ -1,840 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2015 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_http.h" - -#include -#include - -#include "nghttp3_stream.h" -#include "nghttp3_macro.h" -#include "nghttp3_conv.h" - -static uint8_t downcase(uint8_t c) { - return 'A' <= c && c <= 'Z' ? (uint8_t)(c - 'A' + 'a') : c; -} - -static int memieq(const void *a, const void *b, size_t n) { - size_t i; - const uint8_t *aa = a, *bb = b; - - for (i = 0; i < n; ++i) { - if (downcase(aa[i]) != downcase(bb[i])) { - return 0; - } - } - return 1; -} - -#define lstrieq(A, B, N) ((sizeof((A)) - 1) == (N) && memieq((A), (B), (N))) - -static int64_t parse_uint(const uint8_t *s, size_t len) { - int64_t n = 0; - size_t i; - if (len == 0) { - return -1; - } - for (i = 0; i < len; ++i) { - if ('0' <= s[i] && s[i] <= '9') { - if (n > INT64_MAX / 10) { - return -1; - } - n *= 10; - if (n > INT64_MAX - (s[i] - '0')) { - return -1; - } - n += s[i] - '0'; - continue; - } - return -1; - } - return n; -} - -static int lws(const uint8_t *s, size_t n) { - size_t i; - for (i = 0; i < n; ++i) { - if (s[i] != ' ' && s[i] != '\t') { - return 0; - } - } - return 1; -} - -static int check_pseudo_header(nghttp3_http_state *http, - const nghttp3_qpack_nv *nv, int flag) { - if (http->flags & flag) { - return 0; - } - if (lws(nv->value->base, nv->value->len)) { - return 0; - } - http->flags = (uint16_t)(http->flags | flag); - return 1; -} - -static int expect_response_body(nghttp3_http_state *http) { - return (http->flags & NGHTTP3_HTTP_FLAG_METH_HEAD) == 0 && - http->status_code / 100 != 1 && http->status_code != 304 && - http->status_code != 204; -} - -/* For "http" or "https" URIs, OPTIONS request may have "*" in :path - header field to represent system-wide OPTIONS request. Otherwise, - :path header field value must start with "/". This function must - be called after ":method" header field was received. This function - returns nonzero if path is valid.*/ -static int check_path(nghttp3_http_state *http) { - return (http->flags & NGHTTP3_HTTP_FLAG_SCHEME_HTTP) == 0 || - ((http->flags & NGHTTP3_HTTP_FLAG_PATH_REGULAR) || - ((http->flags & NGHTTP3_HTTP_FLAG_METH_OPTIONS) && - (http->flags & NGHTTP3_HTTP_FLAG_PATH_ASTERISK))); -} - -int nghttp3_http_parse_priority(nghttp3_pri *dest, const uint8_t *value, - size_t len) { - nghttp3_pri pri = *dest; - const uint8_t *p = value, *end = value + len; - - for (;;) { - for (; p != end && (*p == ' ' || *p == '\t'); ++p) - ; - - if (p == end) { - break; - } - - switch (*p) { - case 'u': - ++p; - - if (p + 2 > end || *p++ != '=') { - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - if (!('0' <= *p && *p <= '7')) { - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - pri.urgency = (uint32_t)(*p++ - '0'); - - if (p == end) { - goto fin; - } - - if (*p++ != ',') { - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - break; - case 'i': - ++p; - - if (p == end) { - pri.inc = 1; - goto fin; - } - - if (*p == ',') { - pri.inc = 1; - ++p; - break; - } - - if (p + 3 > end || *p != '=' || *(p + 1) != '?' || - (*(p + 2) != '0' && *(p + 2) != '1')) { - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - pri.inc = *(p + 2) == '1'; - - p += 3; - - if (p == end) { - goto fin; - } - - if (*p++ != ',') { - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - break; - default: - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - if (p == end) { - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - } - -fin: - - *dest = pri; - - return 0; -} - -static int http_request_on_header(nghttp3_http_state *http, int64_t frame_type, - nghttp3_qpack_nv *nv, int trailers, - int connect_protocol) { - nghttp3_pri pri; - - if (nv->name->base[0] == ':') { - if (trailers || - (http->flags & NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - } - - switch (nv->token) { - case NGHTTP3_QPACK_TOKEN__AUTHORITY: - if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__AUTHORITY)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - break; - case NGHTTP3_QPACK_TOKEN__METHOD: - if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__METHOD)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - switch (nv->value->len) { - case 4: - if (lstreq("HEAD", nv->value->base, nv->value->len)) { - http->flags |= NGHTTP3_HTTP_FLAG_METH_HEAD; - } - break; - case 7: - switch (nv->value->base[6]) { - case 'T': - if (lstreq("CONNECT", nv->value->base, nv->value->len)) { - if (frame_type == NGHTTP3_FRAME_PUSH_PROMISE) { - /* we won't allow CONNECT for push */ - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - http->flags |= NGHTTP3_HTTP_FLAG_METH_CONNECT; - } - break; - case 'S': - if (lstreq("OPTIONS", nv->value->base, nv->value->len)) { - http->flags |= NGHTTP3_HTTP_FLAG_METH_OPTIONS; - } - break; - } - break; - } - break; - case NGHTTP3_QPACK_TOKEN__PATH: - if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__PATH)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - if (nv->value->base[0] == '/') { - http->flags |= NGHTTP3_HTTP_FLAG_PATH_REGULAR; - } else if (nv->value->len == 1 && nv->value->base[0] == '*') { - http->flags |= NGHTTP3_HTTP_FLAG_PATH_ASTERISK; - } - break; - case NGHTTP3_QPACK_TOKEN__SCHEME: - if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__SCHEME)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - if ((nv->value->len == 4 && memieq("http", nv->value->base, 4)) || - (nv->value->len == 5 && memieq("https", nv->value->base, 5))) { - http->flags |= NGHTTP3_HTTP_FLAG_SCHEME_HTTP; - } - break; - case NGHTTP3_QPACK_TOKEN__PROTOCOL: - if (!connect_protocol) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - - if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__PROTOCOL)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - break; - case NGHTTP3_QPACK_TOKEN_HOST: - if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG_HOST)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - break; - case NGHTTP3_QPACK_TOKEN_CONTENT_LENGTH: { - /* https://tools.ietf.org/html/rfc7230#section-4.1.2: A sender - MUST NOT generate a trailer that contains a field necessary for - message framing (e.g., Transfer-Encoding and Content-Length), - ... */ - if (trailers) { - return NGHTTP3_ERR_REMOVE_HTTP_HEADER; - } - if (http->content_length != -1) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - http->content_length = parse_uint(nv->value->base, nv->value->len); - if (http->content_length == -1) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - break; - } - /* disallowed header fields */ - case NGHTTP3_QPACK_TOKEN_CONNECTION: - case NGHTTP3_QPACK_TOKEN_KEEP_ALIVE: - case NGHTTP3_QPACK_TOKEN_PROXY_CONNECTION: - case NGHTTP3_QPACK_TOKEN_TRANSFER_ENCODING: - case NGHTTP3_QPACK_TOKEN_UPGRADE: - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - case NGHTTP3_QPACK_TOKEN_TE: - if (!lstrieq("trailers", nv->value->base, nv->value->len)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - break; - case NGHTTP3_QPACK_TOKEN_PRIORITY: - pri.urgency = nghttp3_pri_uint8_urgency(http->pri); - pri.inc = nghttp3_pri_uint8_inc(http->pri); - if (nghttp3_http_parse_priority(&pri, nv->value->base, nv->value->len) == - 0) { - http->pri = nghttp3_pri_to_uint8(&pri); - } - break; - default: - if (nv->name->base[0] == ':') { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - } - - if (nv->name->base[0] != ':') { - http->flags |= NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED; - } - - return 0; -} - -static int http_response_on_header(nghttp3_http_state *http, - nghttp3_qpack_nv *nv, int trailers) { - if (nv->name->base[0] == ':') { - if (trailers || - (http->flags & NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - } - - switch (nv->token) { - case NGHTTP3_QPACK_TOKEN__STATUS: { - if (!check_pseudo_header(http, nv, NGHTTP3_HTTP_FLAG__STATUS)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - if (nv->value->len != 3) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - http->status_code = (int16_t)parse_uint(nv->value->base, nv->value->len); - if (http->status_code < 100 || http->status_code == 101) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - break; - } - case NGHTTP3_QPACK_TOKEN_CONTENT_LENGTH: { - /* https://tools.ietf.org/html/rfc7230#section-4.1.2: A sender - MUST NOT generate a trailer that contains a field necessary for - message framing (e.g., Transfer-Encoding and Content-Length), - ... */ - if (trailers) { - return NGHTTP3_ERR_REMOVE_HTTP_HEADER; - } - if (http->status_code == 204) { - /* content-length header field in 204 response is prohibited by - RFC 7230. But some widely used servers send content-length: - 0. Until they get fixed, we ignore it. */ - if (http->content_length != -1) { - /* Found multiple content-length field */ - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - if (!lstrieq("0", nv->value->base, nv->value->len)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - http->content_length = 0; - return NGHTTP3_ERR_REMOVE_HTTP_HEADER; - } - if (http->status_code / 100 == 1) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - /* https://tools.ietf.org/html/rfc7230#section-3.3.3 */ - if (http->status_code / 100 == 2 && - (http->flags & NGHTTP3_HTTP_FLAG_METH_CONNECT)) { - return NGHTTP3_ERR_REMOVE_HTTP_HEADER; - } - if (http->content_length != -1) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - http->content_length = parse_uint(nv->value->base, nv->value->len); - if (http->content_length == -1) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - break; - } - /* disallowed header fields */ - case NGHTTP3_QPACK_TOKEN_CONNECTION: - case NGHTTP3_QPACK_TOKEN_KEEP_ALIVE: - case NGHTTP3_QPACK_TOKEN_PROXY_CONNECTION: - case NGHTTP3_QPACK_TOKEN_TRANSFER_ENCODING: - case NGHTTP3_QPACK_TOKEN_UPGRADE: - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - case NGHTTP3_QPACK_TOKEN_TE: - if (!lstrieq("trailers", nv->value->base, nv->value->len)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - break; - default: - if (nv->name->base[0] == ':') { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - } - - if (nv->name->base[0] != ':') { - http->flags |= NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED; - } - - return 0; -} - -/* Generated by genauthroitychartbl.py */ -static char VALID_AUTHORITY_CHARS[] = { - 0 /* NUL */, 0 /* SOH */, 0 /* STX */, 0 /* ETX */, - 0 /* EOT */, 0 /* ENQ */, 0 /* ACK */, 0 /* BEL */, - 0 /* BS */, 0 /* HT */, 0 /* LF */, 0 /* VT */, - 0 /* FF */, 0 /* CR */, 0 /* SO */, 0 /* SI */, - 0 /* DLE */, 0 /* DC1 */, 0 /* DC2 */, 0 /* DC3 */, - 0 /* DC4 */, 0 /* NAK */, 0 /* SYN */, 0 /* ETB */, - 0 /* CAN */, 0 /* EM */, 0 /* SUB */, 0 /* ESC */, - 0 /* FS */, 0 /* GS */, 0 /* RS */, 0 /* US */, - 0 /* SPC */, 1 /* ! */, 0 /* " */, 0 /* # */, - 1 /* $ */, 1 /* % */, 1 /* & */, 1 /* ' */, - 1 /* ( */, 1 /* ) */, 1 /* * */, 1 /* + */, - 1 /* , */, 1 /* - */, 1 /* . */, 0 /* / */, - 1 /* 0 */, 1 /* 1 */, 1 /* 2 */, 1 /* 3 */, - 1 /* 4 */, 1 /* 5 */, 1 /* 6 */, 1 /* 7 */, - 1 /* 8 */, 1 /* 9 */, 1 /* : */, 1 /* ; */, - 0 /* < */, 1 /* = */, 0 /* > */, 0 /* ? */, - 1 /* @ */, 1 /* A */, 1 /* B */, 1 /* C */, - 1 /* D */, 1 /* E */, 1 /* F */, 1 /* G */, - 1 /* H */, 1 /* I */, 1 /* J */, 1 /* K */, - 1 /* L */, 1 /* M */, 1 /* N */, 1 /* O */, - 1 /* P */, 1 /* Q */, 1 /* R */, 1 /* S */, - 1 /* T */, 1 /* U */, 1 /* V */, 1 /* W */, - 1 /* X */, 1 /* Y */, 1 /* Z */, 1 /* [ */, - 0 /* \ */, 1 /* ] */, 0 /* ^ */, 1 /* _ */, - 0 /* ` */, 1 /* a */, 1 /* b */, 1 /* c */, - 1 /* d */, 1 /* e */, 1 /* f */, 1 /* g */, - 1 /* h */, 1 /* i */, 1 /* j */, 1 /* k */, - 1 /* l */, 1 /* m */, 1 /* n */, 1 /* o */, - 1 /* p */, 1 /* q */, 1 /* r */, 1 /* s */, - 1 /* t */, 1 /* u */, 1 /* v */, 1 /* w */, - 1 /* x */, 1 /* y */, 1 /* z */, 0 /* { */, - 0 /* | */, 0 /* } */, 1 /* ~ */, 0 /* DEL */, - 0 /* 0x80 */, 0 /* 0x81 */, 0 /* 0x82 */, 0 /* 0x83 */, - 0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */, 0 /* 0x87 */, - 0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */, - 0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */, - 0 /* 0x90 */, 0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */, - 0 /* 0x94 */, 0 /* 0x95 */, 0 /* 0x96 */, 0 /* 0x97 */, - 0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */, 0 /* 0x9b */, - 0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */, - 0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */, - 0 /* 0xa4 */, 0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */, - 0 /* 0xa8 */, 0 /* 0xa9 */, 0 /* 0xaa */, 0 /* 0xab */, - 0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */, 0 /* 0xaf */, - 0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */, - 0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */, - 0 /* 0xb8 */, 0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */, - 0 /* 0xbc */, 0 /* 0xbd */, 0 /* 0xbe */, 0 /* 0xbf */, - 0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */, 0 /* 0xc3 */, - 0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */, - 0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */, - 0 /* 0xcc */, 0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */, - 0 /* 0xd0 */, 0 /* 0xd1 */, 0 /* 0xd2 */, 0 /* 0xd3 */, - 0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */, 0 /* 0xd7 */, - 0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */, - 0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */, - 0 /* 0xe0 */, 0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */, - 0 /* 0xe4 */, 0 /* 0xe5 */, 0 /* 0xe6 */, 0 /* 0xe7 */, - 0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */, 0 /* 0xeb */, - 0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */, - 0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */, - 0 /* 0xf4 */, 0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */, - 0 /* 0xf8 */, 0 /* 0xf9 */, 0 /* 0xfa */, 0 /* 0xfb */, - 0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */, 0 /* 0xff */ -}; - -static int check_authority(const uint8_t *value, size_t len) { - const uint8_t *last; - for (last = value + len; value != last; ++value) { - if (!VALID_AUTHORITY_CHARS[*value]) { - return 0; - } - } - return 1; -} - -static int check_scheme(const uint8_t *value, size_t len) { - const uint8_t *last; - if (len == 0) { - return 0; - } - - if (!(('A' <= *value && *value <= 'Z') || ('a' <= *value && *value <= 'z'))) { - return 0; - } - - last = value + len; - ++value; - - for (; value != last; ++value) { - if (!(('A' <= *value && *value <= 'Z') || - ('a' <= *value && *value <= 'z') || - ('0' <= *value && *value <= '9') || *value == '+' || *value == '-' || - *value == '.')) { - return 0; - } - } - return 1; -} - -int nghttp3_http_on_header(nghttp3_http_state *http, int64_t frame_type, - nghttp3_qpack_nv *nv, int request, int trailers) { - int rv; - size_t i; - uint8_t c; - - if (!nghttp3_check_header_name(nv->name->base, nv->name->len)) { - if (nv->name->len > 0 && nv->name->base[0] == ':') { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - /* header field name must be lower-cased without exception */ - for (i = 0; i < nv->name->len; ++i) { - c = nv->name->base[i]; - if ('A' <= c && c <= 'Z') { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - } - /* When ignoring regular header fields, we set this flag so that - we still enforce header field ordering rule for pseudo header - fields. */ - http->flags |= NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED; - return NGHTTP3_ERR_REMOVE_HTTP_HEADER; - } - - if (nv->token == NGHTTP3_QPACK_TOKEN__AUTHORITY || - nv->token == NGHTTP3_QPACK_TOKEN_HOST) { - rv = check_authority(nv->value->base, nv->value->len); - } else if (nv->token == NGHTTP3_QPACK_TOKEN__SCHEME) { - rv = check_scheme(nv->value->base, nv->value->len); - } else { - rv = nghttp3_check_header_value(nv->value->base, nv->value->len); - } - - if (rv == 0) { - assert(nv->name->len > 0); - if (nv->name->base[0] == ':') { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - /* When ignoring regular header fields, we set this flag so that - we still enforce header field ordering rule for pseudo header - fields. */ - http->flags |= NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED; - return NGHTTP3_ERR_REMOVE_HTTP_HEADER; - } - - if (request) { - return http_request_on_header(http, frame_type, nv, trailers, - /* connect_protocol = */ 0); - } - - return http_response_on_header(http, nv, trailers); -} - -int nghttp3_http_on_request_headers(nghttp3_http_state *http) { - if (!(http->flags & NGHTTP3_HTTP_FLAG__PROTOCOL) && - (http->flags & NGHTTP3_HTTP_FLAG_METH_CONNECT)) { - if ((http->flags & (NGHTTP3_HTTP_FLAG__SCHEME | NGHTTP3_HTTP_FLAG__PATH)) || - (http->flags & NGHTTP3_HTTP_FLAG__AUTHORITY) == 0) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - http->content_length = -1; - } else { - if ((http->flags & NGHTTP3_HTTP_FLAG_REQ_HEADERS) != - NGHTTP3_HTTP_FLAG_REQ_HEADERS || - (http->flags & - (NGHTTP3_HTTP_FLAG__AUTHORITY | NGHTTP3_HTTP_FLAG_HOST)) == 0) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - if ((http->flags & NGHTTP3_HTTP_FLAG__PROTOCOL) && - ((http->flags & NGHTTP3_HTTP_FLAG_METH_CONNECT) == 0 || - (http->flags & NGHTTP3_HTTP_FLAG__AUTHORITY) == 0)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - if (!check_path(http)) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - } - - return 0; -} - -int nghttp3_http_on_response_headers(nghttp3_http_state *http) { - if ((http->flags & NGHTTP3_HTTP_FLAG__STATUS) == 0) { - return NGHTTP3_ERR_MALFORMED_HTTP_HEADER; - } - - if (http->status_code / 100 == 1) { - /* non-final response */ - http->flags = (uint16_t)((http->flags & NGHTTP3_HTTP_FLAG_METH_ALL) | - NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE); - http->content_length = -1; - http->status_code = -1; - return 0; - } - - http->flags = - (uint16_t)(http->flags & ~NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE); - - if (!expect_response_body(http)) { - http->content_length = 0; - } else if (http->flags & NGHTTP3_HTTP_FLAG_METH_CONNECT) { - http->content_length = -1; - } - - return 0; -} - -int nghttp3_http_on_remote_end_stream(nghttp3_stream *stream) { - if (stream->flags & NGHTTP3_STREAM_FLAG_RESET) { - return 0; - } - if ((stream->rx.http.flags & NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE) || - (stream->rx.http.content_length != -1 && - stream->rx.http.content_length != stream->rx.http.recv_content_length)) { - return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING; - } - - return 0; -} - -int nghttp3_http_on_data_chunk(nghttp3_stream *stream, size_t n) { - stream->rx.http.recv_content_length += (int64_t)n; - - if ((stream->rx.http.flags & NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE) || - (stream->rx.http.content_length != -1 && - stream->rx.http.recv_content_length > stream->rx.http.content_length)) { - return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING; - } - - return 0; -} - -void nghttp3_http_record_request_method(nghttp3_stream *stream, - const nghttp3_nv *nva, size_t nvlen) { - size_t i; - const nghttp3_nv *nv; - - /* TODO we should do this strictly. */ - for (i = 0; i < nvlen; ++i) { - nv = &nva[i]; - if (!(nv->namelen == 7 && nv->name[6] == 'd' && - memcmp(":metho", nv->name, nv->namelen - 1) == 0)) { - continue; - } - if (lstreq("CONNECT", nv->value, nv->valuelen)) { - stream->rx.http.flags |= NGHTTP3_HTTP_FLAG_METH_CONNECT; - return; - } - if (lstreq("HEAD", nv->value, nv->valuelen)) { - stream->rx.http.flags |= NGHTTP3_HTTP_FLAG_METH_HEAD; - return; - } - return; - } -} - -/* Generated by gennmchartbl.py */ -static const int VALID_HD_NAME_CHARS[] = { - 0 /* NUL */, 0 /* SOH */, 0 /* STX */, 0 /* ETX */, - 0 /* EOT */, 0 /* ENQ */, 0 /* ACK */, 0 /* BEL */, - 0 /* BS */, 0 /* HT */, 0 /* LF */, 0 /* VT */, - 0 /* FF */, 0 /* CR */, 0 /* SO */, 0 /* SI */, - 0 /* DLE */, 0 /* DC1 */, 0 /* DC2 */, 0 /* DC3 */, - 0 /* DC4 */, 0 /* NAK */, 0 /* SYN */, 0 /* ETB */, - 0 /* CAN */, 0 /* EM */, 0 /* SUB */, 0 /* ESC */, - 0 /* FS */, 0 /* GS */, 0 /* RS */, 0 /* US */, - 0 /* SPC */, 1 /* ! */, 0 /* " */, 1 /* # */, - 1 /* $ */, 1 /* % */, 1 /* & */, 1 /* ' */, - 0 /* ( */, 0 /* ) */, 1 /* * */, 1 /* + */, - 0 /* , */, 1 /* - */, 1 /* . */, 0 /* / */, - 1 /* 0 */, 1 /* 1 */, 1 /* 2 */, 1 /* 3 */, - 1 /* 4 */, 1 /* 5 */, 1 /* 6 */, 1 /* 7 */, - 1 /* 8 */, 1 /* 9 */, 0 /* : */, 0 /* ; */, - 0 /* < */, 0 /* = */, 0 /* > */, 0 /* ? */, - 0 /* @ */, 0 /* A */, 0 /* B */, 0 /* C */, - 0 /* D */, 0 /* E */, 0 /* F */, 0 /* G */, - 0 /* H */, 0 /* I */, 0 /* J */, 0 /* K */, - 0 /* L */, 0 /* M */, 0 /* N */, 0 /* O */, - 0 /* P */, 0 /* Q */, 0 /* R */, 0 /* S */, - 0 /* T */, 0 /* U */, 0 /* V */, 0 /* W */, - 0 /* X */, 0 /* Y */, 0 /* Z */, 0 /* [ */, - 0 /* \ */, 0 /* ] */, 1 /* ^ */, 1 /* _ */, - 1 /* ` */, 1 /* a */, 1 /* b */, 1 /* c */, - 1 /* d */, 1 /* e */, 1 /* f */, 1 /* g */, - 1 /* h */, 1 /* i */, 1 /* j */, 1 /* k */, - 1 /* l */, 1 /* m */, 1 /* n */, 1 /* o */, - 1 /* p */, 1 /* q */, 1 /* r */, 1 /* s */, - 1 /* t */, 1 /* u */, 1 /* v */, 1 /* w */, - 1 /* x */, 1 /* y */, 1 /* z */, 0 /* { */, - 1 /* | */, 0 /* } */, 1 /* ~ */, 0 /* DEL */, - 0 /* 0x80 */, 0 /* 0x81 */, 0 /* 0x82 */, 0 /* 0x83 */, - 0 /* 0x84 */, 0 /* 0x85 */, 0 /* 0x86 */, 0 /* 0x87 */, - 0 /* 0x88 */, 0 /* 0x89 */, 0 /* 0x8a */, 0 /* 0x8b */, - 0 /* 0x8c */, 0 /* 0x8d */, 0 /* 0x8e */, 0 /* 0x8f */, - 0 /* 0x90 */, 0 /* 0x91 */, 0 /* 0x92 */, 0 /* 0x93 */, - 0 /* 0x94 */, 0 /* 0x95 */, 0 /* 0x96 */, 0 /* 0x97 */, - 0 /* 0x98 */, 0 /* 0x99 */, 0 /* 0x9a */, 0 /* 0x9b */, - 0 /* 0x9c */, 0 /* 0x9d */, 0 /* 0x9e */, 0 /* 0x9f */, - 0 /* 0xa0 */, 0 /* 0xa1 */, 0 /* 0xa2 */, 0 /* 0xa3 */, - 0 /* 0xa4 */, 0 /* 0xa5 */, 0 /* 0xa6 */, 0 /* 0xa7 */, - 0 /* 0xa8 */, 0 /* 0xa9 */, 0 /* 0xaa */, 0 /* 0xab */, - 0 /* 0xac */, 0 /* 0xad */, 0 /* 0xae */, 0 /* 0xaf */, - 0 /* 0xb0 */, 0 /* 0xb1 */, 0 /* 0xb2 */, 0 /* 0xb3 */, - 0 /* 0xb4 */, 0 /* 0xb5 */, 0 /* 0xb6 */, 0 /* 0xb7 */, - 0 /* 0xb8 */, 0 /* 0xb9 */, 0 /* 0xba */, 0 /* 0xbb */, - 0 /* 0xbc */, 0 /* 0xbd */, 0 /* 0xbe */, 0 /* 0xbf */, - 0 /* 0xc0 */, 0 /* 0xc1 */, 0 /* 0xc2 */, 0 /* 0xc3 */, - 0 /* 0xc4 */, 0 /* 0xc5 */, 0 /* 0xc6 */, 0 /* 0xc7 */, - 0 /* 0xc8 */, 0 /* 0xc9 */, 0 /* 0xca */, 0 /* 0xcb */, - 0 /* 0xcc */, 0 /* 0xcd */, 0 /* 0xce */, 0 /* 0xcf */, - 0 /* 0xd0 */, 0 /* 0xd1 */, 0 /* 0xd2 */, 0 /* 0xd3 */, - 0 /* 0xd4 */, 0 /* 0xd5 */, 0 /* 0xd6 */, 0 /* 0xd7 */, - 0 /* 0xd8 */, 0 /* 0xd9 */, 0 /* 0xda */, 0 /* 0xdb */, - 0 /* 0xdc */, 0 /* 0xdd */, 0 /* 0xde */, 0 /* 0xdf */, - 0 /* 0xe0 */, 0 /* 0xe1 */, 0 /* 0xe2 */, 0 /* 0xe3 */, - 0 /* 0xe4 */, 0 /* 0xe5 */, 0 /* 0xe6 */, 0 /* 0xe7 */, - 0 /* 0xe8 */, 0 /* 0xe9 */, 0 /* 0xea */, 0 /* 0xeb */, - 0 /* 0xec */, 0 /* 0xed */, 0 /* 0xee */, 0 /* 0xef */, - 0 /* 0xf0 */, 0 /* 0xf1 */, 0 /* 0xf2 */, 0 /* 0xf3 */, - 0 /* 0xf4 */, 0 /* 0xf5 */, 0 /* 0xf6 */, 0 /* 0xf7 */, - 0 /* 0xf8 */, 0 /* 0xf9 */, 0 /* 0xfa */, 0 /* 0xfb */, - 0 /* 0xfc */, 0 /* 0xfd */, 0 /* 0xfe */, 0 /* 0xff */ -}; - -int nghttp3_check_header_name(const uint8_t *name, size_t len) { - const uint8_t *last; - if (len == 0) { - return 0; - } - if (*name == ':') { - if (len == 1) { - return 0; - } - ++name; - --len; - } - for (last = name + len; name != last; ++name) { - if (!VALID_HD_NAME_CHARS[*name]) { - return 0; - } - } - return 1; -} - -/* Generated by genvchartbl.py */ -static const int VALID_HD_VALUE_CHARS[] = { - 0 /* NUL */, 0 /* SOH */, 0 /* STX */, 0 /* ETX */, - 0 /* EOT */, 0 /* ENQ */, 0 /* ACK */, 0 /* BEL */, - 0 /* BS */, 1 /* HT */, 0 /* LF */, 0 /* VT */, - 0 /* FF */, 0 /* CR */, 0 /* SO */, 0 /* SI */, - 0 /* DLE */, 0 /* DC1 */, 0 /* DC2 */, 0 /* DC3 */, - 0 /* DC4 */, 0 /* NAK */, 0 /* SYN */, 0 /* ETB */, - 0 /* CAN */, 0 /* EM */, 0 /* SUB */, 0 /* ESC */, - 0 /* FS */, 0 /* GS */, 0 /* RS */, 0 /* US */, - 1 /* SPC */, 1 /* ! */, 1 /* " */, 1 /* # */, - 1 /* $ */, 1 /* % */, 1 /* & */, 1 /* ' */, - 1 /* ( */, 1 /* ) */, 1 /* * */, 1 /* + */, - 1 /* , */, 1 /* - */, 1 /* . */, 1 /* / */, - 1 /* 0 */, 1 /* 1 */, 1 /* 2 */, 1 /* 3 */, - 1 /* 4 */, 1 /* 5 */, 1 /* 6 */, 1 /* 7 */, - 1 /* 8 */, 1 /* 9 */, 1 /* : */, 1 /* ; */, - 1 /* < */, 1 /* = */, 1 /* > */, 1 /* ? */, - 1 /* @ */, 1 /* A */, 1 /* B */, 1 /* C */, - 1 /* D */, 1 /* E */, 1 /* F */, 1 /* G */, - 1 /* H */, 1 /* I */, 1 /* J */, 1 /* K */, - 1 /* L */, 1 /* M */, 1 /* N */, 1 /* O */, - 1 /* P */, 1 /* Q */, 1 /* R */, 1 /* S */, - 1 /* T */, 1 /* U */, 1 /* V */, 1 /* W */, - 1 /* X */, 1 /* Y */, 1 /* Z */, 1 /* [ */, - 1 /* \ */, 1 /* ] */, 1 /* ^ */, 1 /* _ */, - 1 /* ` */, 1 /* a */, 1 /* b */, 1 /* c */, - 1 /* d */, 1 /* e */, 1 /* f */, 1 /* g */, - 1 /* h */, 1 /* i */, 1 /* j */, 1 /* k */, - 1 /* l */, 1 /* m */, 1 /* n */, 1 /* o */, - 1 /* p */, 1 /* q */, 1 /* r */, 1 /* s */, - 1 /* t */, 1 /* u */, 1 /* v */, 1 /* w */, - 1 /* x */, 1 /* y */, 1 /* z */, 1 /* { */, - 1 /* | */, 1 /* } */, 1 /* ~ */, 0 /* DEL */, - 1 /* 0x80 */, 1 /* 0x81 */, 1 /* 0x82 */, 1 /* 0x83 */, - 1 /* 0x84 */, 1 /* 0x85 */, 1 /* 0x86 */, 1 /* 0x87 */, - 1 /* 0x88 */, 1 /* 0x89 */, 1 /* 0x8a */, 1 /* 0x8b */, - 1 /* 0x8c */, 1 /* 0x8d */, 1 /* 0x8e */, 1 /* 0x8f */, - 1 /* 0x90 */, 1 /* 0x91 */, 1 /* 0x92 */, 1 /* 0x93 */, - 1 /* 0x94 */, 1 /* 0x95 */, 1 /* 0x96 */, 1 /* 0x97 */, - 1 /* 0x98 */, 1 /* 0x99 */, 1 /* 0x9a */, 1 /* 0x9b */, - 1 /* 0x9c */, 1 /* 0x9d */, 1 /* 0x9e */, 1 /* 0x9f */, - 1 /* 0xa0 */, 1 /* 0xa1 */, 1 /* 0xa2 */, 1 /* 0xa3 */, - 1 /* 0xa4 */, 1 /* 0xa5 */, 1 /* 0xa6 */, 1 /* 0xa7 */, - 1 /* 0xa8 */, 1 /* 0xa9 */, 1 /* 0xaa */, 1 /* 0xab */, - 1 /* 0xac */, 1 /* 0xad */, 1 /* 0xae */, 1 /* 0xaf */, - 1 /* 0xb0 */, 1 /* 0xb1 */, 1 /* 0xb2 */, 1 /* 0xb3 */, - 1 /* 0xb4 */, 1 /* 0xb5 */, 1 /* 0xb6 */, 1 /* 0xb7 */, - 1 /* 0xb8 */, 1 /* 0xb9 */, 1 /* 0xba */, 1 /* 0xbb */, - 1 /* 0xbc */, 1 /* 0xbd */, 1 /* 0xbe */, 1 /* 0xbf */, - 1 /* 0xc0 */, 1 /* 0xc1 */, 1 /* 0xc2 */, 1 /* 0xc3 */, - 1 /* 0xc4 */, 1 /* 0xc5 */, 1 /* 0xc6 */, 1 /* 0xc7 */, - 1 /* 0xc8 */, 1 /* 0xc9 */, 1 /* 0xca */, 1 /* 0xcb */, - 1 /* 0xcc */, 1 /* 0xcd */, 1 /* 0xce */, 1 /* 0xcf */, - 1 /* 0xd0 */, 1 /* 0xd1 */, 1 /* 0xd2 */, 1 /* 0xd3 */, - 1 /* 0xd4 */, 1 /* 0xd5 */, 1 /* 0xd6 */, 1 /* 0xd7 */, - 1 /* 0xd8 */, 1 /* 0xd9 */, 1 /* 0xda */, 1 /* 0xdb */, - 1 /* 0xdc */, 1 /* 0xdd */, 1 /* 0xde */, 1 /* 0xdf */, - 1 /* 0xe0 */, 1 /* 0xe1 */, 1 /* 0xe2 */, 1 /* 0xe3 */, - 1 /* 0xe4 */, 1 /* 0xe5 */, 1 /* 0xe6 */, 1 /* 0xe7 */, - 1 /* 0xe8 */, 1 /* 0xe9 */, 1 /* 0xea */, 1 /* 0xeb */, - 1 /* 0xec */, 1 /* 0xed */, 1 /* 0xee */, 1 /* 0xef */, - 1 /* 0xf0 */, 1 /* 0xf1 */, 1 /* 0xf2 */, 1 /* 0xf3 */, - 1 /* 0xf4 */, 1 /* 0xf5 */, 1 /* 0xf6 */, 1 /* 0xf7 */, - 1 /* 0xf8 */, 1 /* 0xf9 */, 1 /* 0xfa */, 1 /* 0xfb */, - 1 /* 0xfc */, 1 /* 0xfd */, 1 /* 0xfe */, 1 /* 0xff */ -}; - -int nghttp3_check_header_value(const uint8_t *value, size_t len) { - const uint8_t *last; - for (last = value + len; value != last; ++value) { - if (!VALID_HD_VALUE_CHARS[*value]) { - return 0; - } - } - return 1; -} diff --git a/deps/nghttp3/lib/nghttp3_http.h b/deps/nghttp3/lib/nghttp3_http.h deleted file mode 100644 index 00b74f2a260c0e..00000000000000 --- a/deps/nghttp3/lib/nghttp3_http.h +++ /dev/null @@ -1,146 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2015 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_HTTP_H -#define NGHTTP3_HTTP_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -struct nghttp3_stream; -typedef struct nghttp3_stream nghttp3_stream; - -struct nghttp3_http_state; -typedef struct nghttp3_http_state nghttp3_http_state; - -/* HTTP related flags to enforce HTTP semantics */ -typedef enum { - NGHTTP3_HTTP_FLAG_NONE = 0, - /* header field seen so far */ - NGHTTP3_HTTP_FLAG__AUTHORITY = 1, - NGHTTP3_HTTP_FLAG__PATH = 1 << 1, - NGHTTP3_HTTP_FLAG__METHOD = 1 << 2, - NGHTTP3_HTTP_FLAG__SCHEME = 1 << 3, - /* host is not pseudo header, but we require either host or - :authority */ - NGHTTP3_HTTP_FLAG_HOST = 1 << 4, - NGHTTP3_HTTP_FLAG__STATUS = 1 << 5, - /* required header fields for HTTP request except for CONNECT - method. */ - NGHTTP3_HTTP_FLAG_REQ_HEADERS = NGHTTP3_HTTP_FLAG__METHOD | - NGHTTP3_HTTP_FLAG__PATH | - NGHTTP3_HTTP_FLAG__SCHEME, - NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED = 1 << 6, - /* HTTP method flags */ - NGHTTP3_HTTP_FLAG_METH_CONNECT = 1 << 7, - NGHTTP3_HTTP_FLAG_METH_HEAD = 1 << 8, - NGHTTP3_HTTP_FLAG_METH_OPTIONS = 1 << 9, - NGHTTP3_HTTP_FLAG_METH_ALL = NGHTTP3_HTTP_FLAG_METH_CONNECT | - NGHTTP3_HTTP_FLAG_METH_HEAD | - NGHTTP3_HTTP_FLAG_METH_OPTIONS, - /* :path category */ - /* path starts with "/" */ - NGHTTP3_HTTP_FLAG_PATH_REGULAR = 1 << 11, - /* path "*" */ - NGHTTP3_HTTP_FLAG_PATH_ASTERISK = 1 << 12, - /* scheme */ - /* "http" or "https" scheme */ - NGHTTP3_HTTP_FLAG_SCHEME_HTTP = 1 << 13, - /* set if final response is expected */ - NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE = 1 << 14, - NGHTTP3_HTTP_FLAG__PROTOCOL = 1 << 15, -} nghttp3_http_flag; - -/* - * This function is called when HTTP header field |nv| in a frame of type - * |frame_type| is received for |http|. This function will validate |nv| - * against the current state of stream. Pass nonzero if this is request - * headers. Pass nonzero to |trailers| if |nv| is included in trailers. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_MALFORMED_HTTP_HEADER - * Invalid HTTP header field was received. - * NGHTTP3_ERR_REMOVE_HTTP_HEADER - * Invalid HTTP header field was received but it can be treated as - * if it was not received because of compatibility reasons. - */ -int nghttp3_http_on_header(nghttp3_http_state *http, int64_t frame_type, - nghttp3_qpack_nv *nv, int request, int trailers); - -/* - * This function is called when request header is received. This - * function performs validation and returns 0 if it succeeds, or one - * of the following negative error codes: - * - * NGHTTP3_ERR_MALFORMED_HTTP_HEADER - * Required HTTP header field was not received; or an invalid - * header field was received. - */ -int nghttp3_http_on_request_headers(nghttp3_http_state *http); - -/* - * This function is called when response header is received. This - * function performs validation and returns 0 if it succeeds, or one - * of the following negative error codes: - * - * NGHTTP3_ERR_MALFORMED_HTTP_HEADER - * Required HTTP header field was not received; or an invalid - * header field was received. - */ -int nghttp3_http_on_response_headers(nghttp3_http_state *http); - -/* - * This function is called when read side stream is closed. This - * function performs validation and returns 0 if it succeeds, or one - * of the following negative error codes: - * - * NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING - * HTTP messaging is violated. - */ -int nghttp3_http_on_remote_end_stream(nghttp3_stream *stream); - -/* - * This function is called when chunk of data is received. This - * function performs validation and returns 0 if it succeeds, or one - * of the following negative error codes: - * - * NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING - * HTTP messaging is violated. - */ -int nghttp3_http_on_data_chunk(nghttp3_stream *stream, size_t n); - -/* - * This function inspects header fields in |nva| of length |nvlen| and - * records its method in stream->http_flags. - */ -void nghttp3_http_record_request_method(nghttp3_stream *stream, - const nghttp3_nv *nva, size_t nvlen); - -#endif /* NGHTTP3_HTTP_H */ diff --git a/deps/nghttp3/lib/nghttp3_idtr.c b/deps/nghttp3/lib/nghttp3_idtr.c deleted file mode 100644 index cd8fd82e6b2bb5..00000000000000 --- a/deps/nghttp3/lib/nghttp3_idtr.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_idtr.h" - -#include - -int nghttp3_idtr_init(nghttp3_idtr *idtr, int server, const nghttp3_mem *mem) { - int rv; - - rv = nghttp3_gaptr_init(&idtr->gap, mem); - if (rv != 0) { - return rv; - } - - idtr->server = server; - idtr->mem = mem; - - return 0; -} - -void nghttp3_idtr_free(nghttp3_idtr *idtr) { - if (idtr == NULL) { - return; - } - - nghttp3_gaptr_free(&idtr->gap); -} - -/* - * id_from_stream_id translates |stream_id| to id space used by - * nghttp3_idtr. - */ -static uint64_t id_from_stream_id(int64_t stream_id) { - return (uint64_t)(stream_id >> 2); -} - -int nghttp3_idtr_open(nghttp3_idtr *idtr, int64_t stream_id) { - uint64_t q; - - assert((idtr->server && (stream_id % 2)) || - (!idtr->server && (stream_id % 2)) == 0); - - q = id_from_stream_id(stream_id); - - if (nghttp3_gaptr_is_pushed(&idtr->gap, q, 1)) { - return NGHTTP3_ERR_STREAM_IN_USE; - } - - return nghttp3_gaptr_push(&idtr->gap, q, 1); -} - -int nghttp3_idtr_is_open(nghttp3_idtr *idtr, int64_t stream_id) { - uint64_t q; - - assert((idtr->server && (stream_id % 2)) || - (!idtr->server && (stream_id % 2)) == 0); - - q = id_from_stream_id(stream_id); - - return nghttp3_gaptr_is_pushed(&idtr->gap, q, 1); -} - -uint64_t nghttp3_idtr_first_gap(nghttp3_idtr *idtr) { - return nghttp3_gaptr_first_gap_offset(&idtr->gap); -} diff --git a/deps/nghttp3/lib/nghttp3_idtr.h b/deps/nghttp3/lib/nghttp3_idtr.h deleted file mode 100644 index ba2808a11f5c68..00000000000000 --- a/deps/nghttp3/lib/nghttp3_idtr.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_IDTR_H -#define NGHTTP3_IDTR_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "nghttp3_mem.h" -#include "nghttp3_gaptr.h" - -/* - * nghttp3_idtr tracks the usage of stream ID. - */ -typedef struct { - /* gap maintains the range of ID which is not used yet. Initially, - its range is [0, UINT64_MAX). */ - nghttp3_gaptr gap; - /* server is nonzero if this object records server initiated stream - ID. */ - int server; - /* mem is custom memory allocator */ - const nghttp3_mem *mem; -} nghttp3_idtr; - -/* - * nghttp3_idtr_init initializes |idtr|. |chunk| is the size of buffer - * per chunk. - * - * If this object records server initiated ID (even number), set - * |server| to nonzero. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_idtr_init(nghttp3_idtr *idtr, int server, const nghttp3_mem *mem); - -/* - * nghttp3_idtr_free frees resources allocated for |idtr|. - */ -void nghttp3_idtr_free(nghttp3_idtr *idtr); - -/* - * nghttp3_idtr_open claims that |stream_id| is in used. - * - * It returns 0 if it succeeds, or one of the following negative error - * codes: - * - * NGHTTP3_ERR_STREAM_IN_USE - * ID has already been used. - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_idtr_open(nghttp3_idtr *idtr, int64_t stream_id); - -/* - * nghttp3_idtr_open tells whether ID |stream_id| is in used or not. - * - * It returns nonzero if |stream_id| is used. - */ -int nghttp3_idtr_is_open(nghttp3_idtr *idtr, int64_t stream_id); - -/* - * nghttp3_idtr_first_gap returns the first id of first gap. If there - * is no gap, it returns UINT64_MAX. The returned id is an id space - * used in this object internally, and not stream ID. - */ -uint64_t nghttp3_idtr_first_gap(nghttp3_idtr *idtr); - -#endif /* NGHTTP3_IDTR_H */ diff --git a/deps/nghttp3/lib/nghttp3_ksl.c b/deps/nghttp3/lib/nghttp3_ksl.c deleted file mode 100644 index 6a0f7c1de571cc..00000000000000 --- a/deps/nghttp3/lib/nghttp3_ksl.c +++ /dev/null @@ -1,722 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_ksl.h" - -#include -#include -#include -#include - -#include "nghttp3_macro.h" -#include "nghttp3_mem.h" -#include "nghttp3_range.h" - -static size_t ksl_nodelen(size_t keylen) { - return (sizeof(nghttp3_ksl_node) + keylen - sizeof(uint64_t) + 0xf) & - (size_t)~0xf; -} - -static size_t ksl_blklen(size_t nodelen) { - return sizeof(nghttp3_ksl_blk) + nodelen * NGHTTP3_KSL_MAX_NBLK - - sizeof(uint64_t); -} - -/* - * ksl_node_set_key sets |key| to |node|. - */ -static void ksl_node_set_key(nghttp3_ksl *ksl, nghttp3_ksl_node *node, - const void *key) { - memcpy(node->key, key, ksl->keylen); -} - -int nghttp3_ksl_init(nghttp3_ksl *ksl, nghttp3_ksl_compar compar, size_t keylen, - const nghttp3_mem *mem) { - size_t nodelen = ksl_nodelen(keylen); - size_t blklen = ksl_blklen(nodelen); - nghttp3_ksl_blk *head; - - ksl->head = nghttp3_mem_malloc(mem, blklen); - if (!ksl->head) { - return NGHTTP3_ERR_NOMEM; - } - ksl->front = ksl->back = ksl->head; - ksl->compar = compar; - ksl->keylen = keylen; - ksl->nodelen = nodelen; - ksl->n = 0; - ksl->mem = mem; - - head = ksl->head; - head->next = head->prev = NULL; - head->n = 0; - head->leaf = 1; - - return 0; -} - -/* - * ksl_free_blk frees |blk| recursively. - */ -static void ksl_free_blk(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk) { - size_t i; - - if (!blk->leaf) { - for (i = 0; i < blk->n; ++i) { - ksl_free_blk(ksl, nghttp3_ksl_nth_node(ksl, blk, i)->blk); - } - } - - nghttp3_mem_free(ksl->mem, blk); -} - -void nghttp3_ksl_free(nghttp3_ksl *ksl) { - if (!ksl) { - return; - } - - ksl_free_blk(ksl, ksl->head); -} - -/* - * ksl_split_blk splits |blk| into 2 nghttp3_ksl_blk objects. The new - * nghttp3_ksl_blk is always the "right" block. - * - * It returns the pointer to the nghttp3_ksl_blk created which is the - * located at the right of |blk|, or NULL which indicates out of - * memory error. - */ -static nghttp3_ksl_blk *ksl_split_blk(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk) { - nghttp3_ksl_blk *rblk; - - rblk = nghttp3_mem_malloc(ksl->mem, ksl_blklen(ksl->nodelen)); - if (rblk == NULL) { - return NULL; - } - - rblk->next = blk->next; - blk->next = rblk; - if (rblk->next) { - rblk->next->prev = rblk; - } else if (ksl->back == blk) { - ksl->back = rblk; - } - rblk->prev = blk; - rblk->leaf = blk->leaf; - - rblk->n = blk->n / 2; - - memcpy(rblk->nodes, blk->nodes + ksl->nodelen * (blk->n - rblk->n), - ksl->nodelen * rblk->n); - - blk->n -= rblk->n; - - assert(blk->n >= NGHTTP3_KSL_MIN_NBLK); - assert(rblk->n >= NGHTTP3_KSL_MIN_NBLK); - - return rblk; -} - -/* - * ksl_split_node splits a node included in |blk| at the position |i| - * into 2 adjacent nodes. The new node is always inserted at the - * position |i+1|. - * - * It returns 0 if it succeeds, or one of the following negative error - * codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -static int ksl_split_node(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t i) { - nghttp3_ksl_node *node; - nghttp3_ksl_blk *lblk = nghttp3_ksl_nth_node(ksl, blk, i)->blk, *rblk; - - rblk = ksl_split_blk(ksl, lblk); - if (rblk == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - memmove(blk->nodes + (i + 2) * ksl->nodelen, - blk->nodes + (i + 1) * ksl->nodelen, - ksl->nodelen * (blk->n - (i + 1))); - - node = nghttp3_ksl_nth_node(ksl, blk, i + 1); - node->blk = rblk; - ++blk->n; - ksl_node_set_key(ksl, node, - nghttp3_ksl_nth_node(ksl, rblk, rblk->n - 1)->key); - - node = nghttp3_ksl_nth_node(ksl, blk, i); - ksl_node_set_key(ksl, node, - nghttp3_ksl_nth_node(ksl, lblk, lblk->n - 1)->key); - - return 0; -} - -/* - * ksl_split_head splits a head (root) block. It increases the height - * of skip list by 1. - * - * It returns 0 if it succeeds, or one of the following negative error - * codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -static int ksl_split_head(nghttp3_ksl *ksl) { - nghttp3_ksl_blk *rblk = NULL, *lblk, *nhead = NULL; - nghttp3_ksl_node *node; - - rblk = ksl_split_blk(ksl, ksl->head); - if (rblk == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - lblk = ksl->head; - - nhead = nghttp3_mem_malloc(ksl->mem, ksl_blklen(ksl->nodelen)); - if (nhead == NULL) { - nghttp3_mem_free(ksl->mem, rblk); - return NGHTTP3_ERR_NOMEM; - } - nhead->next = nhead->prev = NULL; - nhead->n = 2; - nhead->leaf = 0; - - node = nghttp3_ksl_nth_node(ksl, nhead, 0); - ksl_node_set_key(ksl, node, - nghttp3_ksl_nth_node(ksl, lblk, lblk->n - 1)->key); - node->blk = lblk; - - node = nghttp3_ksl_nth_node(ksl, nhead, 1); - ksl_node_set_key(ksl, node, - nghttp3_ksl_nth_node(ksl, rblk, rblk->n - 1)->key); - node->blk = rblk; - - ksl->head = nhead; - - return 0; -} - -/* - * insert_node inserts a node whose key is |key| with the associated - * |data| at the index of |i|. This function assumes that the number - * of nodes contained by |blk| is strictly less than - * NGHTTP3_KSL_MAX_NBLK. - */ -static void ksl_insert_node(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t i, - const nghttp3_ksl_key *key, void *data) { - nghttp3_ksl_node *node; - - assert(blk->n < NGHTTP3_KSL_MAX_NBLK); - - memmove(blk->nodes + (i + 1) * ksl->nodelen, blk->nodes + i * ksl->nodelen, - ksl->nodelen * (blk->n - i)); - - node = nghttp3_ksl_nth_node(ksl, blk, i); - ksl_node_set_key(ksl, node, key); - node->data = data; - - ++blk->n; -} - -static size_t ksl_bsearch(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, - const nghttp3_ksl_key *key, - nghttp3_ksl_compar compar) { - nghttp3_ssize left = -1, right = (nghttp3_ssize)blk->n, mid; - nghttp3_ksl_node *node; - - while (right - left > 1) { - mid = (left + right) / 2; - node = nghttp3_ksl_nth_node(ksl, blk, (size_t)mid); - if (compar((nghttp3_ksl_key *)node->key, key)) { - left = mid; - } else { - right = mid; - } - } - - return (size_t)right; -} - -int nghttp3_ksl_insert(nghttp3_ksl *ksl, nghttp3_ksl_it *it, - const nghttp3_ksl_key *key, void *data) { - nghttp3_ksl_blk *blk = ksl->head; - nghttp3_ksl_node *node; - size_t i; - int rv; - - if (blk->n == NGHTTP3_KSL_MAX_NBLK) { - rv = ksl_split_head(ksl); - if (rv != 0) { - return rv; - } - blk = ksl->head; - } - - for (;;) { - i = ksl_bsearch(ksl, blk, key, ksl->compar); - - if (blk->leaf) { - if (i < blk->n && - !ksl->compar(key, nghttp3_ksl_nth_node(ksl, blk, i)->key)) { - if (it) { - *it = nghttp3_ksl_end(ksl); - } - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - ksl_insert_node(ksl, blk, i, key, data); - ++ksl->n; - if (it) { - nghttp3_ksl_it_init(it, ksl, blk, i); - } - return 0; - } - - if (i == blk->n) { - /* This insertion extends the largest key in this subtree. */ - for (; !blk->leaf;) { - node = nghttp3_ksl_nth_node(ksl, blk, blk->n - 1); - if (node->blk->n == NGHTTP3_KSL_MAX_NBLK) { - rv = ksl_split_node(ksl, blk, blk->n - 1); - if (rv != 0) { - return rv; - } - node = nghttp3_ksl_nth_node(ksl, blk, blk->n - 1); - } - ksl_node_set_key(ksl, node, key); - blk = node->blk; - } - ksl_insert_node(ksl, blk, blk->n, key, data); - ++ksl->n; - if (it) { - nghttp3_ksl_it_init(it, ksl, blk, blk->n - 1); - } - return 0; - } - - node = nghttp3_ksl_nth_node(ksl, blk, i); - - if (node->blk->n == NGHTTP3_KSL_MAX_NBLK) { - rv = ksl_split_node(ksl, blk, i); - if (rv != 0) { - return rv; - } - if (ksl->compar((nghttp3_ksl_key *)node->key, key)) { - node = nghttp3_ksl_nth_node(ksl, blk, i + 1); - if (ksl->compar((nghttp3_ksl_key *)node->key, key)) { - ksl_node_set_key(ksl, node, key); - } - } - } - - blk = node->blk; - } -} - -/* - * ksl_remove_node removes the node included in |blk| at the index of - * |i|. - */ -static void ksl_remove_node(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t i) { - memmove(blk->nodes + i * ksl->nodelen, blk->nodes + (i + 1) * ksl->nodelen, - ksl->nodelen * (blk->n - (i + 1))); - - --blk->n; -} - -/* - * ksl_merge_node merges 2 nodes which are the nodes at the index of - * |i| and |i + 1|. - * - * If |blk| is the direct descendant of head (root) block and the head - * block contains just 2 nodes, the merged block becomes head block, - * which decreases the height of |ksl| by 1. - * - * This function returns the pointer to the merged block. - */ -static nghttp3_ksl_blk *ksl_merge_node(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, - size_t i) { - nghttp3_ksl_blk *lblk, *rblk; - - assert(i + 1 < blk->n); - - lblk = nghttp3_ksl_nth_node(ksl, blk, i)->blk; - rblk = nghttp3_ksl_nth_node(ksl, blk, i + 1)->blk; - - assert(lblk->n + rblk->n < NGHTTP3_KSL_MAX_NBLK); - - memcpy(lblk->nodes + ksl->nodelen * lblk->n, rblk->nodes, - ksl->nodelen * rblk->n); - - lblk->n += rblk->n; - lblk->next = rblk->next; - if (lblk->next) { - lblk->next->prev = lblk; - } else if (ksl->back == rblk) { - ksl->back = lblk; - } - - nghttp3_mem_free(ksl->mem, rblk); - - if (ksl->head == blk && blk->n == 2) { - nghttp3_mem_free(ksl->mem, ksl->head); - ksl->head = lblk; - } else { - ksl_remove_node(ksl, blk, i + 1); - ksl_node_set_key(ksl, nghttp3_ksl_nth_node(ksl, blk, i), - nghttp3_ksl_nth_node(ksl, lblk, lblk->n - 1)->key); - } - - return lblk; -} - -/* - * ksl_shift_left moves the first node in blk->nodes[i]->blk->nodes to - * blk->nodes[i - 1]->blk->nodes. - */ -static void ksl_shift_left(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t i) { - nghttp3_ksl_node *lnode, *rnode, *dest, *src; - - assert(i > 0); - - lnode = nghttp3_ksl_nth_node(ksl, blk, i - 1); - rnode = nghttp3_ksl_nth_node(ksl, blk, i); - - assert(lnode->blk->n < NGHTTP3_KSL_MAX_NBLK); - assert(rnode->blk->n > NGHTTP3_KSL_MIN_NBLK); - - dest = nghttp3_ksl_nth_node(ksl, lnode->blk, lnode->blk->n); - src = nghttp3_ksl_nth_node(ksl, rnode->blk, 0); - - memcpy(dest, src, ksl->nodelen); - ksl_node_set_key(ksl, lnode, dest->key); - ++lnode->blk->n; - - --rnode->blk->n; - memmove(rnode->blk->nodes, rnode->blk->nodes + ksl->nodelen, - ksl->nodelen * rnode->blk->n); -} - -/* - * ksl_shift_right moves the last node in blk->nodes[i]->blk->nodes to - * blk->nodes[i + 1]->blk->nodes. - */ -static void ksl_shift_right(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t i) { - nghttp3_ksl_node *lnode, *rnode, *dest, *src; - - assert(i < blk->n - 1); - - lnode = nghttp3_ksl_nth_node(ksl, blk, i); - rnode = nghttp3_ksl_nth_node(ksl, blk, i + 1); - - assert(lnode->blk->n > NGHTTP3_KSL_MIN_NBLK); - assert(rnode->blk->n < NGHTTP3_KSL_MAX_NBLK); - - memmove(rnode->blk->nodes + ksl->nodelen, rnode->blk->nodes, - ksl->nodelen * rnode->blk->n); - ++rnode->blk->n; - - dest = nghttp3_ksl_nth_node(ksl, rnode->blk, 0); - src = nghttp3_ksl_nth_node(ksl, lnode->blk, lnode->blk->n - 1); - - memcpy(dest, src, ksl->nodelen); - - --lnode->blk->n; - ksl_node_set_key( - ksl, lnode, - nghttp3_ksl_nth_node(ksl, lnode->blk, lnode->blk->n - 1)->key); -} - -/* - * key_equal returns nonzero if |lhs| and |rhs| are equal using the - * function |compar|. - */ -static int key_equal(nghttp3_ksl_compar compar, const nghttp3_ksl_key *lhs, - const nghttp3_ksl_key *rhs) { - return !compar(lhs, rhs) && !compar(rhs, lhs); -} - -int nghttp3_ksl_remove(nghttp3_ksl *ksl, nghttp3_ksl_it *it, - const nghttp3_ksl_key *key) { - nghttp3_ksl_blk *blk = ksl->head; - nghttp3_ksl_node *node; - size_t i; - - if (!blk->leaf && blk->n == 2 && - nghttp3_ksl_nth_node(ksl, blk, 0)->blk->n == NGHTTP3_KSL_MIN_NBLK && - nghttp3_ksl_nth_node(ksl, blk, 1)->blk->n == NGHTTP3_KSL_MIN_NBLK) { - blk = ksl_merge_node(ksl, ksl->head, 0); - } - - for (;;) { - i = ksl_bsearch(ksl, blk, key, ksl->compar); - - if (i == blk->n) { - if (it) { - *it = nghttp3_ksl_end(ksl); - } - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - if (blk->leaf) { - if (ksl->compar(key, nghttp3_ksl_nth_node(ksl, blk, i)->key)) { - if (it) { - *it = nghttp3_ksl_end(ksl); - } - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - ksl_remove_node(ksl, blk, i); - --ksl->n; - if (it) { - if (blk->n == i && blk->next) { - nghttp3_ksl_it_init(it, ksl, blk->next, 0); - } else { - nghttp3_ksl_it_init(it, ksl, blk, i); - } - } - return 0; - } - - node = nghttp3_ksl_nth_node(ksl, blk, i); - - if (node->blk->n == NGHTTP3_KSL_MIN_NBLK) { - if (i > 0 && nghttp3_ksl_nth_node(ksl, blk, i - 1)->blk->n > - NGHTTP3_KSL_MIN_NBLK) { - ksl_shift_right(ksl, blk, i - 1); - blk = node->blk; - } else if (i + 1 < blk->n && - nghttp3_ksl_nth_node(ksl, blk, i + 1)->blk->n > - NGHTTP3_KSL_MIN_NBLK) { - ksl_shift_left(ksl, blk, i + 1); - blk = node->blk; - } else if (i > 0) { - blk = ksl_merge_node(ksl, blk, i - 1); - } else { - assert(i + 1 < blk->n); - blk = ksl_merge_node(ksl, blk, i); - } - } else { - blk = node->blk; - } - } -} - -nghttp3_ksl_it nghttp3_ksl_lower_bound(nghttp3_ksl *ksl, - const nghttp3_ksl_key *key) { - nghttp3_ksl_blk *blk = ksl->head; - nghttp3_ksl_it it; - size_t i; - - for (;;) { - i = ksl_bsearch(ksl, blk, key, ksl->compar); - - if (blk->leaf) { - if (i == blk->n && blk->next) { - blk = blk->next; - i = 0; - } - nghttp3_ksl_it_init(&it, ksl, blk, i); - return it; - } - - if (i == blk->n) { - /* This happens if descendant has smaller key. Fast forward to - find last node in this subtree. */ - for (; !blk->leaf; blk = nghttp3_ksl_nth_node(ksl, blk, blk->n - 1)->blk) - ; - if (blk->next) { - blk = blk->next; - i = 0; - } else { - i = blk->n; - } - nghttp3_ksl_it_init(&it, ksl, blk, i); - return it; - } - blk = nghttp3_ksl_nth_node(ksl, blk, i)->blk; - } -} - -nghttp3_ksl_it nghttp3_ksl_lower_bound_compar(nghttp3_ksl *ksl, - const nghttp3_ksl_key *key, - nghttp3_ksl_compar compar) { - nghttp3_ksl_blk *blk = ksl->head; - nghttp3_ksl_it it; - size_t i; - - for (;;) { - i = ksl_bsearch(ksl, blk, key, compar); - - if (blk->leaf) { - if (i == blk->n && blk->next) { - blk = blk->next; - i = 0; - } - nghttp3_ksl_it_init(&it, ksl, blk, i); - return it; - } - - if (i == blk->n) { - /* This happens if descendant has smaller key. Fast forward to - find last node in this subtree. */ - for (; !blk->leaf; blk = nghttp3_ksl_nth_node(ksl, blk, blk->n - 1)->blk) - ; - if (blk->next) { - blk = blk->next; - i = 0; - } else { - i = blk->n; - } - nghttp3_ksl_it_init(&it, ksl, blk, i); - return it; - } - blk = nghttp3_ksl_nth_node(ksl, blk, i)->blk; - } -} - -void nghttp3_ksl_update_key(nghttp3_ksl *ksl, const nghttp3_ksl_key *old_key, - const nghttp3_ksl_key *new_key) { - nghttp3_ksl_blk *blk = ksl->head; - nghttp3_ksl_node *node; - size_t i; - - for (;;) { - i = ksl_bsearch(ksl, blk, old_key, ksl->compar); - - assert(i < blk->n); - node = nghttp3_ksl_nth_node(ksl, blk, i); - - if (blk->leaf) { - assert(key_equal(ksl->compar, (nghttp3_ksl_key *)node->key, old_key)); - ksl_node_set_key(ksl, node, new_key); - return; - } - - if (key_equal(ksl->compar, (nghttp3_ksl_key *)node->key, old_key) || - ksl->compar((nghttp3_ksl_key *)node->key, new_key)) { - ksl_node_set_key(ksl, node, new_key); - } - - blk = node->blk; - } -} - -static void ksl_print(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t level) { - size_t i; - nghttp3_ksl_node *node; - - fprintf(stderr, "LV=%zu n=%zu\n", level, blk->n); - - if (blk->leaf) { - for (i = 0; i < blk->n; ++i) { - node = nghttp3_ksl_nth_node(ksl, blk, i); - fprintf(stderr, " %" PRId64, *(int64_t *)(void *)node->key); - } - fprintf(stderr, "\n"); - return; - } - - for (i = 0; i < blk->n; ++i) { - ksl_print(ksl, nghttp3_ksl_nth_node(ksl, blk, i)->blk, level + 1); - } -} - -size_t nghttp3_ksl_len(nghttp3_ksl *ksl) { return ksl->n; } - -void nghttp3_ksl_clear(nghttp3_ksl *ksl) { - size_t i; - nghttp3_ksl_blk *head; - - if (!ksl->head->leaf) { - for (i = 0; i < ksl->head->n; ++i) { - ksl_free_blk(ksl, nghttp3_ksl_nth_node(ksl, ksl->head, i)->blk); - } - } - - ksl->front = ksl->back = ksl->head; - ksl->n = 0; - - head = ksl->head; - - head->next = head->prev = NULL; - head->n = 0; - head->leaf = 1; -} - -void nghttp3_ksl_print(nghttp3_ksl *ksl) { ksl_print(ksl, ksl->head, 0); } - -nghttp3_ksl_it nghttp3_ksl_begin(const nghttp3_ksl *ksl) { - nghttp3_ksl_it it; - nghttp3_ksl_it_init(&it, ksl, ksl->front, 0); - return it; -} - -nghttp3_ksl_it nghttp3_ksl_end(const nghttp3_ksl *ksl) { - nghttp3_ksl_it it; - nghttp3_ksl_it_init(&it, ksl, ksl->back, ksl->back->n); - return it; -} - -void nghttp3_ksl_it_init(nghttp3_ksl_it *it, const nghttp3_ksl *ksl, - nghttp3_ksl_blk *blk, size_t i) { - it->ksl = ksl; - it->blk = blk; - it->i = i; -} - -void *nghttp3_ksl_it_get(const nghttp3_ksl_it *it) { - assert(it->i < it->blk->n); - return nghttp3_ksl_nth_node(it->ksl, it->blk, it->i)->data; -} - -void nghttp3_ksl_it_prev(nghttp3_ksl_it *it) { - assert(!nghttp3_ksl_it_begin(it)); - - if (it->i == 0) { - it->blk = it->blk->prev; - it->i = it->blk->n - 1; - } else { - --it->i; - } -} - -int nghttp3_ksl_it_begin(const nghttp3_ksl_it *it) { - return it->i == 0 && it->blk->prev == NULL; -} - -int nghttp3_ksl_range_compar(const nghttp3_ksl_key *lhs, - const nghttp3_ksl_key *rhs) { - const nghttp3_range *a = lhs, *b = rhs; - return a->begin < b->begin; -} - -int nghttp3_ksl_range_exclusive_compar(const nghttp3_ksl_key *lhs, - const nghttp3_ksl_key *rhs) { - const nghttp3_range *a = lhs, *b = rhs; - return a->begin < b->begin && - !(nghttp3_max(a->begin, b->begin) < nghttp3_min(a->end, b->end)); -} diff --git a/deps/nghttp3/lib/nghttp3_ksl.h b/deps/nghttp3/lib/nghttp3_ksl.h deleted file mode 100644 index aeb77eea575bcc..00000000000000 --- a/deps/nghttp3/lib/nghttp3_ksl.h +++ /dev/null @@ -1,335 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_KSL_H -#define NGHTTP3_KSL_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include - -/* - * Skip List using single key instead of range. - */ - -#define NGHTTP3_KSL_DEGR 16 -/* NGHTTP3_KSL_MAX_NBLK is the maximum number of nodes which a single - block can contain. */ -#define NGHTTP3_KSL_MAX_NBLK (2 * NGHTTP3_KSL_DEGR - 1) -/* NGHTTP3_KSL_MIN_NBLK is the minimum number of nodes which a single - block other than root must contains. */ -#define NGHTTP3_KSL_MIN_NBLK (NGHTTP3_KSL_DEGR - 1) - -/* - * nghttp3_ksl_key represents key in nghttp3_ksl. - */ -typedef void nghttp3_ksl_key; - -struct nghttp3_ksl_node; -typedef struct nghttp3_ksl_node nghttp3_ksl_node; - -struct nghttp3_ksl_blk; -typedef struct nghttp3_ksl_blk nghttp3_ksl_blk; - -/* - * nghttp3_ksl_node is a node which contains either nghttp3_ksl_blk or - * opaque data. If a node is an internal node, it contains - * nghttp3_ksl_blk. Otherwise, it has data. The key is stored at the - * location starting at key. - */ -struct nghttp3_ksl_node { - union { - nghttp3_ksl_blk *blk; - void *data; - }; - union { - uint64_t align; - /* key is a buffer to include key associated to this node. - Because the length of key is unknown until nghttp3_ksl_init is - called, the actual buffer will be allocated after this - field. */ - uint8_t key[1]; - }; -}; - -/* - * nghttp3_ksl_blk contains nghttp3_ksl_node objects. - */ -struct nghttp3_ksl_blk { - /* next points to the next block if leaf field is nonzero. */ - nghttp3_ksl_blk *next; - /* prev points to the previous block if leaf field is nonzero. */ - nghttp3_ksl_blk *prev; - /* n is the number of nodes this object contains in nodes. */ - size_t n; - /* leaf is nonzero if this block contains leaf nodes. */ - int leaf; - union { - uint64_t align; - /* nodes is a buffer to contain NGHTTP3_KSL_MAX_NBLK - nghttp3_ksl_node objects. Because nghttp3_ksl_node object is - allocated along with the additional variable length key - storage, the size of buffer is unknown until nghttp3_ksl_init - is called. */ - uint8_t nodes[1]; - }; -}; - -/* - * nghttp3_ksl_compar is a function type which returns nonzero if key - * |lhs| should be placed before |rhs|. It returns 0 otherwise. - */ -typedef int (*nghttp3_ksl_compar)(const nghttp3_ksl_key *lhs, - const nghttp3_ksl_key *rhs); - -struct nghttp3_ksl; -typedef struct nghttp3_ksl nghttp3_ksl; - -struct nghttp3_ksl_it; -typedef struct nghttp3_ksl_it nghttp3_ksl_it; - -/* - * nghttp3_ksl_it is a forward iterator to iterate nodes. - */ -struct nghttp3_ksl_it { - const nghttp3_ksl *ksl; - nghttp3_ksl_blk *blk; - size_t i; -}; - -/* - * nghttp3_ksl is a deterministic paged skip list. - */ -struct nghttp3_ksl { - /* head points to the root block. */ - nghttp3_ksl_blk *head; - /* front points to the first leaf block. */ - nghttp3_ksl_blk *front; - /* back points to the last leaf block. */ - nghttp3_ksl_blk *back; - nghttp3_ksl_compar compar; - size_t n; - /* keylen is the size of key */ - size_t keylen; - /* nodelen is the actual size of nghttp3_ksl_node including key - storage. */ - size_t nodelen; - const nghttp3_mem *mem; -}; - -/* - * nghttp3_ksl_init initializes |ksl|. |compar| specifies compare - * function. |keylen| is the length of key. - * - * It returns 0 if it succeeds, or one of the following negative error - * codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_ksl_init(nghttp3_ksl *ksl, nghttp3_ksl_compar compar, size_t keylen, - const nghttp3_mem *mem); - -/* - * nghttp3_ksl_free frees resources allocated for |ksl|. If |ksl| is - * NULL, this function does nothing. It does not free the memory - * region pointed by |ksl| itself. - */ -void nghttp3_ksl_free(nghttp3_ksl *ksl); - -/* - * nghttp3_ksl_insert inserts |key| with its associated |data|. On - * successful insertion, the iterator points to the inserted node is - * stored in |*it|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - * NGHTTP3_ERR_INVALID_ARGUMENT - * |key| already exists. - */ -int nghttp3_ksl_insert(nghttp3_ksl *ksl, nghttp3_ksl_it *it, - const nghttp3_ksl_key *key, void *data); - -/* - * nghttp3_ksl_remove removes the |key| from |ksl|. - * - * This function assigns the iterator to |*it|, which points to the - * node which is located at the right next of the removed node if |it| - * is not NULL. If |key| is not found, no deletion takes place and - * the return value of nghttp3_ksl_end(ksl) is assigned to |*it|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_INVALID_ARGUMENT - * |key| does not exist. - */ -int nghttp3_ksl_remove(nghttp3_ksl *ksl, nghttp3_ksl_it *it, - const nghttp3_ksl_key *key); - -/* - * nghttp3_ksl_lower_bound returns the iterator which points to the - * first node which has the key which is equal to |key| or the last - * node which satisfies !compar(&node->key, key). If there is no such - * node, it returns the iterator which satisfies nghttp3_ksl_it_end(it) - * != 0. - */ -nghttp3_ksl_it nghttp3_ksl_lower_bound(nghttp3_ksl *ksl, - const nghttp3_ksl_key *key); - -/* - * nghttp3_ksl_lower_bound_compar works like nghttp3_ksl_lower_bound, - * but it takes custom function |compar| to do lower bound search. - */ -nghttp3_ksl_it nghttp3_ksl_lower_bound_compar(nghttp3_ksl *ksl, - const nghttp3_ksl_key *key, - nghttp3_ksl_compar compar); - -/* - * nghttp3_ksl_update_key replaces the key of nodes which has |old_key| - * with |new_key|. |new_key| must be strictly greater than the - * previous node and strictly smaller than the next node. - */ -void nghttp3_ksl_update_key(nghttp3_ksl *ksl, const nghttp3_ksl_key *old_key, - const nghttp3_ksl_key *new_key); - -/* - * nghttp3_ksl_begin returns the iterator which points to the first - * node. If there is no node in |ksl|, it returns the iterator which - * satisfies nghttp3_ksl_it_end(it) != 0. - */ -nghttp3_ksl_it nghttp3_ksl_begin(const nghttp3_ksl *ksl); - -/* - * nghttp3_ksl_end returns the iterator which points to the node - * following the last node. The returned object satisfies - * nghttp3_ksl_it_end(). If there is no node in |ksl|, it returns the - * iterator which satisfies nghttp3_ksl_it_begin(it) != 0. - */ -nghttp3_ksl_it nghttp3_ksl_end(const nghttp3_ksl *ksl); - -/* - * nghttp3_ksl_len returns the number of elements stored in |ksl|. - */ -size_t nghttp3_ksl_len(nghttp3_ksl *ksl); - -/* - * nghttp3_ksl_clear removes all elements stored in |ksl|. - */ -void nghttp3_ksl_clear(nghttp3_ksl *ksl); - -/* - * nghttp3_ksl_nth_node returns the |n|th node under |blk|. - */ -#define nghttp3_ksl_nth_node(KSL, BLK, N) \ - ((nghttp3_ksl_node *)(void *)((BLK)->nodes + (KSL)->nodelen * (N))) - -/* - * nghttp3_ksl_print prints its internal state in stderr. It assumes - * that the key is of type int64_t. This function should be used for - * the debugging purpose only. - */ -void nghttp3_ksl_print(nghttp3_ksl *ksl); - -/* - * nghttp3_ksl_it_init initializes |it|. - */ -void nghttp3_ksl_it_init(nghttp3_ksl_it *it, const nghttp3_ksl *ksl, - nghttp3_ksl_blk *blk, size_t i); - -/* - * nghttp3_ksl_it_get returns the data associated to the node which - * |it| points to. It is undefined to call this function when - * nghttp3_ksl_it_end(it) returns nonzero. - */ -void *nghttp3_ksl_it_get(const nghttp3_ksl_it *it); - -/* - * nghttp3_ksl_it_next advances the iterator by one. It is undefined - * if this function is called when nghttp3_ksl_it_end(it) returns - * nonzero. - */ -#define nghttp3_ksl_it_next(IT) \ - (++(IT)->i == (IT)->blk->n && (IT)->blk->next \ - ? ((IT)->blk = (IT)->blk->next, (IT)->i = 0) \ - : 0) - -/* - * nghttp3_ksl_it_prev moves backward the iterator by one. It is - * undefined if this function is called when nghttp3_ksl_it_begin(it) - * returns nonzero. - */ -void nghttp3_ksl_it_prev(nghttp3_ksl_it *it); - -/* - * nghttp3_ksl_it_end returns nonzero if |it| points to the beyond the - * last node. - */ -#define nghttp3_ksl_it_end(IT) \ - ((IT)->blk->n == (IT)->i && (IT)->blk->next == NULL) - -/* - * nghttp3_ksl_it_begin returns nonzero if |it| points to the first - * node. |it| might satisfy both nghttp3_ksl_it_begin(&it) and - * nghttp3_ksl_it_end(&it) if the skip list has no node. - */ -int nghttp3_ksl_it_begin(const nghttp3_ksl_it *it); - -/* - * nghttp3_ksl_key returns the key of the node which |it| points to. - * It is undefined to call this function when nghttp3_ksl_it_end(it) - * returns nonzero. - */ -#define nghttp3_ksl_it_key(IT) \ - ((nghttp3_ksl_key *)nghttp3_ksl_nth_node((IT)->ksl, (IT)->blk, (IT)->i)->key) - -/* - * nghttp3_ksl_range_compar is an implementation of - * nghttp3_ksl_compar. lhs->ptr and rhs->ptr must point to - * nghttp3_range object and the function returns nonzero if (const - * nghttp3_range *)(lhs->ptr)->begin < (const nghttp3_range - * *)(rhs->ptr)->begin. - */ -int nghttp3_ksl_range_compar(const nghttp3_ksl_key *lhs, - const nghttp3_ksl_key *rhs); - -/* - * nghttp3_ksl_range_exclusive_compar is an implementation of - * nghttp3_ksl_compar. lhs->ptr and rhs->ptr must point to - * nghttp3_range object and the function returns nonzero if (const - * nghttp3_range *)(lhs->ptr)->begin < (const nghttp3_range - * *)(rhs->ptr)->begin and the 2 ranges do not intersect. - */ -int nghttp3_ksl_range_exclusive_compar(const nghttp3_ksl_key *lhs, - const nghttp3_ksl_key *rhs); - -#endif /* NGHTTP3_KSL_H */ diff --git a/deps/nghttp3/lib/nghttp3_macro.h b/deps/nghttp3/lib/nghttp3_macro.h deleted file mode 100644 index 6ee704cc47dd98..00000000000000 --- a/deps/nghttp3/lib/nghttp3_macro.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_MACRO_H -#define NGHTTP3_MACRO_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include - -#define nghttp3_min(A, B) ((A) < (B) ? (A) : (B)) -#define nghttp3_max(A, B) ((A) > (B) ? (A) : (B)) - -#define nghttp3_struct_of(ptr, type, member) \ - ((type *)(void *)((char *)(ptr)-offsetof(type, member))) - -#define nghttp3_arraylen(A) (sizeof(A) / sizeof(*(A))) - -#define lstreq(A, B, N) ((sizeof((A)) - 1) == (N) && memcmp((A), (B), (N)) == 0) - -#endif /* NGHTTP3_MACRO_H */ diff --git a/deps/nghttp3/lib/nghttp3_map.c b/deps/nghttp3/lib/nghttp3_map.c deleted file mode 100644 index e8eb811566dcc7..00000000000000 --- a/deps/nghttp3/lib/nghttp3_map.c +++ /dev/null @@ -1,337 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2012 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_map.h" - -#include -#include - -#include "nghttp3_conv.h" - -#define INITIAL_TABLE_LENGTH 256 - -int nghttp3_map_init(nghttp3_map *map, const nghttp3_mem *mem) { - map->mem = mem; - map->tablelen = INITIAL_TABLE_LENGTH; - map->table = - nghttp3_mem_calloc(mem, map->tablelen, sizeof(nghttp3_map_bucket)); - if (map->table == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - map->size = 0; - - return 0; -} - -void nghttp3_map_free(nghttp3_map *map) { - size_t i; - nghttp3_map_bucket *bkt; - - if (!map) { - return; - } - - for (i = 0; i < map->tablelen; ++i) { - bkt = &map->table[i]; - if (bkt->ksl) { - nghttp3_ksl_free(bkt->ksl); - nghttp3_mem_free(map->mem, bkt->ksl); - } - } - - nghttp3_mem_free(map->mem, map->table); -} - -void nghttp3_map_each_free(nghttp3_map *map, - int (*func)(nghttp3_map_entry *entry, void *ptr), - void *ptr) { - uint32_t i; - nghttp3_map_bucket *bkt; - nghttp3_ksl_it it; - - for (i = 0; i < map->tablelen; ++i) { - bkt = &map->table[i]; - - if (bkt->ptr) { - func(bkt->ptr, ptr); - bkt->ptr = NULL; - assert(bkt->ksl == NULL || nghttp3_ksl_len(bkt->ksl) == 0); - continue; - } - - if (bkt->ksl) { - for (it = nghttp3_ksl_begin(bkt->ksl); !nghttp3_ksl_it_end(&it); - nghttp3_ksl_it_next(&it)) { - func(nghttp3_ksl_it_get(&it), ptr); - } - - nghttp3_ksl_free(bkt->ksl); - nghttp3_mem_free(map->mem, bkt->ksl); - bkt->ksl = NULL; - } - } -} - -int nghttp3_map_each(nghttp3_map *map, - int (*func)(nghttp3_map_entry *entry, void *ptr), - void *ptr) { - int rv; - uint32_t i; - nghttp3_map_bucket *bkt; - nghttp3_ksl_it it; - - for (i = 0; i < map->tablelen; ++i) { - bkt = &map->table[i]; - - if (bkt->ptr) { - rv = func(bkt->ptr, ptr); - if (rv != 0) { - return rv; - } - assert(bkt->ksl == NULL || nghttp3_ksl_len(bkt->ksl) == 0); - continue; - } - - if (bkt->ksl) { - for (it = nghttp3_ksl_begin(bkt->ksl); !nghttp3_ksl_it_end(&it); - nghttp3_ksl_it_next(&it)) { - rv = func(nghttp3_ksl_it_get(&it), ptr); - if (rv != 0) { - return rv; - } - } - } - } - return 0; -} - -void nghttp3_map_entry_init(nghttp3_map_entry *entry, key_type key) { - entry->key = key; - entry->next = NULL; -} - -/* FNV1a hash */ -static uint32_t hash(key_type key, uint32_t mod) { - uint8_t *p, *end; - uint32_t h = 0x811C9DC5u; - - key = nghttp3_htonl64(key); - p = (uint8_t *)&key; - end = p + sizeof(key_type); - - for (; p != end;) { - h ^= *p++; - h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24); - } - - return h & (mod - 1); -} - -static int less(const nghttp3_ksl_key *lhs, const nghttp3_ksl_key *rhs) { - return *(key_type *)lhs < *(key_type *)rhs; -} - -static int map_insert(nghttp3_map *map, nghttp3_map_bucket *table, - uint32_t tablelen, nghttp3_map_entry *entry) { - uint32_t h = hash(entry->key, tablelen); - nghttp3_map_bucket *bkt = &table[h]; - const nghttp3_mem *mem = map->mem; - int rv; - - if (bkt->ptr == NULL && - (bkt->ksl == NULL || nghttp3_ksl_len(bkt->ksl) == 0)) { - bkt->ptr = entry; - return 0; - } - - if (!bkt->ksl) { - bkt->ksl = nghttp3_mem_malloc(mem, sizeof(*bkt->ksl)); - if (bkt->ksl == NULL) { - return NGHTTP3_ERR_NOMEM; - } - nghttp3_ksl_init(bkt->ksl, less, sizeof(key_type), mem); - } - - if (bkt->ptr) { - rv = nghttp3_ksl_insert(bkt->ksl, NULL, &bkt->ptr->key, bkt->ptr); - if (rv != 0) { - return rv; - } - - bkt->ptr = NULL; - } - - return nghttp3_ksl_insert(bkt->ksl, NULL, &entry->key, entry); -} - -/* new_tablelen must be power of 2 */ -static int map_resize(nghttp3_map *map, uint32_t new_tablelen) { - uint32_t i; - nghttp3_map_bucket *new_table; - nghttp3_map_bucket *bkt; - nghttp3_ksl_it it; - int rv; - - new_table = - nghttp3_mem_calloc(map->mem, new_tablelen, sizeof(nghttp3_map_bucket)); - if (new_table == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - for (i = 0; i < map->tablelen; ++i) { - bkt = &map->table[i]; - - if (bkt->ptr) { - rv = map_insert(map, new_table, new_tablelen, bkt->ptr); - if (rv != 0) { - goto fail; - } - assert(bkt->ksl == NULL || nghttp3_ksl_len(bkt->ksl) == 0); - continue; - } - - if (bkt->ksl) { - for (it = nghttp3_ksl_begin(bkt->ksl); !nghttp3_ksl_it_end(&it); - nghttp3_ksl_it_next(&it)) { - rv = map_insert(map, new_table, new_tablelen, nghttp3_ksl_it_get(&it)); - if (rv != 0) { - goto fail; - } - } - } - } - - for (i = 0; i < map->tablelen; ++i) { - bkt = &map->table[i]; - if (bkt->ksl) { - nghttp3_ksl_free(bkt->ksl); - nghttp3_mem_free(map->mem, bkt->ksl); - } - } - - nghttp3_mem_free(map->mem, map->table); - map->tablelen = new_tablelen; - map->table = new_table; - - return 0; - -fail: - for (i = 0; i < new_tablelen; ++i) { - bkt = &new_table[i]; - if (bkt->ksl) { - nghttp3_ksl_free(bkt->ksl); - nghttp3_mem_free(map->mem, bkt->ksl); - } - } - - return rv; -} - -int nghttp3_map_insert(nghttp3_map *map, nghttp3_map_entry *new_entry) { - int rv; - - /* Load factor is 0.75 */ - if ((map->size + 1) * 4 > map->tablelen * 3) { - rv = map_resize(map, map->tablelen * 2); - if (rv != 0) { - return rv; - } - } - rv = map_insert(map, map->table, map->tablelen, new_entry); - if (rv != 0) { - return rv; - } - ++map->size; - return 0; -} - -nghttp3_map_entry *nghttp3_map_find(nghttp3_map *map, key_type key) { - nghttp3_map_bucket *bkt = &map->table[hash(key, map->tablelen)]; - nghttp3_ksl_it it; - - if (bkt->ptr) { - if (bkt->ptr->key == key) { - return bkt->ptr; - } - return NULL; - } - - if (bkt->ksl) { - it = nghttp3_ksl_lower_bound(bkt->ksl, &key); - if (nghttp3_ksl_it_end(&it) || - *(key_type *)nghttp3_ksl_it_key(&it) != key) { - return NULL; - } - return nghttp3_ksl_it_get(&it); - } - - return NULL; -} - -int nghttp3_map_remove(nghttp3_map *map, key_type key) { - nghttp3_map_bucket *bkt = &map->table[hash(key, map->tablelen)]; - int rv; - - if (bkt->ptr) { - if (bkt->ptr->key == key) { - bkt->ptr = NULL; - --map->size; - return 0; - } - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - if (bkt->ksl) { - rv = nghttp3_ksl_remove(bkt->ksl, NULL, &key); - if (rv != 0) { - return rv; - } - --map->size; - return 0; - } - - return NGHTTP3_ERR_INVALID_ARGUMENT; -} - -void nghttp3_map_clear(nghttp3_map *map) { - uint32_t i; - nghttp3_map_bucket *bkt; - - for (i = 0; i < map->tablelen; ++i) { - bkt = &map->table[i]; - bkt->ptr = NULL; - if (bkt->ksl) { - nghttp3_ksl_free(bkt->ksl); - nghttp3_mem_free(map->mem, bkt->ksl); - bkt->ksl = NULL; - } - } - - map->size = 0; -} - -size_t nghttp3_map_size(nghttp3_map *map) { return map->size; } diff --git a/deps/nghttp3/lib/nghttp3_map.h b/deps/nghttp3/lib/nghttp3_map.h deleted file mode 100644 index 8a00711970907c..00000000000000 --- a/deps/nghttp3/lib/nghttp3_map.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2012 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_MAP_H -#define NGHTTP3_MAP_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "nghttp3_mem.h" -#include "nghttp3_ksl.h" - -/* Implementation of unordered map */ - -typedef uint64_t key_type; - -typedef struct nghttp3_map_entry { - struct nghttp3_map_entry *next; - key_type key; -} nghttp3_map_entry; - -typedef struct nghttp3_map_bucket { - nghttp3_map_entry *ptr; - nghttp3_ksl *ksl; -} nghttp3_map_bucket; - -typedef struct { - nghttp3_map_bucket *table; - const nghttp3_mem *mem; - size_t size; - uint32_t tablelen; -} nghttp3_map; - -/* - * Initializes the map |map|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory - */ -int nghttp3_map_init(nghttp3_map *map, const nghttp3_mem *mem); - -/* - * Deallocates any resources allocated for |map|. The stored entries - * are not freed by this function. Use nghttp3_map_each_free() to free - * each entries. - */ -void nghttp3_map_free(nghttp3_map *map); - -/* - * Deallocates each entries using |func| function and any resources - * allocated for |map|. The |func| function is responsible for freeing - * given the |entry| object. The |ptr| will be passed to the |func| as - * send argument. The return value of the |func| will be ignored. - */ -void nghttp3_map_each_free(nghttp3_map *map, - int (*func)(nghttp3_map_entry *entry, void *ptr), - void *ptr); - -/* - * Initializes the |entry| with the |key|. All entries to be inserted - * to the map must be initialized with this function. - */ -void nghttp3_map_entry_init(nghttp3_map_entry *entry, key_type key); - -/* - * Inserts the new |entry| with the key |entry->key| to the map |map|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_INVALID_ARGUMENT - * The item associated by |key| already exists. - * NGHTTP3_ERR_NOMEM - * Out of memory - */ -int nghttp3_map_insert(nghttp3_map *map, nghttp3_map_entry *entry); - -/* - * Returns the entry associated by the key |key|. If there is no such - * entry, this function returns NULL. - */ -nghttp3_map_entry *nghttp3_map_find(nghttp3_map *map, key_type key); - -/* - * Removes the entry associated by the key |key| from the |map|. The - * removed entry is not freed by this function. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_INVALID_ARGUMENT - * The entry associated by |key| does not exist. - */ -int nghttp3_map_remove(nghttp3_map *map, key_type key); - -/* - * Removes all entries from |map|. - */ -void nghttp3_map_clear(nghttp3_map *map); - -/* - * Returns the number of items stored in the map |map|. - */ -size_t nghttp3_map_size(nghttp3_map *map); - -/* - * Applies the function |func| to each entry in the |map| with the - * optional user supplied pointer |ptr|. - * - * If the |func| returns 0, this function calls the |func| with the - * next entry. If the |func| returns nonzero, it will not call the - * |func| for further entries and return the return value of the - * |func| immediately. Thus, this function returns 0 if all the - * invocations of the |func| return 0, or nonzero value which the last - * invocation of |func| returns. - * - * Don't use this function to free each entry. Use - * nghttp3_map_each_free() instead. - */ -int nghttp3_map_each(nghttp3_map *map, - int (*func)(nghttp3_map_entry *entry, void *ptr), - void *ptr); - -#endif /* NGHTTP3_MAP_H */ diff --git a/deps/nghttp3/lib/nghttp3_mem.c b/deps/nghttp3/lib/nghttp3_mem.c deleted file mode 100644 index e5f93f10bdabf2..00000000000000 --- a/deps/nghttp3/lib/nghttp3_mem.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2014 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_mem.h" - -static void *default_malloc(size_t size, void *mem_user_data) { - (void)mem_user_data; - - return malloc(size); -} - -static void default_free(void *ptr, void *mem_user_data) { - (void)mem_user_data; - - free(ptr); -} - -static void *default_calloc(size_t nmemb, size_t size, void *mem_user_data) { - (void)mem_user_data; - - return calloc(nmemb, size); -} - -static void *default_realloc(void *ptr, size_t size, void *mem_user_data) { - (void)mem_user_data; - - return realloc(ptr, size); -} - -static nghttp3_mem mem_default = {NULL, default_malloc, default_free, - default_calloc, default_realloc}; - -const nghttp3_mem *nghttp3_mem_default(void) { return &mem_default; } - -void *nghttp3_mem_malloc(const nghttp3_mem *mem, size_t size) { - return mem->malloc(size, mem->mem_user_data); -} - -void nghttp3_mem_free(const nghttp3_mem *mem, void *ptr) { - mem->free(ptr, mem->mem_user_data); -} - -void nghttp3_mem_free2(const nghttp3_free free_func, void *ptr, - void *mem_user_data) { - free_func(ptr, mem_user_data); -} - -void *nghttp3_mem_calloc(const nghttp3_mem *mem, size_t nmemb, size_t size) { - return mem->calloc(nmemb, size, mem->mem_user_data); -} - -void *nghttp3_mem_realloc(const nghttp3_mem *mem, void *ptr, size_t size) { - return mem->realloc(ptr, size, mem->mem_user_data); -} diff --git a/deps/nghttp3/lib/nghttp3_mem.h b/deps/nghttp3/lib/nghttp3_mem.h deleted file mode 100644 index 55ef86b4f921c9..00000000000000 --- a/deps/nghttp3/lib/nghttp3_mem.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2014 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_MEM_H -#define NGHTTP3_MEM_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -/* Convenient wrapper functions to call allocator function in - |mem|. */ -void *nghttp3_mem_malloc(const nghttp3_mem *mem, size_t size); -void nghttp3_mem_free(const nghttp3_mem *mem, void *ptr); -void nghttp3_mem_free2(const nghttp3_free free_func, void *ptr, - void *mem_user_data); -void *nghttp3_mem_calloc(const nghttp3_mem *mem, size_t nmemb, size_t size); -void *nghttp3_mem_realloc(const nghttp3_mem *mem, void *ptr, size_t size); - -#endif /* NGHTTP3_MEM_H */ diff --git a/deps/nghttp3/lib/nghttp3_pq.c b/deps/nghttp3/lib/nghttp3_pq.c deleted file mode 100644 index 5d09050ae63798..00000000000000 --- a/deps/nghttp3/lib/nghttp3_pq.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2012 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_pq.h" - -#include - -#include "nghttp3_macro.h" - -void nghttp3_pq_init(nghttp3_pq *pq, nghttp3_less less, - const nghttp3_mem *mem) { - pq->mem = mem; - pq->capacity = 0; - pq->q = NULL; - pq->length = 0; - pq->less = less; -} - -void nghttp3_pq_free(nghttp3_pq *pq) { - nghttp3_mem_free(pq->mem, pq->q); - pq->q = NULL; -} - -static void swap(nghttp3_pq *pq, size_t i, size_t j) { - nghttp3_pq_entry *a = pq->q[i]; - nghttp3_pq_entry *b = pq->q[j]; - - pq->q[i] = b; - b->index = i; - pq->q[j] = a; - a->index = j; -} - -static void bubble_up(nghttp3_pq *pq, size_t index) { - size_t parent; - while (index != 0) { - parent = (index - 1) / 2; - if (!pq->less(pq->q[index], pq->q[parent])) { - return; - } - swap(pq, parent, index); - index = parent; - } -} - -int nghttp3_pq_push(nghttp3_pq *pq, nghttp3_pq_entry *item) { - if (pq->capacity <= pq->length) { - void *nq; - size_t ncapacity; - - ncapacity = nghttp3_max(4, (pq->capacity * 2)); - - nq = nghttp3_mem_realloc(pq->mem, pq->q, - ncapacity * sizeof(nghttp3_pq_entry *)); - if (nq == NULL) { - return NGHTTP3_ERR_NOMEM; - } - pq->capacity = ncapacity; - pq->q = nq; - } - pq->q[pq->length] = item; - item->index = pq->length; - ++pq->length; - bubble_up(pq, pq->length - 1); - return 0; -} - -nghttp3_pq_entry *nghttp3_pq_top(const nghttp3_pq *pq) { - assert(pq->length); - return pq->q[0]; -} - -static void bubble_down(nghttp3_pq *pq, size_t index) { - size_t i, j, minindex; - for (;;) { - j = index * 2 + 1; - minindex = index; - for (i = 0; i < 2; ++i, ++j) { - if (j >= pq->length) { - break; - } - if (pq->less(pq->q[j], pq->q[minindex])) { - minindex = j; - } - } - if (minindex == index) { - return; - } - swap(pq, index, minindex); - index = minindex; - } -} - -void nghttp3_pq_pop(nghttp3_pq *pq) { - if (pq->length > 0) { - pq->q[0] = pq->q[pq->length - 1]; - pq->q[0]->index = 0; - --pq->length; - bubble_down(pq, 0); - } -} - -void nghttp3_pq_remove(nghttp3_pq *pq, nghttp3_pq_entry *item) { - assert(pq->q[item->index] == item); - - if (item->index == 0) { - nghttp3_pq_pop(pq); - return; - } - - if (item->index == pq->length - 1) { - --pq->length; - return; - } - - pq->q[item->index] = pq->q[pq->length - 1]; - pq->q[item->index]->index = item->index; - --pq->length; - - if (pq->less(item, pq->q[item->index])) { - bubble_down(pq, item->index); - } else { - bubble_up(pq, item->index); - } -} - -int nghttp3_pq_empty(const nghttp3_pq *pq) { return pq->length == 0; } - -size_t nghttp3_pq_size(const nghttp3_pq *pq) { return pq->length; } - -int nghttp3_pq_each(const nghttp3_pq *pq, nghttp3_pq_item_cb fun, void *arg) { - size_t i; - - if (pq->length == 0) { - return 0; - } - for (i = 0; i < pq->length; ++i) { - if ((*fun)(pq->q[i], arg)) { - return 1; - } - } - return 0; -} - -void nghttp3_pq_clear(nghttp3_pq *pq) { pq->length = 0; } diff --git a/deps/nghttp3/lib/nghttp3_pq.h b/deps/nghttp3/lib/nghttp3_pq.h deleted file mode 100644 index e80b1bc43b9f3e..00000000000000 --- a/deps/nghttp3/lib/nghttp3_pq.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2012 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_PQ_H -#define NGHTTP3_PQ_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "nghttp3_mem.h" - -/* Implementation of priority queue */ - -/* NGHTTP3_PQ_BAD_INDEX is the priority queue index which indicates - that an entry is not queued. Assigning this value to - nghttp3_pq_entry.index can check that the entry is queued or not. */ -#define NGHTTP3_PQ_BAD_INDEX SIZE_MAX - -typedef struct { - size_t index; -} nghttp3_pq_entry; - -/* "less" function, return nonzero if |lhs| is less than |rhs|. */ -typedef int (*nghttp3_less)(const nghttp3_pq_entry *lhs, - const nghttp3_pq_entry *rhs); - -typedef struct { - /* The pointer to the pointer to the item stored */ - nghttp3_pq_entry **q; - /* Memory allocator */ - const nghttp3_mem *mem; - /* The number of items stored */ - size_t length; - /* The maximum number of items this pq can store. This is - automatically extended when length is reached to this value. */ - size_t capacity; - /* The less function between items */ - nghttp3_less less; -} nghttp3_pq; - -/* - * Initializes priority queue |pq| with compare function |cmp|. - */ -void nghttp3_pq_init(nghttp3_pq *pq, nghttp3_less less, const nghttp3_mem *mem); - -/* - * Deallocates any resources allocated for |pq|. The stored items are - * not freed by this function. - */ -void nghttp3_pq_free(nghttp3_pq *pq); - -/* - * Adds |item| to the priority queue |pq|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_pq_push(nghttp3_pq *pq, nghttp3_pq_entry *item); - -/* - * Returns item at the top of the queue |pq|. It is undefined if the - * queue is empty. - */ -nghttp3_pq_entry *nghttp3_pq_top(const nghttp3_pq *pq); - -/* - * Pops item at the top of the queue |pq|. The popped item is not - * freed by this function. - */ -void nghttp3_pq_pop(nghttp3_pq *pq); - -/* - * Returns nonzero if the queue |pq| is empty. - */ -int nghttp3_pq_empty(const nghttp3_pq *pq); - -/* - * Returns the number of items in the queue |pq|. - */ -size_t nghttp3_pq_size(const nghttp3_pq *pq); - -typedef int (*nghttp3_pq_item_cb)(nghttp3_pq_entry *item, void *arg); - -/* - * Applys |fun| to each item in |pq|. The |arg| is passed as arg - * parameter to callback function. This function must not change the - * ordering key. If the return value from callback is nonzero, this - * function returns 1 immediately without iterating remaining items. - * Otherwise this function returns 0. - */ -int nghttp3_pq_each(const nghttp3_pq *pq, nghttp3_pq_item_cb fun, void *arg); - -/* - * Removes |item| from priority queue. - */ -void nghttp3_pq_remove(nghttp3_pq *pq, nghttp3_pq_entry *item); - -void nghttp3_pq_clear(nghttp3_pq *pq); - -#endif /* NGHTTP3_PQ_H */ diff --git a/deps/nghttp3/lib/nghttp3_qpack.c b/deps/nghttp3/lib/nghttp3_qpack.c deleted file mode 100644 index d74e29f6fec916..00000000000000 --- a/deps/nghttp3/lib/nghttp3_qpack.c +++ /dev/null @@ -1,4096 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2013 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_qpack.h" - -#include -#include -#include - -#include "nghttp3_str.h" -#include "nghttp3_macro.h" -#include "nghttp3_debug.h" - -/* NGHTTP3_QPACK_MAX_QPACK_STREAMS is the maximum number of concurrent - nghttp3_qpack_stream object to handle a client which never cancel - or acknowledge header block. After this limit, encoder stops using - dynamic table. */ -#define NGHTTP3_QPACK_MAX_QPACK_STREAMS 2000 - -/* Make scalar initialization form of nghttp3_qpack_static_entry */ -#define MAKE_STATIC_ENT(I, T, H) \ - { I, T, H } - -/* Generated by mkstatichdtbl.py */ -static nghttp3_qpack_static_entry token_stable[] = { - MAKE_STATIC_ENT(0, NGHTTP3_QPACK_TOKEN__AUTHORITY, 3153725150u), - MAKE_STATIC_ENT(15, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u), - MAKE_STATIC_ENT(16, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u), - MAKE_STATIC_ENT(17, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u), - MAKE_STATIC_ENT(18, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u), - MAKE_STATIC_ENT(19, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u), - MAKE_STATIC_ENT(20, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u), - MAKE_STATIC_ENT(21, NGHTTP3_QPACK_TOKEN__METHOD, 695666056u), - MAKE_STATIC_ENT(1, NGHTTP3_QPACK_TOKEN__PATH, 3292848686u), - MAKE_STATIC_ENT(22, NGHTTP3_QPACK_TOKEN__SCHEME, 2510477674u), - MAKE_STATIC_ENT(23, NGHTTP3_QPACK_TOKEN__SCHEME, 2510477674u), - MAKE_STATIC_ENT(24, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(25, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(26, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(27, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(28, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(63, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(64, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(65, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(66, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(67, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(68, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(69, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(70, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(71, NGHTTP3_QPACK_TOKEN__STATUS, 4000288983u), - MAKE_STATIC_ENT(29, NGHTTP3_QPACK_TOKEN_ACCEPT, 136609321u), - MAKE_STATIC_ENT(30, NGHTTP3_QPACK_TOKEN_ACCEPT, 136609321u), - MAKE_STATIC_ENT(31, NGHTTP3_QPACK_TOKEN_ACCEPT_ENCODING, 3379649177u), - MAKE_STATIC_ENT(72, NGHTTP3_QPACK_TOKEN_ACCEPT_LANGUAGE, 1979086614u), - MAKE_STATIC_ENT(32, NGHTTP3_QPACK_TOKEN_ACCEPT_RANGES, 1713753958u), - MAKE_STATIC_ENT(73, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_CREDENTIALS, - 901040780u), - MAKE_STATIC_ENT(74, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_CREDENTIALS, - 901040780u), - MAKE_STATIC_ENT(33, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS, - 1524311232u), - MAKE_STATIC_ENT(34, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS, - 1524311232u), - MAKE_STATIC_ENT(75, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS, - 1524311232u), - MAKE_STATIC_ENT(76, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_METHODS, - 2175229868u), - MAKE_STATIC_ENT(77, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_METHODS, - 2175229868u), - MAKE_STATIC_ENT(78, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_METHODS, - 2175229868u), - MAKE_STATIC_ENT(35, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_ORIGIN, - 2710797292u), - MAKE_STATIC_ENT(79, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_EXPOSE_HEADERS, - 2449824425u), - MAKE_STATIC_ENT(80, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_REQUEST_HEADERS, - 3599549072u), - MAKE_STATIC_ENT(81, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_REQUEST_METHOD, - 2417078055u), - MAKE_STATIC_ENT(82, NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_REQUEST_METHOD, - 2417078055u), - MAKE_STATIC_ENT(2, NGHTTP3_QPACK_TOKEN_AGE, 742476188u), - MAKE_STATIC_ENT(83, NGHTTP3_QPACK_TOKEN_ALT_SVC, 2148877059u), - MAKE_STATIC_ENT(84, NGHTTP3_QPACK_TOKEN_AUTHORIZATION, 2436257726u), - MAKE_STATIC_ENT(36, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669u), - MAKE_STATIC_ENT(37, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669u), - MAKE_STATIC_ENT(38, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669u), - MAKE_STATIC_ENT(39, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669u), - MAKE_STATIC_ENT(40, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669u), - MAKE_STATIC_ENT(41, NGHTTP3_QPACK_TOKEN_CACHE_CONTROL, 1355326669u), - MAKE_STATIC_ENT(3, NGHTTP3_QPACK_TOKEN_CONTENT_DISPOSITION, 3889184348u), - MAKE_STATIC_ENT(42, NGHTTP3_QPACK_TOKEN_CONTENT_ENCODING, 65203592u), - MAKE_STATIC_ENT(43, NGHTTP3_QPACK_TOKEN_CONTENT_ENCODING, 65203592u), - MAKE_STATIC_ENT(4, NGHTTP3_QPACK_TOKEN_CONTENT_LENGTH, 1308181789u), - MAKE_STATIC_ENT(85, NGHTTP3_QPACK_TOKEN_CONTENT_SECURITY_POLICY, - 1569039836u), - MAKE_STATIC_ENT(44, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u), - MAKE_STATIC_ENT(45, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u), - MAKE_STATIC_ENT(46, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u), - MAKE_STATIC_ENT(47, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u), - MAKE_STATIC_ENT(48, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u), - MAKE_STATIC_ENT(49, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u), - MAKE_STATIC_ENT(50, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u), - MAKE_STATIC_ENT(51, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u), - MAKE_STATIC_ENT(52, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u), - MAKE_STATIC_ENT(53, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u), - MAKE_STATIC_ENT(54, NGHTTP3_QPACK_TOKEN_CONTENT_TYPE, 4244048277u), - MAKE_STATIC_ENT(5, NGHTTP3_QPACK_TOKEN_COOKIE, 2007449791u), - MAKE_STATIC_ENT(6, NGHTTP3_QPACK_TOKEN_DATE, 3564297305u), - MAKE_STATIC_ENT(86, NGHTTP3_QPACK_TOKEN_EARLY_DATA, 4080895051u), - MAKE_STATIC_ENT(7, NGHTTP3_QPACK_TOKEN_ETAG, 113792960u), - MAKE_STATIC_ENT(87, NGHTTP3_QPACK_TOKEN_EXPECT_CT, 1183214960u), - MAKE_STATIC_ENT(88, NGHTTP3_QPACK_TOKEN_FORWARDED, 1485178027u), - MAKE_STATIC_ENT(8, NGHTTP3_QPACK_TOKEN_IF_MODIFIED_SINCE, 2213050793u), - MAKE_STATIC_ENT(9, NGHTTP3_QPACK_TOKEN_IF_NONE_MATCH, 2536202615u), - MAKE_STATIC_ENT(89, NGHTTP3_QPACK_TOKEN_IF_RANGE, 2340978238u), - MAKE_STATIC_ENT(10, NGHTTP3_QPACK_TOKEN_LAST_MODIFIED, 3226950251u), - MAKE_STATIC_ENT(11, NGHTTP3_QPACK_TOKEN_LINK, 232457833u), - MAKE_STATIC_ENT(12, NGHTTP3_QPACK_TOKEN_LOCATION, 200649126u), - MAKE_STATIC_ENT(90, NGHTTP3_QPACK_TOKEN_ORIGIN, 3649018447u), - MAKE_STATIC_ENT(91, NGHTTP3_QPACK_TOKEN_PURPOSE, 4212263681u), - MAKE_STATIC_ENT(55, NGHTTP3_QPACK_TOKEN_RANGE, 4208725202u), - MAKE_STATIC_ENT(13, NGHTTP3_QPACK_TOKEN_REFERER, 3969579366u), - MAKE_STATIC_ENT(92, NGHTTP3_QPACK_TOKEN_SERVER, 1085029842u), - MAKE_STATIC_ENT(14, NGHTTP3_QPACK_TOKEN_SET_COOKIE, 1848371000u), - MAKE_STATIC_ENT(56, NGHTTP3_QPACK_TOKEN_STRICT_TRANSPORT_SECURITY, - 4138147361u), - MAKE_STATIC_ENT(57, NGHTTP3_QPACK_TOKEN_STRICT_TRANSPORT_SECURITY, - 4138147361u), - MAKE_STATIC_ENT(58, NGHTTP3_QPACK_TOKEN_STRICT_TRANSPORT_SECURITY, - 4138147361u), - MAKE_STATIC_ENT(93, NGHTTP3_QPACK_TOKEN_TIMING_ALLOW_ORIGIN, 2432297564u), - MAKE_STATIC_ENT(94, NGHTTP3_QPACK_TOKEN_UPGRADE_INSECURE_REQUESTS, - 2479169413u), - MAKE_STATIC_ENT(95, NGHTTP3_QPACK_TOKEN_USER_AGENT, 606444526u), - MAKE_STATIC_ENT(59, NGHTTP3_QPACK_TOKEN_VARY, 1085005381u), - MAKE_STATIC_ENT(60, NGHTTP3_QPACK_TOKEN_VARY, 1085005381u), - MAKE_STATIC_ENT(61, NGHTTP3_QPACK_TOKEN_X_CONTENT_TYPE_OPTIONS, - 3644557769u), - MAKE_STATIC_ENT(96, NGHTTP3_QPACK_TOKEN_X_FORWARDED_FOR, 2914187656u), - MAKE_STATIC_ENT(97, NGHTTP3_QPACK_TOKEN_X_FRAME_OPTIONS, 3993834824u), - MAKE_STATIC_ENT(98, NGHTTP3_QPACK_TOKEN_X_FRAME_OPTIONS, 3993834824u), - MAKE_STATIC_ENT(62, NGHTTP3_QPACK_TOKEN_X_XSS_PROTECTION, 2501058888u), -}; - -/* Make scalar initialization form of nghttp3_qpack_static_entry */ -#define MAKE_STATIC_HD(N, V, T) \ - { \ - {NULL, NULL, (uint8_t *)(N), sizeof((N)) - 1, -1}, \ - {NULL, NULL, (uint8_t *)(V), sizeof((V)) - 1, -1}, T \ - } - -static nghttp3_qpack_static_header stable[] = { - MAKE_STATIC_HD(":authority", "", NGHTTP3_QPACK_TOKEN__AUTHORITY), - MAKE_STATIC_HD(":path", "/", NGHTTP3_QPACK_TOKEN__PATH), - MAKE_STATIC_HD("age", "0", NGHTTP3_QPACK_TOKEN_AGE), - MAKE_STATIC_HD("content-disposition", "", - NGHTTP3_QPACK_TOKEN_CONTENT_DISPOSITION), - MAKE_STATIC_HD("content-length", "0", NGHTTP3_QPACK_TOKEN_CONTENT_LENGTH), - MAKE_STATIC_HD("cookie", "", NGHTTP3_QPACK_TOKEN_COOKIE), - MAKE_STATIC_HD("date", "", NGHTTP3_QPACK_TOKEN_DATE), - MAKE_STATIC_HD("etag", "", NGHTTP3_QPACK_TOKEN_ETAG), - MAKE_STATIC_HD("if-modified-since", "", - NGHTTP3_QPACK_TOKEN_IF_MODIFIED_SINCE), - MAKE_STATIC_HD("if-none-match", "", NGHTTP3_QPACK_TOKEN_IF_NONE_MATCH), - MAKE_STATIC_HD("last-modified", "", NGHTTP3_QPACK_TOKEN_LAST_MODIFIED), - MAKE_STATIC_HD("link", "", NGHTTP3_QPACK_TOKEN_LINK), - MAKE_STATIC_HD("location", "", NGHTTP3_QPACK_TOKEN_LOCATION), - MAKE_STATIC_HD("referer", "", NGHTTP3_QPACK_TOKEN_REFERER), - MAKE_STATIC_HD("set-cookie", "", NGHTTP3_QPACK_TOKEN_SET_COOKIE), - MAKE_STATIC_HD(":method", "CONNECT", NGHTTP3_QPACK_TOKEN__METHOD), - MAKE_STATIC_HD(":method", "DELETE", NGHTTP3_QPACK_TOKEN__METHOD), - MAKE_STATIC_HD(":method", "GET", NGHTTP3_QPACK_TOKEN__METHOD), - MAKE_STATIC_HD(":method", "HEAD", NGHTTP3_QPACK_TOKEN__METHOD), - MAKE_STATIC_HD(":method", "OPTIONS", NGHTTP3_QPACK_TOKEN__METHOD), - MAKE_STATIC_HD(":method", "POST", NGHTTP3_QPACK_TOKEN__METHOD), - MAKE_STATIC_HD(":method", "PUT", NGHTTP3_QPACK_TOKEN__METHOD), - MAKE_STATIC_HD(":scheme", "http", NGHTTP3_QPACK_TOKEN__SCHEME), - MAKE_STATIC_HD(":scheme", "https", NGHTTP3_QPACK_TOKEN__SCHEME), - MAKE_STATIC_HD(":status", "103", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD(":status", "200", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD(":status", "304", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD(":status", "404", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD(":status", "503", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD("accept", "*/*", NGHTTP3_QPACK_TOKEN_ACCEPT), - MAKE_STATIC_HD("accept", "application/dns-message", - NGHTTP3_QPACK_TOKEN_ACCEPT), - MAKE_STATIC_HD("accept-encoding", "gzip, deflate, br", - NGHTTP3_QPACK_TOKEN_ACCEPT_ENCODING), - MAKE_STATIC_HD("accept-ranges", "bytes", NGHTTP3_QPACK_TOKEN_ACCEPT_RANGES), - MAKE_STATIC_HD("access-control-allow-headers", "cache-control", - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS), - MAKE_STATIC_HD("access-control-allow-headers", "content-type", - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS), - MAKE_STATIC_HD("access-control-allow-origin", "*", - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_ORIGIN), - MAKE_STATIC_HD("cache-control", "max-age=0", - NGHTTP3_QPACK_TOKEN_CACHE_CONTROL), - MAKE_STATIC_HD("cache-control", "max-age=2592000", - NGHTTP3_QPACK_TOKEN_CACHE_CONTROL), - MAKE_STATIC_HD("cache-control", "max-age=604800", - NGHTTP3_QPACK_TOKEN_CACHE_CONTROL), - MAKE_STATIC_HD("cache-control", "no-cache", - NGHTTP3_QPACK_TOKEN_CACHE_CONTROL), - MAKE_STATIC_HD("cache-control", "no-store", - NGHTTP3_QPACK_TOKEN_CACHE_CONTROL), - MAKE_STATIC_HD("cache-control", "public, max-age=31536000", - NGHTTP3_QPACK_TOKEN_CACHE_CONTROL), - MAKE_STATIC_HD("content-encoding", "br", - NGHTTP3_QPACK_TOKEN_CONTENT_ENCODING), - MAKE_STATIC_HD("content-encoding", "gzip", - NGHTTP3_QPACK_TOKEN_CONTENT_ENCODING), - MAKE_STATIC_HD("content-type", "application/dns-message", - NGHTTP3_QPACK_TOKEN_CONTENT_TYPE), - MAKE_STATIC_HD("content-type", "application/javascript", - NGHTTP3_QPACK_TOKEN_CONTENT_TYPE), - MAKE_STATIC_HD("content-type", "application/json", - NGHTTP3_QPACK_TOKEN_CONTENT_TYPE), - MAKE_STATIC_HD("content-type", "application/x-www-form-urlencoded", - NGHTTP3_QPACK_TOKEN_CONTENT_TYPE), - MAKE_STATIC_HD("content-type", "image/gif", - NGHTTP3_QPACK_TOKEN_CONTENT_TYPE), - MAKE_STATIC_HD("content-type", "image/jpeg", - NGHTTP3_QPACK_TOKEN_CONTENT_TYPE), - MAKE_STATIC_HD("content-type", "image/png", - NGHTTP3_QPACK_TOKEN_CONTENT_TYPE), - MAKE_STATIC_HD("content-type", "text/css", - NGHTTP3_QPACK_TOKEN_CONTENT_TYPE), - MAKE_STATIC_HD("content-type", "text/html; charset=utf-8", - NGHTTP3_QPACK_TOKEN_CONTENT_TYPE), - MAKE_STATIC_HD("content-type", "text/plain", - NGHTTP3_QPACK_TOKEN_CONTENT_TYPE), - MAKE_STATIC_HD("content-type", "text/plain;charset=utf-8", - NGHTTP3_QPACK_TOKEN_CONTENT_TYPE), - MAKE_STATIC_HD("range", "bytes=0-", NGHTTP3_QPACK_TOKEN_RANGE), - MAKE_STATIC_HD("strict-transport-security", "max-age=31536000", - NGHTTP3_QPACK_TOKEN_STRICT_TRANSPORT_SECURITY), - MAKE_STATIC_HD("strict-transport-security", - "max-age=31536000; includesubdomains", - NGHTTP3_QPACK_TOKEN_STRICT_TRANSPORT_SECURITY), - MAKE_STATIC_HD("strict-transport-security", - "max-age=31536000; includesubdomains; preload", - NGHTTP3_QPACK_TOKEN_STRICT_TRANSPORT_SECURITY), - MAKE_STATIC_HD("vary", "accept-encoding", NGHTTP3_QPACK_TOKEN_VARY), - MAKE_STATIC_HD("vary", "origin", NGHTTP3_QPACK_TOKEN_VARY), - MAKE_STATIC_HD("x-content-type-options", "nosniff", - NGHTTP3_QPACK_TOKEN_X_CONTENT_TYPE_OPTIONS), - MAKE_STATIC_HD("x-xss-protection", "1; mode=block", - NGHTTP3_QPACK_TOKEN_X_XSS_PROTECTION), - MAKE_STATIC_HD(":status", "100", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD(":status", "204", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD(":status", "206", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD(":status", "302", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD(":status", "400", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD(":status", "403", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD(":status", "421", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD(":status", "425", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD(":status", "500", NGHTTP3_QPACK_TOKEN__STATUS), - MAKE_STATIC_HD("accept-language", "", NGHTTP3_QPACK_TOKEN_ACCEPT_LANGUAGE), - MAKE_STATIC_HD("access-control-allow-credentials", "FALSE", - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_CREDENTIALS), - MAKE_STATIC_HD("access-control-allow-credentials", "TRUE", - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_CREDENTIALS), - MAKE_STATIC_HD("access-control-allow-headers", "*", - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS), - MAKE_STATIC_HD("access-control-allow-methods", "get", - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_METHODS), - MAKE_STATIC_HD("access-control-allow-methods", "get, post, options", - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_METHODS), - MAKE_STATIC_HD("access-control-allow-methods", "options", - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_METHODS), - MAKE_STATIC_HD("access-control-expose-headers", "content-length", - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_EXPOSE_HEADERS), - MAKE_STATIC_HD("access-control-request-headers", "content-type", - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_REQUEST_HEADERS), - MAKE_STATIC_HD("access-control-request-method", "get", - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_REQUEST_METHOD), - MAKE_STATIC_HD("access-control-request-method", "post", - NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_REQUEST_METHOD), - MAKE_STATIC_HD("alt-svc", "clear", NGHTTP3_QPACK_TOKEN_ALT_SVC), - MAKE_STATIC_HD("authorization", "", NGHTTP3_QPACK_TOKEN_AUTHORIZATION), - MAKE_STATIC_HD("content-security-policy", - "script-src 'none'; object-src 'none'; base-uri 'none'", - NGHTTP3_QPACK_TOKEN_CONTENT_SECURITY_POLICY), - MAKE_STATIC_HD("early-data", "1", NGHTTP3_QPACK_TOKEN_EARLY_DATA), - MAKE_STATIC_HD("expect-ct", "", NGHTTP3_QPACK_TOKEN_EXPECT_CT), - MAKE_STATIC_HD("forwarded", "", NGHTTP3_QPACK_TOKEN_FORWARDED), - MAKE_STATIC_HD("if-range", "", NGHTTP3_QPACK_TOKEN_IF_RANGE), - MAKE_STATIC_HD("origin", "", NGHTTP3_QPACK_TOKEN_ORIGIN), - MAKE_STATIC_HD("purpose", "prefetch", NGHTTP3_QPACK_TOKEN_PURPOSE), - MAKE_STATIC_HD("server", "", NGHTTP3_QPACK_TOKEN_SERVER), - MAKE_STATIC_HD("timing-allow-origin", "*", - NGHTTP3_QPACK_TOKEN_TIMING_ALLOW_ORIGIN), - MAKE_STATIC_HD("upgrade-insecure-requests", "1", - NGHTTP3_QPACK_TOKEN_UPGRADE_INSECURE_REQUESTS), - MAKE_STATIC_HD("user-agent", "", NGHTTP3_QPACK_TOKEN_USER_AGENT), - MAKE_STATIC_HD("x-forwarded-for", "", NGHTTP3_QPACK_TOKEN_X_FORWARDED_FOR), - MAKE_STATIC_HD("x-frame-options", "deny", - NGHTTP3_QPACK_TOKEN_X_FRAME_OPTIONS), - MAKE_STATIC_HD("x-frame-options", "sameorigin", - NGHTTP3_QPACK_TOKEN_X_FRAME_OPTIONS), -}; - -static int memeq(const void *s1, const void *s2, size_t n) { - return n == 0 || memcmp(s1, s2, n) == 0; -} - -/* Generated by genlibtokenlookup.py */ -static int32_t qpack_lookup_token(const uint8_t *name, size_t namelen) { - switch (namelen) { - case 2: - switch (name[1]) { - case 'e': - if (memeq("t", name, 1)) { - return NGHTTP3_QPACK_TOKEN_TE; - } - break; - } - break; - case 3: - switch (name[2]) { - case 'e': - if (memeq("ag", name, 2)) { - return NGHTTP3_QPACK_TOKEN_AGE; - } - break; - } - break; - case 4: - switch (name[3]) { - case 'e': - if (memeq("dat", name, 3)) { - return NGHTTP3_QPACK_TOKEN_DATE; - } - break; - case 'g': - if (memeq("eta", name, 3)) { - return NGHTTP3_QPACK_TOKEN_ETAG; - } - break; - case 'k': - if (memeq("lin", name, 3)) { - return NGHTTP3_QPACK_TOKEN_LINK; - } - break; - case 't': - if (memeq("hos", name, 3)) { - return NGHTTP3_QPACK_TOKEN_HOST; - } - break; - case 'y': - if (memeq("var", name, 3)) { - return NGHTTP3_QPACK_TOKEN_VARY; - } - break; - } - break; - case 5: - switch (name[4]) { - case 'e': - if (memeq("rang", name, 4)) { - return NGHTTP3_QPACK_TOKEN_RANGE; - } - break; - case 'h': - if (memeq(":pat", name, 4)) { - return NGHTTP3_QPACK_TOKEN__PATH; - } - break; - } - break; - case 6: - switch (name[5]) { - case 'e': - if (memeq("cooki", name, 5)) { - return NGHTTP3_QPACK_TOKEN_COOKIE; - } - break; - case 'n': - if (memeq("origi", name, 5)) { - return NGHTTP3_QPACK_TOKEN_ORIGIN; - } - break; - case 'r': - if (memeq("serve", name, 5)) { - return NGHTTP3_QPACK_TOKEN_SERVER; - } - break; - case 't': - if (memeq("accep", name, 5)) { - return NGHTTP3_QPACK_TOKEN_ACCEPT; - } - break; - } - break; - case 7: - switch (name[6]) { - case 'c': - if (memeq("alt-sv", name, 6)) { - return NGHTTP3_QPACK_TOKEN_ALT_SVC; - } - break; - case 'd': - if (memeq(":metho", name, 6)) { - return NGHTTP3_QPACK_TOKEN__METHOD; - } - break; - case 'e': - if (memeq(":schem", name, 6)) { - return NGHTTP3_QPACK_TOKEN__SCHEME; - } - if (memeq("purpos", name, 6)) { - return NGHTTP3_QPACK_TOKEN_PURPOSE; - } - if (memeq("upgrad", name, 6)) { - return NGHTTP3_QPACK_TOKEN_UPGRADE; - } - break; - case 'r': - if (memeq("refere", name, 6)) { - return NGHTTP3_QPACK_TOKEN_REFERER; - } - break; - case 's': - if (memeq(":statu", name, 6)) { - return NGHTTP3_QPACK_TOKEN__STATUS; - } - break; - } - break; - case 8: - switch (name[7]) { - case 'e': - if (memeq("if-rang", name, 7)) { - return NGHTTP3_QPACK_TOKEN_IF_RANGE; - } - break; - case 'n': - if (memeq("locatio", name, 7)) { - return NGHTTP3_QPACK_TOKEN_LOCATION; - } - break; - case 'y': - if (memeq("priorit", name, 7)) { - return NGHTTP3_QPACK_TOKEN_PRIORITY; - } - break; - } - break; - case 9: - switch (name[8]) { - case 'd': - if (memeq("forwarde", name, 8)) { - return NGHTTP3_QPACK_TOKEN_FORWARDED; - } - break; - case 'l': - if (memeq(":protoco", name, 8)) { - return NGHTTP3_QPACK_TOKEN__PROTOCOL; - } - break; - case 't': - if (memeq("expect-c", name, 8)) { - return NGHTTP3_QPACK_TOKEN_EXPECT_CT; - } - break; - } - break; - case 10: - switch (name[9]) { - case 'a': - if (memeq("early-dat", name, 9)) { - return NGHTTP3_QPACK_TOKEN_EARLY_DATA; - } - break; - case 'e': - if (memeq("keep-aliv", name, 9)) { - return NGHTTP3_QPACK_TOKEN_KEEP_ALIVE; - } - if (memeq("set-cooki", name, 9)) { - return NGHTTP3_QPACK_TOKEN_SET_COOKIE; - } - break; - case 'n': - if (memeq("connectio", name, 9)) { - return NGHTTP3_QPACK_TOKEN_CONNECTION; - } - break; - case 't': - if (memeq("user-agen", name, 9)) { - return NGHTTP3_QPACK_TOKEN_USER_AGENT; - } - break; - case 'y': - if (memeq(":authorit", name, 9)) { - return NGHTTP3_QPACK_TOKEN__AUTHORITY; - } - break; - } - break; - case 12: - switch (name[11]) { - case 'e': - if (memeq("content-typ", name, 11)) { - return NGHTTP3_QPACK_TOKEN_CONTENT_TYPE; - } - break; - } - break; - case 13: - switch (name[12]) { - case 'd': - if (memeq("last-modifie", name, 12)) { - return NGHTTP3_QPACK_TOKEN_LAST_MODIFIED; - } - break; - case 'h': - if (memeq("if-none-matc", name, 12)) { - return NGHTTP3_QPACK_TOKEN_IF_NONE_MATCH; - } - break; - case 'l': - if (memeq("cache-contro", name, 12)) { - return NGHTTP3_QPACK_TOKEN_CACHE_CONTROL; - } - break; - case 'n': - if (memeq("authorizatio", name, 12)) { - return NGHTTP3_QPACK_TOKEN_AUTHORIZATION; - } - break; - case 's': - if (memeq("accept-range", name, 12)) { - return NGHTTP3_QPACK_TOKEN_ACCEPT_RANGES; - } - break; - } - break; - case 14: - switch (name[13]) { - case 'h': - if (memeq("content-lengt", name, 13)) { - return NGHTTP3_QPACK_TOKEN_CONTENT_LENGTH; - } - break; - } - break; - case 15: - switch (name[14]) { - case 'e': - if (memeq("accept-languag", name, 14)) { - return NGHTTP3_QPACK_TOKEN_ACCEPT_LANGUAGE; - } - break; - case 'g': - if (memeq("accept-encodin", name, 14)) { - return NGHTTP3_QPACK_TOKEN_ACCEPT_ENCODING; - } - break; - case 'r': - if (memeq("x-forwarded-fo", name, 14)) { - return NGHTTP3_QPACK_TOKEN_X_FORWARDED_FOR; - } - break; - case 's': - if (memeq("x-frame-option", name, 14)) { - return NGHTTP3_QPACK_TOKEN_X_FRAME_OPTIONS; - } - break; - } - break; - case 16: - switch (name[15]) { - case 'g': - if (memeq("content-encodin", name, 15)) { - return NGHTTP3_QPACK_TOKEN_CONTENT_ENCODING; - } - break; - case 'n': - if (memeq("proxy-connectio", name, 15)) { - return NGHTTP3_QPACK_TOKEN_PROXY_CONNECTION; - } - if (memeq("x-xss-protectio", name, 15)) { - return NGHTTP3_QPACK_TOKEN_X_XSS_PROTECTION; - } - break; - } - break; - case 17: - switch (name[16]) { - case 'e': - if (memeq("if-modified-sinc", name, 16)) { - return NGHTTP3_QPACK_TOKEN_IF_MODIFIED_SINCE; - } - break; - case 'g': - if (memeq("transfer-encodin", name, 16)) { - return NGHTTP3_QPACK_TOKEN_TRANSFER_ENCODING; - } - break; - } - break; - case 19: - switch (name[18]) { - case 'n': - if (memeq("content-dispositio", name, 18)) { - return NGHTTP3_QPACK_TOKEN_CONTENT_DISPOSITION; - } - if (memeq("timing-allow-origi", name, 18)) { - return NGHTTP3_QPACK_TOKEN_TIMING_ALLOW_ORIGIN; - } - break; - } - break; - case 22: - switch (name[21]) { - case 's': - if (memeq("x-content-type-option", name, 21)) { - return NGHTTP3_QPACK_TOKEN_X_CONTENT_TYPE_OPTIONS; - } - break; - } - break; - case 23: - switch (name[22]) { - case 'y': - if (memeq("content-security-polic", name, 22)) { - return NGHTTP3_QPACK_TOKEN_CONTENT_SECURITY_POLICY; - } - break; - } - break; - case 25: - switch (name[24]) { - case 's': - if (memeq("upgrade-insecure-request", name, 24)) { - return NGHTTP3_QPACK_TOKEN_UPGRADE_INSECURE_REQUESTS; - } - break; - case 'y': - if (memeq("strict-transport-securit", name, 24)) { - return NGHTTP3_QPACK_TOKEN_STRICT_TRANSPORT_SECURITY; - } - break; - } - break; - case 27: - switch (name[26]) { - case 'n': - if (memeq("access-control-allow-origi", name, 26)) { - return NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_ORIGIN; - } - break; - } - break; - case 28: - switch (name[27]) { - case 's': - if (memeq("access-control-allow-header", name, 27)) { - return NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_HEADERS; - } - if (memeq("access-control-allow-method", name, 27)) { - return NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_METHODS; - } - break; - } - break; - case 29: - switch (name[28]) { - case 'd': - if (memeq("access-control-request-metho", name, 28)) { - return NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_REQUEST_METHOD; - } - break; - case 's': - if (memeq("access-control-expose-header", name, 28)) { - return NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_EXPOSE_HEADERS; - } - break; - } - break; - case 30: - switch (name[29]) { - case 's': - if (memeq("access-control-request-header", name, 29)) { - return NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_REQUEST_HEADERS; - } - break; - } - break; - case 32: - switch (name[31]) { - case 's': - if (memeq("access-control-allow-credential", name, 31)) { - return NGHTTP3_QPACK_TOKEN_ACCESS_CONTROL_ALLOW_CREDENTIALS; - } - break; - } - break; - } - return -1; -} - -static size_t table_space(size_t namelen, size_t valuelen) { - return NGHTTP3_QPACK_ENTRY_OVERHEAD + namelen + valuelen; -} - -static int qpack_nv_name_eq(const nghttp3_qpack_nv *a, const nghttp3_nv *b) { - return a->name->len == b->namelen && - memeq(a->name->base, b->name, b->namelen); -} - -static int qpack_nv_value_eq(const nghttp3_qpack_nv *a, const nghttp3_nv *b) { - return a->value->len == b->valuelen && - memeq(a->value->base, b->value, b->valuelen); -} - -static void qpack_map_init(nghttp3_qpack_map *map) { - memset(map, 0, sizeof(nghttp3_qpack_map)); -} - -static void qpack_map_insert(nghttp3_qpack_map *map, nghttp3_qpack_entry *ent) { - nghttp3_qpack_entry **bucket; - - bucket = &map->table[ent->hash & (NGHTTP3_QPACK_MAP_SIZE - 1)]; - - if (*bucket == NULL) { - *bucket = ent; - return; - } - - /* larger absidx is linked near the root */ - ent->map_next = *bucket; - *bucket = ent; -} - -static void qpack_map_remove(nghttp3_qpack_map *map, nghttp3_qpack_entry *ent) { - nghttp3_qpack_entry **dst; - - dst = &map->table[ent->hash & (NGHTTP3_QPACK_MAP_SIZE - 1)]; - - for (; *dst; dst = &(*dst)->map_next) { - if (*dst != ent) { - continue; - } - - *dst = ent->map_next; - ent->map_next = NULL; - return; - } -} - -/* - * qpack_context_can_reference returns nonzero if dynamic table entry - * at |absidx| can be referenced. In other words, it is within - * ctx->max_dtable_size. - */ -static int qpack_context_can_reference(nghttp3_qpack_context *ctx, - uint64_t absidx) { - nghttp3_qpack_entry *ent = nghttp3_qpack_context_dtable_get(ctx, absidx); - return ctx->dtable_sum - ent->sum <= ctx->max_dtable_size; -} - -/* |*ppb_match| (post-base match), if it is not NULL, is always exact - match. */ -static void encoder_qpack_map_find(nghttp3_qpack_encoder *encoder, - int *exact_match, - nghttp3_qpack_entry **pmatch, - nghttp3_qpack_entry **ppb_match, - const nghttp3_nv *nv, int32_t token, - uint32_t hash, uint64_t krcnt, - int allow_blocking, int name_only) { - nghttp3_qpack_entry *p; - - *exact_match = 0; - *pmatch = NULL; - *ppb_match = NULL; - - for (p = encoder->dtable_map.table[hash & (NGHTTP3_QPACK_MAP_SIZE - 1)]; p; - p = p->map_next) { - if (token != p->nv.token || - (token == -1 && (hash != p->hash || !qpack_nv_name_eq(&p->nv, nv))) || - !qpack_context_can_reference(&encoder->ctx, p->absidx)) { - continue; - } - if (allow_blocking || p->absidx + 1 <= krcnt) { - if (!*pmatch) { - *pmatch = p; - if (name_only) { - return; - } - } - if (qpack_nv_value_eq(&p->nv, nv)) { - *pmatch = p; - *exact_match = 1; - return; - } - } else if (!*ppb_match && qpack_nv_value_eq(&p->nv, nv)) { - *ppb_match = p; - } - } -} - -/* - * qpack_context_init initializes |ctx|. |max_dtable_size| is the - * maximum size of dynamic table. |mem| is a memory allocator. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -static int qpack_context_init(nghttp3_qpack_context *ctx, - size_t max_dtable_size, size_t max_blocked, - const nghttp3_mem *mem) { - int rv; - size_t len = 4096 / NGHTTP3_QPACK_ENTRY_OVERHEAD; - size_t len2; - - for (len2 = 1; len2 < len; len2 <<= 1) - ; - - rv = nghttp3_ringbuf_init(&ctx->dtable, len2, sizeof(nghttp3_qpack_entry *), - mem); - if (rv != 0) { - return rv; - } - - ctx->mem = mem; - ctx->dtable_size = 0; - ctx->dtable_sum = 0; - ctx->hard_max_dtable_size = max_dtable_size; - ctx->max_dtable_size = 0; - ctx->max_blocked = max_blocked; - ctx->next_absidx = 0; - ctx->bad = 0; - - return 0; -} - -static void qpack_context_free(nghttp3_qpack_context *ctx) { - nghttp3_qpack_entry *ent; - size_t i, len = nghttp3_ringbuf_len(&ctx->dtable); - - for (i = 0; i < len; ++i) { - ent = *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&ctx->dtable, i); - nghttp3_qpack_entry_free(ent); - nghttp3_mem_free(ctx->mem, ent); - } - nghttp3_ringbuf_free(&ctx->dtable); -} - -static int ref_min_cnt_less(const nghttp3_pq_entry *lhsx, - const nghttp3_pq_entry *rhsx) { - nghttp3_qpack_header_block_ref *lhs = - nghttp3_struct_of(lhsx, nghttp3_qpack_header_block_ref, min_cnts_pe); - nghttp3_qpack_header_block_ref *rhs = - nghttp3_struct_of(rhsx, nghttp3_qpack_header_block_ref, min_cnts_pe); - - return lhs->min_cnt < rhs->min_cnt; -} - -typedef struct { - uint64_t max_cnt; - uint64_t id; -} nghttp3_blocked_streams_key; - -static int max_cnt_greater(const nghttp3_ksl_key *lhs, - const nghttp3_ksl_key *rhs) { - const nghttp3_blocked_streams_key *a = lhs; - const nghttp3_blocked_streams_key *b = rhs; - return a->max_cnt > b->max_cnt || (a->max_cnt == b->max_cnt && a->id < b->id); -} - -int nghttp3_qpack_encoder_init(nghttp3_qpack_encoder *encoder, - size_t max_dtable_size, size_t max_blocked, - const nghttp3_mem *mem) { - int rv; - - rv = qpack_context_init(&encoder->ctx, max_dtable_size, max_blocked, mem); - if (rv != 0) { - return rv; - } - - rv = nghttp3_map_init(&encoder->streams, mem); - if (rv != 0) { - goto streams_init_fail; - } - - rv = nghttp3_ksl_init(&encoder->blocked_streams, max_cnt_greater, - sizeof(nghttp3_blocked_streams_key), mem); - if (rv != 0) { - goto blocked_streams_init_fail; - } - - qpack_map_init(&encoder->dtable_map); - nghttp3_pq_init(&encoder->min_cnts, ref_min_cnt_less, mem); - - encoder->krcnt = 0; - encoder->state = NGHTTP3_QPACK_DS_STATE_OPCODE; - encoder->opcode = 0; - encoder->min_dtable_update = SIZE_MAX; - encoder->last_max_dtable_update = 0; - encoder->flags = NGHTTP3_QPACK_ENCODER_FLAG_NONE; - - nghttp3_qpack_read_state_reset(&encoder->rstate); - - return 0; - -blocked_streams_init_fail: - nghttp3_map_free(&encoder->streams); -streams_init_fail: - qpack_context_free(&encoder->ctx); - - return rv; -} - -static int map_stream_free(nghttp3_map_entry *entry, void *ptr) { - const nghttp3_mem *mem = ptr; - nghttp3_qpack_stream *stream = - nghttp3_struct_of(entry, nghttp3_qpack_stream, me); - nghttp3_qpack_stream_del(stream, mem); - return 0; -} - -void nghttp3_qpack_encoder_free(nghttp3_qpack_encoder *encoder) { - nghttp3_pq_free(&encoder->min_cnts); - nghttp3_ksl_free(&encoder->blocked_streams); - nghttp3_map_each_free(&encoder->streams, map_stream_free, - (void *)encoder->ctx.mem); - nghttp3_map_free(&encoder->streams); - qpack_context_free(&encoder->ctx); -} - -int nghttp3_qpack_encoder_set_max_dtable_size(nghttp3_qpack_encoder *encoder, - size_t max_dtable_size) { - if (encoder->ctx.hard_max_dtable_size < max_dtable_size) { - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - if (encoder->ctx.max_dtable_size == max_dtable_size) { - return 0; - } - - encoder->flags |= NGHTTP3_QPACK_ENCODER_FLAG_PENDING_SET_DTABLE_CAP; - - if (encoder->min_dtable_update > max_dtable_size) { - encoder->min_dtable_update = max_dtable_size; - encoder->ctx.max_dtable_size = max_dtable_size; - } - encoder->last_max_dtable_update = max_dtable_size; - - return 0; -} - -int nghttp3_qpack_encoder_set_hard_max_dtable_size( - nghttp3_qpack_encoder *encoder, size_t hard_max_dtable_size) { - /* TODO This is not ideal. */ - if (encoder->ctx.hard_max_dtable_size) { - return NGHTTP3_ERR_INVALID_STATE; - } - - encoder->ctx.hard_max_dtable_size = hard_max_dtable_size; - - return 0; -} - -int nghttp3_qpack_encoder_set_max_blocked(nghttp3_qpack_encoder *encoder, - size_t max_blocked) { - /* TODO This is not ideal. */ - if (encoder->ctx.max_blocked) { - return NGHTTP3_ERR_INVALID_STATE; - } - - encoder->ctx.max_blocked = max_blocked; - - return 0; -} - -uint64_t nghttp3_qpack_encoder_get_min_cnt(nghttp3_qpack_encoder *encoder) { - assert(!nghttp3_pq_empty(&encoder->min_cnts)); - - return nghttp3_struct_of(nghttp3_pq_top(&encoder->min_cnts), - nghttp3_qpack_header_block_ref, min_cnts_pe) - ->min_cnt; -} - -void nghttp3_qpack_encoder_shrink_dtable(nghttp3_qpack_encoder *encoder) { - nghttp3_ringbuf *dtable = &encoder->ctx.dtable; - const nghttp3_mem *mem = encoder->ctx.mem; - uint64_t min_cnt = UINT64_MAX; - size_t len; - nghttp3_qpack_entry *ent; - - if (encoder->ctx.dtable_size <= encoder->ctx.max_dtable_size) { - return; - } - - if (!nghttp3_pq_empty(&encoder->min_cnts)) { - min_cnt = nghttp3_qpack_encoder_get_min_cnt(encoder); - } - - for (; encoder->ctx.dtable_size > encoder->ctx.max_dtable_size;) { - len = nghttp3_ringbuf_len(dtable); - ent = *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(dtable, len - 1); - if (ent->absidx + 1 == min_cnt) { - return; - } - - encoder->ctx.dtable_size -= - table_space(ent->nv.name->len, ent->nv.value->len); - - nghttp3_ringbuf_pop_back(dtable); - qpack_map_remove(&encoder->dtable_map, ent); - - nghttp3_qpack_entry_free(ent); - nghttp3_mem_free(mem, ent); - } -} - -/* - * qpack_encoder_add_stream_ref adds another dynamic table reference - * to a stream denoted by |stream_id|. |stream| must be NULL if no - * stream object is not found for the given stream ID. |max_cnt| and - * |min_cnt| is the maximum and minimum insert count it references - * respectively. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -static int qpack_encoder_add_stream_ref(nghttp3_qpack_encoder *encoder, - int64_t stream_id, - nghttp3_qpack_stream *stream, - uint64_t max_cnt, uint64_t min_cnt) { - nghttp3_qpack_header_block_ref *ref; - const nghttp3_mem *mem = encoder->ctx.mem; - uint64_t prev_max_cnt = 0; - int rv; - - if (stream == NULL) { - rv = nghttp3_qpack_stream_new(&stream, stream_id, mem); - if (rv != 0) { - assert(rv == NGHTTP3_ERR_NOMEM); - return rv; - } - rv = nghttp3_map_insert(&encoder->streams, &stream->me); - if (rv != 0) { - assert(rv == NGHTTP3_ERR_NOMEM); - nghttp3_qpack_stream_del(stream, mem); - return rv; - } - } else { - prev_max_cnt = nghttp3_qpack_stream_get_max_cnt(stream); - if (nghttp3_qpack_encoder_stream_is_blocked(encoder, stream) && - max_cnt > prev_max_cnt) { - nghttp3_qpack_encoder_unblock_stream(encoder, stream); - } - } - - rv = nghttp3_qpack_header_block_ref_new(&ref, max_cnt, min_cnt, mem); - if (rv != 0) { - return rv; - } - - rv = nghttp3_qpack_stream_add_ref(stream, ref); - if (rv != 0) { - nghttp3_qpack_header_block_ref_del(ref, mem); - return rv; - } - - if (max_cnt > prev_max_cnt && - nghttp3_qpack_encoder_stream_is_blocked(encoder, stream)) { - rv = nghttp3_qpack_encoder_block_stream(encoder, stream); - if (rv != 0) { - return rv; - } - } - - return nghttp3_pq_push(&encoder->min_cnts, &ref->min_cnts_pe); -} - -static void qpack_encoder_remove_stream(nghttp3_qpack_encoder *encoder, - nghttp3_qpack_stream *stream) { - size_t i, len; - nghttp3_qpack_header_block_ref *ref; - - nghttp3_map_remove(&encoder->streams, stream->me.key); - - len = nghttp3_ringbuf_len(&stream->refs); - for (i = 0; i < len; ++i) { - ref = *(nghttp3_qpack_header_block_ref **)nghttp3_ringbuf_get(&stream->refs, - i); - - assert(ref->min_cnts_pe.index != NGHTTP3_PQ_BAD_INDEX); - - nghttp3_pq_remove(&encoder->min_cnts, &ref->min_cnts_pe); - } -} - -/* - * reserve_buf_internal ensures that |buf| contains at least - * |extra_size| of free space. In other words, if this function - * succeeds, nghttp2_buf_left(buf) >= extra_size holds. |min_size| is - * the minimum size of buffer. The allocated buffer has at least - * |min_size| bytes. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -static int reserve_buf_internal(nghttp3_buf *buf, size_t extra_size, - size_t min_size, const nghttp3_mem *mem) { - size_t left = nghttp3_buf_left(buf); - size_t n = min_size, need; - - if (left >= extra_size) { - return 0; - } - - need = nghttp3_buf_cap(buf) + extra_size - left; - - for (; n < need; n *= 2) - ; - - return nghttp3_buf_reserve(buf, n, mem); -} - -static int reserve_buf_small(nghttp3_buf *buf, size_t extra_size, - const nghttp3_mem *mem) { - return reserve_buf_internal(buf, extra_size, 32, mem); -} - -static int reserve_buf(nghttp3_buf *buf, size_t extra_size, - const nghttp3_mem *mem) { - return reserve_buf_internal(buf, extra_size, 32, mem); -} - -int nghttp3_qpack_encoder_encode(nghttp3_qpack_encoder *encoder, - nghttp3_buf *pbuf, nghttp3_buf *rbuf, - nghttp3_buf *ebuf, int64_t stream_id, - const nghttp3_nv *nva, size_t nvlen) { - size_t i; - uint64_t max_cnt = 0, min_cnt = UINT64_MAX; - uint64_t base; - int rv = 0; - int allow_blocking; - int blocked_stream; - nghttp3_qpack_stream *stream; - - if (encoder->ctx.bad) { - return NGHTTP3_ERR_QPACK_FATAL; - } - - rv = nghttp3_qpack_encoder_process_dtable_update(encoder, ebuf); - if (rv != 0) { - goto fail; - } - - base = encoder->ctx.next_absidx; - - stream = nghttp3_qpack_encoder_find_stream(encoder, stream_id); - blocked_stream = - stream && nghttp3_qpack_encoder_stream_is_blocked(encoder, stream); - allow_blocking = - blocked_stream || - encoder->ctx.max_blocked > nghttp3_ksl_len(&encoder->blocked_streams); - - DEBUGF("qpack::encode: stream %ld blocked=%d allow_blocking=%d\n", stream_id, - blocked_stream, allow_blocking); - - for (i = 0; i < nvlen; ++i) { - rv = nghttp3_qpack_encoder_encode_nv(encoder, &max_cnt, &min_cnt, rbuf, - ebuf, &nva[i], base, allow_blocking); - if (rv != 0) { - goto fail; - } - } - - nghttp3_qpack_encoder_write_field_section_prefix(encoder, pbuf, max_cnt, - base); - - /* TODO If max_cnt == 0, no reference is made to dtable. */ - if (!max_cnt) { - return 0; - } - - rv = qpack_encoder_add_stream_ref(encoder, stream_id, stream, max_cnt, - min_cnt); - if (rv != 0) { - goto fail; - } - - return 0; - -fail: - encoder->ctx.bad = 1; - return rv; -} - -/* - * qpack_write_number writes variable integer to |rbuf|. |num| is an - * integer to write. |prefix| is a prefix of variable integer - * encoding. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -static int qpack_write_number(nghttp3_buf *rbuf, uint8_t fb, uint64_t num, - size_t prefix, const nghttp3_mem *mem) { - int rv; - size_t len = nghttp3_qpack_put_varint_len(num, prefix); - uint8_t *p; - - rv = reserve_buf(rbuf, len, mem); - if (rv != 0) { - return rv; - } - - p = rbuf->last; - - *p = fb; - p = nghttp3_qpack_put_varint(p, num, prefix); - - assert((size_t)(p - rbuf->last) == len); - - rbuf->last = p; - - return 0; -} - -int nghttp3_qpack_encoder_process_dtable_update(nghttp3_qpack_encoder *encoder, - nghttp3_buf *ebuf) { - int rv; - - nghttp3_qpack_encoder_shrink_dtable(encoder); - - if (encoder->ctx.max_dtable_size < encoder->ctx.dtable_size || - !(encoder->flags & NGHTTP3_QPACK_ENCODER_FLAG_PENDING_SET_DTABLE_CAP)) { - return 0; - } - - if (encoder->min_dtable_update < encoder->last_max_dtable_update) { - rv = nghttp3_qpack_encoder_write_set_dtable_cap(encoder, ebuf, - encoder->min_dtable_update); - if (rv != 0) { - return rv; - } - } - - rv = nghttp3_qpack_encoder_write_set_dtable_cap( - encoder, ebuf, encoder->last_max_dtable_update); - if (rv != 0) { - return rv; - } - - encoder->flags &= (uint8_t)~NGHTTP3_QPACK_ENCODER_FLAG_PENDING_SET_DTABLE_CAP; - encoder->min_dtable_update = SIZE_MAX; - encoder->ctx.max_dtable_size = encoder->last_max_dtable_update; - - return 0; -} - -int nghttp3_qpack_encoder_write_set_dtable_cap(nghttp3_qpack_encoder *encoder, - nghttp3_buf *ebuf, size_t cap) { - DEBUGF("qpack::encode: Set Dynamic Table Capacity capacity=%zu\n", cap); - return qpack_write_number(ebuf, 0x20, cap, 5, encoder->ctx.mem); -} - -nghttp3_qpack_stream * -nghttp3_qpack_encoder_find_stream(nghttp3_qpack_encoder *encoder, - int64_t stream_id) { - nghttp3_map_entry *me = - nghttp3_map_find(&encoder->streams, (uint64_t)stream_id); - return me == NULL ? NULL : nghttp3_struct_of(me, nghttp3_qpack_stream, me); -} - -int nghttp3_qpack_encoder_stream_is_blocked(nghttp3_qpack_encoder *encoder, - nghttp3_qpack_stream *stream) { - return stream && encoder->krcnt < nghttp3_qpack_stream_get_max_cnt(stream); -} - -/* - * qpack_encoder_decide_indexing_mode determines and returns indexing - * mode for header field |nv|. |token| is a token of header field - * name. - */ -static nghttp3_qpack_indexing_mode -qpack_encoder_decide_indexing_mode(nghttp3_qpack_encoder *encoder, - const nghttp3_nv *nv, int32_t token) { - if (nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) { - return NGHTTP3_QPACK_INDEXING_MODE_NEVER; - } - - switch (token) { - case NGHTTP3_QPACK_TOKEN_AUTHORIZATION: - return NGHTTP3_QPACK_INDEXING_MODE_NEVER; - case NGHTTP3_QPACK_TOKEN_COOKIE: - if (nv->valuelen < 20) { - return NGHTTP3_QPACK_INDEXING_MODE_NEVER; - } - break; - case -1: - case NGHTTP3_QPACK_TOKEN__PATH: - case NGHTTP3_QPACK_TOKEN_AGE: - case NGHTTP3_QPACK_TOKEN_CONTENT_LENGTH: - case NGHTTP3_QPACK_TOKEN_ETAG: - case NGHTTP3_QPACK_TOKEN_IF_MODIFIED_SINCE: - case NGHTTP3_QPACK_TOKEN_IF_NONE_MATCH: - case NGHTTP3_QPACK_TOKEN_LOCATION: - case NGHTTP3_QPACK_TOKEN_SET_COOKIE: - return NGHTTP3_QPACK_INDEXING_MODE_LITERAL; - case NGHTTP3_QPACK_TOKEN_HOST: - case NGHTTP3_QPACK_TOKEN_TE: - case NGHTTP3_QPACK_TOKEN__PROTOCOL: - case NGHTTP3_QPACK_TOKEN_PRIORITY: - break; - default: - if (token >= 1000) { - return NGHTTP3_QPACK_INDEXING_MODE_LITERAL; - } - } - - if (table_space(nv->namelen, nv->valuelen) > - encoder->ctx.max_dtable_size * 3 / 4) { - return NGHTTP3_QPACK_INDEXING_MODE_LITERAL; - } - - return NGHTTP3_QPACK_INDEXING_MODE_STORE; -} - -/* - * qpack_encoder_can_index returns nonzero if an entry which occupies - * |need| bytes can be inserted into dynamic table. |min_cnt| is the - * minimum insert count which blocked stream requires. - */ -static int qpack_encoder_can_index(nghttp3_qpack_encoder *encoder, size_t need, - uint64_t min_cnt) { - size_t avail = 0; - size_t len; - uint64_t gmin_cnt; - nghttp3_qpack_entry *min_ent, *last_ent; - nghttp3_ringbuf *dtable = &encoder->ctx.dtable; - - if (encoder->ctx.max_dtable_size > encoder->ctx.dtable_size) { - avail = encoder->ctx.max_dtable_size - encoder->ctx.dtable_size; - if (need <= avail) { - return 1; - } - } - - if (!nghttp3_pq_empty(&encoder->min_cnts)) { - gmin_cnt = nghttp3_qpack_encoder_get_min_cnt(encoder); - min_cnt = nghttp3_min(min_cnt, gmin_cnt); - } - - if (min_cnt == UINT64_MAX) { - return encoder->ctx.max_dtable_size >= need; - } - - min_ent = nghttp3_qpack_context_dtable_get(&encoder->ctx, min_cnt - 1); - - len = nghttp3_ringbuf_len(&encoder->ctx.dtable); - assert(len); - last_ent = *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(dtable, len - 1); - - if (min_ent == last_ent) { - return 0; - } - - return avail + min_ent->sum - last_ent->sum >= need; -} - -/* - * qpack_encoder_can_index_nv returns nonzero if header field |nv| can - * be inserted into dynamic table. |min_cnt| is the minimum insert - * count which blocked stream requires. - */ -static int qpack_encoder_can_index_nv(nghttp3_qpack_encoder *encoder, - const nghttp3_nv *nv, uint64_t min_cnt) { - return qpack_encoder_can_index( - encoder, table_space(nv->namelen, nv->valuelen), min_cnt); -} - -/* - * qpack_encoder_can_index_duplicate returns nonzero if an entry at - * |absidx| in dynamic table can be inserted to dynamic table as - * duplicate. |min_cnt| is the minimum insert count which blocked - * stream requires. - */ -static int qpack_encoder_can_index_duplicate(nghttp3_qpack_encoder *encoder, - uint64_t absidx, - uint64_t min_cnt) { - nghttp3_qpack_entry *ent = - nghttp3_qpack_context_dtable_get(&encoder->ctx, absidx); - - return qpack_encoder_can_index( - encoder, table_space(ent->nv.name->len, ent->nv.value->len), min_cnt); -} - -/* - * qpack_context_check_draining returns nonzero if an entry at - * |absidx| in dynamic table is one of draining entries. - */ -static int qpack_context_check_draining(nghttp3_qpack_context *ctx, - uint64_t absidx) { - const size_t safe = - ctx->max_dtable_size - nghttp3_min(512, ctx->max_dtable_size * 1 / 8); - nghttp3_qpack_entry *ent = nghttp3_qpack_context_dtable_get(ctx, absidx); - - return ctx->dtable_sum - ent->sum > safe; -} - -int nghttp3_qpack_encoder_encode_nv(nghttp3_qpack_encoder *encoder, - uint64_t *pmax_cnt, uint64_t *pmin_cnt, - nghttp3_buf *rbuf, nghttp3_buf *ebuf, - const nghttp3_nv *nv, uint64_t base, - int allow_blocking) { - uint32_t hash = 0; - int32_t token; - nghttp3_qpack_indexing_mode indexing_mode; - nghttp3_qpack_lookup_result sres = {-1, 0, -1}, dres = {-1, 0, -1}; - nghttp3_qpack_entry *new_ent = NULL; - int static_entry; - int just_index = 0; - int rv; - - token = qpack_lookup_token(nv->name, nv->namelen); - static_entry = token != -1 && (size_t)token < nghttp3_arraylen(token_stable); - if (static_entry) { - hash = token_stable[token].hash; - } else { - switch (token) { - case NGHTTP3_QPACK_TOKEN_HOST: - hash = 2952701295u; - break; - case NGHTTP3_QPACK_TOKEN_TE: - hash = 1011170994u; - break; - case NGHTTP3_QPACK_TOKEN__PROTOCOL: - hash = 1128642621u; - break; - case NGHTTP3_QPACK_TOKEN_PRIORITY: - hash = 2498028297u; - break; - } - } - - indexing_mode = qpack_encoder_decide_indexing_mode(encoder, nv, token); - - if (static_entry) { - sres = nghttp3_qpack_lookup_stable(nv, token, indexing_mode); - if (sres.index != -1 && sres.name_value_match) { - return nghttp3_qpack_encoder_write_static_indexed(encoder, rbuf, - (size_t)sres.index); - } - } - - if (hash && - nghttp3_map_size(&encoder->streams) < NGHTTP3_QPACK_MAX_QPACK_STREAMS) { - dres = nghttp3_qpack_encoder_lookup_dtable(encoder, nv, token, hash, - indexing_mode, encoder->krcnt, - allow_blocking); - just_index = indexing_mode == NGHTTP3_QPACK_INDEXING_MODE_STORE && - dres.pb_index == -1; - } - - if (dres.index != -1 && dres.name_value_match) { - if (allow_blocking && - qpack_context_check_draining(&encoder->ctx, (size_t)dres.index) && - qpack_encoder_can_index_duplicate(encoder, (size_t)dres.index, - *pmin_cnt)) { - rv = nghttp3_qpack_encoder_write_duplicate_insert(encoder, ebuf, - (size_t)dres.index); - if (rv != 0) { - return rv; - } - rv = nghttp3_qpack_encoder_dtable_duplicate_add(encoder, - (size_t)dres.index); - if (rv != 0) { - return rv; - } - - new_ent = nghttp3_qpack_context_dtable_top(&encoder->ctx); - dres.index = (nghttp3_ssize)new_ent->absidx; - } - *pmax_cnt = nghttp3_max(*pmax_cnt, (size_t)(dres.index + 1)); - *pmin_cnt = nghttp3_min(*pmin_cnt, (size_t)(dres.index + 1)); - - return nghttp3_qpack_encoder_write_dynamic_indexed( - encoder, rbuf, (size_t)dres.index, base); - } - - if (sres.index != -1) { - if (just_index && qpack_encoder_can_index_nv(encoder, nv, *pmin_cnt)) { - rv = nghttp3_qpack_encoder_write_static_insert(encoder, ebuf, - (size_t)sres.index, nv); - if (rv != 0) { - return rv; - } - rv = nghttp3_qpack_encoder_dtable_static_add(encoder, (size_t)sres.index, - nv, hash); - if (rv != 0) { - return rv; - } - if (allow_blocking) { - new_ent = nghttp3_qpack_context_dtable_top(&encoder->ctx); - *pmax_cnt = nghttp3_max(*pmax_cnt, new_ent->absidx + 1); - *pmin_cnt = nghttp3_min(*pmin_cnt, new_ent->absidx + 1); - - return nghttp3_qpack_encoder_write_dynamic_indexed( - encoder, rbuf, new_ent->absidx, base); - } - } - - return nghttp3_qpack_encoder_write_static_indexed_name( - encoder, rbuf, (size_t)sres.index, nv); - } - - if (dres.index != -1) { - if (just_index && - qpack_encoder_can_index_nv( - encoder, nv, - allow_blocking ? *pmin_cnt - : nghttp3_min((size_t)dres.index + 1, *pmin_cnt))) { - rv = nghttp3_qpack_encoder_write_dynamic_insert(encoder, ebuf, - (size_t)dres.index, nv); - if (rv != 0) { - return rv; - } - - if (!allow_blocking) { - *pmin_cnt = nghttp3_min(*pmin_cnt, (size_t)dres.index + 1); - } - - rv = nghttp3_qpack_encoder_dtable_dynamic_add(encoder, (size_t)dres.index, - nv, hash); - if (rv != 0) { - return rv; - } - - if (allow_blocking) { - new_ent = nghttp3_qpack_context_dtable_top(&encoder->ctx); - *pmax_cnt = nghttp3_max(*pmax_cnt, new_ent->absidx + 1); - *pmin_cnt = nghttp3_min(*pmin_cnt, new_ent->absidx + 1); - - return nghttp3_qpack_encoder_write_dynamic_indexed( - encoder, rbuf, new_ent->absidx, base); - } - } - - *pmax_cnt = nghttp3_max(*pmax_cnt, (size_t)(dres.index + 1)); - *pmin_cnt = nghttp3_min(*pmin_cnt, (size_t)(dres.index + 1)); - - return nghttp3_qpack_encoder_write_dynamic_indexed_name( - encoder, rbuf, (size_t)dres.index, base, nv); - } - - if (just_index && qpack_encoder_can_index_nv(encoder, nv, *pmin_cnt)) { - rv = nghttp3_qpack_encoder_dtable_literal_add(encoder, nv, token, hash); - if (rv != 0) { - return rv; - } - rv = nghttp3_qpack_encoder_write_literal_insert(encoder, ebuf, nv); - if (rv != 0) { - return rv; - } - if (allow_blocking) { - new_ent = nghttp3_qpack_context_dtable_top(&encoder->ctx); - *pmax_cnt = nghttp3_max(*pmax_cnt, new_ent->absidx + 1); - *pmin_cnt = nghttp3_min(*pmin_cnt, new_ent->absidx + 1); - - return nghttp3_qpack_encoder_write_dynamic_indexed(encoder, rbuf, - new_ent->absidx, base); - } - } - - return nghttp3_qpack_encoder_write_literal(encoder, rbuf, nv); -} - -nghttp3_qpack_lookup_result -nghttp3_qpack_lookup_stable(const nghttp3_nv *nv, int32_t token, - nghttp3_qpack_indexing_mode indexing_mode) { - nghttp3_qpack_lookup_result res = {(nghttp3_ssize)token_stable[token].absidx, - 0, -1}; - nghttp3_qpack_static_entry *ent; - nghttp3_qpack_static_header *hdr; - size_t i; - - assert(token >= 0); - - if (indexing_mode == NGHTTP3_QPACK_INDEXING_MODE_NEVER) { - return res; - } - - for (i = (size_t)token; - i < nghttp3_arraylen(token_stable) && token_stable[i].token == token; - ++i) { - ent = &token_stable[i]; - hdr = &stable[ent->absidx]; - if (hdr->value.len == nv->valuelen && - memeq(hdr->value.base, nv->value, nv->valuelen)) { - res.index = (nghttp3_ssize)ent->absidx; - res.name_value_match = 1; - return res; - } - } - return res; -} - -nghttp3_qpack_lookup_result nghttp3_qpack_encoder_lookup_dtable( - nghttp3_qpack_encoder *encoder, const nghttp3_nv *nv, int32_t token, - uint32_t hash, nghttp3_qpack_indexing_mode indexing_mode, uint64_t krcnt, - int allow_blocking) { - nghttp3_qpack_lookup_result res = {-1, 0, -1}; - int exact_match = 0; - nghttp3_qpack_entry *match, *pb_match; - - encoder_qpack_map_find(encoder, &exact_match, &match, &pb_match, nv, token, - hash, krcnt, allow_blocking, - indexing_mode == NGHTTP3_QPACK_INDEXING_MODE_NEVER); - if (match) { - res.index = (nghttp3_ssize)match->absidx; - res.name_value_match = exact_match; - } - if (pb_match) { - res.pb_index = (nghttp3_ssize)pb_match->absidx; - } - - return res; -} - -int nghttp3_qpack_header_block_ref_new(nghttp3_qpack_header_block_ref **pref, - uint64_t max_cnt, uint64_t min_cnt, - const nghttp3_mem *mem) { - nghttp3_qpack_header_block_ref *ref = - nghttp3_mem_malloc(mem, sizeof(nghttp3_qpack_header_block_ref)); - - if (ref == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - ref->max_cnts_pe.index = NGHTTP3_PQ_BAD_INDEX; - ref->min_cnts_pe.index = NGHTTP3_PQ_BAD_INDEX; - ref->max_cnt = max_cnt; - ref->min_cnt = min_cnt; - - *pref = ref; - - return 0; -} - -void nghttp3_qpack_header_block_ref_del(nghttp3_qpack_header_block_ref *ref, - const nghttp3_mem *mem) { - nghttp3_mem_free(mem, ref); -} - -static int ref_max_cnt_greater(const nghttp3_pq_entry *lhsx, - const nghttp3_pq_entry *rhsx) { - const nghttp3_qpack_header_block_ref *lhs = - nghttp3_struct_of(lhsx, nghttp3_qpack_header_block_ref, max_cnts_pe); - const nghttp3_qpack_header_block_ref *rhs = - nghttp3_struct_of(rhsx, nghttp3_qpack_header_block_ref, max_cnts_pe); - - return lhs->max_cnt > rhs->max_cnt; -} - -int nghttp3_qpack_stream_new(nghttp3_qpack_stream **pstream, int64_t stream_id, - const nghttp3_mem *mem) { - int rv; - nghttp3_qpack_stream *stream; - - stream = nghttp3_mem_malloc(mem, sizeof(nghttp3_qpack_stream)); - if (stream == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - rv = nghttp3_ringbuf_init(&stream->refs, 4, - sizeof(nghttp3_qpack_header_block_ref *), mem); - if (rv != 0) { - nghttp3_mem_free(mem, stream); - return rv; - } - - nghttp3_pq_init(&stream->max_cnts, ref_max_cnt_greater, mem); - - stream->me.next = NULL; - stream->me.key = (uint64_t)stream_id; - - *pstream = stream; - - return 0; -} - -void nghttp3_qpack_stream_del(nghttp3_qpack_stream *stream, - const nghttp3_mem *mem) { - nghttp3_qpack_header_block_ref *ref; - size_t i, len; - - if (stream == NULL) { - return; - } - - nghttp3_pq_free(&stream->max_cnts); - - len = nghttp3_ringbuf_len(&stream->refs); - for (i = 0; i < len; ++i) { - ref = *(nghttp3_qpack_header_block_ref **)nghttp3_ringbuf_get(&stream->refs, - i); - nghttp3_qpack_header_block_ref_del(ref, mem); - } - - nghttp3_ringbuf_free(&stream->refs); - - nghttp3_mem_free(mem, stream); -} - -uint64_t nghttp3_qpack_stream_get_max_cnt(const nghttp3_qpack_stream *stream) { - nghttp3_qpack_header_block_ref *ref; - - if (nghttp3_pq_empty(&stream->max_cnts)) { - return 0; - } - - ref = nghttp3_struct_of(nghttp3_pq_top(&stream->max_cnts), - nghttp3_qpack_header_block_ref, max_cnts_pe); - return ref->max_cnt; -} - -int nghttp3_qpack_stream_add_ref(nghttp3_qpack_stream *stream, - nghttp3_qpack_header_block_ref *ref) { - nghttp3_qpack_header_block_ref **dest; - int rv; - - if (nghttp3_ringbuf_full(&stream->refs)) { - rv = nghttp3_ringbuf_reserve(&stream->refs, - nghttp3_ringbuf_len(&stream->refs) * 2); - if (rv != 0) { - return rv; - } - } - - dest = nghttp3_ringbuf_push_back(&stream->refs); - *dest = ref; - - return nghttp3_pq_push(&stream->max_cnts, &ref->max_cnts_pe); -} - -void nghttp3_qpack_stream_pop_ref(nghttp3_qpack_stream *stream) { - nghttp3_qpack_header_block_ref *ref; - - assert(nghttp3_ringbuf_len(&stream->refs)); - - ref = - *(nghttp3_qpack_header_block_ref **)nghttp3_ringbuf_get(&stream->refs, 0); - - assert(ref->max_cnts_pe.index != NGHTTP3_PQ_BAD_INDEX); - - nghttp3_pq_remove(&stream->max_cnts, &ref->max_cnts_pe); - - nghttp3_ringbuf_pop_front(&stream->refs); -} - -int nghttp3_qpack_encoder_write_static_indexed(nghttp3_qpack_encoder *encoder, - nghttp3_buf *rbuf, - uint64_t absidx) { - DEBUGF("qpack::encode: Indexed Field Line (static) absidx=%" PRIu64 "\n", - absidx); - return qpack_write_number(rbuf, 0xc0, absidx, 6, encoder->ctx.mem); -} - -int nghttp3_qpack_encoder_write_dynamic_indexed(nghttp3_qpack_encoder *encoder, - nghttp3_buf *rbuf, - uint64_t absidx, - uint64_t base) { - DEBUGF("qpack::encode: Indexed Field Line (dynamic) absidx=%" PRIu64 - " base=%" PRIu64 "\n", - absidx, base); - - if (absidx < base) { - return qpack_write_number(rbuf, 0x80, base - absidx - 1, 6, - encoder->ctx.mem); - } - - return qpack_write_number(rbuf, 0x10, absidx - base, 4, encoder->ctx.mem); -} - -/* - * qpack_encoder_write_indexed_name writes generic indexed name. |fb| - * is the first byte. |nameidx| is an index of referenced name. - * |prefix| is a prefix of variable integer encoding. |nv| is a - * header field to encode. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -static int qpack_encoder_write_indexed_name(nghttp3_qpack_encoder *encoder, - nghttp3_buf *buf, uint8_t fb, - uint64_t nameidx, size_t prefix, - const nghttp3_nv *nv) { - int rv; - size_t len = nghttp3_qpack_put_varint_len(nameidx, prefix); - uint8_t *p; - size_t hlen; - int h = 0; - - hlen = nghttp3_qpack_huffman_encode_count(nv->value, nv->valuelen); - if (hlen < nv->valuelen) { - h = 1; - len += nghttp3_qpack_put_varint_len(hlen, 7) + hlen; - } else { - len += nghttp3_qpack_put_varint_len(nv->valuelen, 7) + nv->valuelen; - } - - rv = reserve_buf(buf, len, encoder->ctx.mem); - if (rv != 0) { - return rv; - } - - p = buf->last; - - *p = fb; - p = nghttp3_qpack_put_varint(p, nameidx, prefix); - - if (h) { - *p = 0x80; - p = nghttp3_qpack_put_varint(p, hlen, 7); - p = nghttp3_qpack_huffman_encode(p, nv->value, nv->valuelen); - } else { - *p = 0; - p = nghttp3_qpack_put_varint(p, nv->valuelen, 7); - if (nv->valuelen) { - p = nghttp3_cpymem(p, nv->value, nv->valuelen); - } - } - - assert((size_t)(p - buf->last) == len); - - buf->last = p; - - return 0; -} - -int nghttp3_qpack_encoder_write_static_indexed_name( - nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx, - const nghttp3_nv *nv) { - uint8_t fb = - (uint8_t)(0x50 | ((nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) ? 0x20 : 0)); - - DEBUGF("qpack::encode: Literal Field Line With Name Reference (static) " - "absidx=%" PRIu64 " never=%d\n", - absidx, (nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) != 0); - return qpack_encoder_write_indexed_name(encoder, rbuf, fb, absidx, 4, nv); -} - -int nghttp3_qpack_encoder_write_dynamic_indexed_name( - nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx, - uint64_t base, const nghttp3_nv *nv) { - uint8_t fb; - - DEBUGF("qpack::encode: Literal Field Line With Name Reference (dynamic) " - "absidx=%" PRIu64 " base=%" PRIu64 " never=%d\n", - absidx, base, (nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) != 0); - - if (absidx < base) { - fb = (uint8_t)(0x40 | - ((nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) ? 0x20 : 0)); - return qpack_encoder_write_indexed_name(encoder, rbuf, fb, - base - absidx - 1, 4, nv); - } - - fb = (nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) ? 0x08 : 0; - return qpack_encoder_write_indexed_name(encoder, rbuf, fb, absidx - base, 3, - nv); -} - -/* - * qpack_encoder_write_literal writes generic literal header field - * representation. |fb| is a first byte. |prefix| is a prefix of - * variable integer encoding for name length. |nv| is a header field - * to encode. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -static int qpack_encoder_write_literal(nghttp3_qpack_encoder *encoder, - nghttp3_buf *buf, uint8_t fb, - size_t prefix, const nghttp3_nv *nv) { - int rv; - size_t len; - uint8_t *p; - size_t nhlen, vhlen; - int nh = 0, vh = 0; - - nhlen = nghttp3_qpack_huffman_encode_count(nv->name, nv->namelen); - if (nhlen < nv->namelen) { - nh = 1; - len = nghttp3_qpack_put_varint_len(nhlen, prefix) + nhlen; - } else { - len = nghttp3_qpack_put_varint_len(nv->namelen, prefix) + nv->namelen; - } - - vhlen = nghttp3_qpack_huffman_encode_count(nv->value, nv->valuelen); - if (vhlen < nv->valuelen) { - vh = 1; - len += nghttp3_qpack_put_varint_len(vhlen, 7) + vhlen; - } else { - len += nghttp3_qpack_put_varint_len(nv->valuelen, 7) + nv->valuelen; - } - - rv = reserve_buf(buf, len, encoder->ctx.mem); - if (rv != 0) { - return rv; - } - - p = buf->last; - - *p = fb; - if (nh) { - *p |= (uint8_t)(1 << prefix); - p = nghttp3_qpack_put_varint(p, nhlen, prefix); - p = nghttp3_qpack_huffman_encode(p, nv->name, nv->namelen); - } else { - p = nghttp3_qpack_put_varint(p, nv->namelen, prefix); - if (nv->namelen) { - p = nghttp3_cpymem(p, nv->name, nv->namelen); - } - } - - *p = 0; - - if (vh) { - *p |= 0x80; - p = nghttp3_qpack_put_varint(p, vhlen, 7); - p = nghttp3_qpack_huffman_encode(p, nv->value, nv->valuelen); - } else { - p = nghttp3_qpack_put_varint(p, nv->valuelen, 7); - if (nv->valuelen) { - p = nghttp3_cpymem(p, nv->value, nv->valuelen); - } - } - - assert((size_t)(p - buf->last) == len); - - buf->last = p; - - return 0; -} - -int nghttp3_qpack_encoder_write_literal(nghttp3_qpack_encoder *encoder, - nghttp3_buf *rbuf, - const nghttp3_nv *nv) { - uint8_t fb = - (uint8_t)(0x20 | ((nv->flags & NGHTTP3_NV_FLAG_NEVER_INDEX) ? 0x10 : 0)); - - DEBUGF("qpack::encode: Literal Field Line Without Name Reference\n"); - return qpack_encoder_write_literal(encoder, rbuf, fb, 3, nv); -} - -int nghttp3_qpack_encoder_write_static_insert(nghttp3_qpack_encoder *encoder, - nghttp3_buf *ebuf, - uint64_t absidx, - const nghttp3_nv *nv) { - DEBUGF("qpack::encode: Insert With Name Reference (static) absidx=%" PRIu64 - "\n", - absidx); - return qpack_encoder_write_indexed_name(encoder, ebuf, 0xc0, absidx, 6, nv); -} - -int nghttp3_qpack_encoder_write_dynamic_insert(nghttp3_qpack_encoder *encoder, - nghttp3_buf *ebuf, - uint64_t absidx, - const nghttp3_nv *nv) { - DEBUGF("qpack::encode: Insert With Name Reference (dynamic) absidx=%" PRIu64 - "\n", - absidx); - return qpack_encoder_write_indexed_name( - encoder, ebuf, 0x80, encoder->ctx.next_absidx - absidx - 1, 6, nv); -} - -int nghttp3_qpack_encoder_write_duplicate_insert(nghttp3_qpack_encoder *encoder, - nghttp3_buf *ebuf, - uint64_t absidx) { - uint64_t idx = encoder->ctx.next_absidx - absidx - 1; - size_t len = nghttp3_qpack_put_varint_len(idx, 5); - uint8_t *p; - int rv; - - DEBUGF("qpack::encode: Insert duplicate absidx=%" PRIu64 "\n", absidx); - - rv = reserve_buf(ebuf, len, encoder->ctx.mem); - if (rv != 0) { - return rv; - } - - p = ebuf->last; - - *p = 0; - p = nghttp3_qpack_put_varint(p, idx, 5); - - assert((size_t)(p - ebuf->last) == len); - - ebuf->last = p; - - return 0; -} - -int nghttp3_qpack_encoder_write_literal_insert(nghttp3_qpack_encoder *encoder, - nghttp3_buf *ebuf, - const nghttp3_nv *nv) { - DEBUGF("qpack::encode: Insert Without Name Reference\n"); - return qpack_encoder_write_literal(encoder, ebuf, 0x40, 5, nv); -} - -int nghttp3_qpack_context_dtable_add(nghttp3_qpack_context *ctx, - nghttp3_qpack_nv *qnv, - nghttp3_qpack_map *dtable_map, - uint32_t hash) { - nghttp3_qpack_entry *new_ent, **p, *ent; - const nghttp3_mem *mem = ctx->mem; - size_t space; - size_t i; - int rv; - - space = table_space(qnv->name->len, qnv->value->len); - - assert(space <= ctx->max_dtable_size); - - while (ctx->dtable_size + space > ctx->max_dtable_size) { - i = nghttp3_ringbuf_len(&ctx->dtable); - assert(i); - ent = *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&ctx->dtable, i - 1); - - ctx->dtable_size -= table_space(ent->nv.name->len, ent->nv.value->len); - - nghttp3_ringbuf_pop_back(&ctx->dtable); - if (dtable_map) { - qpack_map_remove(dtable_map, ent); - } - - nghttp3_qpack_entry_free(ent); - nghttp3_mem_free(mem, ent); - } - - new_ent = nghttp3_mem_malloc(mem, sizeof(nghttp3_qpack_entry)); - if (new_ent == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - nghttp3_qpack_entry_init(new_ent, qnv, ctx->dtable_sum, ctx->next_absidx++, - hash); - - if (nghttp3_ringbuf_full(&ctx->dtable)) { - rv = nghttp3_ringbuf_reserve(&ctx->dtable, - nghttp3_ringbuf_len(&ctx->dtable) * 2); - if (rv != 0) { - goto fail; - } - } - - p = nghttp3_ringbuf_push_front(&ctx->dtable); - *p = new_ent; - - if (dtable_map) { - qpack_map_insert(dtable_map, new_ent); - } - - ctx->dtable_size += space; - ctx->dtable_sum += space; - - return 0; - -fail: - nghttp3_qpack_entry_free(new_ent); - nghttp3_mem_free(mem, new_ent); - - return rv; -} - -int nghttp3_qpack_encoder_dtable_static_add(nghttp3_qpack_encoder *encoder, - uint64_t absidx, - const nghttp3_nv *nv, - uint32_t hash) { - const nghttp3_qpack_static_header *shd; - nghttp3_qpack_nv qnv; - const nghttp3_mem *mem = encoder->ctx.mem; - int rv; - - rv = nghttp3_rcbuf_new2(&qnv.value, nv->value, nv->valuelen, mem); - if (rv != 0) { - return rv; - } - - assert(nghttp3_arraylen(stable) > absidx); - - shd = &stable[absidx]; - - qnv.name = (nghttp3_rcbuf *)&shd->name; - qnv.token = shd->token; - qnv.flags = NGHTTP3_NV_FLAG_NONE; - - rv = nghttp3_qpack_context_dtable_add(&encoder->ctx, &qnv, - &encoder->dtable_map, hash); - - nghttp3_rcbuf_decref(qnv.value); - - return rv; -} - -int nghttp3_qpack_encoder_dtable_dynamic_add(nghttp3_qpack_encoder *encoder, - uint64_t absidx, - const nghttp3_nv *nv, - uint32_t hash) { - nghttp3_qpack_nv qnv; - nghttp3_qpack_entry *ent; - const nghttp3_mem *mem = encoder->ctx.mem; - int rv; - - rv = nghttp3_rcbuf_new2(&qnv.value, nv->value, nv->valuelen, mem); - if (rv != 0) { - return rv; - } - - ent = nghttp3_qpack_context_dtable_get(&encoder->ctx, absidx); - - qnv.name = ent->nv.name; - qnv.token = ent->nv.token; - qnv.flags = NGHTTP3_NV_FLAG_NONE; - - nghttp3_rcbuf_incref(qnv.name); - - rv = nghttp3_qpack_context_dtable_add(&encoder->ctx, &qnv, - &encoder->dtable_map, hash); - - nghttp3_rcbuf_decref(qnv.value); - nghttp3_rcbuf_decref(qnv.name); - - return rv; -} - -int nghttp3_qpack_encoder_dtable_duplicate_add(nghttp3_qpack_encoder *encoder, - uint64_t absidx) { - nghttp3_qpack_nv qnv; - nghttp3_qpack_entry *ent; - int rv; - - ent = nghttp3_qpack_context_dtable_get(&encoder->ctx, absidx); - - qnv = ent->nv; - nghttp3_rcbuf_incref(qnv.name); - nghttp3_rcbuf_incref(qnv.value); - - rv = nghttp3_qpack_context_dtable_add(&encoder->ctx, &qnv, - &encoder->dtable_map, ent->hash); - - nghttp3_rcbuf_decref(qnv.name); - nghttp3_rcbuf_decref(qnv.value); - - return rv; -} - -int nghttp3_qpack_encoder_dtable_literal_add(nghttp3_qpack_encoder *encoder, - const nghttp3_nv *nv, - int32_t token, uint32_t hash) { - nghttp3_qpack_nv qnv; - const nghttp3_mem *mem = encoder->ctx.mem; - int rv; - - rv = nghttp3_rcbuf_new2(&qnv.name, nv->name, nv->namelen, mem); - if (rv != 0) { - return rv; - } - - rv = nghttp3_rcbuf_new2(&qnv.value, nv->value, nv->valuelen, mem); - if (rv != 0) { - nghttp3_rcbuf_decref(qnv.name); - return rv; - } - - qnv.token = token; - qnv.flags = NGHTTP3_NV_FLAG_NONE; - - rv = nghttp3_qpack_context_dtable_add(&encoder->ctx, &qnv, - &encoder->dtable_map, hash); - - nghttp3_rcbuf_decref(qnv.value); - nghttp3_rcbuf_decref(qnv.name); - - return rv; -} - -nghttp3_qpack_entry * -nghttp3_qpack_context_dtable_get(nghttp3_qpack_context *ctx, uint64_t absidx) { - size_t relidx; - - assert(ctx->next_absidx > absidx); - assert(ctx->next_absidx - absidx - 1 < nghttp3_ringbuf_len(&ctx->dtable)); - - relidx = (size_t)(ctx->next_absidx - absidx - 1); - - return *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&ctx->dtable, relidx); -} - -nghttp3_qpack_entry * -nghttp3_qpack_context_dtable_top(nghttp3_qpack_context *ctx) { - assert(nghttp3_ringbuf_len(&ctx->dtable)); - return *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&ctx->dtable, 0); -} - -void nghttp3_qpack_entry_init(nghttp3_qpack_entry *ent, nghttp3_qpack_nv *qnv, - size_t sum, uint64_t absidx, uint32_t hash) { - ent->nv = *qnv; - ent->map_next = NULL; - ent->sum = sum; - ent->absidx = absidx; - ent->hash = hash; - - nghttp3_rcbuf_incref(ent->nv.name); - nghttp3_rcbuf_incref(ent->nv.value); -} - -void nghttp3_qpack_entry_free(nghttp3_qpack_entry *ent) { - nghttp3_rcbuf_decref(ent->nv.value); - nghttp3_rcbuf_decref(ent->nv.name); -} - -int nghttp3_qpack_encoder_block_stream(nghttp3_qpack_encoder *encoder, - nghttp3_qpack_stream *stream) { - nghttp3_blocked_streams_key bsk = { - nghttp3_struct_of(nghttp3_pq_top(&stream->max_cnts), - nghttp3_qpack_header_block_ref, max_cnts_pe) - ->max_cnt, - stream->me.key}; - - return nghttp3_ksl_insert(&encoder->blocked_streams, NULL, &bsk, stream); -} - -void nghttp3_qpack_encoder_unblock_stream(nghttp3_qpack_encoder *encoder, - nghttp3_qpack_stream *stream) { - nghttp3_blocked_streams_key bsk = { - nghttp3_struct_of(nghttp3_pq_top(&stream->max_cnts), - nghttp3_qpack_header_block_ref, max_cnts_pe) - ->max_cnt, - stream->me.key}; - nghttp3_ksl_it it; - - /* This is purely debugging purpose only */ - it = nghttp3_ksl_lower_bound(&encoder->blocked_streams, &bsk); - - assert(!nghttp3_ksl_it_end(&it)); - assert(nghttp3_ksl_it_get(&it) == stream); - - nghttp3_ksl_remove(&encoder->blocked_streams, NULL, &bsk); -} - -void nghttp3_qpack_encoder_unblock(nghttp3_qpack_encoder *encoder, - uint64_t max_cnt) { - nghttp3_blocked_streams_key bsk = {max_cnt, 0}; - nghttp3_ksl_it it; - - it = nghttp3_ksl_lower_bound(&encoder->blocked_streams, &bsk); - - for (; !nghttp3_ksl_it_end(&it);) { - bsk = *(nghttp3_blocked_streams_key *)nghttp3_ksl_it_key(&it); - nghttp3_ksl_remove(&encoder->blocked_streams, &it, &bsk); - } -} - -void nghttp3_qpack_encoder_ack_header(nghttp3_qpack_encoder *encoder, - int64_t stream_id) { - nghttp3_qpack_stream *stream = - nghttp3_qpack_encoder_find_stream(encoder, stream_id); - const nghttp3_mem *mem = encoder->ctx.mem; - nghttp3_qpack_header_block_ref *ref; - - if (stream == NULL) { - /* This might be NGHTTP3_ERR_QPACK_DECODER_STREAM_ERROR, but we - don't create stream which does not use dynamic table. */ - return; - } - - assert(nghttp3_ringbuf_len(&stream->refs)); - - ref = - *(nghttp3_qpack_header_block_ref **)nghttp3_ringbuf_get(&stream->refs, 0); - - DEBUGF("qpack::encoder: Header acknowledgement stream=%ld ricnt=%" PRIu64 - " krcnt=%" PRIu64 "\n", - stream_id, ref->max_cnt, encoder->krcnt); - - if (encoder->krcnt < ref->max_cnt) { - encoder->krcnt = ref->max_cnt; - - nghttp3_qpack_encoder_unblock(encoder, ref->max_cnt); - } - - nghttp3_qpack_stream_pop_ref(stream); - - assert(ref->min_cnts_pe.index != NGHTTP3_PQ_BAD_INDEX); - - nghttp3_pq_remove(&encoder->min_cnts, &ref->min_cnts_pe); - - nghttp3_qpack_header_block_ref_del(ref, mem); - - if (nghttp3_ringbuf_len(&stream->refs)) { - return; - } - - qpack_encoder_remove_stream(encoder, stream); - - nghttp3_qpack_stream_del(stream, mem); -} - -int nghttp3_qpack_encoder_add_insert_count(nghttp3_qpack_encoder *encoder, - uint64_t n) { - if (encoder->ctx.next_absidx - encoder->krcnt < n) { - return NGHTTP3_ERR_QPACK_DECODER_STREAM_ERROR; - } - encoder->krcnt += n; - - nghttp3_qpack_encoder_unblock(encoder, encoder->krcnt); - - return 0; -} - -void nghttp3_qpack_encoder_ack_everything(nghttp3_qpack_encoder *encoder) { - encoder->krcnt = encoder->ctx.next_absidx; - - nghttp3_ksl_clear(&encoder->blocked_streams); - nghttp3_pq_clear(&encoder->min_cnts); - nghttp3_map_each_free(&encoder->streams, map_stream_free, - (void *)encoder->ctx.mem); -} - -void nghttp3_qpack_encoder_cancel_stream(nghttp3_qpack_encoder *encoder, - int64_t stream_id) { - nghttp3_qpack_stream *stream = - nghttp3_qpack_encoder_find_stream(encoder, stream_id); - const nghttp3_mem *mem = encoder->ctx.mem; - - if (stream == NULL) { - return; - } - - if (nghttp3_qpack_encoder_stream_is_blocked(encoder, stream)) { - nghttp3_qpack_encoder_unblock_stream(encoder, stream); - } - - qpack_encoder_remove_stream(encoder, stream); - - nghttp3_qpack_stream_del(stream, mem); -} - -size_t nghttp3_qpack_encoder_get_num_blocked(nghttp3_qpack_encoder *encoder) { - return nghttp3_ksl_len(&encoder->blocked_streams); -} - -int nghttp3_qpack_encoder_write_field_section_prefix( - nghttp3_qpack_encoder *encoder, nghttp3_buf *pbuf, uint64_t ricnt, - uint64_t base) { - size_t max_ents = - encoder->ctx.hard_max_dtable_size / NGHTTP3_QPACK_ENTRY_OVERHEAD; - uint64_t encricnt = ricnt == 0 ? 0 : (ricnt % (2 * max_ents)) + 1; - int sign = base < ricnt; - uint64_t delta_base = sign ? ricnt - base - 1 : base - ricnt; - size_t len = nghttp3_qpack_put_varint_len(encricnt, 8) + - nghttp3_qpack_put_varint_len(delta_base, 7); - uint8_t *p; - int rv; - - DEBUGF("qpack::encode: ricnt=%" PRIu64 " base=%" PRIu64 " icnt=%" PRIu64 "\n", - ricnt, base, encoder->ctx.next_absidx); - - rv = reserve_buf(pbuf, len, encoder->ctx.mem); - if (rv != 0) { - return rv; - } - - p = pbuf->last; - - p = nghttp3_qpack_put_varint(p, encricnt, 8); - if (sign) { - *p = 0x80; - } else { - *p = 0; - } - p = nghttp3_qpack_put_varint(p, delta_base, 7); - - assert((size_t)(p - pbuf->last) == len); - - pbuf->last = p; - - return 0; -} - -/* - * qpack_read_varint reads |rstate->prefix| prefixed integer stored - * from |begin|. The |end| represents the 1 beyond the last of the - * valid contiguous memory region from |begin|. The decoded integer - * must be less than or equal to NGHTTP3_QPACK_INT_MAX. - * - * If the |rstate->left| is nonzero, it is used as an initial value, - * and this function assumes the |begin| starts with intermediate - * data. |rstate->shift| is used as initial integer shift. - * - * If an entire integer is decoded successfully, the |*fin| is set to - * nonzero. - * - * This function stores the decoded integer in |rstate->left| if it - * succeeds, including partial decoding (in this case, number of shift - * to make in the next call will be stored in |rstate->shift|) and - * returns number of bytes processed, or returns negative error code - * NGHTTP3_ERR_QPACK_FATAL, indicating decoding error. - */ -static nghttp3_ssize qpack_read_varint(int *fin, - nghttp3_qpack_read_state *rstate, - const uint8_t *begin, - const uint8_t *end) { - uint64_t k = (uint8_t)((1 << rstate->prefix) - 1); - uint64_t n = rstate->left; - uint64_t add; - const uint8_t *p = begin; - size_t shift = rstate->shift; - - rstate->shift = 0; - *fin = 0; - - if (n == 0) { - if (((*p) & k) != k) { - rstate->left = (*p) & k; - *fin = 1; - return 1; - } - - n = k; - - if (++p == end) { - rstate->left = n; - return (nghttp3_ssize)(p - begin); - } - } - - for (; p != end; ++p, shift += 7) { - add = (*p) & 0x7f; - - if (shift > 62) { - return NGHTTP3_ERR_QPACK_FATAL; - } - - if ((NGHTTP3_QPACK_INT_MAX >> shift) < add) { - return NGHTTP3_ERR_QPACK_FATAL; - } - - add <<= shift; - - if (NGHTTP3_QPACK_INT_MAX - add < n) { - return NGHTTP3_ERR_QPACK_FATAL; - } - - n += add; - - if (((*p) & (1 << 7)) == 0) { - break; - } - } - - rstate->shift = shift; - - if (p == end) { - rstate->left = n; - return (nghttp3_ssize)(p - begin); - } - - rstate->left = n; - *fin = 1; - return (nghttp3_ssize)(p + 1 - begin); -} - -nghttp3_ssize nghttp3_qpack_encoder_read_decoder(nghttp3_qpack_encoder *encoder, - const uint8_t *src, - size_t srclen) { - const uint8_t *p = src, *end; - int rv; - nghttp3_ssize nread; - int rfin; - - if (encoder->ctx.bad) { - return NGHTTP3_ERR_QPACK_FATAL; - } - - if (srclen == 0) { - return 0; - } - - end = src + srclen; - - for (; p != end;) { - switch (encoder->state) { - case NGHTTP3_QPACK_DS_STATE_OPCODE: - if ((*p) & 0x80) { - DEBUGF("qpack::encode: OPCODE_SECTION_ACK\n"); - encoder->opcode = NGHTTP3_QPACK_DS_OPCODE_SECTION_ACK; - encoder->rstate.prefix = 7; - } else if ((*p) & 0x40) { - DEBUGF("qpack::encode: OPCODE_STREAM_CANCEL\n"); - encoder->opcode = NGHTTP3_QPACK_DS_OPCODE_STREAM_CANCEL; - encoder->rstate.prefix = 6; - } else { - DEBUGF("qpack::encode: OPCODE_ICNT_INCREMENT\n"); - encoder->opcode = NGHTTP3_QPACK_DS_OPCODE_ICNT_INCREMENT; - encoder->rstate.prefix = 6; - } - encoder->state = NGHTTP3_QPACK_DS_STATE_READ_NUMBER; - /* fall through */ - case NGHTTP3_QPACK_DS_STATE_READ_NUMBER: - nread = qpack_read_varint(&rfin, &encoder->rstate, p, end); - if (nread < 0) { - assert(nread == NGHTTP3_ERR_QPACK_FATAL); - rv = NGHTTP3_ERR_QPACK_DECODER_STREAM_ERROR; - goto fail; - } - - p += nread; - - if (!rfin) { - return p - src; - } - - switch (encoder->opcode) { - case NGHTTP3_QPACK_DS_OPCODE_ICNT_INCREMENT: - rv = nghttp3_qpack_encoder_add_insert_count(encoder, - encoder->rstate.left); - if (rv != 0) { - goto fail; - } - break; - case NGHTTP3_QPACK_DS_OPCODE_SECTION_ACK: - nghttp3_qpack_encoder_ack_header(encoder, - (int64_t)encoder->rstate.left); - break; - case NGHTTP3_QPACK_DS_OPCODE_STREAM_CANCEL: - nghttp3_qpack_encoder_cancel_stream(encoder, - (int64_t)encoder->rstate.left); - break; - default: - /* unreachable */ - assert(0); - break; - } - - encoder->state = NGHTTP3_QPACK_DS_STATE_OPCODE; - nghttp3_qpack_read_state_reset(&encoder->rstate); - break; - default: - /* unreachable */ - assert(0); - break; - } - } - - return p - src; - -fail: - encoder->ctx.bad = 1; - return rv; -} - -size_t nghttp3_qpack_put_varint_len(uint64_t n, size_t prefix) { - size_t k = (size_t)((1 << prefix) - 1); - size_t len = 0; - - if (n < k) { - return 1; - } - - n -= k; - ++len; - - for (; n >= 128; n >>= 7, ++len) - ; - - return len + 1; -} - -uint8_t *nghttp3_qpack_put_varint(uint8_t *buf, uint64_t n, size_t prefix) { - size_t k = (size_t)((1 << prefix) - 1); - - *buf = (uint8_t)(*buf & ~k); - - if (n < k) { - *buf = (uint8_t)(*buf | n); - return buf + 1; - } - - *buf = (uint8_t)(*buf | k); - ++buf; - - n -= k; - - for (; n >= 128; n >>= 7) { - *buf++ = (uint8_t)((1 << 7) | (n & 0x7f)); - } - - *buf++ = (uint8_t)n; - - return buf; -} - -void nghttp3_qpack_read_state_free(nghttp3_qpack_read_state *rstate) { - nghttp3_rcbuf_decref(rstate->value); - nghttp3_rcbuf_decref(rstate->name); -} - -void nghttp3_qpack_read_state_reset(nghttp3_qpack_read_state *rstate) { - rstate->name = NULL; - rstate->value = NULL; - nghttp3_buf_init(&rstate->namebuf); - nghttp3_buf_init(&rstate->valuebuf); - rstate->left = 0; - rstate->prefix = 0; - rstate->shift = 0; - rstate->absidx = 0; - rstate->never = 0; - rstate->dynamic = 0; - rstate->huffman_encoded = 0; -} - -int nghttp3_qpack_decoder_init(nghttp3_qpack_decoder *decoder, - size_t max_dtable_size, size_t max_blocked, - const nghttp3_mem *mem) { - int rv; - - rv = qpack_context_init(&decoder->ctx, max_dtable_size, max_blocked, mem); - if (rv != 0) { - return rv; - } - - decoder->state = NGHTTP3_QPACK_ES_STATE_OPCODE; - decoder->opcode = 0; - decoder->written_icnt = 0; - decoder->max_concurrent_streams = 0; - - nghttp3_qpack_read_state_reset(&decoder->rstate); - nghttp3_buf_init(&decoder->dbuf); - - return 0; -} - -void nghttp3_qpack_decoder_free(nghttp3_qpack_decoder *decoder) { - nghttp3_buf_free(&decoder->dbuf, decoder->ctx.mem); - nghttp3_qpack_read_state_free(&decoder->rstate); - qpack_context_free(&decoder->ctx); -} - -/* - * qpack_read_huffman_string decodes huffman string in buffer [begin, - * end) and writes the decoded string to |dest|. This function - * assumes the buffer pointed by |dest| has enough space. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_QPACK_FATAL - * Could not decode huffman string. - */ -static nghttp3_ssize qpack_read_huffman_string(nghttp3_qpack_read_state *rstate, - nghttp3_buf *dest, - const uint8_t *begin, - const uint8_t *end) { - nghttp3_ssize nwrite; - size_t len = (size_t)(end - begin); - int fin = 0; - - if (len >= rstate->left) { - len = (size_t)rstate->left; - fin = 1; - } - - nwrite = nghttp3_qpack_huffman_decode(&rstate->huffman_ctx, dest->last, begin, - len, fin); - if (nwrite < 0) { - return nwrite; - } - - if (nghttp3_qpack_huffman_decode_failure_state(&rstate->huffman_ctx)) { - return NGHTTP3_ERR_QPACK_FATAL; - } - - dest->last += nwrite; - rstate->left -= len; - return (nghttp3_ssize)len; -} - -static nghttp3_ssize qpack_read_string(nghttp3_qpack_read_state *rstate, - nghttp3_buf *dest, const uint8_t *begin, - const uint8_t *end) { - size_t len = (size_t)(end - begin); - size_t n = (size_t)nghttp3_min((uint64_t)len, rstate->left); - - dest->last = nghttp3_cpymem(dest->last, begin, n); - - rstate->left -= n; - return (nghttp3_ssize)n; -} - -/* - * qpack_decoder_validate_index checks rstate->absidx is acceptable. - * - * It returns 0 if it suceeds, or one of the following negative error - * codes: - * - * NGHTTP3_ERR_QPACK_FATAL - * rstate->absidx is invalid. - */ -static int qpack_decoder_validate_index(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_read_state *rstate) { - if (rstate->dynamic) { - return rstate->absidx < decoder->ctx.next_absidx && - decoder->ctx.next_absidx - rstate->absidx - 1 < - nghttp3_ringbuf_len(&decoder->ctx.dtable) - ? 0 - : NGHTTP3_ERR_QPACK_FATAL; - } - return rstate->absidx < nghttp3_arraylen(stable) ? 0 - : NGHTTP3_ERR_QPACK_FATAL; -} - -static void qpack_read_state_check_huffman(nghttp3_qpack_read_state *rstate, - const uint8_t b) { - rstate->huffman_encoded = (b & (1 << rstate->prefix)) != 0; -} - -static void qpack_read_state_terminate_name(nghttp3_qpack_read_state *rstate) { - *rstate->namebuf.last = '\0'; - rstate->name->len = nghttp3_buf_len(&rstate->namebuf); -} - -static void qpack_read_state_terminate_value(nghttp3_qpack_read_state *rstate) { - *rstate->valuebuf.last = '\0'; - rstate->value->len = nghttp3_buf_len(&rstate->valuebuf); -} - -nghttp3_ssize nghttp3_qpack_decoder_read_encoder(nghttp3_qpack_decoder *decoder, - const uint8_t *src, - size_t srclen) { - const uint8_t *p = src, *end; - int rv; - int busy = 0; - const nghttp3_mem *mem = decoder->ctx.mem; - nghttp3_ssize nread; - int rfin; - - if (decoder->ctx.bad) { - return NGHTTP3_ERR_QPACK_FATAL; - } - - if (srclen == 0) { - return 0; - } - - end = src + srclen; - - for (; p != end || busy;) { - busy = 0; - switch (decoder->state) { - case NGHTTP3_QPACK_ES_STATE_OPCODE: - if ((*p) & 0x80) { - DEBUGF("qpack::decode: OPCODE_INSERT_INDEXED\n"); - decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_INSERT_INDEXED; - decoder->rstate.dynamic = !((*p) & 0x40); - decoder->rstate.prefix = 6; - decoder->state = NGHTTP3_QPACK_ES_STATE_READ_INDEX; - } else if ((*p) & 0x40) { - DEBUGF("qpack::decode: OPCODE_INSERT\n"); - decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_INSERT; - decoder->rstate.dynamic = 0; - decoder->rstate.prefix = 5; - decoder->state = NGHTTP3_QPACK_ES_STATE_CHECK_NAME_HUFFMAN; - } else if ((*p) & 0x20) { - DEBUGF("qpack::decode: OPCODE_SET_DTABLE_TABLE_CAP\n"); - decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_SET_DTABLE_CAP; - decoder->rstate.prefix = 5; - decoder->state = NGHTTP3_QPACK_ES_STATE_READ_INDEX; - } else if (!((*p) & 0x20)) { - DEBUGF("qpack::decode: OPCODE_DUPLICATE\n"); - decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_DUPLICATE; - decoder->rstate.dynamic = 1; - decoder->rstate.prefix = 5; - decoder->state = NGHTTP3_QPACK_ES_STATE_READ_INDEX; - } else { - DEBUGF("qpack::decode: unknown opcode %02x\n", *p); - rv = NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; - goto fail; - } - break; - case NGHTTP3_QPACK_ES_STATE_READ_INDEX: - nread = qpack_read_varint(&rfin, &decoder->rstate, p, end); - if (nread < 0) { - assert(NGHTTP3_ERR_QPACK_FATAL == nread); - rv = NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; - goto fail; - } - - p += nread; - - if (!rfin) { - return p - src; - } - - if (decoder->opcode == NGHTTP3_QPACK_ES_OPCODE_SET_DTABLE_CAP) { - if (decoder->rstate.left > decoder->ctx.hard_max_dtable_size) { - rv = NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; - goto fail; - } - DEBUGF("qpack::decode: Set dtable capacity to %" PRIu64 "\n", - decoder->rstate.left); - nghttp3_qpack_decoder_set_dtable_cap(decoder, - (size_t)decoder->rstate.left); - - decoder->state = NGHTTP3_QPACK_ES_STATE_OPCODE; - nghttp3_qpack_read_state_reset(&decoder->rstate); - break; - } - - rv = nghttp3_qpack_decoder_rel2abs(decoder, &decoder->rstate); - if (rv < 0) { - goto fail; - } - - if (decoder->opcode == NGHTTP3_QPACK_ES_OPCODE_DUPLICATE) { - rv = nghttp3_qpack_decoder_dtable_duplicate_add(decoder); - if (rv != 0) { - goto fail; - } - decoder->state = NGHTTP3_QPACK_ES_STATE_OPCODE; - nghttp3_qpack_read_state_reset(&decoder->rstate); - break; - } - - if (decoder->opcode == NGHTTP3_QPACK_ES_OPCODE_INSERT_INDEXED) { - decoder->rstate.prefix = 7; - decoder->state = NGHTTP3_QPACK_ES_STATE_CHECK_VALUE_HUFFMAN; - break; - } - - /* Unreachable */ - assert(0); - break; - case NGHTTP3_QPACK_ES_STATE_CHECK_NAME_HUFFMAN: - qpack_read_state_check_huffman(&decoder->rstate, *p); - decoder->state = NGHTTP3_QPACK_ES_STATE_READ_NAMELEN; - decoder->rstate.left = 0; - decoder->rstate.shift = 0; - /* Fall through */ - case NGHTTP3_QPACK_ES_STATE_READ_NAMELEN: - nread = qpack_read_varint(&rfin, &decoder->rstate, p, end); - if (nread < 0) { - assert(NGHTTP3_ERR_QPACK_FATAL == nread); - rv = NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; - goto fail; - } - - p += nread; - - if (!rfin) { - return p - src; - } - - if (decoder->rstate.left > NGHTTP3_QPACK_MAX_NAMELEN) { - rv = NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE; - goto fail; - } - - if (decoder->rstate.huffman_encoded) { - decoder->state = NGHTTP3_QPACK_ES_STATE_READ_NAME_HUFFMAN; - nghttp3_qpack_huffman_decode_context_init(&decoder->rstate.huffman_ctx); - rv = nghttp3_rcbuf_new(&decoder->rstate.name, - (size_t)decoder->rstate.left * 2 + 1, mem); - } else { - decoder->state = NGHTTP3_QPACK_ES_STATE_READ_NAME; - rv = nghttp3_rcbuf_new(&decoder->rstate.name, - (size_t)decoder->rstate.left + 1, mem); - } - if (rv != 0) { - goto fail; - } - - nghttp3_buf_wrap_init(&decoder->rstate.namebuf, - decoder->rstate.name->base, - decoder->rstate.name->len); - break; - case NGHTTP3_QPACK_ES_STATE_READ_NAME_HUFFMAN: - nread = qpack_read_huffman_string(&decoder->rstate, - &decoder->rstate.namebuf, p, end); - if (nread < 0) { - assert(NGHTTP3_ERR_QPACK_FATAL == nread); - rv = NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; - goto fail; - } - - p += nread; - - if (decoder->rstate.left) { - return p - src; - } - - qpack_read_state_terminate_name(&decoder->rstate); - - decoder->state = NGHTTP3_QPACK_ES_STATE_CHECK_VALUE_HUFFMAN; - decoder->rstate.prefix = 7; - break; - case NGHTTP3_QPACK_ES_STATE_READ_NAME: - nread = - qpack_read_string(&decoder->rstate, &decoder->rstate.namebuf, p, end); - if (nread < 0) { - rv = (int)nread; - goto fail; - } - - p += nread; - - if (decoder->rstate.left) { - return p - src; - } - - qpack_read_state_terminate_name(&decoder->rstate); - - decoder->state = NGHTTP3_QPACK_ES_STATE_CHECK_VALUE_HUFFMAN; - decoder->rstate.prefix = 7; - break; - case NGHTTP3_QPACK_ES_STATE_CHECK_VALUE_HUFFMAN: - qpack_read_state_check_huffman(&decoder->rstate, *p); - decoder->state = NGHTTP3_QPACK_ES_STATE_READ_VALUELEN; - decoder->rstate.left = 0; - decoder->rstate.shift = 0; - /* Fall through */ - case NGHTTP3_QPACK_ES_STATE_READ_VALUELEN: - nread = qpack_read_varint(&rfin, &decoder->rstate, p, end); - if (nread < 0) { - assert(NGHTTP3_ERR_QPACK_FATAL == nread); - rv = NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; - goto fail; - } - - p += nread; - - if (!rfin) { - return p - src; - } - - if (decoder->rstate.left > NGHTTP3_QPACK_MAX_VALUELEN) { - rv = NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE; - goto fail; - } - - if (decoder->rstate.huffman_encoded) { - decoder->state = NGHTTP3_QPACK_ES_STATE_READ_VALUE_HUFFMAN; - nghttp3_qpack_huffman_decode_context_init(&decoder->rstate.huffman_ctx); - rv = nghttp3_rcbuf_new(&decoder->rstate.value, - (size_t)decoder->rstate.left * 2 + 1, mem); - } else { - decoder->state = NGHTTP3_QPACK_ES_STATE_READ_VALUE; - rv = nghttp3_rcbuf_new(&decoder->rstate.value, - (size_t)decoder->rstate.left + 1, mem); - } - if (rv != 0) { - goto fail; - } - - nghttp3_buf_wrap_init(&decoder->rstate.valuebuf, - decoder->rstate.value->base, - decoder->rstate.value->len); - - /* value might be 0 length */ - busy = 1; - break; - case NGHTTP3_QPACK_ES_STATE_READ_VALUE_HUFFMAN: - nread = qpack_read_huffman_string(&decoder->rstate, - &decoder->rstate.valuebuf, p, end); - if (nread < 0) { - assert(NGHTTP3_ERR_QPACK_FATAL == nread); - rv = NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; - goto fail; - } - - p += nread; - - if (decoder->rstate.left) { - return p - src; - } - - qpack_read_state_terminate_value(&decoder->rstate); - - switch (decoder->opcode) { - case NGHTTP3_QPACK_ES_OPCODE_INSERT_INDEXED: - rv = nghttp3_qpack_decoder_dtable_indexed_add(decoder); - break; - case NGHTTP3_QPACK_ES_OPCODE_INSERT: - rv = nghttp3_qpack_decoder_dtable_literal_add(decoder); - break; - default: - /* Unreachable */ - assert(0); - } - if (rv != 0) { - goto fail; - } - - decoder->state = NGHTTP3_QPACK_ES_STATE_OPCODE; - nghttp3_qpack_read_state_reset(&decoder->rstate); - break; - case NGHTTP3_QPACK_ES_STATE_READ_VALUE: - nread = qpack_read_string(&decoder->rstate, &decoder->rstate.valuebuf, p, - end); - if (nread < 0) { - rv = (int)nread; - goto fail; - } - - p += nread; - - if (decoder->rstate.left) { - return p - src; - } - - qpack_read_state_terminate_value(&decoder->rstate); - - switch (decoder->opcode) { - case NGHTTP3_QPACK_ES_OPCODE_INSERT_INDEXED: - rv = nghttp3_qpack_decoder_dtable_indexed_add(decoder); - break; - case NGHTTP3_QPACK_ES_OPCODE_INSERT: - rv = nghttp3_qpack_decoder_dtable_literal_add(decoder); - break; - default: - /* Unreachable */ - assert(0); - } - if (rv != 0) { - goto fail; - } - - decoder->state = NGHTTP3_QPACK_ES_STATE_OPCODE; - nghttp3_qpack_read_state_reset(&decoder->rstate); - break; - } - } - - return p - src; - -fail: - decoder->ctx.bad = 1; - return rv; -} - -void nghttp3_qpack_decoder_set_dtable_cap(nghttp3_qpack_decoder *decoder, - size_t cap) { - nghttp3_qpack_entry *ent; - size_t i; - nghttp3_qpack_context *ctx = &decoder->ctx; - const nghttp3_mem *mem = ctx->mem; - - ctx->max_dtable_size = cap; - - while (ctx->dtable_size > cap) { - i = nghttp3_ringbuf_len(&ctx->dtable); - assert(i); - ent = *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&ctx->dtable, i - 1); - - ctx->dtable_size -= table_space(ent->nv.name->len, ent->nv.value->len); - - nghttp3_ringbuf_pop_back(&ctx->dtable); - nghttp3_qpack_entry_free(ent); - nghttp3_mem_free(mem, ent); - } -} - -int nghttp3_qpack_decoder_dtable_indexed_add(nghttp3_qpack_decoder *decoder) { - DEBUGF("qpack::decode: Insert With Name Reference (%s) absidx=%" PRIu64 ": " - "value=%*s\n", - decoder->rstate.dynamic ? "dynamic" : "static", decoder->rstate.absidx, - (int)decoder->rstate.value->len, decoder->rstate.value->base); - - if (decoder->rstate.dynamic) { - return nghttp3_qpack_decoder_dtable_dynamic_add(decoder); - } - - return nghttp3_qpack_decoder_dtable_static_add(decoder); -} - -int nghttp3_qpack_decoder_dtable_static_add(nghttp3_qpack_decoder *decoder) { - nghttp3_qpack_nv qnv; - int rv; - const nghttp3_qpack_static_header *shd; - - shd = &stable[decoder->rstate.absidx]; - - if (table_space(shd->name.len, decoder->rstate.value->len) > - decoder->ctx.max_dtable_size) { - return NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; - } - - qnv.name = (nghttp3_rcbuf *)&shd->name; - qnv.value = decoder->rstate.value; - qnv.token = shd->token; - qnv.flags = NGHTTP3_NV_FLAG_NONE; - - rv = nghttp3_qpack_context_dtable_add(&decoder->ctx, &qnv, NULL, 0); - - nghttp3_rcbuf_decref(qnv.value); - - return rv; -} - -int nghttp3_qpack_decoder_dtable_dynamic_add(nghttp3_qpack_decoder *decoder) { - nghttp3_qpack_nv qnv; - int rv; - nghttp3_qpack_entry *ent; - - ent = nghttp3_qpack_context_dtable_get(&decoder->ctx, decoder->rstate.absidx); - - if (table_space(ent->nv.name->len, decoder->rstate.value->len) > - decoder->ctx.max_dtable_size) { - return NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; - } - - qnv.name = ent->nv.name; - qnv.value = decoder->rstate.value; - qnv.token = ent->nv.token; - qnv.flags = NGHTTP3_NV_FLAG_NONE; - - nghttp3_rcbuf_incref(qnv.name); - - rv = nghttp3_qpack_context_dtable_add(&decoder->ctx, &qnv, NULL, 0); - - nghttp3_rcbuf_decref(qnv.value); - nghttp3_rcbuf_decref(qnv.name); - - return rv; -} - -int nghttp3_qpack_decoder_dtable_duplicate_add(nghttp3_qpack_decoder *decoder) { - int rv; - nghttp3_qpack_entry *ent; - nghttp3_qpack_nv qnv; - - DEBUGF("qpack::decode: Insert duplicate absidx=%" PRIu64 "\n", - decoder->rstate.absidx); - - ent = nghttp3_qpack_context_dtable_get(&decoder->ctx, decoder->rstate.absidx); - - if (table_space(ent->nv.name->len, ent->nv.value->len) > - decoder->ctx.max_dtable_size) { - return NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; - } - - qnv = ent->nv; - nghttp3_rcbuf_incref(qnv.name); - nghttp3_rcbuf_incref(qnv.value); - - rv = nghttp3_qpack_context_dtable_add(&decoder->ctx, &qnv, NULL, 0); - - nghttp3_rcbuf_decref(qnv.value); - nghttp3_rcbuf_decref(qnv.name); - - return rv; -} - -int nghttp3_qpack_decoder_dtable_literal_add(nghttp3_qpack_decoder *decoder) { - nghttp3_qpack_nv qnv; - int rv; - - DEBUGF("qpack::decode: Insert Without Name Reference: name=%*s value=%*s\n", - (int)decoder->rstate.name->len, decoder->rstate.name->base, - (int)decoder->rstate.value->len, decoder->rstate.value->base); - - if (table_space(decoder->rstate.name->len, decoder->rstate.value->len) > - decoder->ctx.max_dtable_size) { - return NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; - } - - qnv.name = decoder->rstate.name; - qnv.value = decoder->rstate.value; - qnv.token = qpack_lookup_token(qnv.name->base, qnv.name->len); - qnv.flags = NGHTTP3_NV_FLAG_NONE; - - rv = nghttp3_qpack_context_dtable_add(&decoder->ctx, &qnv, NULL, 0); - - nghttp3_rcbuf_decref(qnv.value); - nghttp3_rcbuf_decref(qnv.name); - - return rv; -} - -void nghttp3_qpack_decoder_set_max_concurrent_streams( - nghttp3_qpack_decoder *decoder, size_t max_concurrent_streams) { - decoder->max_concurrent_streams = - nghttp3_max(decoder->max_concurrent_streams, max_concurrent_streams); -} - -void nghttp3_qpack_stream_context_init(nghttp3_qpack_stream_context *sctx, - int64_t stream_id, - const nghttp3_mem *mem) { - nghttp3_qpack_read_state_reset(&sctx->rstate); - - sctx->mem = mem; - sctx->rstate.prefix = 8; - sctx->state = NGHTTP3_QPACK_RS_STATE_RICNT; - sctx->opcode = 0; - sctx->stream_id = stream_id; - sctx->ricnt = 0; - sctx->dbase_sign = 0; - sctx->base = 0; -} - -void nghttp3_qpack_stream_context_free(nghttp3_qpack_stream_context *sctx) { - nghttp3_qpack_read_state_free(&sctx->rstate); -} - -void nghttp3_qpack_stream_context_reset(nghttp3_qpack_stream_context *sctx) { - nghttp3_qpack_stream_context_init(sctx, sctx->stream_id, sctx->mem); -} - -uint64_t -nghttp3_qpack_stream_context_get_ricnt(nghttp3_qpack_stream_context *sctx) { - return sctx->ricnt; -} - -nghttp3_ssize -nghttp3_qpack_decoder_read_request(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx, - nghttp3_qpack_nv *nv, uint8_t *pflags, - const uint8_t *src, size_t srclen, int fin) { - const uint8_t *p = src, *end = src ? src + srclen : src; - int rv; - int busy = 0; - nghttp3_ssize nread; - int rfin; - const nghttp3_mem *mem = decoder->ctx.mem; - - if (decoder->ctx.bad) { - return NGHTTP3_ERR_QPACK_FATAL; - } - - *pflags = NGHTTP3_QPACK_DECODE_FLAG_NONE; - - for (; p != end || busy;) { - busy = 0; - switch (sctx->state) { - case NGHTTP3_QPACK_RS_STATE_RICNT: - nread = qpack_read_varint(&rfin, &sctx->rstate, p, end); - if (nread < 0) { - assert(NGHTTP3_ERR_QPACK_FATAL == nread); - rv = NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - goto fail; - } - - p += nread; - - if (!rfin) { - goto almost_ok; - } - - rv = nghttp3_qpack_decoder_reconstruct_ricnt(decoder, &sctx->ricnt, - sctx->rstate.left); - if (rv != 0) { - goto fail; - } - - sctx->state = NGHTTP3_QPACK_RS_STATE_DBASE_SIGN; - break; - case NGHTTP3_QPACK_RS_STATE_DBASE_SIGN: - if ((*p) & 0x80) { - sctx->dbase_sign = 1; - } - sctx->state = NGHTTP3_QPACK_RS_STATE_DBASE; - sctx->rstate.left = 0; - sctx->rstate.prefix = 7; - sctx->rstate.shift = 0; - /* Fall through */ - case NGHTTP3_QPACK_RS_STATE_DBASE: - nread = qpack_read_varint(&rfin, &sctx->rstate, p, end); - if (nread < 0) { - assert(NGHTTP3_ERR_QPACK_FATAL == nread); - rv = NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - goto fail; - } - - p += nread; - - if (!rfin) { - goto almost_ok; - } - - if (sctx->dbase_sign) { - if (sctx->ricnt < sctx->rstate.left) { - rv = NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - goto fail; - } - sctx->base = sctx->ricnt - sctx->rstate.left - 1; - } else { - sctx->base = sctx->ricnt + sctx->rstate.left; - } - - DEBUGF("qpack::decode: ricnt=%" PRIu64 " base=%" PRIu64 " icnt=%" PRIu64 - "\n", - sctx->ricnt, sctx->base, decoder->ctx.next_absidx); - - if (sctx->ricnt > decoder->ctx.next_absidx) { - DEBUGF("qpack::decode: stream blocked\n"); - sctx->state = NGHTTP3_QPACK_RS_STATE_BLOCKED; - *pflags |= NGHTTP3_QPACK_DECODE_FLAG_BLOCKED; - return p - src; - } - - sctx->state = NGHTTP3_QPACK_RS_STATE_OPCODE; - sctx->rstate.left = 0; - sctx->rstate.shift = 0; - break; - case NGHTTP3_QPACK_RS_STATE_OPCODE: - assert(sctx->rstate.left == 0); - assert(sctx->rstate.shift == 0); - if ((*p) & 0x80) { - DEBUGF("qpack::decode: OPCODE_INDEXED\n"); - sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED; - sctx->rstate.dynamic = !((*p) & 0x40); - sctx->rstate.prefix = 6; - sctx->state = NGHTTP3_QPACK_RS_STATE_READ_INDEX; - } else if ((*p) & 0x40) { - DEBUGF("qpack::decode: OPCODE_INDEXED_NAME\n"); - sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME; - sctx->rstate.never = (*p) & 0x20; - sctx->rstate.dynamic = !((*p) & 0x10); - sctx->rstate.prefix = 4; - sctx->state = NGHTTP3_QPACK_RS_STATE_READ_INDEX; - } else if ((*p) & 0x20) { - DEBUGF("qpack::decode: OPCODE_LITERAL\n"); - sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_LITERAL; - sctx->rstate.never = (*p) & 0x10; - sctx->rstate.dynamic = 0; - sctx->rstate.prefix = 3; - sctx->state = NGHTTP3_QPACK_RS_STATE_CHECK_NAME_HUFFMAN; - } else if ((*p) & 0x10) { - DEBUGF("qpack::decode: OPCODE_INDEXED_PB\n"); - sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED_PB; - sctx->rstate.dynamic = 1; - sctx->rstate.prefix = 4; - sctx->state = NGHTTP3_QPACK_RS_STATE_READ_INDEX; - } else { - DEBUGF("qpack::decode: OPCODE_INDEXED_NAME_PB\n"); - sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME_PB; - sctx->rstate.never = (*p) & 0x08; - sctx->rstate.dynamic = 1; - sctx->rstate.prefix = 3; - sctx->state = NGHTTP3_QPACK_RS_STATE_READ_INDEX; - } - break; - case NGHTTP3_QPACK_RS_STATE_READ_INDEX: - nread = qpack_read_varint(&rfin, &sctx->rstate, p, end); - if (nread < 0) { - assert(NGHTTP3_ERR_QPACK_FATAL == nread); - rv = NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - goto fail; - } - - p += nread; - - if (!rfin) { - goto almost_ok; - } - - switch (sctx->opcode) { - case NGHTTP3_QPACK_RS_OPCODE_INDEXED: - rv = nghttp3_qpack_decoder_brel2abs(decoder, sctx); - if (rv != 0) { - goto fail; - } - nghttp3_qpack_decoder_emit_indexed(decoder, sctx, nv); - *pflags |= NGHTTP3_QPACK_DECODE_FLAG_EMIT; - - sctx->state = NGHTTP3_QPACK_RS_STATE_OPCODE; - nghttp3_qpack_read_state_reset(&sctx->rstate); - - return p - src; - case NGHTTP3_QPACK_RS_OPCODE_INDEXED_PB: - rv = nghttp3_qpack_decoder_pbrel2abs(decoder, sctx); - if (rv != 0) { - goto fail; - } - nghttp3_qpack_decoder_emit_indexed(decoder, sctx, nv); - *pflags |= NGHTTP3_QPACK_DECODE_FLAG_EMIT; - - sctx->state = NGHTTP3_QPACK_RS_STATE_OPCODE; - nghttp3_qpack_read_state_reset(&sctx->rstate); - - return p - src; - case NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME: - rv = nghttp3_qpack_decoder_brel2abs(decoder, sctx); - if (rv != 0) { - goto fail; - } - sctx->rstate.prefix = 7; - sctx->state = NGHTTP3_QPACK_RS_STATE_CHECK_VALUE_HUFFMAN; - break; - case NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME_PB: - rv = nghttp3_qpack_decoder_pbrel2abs(decoder, sctx); - if (rv != 0) { - goto fail; - } - sctx->rstate.prefix = 7; - sctx->state = NGHTTP3_QPACK_RS_STATE_CHECK_VALUE_HUFFMAN; - break; - default: - /* Unreachable */ - assert(0); - } - break; - case NGHTTP3_QPACK_RS_STATE_CHECK_NAME_HUFFMAN: - qpack_read_state_check_huffman(&sctx->rstate, *p); - sctx->state = NGHTTP3_QPACK_RS_STATE_READ_NAMELEN; - sctx->rstate.left = 0; - sctx->rstate.shift = 0; - /* Fall through */ - case NGHTTP3_QPACK_RS_STATE_READ_NAMELEN: - nread = qpack_read_varint(&rfin, &sctx->rstate, p, end); - if (nread < 0) { - assert(NGHTTP3_ERR_QPACK_FATAL == nread); - rv = NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - goto fail; - } - - p += nread; - - if (!rfin) { - goto almost_ok; - } - - if (sctx->rstate.left > NGHTTP3_QPACK_MAX_NAMELEN) { - rv = NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE; - goto fail; - } - - if (sctx->rstate.huffman_encoded) { - sctx->state = NGHTTP3_QPACK_RS_STATE_READ_NAME_HUFFMAN; - nghttp3_qpack_huffman_decode_context_init(&sctx->rstate.huffman_ctx); - rv = nghttp3_rcbuf_new(&sctx->rstate.name, - (size_t)sctx->rstate.left * 2 + 1, mem); - } else { - sctx->state = NGHTTP3_QPACK_RS_STATE_READ_NAME; - rv = nghttp3_rcbuf_new(&sctx->rstate.name, - (size_t)sctx->rstate.left + 1, mem); - } - if (rv != 0) { - goto fail; - } - - nghttp3_buf_wrap_init(&sctx->rstate.namebuf, sctx->rstate.name->base, - sctx->rstate.name->len); - break; - case NGHTTP3_QPACK_RS_STATE_READ_NAME_HUFFMAN: - nread = qpack_read_huffman_string(&sctx->rstate, &sctx->rstate.namebuf, p, - end); - if (nread < 0) { - assert(NGHTTP3_ERR_QPACK_FATAL == nread); - rv = NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - goto fail; - } - - p += nread; - - if (sctx->rstate.left) { - goto almost_ok; - } - - qpack_read_state_terminate_name(&sctx->rstate); - - sctx->state = NGHTTP3_QPACK_RS_STATE_CHECK_VALUE_HUFFMAN; - sctx->rstate.prefix = 7; - break; - case NGHTTP3_QPACK_RS_STATE_READ_NAME: - nread = qpack_read_string(&sctx->rstate, &sctx->rstate.namebuf, p, end); - if (nread < 0) { - rv = (int)nread; - goto fail; - } - - p += nread; - - if (sctx->rstate.left) { - goto almost_ok; - } - - qpack_read_state_terminate_name(&sctx->rstate); - - sctx->state = NGHTTP3_QPACK_RS_STATE_CHECK_VALUE_HUFFMAN; - sctx->rstate.prefix = 7; - break; - case NGHTTP3_QPACK_RS_STATE_CHECK_VALUE_HUFFMAN: - qpack_read_state_check_huffman(&sctx->rstate, *p); - sctx->state = NGHTTP3_QPACK_RS_STATE_READ_VALUELEN; - sctx->rstate.left = 0; - sctx->rstate.shift = 0; - /* Fall through */ - case NGHTTP3_QPACK_RS_STATE_READ_VALUELEN: - nread = qpack_read_varint(&rfin, &sctx->rstate, p, end); - if (nread < 0) { - assert(NGHTTP3_ERR_QPACK_FATAL == nread); - rv = NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - goto fail; - } - - p += nread; - - if (!rfin) { - goto almost_ok; - } - - if (sctx->rstate.left > NGHTTP3_QPACK_MAX_VALUELEN) { - rv = NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE; - goto fail; - } - - if (sctx->rstate.huffman_encoded) { - sctx->state = NGHTTP3_QPACK_RS_STATE_READ_VALUE_HUFFMAN; - nghttp3_qpack_huffman_decode_context_init(&sctx->rstate.huffman_ctx); - rv = nghttp3_rcbuf_new(&sctx->rstate.value, - (size_t)sctx->rstate.left * 2 + 1, mem); - } else { - sctx->state = NGHTTP3_QPACK_RS_STATE_READ_VALUE; - rv = nghttp3_rcbuf_new(&sctx->rstate.value, - (size_t)sctx->rstate.left + 1, mem); - } - if (rv != 0) { - goto fail; - } - - nghttp3_buf_wrap_init(&sctx->rstate.valuebuf, sctx->rstate.value->base, - sctx->rstate.value->len); - - /* value might be 0 length */ - busy = 1; - break; - case NGHTTP3_QPACK_RS_STATE_READ_VALUE_HUFFMAN: - nread = qpack_read_huffman_string(&sctx->rstate, &sctx->rstate.valuebuf, - p, end); - if (nread < 0) { - assert(NGHTTP3_ERR_QPACK_FATAL == nread); - rv = NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - goto fail; - } - - p += nread; - - if (sctx->rstate.left) { - goto almost_ok; - } - - qpack_read_state_terminate_value(&sctx->rstate); - - switch (sctx->opcode) { - case NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME: - case NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME_PB: - nghttp3_qpack_decoder_emit_indexed_name(decoder, sctx, nv); - break; - case NGHTTP3_QPACK_RS_OPCODE_LITERAL: - nghttp3_qpack_decoder_emit_literal(decoder, sctx, nv); - break; - default: - /* Unreachable */ - assert(0); - } - - *pflags |= NGHTTP3_QPACK_DECODE_FLAG_EMIT; - - sctx->state = NGHTTP3_QPACK_RS_STATE_OPCODE; - nghttp3_qpack_read_state_reset(&sctx->rstate); - - return p - src; - case NGHTTP3_QPACK_RS_STATE_READ_VALUE: - nread = qpack_read_string(&sctx->rstate, &sctx->rstate.valuebuf, p, end); - if (nread < 0) { - rv = (int)nread; - goto fail; - } - - p += nread; - - if (sctx->rstate.left) { - goto almost_ok; - } - - qpack_read_state_terminate_value(&sctx->rstate); - - switch (sctx->opcode) { - case NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME: - case NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME_PB: - nghttp3_qpack_decoder_emit_indexed_name(decoder, sctx, nv); - break; - case NGHTTP3_QPACK_RS_OPCODE_LITERAL: - nghttp3_qpack_decoder_emit_literal(decoder, sctx, nv); - break; - default: - /* Unreachable */ - assert(0); - } - - *pflags |= NGHTTP3_QPACK_DECODE_FLAG_EMIT; - - sctx->state = NGHTTP3_QPACK_RS_STATE_OPCODE; - nghttp3_qpack_read_state_reset(&sctx->rstate); - - return p - src; - case NGHTTP3_QPACK_RS_STATE_BLOCKED: - if (sctx->ricnt > decoder->ctx.next_absidx) { - DEBUGF("qpack::decode: stream still blocked\n"); - *pflags |= NGHTTP3_QPACK_DECODE_FLAG_BLOCKED; - return p - src; - } - sctx->state = NGHTTP3_QPACK_RS_STATE_OPCODE; - nghttp3_qpack_read_state_reset(&sctx->rstate); - break; - } - } - -almost_ok: - if (fin) { - if (sctx->state != NGHTTP3_QPACK_RS_STATE_OPCODE) { - rv = NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - goto fail; - } - - *pflags |= NGHTTP3_QPACK_DECODE_FLAG_FINAL; - - if (sctx->ricnt) { - rv = nghttp3_qpack_decoder_write_section_ack(decoder, sctx); - if (rv != 0) { - goto fail; - } - } - } - - return p - src; - -fail: - decoder->ctx.bad = 1; - return rv; -} - -static int qpack_decoder_dbuf_overflow(nghttp3_qpack_decoder *decoder) { - size_t limit = nghttp3_max(decoder->max_concurrent_streams, 100); - /* 10 = nghttp3_qpack_put_varint_len((1ULL << 62) - 1, 2)) */ - return nghttp3_buf_len(&decoder->dbuf) > limit * 2 * 10; -} - -int nghttp3_qpack_decoder_write_section_ack( - nghttp3_qpack_decoder *decoder, const nghttp3_qpack_stream_context *sctx) { - nghttp3_buf *dbuf = &decoder->dbuf; - uint8_t *p; - int rv; - - if (qpack_decoder_dbuf_overflow(decoder)) { - return NGHTTP3_ERR_QPACK_FATAL; - } - - rv = reserve_buf_small( - dbuf, nghttp3_qpack_put_varint_len((uint64_t)sctx->stream_id, 7), - decoder->ctx.mem); - if (rv != 0) { - return rv; - } - - p = dbuf->last; - *p = 0x80; - dbuf->last = nghttp3_qpack_put_varint(p, (uint64_t)sctx->stream_id, 7); - - if (decoder->written_icnt < sctx->ricnt) { - decoder->written_icnt = sctx->ricnt; - } - - return 0; -} - -size_t -nghttp3_qpack_decoder_get_decoder_streamlen(nghttp3_qpack_decoder *decoder) { - uint64_t n; - size_t len = 0; - - if (decoder->written_icnt < decoder->ctx.next_absidx) { - n = decoder->ctx.next_absidx - decoder->written_icnt; - len = nghttp3_qpack_put_varint_len(n, 6); - } - - return nghttp3_buf_len(&decoder->dbuf) + len; -} - -void nghttp3_qpack_decoder_write_decoder(nghttp3_qpack_decoder *decoder, - nghttp3_buf *dbuf) { - uint8_t *p; - uint64_t n = 0; - size_t len = 0; - - if (decoder->written_icnt < decoder->ctx.next_absidx) { - n = decoder->ctx.next_absidx - decoder->written_icnt; - len = nghttp3_qpack_put_varint_len(n, 6); - } - - assert(nghttp3_buf_left(dbuf) >= nghttp3_buf_len(&decoder->dbuf) + len); - - if (nghttp3_buf_len(&decoder->dbuf)) { - dbuf->last = nghttp3_cpymem(dbuf->last, decoder->dbuf.pos, - nghttp3_buf_len(&decoder->dbuf)); - } - - if (n) { - p = dbuf->last; - *p = 0; - dbuf->last = nghttp3_qpack_put_varint(p, n, 6); - - decoder->written_icnt = decoder->ctx.next_absidx; - } - - nghttp3_buf_reset(&decoder->dbuf); -} - -int nghttp3_qpack_decoder_cancel_stream(nghttp3_qpack_decoder *decoder, - int64_t stream_id) { - uint8_t *p; - int rv; - - if (qpack_decoder_dbuf_overflow(decoder)) { - return NGHTTP3_ERR_QPACK_FATAL; - } - - rv = reserve_buf(&decoder->dbuf, - nghttp3_qpack_put_varint_len((uint64_t)stream_id, 6), - decoder->ctx.mem); - if (rv != 0) { - return rv; - } - - p = decoder->dbuf.last; - *p = 0x40; - decoder->dbuf.last = nghttp3_qpack_put_varint(p, (uint64_t)stream_id, 6); - - return 0; -} - -int nghttp3_qpack_decoder_reconstruct_ricnt(nghttp3_qpack_decoder *decoder, - uint64_t *dest, uint64_t encricnt) { - uint64_t max_ents, full, max, max_wrapped, ricnt; - - if (encricnt == 0) { - *dest = 0; - return 0; - } - - max_ents = decoder->ctx.hard_max_dtable_size / NGHTTP3_QPACK_ENTRY_OVERHEAD; - full = 2 * max_ents; - - if (encricnt > full) { - return NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - } - - max = decoder->ctx.next_absidx + max_ents; - max_wrapped = max / full * full; - ricnt = max_wrapped + encricnt - 1; - - if (ricnt > max) { - if (ricnt <= full) { - return NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - } - ricnt -= full; - } - - if (ricnt == 0) { - return NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - } - - *dest = ricnt; - - return 0; -} - -int nghttp3_qpack_decoder_rel2abs(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_read_state *rstate) { - DEBUGF("qpack::decode: dynamic=%d relidx=%" PRIu64 " icnt=%" PRIu64 "\n", - rstate->dynamic, rstate->left, decoder->ctx.next_absidx); - - if (rstate->dynamic) { - if (decoder->ctx.next_absidx < rstate->left + 1) { - return NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; - } - rstate->absidx = decoder->ctx.next_absidx - rstate->left - 1; - } else { - rstate->absidx = rstate->left; - } - if (qpack_decoder_validate_index(decoder, rstate) != 0) { - return NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; - } - return 0; -} - -int nghttp3_qpack_decoder_brel2abs(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx) { - nghttp3_qpack_read_state *rstate = &sctx->rstate; - - DEBUGF("qpack::decode: dynamic=%d relidx=%" PRIu64 " base=%" PRIu64 - " icnt=%" PRIu64 "\n", - rstate->dynamic, rstate->left, sctx->base, decoder->ctx.next_absidx); - - if (rstate->dynamic) { - if (sctx->base < rstate->left + 1) { - return NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - } - rstate->absidx = sctx->base - rstate->left - 1; - - if (rstate->absidx >= sctx->ricnt) { - return NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - } - } else { - rstate->absidx = rstate->left; - } - - if (qpack_decoder_validate_index(decoder, rstate) != 0) { - return NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - } - return 0; -} - -int nghttp3_qpack_decoder_pbrel2abs(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx) { - nghttp3_qpack_read_state *rstate = &sctx->rstate; - - DEBUGF("qpack::decode: pbidx=%" PRIu64 " base=%" PRIu64 " icnt=%" PRIu64 "\n", - rstate->left, sctx->base, decoder->ctx.next_absidx); - - assert(rstate->dynamic); - - rstate->absidx = rstate->left + sctx->base; - - if (rstate->absidx >= sctx->ricnt) { - return NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - } - - if (qpack_decoder_validate_index(decoder, rstate) != 0) { - return NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED; - } - return 0; -} - -static void -qpack_decoder_emit_static_indexed(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx, - nghttp3_qpack_nv *nv) { - const nghttp3_qpack_static_header *shd = &stable[sctx->rstate.absidx]; - (void)decoder; - - nv->name = (nghttp3_rcbuf *)&shd->name; - nv->value = (nghttp3_rcbuf *)&shd->value; - nv->token = shd->token; - nv->flags = NGHTTP3_NV_FLAG_NONE; -} - -static void -qpack_decoder_emit_dynamic_indexed(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx, - nghttp3_qpack_nv *nv) { - nghttp3_qpack_entry *ent = - nghttp3_qpack_context_dtable_get(&decoder->ctx, sctx->rstate.absidx); - - *nv = ent->nv; - - nghttp3_rcbuf_incref(nv->name); - nghttp3_rcbuf_incref(nv->value); -} - -void nghttp3_qpack_decoder_emit_indexed(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx, - nghttp3_qpack_nv *nv) { - DEBUGF("qpack::decode: Indexed (%s) absidx=%" PRIu64 "\n", - sctx->rstate.dynamic ? "dynamic" : "static", sctx->rstate.absidx); - - if (sctx->rstate.dynamic) { - qpack_decoder_emit_dynamic_indexed(decoder, sctx, nv); - } else { - qpack_decoder_emit_static_indexed(decoder, sctx, nv); - } -} - -static void -qpack_decoder_emit_static_indexed_name(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx, - nghttp3_qpack_nv *nv) { - const nghttp3_qpack_static_header *shd = &stable[sctx->rstate.absidx]; - (void)decoder; - - nv->name = (nghttp3_rcbuf *)&shd->name; - nv->value = sctx->rstate.value; - nv->token = shd->token; - nv->flags = - sctx->rstate.never ? NGHTTP3_NV_FLAG_NEVER_INDEX : NGHTTP3_NV_FLAG_NONE; - - sctx->rstate.value = NULL; -} - -static void -qpack_decoder_emit_dynamic_indexed_name(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx, - nghttp3_qpack_nv *nv) { - nghttp3_qpack_entry *ent = - nghttp3_qpack_context_dtable_get(&decoder->ctx, sctx->rstate.absidx); - (void)decoder; - - nv->name = ent->nv.name; - nv->value = sctx->rstate.value; - nv->token = ent->nv.token; - nv->flags = - sctx->rstate.never ? NGHTTP3_NV_FLAG_NEVER_INDEX : NGHTTP3_NV_FLAG_NONE; - - nghttp3_rcbuf_incref(nv->name); - - sctx->rstate.value = NULL; -} - -void nghttp3_qpack_decoder_emit_indexed_name(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx, - nghttp3_qpack_nv *nv) { - (void)decoder; - - DEBUGF("qpack::decode: Indexed name (%s) absidx=%" PRIu64 " value=%*s\n", - sctx->rstate.dynamic ? "dynamic" : "static", sctx->rstate.absidx, - (int)sctx->rstate.value->len, sctx->rstate.value->base); - - if (sctx->rstate.dynamic) { - qpack_decoder_emit_dynamic_indexed_name(decoder, sctx, nv); - } else { - qpack_decoder_emit_static_indexed_name(decoder, sctx, nv); - } -} - -void nghttp3_qpack_decoder_emit_literal(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx, - nghttp3_qpack_nv *nv) { - (void)decoder; - - DEBUGF("qpack::decode: Emit literal name=%*s value=%*s\n", - (int)sctx->rstate.name->len, sctx->rstate.name->base, - (int)sctx->rstate.value->len, sctx->rstate.value->base); - - nv->name = sctx->rstate.name; - nv->value = sctx->rstate.value; - nv->token = qpack_lookup_token(nv->name->base, nv->name->len); - nv->flags = - sctx->rstate.never ? NGHTTP3_NV_FLAG_NEVER_INDEX : NGHTTP3_NV_FLAG_NONE; - - sctx->rstate.name = NULL; - sctx->rstate.value = NULL; -} - -int nghttp3_qpack_encoder_new(nghttp3_qpack_encoder **pencoder, - size_t max_dtable_size, size_t max_blocked, - const nghttp3_mem *mem) { - int rv; - nghttp3_qpack_encoder *p; - - p = nghttp3_mem_malloc(mem, sizeof(nghttp3_qpack_encoder)); - if (p == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - rv = nghttp3_qpack_encoder_init(p, max_dtable_size, max_blocked, mem); - if (rv != 0) { - return rv; - } - - *pencoder = p; - - return 0; -} - -void nghttp3_qpack_encoder_del(nghttp3_qpack_encoder *encoder) { - const nghttp3_mem *mem; - - if (encoder == NULL) { - return; - } - - mem = encoder->ctx.mem; - - nghttp3_qpack_encoder_free(encoder); - nghttp3_mem_free(mem, encoder); -} - -int nghttp3_qpack_stream_context_new(nghttp3_qpack_stream_context **psctx, - int64_t stream_id, - const nghttp3_mem *mem) { - nghttp3_qpack_stream_context *p; - - p = nghttp3_mem_malloc(mem, sizeof(nghttp3_qpack_stream_context)); - if (p == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - nghttp3_qpack_stream_context_init(p, stream_id, mem); - - *psctx = p; - - return 0; -} - -void nghttp3_qpack_stream_context_del(nghttp3_qpack_stream_context *sctx) { - const nghttp3_mem *mem; - - if (sctx == NULL) { - return; - } - - mem = sctx->mem; - - nghttp3_qpack_stream_context_free(sctx); - nghttp3_mem_free(mem, sctx); -} - -int nghttp3_qpack_decoder_new(nghttp3_qpack_decoder **pdecoder, - size_t max_dtable_size, size_t max_blocked, - const nghttp3_mem *mem) { - int rv; - nghttp3_qpack_decoder *p; - - p = nghttp3_mem_malloc(mem, sizeof(nghttp3_qpack_decoder)); - if (p == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - rv = nghttp3_qpack_decoder_init(p, max_dtable_size, max_blocked, mem); - if (rv != 0) { - return rv; - } - - *pdecoder = p; - - return 0; -} - -void nghttp3_qpack_decoder_del(nghttp3_qpack_decoder *decoder) { - const nghttp3_mem *mem; - - if (decoder == NULL) { - return; - } - - mem = decoder->ctx.mem; - - nghttp3_qpack_decoder_free(decoder); - nghttp3_mem_free(mem, decoder); -} - -uint64_t nghttp3_qpack_decoder_get_icnt(const nghttp3_qpack_decoder *decoder) { - return decoder->ctx.next_absidx; -} diff --git a/deps/nghttp3/lib/nghttp3_qpack.h b/deps/nghttp3/lib/nghttp3_qpack.h deleted file mode 100644 index ddfb2b66385f8c..00000000000000 --- a/deps/nghttp3/lib/nghttp3_qpack.h +++ /dev/null @@ -1,966 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2013 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_QPACK_H -#define NGHTTP3_QPACK_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "nghttp3_rcbuf.h" -#include "nghttp3_map.h" -#include "nghttp3_pq.h" -#include "nghttp3_ringbuf.h" -#include "nghttp3_buf.h" -#include "nghttp3_ksl.h" -#include "nghttp3_qpack_huffman.h" - -#define NGHTTP3_QPACK_INT_MAX ((1ull << 62) - 1) - -/* NGHTTP3_QPACK_MAX_NAMELEN is the maximum (compressed) length of - header name this library can decode. */ -#define NGHTTP3_QPACK_MAX_NAMELEN 256 -/* NGHTTP3_QPACK_MAX_VALUELEN is the maximum (compressed) length of - header value this library can decode. */ -#define NGHTTP3_QPACK_MAX_VALUELEN 65536 - -/* nghttp3_qpack_indexing_mode is a indexing strategy. */ -typedef enum { - /* NGHTTP3_QPACK_INDEXING_MODE_LITERAL means that header field - should not be inserted into dynamic table. */ - NGHTTP3_QPACK_INDEXING_MODE_LITERAL, - /* NGHTTP3_QPACK_INDEXING_MODE_STORE means that header field can be - inserted into dynamic table. */ - NGHTTP3_QPACK_INDEXING_MODE_STORE, - /* NGHTTP3_QPACK_INDEXING_MODE_NEVER means that header field should - not be inserted into dynamic table and this must be true for all - forwarding paths. */ - NGHTTP3_QPACK_INDEXING_MODE_NEVER, -} nghttp3_qpack_indexing_mode; - -struct nghttp3_qpack_entry; -typedef struct nghttp3_qpack_entry nghttp3_qpack_entry; - -struct nghttp3_qpack_entry { - /* The header field name/value pair */ - nghttp3_qpack_nv nv; - /* map_next points to the entry which shares same bucket in hash - table. */ - nghttp3_qpack_entry *map_next; - /* sum is the sum of all entries inserted up to this entry. This - value does not contain the space required for this entry. */ - size_t sum; - /* absidx is the absolute index of this entry. */ - uint64_t absidx; - /* The hash value for header name (nv.name). */ - uint32_t hash; -}; - -/* The entry used for static table. */ -typedef struct { - uint64_t absidx; - int32_t token; - uint32_t hash; -} nghttp3_qpack_static_entry; - -typedef struct { - nghttp3_rcbuf name; - nghttp3_rcbuf value; - int32_t token; -} nghttp3_qpack_static_header; - -/* - * nghttp3_qpack_header_block_ref is created per encoded header block - * and includes the required insert count and the minimum insert count - * of dynamic table entry it refers to. - */ -typedef struct { - nghttp3_pq_entry max_cnts_pe; - nghttp3_pq_entry min_cnts_pe; - /* max_cnt is the required insert count. */ - uint64_t max_cnt; - /* min_cnt is the minimum insert count of dynamic table entry it - refers to. In other words, this is the minimum absolute index of - dynamic header table entry this encoded block refers to plus - 1. */ - uint64_t min_cnt; -} nghttp3_qpack_header_block_ref; - -int nghttp3_qpack_header_block_ref_new(nghttp3_qpack_header_block_ref **pref, - uint64_t max_cnt, uint64_t min_cnt, - const nghttp3_mem *mem); - -void nghttp3_qpack_header_block_ref_del(nghttp3_qpack_header_block_ref *ref, - const nghttp3_mem *mem); - -typedef struct { - nghttp3_map_entry me; - /* refs is an array of pointer to nghttp3_qpack_header_block_ref in - the order of the time they are encoded. HTTP/3 allows multiple - header blocks (e.g., non-final response headers, final response - headers, trailers, and push promises) per stream. */ - nghttp3_ringbuf refs; - /* max_cnts is a priority queue sorted by descending order of - max_cnt of nghttp3_qpack_header_block_ref. */ - nghttp3_pq max_cnts; -} nghttp3_qpack_stream; - -int nghttp3_qpack_stream_new(nghttp3_qpack_stream **pstream, int64_t stream_id, - const nghttp3_mem *mem); - -void nghttp3_qpack_stream_del(nghttp3_qpack_stream *stream, - const nghttp3_mem *mem); - -uint64_t nghttp3_qpack_stream_get_max_cnt(const nghttp3_qpack_stream *stream); - -int nghttp3_qpack_stream_add_ref(nghttp3_qpack_stream *stream, - nghttp3_qpack_header_block_ref *ref); - -void nghttp3_qpack_stream_pop_ref(nghttp3_qpack_stream *stream); - -#define NGHTTP3_QPACK_ENTRY_OVERHEAD 32 - -typedef struct { - /* dtable is a dynamic table */ - nghttp3_ringbuf dtable; - /* mem is memory allocator */ - const nghttp3_mem *mem; - /* dtable_size is abstracted buffer size of dtable as described in - the spec. This is the sum of length of name/value in dtable + - NGHTTP3_QPACK_ENTRY_OVERHEAD bytes overhead per each entry. */ - size_t dtable_size; - size_t dtable_sum; - /* hard_max_dtable_size is the maximum size of dynamic table. In - HTTP/3, it is notified by decoder as - SETTINGS_QPACK_MAX_TABLE_CAPACITY. Any value lower than or equal - to SETTINGS_QPACK_MAX_TABLE_CAPACITY is OK because encoder has - the authority to decide how many entries are inserted into - dynamic table. */ - size_t hard_max_dtable_size; - /* max_dtable_size is the effective maximum size of dynamic table. */ - size_t max_dtable_size; - /* max_blocked is the maximum number of stream which can be - blocked. */ - size_t max_blocked; - /* next_absidx is the next absolute index for nghttp3_qpack_entry. - It is equivalent to insert count. */ - uint64_t next_absidx; - /* If inflate/deflate error occurred, this value is set to 1 and - further invocation of inflate/deflate will fail with - NGHTTP3_ERR_QPACK_FATAL. */ - uint8_t bad; -} nghttp3_qpack_context; - -typedef struct { - nghttp3_qpack_huffman_decode_context huffman_ctx; - nghttp3_buf namebuf; - nghttp3_buf valuebuf; - nghttp3_rcbuf *name; - nghttp3_rcbuf *value; - uint64_t left; - size_t prefix; - size_t shift; - uint64_t absidx; - int never; - int dynamic; - int huffman_encoded; -} nghttp3_qpack_read_state; - -void nghttp3_qpack_read_state_free(nghttp3_qpack_read_state *rstate); - -void nghttp3_qpack_read_state_reset(nghttp3_qpack_read_state *rstate); - -#define NGHTTP3_QPACK_MAP_SIZE 64 - -typedef struct { - nghttp3_qpack_entry *table[NGHTTP3_QPACK_MAP_SIZE]; -} nghttp3_qpack_map; - -/* nghttp3_qpack_decoder_stream_state is a set of states when decoding - decoder stream. */ -typedef enum { - NGHTTP3_QPACK_DS_STATE_OPCODE, - NGHTTP3_QPACK_DS_STATE_READ_NUMBER, -} nghttp3_qpack_decoder_stream_state; - -/* nghttp3_qpack_decoder_stream_opcode is opcode used in decoder - stream. */ -typedef enum { - NGHTTP3_QPACK_DS_OPCODE_ICNT_INCREMENT, - NGHTTP3_QPACK_DS_OPCODE_SECTION_ACK, - NGHTTP3_QPACK_DS_OPCODE_STREAM_CANCEL, -} nghttp3_qpack_decoder_stream_opcode; - -/* nghttp3_qpack_encoder_flag is a set of flags used by - nghttp3_qpack_encoder. */ -typedef enum { - NGHTTP3_QPACK_ENCODER_FLAG_NONE = 0x00, - /* NGHTTP3_QPACK_ENCODER_FLAG_PENDING_SET_DTABLE_CAP indicates that - Set Dynamic Table Capacity is required. */ - NGHTTP3_QPACK_ENCODER_FLAG_PENDING_SET_DTABLE_CAP = 0x01, -} nghttp3_qpack_encoder_flag; - -struct nghttp3_qpack_encoder { - nghttp3_qpack_context ctx; - /* dtable_map is a map of hash to nghttp3_qpack_entry to provide - fast access to an entry in dynamic table. */ - nghttp3_qpack_map dtable_map; - /* streams is a map of stream ID to nghttp3_qpack_stream to keep - track of unacknowledged streams. */ - nghttp3_map streams; - /* blocked_streams is an ordered list of nghttp3_qpack_stream, in - descending order of max_cnt, to search the unblocked streams by - received known count. */ - nghttp3_ksl blocked_streams; - /* min_cnts is a priority queue of nghttp3_qpack_header_block_ref - sorted by ascending order of min_cnt to know that an entry can be - evicted from dynamic table. */ - nghttp3_pq min_cnts; - /* krcnt is Known Received Count. */ - uint64_t krcnt; - /* state is a current state of reading decoder stream. */ - nghttp3_qpack_decoder_stream_state state; - /* opcode is a decoder stream opcode being processed. */ - nghttp3_qpack_decoder_stream_opcode opcode; - /* rstate is a set of intermediate state which are used to process - decoder stream. */ - nghttp3_qpack_read_state rstate; - /* min_dtable_update is the minimum dynamic table size required. */ - size_t min_dtable_update; - /* last_max_dtable_update is the dynamic table size last - requested. */ - size_t last_max_dtable_update; - /* flags is bitwise OR of zero or more of - nghttp3_qpack_encoder_flag. */ - uint8_t flags; -}; - -/* - * nghttp3_qpack_encoder_init initializes |encoder|. - * |max_dtable_size| is the maximum size of dynamic table. - * |max_blocked| is the maximum number of stream which can be blocked. - * |mem| is a memory allocator. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_init(nghttp3_qpack_encoder *encoder, - size_t max_dtable_size, size_t max_blocked, - const nghttp3_mem *mem); - -/* - * nghttp3_qpack_encoder_free frees memory allocated for |encoder|. - * This function does not free memory pointed by |encoder|. - */ -void nghttp3_qpack_encoder_free(nghttp3_qpack_encoder *encoder); - -/* - * nghttp3_qpack_encoder_encode_nv encodes |nv|. It writes request - * stream into |rbuf| and writes encoder stream into |ebuf|. |nv| is - * a header field to encode. |base| is base. |allow_blocking| is - * nonzero if this stream can be blocked (or it has been blocked - * already). - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_encode_nv(nghttp3_qpack_encoder *encoder, - uint64_t *pmax_cnt, uint64_t *pmin_cnt, - nghttp3_buf *rbuf, nghttp3_buf *ebuf, - const nghttp3_nv *nv, uint64_t base, - int allow_blocking); - -/* nghttp3_qpack_lookup_result stores a result of table lookup. */ -typedef struct { - /* index is an index of matched entry. -1 if no match is made. */ - nghttp3_ssize index; - /* name_value_match is nonzero if both name and value are - matched. */ - int name_value_match; - /* pb_index is the absolute index of matched post-based dynamic - table entry. -1 if no such entry exists. */ - nghttp3_ssize pb_index; -} nghttp3_qpack_lookup_result; - -/* - * nghttp3_qpack_lookup_stable searches |nv| in static table. |token| - * is a token of nv->name and it is -1 if there is no corresponding - * token defined. |indexing_mode| provides indexing strategy. - */ -nghttp3_qpack_lookup_result -nghttp3_qpack_lookup_stable(const nghttp3_nv *nv, int32_t token, - nghttp3_qpack_indexing_mode indexing_mode); - -/* - * nghttp3_qpack_encoder_lookup_dtable searches |nv| in dynamic table. - * |token| is a token of nv->name and it is -1 if there is no - * corresponding token defined. |hash| is a hash of nv->name. - * |indexing_mode| provides indexing strategy. |krcnt| is Known - * Received Count. |allow_blocking| is nonzero if this stream can be - * blocked (or it has been blocked already). - */ -nghttp3_qpack_lookup_result nghttp3_qpack_encoder_lookup_dtable( - nghttp3_qpack_encoder *encoder, const nghttp3_nv *nv, int32_t token, - uint32_t hash, nghttp3_qpack_indexing_mode indexing_mode, uint64_t krcnt, - int allow_blocking); - -/* - * nghttp3_qpack_encoder_write_field_section_prefix writes Encoded - * Field Section Prefix into |pbuf|. |ricnt| is Required Insert - * Count. |base| is Base. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_write_field_section_prefix( - nghttp3_qpack_encoder *encoder, nghttp3_buf *pbuf, uint64_t ricnt, - uint64_t base); - -/* - * nghttp3_qpack_encoder_write_static_indexed writes Indexed Header - * Field to |rbuf|. |absidx| is an absolute index into static table. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_write_static_indexed(nghttp3_qpack_encoder *encoder, - nghttp3_buf *rbuf, - uint64_t absidx); - -/* - * nghttp3_qpack_encoder_write_dynamic_indexed writes Indexed Header - * Field to |rbuf|. |absidx| is an absolute index into dynamic table. - * |base| is base. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_write_dynamic_indexed(nghttp3_qpack_encoder *encoder, - nghttp3_buf *rbuf, - uint64_t absidx, uint64_t base); - -/* - * nghttp3_qpack_encoder_write_static_indexed writes Literal Header - * Field With Name Reference to |rbuf|. |absidx| is an absolute index - * into static table to reference a name. |nv| is a header field to - * encode. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_write_static_indexed_name( - nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx, - const nghttp3_nv *nv); - -/* - * nghttp3_qpack_encoder_write_dynamic_indexed writes Literal Header - * Field With Name Reference to |rbuf|. |absidx| is an absolute index - * into dynamic table to reference a name. |base| is a base. |nv| is - * a header field to encode. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_write_dynamic_indexed_name( - nghttp3_qpack_encoder *encoder, nghttp3_buf *rbuf, uint64_t absidx, - uint64_t base, const nghttp3_nv *nv); - -/* - * nghttp3_qpack_encoder_write_literal writes Literal Header Field - * Without Name Reference to |rbuf|. |nv| is a header field to - * encode. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_write_literal(nghttp3_qpack_encoder *encoder, - nghttp3_buf *rbuf, - const nghttp3_nv *nv); - -/* - * nghttp3_qpack_encoder_write_static_insert writes Insert With Name - * Reference to |ebuf|. |absidx| is an absolute index into static - * table to reference a name. |nv| is a header field to insert. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_write_static_insert(nghttp3_qpack_encoder *encoder, - nghttp3_buf *ebuf, - uint64_t absidx, - const nghttp3_nv *nv); - -/* - * nghttp3_qpack_encoder_write_dynamic_insert writes Insert With Name - * Reference to |ebuf|. |absidx| is an absolute index into dynamic - * table to reference a name. |nv| is a header field to insert. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_write_dynamic_insert(nghttp3_qpack_encoder *encoder, - nghttp3_buf *ebuf, - uint64_t absidx, - const nghttp3_nv *nv); - -/* - * nghttp3_qpack_encoder_write_duplicate_insert writes Duplicate to - * |ebuf|. |absidx| is an absolute index into dynamic table to - * reference an entry. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_write_duplicate_insert(nghttp3_qpack_encoder *encoder, - nghttp3_buf *ebuf, - uint64_t absidx); - -/* - * nghttp3_qpack_encoder_write_literal_insert writes Insert Without - * Name Reference to |ebuf|. |nv| is a header field to insert. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_write_literal_insert(nghttp3_qpack_encoder *encoder, - nghttp3_buf *ebuf, - const nghttp3_nv *nv); - -int nghttp3_qpack_encoder_stream_is_blocked(nghttp3_qpack_encoder *encoder, - nghttp3_qpack_stream *stream); - -/* - * nghttp3_qpack_encoder_block_stream blocks |stream|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_block_stream(nghttp3_qpack_encoder *encoder, - nghttp3_qpack_stream *stream); - -/* - * nghttp3_qpack_encoder_unblock_stream unblocks |stream|. - */ -void nghttp3_qpack_encoder_unblock_stream(nghttp3_qpack_encoder *encoder, - nghttp3_qpack_stream *stream); - -/* - * nghttp3_qpack_encoder_unblock unblocks stream whose max_cnt is less - * than or equal to |max_cnt|. - */ -void nghttp3_qpack_encoder_unblock(nghttp3_qpack_encoder *encoder, - uint64_t max_cnt); - -/* - * nghttp3_qpack_encoder_find_stream returns stream whose stream ID is - * |stream_id|. This function returns NULL if there is no such - * stream. - */ -nghttp3_qpack_stream * -nghttp3_qpack_encoder_find_stream(nghttp3_qpack_encoder *encoder, - int64_t stream_id); - -uint64_t nghttp3_qpack_encoder_get_min_cnt(nghttp3_qpack_encoder *encoder); - -/* - * nghttp3_qpack_encoder_shrink_dtable shrinks dynamic table so that - * the dynamic table size is less than or equal to maximum size. - */ -void nghttp3_qpack_encoder_shrink_dtable(nghttp3_qpack_encoder *encoder); - -/* - * nghttp3_qpack_encoder_process_dtable_update processes pending - * dynamic table size update. It might write encoder stream into - * |ebuf|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_process_dtable_update(nghttp3_qpack_encoder *encoder, - nghttp3_buf *ebuf); - -/* - * nghttp3_qpack_encoder_write_set_dtable_cap writes Set Dynamic Table - * Capacity. to |ebuf|. |cap| is the capacity of dynamic table. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_write_set_dtable_cap(nghttp3_qpack_encoder *encoder, - nghttp3_buf *ebuf, size_t cap); - -/* - * nghttp3_qpack_context_dtable_add adds |qnv| to dynamic table. If - * |ctx| is a part of encoder, |dtable_map| is not NULL. |hash| is a - * hash value of name. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_context_dtable_add(nghttp3_qpack_context *ctx, - nghttp3_qpack_nv *qnv, - nghttp3_qpack_map *dtable_map, - uint32_t hash); - -/* - * nghttp3_qpack_encoder_dtable_static_add adds |nv| to dynamic table - * by referencing static table entry at an absolute index |absidx|. - * The hash of name is given as |hash|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_dtable_static_add(nghttp3_qpack_encoder *encoder, - uint64_t absidx, - const nghttp3_nv *nv, - uint32_t hash); - -/* - * nghttp3_qpack_encoder_dtable_dynamic_add adds |nv| to dynamic table - * by referencing dynamic table entry at an absolute index |absidx|. - * The hash of name is given as |hash|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_dtable_dynamic_add(nghttp3_qpack_encoder *encoder, - uint64_t absidx, - const nghttp3_nv *nv, - uint32_t hash); - -/* - * nghttp3_qpack_encoder_dtable_duplicate_add duplicates dynamic table - * entry at an absolute index |absidx|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_encoder_dtable_duplicate_add(nghttp3_qpack_encoder *encoder, - uint64_t absidx); - -/* - * nghttp3_qpack_encoder_dtable_literal_add adds |nv| to dynamic - * table. |token| is a token of name and is -1 if it has no token - * value defined. |hash| is a hash of name. - * - * NGHTTP3_ERR_NOMEM Out of memory. - */ -int nghttp3_qpack_encoder_dtable_literal_add(nghttp3_qpack_encoder *encoder, - const nghttp3_nv *nv, - int32_t token, uint32_t hash); - -/* - * nghttp3_qpack_context_dtable_get returns dynamic table entry whose - * absolute index is |absidx|. This function assumes that such entry - * exists. - */ -nghttp3_qpack_entry * -nghttp3_qpack_context_dtable_get(nghttp3_qpack_context *ctx, uint64_t absidx); - -/* - * nghttp3_qpack_context_dtable_top returns latest dynamic table - * entry. This function assumes dynamic table is not empty. - */ -nghttp3_qpack_entry * -nghttp3_qpack_context_dtable_top(nghttp3_qpack_context *ctx); - -/* - * nghttp3_qpack_entry_init initializes |ent|. |qnv| is a header - * field. |sum| is the sum of table space occupied by all entries - * inserted so far. It does not include this entry. |absidx| is an - * absolute index of this entry. |hash| is a hash of header field - * name. This function increases reference count of qnv->nv.name and - * qnv->nv.value. - */ -void nghttp3_qpack_entry_init(nghttp3_qpack_entry *ent, nghttp3_qpack_nv *qnv, - size_t sum, uint64_t absidx, uint32_t hash); - -/* - * nghttp3_qpack_entry_free frees memory allocated for |ent|. - */ -void nghttp3_qpack_entry_free(nghttp3_qpack_entry *ent); - -/* - * nghttp3_qpack_put_varint_len returns the required number of bytes - * to encode |n| with |prefix| bits. - */ -size_t nghttp3_qpack_put_varint_len(uint64_t n, size_t prefix); - -/* - * nghttp3_qpack_put_varint encodes |n| using variable integer - * encoding with |prefix| bits into |buf|. This function assumes the - * buffer pointed by |buf| has enough space. This function returns - * the one byte beyond the last write (buf + - * nghttp3_qpack_put_varint_len(n, prefix)). - */ -uint8_t *nghttp3_qpack_put_varint(uint8_t *buf, uint64_t n, size_t prefix); - -/* nghttp3_qpack_encoder_stream_state is a set of states for encoder - stream decoding. */ -typedef enum { - NGHTTP3_QPACK_ES_STATE_OPCODE, - NGHTTP3_QPACK_ES_STATE_READ_INDEX, - NGHTTP3_QPACK_ES_STATE_CHECK_NAME_HUFFMAN, - NGHTTP3_QPACK_ES_STATE_READ_NAMELEN, - NGHTTP3_QPACK_ES_STATE_READ_NAME_HUFFMAN, - NGHTTP3_QPACK_ES_STATE_READ_NAME, - NGHTTP3_QPACK_ES_STATE_CHECK_VALUE_HUFFMAN, - NGHTTP3_QPACK_ES_STATE_READ_VALUELEN, - NGHTTP3_QPACK_ES_STATE_READ_VALUE_HUFFMAN, - NGHTTP3_QPACK_ES_STATE_READ_VALUE, -} nghttp3_qpack_encoder_stream_state; - -/* nghttp3_qpack_encoder_stream_opcode is a set of opcodes used in - encoder stream. */ -typedef enum { - NGHTTP3_QPACK_ES_OPCODE_INSERT_INDEXED, - NGHTTP3_QPACK_ES_OPCODE_INSERT, - NGHTTP3_QPACK_ES_OPCODE_DUPLICATE, - NGHTTP3_QPACK_ES_OPCODE_SET_DTABLE_CAP, -} nghttp3_qpack_encoder_stream_opcode; - -/* nghttp3_qpack_request_stream_state is a set of states for request - stream decoding. */ -typedef enum { - NGHTTP3_QPACK_RS_STATE_RICNT, - NGHTTP3_QPACK_RS_STATE_DBASE_SIGN, - NGHTTP3_QPACK_RS_STATE_DBASE, - NGHTTP3_QPACK_RS_STATE_OPCODE, - NGHTTP3_QPACK_RS_STATE_READ_INDEX, - NGHTTP3_QPACK_RS_STATE_CHECK_NAME_HUFFMAN, - NGHTTP3_QPACK_RS_STATE_READ_NAMELEN, - NGHTTP3_QPACK_RS_STATE_READ_NAME_HUFFMAN, - NGHTTP3_QPACK_RS_STATE_READ_NAME, - NGHTTP3_QPACK_RS_STATE_CHECK_VALUE_HUFFMAN, - NGHTTP3_QPACK_RS_STATE_READ_VALUELEN, - NGHTTP3_QPACK_RS_STATE_READ_VALUE_HUFFMAN, - NGHTTP3_QPACK_RS_STATE_READ_VALUE, - NGHTTP3_QPACK_RS_STATE_BLOCKED, -} nghttp3_qpack_request_stream_state; - -/* nghttp3_qpack_request_stream_opcode is a set of opcodes used in - request stream. */ -typedef enum { - NGHTTP3_QPACK_RS_OPCODE_INDEXED, - NGHTTP3_QPACK_RS_OPCODE_INDEXED_PB, - NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME, - NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME_PB, - NGHTTP3_QPACK_RS_OPCODE_LITERAL, -} nghttp3_qpack_request_stream_opcode; - -struct nghttp3_qpack_decoder { - nghttp3_qpack_context ctx; - /* state is a current state of reading encoder stream. */ - nghttp3_qpack_encoder_stream_state state; - /* opcode is an encoder stream opcode being processed. */ - nghttp3_qpack_encoder_stream_opcode opcode; - /* rstate is a set of intermediate state which are used to process - encoder stream. */ - nghttp3_qpack_read_state rstate; - /* dbuf is decoder stream. */ - nghttp3_buf dbuf; - /* written_icnt is Insert Count written to decoder stream so far. */ - uint64_t written_icnt; - /* max_concurrent_streams is the number of concurrent streams that a - remote endpoint can open, including both bidirectional and - unidirectional streams which potentially receives QPACK encoded - HEADER frame. */ - size_t max_concurrent_streams; -}; - -/* - * nghttp3_qpack_decoder_init initializes |decoder|. - * |max_dtable_size| is the maximum size of dynamic table. - * |max_blocked| is the maximum number of stream which can be blocked. - * |mem| is a memory allocator. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_qpack_decoder_init(nghttp3_qpack_decoder *decoder, - size_t max_dtable_size, size_t max_blocked, - const nghttp3_mem *mem); - -/* - * nghttp3_qpack_decoder_free frees memory allocated for |decoder|. - * This function does not free memory pointed by |decoder|. - */ -void nghttp3_qpack_decoder_free(nghttp3_qpack_decoder *decoder); - -/* - * nghttp3_qpack_decoder_dtable_indexed_add adds entry received in - * Insert With Name Reference to dynamic table. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - * NGHTTP3_ERR_QPACK_ENCODER_STREAM - * Space required for a decoded entry exceeds max dynamic table - * size. - */ -int nghttp3_qpack_decoder_dtable_indexed_add(nghttp3_qpack_decoder *decoder); - -/* - * nghttp3_qpack_decoder_dtable_static_add adds entry received in - * Insert With Name Reference (static) to dynamic table. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - * NGHTTP3_ERR_QPACK_ENCODER_STREAM - * Space required for a decoded entry exceeds max dynamic table - * size. - */ -int nghttp3_qpack_decoder_dtable_static_add(nghttp3_qpack_decoder *decoder); - -/* - * nghttp3_qpack_decoder_dtable_dynamic_add adds entry received in - * Insert With Name Reference (dynamic) to dynamic table. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - * NGHTTP3_ERR_QPACK_ENCODER_STREAM - * Space required for a decoded entry exceeds max dynamic table - * size. - */ -int nghttp3_qpack_decoder_dtable_dynamic_add(nghttp3_qpack_decoder *decoder); - -/* - * nghttp3_qpack_decoder_dtable_duplicate_add adds entry received in - * Duplicate to dynamic table. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - * NGHTTP3_ERR_QPACK_ENCODER_STREAM - * Space required for a decoded entry exceeds max dynamic table - * size. - */ -int nghttp3_qpack_decoder_dtable_duplicate_add(nghttp3_qpack_decoder *decoder); - -/* - * nghttp3_qpack_decoder_dtable_literal_add adds entry received in - * Insert Without Name Reference to dynamic table. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - * NGHTTP3_ERR_QPACK_ENCODER_STREAM - * Space required for a decoded entry exceeds max dynamic table - * size. - */ -int nghttp3_qpack_decoder_dtable_literal_add(nghttp3_qpack_decoder *decoder); - -struct nghttp3_qpack_stream_context { - /* state is a current state of reading request stream. */ - nghttp3_qpack_request_stream_state state; - /* rstate is a set of intermediate state which are used to process - request stream. */ - nghttp3_qpack_read_state rstate; - const nghttp3_mem *mem; - /* opcode is a request stream opcode being processed. */ - nghttp3_qpack_request_stream_opcode opcode; - int64_t stream_id; - /* ricnt is Required Insert Count to decode this header block. */ - uint64_t ricnt; - /* base is Base in Header Block Prefix. */ - uint64_t base; - /* dbase_sign is the delta base sign in Header Block Prefix. */ - int dbase_sign; -}; - -/* - * nghttp3_qpack_stream_context_init initializes |sctx|. - */ -void nghttp3_qpack_stream_context_init(nghttp3_qpack_stream_context *sctx, - int64_t stream_id, - const nghttp3_mem *mem); - -/* - * nghttp3_qpack_stream_context_free frees memory allocated for - * |sctx|. This function does not free memory pointed by |sctx|. - */ -void nghttp3_qpack_stream_context_free(nghttp3_qpack_stream_context *sctx); - -void nghttp3_qpack_stream_context_reset(nghttp3_qpack_stream_context *sctx); - -/* - * nghttp3_qpack_decoder_reconstruct_ricnt reconstructs Required - * Insert Count from the encoded form |encricnt| and stores Required - * Insert Count in |*dest|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED - * Unable to reconstruct Required Insert Count. - */ -int nghttp3_qpack_decoder_reconstruct_ricnt(nghttp3_qpack_decoder *decoder, - uint64_t *dest, uint64_t encricnt); - -/* - * nghttp3_qpack_decoder_rel2abs converts relative index rstate->left - * received in encoder stream to absolute index and stores it in - * rstate->absidx. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_QPACK_ENCODER_STREAM - * Relative index is invalid. - */ -int nghttp3_qpack_decoder_rel2abs(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_read_state *rstate); - -/* - * nghttp3_qpack_decoder_brel2abs converts Base relative index - * rstate->left received in request stream to absolute index and - * stores it in rstate->absidx. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED - * Base relative index is invalid. - */ -int nghttp3_qpack_decoder_brel2abs(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx); - -/* - * nghttp3_qpack_decoder_pbrel2abs converts Post-Base relative index - * rstate->left received in request stream to absolute index and - * stores it in rstate->absidx. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED - * Post-Base relative index is invalid. - */ -int nghttp3_qpack_decoder_pbrel2abs(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx); - -void nghttp3_qpack_decoder_emit_indexed(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx, - nghttp3_qpack_nv *nv); - -void nghttp3_qpack_decoder_emit_indexed_name(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx, - nghttp3_qpack_nv *nv); - -void nghttp3_qpack_decoder_emit_literal(nghttp3_qpack_decoder *decoder, - nghttp3_qpack_stream_context *sctx, - nghttp3_qpack_nv *nv); - -/* - * nghttp3_qpack_decoder_write_section_ack writes Section - * Acknowledgement to decoder stream. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - * NGHTTP3_ERR_QPACK_FATAL - * Decoder stream overflow. - */ -int nghttp3_qpack_decoder_write_section_ack( - nghttp3_qpack_decoder *decoder, const nghttp3_qpack_stream_context *sctx); - -#endif /* NGHTTP3_QPACK_H */ diff --git a/deps/nghttp3/lib/nghttp3_qpack_huffman.c b/deps/nghttp3/lib/nghttp3_qpack_huffman.c deleted file mode 100644 index c36a68ededd1af..00000000000000 --- a/deps/nghttp3/lib/nghttp3_qpack_huffman.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2013 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_qpack_huffman.h" - -#include -#include -#include - -#include "nghttp3_conv.h" - -size_t nghttp3_qpack_huffman_encode_count(const uint8_t *src, size_t len) { - size_t i; - size_t nbits = 0; - - for (i = 0; i < len; ++i) { - nbits += huffman_sym_table[src[i]].nbits; - } - /* pad the prefix of EOS (256) */ - return (nbits + 7) / 8; -} - -uint8_t *nghttp3_qpack_huffman_encode(uint8_t *dest, const uint8_t *src, - size_t srclen) { - const nghttp3_qpack_huffman_sym *sym; - const uint8_t *end = src + srclen; - uint64_t code = 0; - size_t nbits = 0; - uint32_t x; - - for (; src != end;) { - sym = &huffman_sym_table[*src++]; - code |= (uint64_t)sym->code << (32 - nbits); - nbits += sym->nbits; - if (nbits < 32) { - continue; - } - x = htonl((uint32_t)(code >> 32)); - memcpy(dest, &x, 4); - dest += 4; - code <<= 32; - nbits -= 32; - } - - for (; nbits >= 8;) { - *dest++ = (uint8_t)(code >> 56); - code <<= 8; - nbits -= 8; - } - - if (nbits) { - *dest++ = (uint8_t)((uint8_t)(code >> 56) | ((1 << (8 - nbits)) - 1)); - } - - return dest; -} - -void nghttp3_qpack_huffman_decode_context_init( - nghttp3_qpack_huffman_decode_context *ctx) { - ctx->fstate = NGHTTP3_QPACK_HUFFMAN_ACCEPTED; -} - -nghttp3_ssize -nghttp3_qpack_huffman_decode(nghttp3_qpack_huffman_decode_context *ctx, - uint8_t *dest, const uint8_t *src, size_t srclen, - int fin) { - uint8_t *p = dest; - const uint8_t *end = src + srclen; - nghttp3_qpack_huffman_decode_node node = {ctx->fstate, 0}; - const nghttp3_qpack_huffman_decode_node *t = &node; - uint8_t c; - - /* We use the decoding algorithm described in - http://graphics.ics.uci.edu/pub/Prefix.pdf */ - for (; src != end;) { - c = *src++; - t = &qpack_huffman_decode_table[t->fstate & 0x1ff][c >> 4]; - if (t->fstate & NGHTTP3_QPACK_HUFFMAN_SYM) { - *p++ = t->sym; - } - - t = &qpack_huffman_decode_table[t->fstate & 0x1ff][c & 0xf]; - if (t->fstate & NGHTTP3_QPACK_HUFFMAN_SYM) { - *p++ = t->sym; - } - } - - ctx->fstate = t->fstate; - - if (fin && !(ctx->fstate & NGHTTP3_QPACK_HUFFMAN_ACCEPTED)) { - return NGHTTP3_ERR_QPACK_FATAL; - } - - return p - dest; -} - -int nghttp3_qpack_huffman_decode_failure_state( - nghttp3_qpack_huffman_decode_context *ctx) { - return ctx->fstate == 0x100; -} diff --git a/deps/nghttp3/lib/nghttp3_qpack_huffman.h b/deps/nghttp3/lib/nghttp3_qpack_huffman.h deleted file mode 100644 index 0cab6ed93e6ccc..00000000000000 --- a/deps/nghttp3/lib/nghttp3_qpack_huffman.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2013 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_QPACK_HUFFMAN_H -#define NGHTTP3_QPACK_HUFFMAN_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -typedef struct { - /* The number of bits in this code */ - uint32_t nbits; - /* Huffman code aligned to LSB */ - uint32_t code; -} nghttp3_qpack_huffman_sym; - -extern const nghttp3_qpack_huffman_sym huffman_sym_table[]; - -size_t nghttp3_qpack_huffman_encode_count(const uint8_t *src, size_t len); - -uint8_t *nghttp3_qpack_huffman_encode(uint8_t *dest, const uint8_t *src, - size_t srclen); - -typedef enum { - /* FSA accepts this state as the end of huffman encoding - sequence. */ - NGHTTP3_QPACK_HUFFMAN_ACCEPTED = 1 << 14, - /* This state emits symbol */ - NGHTTP3_QPACK_HUFFMAN_SYM = 1 << 15, -} nghttp3_qpack_huffman_decode_flag; - -typedef struct { - /* fstate is the current huffman decoding state, which is actually - the node ID of internal huffman tree with - nghttp3_qpack_huffman_decode_flag OR-ed. We have 257 leaf nodes, - but they are identical to root node other than emitting a symbol, - so we have 256 internal nodes [1..256], inclusive. The node ID - 256 is a special node and it is a terminal state that means - decoding failed. */ - uint16_t fstate; - /* symbol if NGHTTP3_QPACK_HUFFMAN_SYM flag set */ - uint8_t sym; -} nghttp3_qpack_huffman_decode_node; - -typedef struct { - /* fstate is the current huffman decoding state. */ - uint16_t fstate; -} nghttp3_qpack_huffman_decode_context; - -extern const nghttp3_qpack_huffman_decode_node qpack_huffman_decode_table[][16]; - -void nghttp3_qpack_huffman_decode_context_init( - nghttp3_qpack_huffman_decode_context *ctx); - -/* - * nghttp3_qpack_huffman_decode decodes huffman encoded byte string - * stored in |src| of length |srclen|. |ctx| is a decoding context. - * |ctx| remembers the decoding state, and caller can call this - * function multiple times to feed each chunk of huffman encoded - * substring. |fin| must be nonzero if |src| contains the last chunk - * of huffman string. The decoded string is written to the buffer - * pointed by |dest|. This function assumes that the buffer pointed - * by |dest| contains enough memory to store decoded byte string. - * - * This function returns the number of bytes written to |dest|, or one - * of the following negative error codes: - * - * NGHTTP3_ERR_QPACK_FATAL - * Could not decode huffman string. - */ -nghttp3_ssize -nghttp3_qpack_huffman_decode(nghttp3_qpack_huffman_decode_context *ctx, - uint8_t *dest, const uint8_t *src, size_t srclen, - int fin); - -/* - * nghttp3_qpack_huffman_decode_failure_state returns nonzero if |ctx| - * indicates that huffman decoding context is in failure state. - */ -int nghttp3_qpack_huffman_decode_failure_state( - nghttp3_qpack_huffman_decode_context *ctx); - -#endif /* NGHTTP3_QPACK_HUFFMAN_H */ diff --git a/deps/nghttp3/lib/nghttp3_qpack_huffman_data.c b/deps/nghttp3/lib/nghttp3_qpack_huffman_data.c deleted file mode 100644 index 0c104dbc0a0bd8..00000000000000 --- a/deps/nghttp3/lib/nghttp3_qpack_huffman_data.c +++ /dev/null @@ -1,4981 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2013 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_qpack_huffman.h" - -/* Generated by mkhufftbl.py */ - -const nghttp3_qpack_huffman_sym huffman_sym_table[] = { - {13, 0xffc00000u}, {23, 0xffffb000u}, {28, 0xfffffe20u}, {28, 0xfffffe30u}, - {28, 0xfffffe40u}, {28, 0xfffffe50u}, {28, 0xfffffe60u}, {28, 0xfffffe70u}, - {28, 0xfffffe80u}, {24, 0xffffea00u}, {30, 0xfffffff0u}, {28, 0xfffffe90u}, - {28, 0xfffffea0u}, {30, 0xfffffff4u}, {28, 0xfffffeb0u}, {28, 0xfffffec0u}, - {28, 0xfffffed0u}, {28, 0xfffffee0u}, {28, 0xfffffef0u}, {28, 0xffffff00u}, - {28, 0xffffff10u}, {28, 0xffffff20u}, {30, 0xfffffff8u}, {28, 0xffffff30u}, - {28, 0xffffff40u}, {28, 0xffffff50u}, {28, 0xffffff60u}, {28, 0xffffff70u}, - {28, 0xffffff80u}, {28, 0xffffff90u}, {28, 0xffffffa0u}, {28, 0xffffffb0u}, - {6, 0x50000000u}, {10, 0xfe000000u}, {10, 0xfe400000u}, {12, 0xffa00000u}, - {13, 0xffc80000u}, {6, 0x54000000u}, {8, 0xf8000000u}, {11, 0xff400000u}, - {10, 0xfe800000u}, {10, 0xfec00000u}, {8, 0xf9000000u}, {11, 0xff600000u}, - {8, 0xfa000000u}, {6, 0x58000000u}, {6, 0x5c000000u}, {6, 0x60000000u}, - {5, 0x0u}, {5, 0x8000000u}, {5, 0x10000000u}, {6, 0x64000000u}, - {6, 0x68000000u}, {6, 0x6c000000u}, {6, 0x70000000u}, {6, 0x74000000u}, - {6, 0x78000000u}, {6, 0x7c000000u}, {7, 0xb8000000u}, {8, 0xfb000000u}, - {15, 0xfff80000u}, {6, 0x80000000u}, {12, 0xffb00000u}, {10, 0xff000000u}, - {13, 0xffd00000u}, {6, 0x84000000u}, {7, 0xba000000u}, {7, 0xbc000000u}, - {7, 0xbe000000u}, {7, 0xc0000000u}, {7, 0xc2000000u}, {7, 0xc4000000u}, - {7, 0xc6000000u}, {7, 0xc8000000u}, {7, 0xca000000u}, {7, 0xcc000000u}, - {7, 0xce000000u}, {7, 0xd0000000u}, {7, 0xd2000000u}, {7, 0xd4000000u}, - {7, 0xd6000000u}, {7, 0xd8000000u}, {7, 0xda000000u}, {7, 0xdc000000u}, - {7, 0xde000000u}, {7, 0xe0000000u}, {7, 0xe2000000u}, {7, 0xe4000000u}, - {8, 0xfc000000u}, {7, 0xe6000000u}, {8, 0xfd000000u}, {13, 0xffd80000u}, - {19, 0xfffe0000u}, {13, 0xffe00000u}, {14, 0xfff00000u}, {6, 0x88000000u}, - {15, 0xfffa0000u}, {5, 0x18000000u}, {6, 0x8c000000u}, {5, 0x20000000u}, - {6, 0x90000000u}, {5, 0x28000000u}, {6, 0x94000000u}, {6, 0x98000000u}, - {6, 0x9c000000u}, {5, 0x30000000u}, {7, 0xe8000000u}, {7, 0xea000000u}, - {6, 0xa0000000u}, {6, 0xa4000000u}, {6, 0xa8000000u}, {5, 0x38000000u}, - {6, 0xac000000u}, {7, 0xec000000u}, {6, 0xb0000000u}, {5, 0x40000000u}, - {5, 0x48000000u}, {6, 0xb4000000u}, {7, 0xee000000u}, {7, 0xf0000000u}, - {7, 0xf2000000u}, {7, 0xf4000000u}, {7, 0xf6000000u}, {15, 0xfffc0000u}, - {11, 0xff800000u}, {14, 0xfff40000u}, {13, 0xffe80000u}, {28, 0xffffffc0u}, - {20, 0xfffe6000u}, {22, 0xffff4800u}, {20, 0xfffe7000u}, {20, 0xfffe8000u}, - {22, 0xffff4c00u}, {22, 0xffff5000u}, {22, 0xffff5400u}, {23, 0xffffb200u}, - {22, 0xffff5800u}, {23, 0xffffb400u}, {23, 0xffffb600u}, {23, 0xffffb800u}, - {23, 0xffffba00u}, {23, 0xffffbc00u}, {24, 0xffffeb00u}, {23, 0xffffbe00u}, - {24, 0xffffec00u}, {24, 0xffffed00u}, {22, 0xffff5c00u}, {23, 0xffffc000u}, - {24, 0xffffee00u}, {23, 0xffffc200u}, {23, 0xffffc400u}, {23, 0xffffc600u}, - {23, 0xffffc800u}, {21, 0xfffee000u}, {22, 0xffff6000u}, {23, 0xffffca00u}, - {22, 0xffff6400u}, {23, 0xffffcc00u}, {23, 0xffffce00u}, {24, 0xffffef00u}, - {22, 0xffff6800u}, {21, 0xfffee800u}, {20, 0xfffe9000u}, {22, 0xffff6c00u}, - {22, 0xffff7000u}, {23, 0xffffd000u}, {23, 0xffffd200u}, {21, 0xfffef000u}, - {23, 0xffffd400u}, {22, 0xffff7400u}, {22, 0xffff7800u}, {24, 0xfffff000u}, - {21, 0xfffef800u}, {22, 0xffff7c00u}, {23, 0xffffd600u}, {23, 0xffffd800u}, - {21, 0xffff0000u}, {21, 0xffff0800u}, {22, 0xffff8000u}, {21, 0xffff1000u}, - {23, 0xffffda00u}, {22, 0xffff8400u}, {23, 0xffffdc00u}, {23, 0xffffde00u}, - {20, 0xfffea000u}, {22, 0xffff8800u}, {22, 0xffff8c00u}, {22, 0xffff9000u}, - {23, 0xffffe000u}, {22, 0xffff9400u}, {22, 0xffff9800u}, {23, 0xffffe200u}, - {26, 0xfffff800u}, {26, 0xfffff840u}, {20, 0xfffeb000u}, {19, 0xfffe2000u}, - {22, 0xffff9c00u}, {23, 0xffffe400u}, {22, 0xffffa000u}, {25, 0xfffff600u}, - {26, 0xfffff880u}, {26, 0xfffff8c0u}, {26, 0xfffff900u}, {27, 0xfffffbc0u}, - {27, 0xfffffbe0u}, {26, 0xfffff940u}, {24, 0xfffff100u}, {25, 0xfffff680u}, - {19, 0xfffe4000u}, {21, 0xffff1800u}, {26, 0xfffff980u}, {27, 0xfffffc00u}, - {27, 0xfffffc20u}, {26, 0xfffff9c0u}, {27, 0xfffffc40u}, {24, 0xfffff200u}, - {21, 0xffff2000u}, {21, 0xffff2800u}, {26, 0xfffffa00u}, {26, 0xfffffa40u}, - {28, 0xffffffd0u}, {27, 0xfffffc60u}, {27, 0xfffffc80u}, {27, 0xfffffca0u}, - {20, 0xfffec000u}, {24, 0xfffff300u}, {20, 0xfffed000u}, {21, 0xffff3000u}, - {22, 0xffffa400u}, {21, 0xffff3800u}, {21, 0xffff4000u}, {23, 0xffffe600u}, - {22, 0xffffa800u}, {22, 0xffffac00u}, {25, 0xfffff700u}, {25, 0xfffff780u}, - {24, 0xfffff400u}, {24, 0xfffff500u}, {26, 0xfffffa80u}, {23, 0xffffe800u}, - {26, 0xfffffac0u}, {27, 0xfffffcc0u}, {26, 0xfffffb00u}, {26, 0xfffffb40u}, - {27, 0xfffffce0u}, {27, 0xfffffd00u}, {27, 0xfffffd20u}, {27, 0xfffffd40u}, - {27, 0xfffffd60u}, {28, 0xffffffe0u}, {27, 0xfffffd80u}, {27, 0xfffffda0u}, - {27, 0xfffffdc0u}, {27, 0xfffffde0u}, {27, 0xfffffe00u}, {26, 0xfffffb80u}, - {30, 0xfffffffcu}}; - -const nghttp3_qpack_huffman_decode_node qpack_huffman_decode_table[][16] = { - /* 0 */ - { - {0x04, 0}, - {0x05, 0}, - {0x07, 0}, - {0x08, 0}, - {0x0b, 0}, - {0x0c, 0}, - {0x10, 0}, - {0x13, 0}, - {0x19, 0}, - {0x1c, 0}, - {0x20, 0}, - {0x23, 0}, - {0x2a, 0}, - {0x31, 0}, - {0x39, 0}, - {0x4040, 0}, - }, - /* 1 */ - { - {0xc000, 48}, - {0xc000, 49}, - {0xc000, 50}, - {0xc000, 97}, - {0xc000, 99}, - {0xc000, 101}, - {0xc000, 105}, - {0xc000, 111}, - {0xc000, 115}, - {0xc000, 116}, - {0x0d, 0}, - {0x0e, 0}, - {0x11, 0}, - {0x12, 0}, - {0x14, 0}, - {0x15, 0}, - }, - /* 2 */ - { - {0x8001, 48}, - {0xc016, 48}, - {0x8001, 49}, - {0xc016, 49}, - {0x8001, 50}, - {0xc016, 50}, - {0x8001, 97}, - {0xc016, 97}, - {0x8001, 99}, - {0xc016, 99}, - {0x8001, 101}, - {0xc016, 101}, - {0x8001, 105}, - {0xc016, 105}, - {0x8001, 111}, - {0xc016, 111}, - }, - /* 3 */ - { - {0x8002, 48}, - {0x8009, 48}, - {0x8017, 48}, - {0xc028, 48}, - {0x8002, 49}, - {0x8009, 49}, - {0x8017, 49}, - {0xc028, 49}, - {0x8002, 50}, - {0x8009, 50}, - {0x8017, 50}, - {0xc028, 50}, - {0x8002, 97}, - {0x8009, 97}, - {0x8017, 97}, - {0xc028, 97}, - }, - /* 4 */ - { - {0x8003, 48}, - {0x8006, 48}, - {0x800a, 48}, - {0x800f, 48}, - {0x8018, 48}, - {0x801f, 48}, - {0x8029, 48}, - {0xc038, 48}, - {0x8003, 49}, - {0x8006, 49}, - {0x800a, 49}, - {0x800f, 49}, - {0x8018, 49}, - {0x801f, 49}, - {0x8029, 49}, - {0xc038, 49}, - }, - /* 5 */ - { - {0x8003, 50}, - {0x8006, 50}, - {0x800a, 50}, - {0x800f, 50}, - {0x8018, 50}, - {0x801f, 50}, - {0x8029, 50}, - {0xc038, 50}, - {0x8003, 97}, - {0x8006, 97}, - {0x800a, 97}, - {0x800f, 97}, - {0x8018, 97}, - {0x801f, 97}, - {0x8029, 97}, - {0xc038, 97}, - }, - /* 6 */ - { - {0x8002, 99}, - {0x8009, 99}, - {0x8017, 99}, - {0xc028, 99}, - {0x8002, 101}, - {0x8009, 101}, - {0x8017, 101}, - {0xc028, 101}, - {0x8002, 105}, - {0x8009, 105}, - {0x8017, 105}, - {0xc028, 105}, - {0x8002, 111}, - {0x8009, 111}, - {0x8017, 111}, - {0xc028, 111}, - }, - /* 7 */ - { - {0x8003, 99}, - {0x8006, 99}, - {0x800a, 99}, - {0x800f, 99}, - {0x8018, 99}, - {0x801f, 99}, - {0x8029, 99}, - {0xc038, 99}, - {0x8003, 101}, - {0x8006, 101}, - {0x800a, 101}, - {0x800f, 101}, - {0x8018, 101}, - {0x801f, 101}, - {0x8029, 101}, - {0xc038, 101}, - }, - /* 8 */ - { - {0x8003, 105}, - {0x8006, 105}, - {0x800a, 105}, - {0x800f, 105}, - {0x8018, 105}, - {0x801f, 105}, - {0x8029, 105}, - {0xc038, 105}, - {0x8003, 111}, - {0x8006, 111}, - {0x800a, 111}, - {0x800f, 111}, - {0x8018, 111}, - {0x801f, 111}, - {0x8029, 111}, - {0xc038, 111}, - }, - /* 9 */ - { - {0x8001, 115}, - {0xc016, 115}, - {0x8001, 116}, - {0xc016, 116}, - {0xc000, 32}, - {0xc000, 37}, - {0xc000, 45}, - {0xc000, 46}, - {0xc000, 47}, - {0xc000, 51}, - {0xc000, 52}, - {0xc000, 53}, - {0xc000, 54}, - {0xc000, 55}, - {0xc000, 56}, - {0xc000, 57}, - }, - /* 10 */ - { - {0x8002, 115}, - {0x8009, 115}, - {0x8017, 115}, - {0xc028, 115}, - {0x8002, 116}, - {0x8009, 116}, - {0x8017, 116}, - {0xc028, 116}, - {0x8001, 32}, - {0xc016, 32}, - {0x8001, 37}, - {0xc016, 37}, - {0x8001, 45}, - {0xc016, 45}, - {0x8001, 46}, - {0xc016, 46}, - }, - /* 11 */ - { - {0x8003, 115}, - {0x8006, 115}, - {0x800a, 115}, - {0x800f, 115}, - {0x8018, 115}, - {0x801f, 115}, - {0x8029, 115}, - {0xc038, 115}, - {0x8003, 116}, - {0x8006, 116}, - {0x800a, 116}, - {0x800f, 116}, - {0x8018, 116}, - {0x801f, 116}, - {0x8029, 116}, - {0xc038, 116}, - }, - /* 12 */ - { - {0x8002, 32}, - {0x8009, 32}, - {0x8017, 32}, - {0xc028, 32}, - {0x8002, 37}, - {0x8009, 37}, - {0x8017, 37}, - {0xc028, 37}, - {0x8002, 45}, - {0x8009, 45}, - {0x8017, 45}, - {0xc028, 45}, - {0x8002, 46}, - {0x8009, 46}, - {0x8017, 46}, - {0xc028, 46}, - }, - /* 13 */ - { - {0x8003, 32}, - {0x8006, 32}, - {0x800a, 32}, - {0x800f, 32}, - {0x8018, 32}, - {0x801f, 32}, - {0x8029, 32}, - {0xc038, 32}, - {0x8003, 37}, - {0x8006, 37}, - {0x800a, 37}, - {0x800f, 37}, - {0x8018, 37}, - {0x801f, 37}, - {0x8029, 37}, - {0xc038, 37}, - }, - /* 14 */ - { - {0x8003, 45}, - {0x8006, 45}, - {0x800a, 45}, - {0x800f, 45}, - {0x8018, 45}, - {0x801f, 45}, - {0x8029, 45}, - {0xc038, 45}, - {0x8003, 46}, - {0x8006, 46}, - {0x800a, 46}, - {0x800f, 46}, - {0x8018, 46}, - {0x801f, 46}, - {0x8029, 46}, - {0xc038, 46}, - }, - /* 15 */ - { - {0x8001, 47}, - {0xc016, 47}, - {0x8001, 51}, - {0xc016, 51}, - {0x8001, 52}, - {0xc016, 52}, - {0x8001, 53}, - {0xc016, 53}, - {0x8001, 54}, - {0xc016, 54}, - {0x8001, 55}, - {0xc016, 55}, - {0x8001, 56}, - {0xc016, 56}, - {0x8001, 57}, - {0xc016, 57}, - }, - /* 16 */ - { - {0x8002, 47}, - {0x8009, 47}, - {0x8017, 47}, - {0xc028, 47}, - {0x8002, 51}, - {0x8009, 51}, - {0x8017, 51}, - {0xc028, 51}, - {0x8002, 52}, - {0x8009, 52}, - {0x8017, 52}, - {0xc028, 52}, - {0x8002, 53}, - {0x8009, 53}, - {0x8017, 53}, - {0xc028, 53}, - }, - /* 17 */ - { - {0x8003, 47}, - {0x8006, 47}, - {0x800a, 47}, - {0x800f, 47}, - {0x8018, 47}, - {0x801f, 47}, - {0x8029, 47}, - {0xc038, 47}, - {0x8003, 51}, - {0x8006, 51}, - {0x800a, 51}, - {0x800f, 51}, - {0x8018, 51}, - {0x801f, 51}, - {0x8029, 51}, - {0xc038, 51}, - }, - /* 18 */ - { - {0x8003, 52}, - {0x8006, 52}, - {0x800a, 52}, - {0x800f, 52}, - {0x8018, 52}, - {0x801f, 52}, - {0x8029, 52}, - {0xc038, 52}, - {0x8003, 53}, - {0x8006, 53}, - {0x800a, 53}, - {0x800f, 53}, - {0x8018, 53}, - {0x801f, 53}, - {0x8029, 53}, - {0xc038, 53}, - }, - /* 19 */ - { - {0x8002, 54}, - {0x8009, 54}, - {0x8017, 54}, - {0xc028, 54}, - {0x8002, 55}, - {0x8009, 55}, - {0x8017, 55}, - {0xc028, 55}, - {0x8002, 56}, - {0x8009, 56}, - {0x8017, 56}, - {0xc028, 56}, - {0x8002, 57}, - {0x8009, 57}, - {0x8017, 57}, - {0xc028, 57}, - }, - /* 20 */ - { - {0x8003, 54}, - {0x8006, 54}, - {0x800a, 54}, - {0x800f, 54}, - {0x8018, 54}, - {0x801f, 54}, - {0x8029, 54}, - {0xc038, 54}, - {0x8003, 55}, - {0x8006, 55}, - {0x800a, 55}, - {0x800f, 55}, - {0x8018, 55}, - {0x801f, 55}, - {0x8029, 55}, - {0xc038, 55}, - }, - /* 21 */ - { - {0x8003, 56}, - {0x8006, 56}, - {0x800a, 56}, - {0x800f, 56}, - {0x8018, 56}, - {0x801f, 56}, - {0x8029, 56}, - {0xc038, 56}, - {0x8003, 57}, - {0x8006, 57}, - {0x800a, 57}, - {0x800f, 57}, - {0x8018, 57}, - {0x801f, 57}, - {0x8029, 57}, - {0xc038, 57}, - }, - /* 22 */ - { - {0x1a, 0}, - {0x1b, 0}, - {0x1d, 0}, - {0x1e, 0}, - {0x21, 0}, - {0x22, 0}, - {0x24, 0}, - {0x25, 0}, - {0x2b, 0}, - {0x2e, 0}, - {0x32, 0}, - {0x35, 0}, - {0x3a, 0}, - {0x3d, 0}, - {0x41, 0}, - {0x4044, 0}, - }, - /* 23 */ - { - {0xc000, 61}, - {0xc000, 65}, - {0xc000, 95}, - {0xc000, 98}, - {0xc000, 100}, - {0xc000, 102}, - {0xc000, 103}, - {0xc000, 104}, - {0xc000, 108}, - {0xc000, 109}, - {0xc000, 110}, - {0xc000, 112}, - {0xc000, 114}, - {0xc000, 117}, - {0x26, 0}, - {0x27, 0}, - }, - /* 24 */ - { - {0x8001, 61}, - {0xc016, 61}, - {0x8001, 65}, - {0xc016, 65}, - {0x8001, 95}, - {0xc016, 95}, - {0x8001, 98}, - {0xc016, 98}, - {0x8001, 100}, - {0xc016, 100}, - {0x8001, 102}, - {0xc016, 102}, - {0x8001, 103}, - {0xc016, 103}, - {0x8001, 104}, - {0xc016, 104}, - }, - /* 25 */ - { - {0x8002, 61}, - {0x8009, 61}, - {0x8017, 61}, - {0xc028, 61}, - {0x8002, 65}, - {0x8009, 65}, - {0x8017, 65}, - {0xc028, 65}, - {0x8002, 95}, - {0x8009, 95}, - {0x8017, 95}, - {0xc028, 95}, - {0x8002, 98}, - {0x8009, 98}, - {0x8017, 98}, - {0xc028, 98}, - }, - /* 26 */ - { - {0x8003, 61}, - {0x8006, 61}, - {0x800a, 61}, - {0x800f, 61}, - {0x8018, 61}, - {0x801f, 61}, - {0x8029, 61}, - {0xc038, 61}, - {0x8003, 65}, - {0x8006, 65}, - {0x800a, 65}, - {0x800f, 65}, - {0x8018, 65}, - {0x801f, 65}, - {0x8029, 65}, - {0xc038, 65}, - }, - /* 27 */ - { - {0x8003, 95}, - {0x8006, 95}, - {0x800a, 95}, - {0x800f, 95}, - {0x8018, 95}, - {0x801f, 95}, - {0x8029, 95}, - {0xc038, 95}, - {0x8003, 98}, - {0x8006, 98}, - {0x800a, 98}, - {0x800f, 98}, - {0x8018, 98}, - {0x801f, 98}, - {0x8029, 98}, - {0xc038, 98}, - }, - /* 28 */ - { - {0x8002, 100}, - {0x8009, 100}, - {0x8017, 100}, - {0xc028, 100}, - {0x8002, 102}, - {0x8009, 102}, - {0x8017, 102}, - {0xc028, 102}, - {0x8002, 103}, - {0x8009, 103}, - {0x8017, 103}, - {0xc028, 103}, - {0x8002, 104}, - {0x8009, 104}, - {0x8017, 104}, - {0xc028, 104}, - }, - /* 29 */ - { - {0x8003, 100}, - {0x8006, 100}, - {0x800a, 100}, - {0x800f, 100}, - {0x8018, 100}, - {0x801f, 100}, - {0x8029, 100}, - {0xc038, 100}, - {0x8003, 102}, - {0x8006, 102}, - {0x800a, 102}, - {0x800f, 102}, - {0x8018, 102}, - {0x801f, 102}, - {0x8029, 102}, - {0xc038, 102}, - }, - /* 30 */ - { - {0x8003, 103}, - {0x8006, 103}, - {0x800a, 103}, - {0x800f, 103}, - {0x8018, 103}, - {0x801f, 103}, - {0x8029, 103}, - {0xc038, 103}, - {0x8003, 104}, - {0x8006, 104}, - {0x800a, 104}, - {0x800f, 104}, - {0x8018, 104}, - {0x801f, 104}, - {0x8029, 104}, - {0xc038, 104}, - }, - /* 31 */ - { - {0x8001, 108}, - {0xc016, 108}, - {0x8001, 109}, - {0xc016, 109}, - {0x8001, 110}, - {0xc016, 110}, - {0x8001, 112}, - {0xc016, 112}, - {0x8001, 114}, - {0xc016, 114}, - {0x8001, 117}, - {0xc016, 117}, - {0xc000, 58}, - {0xc000, 66}, - {0xc000, 67}, - {0xc000, 68}, - }, - /* 32 */ - { - {0x8002, 108}, - {0x8009, 108}, - {0x8017, 108}, - {0xc028, 108}, - {0x8002, 109}, - {0x8009, 109}, - {0x8017, 109}, - {0xc028, 109}, - {0x8002, 110}, - {0x8009, 110}, - {0x8017, 110}, - {0xc028, 110}, - {0x8002, 112}, - {0x8009, 112}, - {0x8017, 112}, - {0xc028, 112}, - }, - /* 33 */ - { - {0x8003, 108}, - {0x8006, 108}, - {0x800a, 108}, - {0x800f, 108}, - {0x8018, 108}, - {0x801f, 108}, - {0x8029, 108}, - {0xc038, 108}, - {0x8003, 109}, - {0x8006, 109}, - {0x800a, 109}, - {0x800f, 109}, - {0x8018, 109}, - {0x801f, 109}, - {0x8029, 109}, - {0xc038, 109}, - }, - /* 34 */ - { - {0x8003, 110}, - {0x8006, 110}, - {0x800a, 110}, - {0x800f, 110}, - {0x8018, 110}, - {0x801f, 110}, - {0x8029, 110}, - {0xc038, 110}, - {0x8003, 112}, - {0x8006, 112}, - {0x800a, 112}, - {0x800f, 112}, - {0x8018, 112}, - {0x801f, 112}, - {0x8029, 112}, - {0xc038, 112}, - }, - /* 35 */ - { - {0x8002, 114}, - {0x8009, 114}, - {0x8017, 114}, - {0xc028, 114}, - {0x8002, 117}, - {0x8009, 117}, - {0x8017, 117}, - {0xc028, 117}, - {0x8001, 58}, - {0xc016, 58}, - {0x8001, 66}, - {0xc016, 66}, - {0x8001, 67}, - {0xc016, 67}, - {0x8001, 68}, - {0xc016, 68}, - }, - /* 36 */ - { - {0x8003, 114}, - {0x8006, 114}, - {0x800a, 114}, - {0x800f, 114}, - {0x8018, 114}, - {0x801f, 114}, - {0x8029, 114}, - {0xc038, 114}, - {0x8003, 117}, - {0x8006, 117}, - {0x800a, 117}, - {0x800f, 117}, - {0x8018, 117}, - {0x801f, 117}, - {0x8029, 117}, - {0xc038, 117}, - }, - /* 37 */ - { - {0x8002, 58}, - {0x8009, 58}, - {0x8017, 58}, - {0xc028, 58}, - {0x8002, 66}, - {0x8009, 66}, - {0x8017, 66}, - {0xc028, 66}, - {0x8002, 67}, - {0x8009, 67}, - {0x8017, 67}, - {0xc028, 67}, - {0x8002, 68}, - {0x8009, 68}, - {0x8017, 68}, - {0xc028, 68}, - }, - /* 38 */ - { - {0x8003, 58}, - {0x8006, 58}, - {0x800a, 58}, - {0x800f, 58}, - {0x8018, 58}, - {0x801f, 58}, - {0x8029, 58}, - {0xc038, 58}, - {0x8003, 66}, - {0x8006, 66}, - {0x800a, 66}, - {0x800f, 66}, - {0x8018, 66}, - {0x801f, 66}, - {0x8029, 66}, - {0xc038, 66}, - }, - /* 39 */ - { - {0x8003, 67}, - {0x8006, 67}, - {0x800a, 67}, - {0x800f, 67}, - {0x8018, 67}, - {0x801f, 67}, - {0x8029, 67}, - {0xc038, 67}, - {0x8003, 68}, - {0x8006, 68}, - {0x800a, 68}, - {0x800f, 68}, - {0x8018, 68}, - {0x801f, 68}, - {0x8029, 68}, - {0xc038, 68}, - }, - /* 40 */ - { - {0x2c, 0}, - {0x2d, 0}, - {0x2f, 0}, - {0x30, 0}, - {0x33, 0}, - {0x34, 0}, - {0x36, 0}, - {0x37, 0}, - {0x3b, 0}, - {0x3c, 0}, - {0x3e, 0}, - {0x3f, 0}, - {0x42, 0}, - {0x43, 0}, - {0x45, 0}, - {0x4048, 0}, - }, - /* 41 */ - { - {0xc000, 69}, - {0xc000, 70}, - {0xc000, 71}, - {0xc000, 72}, - {0xc000, 73}, - {0xc000, 74}, - {0xc000, 75}, - {0xc000, 76}, - {0xc000, 77}, - {0xc000, 78}, - {0xc000, 79}, - {0xc000, 80}, - {0xc000, 81}, - {0xc000, 82}, - {0xc000, 83}, - {0xc000, 84}, - }, - /* 42 */ - { - {0x8001, 69}, - {0xc016, 69}, - {0x8001, 70}, - {0xc016, 70}, - {0x8001, 71}, - {0xc016, 71}, - {0x8001, 72}, - {0xc016, 72}, - {0x8001, 73}, - {0xc016, 73}, - {0x8001, 74}, - {0xc016, 74}, - {0x8001, 75}, - {0xc016, 75}, - {0x8001, 76}, - {0xc016, 76}, - }, - /* 43 */ - { - {0x8002, 69}, - {0x8009, 69}, - {0x8017, 69}, - {0xc028, 69}, - {0x8002, 70}, - {0x8009, 70}, - {0x8017, 70}, - {0xc028, 70}, - {0x8002, 71}, - {0x8009, 71}, - {0x8017, 71}, - {0xc028, 71}, - {0x8002, 72}, - {0x8009, 72}, - {0x8017, 72}, - {0xc028, 72}, - }, - /* 44 */ - { - {0x8003, 69}, - {0x8006, 69}, - {0x800a, 69}, - {0x800f, 69}, - {0x8018, 69}, - {0x801f, 69}, - {0x8029, 69}, - {0xc038, 69}, - {0x8003, 70}, - {0x8006, 70}, - {0x800a, 70}, - {0x800f, 70}, - {0x8018, 70}, - {0x801f, 70}, - {0x8029, 70}, - {0xc038, 70}, - }, - /* 45 */ - { - {0x8003, 71}, - {0x8006, 71}, - {0x800a, 71}, - {0x800f, 71}, - {0x8018, 71}, - {0x801f, 71}, - {0x8029, 71}, - {0xc038, 71}, - {0x8003, 72}, - {0x8006, 72}, - {0x800a, 72}, - {0x800f, 72}, - {0x8018, 72}, - {0x801f, 72}, - {0x8029, 72}, - {0xc038, 72}, - }, - /* 46 */ - { - {0x8002, 73}, - {0x8009, 73}, - {0x8017, 73}, - {0xc028, 73}, - {0x8002, 74}, - {0x8009, 74}, - {0x8017, 74}, - {0xc028, 74}, - {0x8002, 75}, - {0x8009, 75}, - {0x8017, 75}, - {0xc028, 75}, - {0x8002, 76}, - {0x8009, 76}, - {0x8017, 76}, - {0xc028, 76}, - }, - /* 47 */ - { - {0x8003, 73}, - {0x8006, 73}, - {0x800a, 73}, - {0x800f, 73}, - {0x8018, 73}, - {0x801f, 73}, - {0x8029, 73}, - {0xc038, 73}, - {0x8003, 74}, - {0x8006, 74}, - {0x800a, 74}, - {0x800f, 74}, - {0x8018, 74}, - {0x801f, 74}, - {0x8029, 74}, - {0xc038, 74}, - }, - /* 48 */ - { - {0x8003, 75}, - {0x8006, 75}, - {0x800a, 75}, - {0x800f, 75}, - {0x8018, 75}, - {0x801f, 75}, - {0x8029, 75}, - {0xc038, 75}, - {0x8003, 76}, - {0x8006, 76}, - {0x800a, 76}, - {0x800f, 76}, - {0x8018, 76}, - {0x801f, 76}, - {0x8029, 76}, - {0xc038, 76}, - }, - /* 49 */ - { - {0x8001, 77}, - {0xc016, 77}, - {0x8001, 78}, - {0xc016, 78}, - {0x8001, 79}, - {0xc016, 79}, - {0x8001, 80}, - {0xc016, 80}, - {0x8001, 81}, - {0xc016, 81}, - {0x8001, 82}, - {0xc016, 82}, - {0x8001, 83}, - {0xc016, 83}, - {0x8001, 84}, - {0xc016, 84}, - }, - /* 50 */ - { - {0x8002, 77}, - {0x8009, 77}, - {0x8017, 77}, - {0xc028, 77}, - {0x8002, 78}, - {0x8009, 78}, - {0x8017, 78}, - {0xc028, 78}, - {0x8002, 79}, - {0x8009, 79}, - {0x8017, 79}, - {0xc028, 79}, - {0x8002, 80}, - {0x8009, 80}, - {0x8017, 80}, - {0xc028, 80}, - }, - /* 51 */ - { - {0x8003, 77}, - {0x8006, 77}, - {0x800a, 77}, - {0x800f, 77}, - {0x8018, 77}, - {0x801f, 77}, - {0x8029, 77}, - {0xc038, 77}, - {0x8003, 78}, - {0x8006, 78}, - {0x800a, 78}, - {0x800f, 78}, - {0x8018, 78}, - {0x801f, 78}, - {0x8029, 78}, - {0xc038, 78}, - }, - /* 52 */ - { - {0x8003, 79}, - {0x8006, 79}, - {0x800a, 79}, - {0x800f, 79}, - {0x8018, 79}, - {0x801f, 79}, - {0x8029, 79}, - {0xc038, 79}, - {0x8003, 80}, - {0x8006, 80}, - {0x800a, 80}, - {0x800f, 80}, - {0x8018, 80}, - {0x801f, 80}, - {0x8029, 80}, - {0xc038, 80}, - }, - /* 53 */ - { - {0x8002, 81}, - {0x8009, 81}, - {0x8017, 81}, - {0xc028, 81}, - {0x8002, 82}, - {0x8009, 82}, - {0x8017, 82}, - {0xc028, 82}, - {0x8002, 83}, - {0x8009, 83}, - {0x8017, 83}, - {0xc028, 83}, - {0x8002, 84}, - {0x8009, 84}, - {0x8017, 84}, - {0xc028, 84}, - }, - /* 54 */ - { - {0x8003, 81}, - {0x8006, 81}, - {0x800a, 81}, - {0x800f, 81}, - {0x8018, 81}, - {0x801f, 81}, - {0x8029, 81}, - {0xc038, 81}, - {0x8003, 82}, - {0x8006, 82}, - {0x800a, 82}, - {0x800f, 82}, - {0x8018, 82}, - {0x801f, 82}, - {0x8029, 82}, - {0xc038, 82}, - }, - /* 55 */ - { - {0x8003, 83}, - {0x8006, 83}, - {0x800a, 83}, - {0x800f, 83}, - {0x8018, 83}, - {0x801f, 83}, - {0x8029, 83}, - {0xc038, 83}, - {0x8003, 84}, - {0x8006, 84}, - {0x800a, 84}, - {0x800f, 84}, - {0x8018, 84}, - {0x801f, 84}, - {0x8029, 84}, - {0xc038, 84}, - }, - /* 56 */ - { - {0xc000, 85}, - {0xc000, 86}, - {0xc000, 87}, - {0xc000, 89}, - {0xc000, 106}, - {0xc000, 107}, - {0xc000, 113}, - {0xc000, 118}, - {0xc000, 119}, - {0xc000, 120}, - {0xc000, 121}, - {0xc000, 122}, - {0x46, 0}, - {0x47, 0}, - {0x49, 0}, - {0x404a, 0}, - }, - /* 57 */ - { - {0x8001, 85}, - {0xc016, 85}, - {0x8001, 86}, - {0xc016, 86}, - {0x8001, 87}, - {0xc016, 87}, - {0x8001, 89}, - {0xc016, 89}, - {0x8001, 106}, - {0xc016, 106}, - {0x8001, 107}, - {0xc016, 107}, - {0x8001, 113}, - {0xc016, 113}, - {0x8001, 118}, - {0xc016, 118}, - }, - /* 58 */ - { - {0x8002, 85}, - {0x8009, 85}, - {0x8017, 85}, - {0xc028, 85}, - {0x8002, 86}, - {0x8009, 86}, - {0x8017, 86}, - {0xc028, 86}, - {0x8002, 87}, - {0x8009, 87}, - {0x8017, 87}, - {0xc028, 87}, - {0x8002, 89}, - {0x8009, 89}, - {0x8017, 89}, - {0xc028, 89}, - }, - /* 59 */ - { - {0x8003, 85}, - {0x8006, 85}, - {0x800a, 85}, - {0x800f, 85}, - {0x8018, 85}, - {0x801f, 85}, - {0x8029, 85}, - {0xc038, 85}, - {0x8003, 86}, - {0x8006, 86}, - {0x800a, 86}, - {0x800f, 86}, - {0x8018, 86}, - {0x801f, 86}, - {0x8029, 86}, - {0xc038, 86}, - }, - /* 60 */ - { - {0x8003, 87}, - {0x8006, 87}, - {0x800a, 87}, - {0x800f, 87}, - {0x8018, 87}, - {0x801f, 87}, - {0x8029, 87}, - {0xc038, 87}, - {0x8003, 89}, - {0x8006, 89}, - {0x800a, 89}, - {0x800f, 89}, - {0x8018, 89}, - {0x801f, 89}, - {0x8029, 89}, - {0xc038, 89}, - }, - /* 61 */ - { - {0x8002, 106}, - {0x8009, 106}, - {0x8017, 106}, - {0xc028, 106}, - {0x8002, 107}, - {0x8009, 107}, - {0x8017, 107}, - {0xc028, 107}, - {0x8002, 113}, - {0x8009, 113}, - {0x8017, 113}, - {0xc028, 113}, - {0x8002, 118}, - {0x8009, 118}, - {0x8017, 118}, - {0xc028, 118}, - }, - /* 62 */ - { - {0x8003, 106}, - {0x8006, 106}, - {0x800a, 106}, - {0x800f, 106}, - {0x8018, 106}, - {0x801f, 106}, - {0x8029, 106}, - {0xc038, 106}, - {0x8003, 107}, - {0x8006, 107}, - {0x800a, 107}, - {0x800f, 107}, - {0x8018, 107}, - {0x801f, 107}, - {0x8029, 107}, - {0xc038, 107}, - }, - /* 63 */ - { - {0x8003, 113}, - {0x8006, 113}, - {0x800a, 113}, - {0x800f, 113}, - {0x8018, 113}, - {0x801f, 113}, - {0x8029, 113}, - {0xc038, 113}, - {0x8003, 118}, - {0x8006, 118}, - {0x800a, 118}, - {0x800f, 118}, - {0x8018, 118}, - {0x801f, 118}, - {0x8029, 118}, - {0xc038, 118}, - }, - /* 64 */ - { - {0x8001, 119}, - {0xc016, 119}, - {0x8001, 120}, - {0xc016, 120}, - {0x8001, 121}, - {0xc016, 121}, - {0x8001, 122}, - {0xc016, 122}, - {0xc000, 38}, - {0xc000, 42}, - {0xc000, 44}, - {0xc000, 59}, - {0xc000, 88}, - {0xc000, 90}, - {0x4b, 0}, - {0x4e, 0}, - }, - /* 65 */ - { - {0x8002, 119}, - {0x8009, 119}, - {0x8017, 119}, - {0xc028, 119}, - {0x8002, 120}, - {0x8009, 120}, - {0x8017, 120}, - {0xc028, 120}, - {0x8002, 121}, - {0x8009, 121}, - {0x8017, 121}, - {0xc028, 121}, - {0x8002, 122}, - {0x8009, 122}, - {0x8017, 122}, - {0xc028, 122}, - }, - /* 66 */ - { - {0x8003, 119}, - {0x8006, 119}, - {0x800a, 119}, - {0x800f, 119}, - {0x8018, 119}, - {0x801f, 119}, - {0x8029, 119}, - {0xc038, 119}, - {0x8003, 120}, - {0x8006, 120}, - {0x800a, 120}, - {0x800f, 120}, - {0x8018, 120}, - {0x801f, 120}, - {0x8029, 120}, - {0xc038, 120}, - }, - /* 67 */ - { - {0x8003, 121}, - {0x8006, 121}, - {0x800a, 121}, - {0x800f, 121}, - {0x8018, 121}, - {0x801f, 121}, - {0x8029, 121}, - {0xc038, 121}, - {0x8003, 122}, - {0x8006, 122}, - {0x800a, 122}, - {0x800f, 122}, - {0x8018, 122}, - {0x801f, 122}, - {0x8029, 122}, - {0xc038, 122}, - }, - /* 68 */ - { - {0x8001, 38}, - {0xc016, 38}, - {0x8001, 42}, - {0xc016, 42}, - {0x8001, 44}, - {0xc016, 44}, - {0x8001, 59}, - {0xc016, 59}, - {0x8001, 88}, - {0xc016, 88}, - {0x8001, 90}, - {0xc016, 90}, - {0x4c, 0}, - {0x4d, 0}, - {0x4f, 0}, - {0x51, 0}, - }, - /* 69 */ - { - {0x8002, 38}, - {0x8009, 38}, - {0x8017, 38}, - {0xc028, 38}, - {0x8002, 42}, - {0x8009, 42}, - {0x8017, 42}, - {0xc028, 42}, - {0x8002, 44}, - {0x8009, 44}, - {0x8017, 44}, - {0xc028, 44}, - {0x8002, 59}, - {0x8009, 59}, - {0x8017, 59}, - {0xc028, 59}, - }, - /* 70 */ - { - {0x8003, 38}, - {0x8006, 38}, - {0x800a, 38}, - {0x800f, 38}, - {0x8018, 38}, - {0x801f, 38}, - {0x8029, 38}, - {0xc038, 38}, - {0x8003, 42}, - {0x8006, 42}, - {0x800a, 42}, - {0x800f, 42}, - {0x8018, 42}, - {0x801f, 42}, - {0x8029, 42}, - {0xc038, 42}, - }, - /* 71 */ - { - {0x8003, 44}, - {0x8006, 44}, - {0x800a, 44}, - {0x800f, 44}, - {0x8018, 44}, - {0x801f, 44}, - {0x8029, 44}, - {0xc038, 44}, - {0x8003, 59}, - {0x8006, 59}, - {0x800a, 59}, - {0x800f, 59}, - {0x8018, 59}, - {0x801f, 59}, - {0x8029, 59}, - {0xc038, 59}, - }, - /* 72 */ - { - {0x8002, 88}, - {0x8009, 88}, - {0x8017, 88}, - {0xc028, 88}, - {0x8002, 90}, - {0x8009, 90}, - {0x8017, 90}, - {0xc028, 90}, - {0xc000, 33}, - {0xc000, 34}, - {0xc000, 40}, - {0xc000, 41}, - {0xc000, 63}, - {0x50, 0}, - {0x52, 0}, - {0x54, 0}, - }, - /* 73 */ - { - {0x8003, 88}, - {0x8006, 88}, - {0x800a, 88}, - {0x800f, 88}, - {0x8018, 88}, - {0x801f, 88}, - {0x8029, 88}, - {0xc038, 88}, - {0x8003, 90}, - {0x8006, 90}, - {0x800a, 90}, - {0x800f, 90}, - {0x8018, 90}, - {0x801f, 90}, - {0x8029, 90}, - {0xc038, 90}, - }, - /* 74 */ - { - {0x8001, 33}, - {0xc016, 33}, - {0x8001, 34}, - {0xc016, 34}, - {0x8001, 40}, - {0xc016, 40}, - {0x8001, 41}, - {0xc016, 41}, - {0x8001, 63}, - {0xc016, 63}, - {0xc000, 39}, - {0xc000, 43}, - {0xc000, 124}, - {0x53, 0}, - {0x55, 0}, - {0x58, 0}, - }, - /* 75 */ - { - {0x8002, 33}, - {0x8009, 33}, - {0x8017, 33}, - {0xc028, 33}, - {0x8002, 34}, - {0x8009, 34}, - {0x8017, 34}, - {0xc028, 34}, - {0x8002, 40}, - {0x8009, 40}, - {0x8017, 40}, - {0xc028, 40}, - {0x8002, 41}, - {0x8009, 41}, - {0x8017, 41}, - {0xc028, 41}, - }, - /* 76 */ - { - {0x8003, 33}, - {0x8006, 33}, - {0x800a, 33}, - {0x800f, 33}, - {0x8018, 33}, - {0x801f, 33}, - {0x8029, 33}, - {0xc038, 33}, - {0x8003, 34}, - {0x8006, 34}, - {0x800a, 34}, - {0x800f, 34}, - {0x8018, 34}, - {0x801f, 34}, - {0x8029, 34}, - {0xc038, 34}, - }, - /* 77 */ - { - {0x8003, 40}, - {0x8006, 40}, - {0x800a, 40}, - {0x800f, 40}, - {0x8018, 40}, - {0x801f, 40}, - {0x8029, 40}, - {0xc038, 40}, - {0x8003, 41}, - {0x8006, 41}, - {0x800a, 41}, - {0x800f, 41}, - {0x8018, 41}, - {0x801f, 41}, - {0x8029, 41}, - {0xc038, 41}, - }, - /* 78 */ - { - {0x8002, 63}, - {0x8009, 63}, - {0x8017, 63}, - {0xc028, 63}, - {0x8001, 39}, - {0xc016, 39}, - {0x8001, 43}, - {0xc016, 43}, - {0x8001, 124}, - {0xc016, 124}, - {0xc000, 35}, - {0xc000, 62}, - {0x56, 0}, - {0x57, 0}, - {0x59, 0}, - {0x5a, 0}, - }, - /* 79 */ - { - {0x8003, 63}, - {0x8006, 63}, - {0x800a, 63}, - {0x800f, 63}, - {0x8018, 63}, - {0x801f, 63}, - {0x8029, 63}, - {0xc038, 63}, - {0x8002, 39}, - {0x8009, 39}, - {0x8017, 39}, - {0xc028, 39}, - {0x8002, 43}, - {0x8009, 43}, - {0x8017, 43}, - {0xc028, 43}, - }, - /* 80 */ - { - {0x8003, 39}, - {0x8006, 39}, - {0x800a, 39}, - {0x800f, 39}, - {0x8018, 39}, - {0x801f, 39}, - {0x8029, 39}, - {0xc038, 39}, - {0x8003, 43}, - {0x8006, 43}, - {0x800a, 43}, - {0x800f, 43}, - {0x8018, 43}, - {0x801f, 43}, - {0x8029, 43}, - {0xc038, 43}, - }, - /* 81 */ - { - {0x8002, 124}, - {0x8009, 124}, - {0x8017, 124}, - {0xc028, 124}, - {0x8001, 35}, - {0xc016, 35}, - {0x8001, 62}, - {0xc016, 62}, - {0xc000, 0}, - {0xc000, 36}, - {0xc000, 64}, - {0xc000, 91}, - {0xc000, 93}, - {0xc000, 126}, - {0x5b, 0}, - {0x5c, 0}, - }, - /* 82 */ - { - {0x8003, 124}, - {0x8006, 124}, - {0x800a, 124}, - {0x800f, 124}, - {0x8018, 124}, - {0x801f, 124}, - {0x8029, 124}, - {0xc038, 124}, - {0x8002, 35}, - {0x8009, 35}, - {0x8017, 35}, - {0xc028, 35}, - {0x8002, 62}, - {0x8009, 62}, - {0x8017, 62}, - {0xc028, 62}, - }, - /* 83 */ - { - {0x8003, 35}, - {0x8006, 35}, - {0x800a, 35}, - {0x800f, 35}, - {0x8018, 35}, - {0x801f, 35}, - {0x8029, 35}, - {0xc038, 35}, - {0x8003, 62}, - {0x8006, 62}, - {0x800a, 62}, - {0x800f, 62}, - {0x8018, 62}, - {0x801f, 62}, - {0x8029, 62}, - {0xc038, 62}, - }, - /* 84 */ - { - {0x8001, 0}, - {0xc016, 0}, - {0x8001, 36}, - {0xc016, 36}, - {0x8001, 64}, - {0xc016, 64}, - {0x8001, 91}, - {0xc016, 91}, - {0x8001, 93}, - {0xc016, 93}, - {0x8001, 126}, - {0xc016, 126}, - {0xc000, 94}, - {0xc000, 125}, - {0x5d, 0}, - {0x5e, 0}, - }, - /* 85 */ - { - {0x8002, 0}, - {0x8009, 0}, - {0x8017, 0}, - {0xc028, 0}, - {0x8002, 36}, - {0x8009, 36}, - {0x8017, 36}, - {0xc028, 36}, - {0x8002, 64}, - {0x8009, 64}, - {0x8017, 64}, - {0xc028, 64}, - {0x8002, 91}, - {0x8009, 91}, - {0x8017, 91}, - {0xc028, 91}, - }, - /* 86 */ - { - {0x8003, 0}, - {0x8006, 0}, - {0x800a, 0}, - {0x800f, 0}, - {0x8018, 0}, - {0x801f, 0}, - {0x8029, 0}, - {0xc038, 0}, - {0x8003, 36}, - {0x8006, 36}, - {0x800a, 36}, - {0x800f, 36}, - {0x8018, 36}, - {0x801f, 36}, - {0x8029, 36}, - {0xc038, 36}, - }, - /* 87 */ - { - {0x8003, 64}, - {0x8006, 64}, - {0x800a, 64}, - {0x800f, 64}, - {0x8018, 64}, - {0x801f, 64}, - {0x8029, 64}, - {0xc038, 64}, - {0x8003, 91}, - {0x8006, 91}, - {0x800a, 91}, - {0x800f, 91}, - {0x8018, 91}, - {0x801f, 91}, - {0x8029, 91}, - {0xc038, 91}, - }, - /* 88 */ - { - {0x8002, 93}, - {0x8009, 93}, - {0x8017, 93}, - {0xc028, 93}, - {0x8002, 126}, - {0x8009, 126}, - {0x8017, 126}, - {0xc028, 126}, - {0x8001, 94}, - {0xc016, 94}, - {0x8001, 125}, - {0xc016, 125}, - {0xc000, 60}, - {0xc000, 96}, - {0xc000, 123}, - {0x5f, 0}, - }, - /* 89 */ - { - {0x8003, 93}, - {0x8006, 93}, - {0x800a, 93}, - {0x800f, 93}, - {0x8018, 93}, - {0x801f, 93}, - {0x8029, 93}, - {0xc038, 93}, - {0x8003, 126}, - {0x8006, 126}, - {0x800a, 126}, - {0x800f, 126}, - {0x8018, 126}, - {0x801f, 126}, - {0x8029, 126}, - {0xc038, 126}, - }, - /* 90 */ - { - {0x8002, 94}, - {0x8009, 94}, - {0x8017, 94}, - {0xc028, 94}, - {0x8002, 125}, - {0x8009, 125}, - {0x8017, 125}, - {0xc028, 125}, - {0x8001, 60}, - {0xc016, 60}, - {0x8001, 96}, - {0xc016, 96}, - {0x8001, 123}, - {0xc016, 123}, - {0x60, 0}, - {0x6e, 0}, - }, - /* 91 */ - { - {0x8003, 94}, - {0x8006, 94}, - {0x800a, 94}, - {0x800f, 94}, - {0x8018, 94}, - {0x801f, 94}, - {0x8029, 94}, - {0xc038, 94}, - {0x8003, 125}, - {0x8006, 125}, - {0x800a, 125}, - {0x800f, 125}, - {0x8018, 125}, - {0x801f, 125}, - {0x8029, 125}, - {0xc038, 125}, - }, - /* 92 */ - { - {0x8002, 60}, - {0x8009, 60}, - {0x8017, 60}, - {0xc028, 60}, - {0x8002, 96}, - {0x8009, 96}, - {0x8017, 96}, - {0xc028, 96}, - {0x8002, 123}, - {0x8009, 123}, - {0x8017, 123}, - {0xc028, 123}, - {0x61, 0}, - {0x65, 0}, - {0x6f, 0}, - {0x85, 0}, - }, - /* 93 */ - { - {0x8003, 60}, - {0x8006, 60}, - {0x800a, 60}, - {0x800f, 60}, - {0x8018, 60}, - {0x801f, 60}, - {0x8029, 60}, - {0xc038, 60}, - {0x8003, 96}, - {0x8006, 96}, - {0x800a, 96}, - {0x800f, 96}, - {0x8018, 96}, - {0x801f, 96}, - {0x8029, 96}, - {0xc038, 96}, - }, - /* 94 */ - { - {0x8003, 123}, - {0x8006, 123}, - {0x800a, 123}, - {0x800f, 123}, - {0x8018, 123}, - {0x801f, 123}, - {0x8029, 123}, - {0xc038, 123}, - {0x62, 0}, - {0x63, 0}, - {0x66, 0}, - {0x69, 0}, - {0x70, 0}, - {0x77, 0}, - {0x86, 0}, - {0x99, 0}, - }, - /* 95 */ - { - {0xc000, 92}, - {0xc000, 195}, - {0xc000, 208}, - {0x64, 0}, - {0x67, 0}, - {0x68, 0}, - {0x6a, 0}, - {0x6b, 0}, - {0x71, 0}, - {0x74, 0}, - {0x78, 0}, - {0x7e, 0}, - {0x87, 0}, - {0x8e, 0}, - {0x9a, 0}, - {0xa9, 0}, - }, - /* 96 */ - { - {0x8001, 92}, - {0xc016, 92}, - {0x8001, 195}, - {0xc016, 195}, - {0x8001, 208}, - {0xc016, 208}, - {0xc000, 128}, - {0xc000, 130}, - {0xc000, 131}, - {0xc000, 162}, - {0xc000, 184}, - {0xc000, 194}, - {0xc000, 224}, - {0xc000, 226}, - {0x6c, 0}, - {0x6d, 0}, - }, - /* 97 */ - { - {0x8002, 92}, - {0x8009, 92}, - {0x8017, 92}, - {0xc028, 92}, - {0x8002, 195}, - {0x8009, 195}, - {0x8017, 195}, - {0xc028, 195}, - {0x8002, 208}, - {0x8009, 208}, - {0x8017, 208}, - {0xc028, 208}, - {0x8001, 128}, - {0xc016, 128}, - {0x8001, 130}, - {0xc016, 130}, - }, - /* 98 */ - { - {0x8003, 92}, - {0x8006, 92}, - {0x800a, 92}, - {0x800f, 92}, - {0x8018, 92}, - {0x801f, 92}, - {0x8029, 92}, - {0xc038, 92}, - {0x8003, 195}, - {0x8006, 195}, - {0x800a, 195}, - {0x800f, 195}, - {0x8018, 195}, - {0x801f, 195}, - {0x8029, 195}, - {0xc038, 195}, - }, - /* 99 */ - { - {0x8003, 208}, - {0x8006, 208}, - {0x800a, 208}, - {0x800f, 208}, - {0x8018, 208}, - {0x801f, 208}, - {0x8029, 208}, - {0xc038, 208}, - {0x8002, 128}, - {0x8009, 128}, - {0x8017, 128}, - {0xc028, 128}, - {0x8002, 130}, - {0x8009, 130}, - {0x8017, 130}, - {0xc028, 130}, - }, - /* 100 */ - { - {0x8003, 128}, - {0x8006, 128}, - {0x800a, 128}, - {0x800f, 128}, - {0x8018, 128}, - {0x801f, 128}, - {0x8029, 128}, - {0xc038, 128}, - {0x8003, 130}, - {0x8006, 130}, - {0x800a, 130}, - {0x800f, 130}, - {0x8018, 130}, - {0x801f, 130}, - {0x8029, 130}, - {0xc038, 130}, - }, - /* 101 */ - { - {0x8001, 131}, - {0xc016, 131}, - {0x8001, 162}, - {0xc016, 162}, - {0x8001, 184}, - {0xc016, 184}, - {0x8001, 194}, - {0xc016, 194}, - {0x8001, 224}, - {0xc016, 224}, - {0x8001, 226}, - {0xc016, 226}, - {0xc000, 153}, - {0xc000, 161}, - {0xc000, 167}, - {0xc000, 172}, - }, - /* 102 */ - { - {0x8002, 131}, - {0x8009, 131}, - {0x8017, 131}, - {0xc028, 131}, - {0x8002, 162}, - {0x8009, 162}, - {0x8017, 162}, - {0xc028, 162}, - {0x8002, 184}, - {0x8009, 184}, - {0x8017, 184}, - {0xc028, 184}, - {0x8002, 194}, - {0x8009, 194}, - {0x8017, 194}, - {0xc028, 194}, - }, - /* 103 */ - { - {0x8003, 131}, - {0x8006, 131}, - {0x800a, 131}, - {0x800f, 131}, - {0x8018, 131}, - {0x801f, 131}, - {0x8029, 131}, - {0xc038, 131}, - {0x8003, 162}, - {0x8006, 162}, - {0x800a, 162}, - {0x800f, 162}, - {0x8018, 162}, - {0x801f, 162}, - {0x8029, 162}, - {0xc038, 162}, - }, - /* 104 */ - { - {0x8003, 184}, - {0x8006, 184}, - {0x800a, 184}, - {0x800f, 184}, - {0x8018, 184}, - {0x801f, 184}, - {0x8029, 184}, - {0xc038, 184}, - {0x8003, 194}, - {0x8006, 194}, - {0x800a, 194}, - {0x800f, 194}, - {0x8018, 194}, - {0x801f, 194}, - {0x8029, 194}, - {0xc038, 194}, - }, - /* 105 */ - { - {0x8002, 224}, - {0x8009, 224}, - {0x8017, 224}, - {0xc028, 224}, - {0x8002, 226}, - {0x8009, 226}, - {0x8017, 226}, - {0xc028, 226}, - {0x8001, 153}, - {0xc016, 153}, - {0x8001, 161}, - {0xc016, 161}, - {0x8001, 167}, - {0xc016, 167}, - {0x8001, 172}, - {0xc016, 172}, - }, - /* 106 */ - { - {0x8003, 224}, - {0x8006, 224}, - {0x800a, 224}, - {0x800f, 224}, - {0x8018, 224}, - {0x801f, 224}, - {0x8029, 224}, - {0xc038, 224}, - {0x8003, 226}, - {0x8006, 226}, - {0x800a, 226}, - {0x800f, 226}, - {0x8018, 226}, - {0x801f, 226}, - {0x8029, 226}, - {0xc038, 226}, - }, - /* 107 */ - { - {0x8002, 153}, - {0x8009, 153}, - {0x8017, 153}, - {0xc028, 153}, - {0x8002, 161}, - {0x8009, 161}, - {0x8017, 161}, - {0xc028, 161}, - {0x8002, 167}, - {0x8009, 167}, - {0x8017, 167}, - {0xc028, 167}, - {0x8002, 172}, - {0x8009, 172}, - {0x8017, 172}, - {0xc028, 172}, - }, - /* 108 */ - { - {0x8003, 153}, - {0x8006, 153}, - {0x800a, 153}, - {0x800f, 153}, - {0x8018, 153}, - {0x801f, 153}, - {0x8029, 153}, - {0xc038, 153}, - {0x8003, 161}, - {0x8006, 161}, - {0x800a, 161}, - {0x800f, 161}, - {0x8018, 161}, - {0x801f, 161}, - {0x8029, 161}, - {0xc038, 161}, - }, - /* 109 */ - { - {0x8003, 167}, - {0x8006, 167}, - {0x800a, 167}, - {0x800f, 167}, - {0x8018, 167}, - {0x801f, 167}, - {0x8029, 167}, - {0xc038, 167}, - {0x8003, 172}, - {0x8006, 172}, - {0x800a, 172}, - {0x800f, 172}, - {0x8018, 172}, - {0x801f, 172}, - {0x8029, 172}, - {0xc038, 172}, - }, - /* 110 */ - { - {0x72, 0}, - {0x73, 0}, - {0x75, 0}, - {0x76, 0}, - {0x79, 0}, - {0x7b, 0}, - {0x7f, 0}, - {0x82, 0}, - {0x88, 0}, - {0x8b, 0}, - {0x8f, 0}, - {0x92, 0}, - {0x9b, 0}, - {0xa2, 0}, - {0xaa, 0}, - {0xb4, 0}, - }, - /* 111 */ - { - {0xc000, 176}, - {0xc000, 177}, - {0xc000, 179}, - {0xc000, 209}, - {0xc000, 216}, - {0xc000, 217}, - {0xc000, 227}, - {0xc000, 229}, - {0xc000, 230}, - {0x7a, 0}, - {0x7c, 0}, - {0x7d, 0}, - {0x80, 0}, - {0x81, 0}, - {0x83, 0}, - {0x84, 0}, - }, - /* 112 */ - { - {0x8001, 176}, - {0xc016, 176}, - {0x8001, 177}, - {0xc016, 177}, - {0x8001, 179}, - {0xc016, 179}, - {0x8001, 209}, - {0xc016, 209}, - {0x8001, 216}, - {0xc016, 216}, - {0x8001, 217}, - {0xc016, 217}, - {0x8001, 227}, - {0xc016, 227}, - {0x8001, 229}, - {0xc016, 229}, - }, - /* 113 */ - { - {0x8002, 176}, - {0x8009, 176}, - {0x8017, 176}, - {0xc028, 176}, - {0x8002, 177}, - {0x8009, 177}, - {0x8017, 177}, - {0xc028, 177}, - {0x8002, 179}, - {0x8009, 179}, - {0x8017, 179}, - {0xc028, 179}, - {0x8002, 209}, - {0x8009, 209}, - {0x8017, 209}, - {0xc028, 209}, - }, - /* 114 */ - { - {0x8003, 176}, - {0x8006, 176}, - {0x800a, 176}, - {0x800f, 176}, - {0x8018, 176}, - {0x801f, 176}, - {0x8029, 176}, - {0xc038, 176}, - {0x8003, 177}, - {0x8006, 177}, - {0x800a, 177}, - {0x800f, 177}, - {0x8018, 177}, - {0x801f, 177}, - {0x8029, 177}, - {0xc038, 177}, - }, - /* 115 */ - { - {0x8003, 179}, - {0x8006, 179}, - {0x800a, 179}, - {0x800f, 179}, - {0x8018, 179}, - {0x801f, 179}, - {0x8029, 179}, - {0xc038, 179}, - {0x8003, 209}, - {0x8006, 209}, - {0x800a, 209}, - {0x800f, 209}, - {0x8018, 209}, - {0x801f, 209}, - {0x8029, 209}, - {0xc038, 209}, - }, - /* 116 */ - { - {0x8002, 216}, - {0x8009, 216}, - {0x8017, 216}, - {0xc028, 216}, - {0x8002, 217}, - {0x8009, 217}, - {0x8017, 217}, - {0xc028, 217}, - {0x8002, 227}, - {0x8009, 227}, - {0x8017, 227}, - {0xc028, 227}, - {0x8002, 229}, - {0x8009, 229}, - {0x8017, 229}, - {0xc028, 229}, - }, - /* 117 */ - { - {0x8003, 216}, - {0x8006, 216}, - {0x800a, 216}, - {0x800f, 216}, - {0x8018, 216}, - {0x801f, 216}, - {0x8029, 216}, - {0xc038, 216}, - {0x8003, 217}, - {0x8006, 217}, - {0x800a, 217}, - {0x800f, 217}, - {0x8018, 217}, - {0x801f, 217}, - {0x8029, 217}, - {0xc038, 217}, - }, - /* 118 */ - { - {0x8003, 227}, - {0x8006, 227}, - {0x800a, 227}, - {0x800f, 227}, - {0x8018, 227}, - {0x801f, 227}, - {0x8029, 227}, - {0xc038, 227}, - {0x8003, 229}, - {0x8006, 229}, - {0x800a, 229}, - {0x800f, 229}, - {0x8018, 229}, - {0x801f, 229}, - {0x8029, 229}, - {0xc038, 229}, - }, - /* 119 */ - { - {0x8001, 230}, - {0xc016, 230}, - {0xc000, 129}, - {0xc000, 132}, - {0xc000, 133}, - {0xc000, 134}, - {0xc000, 136}, - {0xc000, 146}, - {0xc000, 154}, - {0xc000, 156}, - {0xc000, 160}, - {0xc000, 163}, - {0xc000, 164}, - {0xc000, 169}, - {0xc000, 170}, - {0xc000, 173}, - }, - /* 120 */ - { - {0x8002, 230}, - {0x8009, 230}, - {0x8017, 230}, - {0xc028, 230}, - {0x8001, 129}, - {0xc016, 129}, - {0x8001, 132}, - {0xc016, 132}, - {0x8001, 133}, - {0xc016, 133}, - {0x8001, 134}, - {0xc016, 134}, - {0x8001, 136}, - {0xc016, 136}, - {0x8001, 146}, - {0xc016, 146}, - }, - /* 121 */ - { - {0x8003, 230}, - {0x8006, 230}, - {0x800a, 230}, - {0x800f, 230}, - {0x8018, 230}, - {0x801f, 230}, - {0x8029, 230}, - {0xc038, 230}, - {0x8002, 129}, - {0x8009, 129}, - {0x8017, 129}, - {0xc028, 129}, - {0x8002, 132}, - {0x8009, 132}, - {0x8017, 132}, - {0xc028, 132}, - }, - /* 122 */ - { - {0x8003, 129}, - {0x8006, 129}, - {0x800a, 129}, - {0x800f, 129}, - {0x8018, 129}, - {0x801f, 129}, - {0x8029, 129}, - {0xc038, 129}, - {0x8003, 132}, - {0x8006, 132}, - {0x800a, 132}, - {0x800f, 132}, - {0x8018, 132}, - {0x801f, 132}, - {0x8029, 132}, - {0xc038, 132}, - }, - /* 123 */ - { - {0x8002, 133}, - {0x8009, 133}, - {0x8017, 133}, - {0xc028, 133}, - {0x8002, 134}, - {0x8009, 134}, - {0x8017, 134}, - {0xc028, 134}, - {0x8002, 136}, - {0x8009, 136}, - {0x8017, 136}, - {0xc028, 136}, - {0x8002, 146}, - {0x8009, 146}, - {0x8017, 146}, - {0xc028, 146}, - }, - /* 124 */ - { - {0x8003, 133}, - {0x8006, 133}, - {0x800a, 133}, - {0x800f, 133}, - {0x8018, 133}, - {0x801f, 133}, - {0x8029, 133}, - {0xc038, 133}, - {0x8003, 134}, - {0x8006, 134}, - {0x800a, 134}, - {0x800f, 134}, - {0x8018, 134}, - {0x801f, 134}, - {0x8029, 134}, - {0xc038, 134}, - }, - /* 125 */ - { - {0x8003, 136}, - {0x8006, 136}, - {0x800a, 136}, - {0x800f, 136}, - {0x8018, 136}, - {0x801f, 136}, - {0x8029, 136}, - {0xc038, 136}, - {0x8003, 146}, - {0x8006, 146}, - {0x800a, 146}, - {0x800f, 146}, - {0x8018, 146}, - {0x801f, 146}, - {0x8029, 146}, - {0xc038, 146}, - }, - /* 126 */ - { - {0x8001, 154}, - {0xc016, 154}, - {0x8001, 156}, - {0xc016, 156}, - {0x8001, 160}, - {0xc016, 160}, - {0x8001, 163}, - {0xc016, 163}, - {0x8001, 164}, - {0xc016, 164}, - {0x8001, 169}, - {0xc016, 169}, - {0x8001, 170}, - {0xc016, 170}, - {0x8001, 173}, - {0xc016, 173}, - }, - /* 127 */ - { - {0x8002, 154}, - {0x8009, 154}, - {0x8017, 154}, - {0xc028, 154}, - {0x8002, 156}, - {0x8009, 156}, - {0x8017, 156}, - {0xc028, 156}, - {0x8002, 160}, - {0x8009, 160}, - {0x8017, 160}, - {0xc028, 160}, - {0x8002, 163}, - {0x8009, 163}, - {0x8017, 163}, - {0xc028, 163}, - }, - /* 128 */ - { - {0x8003, 154}, - {0x8006, 154}, - {0x800a, 154}, - {0x800f, 154}, - {0x8018, 154}, - {0x801f, 154}, - {0x8029, 154}, - {0xc038, 154}, - {0x8003, 156}, - {0x8006, 156}, - {0x800a, 156}, - {0x800f, 156}, - {0x8018, 156}, - {0x801f, 156}, - {0x8029, 156}, - {0xc038, 156}, - }, - /* 129 */ - { - {0x8003, 160}, - {0x8006, 160}, - {0x800a, 160}, - {0x800f, 160}, - {0x8018, 160}, - {0x801f, 160}, - {0x8029, 160}, - {0xc038, 160}, - {0x8003, 163}, - {0x8006, 163}, - {0x800a, 163}, - {0x800f, 163}, - {0x8018, 163}, - {0x801f, 163}, - {0x8029, 163}, - {0xc038, 163}, - }, - /* 130 */ - { - {0x8002, 164}, - {0x8009, 164}, - {0x8017, 164}, - {0xc028, 164}, - {0x8002, 169}, - {0x8009, 169}, - {0x8017, 169}, - {0xc028, 169}, - {0x8002, 170}, - {0x8009, 170}, - {0x8017, 170}, - {0xc028, 170}, - {0x8002, 173}, - {0x8009, 173}, - {0x8017, 173}, - {0xc028, 173}, - }, - /* 131 */ - { - {0x8003, 164}, - {0x8006, 164}, - {0x800a, 164}, - {0x800f, 164}, - {0x8018, 164}, - {0x801f, 164}, - {0x8029, 164}, - {0xc038, 164}, - {0x8003, 169}, - {0x8006, 169}, - {0x800a, 169}, - {0x800f, 169}, - {0x8018, 169}, - {0x801f, 169}, - {0x8029, 169}, - {0xc038, 169}, - }, - /* 132 */ - { - {0x8003, 170}, - {0x8006, 170}, - {0x800a, 170}, - {0x800f, 170}, - {0x8018, 170}, - {0x801f, 170}, - {0x8029, 170}, - {0xc038, 170}, - {0x8003, 173}, - {0x8006, 173}, - {0x800a, 173}, - {0x800f, 173}, - {0x8018, 173}, - {0x801f, 173}, - {0x8029, 173}, - {0xc038, 173}, - }, - /* 133 */ - { - {0x89, 0}, - {0x8a, 0}, - {0x8c, 0}, - {0x8d, 0}, - {0x90, 0}, - {0x91, 0}, - {0x93, 0}, - {0x96, 0}, - {0x9c, 0}, - {0x9f, 0}, - {0xa3, 0}, - {0xa6, 0}, - {0xab, 0}, - {0xae, 0}, - {0xb5, 0}, - {0xbe, 0}, - }, - /* 134 */ - { - {0xc000, 178}, - {0xc000, 181}, - {0xc000, 185}, - {0xc000, 186}, - {0xc000, 187}, - {0xc000, 189}, - {0xc000, 190}, - {0xc000, 196}, - {0xc000, 198}, - {0xc000, 228}, - {0xc000, 232}, - {0xc000, 233}, - {0x94, 0}, - {0x95, 0}, - {0x97, 0}, - {0x98, 0}, - }, - /* 135 */ - { - {0x8001, 178}, - {0xc016, 178}, - {0x8001, 181}, - {0xc016, 181}, - {0x8001, 185}, - {0xc016, 185}, - {0x8001, 186}, - {0xc016, 186}, - {0x8001, 187}, - {0xc016, 187}, - {0x8001, 189}, - {0xc016, 189}, - {0x8001, 190}, - {0xc016, 190}, - {0x8001, 196}, - {0xc016, 196}, - }, - /* 136 */ - { - {0x8002, 178}, - {0x8009, 178}, - {0x8017, 178}, - {0xc028, 178}, - {0x8002, 181}, - {0x8009, 181}, - {0x8017, 181}, - {0xc028, 181}, - {0x8002, 185}, - {0x8009, 185}, - {0x8017, 185}, - {0xc028, 185}, - {0x8002, 186}, - {0x8009, 186}, - {0x8017, 186}, - {0xc028, 186}, - }, - /* 137 */ - { - {0x8003, 178}, - {0x8006, 178}, - {0x800a, 178}, - {0x800f, 178}, - {0x8018, 178}, - {0x801f, 178}, - {0x8029, 178}, - {0xc038, 178}, - {0x8003, 181}, - {0x8006, 181}, - {0x800a, 181}, - {0x800f, 181}, - {0x8018, 181}, - {0x801f, 181}, - {0x8029, 181}, - {0xc038, 181}, - }, - /* 138 */ - { - {0x8003, 185}, - {0x8006, 185}, - {0x800a, 185}, - {0x800f, 185}, - {0x8018, 185}, - {0x801f, 185}, - {0x8029, 185}, - {0xc038, 185}, - {0x8003, 186}, - {0x8006, 186}, - {0x800a, 186}, - {0x800f, 186}, - {0x8018, 186}, - {0x801f, 186}, - {0x8029, 186}, - {0xc038, 186}, - }, - /* 139 */ - { - {0x8002, 187}, - {0x8009, 187}, - {0x8017, 187}, - {0xc028, 187}, - {0x8002, 189}, - {0x8009, 189}, - {0x8017, 189}, - {0xc028, 189}, - {0x8002, 190}, - {0x8009, 190}, - {0x8017, 190}, - {0xc028, 190}, - {0x8002, 196}, - {0x8009, 196}, - {0x8017, 196}, - {0xc028, 196}, - }, - /* 140 */ - { - {0x8003, 187}, - {0x8006, 187}, - {0x800a, 187}, - {0x800f, 187}, - {0x8018, 187}, - {0x801f, 187}, - {0x8029, 187}, - {0xc038, 187}, - {0x8003, 189}, - {0x8006, 189}, - {0x800a, 189}, - {0x800f, 189}, - {0x8018, 189}, - {0x801f, 189}, - {0x8029, 189}, - {0xc038, 189}, - }, - /* 141 */ - { - {0x8003, 190}, - {0x8006, 190}, - {0x800a, 190}, - {0x800f, 190}, - {0x8018, 190}, - {0x801f, 190}, - {0x8029, 190}, - {0xc038, 190}, - {0x8003, 196}, - {0x8006, 196}, - {0x800a, 196}, - {0x800f, 196}, - {0x8018, 196}, - {0x801f, 196}, - {0x8029, 196}, - {0xc038, 196}, - }, - /* 142 */ - { - {0x8001, 198}, - {0xc016, 198}, - {0x8001, 228}, - {0xc016, 228}, - {0x8001, 232}, - {0xc016, 232}, - {0x8001, 233}, - {0xc016, 233}, - {0xc000, 1}, - {0xc000, 135}, - {0xc000, 137}, - {0xc000, 138}, - {0xc000, 139}, - {0xc000, 140}, - {0xc000, 141}, - {0xc000, 143}, - }, - /* 143 */ - { - {0x8002, 198}, - {0x8009, 198}, - {0x8017, 198}, - {0xc028, 198}, - {0x8002, 228}, - {0x8009, 228}, - {0x8017, 228}, - {0xc028, 228}, - {0x8002, 232}, - {0x8009, 232}, - {0x8017, 232}, - {0xc028, 232}, - {0x8002, 233}, - {0x8009, 233}, - {0x8017, 233}, - {0xc028, 233}, - }, - /* 144 */ - { - {0x8003, 198}, - {0x8006, 198}, - {0x800a, 198}, - {0x800f, 198}, - {0x8018, 198}, - {0x801f, 198}, - {0x8029, 198}, - {0xc038, 198}, - {0x8003, 228}, - {0x8006, 228}, - {0x800a, 228}, - {0x800f, 228}, - {0x8018, 228}, - {0x801f, 228}, - {0x8029, 228}, - {0xc038, 228}, - }, - /* 145 */ - { - {0x8003, 232}, - {0x8006, 232}, - {0x800a, 232}, - {0x800f, 232}, - {0x8018, 232}, - {0x801f, 232}, - {0x8029, 232}, - {0xc038, 232}, - {0x8003, 233}, - {0x8006, 233}, - {0x800a, 233}, - {0x800f, 233}, - {0x8018, 233}, - {0x801f, 233}, - {0x8029, 233}, - {0xc038, 233}, - }, - /* 146 */ - { - {0x8001, 1}, - {0xc016, 1}, - {0x8001, 135}, - {0xc016, 135}, - {0x8001, 137}, - {0xc016, 137}, - {0x8001, 138}, - {0xc016, 138}, - {0x8001, 139}, - {0xc016, 139}, - {0x8001, 140}, - {0xc016, 140}, - {0x8001, 141}, - {0xc016, 141}, - {0x8001, 143}, - {0xc016, 143}, - }, - /* 147 */ - { - {0x8002, 1}, - {0x8009, 1}, - {0x8017, 1}, - {0xc028, 1}, - {0x8002, 135}, - {0x8009, 135}, - {0x8017, 135}, - {0xc028, 135}, - {0x8002, 137}, - {0x8009, 137}, - {0x8017, 137}, - {0xc028, 137}, - {0x8002, 138}, - {0x8009, 138}, - {0x8017, 138}, - {0xc028, 138}, - }, - /* 148 */ - { - {0x8003, 1}, - {0x8006, 1}, - {0x800a, 1}, - {0x800f, 1}, - {0x8018, 1}, - {0x801f, 1}, - {0x8029, 1}, - {0xc038, 1}, - {0x8003, 135}, - {0x8006, 135}, - {0x800a, 135}, - {0x800f, 135}, - {0x8018, 135}, - {0x801f, 135}, - {0x8029, 135}, - {0xc038, 135}, - }, - /* 149 */ - { - {0x8003, 137}, - {0x8006, 137}, - {0x800a, 137}, - {0x800f, 137}, - {0x8018, 137}, - {0x801f, 137}, - {0x8029, 137}, - {0xc038, 137}, - {0x8003, 138}, - {0x8006, 138}, - {0x800a, 138}, - {0x800f, 138}, - {0x8018, 138}, - {0x801f, 138}, - {0x8029, 138}, - {0xc038, 138}, - }, - /* 150 */ - { - {0x8002, 139}, - {0x8009, 139}, - {0x8017, 139}, - {0xc028, 139}, - {0x8002, 140}, - {0x8009, 140}, - {0x8017, 140}, - {0xc028, 140}, - {0x8002, 141}, - {0x8009, 141}, - {0x8017, 141}, - {0xc028, 141}, - {0x8002, 143}, - {0x8009, 143}, - {0x8017, 143}, - {0xc028, 143}, - }, - /* 151 */ - { - {0x8003, 139}, - {0x8006, 139}, - {0x800a, 139}, - {0x800f, 139}, - {0x8018, 139}, - {0x801f, 139}, - {0x8029, 139}, - {0xc038, 139}, - {0x8003, 140}, - {0x8006, 140}, - {0x800a, 140}, - {0x800f, 140}, - {0x8018, 140}, - {0x801f, 140}, - {0x8029, 140}, - {0xc038, 140}, - }, - /* 152 */ - { - {0x8003, 141}, - {0x8006, 141}, - {0x800a, 141}, - {0x800f, 141}, - {0x8018, 141}, - {0x801f, 141}, - {0x8029, 141}, - {0xc038, 141}, - {0x8003, 143}, - {0x8006, 143}, - {0x800a, 143}, - {0x800f, 143}, - {0x8018, 143}, - {0x801f, 143}, - {0x8029, 143}, - {0xc038, 143}, - }, - /* 153 */ - { - {0x9d, 0}, - {0x9e, 0}, - {0xa0, 0}, - {0xa1, 0}, - {0xa4, 0}, - {0xa5, 0}, - {0xa7, 0}, - {0xa8, 0}, - {0xac, 0}, - {0xad, 0}, - {0xaf, 0}, - {0xb1, 0}, - {0xb6, 0}, - {0xb9, 0}, - {0xbf, 0}, - {0xcf, 0}, - }, - /* 154 */ - { - {0xc000, 147}, - {0xc000, 149}, - {0xc000, 150}, - {0xc000, 151}, - {0xc000, 152}, - {0xc000, 155}, - {0xc000, 157}, - {0xc000, 158}, - {0xc000, 165}, - {0xc000, 166}, - {0xc000, 168}, - {0xc000, 174}, - {0xc000, 175}, - {0xc000, 180}, - {0xc000, 182}, - {0xc000, 183}, - }, - /* 155 */ - { - {0x8001, 147}, - {0xc016, 147}, - {0x8001, 149}, - {0xc016, 149}, - {0x8001, 150}, - {0xc016, 150}, - {0x8001, 151}, - {0xc016, 151}, - {0x8001, 152}, - {0xc016, 152}, - {0x8001, 155}, - {0xc016, 155}, - {0x8001, 157}, - {0xc016, 157}, - {0x8001, 158}, - {0xc016, 158}, - }, - /* 156 */ - { - {0x8002, 147}, - {0x8009, 147}, - {0x8017, 147}, - {0xc028, 147}, - {0x8002, 149}, - {0x8009, 149}, - {0x8017, 149}, - {0xc028, 149}, - {0x8002, 150}, - {0x8009, 150}, - {0x8017, 150}, - {0xc028, 150}, - {0x8002, 151}, - {0x8009, 151}, - {0x8017, 151}, - {0xc028, 151}, - }, - /* 157 */ - { - {0x8003, 147}, - {0x8006, 147}, - {0x800a, 147}, - {0x800f, 147}, - {0x8018, 147}, - {0x801f, 147}, - {0x8029, 147}, - {0xc038, 147}, - {0x8003, 149}, - {0x8006, 149}, - {0x800a, 149}, - {0x800f, 149}, - {0x8018, 149}, - {0x801f, 149}, - {0x8029, 149}, - {0xc038, 149}, - }, - /* 158 */ - { - {0x8003, 150}, - {0x8006, 150}, - {0x800a, 150}, - {0x800f, 150}, - {0x8018, 150}, - {0x801f, 150}, - {0x8029, 150}, - {0xc038, 150}, - {0x8003, 151}, - {0x8006, 151}, - {0x800a, 151}, - {0x800f, 151}, - {0x8018, 151}, - {0x801f, 151}, - {0x8029, 151}, - {0xc038, 151}, - }, - /* 159 */ - { - {0x8002, 152}, - {0x8009, 152}, - {0x8017, 152}, - {0xc028, 152}, - {0x8002, 155}, - {0x8009, 155}, - {0x8017, 155}, - {0xc028, 155}, - {0x8002, 157}, - {0x8009, 157}, - {0x8017, 157}, - {0xc028, 157}, - {0x8002, 158}, - {0x8009, 158}, - {0x8017, 158}, - {0xc028, 158}, - }, - /* 160 */ - { - {0x8003, 152}, - {0x8006, 152}, - {0x800a, 152}, - {0x800f, 152}, - {0x8018, 152}, - {0x801f, 152}, - {0x8029, 152}, - {0xc038, 152}, - {0x8003, 155}, - {0x8006, 155}, - {0x800a, 155}, - {0x800f, 155}, - {0x8018, 155}, - {0x801f, 155}, - {0x8029, 155}, - {0xc038, 155}, - }, - /* 161 */ - { - {0x8003, 157}, - {0x8006, 157}, - {0x800a, 157}, - {0x800f, 157}, - {0x8018, 157}, - {0x801f, 157}, - {0x8029, 157}, - {0xc038, 157}, - {0x8003, 158}, - {0x8006, 158}, - {0x800a, 158}, - {0x800f, 158}, - {0x8018, 158}, - {0x801f, 158}, - {0x8029, 158}, - {0xc038, 158}, - }, - /* 162 */ - { - {0x8001, 165}, - {0xc016, 165}, - {0x8001, 166}, - {0xc016, 166}, - {0x8001, 168}, - {0xc016, 168}, - {0x8001, 174}, - {0xc016, 174}, - {0x8001, 175}, - {0xc016, 175}, - {0x8001, 180}, - {0xc016, 180}, - {0x8001, 182}, - {0xc016, 182}, - {0x8001, 183}, - {0xc016, 183}, - }, - /* 163 */ - { - {0x8002, 165}, - {0x8009, 165}, - {0x8017, 165}, - {0xc028, 165}, - {0x8002, 166}, - {0x8009, 166}, - {0x8017, 166}, - {0xc028, 166}, - {0x8002, 168}, - {0x8009, 168}, - {0x8017, 168}, - {0xc028, 168}, - {0x8002, 174}, - {0x8009, 174}, - {0x8017, 174}, - {0xc028, 174}, - }, - /* 164 */ - { - {0x8003, 165}, - {0x8006, 165}, - {0x800a, 165}, - {0x800f, 165}, - {0x8018, 165}, - {0x801f, 165}, - {0x8029, 165}, - {0xc038, 165}, - {0x8003, 166}, - {0x8006, 166}, - {0x800a, 166}, - {0x800f, 166}, - {0x8018, 166}, - {0x801f, 166}, - {0x8029, 166}, - {0xc038, 166}, - }, - /* 165 */ - { - {0x8003, 168}, - {0x8006, 168}, - {0x800a, 168}, - {0x800f, 168}, - {0x8018, 168}, - {0x801f, 168}, - {0x8029, 168}, - {0xc038, 168}, - {0x8003, 174}, - {0x8006, 174}, - {0x800a, 174}, - {0x800f, 174}, - {0x8018, 174}, - {0x801f, 174}, - {0x8029, 174}, - {0xc038, 174}, - }, - /* 166 */ - { - {0x8002, 175}, - {0x8009, 175}, - {0x8017, 175}, - {0xc028, 175}, - {0x8002, 180}, - {0x8009, 180}, - {0x8017, 180}, - {0xc028, 180}, - {0x8002, 182}, - {0x8009, 182}, - {0x8017, 182}, - {0xc028, 182}, - {0x8002, 183}, - {0x8009, 183}, - {0x8017, 183}, - {0xc028, 183}, - }, - /* 167 */ - { - {0x8003, 175}, - {0x8006, 175}, - {0x800a, 175}, - {0x800f, 175}, - {0x8018, 175}, - {0x801f, 175}, - {0x8029, 175}, - {0xc038, 175}, - {0x8003, 180}, - {0x8006, 180}, - {0x800a, 180}, - {0x800f, 180}, - {0x8018, 180}, - {0x801f, 180}, - {0x8029, 180}, - {0xc038, 180}, - }, - /* 168 */ - { - {0x8003, 182}, - {0x8006, 182}, - {0x800a, 182}, - {0x800f, 182}, - {0x8018, 182}, - {0x801f, 182}, - {0x8029, 182}, - {0xc038, 182}, - {0x8003, 183}, - {0x8006, 183}, - {0x800a, 183}, - {0x800f, 183}, - {0x8018, 183}, - {0x801f, 183}, - {0x8029, 183}, - {0xc038, 183}, - }, - /* 169 */ - { - {0xc000, 188}, - {0xc000, 191}, - {0xc000, 197}, - {0xc000, 231}, - {0xc000, 239}, - {0xb0, 0}, - {0xb2, 0}, - {0xb3, 0}, - {0xb7, 0}, - {0xb8, 0}, - {0xba, 0}, - {0xbb, 0}, - {0xc0, 0}, - {0xc7, 0}, - {0xd0, 0}, - {0xdf, 0}, - }, - /* 170 */ - { - {0x8001, 188}, - {0xc016, 188}, - {0x8001, 191}, - {0xc016, 191}, - {0x8001, 197}, - {0xc016, 197}, - {0x8001, 231}, - {0xc016, 231}, - {0x8001, 239}, - {0xc016, 239}, - {0xc000, 9}, - {0xc000, 142}, - {0xc000, 144}, - {0xc000, 145}, - {0xc000, 148}, - {0xc000, 159}, - }, - /* 171 */ - { - {0x8002, 188}, - {0x8009, 188}, - {0x8017, 188}, - {0xc028, 188}, - {0x8002, 191}, - {0x8009, 191}, - {0x8017, 191}, - {0xc028, 191}, - {0x8002, 197}, - {0x8009, 197}, - {0x8017, 197}, - {0xc028, 197}, - {0x8002, 231}, - {0x8009, 231}, - {0x8017, 231}, - {0xc028, 231}, - }, - /* 172 */ - { - {0x8003, 188}, - {0x8006, 188}, - {0x800a, 188}, - {0x800f, 188}, - {0x8018, 188}, - {0x801f, 188}, - {0x8029, 188}, - {0xc038, 188}, - {0x8003, 191}, - {0x8006, 191}, - {0x800a, 191}, - {0x800f, 191}, - {0x8018, 191}, - {0x801f, 191}, - {0x8029, 191}, - {0xc038, 191}, - }, - /* 173 */ - { - {0x8003, 197}, - {0x8006, 197}, - {0x800a, 197}, - {0x800f, 197}, - {0x8018, 197}, - {0x801f, 197}, - {0x8029, 197}, - {0xc038, 197}, - {0x8003, 231}, - {0x8006, 231}, - {0x800a, 231}, - {0x800f, 231}, - {0x8018, 231}, - {0x801f, 231}, - {0x8029, 231}, - {0xc038, 231}, - }, - /* 174 */ - { - {0x8002, 239}, - {0x8009, 239}, - {0x8017, 239}, - {0xc028, 239}, - {0x8001, 9}, - {0xc016, 9}, - {0x8001, 142}, - {0xc016, 142}, - {0x8001, 144}, - {0xc016, 144}, - {0x8001, 145}, - {0xc016, 145}, - {0x8001, 148}, - {0xc016, 148}, - {0x8001, 159}, - {0xc016, 159}, - }, - /* 175 */ - { - {0x8003, 239}, - {0x8006, 239}, - {0x800a, 239}, - {0x800f, 239}, - {0x8018, 239}, - {0x801f, 239}, - {0x8029, 239}, - {0xc038, 239}, - {0x8002, 9}, - {0x8009, 9}, - {0x8017, 9}, - {0xc028, 9}, - {0x8002, 142}, - {0x8009, 142}, - {0x8017, 142}, - {0xc028, 142}, - }, - /* 176 */ - { - {0x8003, 9}, - {0x8006, 9}, - {0x800a, 9}, - {0x800f, 9}, - {0x8018, 9}, - {0x801f, 9}, - {0x8029, 9}, - {0xc038, 9}, - {0x8003, 142}, - {0x8006, 142}, - {0x800a, 142}, - {0x800f, 142}, - {0x8018, 142}, - {0x801f, 142}, - {0x8029, 142}, - {0xc038, 142}, - }, - /* 177 */ - { - {0x8002, 144}, - {0x8009, 144}, - {0x8017, 144}, - {0xc028, 144}, - {0x8002, 145}, - {0x8009, 145}, - {0x8017, 145}, - {0xc028, 145}, - {0x8002, 148}, - {0x8009, 148}, - {0x8017, 148}, - {0xc028, 148}, - {0x8002, 159}, - {0x8009, 159}, - {0x8017, 159}, - {0xc028, 159}, - }, - /* 178 */ - { - {0x8003, 144}, - {0x8006, 144}, - {0x800a, 144}, - {0x800f, 144}, - {0x8018, 144}, - {0x801f, 144}, - {0x8029, 144}, - {0xc038, 144}, - {0x8003, 145}, - {0x8006, 145}, - {0x800a, 145}, - {0x800f, 145}, - {0x8018, 145}, - {0x801f, 145}, - {0x8029, 145}, - {0xc038, 145}, - }, - /* 179 */ - { - {0x8003, 148}, - {0x8006, 148}, - {0x800a, 148}, - {0x800f, 148}, - {0x8018, 148}, - {0x801f, 148}, - {0x8029, 148}, - {0xc038, 148}, - {0x8003, 159}, - {0x8006, 159}, - {0x800a, 159}, - {0x800f, 159}, - {0x8018, 159}, - {0x801f, 159}, - {0x8029, 159}, - {0xc038, 159}, - }, - /* 180 */ - { - {0xc000, 171}, - {0xc000, 206}, - {0xc000, 215}, - {0xc000, 225}, - {0xc000, 236}, - {0xc000, 237}, - {0xbc, 0}, - {0xbd, 0}, - {0xc1, 0}, - {0xc4, 0}, - {0xc8, 0}, - {0xcb, 0}, - {0xd1, 0}, - {0xd8, 0}, - {0xe0, 0}, - {0xee, 0}, - }, - /* 181 */ - { - {0x8001, 171}, - {0xc016, 171}, - {0x8001, 206}, - {0xc016, 206}, - {0x8001, 215}, - {0xc016, 215}, - {0x8001, 225}, - {0xc016, 225}, - {0x8001, 236}, - {0xc016, 236}, - {0x8001, 237}, - {0xc016, 237}, - {0xc000, 199}, - {0xc000, 207}, - {0xc000, 234}, - {0xc000, 235}, - }, - /* 182 */ - { - {0x8002, 171}, - {0x8009, 171}, - {0x8017, 171}, - {0xc028, 171}, - {0x8002, 206}, - {0x8009, 206}, - {0x8017, 206}, - {0xc028, 206}, - {0x8002, 215}, - {0x8009, 215}, - {0x8017, 215}, - {0xc028, 215}, - {0x8002, 225}, - {0x8009, 225}, - {0x8017, 225}, - {0xc028, 225}, - }, - /* 183 */ - { - {0x8003, 171}, - {0x8006, 171}, - {0x800a, 171}, - {0x800f, 171}, - {0x8018, 171}, - {0x801f, 171}, - {0x8029, 171}, - {0xc038, 171}, - {0x8003, 206}, - {0x8006, 206}, - {0x800a, 206}, - {0x800f, 206}, - {0x8018, 206}, - {0x801f, 206}, - {0x8029, 206}, - {0xc038, 206}, - }, - /* 184 */ - { - {0x8003, 215}, - {0x8006, 215}, - {0x800a, 215}, - {0x800f, 215}, - {0x8018, 215}, - {0x801f, 215}, - {0x8029, 215}, - {0xc038, 215}, - {0x8003, 225}, - {0x8006, 225}, - {0x800a, 225}, - {0x800f, 225}, - {0x8018, 225}, - {0x801f, 225}, - {0x8029, 225}, - {0xc038, 225}, - }, - /* 185 */ - { - {0x8002, 236}, - {0x8009, 236}, - {0x8017, 236}, - {0xc028, 236}, - {0x8002, 237}, - {0x8009, 237}, - {0x8017, 237}, - {0xc028, 237}, - {0x8001, 199}, - {0xc016, 199}, - {0x8001, 207}, - {0xc016, 207}, - {0x8001, 234}, - {0xc016, 234}, - {0x8001, 235}, - {0xc016, 235}, - }, - /* 186 */ - { - {0x8003, 236}, - {0x8006, 236}, - {0x800a, 236}, - {0x800f, 236}, - {0x8018, 236}, - {0x801f, 236}, - {0x8029, 236}, - {0xc038, 236}, - {0x8003, 237}, - {0x8006, 237}, - {0x800a, 237}, - {0x800f, 237}, - {0x8018, 237}, - {0x801f, 237}, - {0x8029, 237}, - {0xc038, 237}, - }, - /* 187 */ - { - {0x8002, 199}, - {0x8009, 199}, - {0x8017, 199}, - {0xc028, 199}, - {0x8002, 207}, - {0x8009, 207}, - {0x8017, 207}, - {0xc028, 207}, - {0x8002, 234}, - {0x8009, 234}, - {0x8017, 234}, - {0xc028, 234}, - {0x8002, 235}, - {0x8009, 235}, - {0x8017, 235}, - {0xc028, 235}, - }, - /* 188 */ - { - {0x8003, 199}, - {0x8006, 199}, - {0x800a, 199}, - {0x800f, 199}, - {0x8018, 199}, - {0x801f, 199}, - {0x8029, 199}, - {0xc038, 199}, - {0x8003, 207}, - {0x8006, 207}, - {0x800a, 207}, - {0x800f, 207}, - {0x8018, 207}, - {0x801f, 207}, - {0x8029, 207}, - {0xc038, 207}, - }, - /* 189 */ - { - {0x8003, 234}, - {0x8006, 234}, - {0x800a, 234}, - {0x800f, 234}, - {0x8018, 234}, - {0x801f, 234}, - {0x8029, 234}, - {0xc038, 234}, - {0x8003, 235}, - {0x8006, 235}, - {0x800a, 235}, - {0x800f, 235}, - {0x8018, 235}, - {0x801f, 235}, - {0x8029, 235}, - {0xc038, 235}, - }, - /* 190 */ - { - {0xc2, 0}, - {0xc3, 0}, - {0xc5, 0}, - {0xc6, 0}, - {0xc9, 0}, - {0xca, 0}, - {0xcc, 0}, - {0xcd, 0}, - {0xd2, 0}, - {0xd5, 0}, - {0xd9, 0}, - {0xdc, 0}, - {0xe1, 0}, - {0xe7, 0}, - {0xef, 0}, - {0xf6, 0}, - }, - /* 191 */ - { - {0xc000, 192}, - {0xc000, 193}, - {0xc000, 200}, - {0xc000, 201}, - {0xc000, 202}, - {0xc000, 205}, - {0xc000, 210}, - {0xc000, 213}, - {0xc000, 218}, - {0xc000, 219}, - {0xc000, 238}, - {0xc000, 240}, - {0xc000, 242}, - {0xc000, 243}, - {0xc000, 255}, - {0xce, 0}, - }, - /* 192 */ - { - {0x8001, 192}, - {0xc016, 192}, - {0x8001, 193}, - {0xc016, 193}, - {0x8001, 200}, - {0xc016, 200}, - {0x8001, 201}, - {0xc016, 201}, - {0x8001, 202}, - {0xc016, 202}, - {0x8001, 205}, - {0xc016, 205}, - {0x8001, 210}, - {0xc016, 210}, - {0x8001, 213}, - {0xc016, 213}, - }, - /* 193 */ - { - {0x8002, 192}, - {0x8009, 192}, - {0x8017, 192}, - {0xc028, 192}, - {0x8002, 193}, - {0x8009, 193}, - {0x8017, 193}, - {0xc028, 193}, - {0x8002, 200}, - {0x8009, 200}, - {0x8017, 200}, - {0xc028, 200}, - {0x8002, 201}, - {0x8009, 201}, - {0x8017, 201}, - {0xc028, 201}, - }, - /* 194 */ - { - {0x8003, 192}, - {0x8006, 192}, - {0x800a, 192}, - {0x800f, 192}, - {0x8018, 192}, - {0x801f, 192}, - {0x8029, 192}, - {0xc038, 192}, - {0x8003, 193}, - {0x8006, 193}, - {0x800a, 193}, - {0x800f, 193}, - {0x8018, 193}, - {0x801f, 193}, - {0x8029, 193}, - {0xc038, 193}, - }, - /* 195 */ - { - {0x8003, 200}, - {0x8006, 200}, - {0x800a, 200}, - {0x800f, 200}, - {0x8018, 200}, - {0x801f, 200}, - {0x8029, 200}, - {0xc038, 200}, - {0x8003, 201}, - {0x8006, 201}, - {0x800a, 201}, - {0x800f, 201}, - {0x8018, 201}, - {0x801f, 201}, - {0x8029, 201}, - {0xc038, 201}, - }, - /* 196 */ - { - {0x8002, 202}, - {0x8009, 202}, - {0x8017, 202}, - {0xc028, 202}, - {0x8002, 205}, - {0x8009, 205}, - {0x8017, 205}, - {0xc028, 205}, - {0x8002, 210}, - {0x8009, 210}, - {0x8017, 210}, - {0xc028, 210}, - {0x8002, 213}, - {0x8009, 213}, - {0x8017, 213}, - {0xc028, 213}, - }, - /* 197 */ - { - {0x8003, 202}, - {0x8006, 202}, - {0x800a, 202}, - {0x800f, 202}, - {0x8018, 202}, - {0x801f, 202}, - {0x8029, 202}, - {0xc038, 202}, - {0x8003, 205}, - {0x8006, 205}, - {0x800a, 205}, - {0x800f, 205}, - {0x8018, 205}, - {0x801f, 205}, - {0x8029, 205}, - {0xc038, 205}, - }, - /* 198 */ - { - {0x8003, 210}, - {0x8006, 210}, - {0x800a, 210}, - {0x800f, 210}, - {0x8018, 210}, - {0x801f, 210}, - {0x8029, 210}, - {0xc038, 210}, - {0x8003, 213}, - {0x8006, 213}, - {0x800a, 213}, - {0x800f, 213}, - {0x8018, 213}, - {0x801f, 213}, - {0x8029, 213}, - {0xc038, 213}, - }, - /* 199 */ - { - {0x8001, 218}, - {0xc016, 218}, - {0x8001, 219}, - {0xc016, 219}, - {0x8001, 238}, - {0xc016, 238}, - {0x8001, 240}, - {0xc016, 240}, - {0x8001, 242}, - {0xc016, 242}, - {0x8001, 243}, - {0xc016, 243}, - {0x8001, 255}, - {0xc016, 255}, - {0xc000, 203}, - {0xc000, 204}, - }, - /* 200 */ - { - {0x8002, 218}, - {0x8009, 218}, - {0x8017, 218}, - {0xc028, 218}, - {0x8002, 219}, - {0x8009, 219}, - {0x8017, 219}, - {0xc028, 219}, - {0x8002, 238}, - {0x8009, 238}, - {0x8017, 238}, - {0xc028, 238}, - {0x8002, 240}, - {0x8009, 240}, - {0x8017, 240}, - {0xc028, 240}, - }, - /* 201 */ - { - {0x8003, 218}, - {0x8006, 218}, - {0x800a, 218}, - {0x800f, 218}, - {0x8018, 218}, - {0x801f, 218}, - {0x8029, 218}, - {0xc038, 218}, - {0x8003, 219}, - {0x8006, 219}, - {0x800a, 219}, - {0x800f, 219}, - {0x8018, 219}, - {0x801f, 219}, - {0x8029, 219}, - {0xc038, 219}, - }, - /* 202 */ - { - {0x8003, 238}, - {0x8006, 238}, - {0x800a, 238}, - {0x800f, 238}, - {0x8018, 238}, - {0x801f, 238}, - {0x8029, 238}, - {0xc038, 238}, - {0x8003, 240}, - {0x8006, 240}, - {0x800a, 240}, - {0x800f, 240}, - {0x8018, 240}, - {0x801f, 240}, - {0x8029, 240}, - {0xc038, 240}, - }, - /* 203 */ - { - {0x8002, 242}, - {0x8009, 242}, - {0x8017, 242}, - {0xc028, 242}, - {0x8002, 243}, - {0x8009, 243}, - {0x8017, 243}, - {0xc028, 243}, - {0x8002, 255}, - {0x8009, 255}, - {0x8017, 255}, - {0xc028, 255}, - {0x8001, 203}, - {0xc016, 203}, - {0x8001, 204}, - {0xc016, 204}, - }, - /* 204 */ - { - {0x8003, 242}, - {0x8006, 242}, - {0x800a, 242}, - {0x800f, 242}, - {0x8018, 242}, - {0x801f, 242}, - {0x8029, 242}, - {0xc038, 242}, - {0x8003, 243}, - {0x8006, 243}, - {0x800a, 243}, - {0x800f, 243}, - {0x8018, 243}, - {0x801f, 243}, - {0x8029, 243}, - {0xc038, 243}, - }, - /* 205 */ - { - {0x8003, 255}, - {0x8006, 255}, - {0x800a, 255}, - {0x800f, 255}, - {0x8018, 255}, - {0x801f, 255}, - {0x8029, 255}, - {0xc038, 255}, - {0x8002, 203}, - {0x8009, 203}, - {0x8017, 203}, - {0xc028, 203}, - {0x8002, 204}, - {0x8009, 204}, - {0x8017, 204}, - {0xc028, 204}, - }, - /* 206 */ - { - {0x8003, 203}, - {0x8006, 203}, - {0x800a, 203}, - {0x800f, 203}, - {0x8018, 203}, - {0x801f, 203}, - {0x8029, 203}, - {0xc038, 203}, - {0x8003, 204}, - {0x8006, 204}, - {0x800a, 204}, - {0x800f, 204}, - {0x8018, 204}, - {0x801f, 204}, - {0x8029, 204}, - {0xc038, 204}, - }, - /* 207 */ - { - {0xd3, 0}, - {0xd4, 0}, - {0xd6, 0}, - {0xd7, 0}, - {0xda, 0}, - {0xdb, 0}, - {0xdd, 0}, - {0xde, 0}, - {0xe2, 0}, - {0xe4, 0}, - {0xe8, 0}, - {0xeb, 0}, - {0xf0, 0}, - {0xf3, 0}, - {0xf7, 0}, - {0xfa, 0}, - }, - /* 208 */ - { - {0xc000, 211}, - {0xc000, 212}, - {0xc000, 214}, - {0xc000, 221}, - {0xc000, 222}, - {0xc000, 223}, - {0xc000, 241}, - {0xc000, 244}, - {0xc000, 245}, - {0xc000, 246}, - {0xc000, 247}, - {0xc000, 248}, - {0xc000, 250}, - {0xc000, 251}, - {0xc000, 252}, - {0xc000, 253}, - }, - /* 209 */ - { - {0x8001, 211}, - {0xc016, 211}, - {0x8001, 212}, - {0xc016, 212}, - {0x8001, 214}, - {0xc016, 214}, - {0x8001, 221}, - {0xc016, 221}, - {0x8001, 222}, - {0xc016, 222}, - {0x8001, 223}, - {0xc016, 223}, - {0x8001, 241}, - {0xc016, 241}, - {0x8001, 244}, - {0xc016, 244}, - }, - /* 210 */ - { - {0x8002, 211}, - {0x8009, 211}, - {0x8017, 211}, - {0xc028, 211}, - {0x8002, 212}, - {0x8009, 212}, - {0x8017, 212}, - {0xc028, 212}, - {0x8002, 214}, - {0x8009, 214}, - {0x8017, 214}, - {0xc028, 214}, - {0x8002, 221}, - {0x8009, 221}, - {0x8017, 221}, - {0xc028, 221}, - }, - /* 211 */ - { - {0x8003, 211}, - {0x8006, 211}, - {0x800a, 211}, - {0x800f, 211}, - {0x8018, 211}, - {0x801f, 211}, - {0x8029, 211}, - {0xc038, 211}, - {0x8003, 212}, - {0x8006, 212}, - {0x800a, 212}, - {0x800f, 212}, - {0x8018, 212}, - {0x801f, 212}, - {0x8029, 212}, - {0xc038, 212}, - }, - /* 212 */ - { - {0x8003, 214}, - {0x8006, 214}, - {0x800a, 214}, - {0x800f, 214}, - {0x8018, 214}, - {0x801f, 214}, - {0x8029, 214}, - {0xc038, 214}, - {0x8003, 221}, - {0x8006, 221}, - {0x800a, 221}, - {0x800f, 221}, - {0x8018, 221}, - {0x801f, 221}, - {0x8029, 221}, - {0xc038, 221}, - }, - /* 213 */ - { - {0x8002, 222}, - {0x8009, 222}, - {0x8017, 222}, - {0xc028, 222}, - {0x8002, 223}, - {0x8009, 223}, - {0x8017, 223}, - {0xc028, 223}, - {0x8002, 241}, - {0x8009, 241}, - {0x8017, 241}, - {0xc028, 241}, - {0x8002, 244}, - {0x8009, 244}, - {0x8017, 244}, - {0xc028, 244}, - }, - /* 214 */ - { - {0x8003, 222}, - {0x8006, 222}, - {0x800a, 222}, - {0x800f, 222}, - {0x8018, 222}, - {0x801f, 222}, - {0x8029, 222}, - {0xc038, 222}, - {0x8003, 223}, - {0x8006, 223}, - {0x800a, 223}, - {0x800f, 223}, - {0x8018, 223}, - {0x801f, 223}, - {0x8029, 223}, - {0xc038, 223}, - }, - /* 215 */ - { - {0x8003, 241}, - {0x8006, 241}, - {0x800a, 241}, - {0x800f, 241}, - {0x8018, 241}, - {0x801f, 241}, - {0x8029, 241}, - {0xc038, 241}, - {0x8003, 244}, - {0x8006, 244}, - {0x800a, 244}, - {0x800f, 244}, - {0x8018, 244}, - {0x801f, 244}, - {0x8029, 244}, - {0xc038, 244}, - }, - /* 216 */ - { - {0x8001, 245}, - {0xc016, 245}, - {0x8001, 246}, - {0xc016, 246}, - {0x8001, 247}, - {0xc016, 247}, - {0x8001, 248}, - {0xc016, 248}, - {0x8001, 250}, - {0xc016, 250}, - {0x8001, 251}, - {0xc016, 251}, - {0x8001, 252}, - {0xc016, 252}, - {0x8001, 253}, - {0xc016, 253}, - }, - /* 217 */ - { - {0x8002, 245}, - {0x8009, 245}, - {0x8017, 245}, - {0xc028, 245}, - {0x8002, 246}, - {0x8009, 246}, - {0x8017, 246}, - {0xc028, 246}, - {0x8002, 247}, - {0x8009, 247}, - {0x8017, 247}, - {0xc028, 247}, - {0x8002, 248}, - {0x8009, 248}, - {0x8017, 248}, - {0xc028, 248}, - }, - /* 218 */ - { - {0x8003, 245}, - {0x8006, 245}, - {0x800a, 245}, - {0x800f, 245}, - {0x8018, 245}, - {0x801f, 245}, - {0x8029, 245}, - {0xc038, 245}, - {0x8003, 246}, - {0x8006, 246}, - {0x800a, 246}, - {0x800f, 246}, - {0x8018, 246}, - {0x801f, 246}, - {0x8029, 246}, - {0xc038, 246}, - }, - /* 219 */ - { - {0x8003, 247}, - {0x8006, 247}, - {0x800a, 247}, - {0x800f, 247}, - {0x8018, 247}, - {0x801f, 247}, - {0x8029, 247}, - {0xc038, 247}, - {0x8003, 248}, - {0x8006, 248}, - {0x800a, 248}, - {0x800f, 248}, - {0x8018, 248}, - {0x801f, 248}, - {0x8029, 248}, - {0xc038, 248}, - }, - /* 220 */ - { - {0x8002, 250}, - {0x8009, 250}, - {0x8017, 250}, - {0xc028, 250}, - {0x8002, 251}, - {0x8009, 251}, - {0x8017, 251}, - {0xc028, 251}, - {0x8002, 252}, - {0x8009, 252}, - {0x8017, 252}, - {0xc028, 252}, - {0x8002, 253}, - {0x8009, 253}, - {0x8017, 253}, - {0xc028, 253}, - }, - /* 221 */ - { - {0x8003, 250}, - {0x8006, 250}, - {0x800a, 250}, - {0x800f, 250}, - {0x8018, 250}, - {0x801f, 250}, - {0x8029, 250}, - {0xc038, 250}, - {0x8003, 251}, - {0x8006, 251}, - {0x800a, 251}, - {0x800f, 251}, - {0x8018, 251}, - {0x801f, 251}, - {0x8029, 251}, - {0xc038, 251}, - }, - /* 222 */ - { - {0x8003, 252}, - {0x8006, 252}, - {0x800a, 252}, - {0x800f, 252}, - {0x8018, 252}, - {0x801f, 252}, - {0x8029, 252}, - {0xc038, 252}, - {0x8003, 253}, - {0x8006, 253}, - {0x800a, 253}, - {0x800f, 253}, - {0x8018, 253}, - {0x801f, 253}, - {0x8029, 253}, - {0xc038, 253}, - }, - /* 223 */ - { - {0xc000, 254}, - {0xe3, 0}, - {0xe5, 0}, - {0xe6, 0}, - {0xe9, 0}, - {0xea, 0}, - {0xec, 0}, - {0xed, 0}, - {0xf1, 0}, - {0xf2, 0}, - {0xf4, 0}, - {0xf5, 0}, - {0xf8, 0}, - {0xf9, 0}, - {0xfb, 0}, - {0xfc, 0}, - }, - /* 224 */ - { - {0x8001, 254}, - {0xc016, 254}, - {0xc000, 2}, - {0xc000, 3}, - {0xc000, 4}, - {0xc000, 5}, - {0xc000, 6}, - {0xc000, 7}, - {0xc000, 8}, - {0xc000, 11}, - {0xc000, 12}, - {0xc000, 14}, - {0xc000, 15}, - {0xc000, 16}, - {0xc000, 17}, - {0xc000, 18}, - }, - /* 225 */ - { - {0x8002, 254}, - {0x8009, 254}, - {0x8017, 254}, - {0xc028, 254}, - {0x8001, 2}, - {0xc016, 2}, - {0x8001, 3}, - {0xc016, 3}, - {0x8001, 4}, - {0xc016, 4}, - {0x8001, 5}, - {0xc016, 5}, - {0x8001, 6}, - {0xc016, 6}, - {0x8001, 7}, - {0xc016, 7}, - }, - /* 226 */ - { - {0x8003, 254}, - {0x8006, 254}, - {0x800a, 254}, - {0x800f, 254}, - {0x8018, 254}, - {0x801f, 254}, - {0x8029, 254}, - {0xc038, 254}, - {0x8002, 2}, - {0x8009, 2}, - {0x8017, 2}, - {0xc028, 2}, - {0x8002, 3}, - {0x8009, 3}, - {0x8017, 3}, - {0xc028, 3}, - }, - /* 227 */ - { - {0x8003, 2}, - {0x8006, 2}, - {0x800a, 2}, - {0x800f, 2}, - {0x8018, 2}, - {0x801f, 2}, - {0x8029, 2}, - {0xc038, 2}, - {0x8003, 3}, - {0x8006, 3}, - {0x800a, 3}, - {0x800f, 3}, - {0x8018, 3}, - {0x801f, 3}, - {0x8029, 3}, - {0xc038, 3}, - }, - /* 228 */ - { - {0x8002, 4}, - {0x8009, 4}, - {0x8017, 4}, - {0xc028, 4}, - {0x8002, 5}, - {0x8009, 5}, - {0x8017, 5}, - {0xc028, 5}, - {0x8002, 6}, - {0x8009, 6}, - {0x8017, 6}, - {0xc028, 6}, - {0x8002, 7}, - {0x8009, 7}, - {0x8017, 7}, - {0xc028, 7}, - }, - /* 229 */ - { - {0x8003, 4}, - {0x8006, 4}, - {0x800a, 4}, - {0x800f, 4}, - {0x8018, 4}, - {0x801f, 4}, - {0x8029, 4}, - {0xc038, 4}, - {0x8003, 5}, - {0x8006, 5}, - {0x800a, 5}, - {0x800f, 5}, - {0x8018, 5}, - {0x801f, 5}, - {0x8029, 5}, - {0xc038, 5}, - }, - /* 230 */ - { - {0x8003, 6}, - {0x8006, 6}, - {0x800a, 6}, - {0x800f, 6}, - {0x8018, 6}, - {0x801f, 6}, - {0x8029, 6}, - {0xc038, 6}, - {0x8003, 7}, - {0x8006, 7}, - {0x800a, 7}, - {0x800f, 7}, - {0x8018, 7}, - {0x801f, 7}, - {0x8029, 7}, - {0xc038, 7}, - }, - /* 231 */ - { - {0x8001, 8}, - {0xc016, 8}, - {0x8001, 11}, - {0xc016, 11}, - {0x8001, 12}, - {0xc016, 12}, - {0x8001, 14}, - {0xc016, 14}, - {0x8001, 15}, - {0xc016, 15}, - {0x8001, 16}, - {0xc016, 16}, - {0x8001, 17}, - {0xc016, 17}, - {0x8001, 18}, - {0xc016, 18}, - }, - /* 232 */ - { - {0x8002, 8}, - {0x8009, 8}, - {0x8017, 8}, - {0xc028, 8}, - {0x8002, 11}, - {0x8009, 11}, - {0x8017, 11}, - {0xc028, 11}, - {0x8002, 12}, - {0x8009, 12}, - {0x8017, 12}, - {0xc028, 12}, - {0x8002, 14}, - {0x8009, 14}, - {0x8017, 14}, - {0xc028, 14}, - }, - /* 233 */ - { - {0x8003, 8}, - {0x8006, 8}, - {0x800a, 8}, - {0x800f, 8}, - {0x8018, 8}, - {0x801f, 8}, - {0x8029, 8}, - {0xc038, 8}, - {0x8003, 11}, - {0x8006, 11}, - {0x800a, 11}, - {0x800f, 11}, - {0x8018, 11}, - {0x801f, 11}, - {0x8029, 11}, - {0xc038, 11}, - }, - /* 234 */ - { - {0x8003, 12}, - {0x8006, 12}, - {0x800a, 12}, - {0x800f, 12}, - {0x8018, 12}, - {0x801f, 12}, - {0x8029, 12}, - {0xc038, 12}, - {0x8003, 14}, - {0x8006, 14}, - {0x800a, 14}, - {0x800f, 14}, - {0x8018, 14}, - {0x801f, 14}, - {0x8029, 14}, - {0xc038, 14}, - }, - /* 235 */ - { - {0x8002, 15}, - {0x8009, 15}, - {0x8017, 15}, - {0xc028, 15}, - {0x8002, 16}, - {0x8009, 16}, - {0x8017, 16}, - {0xc028, 16}, - {0x8002, 17}, - {0x8009, 17}, - {0x8017, 17}, - {0xc028, 17}, - {0x8002, 18}, - {0x8009, 18}, - {0x8017, 18}, - {0xc028, 18}, - }, - /* 236 */ - { - {0x8003, 15}, - {0x8006, 15}, - {0x800a, 15}, - {0x800f, 15}, - {0x8018, 15}, - {0x801f, 15}, - {0x8029, 15}, - {0xc038, 15}, - {0x8003, 16}, - {0x8006, 16}, - {0x800a, 16}, - {0x800f, 16}, - {0x8018, 16}, - {0x801f, 16}, - {0x8029, 16}, - {0xc038, 16}, - }, - /* 237 */ - { - {0x8003, 17}, - {0x8006, 17}, - {0x800a, 17}, - {0x800f, 17}, - {0x8018, 17}, - {0x801f, 17}, - {0x8029, 17}, - {0xc038, 17}, - {0x8003, 18}, - {0x8006, 18}, - {0x800a, 18}, - {0x800f, 18}, - {0x8018, 18}, - {0x801f, 18}, - {0x8029, 18}, - {0xc038, 18}, - }, - /* 238 */ - { - {0xc000, 19}, - {0xc000, 20}, - {0xc000, 21}, - {0xc000, 23}, - {0xc000, 24}, - {0xc000, 25}, - {0xc000, 26}, - {0xc000, 27}, - {0xc000, 28}, - {0xc000, 29}, - {0xc000, 30}, - {0xc000, 31}, - {0xc000, 127}, - {0xc000, 220}, - {0xc000, 249}, - {0xfd, 0}, - }, - /* 239 */ - { - {0x8001, 19}, - {0xc016, 19}, - {0x8001, 20}, - {0xc016, 20}, - {0x8001, 21}, - {0xc016, 21}, - {0x8001, 23}, - {0xc016, 23}, - {0x8001, 24}, - {0xc016, 24}, - {0x8001, 25}, - {0xc016, 25}, - {0x8001, 26}, - {0xc016, 26}, - {0x8001, 27}, - {0xc016, 27}, - }, - /* 240 */ - { - {0x8002, 19}, - {0x8009, 19}, - {0x8017, 19}, - {0xc028, 19}, - {0x8002, 20}, - {0x8009, 20}, - {0x8017, 20}, - {0xc028, 20}, - {0x8002, 21}, - {0x8009, 21}, - {0x8017, 21}, - {0xc028, 21}, - {0x8002, 23}, - {0x8009, 23}, - {0x8017, 23}, - {0xc028, 23}, - }, - /* 241 */ - { - {0x8003, 19}, - {0x8006, 19}, - {0x800a, 19}, - {0x800f, 19}, - {0x8018, 19}, - {0x801f, 19}, - {0x8029, 19}, - {0xc038, 19}, - {0x8003, 20}, - {0x8006, 20}, - {0x800a, 20}, - {0x800f, 20}, - {0x8018, 20}, - {0x801f, 20}, - {0x8029, 20}, - {0xc038, 20}, - }, - /* 242 */ - { - {0x8003, 21}, - {0x8006, 21}, - {0x800a, 21}, - {0x800f, 21}, - {0x8018, 21}, - {0x801f, 21}, - {0x8029, 21}, - {0xc038, 21}, - {0x8003, 23}, - {0x8006, 23}, - {0x800a, 23}, - {0x800f, 23}, - {0x8018, 23}, - {0x801f, 23}, - {0x8029, 23}, - {0xc038, 23}, - }, - /* 243 */ - { - {0x8002, 24}, - {0x8009, 24}, - {0x8017, 24}, - {0xc028, 24}, - {0x8002, 25}, - {0x8009, 25}, - {0x8017, 25}, - {0xc028, 25}, - {0x8002, 26}, - {0x8009, 26}, - {0x8017, 26}, - {0xc028, 26}, - {0x8002, 27}, - {0x8009, 27}, - {0x8017, 27}, - {0xc028, 27}, - }, - /* 244 */ - { - {0x8003, 24}, - {0x8006, 24}, - {0x800a, 24}, - {0x800f, 24}, - {0x8018, 24}, - {0x801f, 24}, - {0x8029, 24}, - {0xc038, 24}, - {0x8003, 25}, - {0x8006, 25}, - {0x800a, 25}, - {0x800f, 25}, - {0x8018, 25}, - {0x801f, 25}, - {0x8029, 25}, - {0xc038, 25}, - }, - /* 245 */ - { - {0x8003, 26}, - {0x8006, 26}, - {0x800a, 26}, - {0x800f, 26}, - {0x8018, 26}, - {0x801f, 26}, - {0x8029, 26}, - {0xc038, 26}, - {0x8003, 27}, - {0x8006, 27}, - {0x800a, 27}, - {0x800f, 27}, - {0x8018, 27}, - {0x801f, 27}, - {0x8029, 27}, - {0xc038, 27}, - }, - /* 246 */ - { - {0x8001, 28}, - {0xc016, 28}, - {0x8001, 29}, - {0xc016, 29}, - {0x8001, 30}, - {0xc016, 30}, - {0x8001, 31}, - {0xc016, 31}, - {0x8001, 127}, - {0xc016, 127}, - {0x8001, 220}, - {0xc016, 220}, - {0x8001, 249}, - {0xc016, 249}, - {0xfe, 0}, - {0xff, 0}, - }, - /* 247 */ - { - {0x8002, 28}, - {0x8009, 28}, - {0x8017, 28}, - {0xc028, 28}, - {0x8002, 29}, - {0x8009, 29}, - {0x8017, 29}, - {0xc028, 29}, - {0x8002, 30}, - {0x8009, 30}, - {0x8017, 30}, - {0xc028, 30}, - {0x8002, 31}, - {0x8009, 31}, - {0x8017, 31}, - {0xc028, 31}, - }, - /* 248 */ - { - {0x8003, 28}, - {0x8006, 28}, - {0x800a, 28}, - {0x800f, 28}, - {0x8018, 28}, - {0x801f, 28}, - {0x8029, 28}, - {0xc038, 28}, - {0x8003, 29}, - {0x8006, 29}, - {0x800a, 29}, - {0x800f, 29}, - {0x8018, 29}, - {0x801f, 29}, - {0x8029, 29}, - {0xc038, 29}, - }, - /* 249 */ - { - {0x8003, 30}, - {0x8006, 30}, - {0x800a, 30}, - {0x800f, 30}, - {0x8018, 30}, - {0x801f, 30}, - {0x8029, 30}, - {0xc038, 30}, - {0x8003, 31}, - {0x8006, 31}, - {0x800a, 31}, - {0x800f, 31}, - {0x8018, 31}, - {0x801f, 31}, - {0x8029, 31}, - {0xc038, 31}, - }, - /* 250 */ - { - {0x8002, 127}, - {0x8009, 127}, - {0x8017, 127}, - {0xc028, 127}, - {0x8002, 220}, - {0x8009, 220}, - {0x8017, 220}, - {0xc028, 220}, - {0x8002, 249}, - {0x8009, 249}, - {0x8017, 249}, - {0xc028, 249}, - {0xc000, 10}, - {0xc000, 13}, - {0xc000, 22}, - {0x100, 0}, - }, - /* 251 */ - { - {0x8003, 127}, - {0x8006, 127}, - {0x800a, 127}, - {0x800f, 127}, - {0x8018, 127}, - {0x801f, 127}, - {0x8029, 127}, - {0xc038, 127}, - {0x8003, 220}, - {0x8006, 220}, - {0x800a, 220}, - {0x800f, 220}, - {0x8018, 220}, - {0x801f, 220}, - {0x8029, 220}, - {0xc038, 220}, - }, - /* 252 */ - { - {0x8003, 249}, - {0x8006, 249}, - {0x800a, 249}, - {0x800f, 249}, - {0x8018, 249}, - {0x801f, 249}, - {0x8029, 249}, - {0xc038, 249}, - {0x8001, 10}, - {0xc016, 10}, - {0x8001, 13}, - {0xc016, 13}, - {0x8001, 22}, - {0xc016, 22}, - {0x100, 0}, - {0x100, 0}, - }, - /* 253 */ - { - {0x8002, 10}, - {0x8009, 10}, - {0x8017, 10}, - {0xc028, 10}, - {0x8002, 13}, - {0x8009, 13}, - {0x8017, 13}, - {0xc028, 13}, - {0x8002, 22}, - {0x8009, 22}, - {0x8017, 22}, - {0xc028, 22}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - }, - /* 254 */ - { - {0x8003, 10}, - {0x8006, 10}, - {0x800a, 10}, - {0x800f, 10}, - {0x8018, 10}, - {0x801f, 10}, - {0x8029, 10}, - {0xc038, 10}, - {0x8003, 13}, - {0x8006, 13}, - {0x800a, 13}, - {0x800f, 13}, - {0x8018, 13}, - {0x801f, 13}, - {0x8029, 13}, - {0xc038, 13}, - }, - /* 255 */ - { - {0x8003, 22}, - {0x8006, 22}, - {0x800a, 22}, - {0x800f, 22}, - {0x8018, 22}, - {0x801f, 22}, - {0x8029, 22}, - {0xc038, 22}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - }, - /* 256 */ - { - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - {0x100, 0}, - }, -}; diff --git a/deps/nghttp3/lib/nghttp3_range.c b/deps/nghttp3/lib/nghttp3_range.c deleted file mode 100644 index 0ce71480d72fec..00000000000000 --- a/deps/nghttp3/lib/nghttp3_range.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_range.h" -#include "nghttp3_macro.h" - -void nghttp3_range_init(nghttp3_range *r, uint64_t begin, uint64_t end) { - r->begin = begin; - r->end = end; -} - -nghttp3_range nghttp3_range_intersect(const nghttp3_range *a, - const nghttp3_range *b) { - nghttp3_range r = {0, 0}; - uint64_t begin = nghttp3_max(a->begin, b->begin); - uint64_t end = nghttp3_min(a->end, b->end); - if (begin < end) { - nghttp3_range_init(&r, begin, end); - } - return r; -} - -uint64_t nghttp3_range_len(const nghttp3_range *r) { return r->end - r->begin; } - -int nghttp3_range_eq(const nghttp3_range *a, const nghttp3_range *b) { - return a->begin == b->begin && a->end == b->end; -} - -void nghttp3_range_cut(nghttp3_range *left, nghttp3_range *right, - const nghttp3_range *a, const nghttp3_range *b) { - /* Assume that b is included in a */ - left->begin = a->begin; - left->end = b->begin; - right->begin = b->end; - right->end = a->end; -} - -int nghttp3_range_not_after(const nghttp3_range *a, const nghttp3_range *b) { - return a->end <= b->end; -} diff --git a/deps/nghttp3/lib/nghttp3_range.h b/deps/nghttp3/lib/nghttp3_range.h deleted file mode 100644 index e65dd148354e48..00000000000000 --- a/deps/nghttp3/lib/nghttp3_range.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_RANGE_H -#define NGHTTP3_RANGE_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -/* - * nghttp3_range represents half-closed range [begin, end). - */ -typedef struct { - uint64_t begin; - uint64_t end; -} nghttp3_range; - -/* - * nghttp3_range_init initializes |r| with the range [|begin|, |end|). - */ -void nghttp3_range_init(nghttp3_range *r, uint64_t begin, uint64_t end); - -/* - * nghttp3_range_intersect returns the intersection of |a| and |b|. - * If they do not overlap, it returns empty range. - */ -nghttp3_range nghttp3_range_intersect(const nghttp3_range *a, - const nghttp3_range *b); - -/* - * nghttp3_range_len returns the length of |r|. - */ -uint64_t nghttp3_range_len(const nghttp3_range *r); - -/* - * nghttp3_range_eq returns nonzero if |a| equals |b|, such that - * a->begin == b->begin, and a->end == b->end hold. - */ -int nghttp3_range_eq(const nghttp3_range *a, const nghttp3_range *b); - -/* - * nghttp3_range_cut returns the left and right range after removing - * |b| from |a|. This function assumes that |a| completely includes - * |b|. In other words, a->begin <= b->begin and b->end <= a->end - * hold. - */ -void nghttp3_range_cut(nghttp3_range *left, nghttp3_range *right, - const nghttp3_range *a, const nghttp3_range *b); - -/* - * nghttp3_range_not_after returns nonzero if the right edge of |a| - * does not go beyond of the right edge of |b|. - */ -int nghttp3_range_not_after(const nghttp3_range *a, const nghttp3_range *b); - -#endif /* NGHTTP3_RANGE_H */ diff --git a/deps/nghttp3/lib/nghttp3_rcbuf.c b/deps/nghttp3/lib/nghttp3_rcbuf.c deleted file mode 100644 index 1c31ecebf608d5..00000000000000 --- a/deps/nghttp3/lib/nghttp3_rcbuf.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2016 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_rcbuf.h" - -#include - -#include "nghttp3_mem.h" -#include "nghttp3_str.h" - -int nghttp3_rcbuf_new(nghttp3_rcbuf **rcbuf_ptr, size_t size, - const nghttp3_mem *mem) { - uint8_t *p; - - p = nghttp3_mem_malloc(mem, sizeof(nghttp3_rcbuf) + size); - if (p == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - *rcbuf_ptr = (void *)p; - - (*rcbuf_ptr)->mem_user_data = mem->mem_user_data; - (*rcbuf_ptr)->free = mem->free; - (*rcbuf_ptr)->base = p + sizeof(nghttp3_rcbuf); - (*rcbuf_ptr)->len = size; - (*rcbuf_ptr)->ref = 1; - - return 0; -} - -int nghttp3_rcbuf_new2(nghttp3_rcbuf **rcbuf_ptr, const uint8_t *src, - size_t srclen, const nghttp3_mem *mem) { - int rv; - uint8_t *p; - - rv = nghttp3_rcbuf_new(rcbuf_ptr, srclen + 1, mem); - if (rv != 0) { - return rv; - } - - (*rcbuf_ptr)->len = srclen; - p = (*rcbuf_ptr)->base; - - if (srclen) { - p = nghttp3_cpymem(p, src, srclen); - } - - *p = '\0'; - - return 0; -} - -/* - * Frees |rcbuf| itself, regardless of its reference cout. - */ -void nghttp3_rcbuf_del(nghttp3_rcbuf *rcbuf) { - nghttp3_mem_free2(rcbuf->free, rcbuf, rcbuf->mem_user_data); -} - -void nghttp3_rcbuf_incref(nghttp3_rcbuf *rcbuf) { - if (rcbuf->ref == -1) { - return; - } - - ++rcbuf->ref; -} - -void nghttp3_rcbuf_decref(nghttp3_rcbuf *rcbuf) { - if (rcbuf == NULL || rcbuf->ref == -1) { - return; - } - - assert(rcbuf->ref > 0); - - if (--rcbuf->ref == 0) { - nghttp3_rcbuf_del(rcbuf); - } -} - -nghttp3_vec nghttp3_rcbuf_get_buf(const nghttp3_rcbuf *rcbuf) { - nghttp3_vec res = {rcbuf->base, rcbuf->len}; - return res; -} - -int nghttp3_rcbuf_is_static(const nghttp3_rcbuf *rcbuf) { - return rcbuf->ref == -1; -} diff --git a/deps/nghttp3/lib/nghttp3_rcbuf.h b/deps/nghttp3/lib/nghttp3_rcbuf.h deleted file mode 100644 index feea8040005422..00000000000000 --- a/deps/nghttp3/lib/nghttp3_rcbuf.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2016 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_RCBUF_H -#define NGHTTP3_RCBUF_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -struct nghttp3_rcbuf { - /* custom memory allocator belongs to the mem parameter when - creating this object. */ - void *mem_user_data; - nghttp3_free free; - /* The pointer to the underlying buffer */ - uint8_t *base; - /* Size of buffer pointed by |base|. */ - size_t len; - /* Reference count */ - int32_t ref; -}; - -/* - * Allocates nghttp3_rcbuf object with |size| as initial buffer size. - * When the function succeeds, the reference count becomes 1. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM: - * Out of memory. - */ -int nghttp3_rcbuf_new(nghttp3_rcbuf **rcbuf_ptr, size_t size, - const nghttp3_mem *mem); - -/* - * Like nghttp3_rcbuf_new(), but initializes the buffer with |src| of - * length |srclen|. This function allocates additional byte at the - * end and puts '\0' into it, so that the resulting buffer could be - * used as NULL-terminated string. Still (*rcbuf_ptr)->len equals to - * |srclen|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM: - * Out of memory. - */ -int nghttp3_rcbuf_new2(nghttp3_rcbuf **rcbuf_ptr, const uint8_t *src, - size_t srclen, const nghttp3_mem *mem); - -/* - * Frees |rcbuf| itself, regardless of its reference cout. - */ -void nghttp3_rcbuf_del(nghttp3_rcbuf *rcbuf); - -#endif /* NGHTTP3_RCBUF_H */ diff --git a/deps/nghttp3/lib/nghttp3_ringbuf.c b/deps/nghttp3/lib/nghttp3_ringbuf.c deleted file mode 100644 index 9ea91c81c8a1b9..00000000000000 --- a/deps/nghttp3/lib/nghttp3_ringbuf.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_ringbuf.h" - -#include -#include -#ifdef WIN32 -# include -#endif - -#include "nghttp3_macro.h" - -#if defined(_MSC_VER) && defined(_M_ARM64) -unsigned int __popcnt(unsigned int x) { - unsigned int c = 0; - for (; x; ++c) { - x &= x - 1; - } - return c; -} -#endif - -int nghttp3_ringbuf_init(nghttp3_ringbuf *rb, size_t nmemb, size_t size, - const nghttp3_mem *mem) { - if (nmemb) { -#ifdef WIN32 - assert(1 == __popcnt((unsigned int)nmemb)); -#else - assert(1 == __builtin_popcount((unsigned int)nmemb)); -#endif - - rb->buf = nghttp3_mem_malloc(mem, nmemb * size); - if (rb->buf == NULL) { - return NGHTTP3_ERR_NOMEM; - } - } else { - rb->buf = NULL; - } - - rb->mem = mem; - rb->nmemb = nmemb; - rb->size = size; - rb->first = 0; - rb->len = 0; - - return 0; -} - -void nghttp3_ringbuf_free(nghttp3_ringbuf *rb) { - if (rb == NULL) { - return; - } - - nghttp3_mem_free(rb->mem, rb->buf); -} - -void *nghttp3_ringbuf_push_front(nghttp3_ringbuf *rb) { - rb->first = (rb->first - 1) & (rb->nmemb - 1); - rb->len = nghttp3_min(rb->nmemb, rb->len + 1); - - return (void *)&rb->buf[rb->first * rb->size]; -} - -void *nghttp3_ringbuf_push_back(nghttp3_ringbuf *rb) { - size_t offset = (rb->first + rb->len) & (rb->nmemb - 1); - - if (rb->len == rb->nmemb) { - rb->first = (rb->first + 1) & (rb->nmemb - 1); - } else { - ++rb->len; - } - - return (void *)&rb->buf[offset * rb->size]; -} - -void nghttp3_ringbuf_pop_front(nghttp3_ringbuf *rb) { - rb->first = (rb->first + 1) & (rb->nmemb - 1); - --rb->len; -} - -void nghttp3_ringbuf_pop_back(nghttp3_ringbuf *rb) { - assert(rb->len); - --rb->len; -} - -void nghttp3_ringbuf_resize(nghttp3_ringbuf *rb, size_t len) { - assert(len <= rb->nmemb); - rb->len = len; -} - -void *nghttp3_ringbuf_get(nghttp3_ringbuf *rb, size_t offset) { - assert(offset < rb->len); - offset = (rb->first + offset) & (rb->nmemb - 1); - return &rb->buf[offset * rb->size]; -} - -int nghttp3_ringbuf_full(nghttp3_ringbuf *rb) { return rb->len == rb->nmemb; } - -int nghttp3_ringbuf_reserve(nghttp3_ringbuf *rb, size_t nmemb) { - uint8_t *buf; - - if (rb->nmemb >= nmemb) { - return 0; - } - -#ifdef WIN32 - assert(1 == __popcnt((unsigned int)nmemb)); -#else - assert(1 == __builtin_popcount((unsigned int)nmemb)); -#endif - - buf = nghttp3_mem_malloc(rb->mem, nmemb * rb->size); - if (buf == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - if (rb->buf != NULL) { - if (rb->first + rb->len <= rb->nmemb) { - memcpy(buf, rb->buf + rb->first * rb->size, rb->len * rb->size); - rb->first = 0; - } else { - memcpy(buf, rb->buf + rb->first * rb->size, - (rb->nmemb - rb->first) * rb->size); - memcpy(buf + (rb->nmemb - rb->first) * rb->size, rb->buf, - (rb->len - (rb->nmemb - rb->first)) * rb->size); - rb->first = 0; - } - - nghttp3_mem_free(rb->mem, rb->buf); - } - - rb->buf = buf; - rb->nmemb = nmemb; - - return 0; -} diff --git a/deps/nghttp3/lib/nghttp3_ringbuf.h b/deps/nghttp3/lib/nghttp3_ringbuf.h deleted file mode 100644 index 51194bd63569d5..00000000000000 --- a/deps/nghttp3/lib/nghttp3_ringbuf.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_RINGBUF_H -#define NGHTTP3_RINGBUF_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "nghttp3_mem.h" - -typedef struct { - /* buf points to the underlying buffer. */ - uint8_t *buf; - const nghttp3_mem *mem; - /* nmemb is the number of elements that can be stored in this ring - buffer. */ - size_t nmemb; - /* size is the size of each element. */ - size_t size; - /* first is the offset to the first element. */ - size_t first; - /* len is the number of elements actually stored. */ - size_t len; -} nghttp3_ringbuf; - -/* - * nghttp3_ringbuf_init initializes |rb|. |nmemb| is the number of - * elements that can be stored in this buffer. |size| is the size of - * each element. |size| must be power of 2. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP3_ERR_NOMEM - * Out of memory. - */ -int nghttp3_ringbuf_init(nghttp3_ringbuf *rb, size_t nmemb, size_t size, - const nghttp3_mem *mem); - -/* - * nghttp3_ringbuf_free frees resources allocated for |rb|. This - * function does not free the memory pointed by |rb|. - */ -void nghttp3_ringbuf_free(nghttp3_ringbuf *rb); - -/* nghttp3_ringbuf_push_front moves the offset to the first element in - the buffer backward, and returns the pointer to the element. - Caller can store data to the buffer pointed by the returned - pointer. If this action exceeds the capacity of the ring buffer, - the last element is silently overwritten, and rb->len remains - unchanged. */ -void *nghttp3_ringbuf_push_front(nghttp3_ringbuf *rb); - -/* nghttp3_ringbuf_push_back moves the offset to the last element in - the buffer forward, and returns the pointer to the element. Caller - can store data to the buffer pointed by the returned pointer. If - this action exceeds the capacity of the ring buffer, the first - element is silently overwritten, and rb->len remains unchanged. */ -void *nghttp3_ringbuf_push_back(nghttp3_ringbuf *rb); - -/* - * nghttp3_ringbuf_pop_front removes first element in |rb|. - */ -void nghttp3_ringbuf_pop_front(nghttp3_ringbuf *rb); - -/* - * nghttp3_ringbuf_pop_back removes the last element in |rb|. - */ -void nghttp3_ringbuf_pop_back(nghttp3_ringbuf *rb); - -/* nghttp3_ringbuf_resize changes the number of elements stored. This - does not change the capacity of the underlying buffer. */ -void nghttp3_ringbuf_resize(nghttp3_ringbuf *rb, size_t len); - -/* nghttp3_ringbuf_get returns the pointer to the element at - |offset|. */ -void *nghttp3_ringbuf_get(nghttp3_ringbuf *rb, size_t offset); - -/* nghttp3_ringbuf_len returns the number of elements stored. */ -#define nghttp3_ringbuf_len(RB) ((RB)->len) - -/* nghttp3_ringbuf_full returns nonzero if |rb| is full. */ -int nghttp3_ringbuf_full(nghttp3_ringbuf *rb); - -int nghttp3_ringbuf_reserve(nghttp3_ringbuf *rb, size_t nmemb); - -#endif /* NGHTTP3_RINGBUF_H */ diff --git a/deps/nghttp3/lib/nghttp3_str.c b/deps/nghttp3/lib/nghttp3_str.c deleted file mode 100644 index 3782aa72cd6e81..00000000000000 --- a/deps/nghttp3/lib/nghttp3_str.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2012 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_str.h" - -#include -#include - -uint8_t *nghttp3_cpymem(uint8_t *dest, const uint8_t *src, size_t n) { - memcpy(dest, src, n); - return dest + n; -} - -/* Generated by gendowncasetbl.py */ -static const uint8_t DOWNCASE_TBL[] = { - 0 /* NUL */, 1 /* SOH */, 2 /* STX */, 3 /* ETX */, - 4 /* EOT */, 5 /* ENQ */, 6 /* ACK */, 7 /* BEL */, - 8 /* BS */, 9 /* HT */, 10 /* LF */, 11 /* VT */, - 12 /* FF */, 13 /* CR */, 14 /* SO */, 15 /* SI */, - 16 /* DLE */, 17 /* DC1 */, 18 /* DC2 */, 19 /* DC3 */, - 20 /* DC4 */, 21 /* NAK */, 22 /* SYN */, 23 /* ETB */, - 24 /* CAN */, 25 /* EM */, 26 /* SUB */, 27 /* ESC */, - 28 /* FS */, 29 /* GS */, 30 /* RS */, 31 /* US */, - 32 /* SPC */, 33 /* ! */, 34 /* " */, 35 /* # */, - 36 /* $ */, 37 /* % */, 38 /* & */, 39 /* ' */, - 40 /* ( */, 41 /* ) */, 42 /* * */, 43 /* + */, - 44 /* , */, 45 /* - */, 46 /* . */, 47 /* / */, - 48 /* 0 */, 49 /* 1 */, 50 /* 2 */, 51 /* 3 */, - 52 /* 4 */, 53 /* 5 */, 54 /* 6 */, 55 /* 7 */, - 56 /* 8 */, 57 /* 9 */, 58 /* : */, 59 /* ; */, - 60 /* < */, 61 /* = */, 62 /* > */, 63 /* ? */, - 64 /* @ */, 97 /* A */, 98 /* B */, 99 /* C */, - 100 /* D */, 101 /* E */, 102 /* F */, 103 /* G */, - 104 /* H */, 105 /* I */, 106 /* J */, 107 /* K */, - 108 /* L */, 109 /* M */, 110 /* N */, 111 /* O */, - 112 /* P */, 113 /* Q */, 114 /* R */, 115 /* S */, - 116 /* T */, 117 /* U */, 118 /* V */, 119 /* W */, - 120 /* X */, 121 /* Y */, 122 /* Z */, 91 /* [ */, - 92 /* \ */, 93 /* ] */, 94 /* ^ */, 95 /* _ */, - 96 /* ` */, 97 /* a */, 98 /* b */, 99 /* c */, - 100 /* d */, 101 /* e */, 102 /* f */, 103 /* g */, - 104 /* h */, 105 /* i */, 106 /* j */, 107 /* k */, - 108 /* l */, 109 /* m */, 110 /* n */, 111 /* o */, - 112 /* p */, 113 /* q */, 114 /* r */, 115 /* s */, - 116 /* t */, 117 /* u */, 118 /* v */, 119 /* w */, - 120 /* x */, 121 /* y */, 122 /* z */, 123 /* { */, - 124 /* | */, 125 /* } */, 126 /* ~ */, 127 /* DEL */, - 128 /* 0x80 */, 129 /* 0x81 */, 130 /* 0x82 */, 131 /* 0x83 */, - 132 /* 0x84 */, 133 /* 0x85 */, 134 /* 0x86 */, 135 /* 0x87 */, - 136 /* 0x88 */, 137 /* 0x89 */, 138 /* 0x8a */, 139 /* 0x8b */, - 140 /* 0x8c */, 141 /* 0x8d */, 142 /* 0x8e */, 143 /* 0x8f */, - 144 /* 0x90 */, 145 /* 0x91 */, 146 /* 0x92 */, 147 /* 0x93 */, - 148 /* 0x94 */, 149 /* 0x95 */, 150 /* 0x96 */, 151 /* 0x97 */, - 152 /* 0x98 */, 153 /* 0x99 */, 154 /* 0x9a */, 155 /* 0x9b */, - 156 /* 0x9c */, 157 /* 0x9d */, 158 /* 0x9e */, 159 /* 0x9f */, - 160 /* 0xa0 */, 161 /* 0xa1 */, 162 /* 0xa2 */, 163 /* 0xa3 */, - 164 /* 0xa4 */, 165 /* 0xa5 */, 166 /* 0xa6 */, 167 /* 0xa7 */, - 168 /* 0xa8 */, 169 /* 0xa9 */, 170 /* 0xaa */, 171 /* 0xab */, - 172 /* 0xac */, 173 /* 0xad */, 174 /* 0xae */, 175 /* 0xaf */, - 176 /* 0xb0 */, 177 /* 0xb1 */, 178 /* 0xb2 */, 179 /* 0xb3 */, - 180 /* 0xb4 */, 181 /* 0xb5 */, 182 /* 0xb6 */, 183 /* 0xb7 */, - 184 /* 0xb8 */, 185 /* 0xb9 */, 186 /* 0xba */, 187 /* 0xbb */, - 188 /* 0xbc */, 189 /* 0xbd */, 190 /* 0xbe */, 191 /* 0xbf */, - 192 /* 0xc0 */, 193 /* 0xc1 */, 194 /* 0xc2 */, 195 /* 0xc3 */, - 196 /* 0xc4 */, 197 /* 0xc5 */, 198 /* 0xc6 */, 199 /* 0xc7 */, - 200 /* 0xc8 */, 201 /* 0xc9 */, 202 /* 0xca */, 203 /* 0xcb */, - 204 /* 0xcc */, 205 /* 0xcd */, 206 /* 0xce */, 207 /* 0xcf */, - 208 /* 0xd0 */, 209 /* 0xd1 */, 210 /* 0xd2 */, 211 /* 0xd3 */, - 212 /* 0xd4 */, 213 /* 0xd5 */, 214 /* 0xd6 */, 215 /* 0xd7 */, - 216 /* 0xd8 */, 217 /* 0xd9 */, 218 /* 0xda */, 219 /* 0xdb */, - 220 /* 0xdc */, 221 /* 0xdd */, 222 /* 0xde */, 223 /* 0xdf */, - 224 /* 0xe0 */, 225 /* 0xe1 */, 226 /* 0xe2 */, 227 /* 0xe3 */, - 228 /* 0xe4 */, 229 /* 0xe5 */, 230 /* 0xe6 */, 231 /* 0xe7 */, - 232 /* 0xe8 */, 233 /* 0xe9 */, 234 /* 0xea */, 235 /* 0xeb */, - 236 /* 0xec */, 237 /* 0xed */, 238 /* 0xee */, 239 /* 0xef */, - 240 /* 0xf0 */, 241 /* 0xf1 */, 242 /* 0xf2 */, 243 /* 0xf3 */, - 244 /* 0xf4 */, 245 /* 0xf5 */, 246 /* 0xf6 */, 247 /* 0xf7 */, - 248 /* 0xf8 */, 249 /* 0xf9 */, 250 /* 0xfa */, 251 /* 0xfb */, - 252 /* 0xfc */, 253 /* 0xfd */, 254 /* 0xfe */, 255 /* 0xff */, -}; - -void nghttp3_downcase(uint8_t *s, size_t len) { - size_t i; - for (i = 0; i < len; ++i) { - s[i] = DOWNCASE_TBL[s[i]]; - } -} diff --git a/deps/nghttp3/lib/nghttp3_str.h b/deps/nghttp3/lib/nghttp3_str.h deleted file mode 100644 index 19c1d2c71b559b..00000000000000 --- a/deps/nghttp3/lib/nghttp3_str.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2012 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_STR_H -#define NGHTTP3_STR_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -uint8_t *nghttp3_cpymem(uint8_t *dest, const uint8_t *src, size_t n); - -void nghttp3_downcase(uint8_t *s, size_t len); - -#endif /* NGHTTP3_STR_H */ diff --git a/deps/nghttp3/lib/nghttp3_stream.c b/deps/nghttp3/lib/nghttp3_stream.c deleted file mode 100644 index bf66d738d78a8b..00000000000000 --- a/deps/nghttp3/lib/nghttp3_stream.c +++ /dev/null @@ -1,1282 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_stream.h" - -#include -#include -#include - -#include "nghttp3_conv.h" -#include "nghttp3_macro.h" -#include "nghttp3_frame.h" -#include "nghttp3_conn.h" -#include "nghttp3_str.h" -#include "nghttp3_http.h" - -/* NGHTTP3_STREAM_MAX_COPY_THRES is the maximum size of buffer which - makes a copy to outq. */ -#define NGHTTP3_STREAM_MAX_COPY_THRES 128 - -/* NGHTTP3_MIN_RBLEN is the minimum length of nghttp3_ringbuf */ -#define NGHTTP3_MIN_RBLEN 4 - -int nghttp3_stream_new(nghttp3_stream **pstream, int64_t stream_id, - uint64_t seq, const nghttp3_stream_callbacks *callbacks, - const nghttp3_mem *mem) { - int rv; - nghttp3_stream *stream = nghttp3_mem_calloc(mem, 1, sizeof(nghttp3_stream)); - nghttp3_node_id nid; - - if (stream == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - nghttp3_tnode_init( - &stream->node, - nghttp3_node_id_init(&nid, NGHTTP3_NODE_ID_TYPE_STREAM, stream_id), seq, - NGHTTP3_DEFAULT_URGENCY); - - rv = nghttp3_ringbuf_init(&stream->frq, 0, sizeof(nghttp3_frame_entry), mem); - if (rv != 0) { - goto frq_init_fail; - } - - rv = nghttp3_ringbuf_init(&stream->chunks, 0, sizeof(nghttp3_buf), mem); - if (rv != 0) { - goto chunks_init_fail; - } - - rv = nghttp3_ringbuf_init(&stream->outq, 0, sizeof(nghttp3_typed_buf), mem); - if (rv != 0) { - goto outq_init_fail; - } - - rv = nghttp3_ringbuf_init(&stream->inq, 0, sizeof(nghttp3_buf), mem); - if (rv != 0) { - goto inq_init_fail; - } - - nghttp3_qpack_stream_context_init(&stream->qpack_sctx, stream_id, mem); - - stream->me.key = (key_type)stream_id; - stream->qpack_blocked_pe.index = NGHTTP3_PQ_BAD_INDEX; - stream->mem = mem; - stream->rx.http.status_code = -1; - stream->rx.http.content_length = -1; - stream->rx.http.pri = NGHTTP3_DEFAULT_URGENCY; - stream->error_code = NGHTTP3_H3_NO_ERROR; - - if (callbacks) { - stream->callbacks = *callbacks; - } - - *pstream = stream; - - return 0; - -inq_init_fail: - nghttp3_ringbuf_free(&stream->outq); -outq_init_fail: - nghttp3_ringbuf_free(&stream->chunks); -chunks_init_fail: - nghttp3_ringbuf_free(&stream->frq); -frq_init_fail: - nghttp3_mem_free(mem, stream); - - return rv; -} - -static void delete_outq(nghttp3_ringbuf *outq, const nghttp3_mem *mem) { - nghttp3_typed_buf *tbuf; - size_t i, len = nghttp3_ringbuf_len(outq); - - for (i = 0; i < len; ++i) { - tbuf = nghttp3_ringbuf_get(outq, i); - if (tbuf->type == NGHTTP3_BUF_TYPE_PRIVATE) { - nghttp3_buf_free(&tbuf->buf, mem); - } - } - - nghttp3_ringbuf_free(outq); -} - -static void delete_chunks(nghttp3_ringbuf *chunks, const nghttp3_mem *mem) { - nghttp3_buf *buf; - size_t i, len = nghttp3_ringbuf_len(chunks); - - for (i = 0; i < len; ++i) { - buf = nghttp3_ringbuf_get(chunks, i); - nghttp3_buf_free(buf, mem); - } - - nghttp3_ringbuf_free(chunks); -} - -static void delete_frq(nghttp3_ringbuf *frq, const nghttp3_mem *mem) { - nghttp3_frame_entry *frent; - size_t i, len = nghttp3_ringbuf_len(frq); - - for (i = 0; i < len; ++i) { - frent = nghttp3_ringbuf_get(frq, i); - switch (frent->fr.hd.type) { - case NGHTTP3_FRAME_HEADERS: - nghttp3_frame_headers_free(&frent->fr.headers, mem); - break; - case NGHTTP3_FRAME_PUSH_PROMISE: - nghttp3_frame_push_promise_free(&frent->fr.push_promise, mem); - break; - default: - break; - } - } - - nghttp3_ringbuf_free(frq); -} - -void nghttp3_stream_del(nghttp3_stream *stream) { - if (stream == NULL) { - return; - } - - nghttp3_qpack_stream_context_free(&stream->qpack_sctx); - delete_chunks(&stream->inq, stream->mem); - delete_outq(&stream->outq, stream->mem); - delete_chunks(&stream->chunks, stream->mem); - delete_frq(&stream->frq, stream->mem); - nghttp3_tnode_free(&stream->node); - - nghttp3_mem_free(stream->mem, stream); -} - -void nghttp3_varint_read_state_reset(nghttp3_varint_read_state *rvint) { - memset(rvint, 0, sizeof(*rvint)); -} - -void nghttp3_stream_read_state_reset(nghttp3_stream_read_state *rstate) { - memset(rstate, 0, sizeof(*rstate)); -} - -nghttp3_ssize nghttp3_read_varint(nghttp3_varint_read_state *rvint, - const uint8_t *src, size_t srclen, int fin) { - size_t nread = 0; - size_t n; - size_t i; - - assert(srclen > 0); - - if (rvint->left == 0) { - assert(rvint->acc == 0); - - rvint->left = nghttp3_get_varint_len(src); - if (rvint->left <= srclen) { - rvint->acc = nghttp3_get_varint(&nread, src); - rvint->left = 0; - return (nghttp3_ssize)nread; - } - - if (fin) { - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - rvint->acc = nghttp3_get_varint_fb(src); - nread = 1; - ++src; - --srclen; - --rvint->left; - } - - n = nghttp3_min(rvint->left, srclen); - - for (i = 0; i < n; ++i) { - rvint->acc = (rvint->acc << 8) + src[i]; - } - - rvint->left -= n; - nread += n; - - if (fin && rvint->left) { - return NGHTTP3_ERR_INVALID_ARGUMENT; - } - - return (nghttp3_ssize)nread; -} - -int nghttp3_stream_frq_add(nghttp3_stream *stream, - const nghttp3_frame_entry *frent) { - nghttp3_ringbuf *frq = &stream->frq; - nghttp3_frame_entry *dest; - int rv; - - if (nghttp3_ringbuf_full(frq)) { - size_t nlen = nghttp3_max(NGHTTP3_MIN_RBLEN, nghttp3_ringbuf_len(frq) * 2); - rv = nghttp3_ringbuf_reserve(frq, nlen); - if (rv != 0) { - return rv; - } - } - - dest = nghttp3_ringbuf_push_back(frq); - *dest = *frent; - - return 0; -} - -int nghttp3_stream_fill_outq(nghttp3_stream *stream) { - nghttp3_ringbuf *frq = &stream->frq; - nghttp3_frame_entry *frent; - int data_eof; - int rv; - - for (; nghttp3_ringbuf_len(frq) && !nghttp3_stream_outq_is_full(stream) && - stream->unsent_bytes < NGHTTP3_MIN_UNSENT_BYTES;) { - frent = nghttp3_ringbuf_get(frq, 0); - - switch (frent->fr.hd.type) { - case NGHTTP3_FRAME_SETTINGS: - rv = nghttp3_stream_write_settings(stream, frent); - if (rv != 0) { - return rv; - } - break; - case NGHTTP3_FRAME_HEADERS: - rv = nghttp3_stream_write_headers(stream, frent); - if (rv != 0) { - return rv; - } - nghttp3_frame_headers_free(&frent->fr.headers, stream->mem); - break; - case NGHTTP3_FRAME_PUSH_PROMISE: - rv = nghttp3_stream_write_push_promise(stream, frent); - if (rv != 0) { - return rv; - } - nghttp3_frame_push_promise_free(&frent->fr.push_promise, stream->mem); - break; - case NGHTTP3_FRAME_CANCEL_PUSH: - rv = nghttp3_stream_write_cancel_push(stream, frent); - if (rv != 0) { - return rv; - } - break; - case NGHTTP3_FRAME_DATA: - rv = nghttp3_stream_write_data(stream, &data_eof, frent); - if (rv != 0) { - return rv; - } - if (stream->flags & NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED) { - return 0; - } - if (!data_eof) { - return 0; - } - break; - case NGHTTP3_FRAME_MAX_PUSH_ID: - rv = nghttp3_stream_write_max_push_id(stream, frent); - if (rv != 0) { - return rv; - } - break; - default: - /* TODO Not implemented */ - break; - } - - nghttp3_ringbuf_pop_front(frq); - } - - return 0; -} - -static void typed_buf_shared_init(nghttp3_typed_buf *tbuf, - const nghttp3_buf *chunk) { - nghttp3_typed_buf_init(tbuf, chunk, NGHTTP3_BUF_TYPE_SHARED); - tbuf->buf.pos = tbuf->buf.last; -} - -int nghttp3_stream_write_stream_type(nghttp3_stream *stream) { - size_t len = nghttp3_put_varint_len((int64_t)stream->type); - nghttp3_buf *chunk; - nghttp3_typed_buf tbuf; - int rv; - - rv = nghttp3_stream_ensure_chunk(stream, len); - if (rv != 0) { - return rv; - } - - chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); - - chunk->last = nghttp3_put_varint(chunk->last, (int64_t)stream->type); - tbuf.buf.last = chunk->last; - - return nghttp3_stream_outq_add(stream, &tbuf); -} - -int nghttp3_stream_write_stream_type_push_id(nghttp3_stream *stream) { - size_t len; - nghttp3_buf *chunk; - nghttp3_typed_buf tbuf; - int rv; - nghttp3_push_promise *pp = stream->pp; - - assert(stream->type == NGHTTP3_STREAM_TYPE_PUSH); - assert(pp); - - len = nghttp3_put_varint_len((int64_t)stream->type) + - nghttp3_put_varint_len(pp->node.nid.id); - - rv = nghttp3_stream_ensure_chunk(stream, len); - if (rv != 0) { - return rv; - } - - chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); - - chunk->last = nghttp3_put_varint(chunk->last, (int64_t)stream->type); - chunk->last = nghttp3_put_varint(chunk->last, pp->node.nid.id); - tbuf.buf.last = chunk->last; - - return nghttp3_stream_outq_add(stream, &tbuf); -} - -int nghttp3_stream_write_settings(nghttp3_stream *stream, - nghttp3_frame_entry *frent) { - size_t len; - int rv; - nghttp3_buf *chunk; - nghttp3_typed_buf tbuf; - struct { - nghttp3_frame_settings settings; - nghttp3_settings_entry iv[15]; - } fr; - nghttp3_settings_entry *iv; - nghttp3_conn_settings *local_settings = frent->aux.settings.local_settings; - - fr.settings.hd.type = NGHTTP3_FRAME_SETTINGS; - fr.settings.niv = 3; - iv = &fr.settings.iv[0]; - - iv[0].id = NGHTTP3_SETTINGS_ID_MAX_FIELD_SECTION_SIZE; - iv[0].value = local_settings->max_field_section_size; - iv[1].id = NGHTTP3_SETTINGS_ID_QPACK_MAX_TABLE_CAPACITY; - iv[1].value = local_settings->qpack_max_table_capacity; - iv[2].id = NGHTTP3_SETTINGS_ID_QPACK_BLOCKED_STREAMS; - iv[2].value = local_settings->qpack_blocked_streams; - - len = nghttp3_frame_write_settings_len(&fr.settings.hd.length, &fr.settings); - - rv = nghttp3_stream_ensure_chunk(stream, len); - if (rv != 0) { - return rv; - } - - chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); - - chunk->last = nghttp3_frame_write_settings(chunk->last, &fr.settings); - - tbuf.buf.last = chunk->last; - - return nghttp3_stream_outq_add(stream, &tbuf); -} - -int nghttp3_stream_write_cancel_push(nghttp3_stream *stream, - nghttp3_frame_entry *frent) { - nghttp3_frame_cancel_push *fr = &frent->fr.cancel_push; - size_t len; - int rv; - nghttp3_buf *chunk; - nghttp3_typed_buf tbuf; - - len = nghttp3_frame_write_cancel_push_len(&fr->hd.length, fr); - - rv = nghttp3_stream_ensure_chunk(stream, len); - if (rv != 0) { - return rv; - } - - chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); - - chunk->last = nghttp3_frame_write_cancel_push(chunk->last, fr); - - tbuf.buf.last = chunk->last; - - return nghttp3_stream_outq_add(stream, &tbuf); -} - -int nghttp3_stream_write_max_push_id(nghttp3_stream *stream, - nghttp3_frame_entry *frent) { - nghttp3_frame_max_push_id *fr = &frent->fr.max_push_id; - nghttp3_conn *conn = stream->conn; - size_t len; - int rv; - nghttp3_buf *chunk; - nghttp3_typed_buf tbuf; - - assert(conn); - assert(conn->flags & NGHTTP3_CONN_FLAG_MAX_PUSH_ID_QUEUED); - - fr->push_id = (int64_t)conn->remote.uni.unsent_max_pushes - 1; - conn->remote.uni.max_pushes = conn->remote.uni.unsent_max_pushes; - conn->flags &= (uint16_t)~NGHTTP3_CONN_FLAG_MAX_PUSH_ID_QUEUED; - - len = nghttp3_frame_write_max_push_id_len(&fr->hd.length, fr); - - rv = nghttp3_stream_ensure_chunk(stream, len); - if (rv != 0) { - return rv; - } - - chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); - - chunk->last = nghttp3_frame_write_max_push_id(chunk->last, fr); - - tbuf.buf.last = chunk->last; - - return nghttp3_stream_outq_add(stream, &tbuf); -} - -int nghttp3_stream_write_headers(nghttp3_stream *stream, - nghttp3_frame_entry *frent) { - nghttp3_frame_headers *fr = &frent->fr.headers; - nghttp3_conn *conn = stream->conn; - - assert(conn); - - return nghttp3_stream_write_header_block( - stream, &conn->qenc, conn->tx.qenc, &conn->tx.qpack.rbuf, - &conn->tx.qpack.ebuf, NGHTTP3_FRAME_HEADERS, 0, fr->nva, fr->nvlen); -} - -int nghttp3_stream_write_push_promise(nghttp3_stream *stream, - nghttp3_frame_entry *frent) { - nghttp3_frame_push_promise *fr = &frent->fr.push_promise; - nghttp3_conn *conn = stream->conn; - - assert(conn); - - return nghttp3_stream_write_header_block( - stream, &conn->qenc, conn->tx.qenc, &conn->tx.qpack.rbuf, - &conn->tx.qpack.ebuf, NGHTTP3_FRAME_PUSH_PROMISE, fr->push_id, fr->nva, - fr->nvlen); -} - -int nghttp3_stream_write_header_block(nghttp3_stream *stream, - nghttp3_qpack_encoder *qenc, - nghttp3_stream *qenc_stream, - nghttp3_buf *rbuf, nghttp3_buf *ebuf, - int64_t frame_type, int64_t push_id, - const nghttp3_nv *nva, size_t nvlen) { - nghttp3_buf pbuf; - int rv; - size_t len; - nghttp3_buf *chunk; - nghttp3_typed_buf tbuf; - nghttp3_frame_hd hd; - size_t push_idlen = 0; - uint8_t raw_pbuf[16]; - size_t pbuflen, rbuflen, ebuflen; - - nghttp3_buf_wrap_init(&pbuf, raw_pbuf, sizeof(raw_pbuf)); - - rv = nghttp3_qpack_encoder_encode(qenc, &pbuf, rbuf, ebuf, - stream->node.nid.id, nva, nvlen); - if (rv != 0) { - goto fail; - } - - pbuflen = nghttp3_buf_len(&pbuf); - rbuflen = nghttp3_buf_len(rbuf); - ebuflen = nghttp3_buf_len(ebuf); - - if (frame_type == NGHTTP3_FRAME_PUSH_PROMISE) { - push_idlen = nghttp3_put_varint_len(push_id); - } - - hd.type = frame_type; - hd.length = (int64_t)(pbuflen + rbuflen + push_idlen); - - len = nghttp3_frame_write_hd_len(&hd) + push_idlen + pbuflen; - - if (rbuflen <= NGHTTP3_STREAM_MAX_COPY_THRES) { - len += rbuflen; - } - - rv = nghttp3_stream_ensure_chunk(stream, len); - if (rv != 0) { - goto fail; - } - - chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); - - chunk->last = nghttp3_frame_write_hd(chunk->last, &hd); - - if (push_idlen) { - chunk->last = nghttp3_put_varint(chunk->last, push_id); - } - - chunk->last = nghttp3_cpymem(chunk->last, pbuf.pos, pbuflen); - nghttp3_buf_init(&pbuf); - - if (rbuflen > NGHTTP3_STREAM_MAX_COPY_THRES) { - tbuf.buf.last = chunk->last; - - rv = nghttp3_stream_outq_add(stream, &tbuf); - if (rv != 0) { - goto fail; - } - - nghttp3_typed_buf_init(&tbuf, rbuf, NGHTTP3_BUF_TYPE_PRIVATE); - rv = nghttp3_stream_outq_add(stream, &tbuf); - if (rv != 0) { - goto fail; - } - nghttp3_buf_init(rbuf); - } else if (rbuflen) { - chunk->last = nghttp3_cpymem(chunk->last, rbuf->pos, rbuflen); - tbuf.buf.last = chunk->last; - - rv = nghttp3_stream_outq_add(stream, &tbuf); - if (rv != 0) { - goto fail; - } - nghttp3_buf_reset(rbuf); - } - - if (ebuflen > NGHTTP3_STREAM_MAX_COPY_THRES) { - assert(qenc_stream); - - nghttp3_typed_buf_init(&tbuf, ebuf, NGHTTP3_BUF_TYPE_PRIVATE); - rv = nghttp3_stream_outq_add(qenc_stream, &tbuf); - if (rv != 0) { - return rv; - } - nghttp3_buf_init(ebuf); - } else if (ebuflen) { - assert(qenc_stream); - - rv = nghttp3_stream_ensure_chunk(qenc_stream, ebuflen); - if (rv != 0) { - goto fail; - } - - chunk = nghttp3_stream_get_chunk(qenc_stream); - typed_buf_shared_init(&tbuf, chunk); - - chunk->last = nghttp3_cpymem(chunk->last, ebuf->pos, ebuflen); - tbuf.buf.last = chunk->last; - - rv = nghttp3_stream_outq_add(qenc_stream, &tbuf); - if (rv != 0) { - goto fail; - } - nghttp3_buf_reset(ebuf); - } - - assert(0 == nghttp3_buf_len(&pbuf)); - assert(0 == nghttp3_buf_len(rbuf)); - assert(0 == nghttp3_buf_len(ebuf)); - - return 0; - -fail: - - return rv; -} - -int nghttp3_stream_write_data(nghttp3_stream *stream, int *peof, - nghttp3_frame_entry *frent) { - int rv; - size_t len; - nghttp3_typed_buf tbuf; - nghttp3_buf buf; - nghttp3_buf *chunk; - nghttp3_read_data_callback read_data = frent->aux.data.dr.read_data; - nghttp3_conn *conn = stream->conn; - size_t datalen; - uint32_t flags = 0; - nghttp3_frame_hd hd; - nghttp3_vec vec[8]; - nghttp3_vec *v; - nghttp3_ssize sveccnt; - size_t i; - - assert(!(stream->flags & NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED)); - assert(read_data); - assert(conn); - - *peof = 0; - - sveccnt = read_data(conn, stream->node.nid.id, vec, nghttp3_arraylen(vec), - &flags, conn->user_data, stream->user_data); - if (sveccnt < 0) { - if (sveccnt == NGHTTP3_ERR_WOULDBLOCK) { - stream->flags |= NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED; - return 0; - } - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - - datalen = nghttp3_vec_len(vec, (size_t)sveccnt); - - assert(datalen || flags & NGHTTP3_DATA_FLAG_EOF); - - if (flags & NGHTTP3_DATA_FLAG_EOF) { - *peof = 1; - if (!(flags & NGHTTP3_DATA_FLAG_NO_END_STREAM)) { - stream->flags |= NGHTTP3_STREAM_FLAG_WRITE_END_STREAM; - if (datalen == 0) { - if (nghttp3_stream_outq_write_done(stream)) { - /* If this is the last data and its is 0 length, we don't - need send DATA frame. We rely on the non-emptiness of - outq to schedule stream, so add empty tbuf to outq to - just send fin. */ - nghttp3_buf_init(&buf); - nghttp3_typed_buf_init(&tbuf, &buf, NGHTTP3_BUF_TYPE_PRIVATE); - return nghttp3_stream_outq_add(stream, &tbuf); - } - return 0; - } - } - - if (datalen == 0) { - /* We are going to send more frames, but no DATA frame this - time. */ - return 0; - } - } - - hd.type = NGHTTP3_FRAME_DATA; - hd.length = (int64_t)datalen; - - len = nghttp3_frame_write_hd_len(&hd); - - rv = nghttp3_stream_ensure_chunk(stream, len); - if (rv != 0) { - return rv; - } - - chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); - - chunk->last = nghttp3_frame_write_hd(chunk->last, &hd); - - tbuf.buf.last = chunk->last; - - rv = nghttp3_stream_outq_add(stream, &tbuf); - if (rv != 0) { - return rv; - } - - if (datalen) { - for (i = 0; i < (size_t)sveccnt; ++i) { - v = &vec[i]; - if (v->len == 0) { - continue; - } - nghttp3_buf_wrap_init(&buf, v->base, v->len); - buf.last = buf.end; - nghttp3_typed_buf_init(&tbuf, &buf, NGHTTP3_BUF_TYPE_ALIEN); - rv = nghttp3_stream_outq_add(stream, &tbuf); - if (rv != 0) { - return rv; - } - } - } - - return 0; -} - -int nghttp3_stream_write_qpack_decoder_stream(nghttp3_stream *stream) { - nghttp3_qpack_decoder *qdec; - nghttp3_buf *chunk; - int rv; - nghttp3_typed_buf tbuf; - size_t len; - - assert(stream->conn); - assert(stream->conn->tx.qdec == stream); - - qdec = &stream->conn->qdec; - - assert(qdec); - - len = nghttp3_qpack_decoder_get_decoder_streamlen(qdec); - if (len == 0) { - return 0; - } - - rv = nghttp3_stream_ensure_chunk(stream, len); - if (rv != 0) { - return rv; - } - - chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); - - nghttp3_qpack_decoder_write_decoder(qdec, chunk); - - tbuf.buf.last = chunk->last; - - return nghttp3_stream_outq_add(stream, &tbuf); -} - -int nghttp3_stream_outq_is_full(nghttp3_stream *stream) { - /* TODO Verify that the limit is reasonable. */ - return nghttp3_ringbuf_len(&stream->outq) >= 1024; -} - -int nghttp3_stream_outq_add(nghttp3_stream *stream, - const nghttp3_typed_buf *tbuf) { - nghttp3_ringbuf *outq = &stream->outq; - int rv; - nghttp3_typed_buf *dest; - size_t len = nghttp3_ringbuf_len(outq); - - stream->unsent_bytes += nghttp3_buf_len(&tbuf->buf); - - if (len) { - dest = nghttp3_ringbuf_get(outq, len - 1); - if (dest->type == tbuf->type && dest->type == NGHTTP3_BUF_TYPE_SHARED && - dest->buf.begin == tbuf->buf.begin && dest->buf.last == tbuf->buf.pos) { - /* If we have already written last entry, adjust outq_idx and - offset so that this entry is eligible to send. */ - if (len == stream->outq_idx) { - --stream->outq_idx; - stream->outq_offset = nghttp3_buf_len(&dest->buf); - } - - dest->buf.last = tbuf->buf.last; - /* TODO Is this required? */ - dest->buf.end = tbuf->buf.end; - - return 0; - } - } - - if (nghttp3_ringbuf_full(outq)) { - size_t nlen = nghttp3_max(NGHTTP3_MIN_RBLEN, len * 2); - rv = nghttp3_ringbuf_reserve(outq, nlen); - if (rv != 0) { - return rv; - } - } - - dest = nghttp3_ringbuf_push_back(outq); - *dest = *tbuf; - - return 0; -} - -int nghttp3_stream_ensure_chunk(nghttp3_stream *stream, size_t need) { - nghttp3_ringbuf *chunks = &stream->chunks; - nghttp3_buf *chunk; - size_t len = nghttp3_ringbuf_len(chunks); - uint8_t *p; - int rv; - size_t n = NGHTTP3_STREAM_MIN_CHUNK_SIZE; - - if (len) { - chunk = nghttp3_ringbuf_get(chunks, len - 1); - if (nghttp3_buf_left(chunk) >= need) { - return 0; - } - } - - for (; n < need; n *= 2) - ; - - p = nghttp3_mem_malloc(stream->mem, n); - if (p == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - if (nghttp3_ringbuf_full(chunks)) { - size_t nlen = nghttp3_max(NGHTTP3_MIN_RBLEN, len * 2); - rv = nghttp3_ringbuf_reserve(chunks, nlen); - if (rv != 0) { - return rv; - } - } - - chunk = nghttp3_ringbuf_push_back(chunks); - nghttp3_buf_wrap_init(chunk, p, n); - - return 0; -} - -nghttp3_buf *nghttp3_stream_get_chunk(nghttp3_stream *stream) { - nghttp3_ringbuf *chunks = &stream->chunks; - size_t len = nghttp3_ringbuf_len(chunks); - - assert(len); - - return nghttp3_ringbuf_get(chunks, len - 1); -} - -int nghttp3_stream_is_blocked(nghttp3_stream *stream) { - return (stream->flags & NGHTTP3_STREAM_FLAG_FC_BLOCKED) || - (stream->flags & NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED); -} - -int nghttp3_stream_require_schedule(nghttp3_stream *stream) { - return (!nghttp3_stream_outq_write_done(stream) && - !(stream->flags & NGHTTP3_STREAM_FLAG_FC_BLOCKED)) || - (nghttp3_ringbuf_len(&stream->frq) && - !(stream->flags & NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED)); -} - -nghttp3_ssize nghttp3_stream_writev(nghttp3_stream *stream, int *pfin, - nghttp3_vec *vec, size_t veccnt) { - nghttp3_ringbuf *outq = &stream->outq; - size_t len = nghttp3_ringbuf_len(outq); - size_t i; - size_t offset = stream->outq_offset; - size_t buflen; - nghttp3_vec *vbegin = vec, *vend = vec + veccnt; - nghttp3_typed_buf *tbuf; - - assert(veccnt > 0); - - for (i = stream->outq_idx; i < len; ++i) { - tbuf = nghttp3_ringbuf_get(outq, i); - buflen = nghttp3_buf_len(&tbuf->buf); - if (offset >= buflen) { - offset -= buflen; - continue; - } - - vec->base = tbuf->buf.pos + offset; - vec->len = buflen - offset; - ++vec; - ++i; - break; - } - - for (; i < len && vec != vend; ++i, ++vec) { - tbuf = nghttp3_ringbuf_get(outq, i); - vec->base = tbuf->buf.pos; - vec->len = nghttp3_buf_len(&tbuf->buf); - } - - /* TODO Rework this if we have finished implementing HTTP - messaging */ - *pfin = nghttp3_ringbuf_len(&stream->frq) == 0 && i == len && - (stream->flags & NGHTTP3_STREAM_FLAG_WRITE_END_STREAM); - - return vec - vbegin; -} - -int nghttp3_stream_add_outq_offset(nghttp3_stream *stream, size_t n) { - nghttp3_ringbuf *outq = &stream->outq; - size_t i; - size_t len = nghttp3_ringbuf_len(outq); - size_t offset = stream->outq_offset + n; - size_t buflen; - nghttp3_typed_buf *tbuf; - - for (i = stream->outq_idx; i < len; ++i) { - tbuf = nghttp3_ringbuf_get(outq, i); - buflen = nghttp3_buf_len(&tbuf->buf); - if (offset >= buflen) { - offset -= buflen; - continue; - } - - break; - } - - assert(i < len || offset == 0); - - stream->unsent_bytes -= n; - stream->outq_idx = i; - stream->outq_offset = offset; - - return 0; -} - -int nghttp3_stream_outq_write_done(nghttp3_stream *stream) { - nghttp3_ringbuf *outq = &stream->outq; - size_t len = nghttp3_ringbuf_len(outq); - - return len == 0 || stream->outq_idx >= len; -} - -static int stream_pop_outq_entry(nghttp3_stream *stream, - nghttp3_typed_buf *tbuf) { - nghttp3_ringbuf *chunks = &stream->chunks; - nghttp3_buf *chunk; - - switch (tbuf->type) { - case NGHTTP3_BUF_TYPE_PRIVATE: - nghttp3_buf_free(&tbuf->buf, stream->mem); - break; - case NGHTTP3_BUF_TYPE_ALIEN: - break; - default: - assert(nghttp3_ringbuf_len(chunks)); - - chunk = nghttp3_ringbuf_get(chunks, 0); - - assert(chunk->begin == tbuf->buf.begin); - assert(chunk->end == tbuf->buf.end); - - if (chunk->last == tbuf->buf.last) { - nghttp3_buf_free(chunk, stream->mem); - nghttp3_ringbuf_pop_front(chunks); - } - }; - - nghttp3_ringbuf_pop_front(&stream->outq); - - return 0; -} - -int nghttp3_stream_add_ack_offset(nghttp3_stream *stream, uint64_t n) { - nghttp3_ringbuf *outq = &stream->outq; - uint64_t offset = stream->ack_offset + n; - size_t buflen; - size_t npopped = 0; - size_t nack; - nghttp3_typed_buf *tbuf; - int rv; - - for (; nghttp3_ringbuf_len(outq);) { - tbuf = nghttp3_ringbuf_get(outq, 0); - buflen = nghttp3_buf_len(&tbuf->buf); - - if (tbuf->type == NGHTTP3_BUF_TYPE_ALIEN) { - nack = (size_t)nghttp3_min(offset, (uint64_t)buflen) - stream->ack_done; - if (stream->callbacks.acked_data) { - rv = stream->callbacks.acked_data(stream, stream->node.nid.id, nack, - stream->user_data); - if (rv != 0) { - return NGHTTP3_ERR_CALLBACK_FAILURE; - } - } - stream->ack_done += nack; - } - - if (offset >= buflen) { - rv = stream_pop_outq_entry(stream, tbuf); - if (rv != 0) { - return rv; - } - - offset -= buflen; - ++npopped; - stream->ack_done = 0; - - if (stream->outq_idx + 1 == npopped) { - stream->outq_offset = 0; - break; - } - - continue; - } - - break; - } - - assert(stream->outq_idx + 1 >= npopped); - if (stream->outq_idx >= npopped) { - stream->outq_idx -= npopped; - } else { - stream->outq_idx = 0; - } - - stream->ack_offset = offset; - - return 0; -} - -int nghttp3_stream_buffer_data(nghttp3_stream *stream, const uint8_t *data, - size_t datalen) { - nghttp3_ringbuf *inq = &stream->inq; - size_t len = nghttp3_ringbuf_len(inq); - nghttp3_buf *buf; - size_t nwrite; - uint8_t *rawbuf; - size_t bufleft; - int rv; - - if (len) { - buf = nghttp3_ringbuf_get(inq, len - 1); - bufleft = nghttp3_buf_left(buf); - nwrite = nghttp3_min(datalen, bufleft); - buf->last = nghttp3_cpymem(buf->last, data, nwrite); - data += nwrite; - datalen -= nwrite; - } - - for (; datalen;) { - if (nghttp3_ringbuf_full(inq)) { - size_t nlen = - nghttp3_max(NGHTTP3_MIN_RBLEN, nghttp3_ringbuf_len(inq) * 2); - rv = nghttp3_ringbuf_reserve(inq, nlen); - if (rv != 0) { - return rv; - } - } - - rawbuf = nghttp3_mem_malloc(stream->mem, 16384); - if (rawbuf == NULL) { - return NGHTTP3_ERR_NOMEM; - } - - buf = nghttp3_ringbuf_push_back(inq); - nghttp3_buf_wrap_init(buf, rawbuf, 16384); - bufleft = nghttp3_buf_left(buf); - nwrite = nghttp3_min(datalen, bufleft); - buf->last = nghttp3_cpymem(buf->last, data, nwrite); - data += nwrite; - datalen -= nwrite; - } - - return 0; -} - -size_t nghttp3_stream_get_buffered_datalen(nghttp3_stream *stream) { - nghttp3_ringbuf *inq = &stream->inq; - size_t len = nghttp3_ringbuf_len(inq); - size_t i, n = 0; - nghttp3_buf *buf; - - for (i = 0; i < len; ++i) { - buf = nghttp3_ringbuf_get(inq, i); - n += nghttp3_buf_len(buf); - } - - return n; -} - -int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream, - nghttp3_stream_http_event event) { - int rv; - - switch (stream->rx.hstate) { - case NGHTTP3_HTTP_STATE_NONE: - return NGHTTP3_ERR_H3_INTERNAL_ERROR; - case NGHTTP3_HTTP_STATE_REQ_INITIAL: - switch (event) { - case NGHTTP3_HTTP_EVENT_HEADERS_BEGIN: - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_HEADERS_BEGIN; - return 0; - default: - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - case NGHTTP3_HTTP_STATE_REQ_HEADERS_BEGIN: - if (event != NGHTTP3_HTTP_EVENT_HEADERS_END) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_HEADERS_END; - return 0; - case NGHTTP3_HTTP_STATE_REQ_HEADERS_END: - switch (event) { - case NGHTTP3_HTTP_EVENT_HEADERS_BEGIN: - /* TODO Better to check status code */ - if (stream->rx.http.flags & NGHTTP3_HTTP_FLAG_METH_CONNECT) { - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - rv = nghttp3_http_on_remote_end_stream(stream); - if (rv != 0) { - return rv; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_TRAILERS_BEGIN; - return 0; - case NGHTTP3_HTTP_EVENT_DATA_BEGIN: - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_DATA_BEGIN; - return 0; - case NGHTTP3_HTTP_EVENT_MSG_END: - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_END; - return 0; - default: - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - case NGHTTP3_HTTP_STATE_REQ_DATA_BEGIN: - if (event != NGHTTP3_HTTP_EVENT_DATA_END) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_DATA_END; - return 0; - case NGHTTP3_HTTP_STATE_REQ_DATA_END: - switch (event) { - case NGHTTP3_HTTP_EVENT_DATA_BEGIN: - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_DATA_BEGIN; - return 0; - case NGHTTP3_HTTP_EVENT_HEADERS_BEGIN: - /* TODO Better to check status code */ - if (stream->rx.http.flags & NGHTTP3_HTTP_FLAG_METH_CONNECT) { - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - rv = nghttp3_http_on_remote_end_stream(stream); - if (rv != 0) { - return rv; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_TRAILERS_BEGIN; - return 0; - case NGHTTP3_HTTP_EVENT_MSG_END: - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_END; - return 0; - default: - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - case NGHTTP3_HTTP_STATE_REQ_TRAILERS_BEGIN: - if (event != NGHTTP3_HTTP_EVENT_HEADERS_END) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_TRAILERS_END; - return 0; - case NGHTTP3_HTTP_STATE_REQ_TRAILERS_END: - if (event != NGHTTP3_HTTP_EVENT_MSG_END) { - /* TODO Should ignore unexpected frame in this state as per - spec. */ - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_END; - return 0; - case NGHTTP3_HTTP_STATE_REQ_END: - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - case NGHTTP3_HTTP_STATE_RESP_INITIAL: - if (event != NGHTTP3_HTTP_EVENT_HEADERS_BEGIN) { - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_HEADERS_BEGIN; - return 0; - case NGHTTP3_HTTP_STATE_RESP_HEADERS_BEGIN: - if (event != NGHTTP3_HTTP_EVENT_HEADERS_END) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_HEADERS_END; - return 0; - case NGHTTP3_HTTP_STATE_RESP_HEADERS_END: - switch (event) { - case NGHTTP3_HTTP_EVENT_HEADERS_BEGIN: - if (stream->rx.http.status_code == -1) { - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_HEADERS_BEGIN; - return 0; - } - if ((stream->rx.http.flags & NGHTTP3_HTTP_FLAG_METH_CONNECT) && - stream->rx.http.status_code / 100 == 2) { - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - rv = nghttp3_http_on_remote_end_stream(stream); - if (rv != 0) { - return rv; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN; - return 0; - case NGHTTP3_HTTP_EVENT_DATA_BEGIN: - if (stream->rx.http.flags & NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE) { - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_DATA_BEGIN; - return 0; - case NGHTTP3_HTTP_EVENT_MSG_END: - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_END; - return 0; - default: - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - case NGHTTP3_HTTP_STATE_RESP_DATA_BEGIN: - if (event != NGHTTP3_HTTP_EVENT_DATA_END) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_DATA_END; - return 0; - case NGHTTP3_HTTP_STATE_RESP_DATA_END: - switch (event) { - case NGHTTP3_HTTP_EVENT_DATA_BEGIN: - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_DATA_BEGIN; - return 0; - case NGHTTP3_HTTP_EVENT_HEADERS_BEGIN: - if ((stream->rx.http.flags & NGHTTP3_HTTP_FLAG_METH_CONNECT) && - stream->rx.http.status_code / 100 == 2) { - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - rv = nghttp3_http_on_remote_end_stream(stream); - if (rv != 0) { - return rv; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN; - return 0; - case NGHTTP3_HTTP_EVENT_MSG_END: - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_END; - return 0; - default: - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; - } - case NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN: - if (event != NGHTTP3_HTTP_EVENT_HEADERS_END) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_TRAILERS_END; - return 0; - case NGHTTP3_HTTP_STATE_RESP_TRAILERS_END: - if (event != NGHTTP3_HTTP_EVENT_MSG_END) { - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } - stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_END; - return 0; - case NGHTTP3_HTTP_STATE_RESP_END: - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - default: - assert(0); - } -} - -int nghttp3_stream_empty_headers_allowed(nghttp3_stream *stream) { - switch (stream->rx.hstate) { - case NGHTTP3_HTTP_STATE_REQ_TRAILERS_BEGIN: - case NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN: - return 0; - default: - return NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR; - } -} - -int nghttp3_stream_bidi_or_push(nghttp3_stream *stream) { - return (!nghttp3_stream_uni(stream->node.nid.id) || - stream->type == NGHTTP3_STREAM_TYPE_PUSH); -} - -int nghttp3_stream_uni(int64_t stream_id) { return (stream_id & 0x2) != 0; } - -int nghttp3_client_stream_bidi(int64_t stream_id) { - return (stream_id & 0x3) == 0; -} - -int nghttp3_client_stream_uni(int64_t stream_id) { - return (stream_id & 0x3) == 0x2; -} - -int nghttp3_server_stream_uni(int64_t stream_id) { - return (stream_id & 0x3) == 0x3; -} diff --git a/deps/nghttp3/lib/nghttp3_stream.h b/deps/nghttp3/lib/nghttp3_stream.h deleted file mode 100644 index 1dcc421123a239..00000000000000 --- a/deps/nghttp3/lib/nghttp3_stream.h +++ /dev/null @@ -1,406 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_STREAM_H -#define NGHTTP3_STREAM_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "nghttp3_map.h" -#include "nghttp3_tnode.h" -#include "nghttp3_ringbuf.h" -#include "nghttp3_buf.h" -#include "nghttp3_frame.h" -#include "nghttp3_qpack.h" - -#define NGHTTP3_STREAM_MIN_CHUNK_SIZE 256 - -/* NGHTTP3_MIN_UNSENT_BYTES is the minimum unsent bytes which is large - enough to fill outgoing single QUIC packet. */ -#define NGHTTP3_MIN_UNSENT_BYTES 4096 - -/* NGHTTP3_STREAM_MIN_WRITELEN is the minimum length of write to cause - the stream to reschedule. */ -#define NGHTTP3_STREAM_MIN_WRITELEN 800 - -/* nghttp3_stream_type is unidirectional stream type. */ -typedef enum { - NGHTTP3_STREAM_TYPE_CONTROL = 0x00, - NGHTTP3_STREAM_TYPE_PUSH = 0x01, - NGHTTP3_STREAM_TYPE_QPACK_ENCODER = 0x02, - NGHTTP3_STREAM_TYPE_QPACK_DECODER = 0x03, - NGHTTP3_STREAM_TYPE_UNKNOWN = UINT64_MAX, -} nghttp3_stream_type; - -typedef enum { - NGHTTP3_CTRL_STREAM_STATE_FRAME_TYPE, - NGHTTP3_CTRL_STREAM_STATE_FRAME_LENGTH, - NGHTTP3_CTRL_STREAM_STATE_CANCEL_PUSH, - NGHTTP3_CTRL_STREAM_STATE_SETTINGS, - NGHTTP3_CTRL_STREAM_STATE_GOAWAY, - NGHTTP3_CTRL_STREAM_STATE_MAX_PUSH_ID, - NGHTTP3_CTRL_STREAM_STATE_IGN_FRAME, - NGHTTP3_CTRL_STREAM_STATE_SETTINGS_ID, - NGHTTP3_CTRL_STREAM_STATE_SETTINGS_VALUE, -} nghttp3_ctrl_stream_state; - -typedef enum { - NGHTTP3_REQ_STREAM_STATE_FRAME_TYPE, - NGHTTP3_REQ_STREAM_STATE_FRAME_LENGTH, - NGHTTP3_REQ_STREAM_STATE_DATA, - NGHTTP3_REQ_STREAM_STATE_HEADERS, - NGHTTP3_REQ_STREAM_STATE_PUSH_PROMISE_PUSH_ID, - NGHTTP3_REQ_STREAM_STATE_PUSH_PROMISE, - NGHTTP3_REQ_STREAM_STATE_IGN_PUSH_PROMISE, - NGHTTP3_REQ_STREAM_STATE_IGN_FRAME, -} nghttp3_req_stream_state; - -typedef enum { - NGHTTP3_PUSH_STREAM_STATE_FRAME_TYPE, - NGHTTP3_PUSH_STREAM_STATE_FRAME_LENGTH, - NGHTTP3_PUSH_STREAM_STATE_DATA, - NGHTTP3_PUSH_STREAM_STATE_HEADERS, - NGHTTP3_PUSH_STREAM_STATE_IGN_FRAME, - NGHTTP3_PUSH_STREAM_STATE_PUSH_ID, - NGHTTP3_PUSH_STREAM_STATE_IGN_REST, -} nghttp3_push_stream_state; - -typedef struct { - int64_t acc; - size_t left; -} nghttp3_varint_read_state; - -typedef struct { - nghttp3_varint_read_state rvint; - nghttp3_frame fr; - int state; - int64_t left; -} nghttp3_stream_read_state; - -typedef enum { - NGHTTP3_STREAM_FLAG_NONE = 0x0000, - NGHTTP3_STREAM_FLAG_TYPE_IDENTIFIED = 0x0001, - /* NGHTTP3_STREAM_FLAG_FC_BLOCKED indicates that stream is - blocked by QUIC flow control. */ - NGHTTP3_STREAM_FLAG_FC_BLOCKED = 0x0002, - /* NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED indicates that application - is temporarily unable to provide data. */ - NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED = 0x0004, - /* NGHTTP3_STREAM_FLAG_WRITE_END_STREAM indicates that application - finished to feed outgoing data. */ - NGHTTP3_STREAM_FLAG_WRITE_END_STREAM = 0x0008, - /* NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED indicates that stream is - blocked due to QPACK decoding. */ - NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED = 0x0010, - /* NGHTTP3_STREAM_FLAG_READ_EOF indicates that remote endpoint sent - fin. */ - NGHTTP3_STREAM_FLAG_READ_EOF = 0x0020, - /* NGHTTP3_STREAM_FLAG_CLOSED indicates that QUIC stream was closed. - nghttp3_stream object can still alive because it might be blocked - by QPACK decoder. */ - NGHTTP3_STREAM_FLAG_CLOSED = 0x0040, - /* NGHTTP3_STREAM_FLAG_PUSH_PROMISE_BLOCKED indicates that stream is - blocked because the corresponding PUSH_PROMISE has not been - received yet. */ - NGHTTP3_STREAM_FLAG_PUSH_PROMISE_BLOCKED = 0x0080, - /* NGHTTP3_STREAM_FLAG_RESET indicates that stream is reset. */ - NGHTTP3_STREAM_FLAG_RESET = 0x0200, -} nghttp3_stream_flag; - -typedef enum { - NGHTTP3_HTTP_STATE_NONE, - NGHTTP3_HTTP_STATE_REQ_INITIAL, - NGHTTP3_HTTP_STATE_REQ_BEGIN, - NGHTTP3_HTTP_STATE_REQ_HEADERS_BEGIN, - NGHTTP3_HTTP_STATE_REQ_HEADERS_END, - NGHTTP3_HTTP_STATE_REQ_DATA_BEGIN, - NGHTTP3_HTTP_STATE_REQ_DATA_END, - NGHTTP3_HTTP_STATE_REQ_TRAILERS_BEGIN, - NGHTTP3_HTTP_STATE_REQ_TRAILERS_END, - NGHTTP3_HTTP_STATE_REQ_END, - NGHTTP3_HTTP_STATE_RESP_INITIAL, - NGHTTP3_HTTP_STATE_RESP_BEGIN, - NGHTTP3_HTTP_STATE_RESP_HEADERS_BEGIN, - NGHTTP3_HTTP_STATE_RESP_HEADERS_END, - NGHTTP3_HTTP_STATE_RESP_DATA_BEGIN, - NGHTTP3_HTTP_STATE_RESP_DATA_END, - NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN, - NGHTTP3_HTTP_STATE_RESP_TRAILERS_END, - NGHTTP3_HTTP_STATE_RESP_END, -} nghttp3_stream_http_state; - -typedef enum { - NGHTTP3_HTTP_EVENT_DATA_BEGIN, - NGHTTP3_HTTP_EVENT_DATA_END, - NGHTTP3_HTTP_EVENT_HEADERS_BEGIN, - NGHTTP3_HTTP_EVENT_HEADERS_END, - NGHTTP3_HTTP_EVENT_PUSH_PROMISE_BEGIN, - NGHTTP3_HTTP_EVENT_PUSH_PROMISE_END, - NGHTTP3_HTTP_EVENT_MSG_END, -} nghttp3_stream_http_event; - -struct nghttp3_stream; -typedef struct nghttp3_stream nghttp3_stream; - -struct nghttp3_push_promise; -typedef struct nghttp3_push_promise nghttp3_push_promise; - -/* - * nghttp3_stream_acked_data is a callback function which is invoked - * when data sent on stream denoted by |stream_id| supplied from - * application is acknowledged by remote endpoint. The number of - * bytes acknowledged is given in |datalen|. - * - * The implementation of this callback must return 0 if it succeeds. - * Returning NGHTTP3_ERR_CALLBACK_FAILURE will return to the caller - * immediately. Any values other than 0 is treated as - * NGHTTP3_ERR_CALLBACK_FAILURE. - */ -typedef int (*nghttp3_stream_acked_data)(nghttp3_stream *stream, - int64_t stream_id, size_t datalen, - void *user_data); - -typedef struct { - nghttp3_stream_acked_data acked_data; -} nghttp3_stream_callbacks; - -struct nghttp3_http_state { - /* status_code is HTTP status code received. This field is used - if connection is initialized as client. */ - int32_t status_code; - /* content_length is the value of received content-length header - field. */ - int64_t content_length; - /* recv_content_length is the number of body bytes received so - far. */ - int64_t recv_content_length; - uint16_t flags; - /* pri is a stream priority produced by nghttp3_pri_to_uint8. */ - uint8_t pri; -}; - -typedef struct nghttp3_http_state nghttp3_http_state; - -struct nghttp3_stream { - const nghttp3_mem *mem; - nghttp3_map_entry me; - /* node is a node in dependency tree. For server initiated - unidirectional stream (push), scheduling is done via - corresponding nghttp3_push_promise object pointed by pp. */ - nghttp3_tnode node; - nghttp3_pq_entry qpack_blocked_pe; - nghttp3_stream_callbacks callbacks; - nghttp3_ringbuf frq; - nghttp3_ringbuf chunks; - nghttp3_ringbuf outq; - /* inq stores the stream raw data which cannot be read because - stream is blocked by QPACK decoder. */ - nghttp3_ringbuf inq; - nghttp3_qpack_stream_context qpack_sctx; - /* conn is a reference to underlying connection. It could be NULL - if stream is not a request/push stream. */ - nghttp3_conn *conn; - void *user_data; - /* unsent_bytes is the number of bytes in outq not written yet */ - size_t unsent_bytes; - /* outq_idx is an index into outq where next write is made. */ - size_t outq_idx; - /* outq_offset is write offset relative to the element at outq_idx - in outq. */ - size_t outq_offset; - /* ack_offset is offset acknowledged by peer relative to the first - element in outq. */ - uint64_t ack_offset; - /* ack_done is the number of bytes notified to an application that - they are acknowledged inside the first outq element if it is of - type NGHTTP3_BUF_TYPE_ALIEN. */ - size_t ack_done; - size_t unscheduled_nwrite; - nghttp3_stream_type type; - nghttp3_stream_read_state rstate; - /* pp is nghttp3_push_promise that this stream fulfills. */ - nghttp3_push_promise *pp; - /* error_code indicates the reason of closure of this stream. */ - uint64_t error_code; - - struct { - nghttp3_stream_http_state hstate; - } tx; - - struct { - nghttp3_stream_http_state hstate; - nghttp3_http_state http; - } rx; - - uint16_t flags; -}; - -typedef struct { - nghttp3_frame fr; - union { - struct { - nghttp3_conn_settings *local_settings; - } settings; - struct { - nghttp3_data_reader dr; - } data; - } aux; -} nghttp3_frame_entry; - -int nghttp3_stream_new(nghttp3_stream **pstream, int64_t stream_id, - uint64_t seq, const nghttp3_stream_callbacks *callbacks, - const nghttp3_mem *mem); - -void nghttp3_stream_del(nghttp3_stream *stream); - -void nghttp3_varint_read_state_reset(nghttp3_varint_read_state *rvint); - -void nghttp3_stream_read_state_reset(nghttp3_stream_read_state *rstate); - -nghttp3_ssize nghttp3_read_varint(nghttp3_varint_read_state *rvint, - const uint8_t *src, size_t srclen, int fin); - -int nghttp3_stream_frq_add(nghttp3_stream *stream, - const nghttp3_frame_entry *frent); - -int nghttp3_stream_fill_outq(nghttp3_stream *stream); - -int nghttp3_stream_write_stream_type(nghttp3_stream *stream); - -int nghttp3_stream_write_stream_type_push_id(nghttp3_stream *stream); - -nghttp3_ssize nghttp3_stream_writev(nghttp3_stream *stream, int *pfin, - nghttp3_vec *vec, size_t veccnt); - -int nghttp3_stream_write_qpack_decoder_stream(nghttp3_stream *stream); - -int nghttp3_stream_outq_is_full(nghttp3_stream *stream); - -int nghttp3_stream_outq_add(nghttp3_stream *stream, - const nghttp3_typed_buf *tbuf); - -int nghttp3_stream_write_headers(nghttp3_stream *stream, - nghttp3_frame_entry *frent); - -int nghttp3_stream_write_push_promise(nghttp3_stream *stream, - nghttp3_frame_entry *frent); - -int nghttp3_stream_write_header_block(nghttp3_stream *stream, - nghttp3_qpack_encoder *qenc, - nghttp3_stream *qenc_stream, - nghttp3_buf *rbuf, nghttp3_buf *ebuf, - int64_t frame_type, int64_t push_id, - const nghttp3_nv *nva, size_t nvlen); - -int nghttp3_stream_write_data(nghttp3_stream *stream, int *peof, - nghttp3_frame_entry *frent); - -int nghttp3_stream_write_settings(nghttp3_stream *stream, - nghttp3_frame_entry *frent); - -int nghttp3_stream_write_cancel_push(nghttp3_stream *stream, - nghttp3_frame_entry *frent); - -int nghttp3_stream_write_max_push_id(nghttp3_stream *stream, - nghttp3_frame_entry *frent); - -int nghttp3_stream_ensure_chunk(nghttp3_stream *stream, size_t need); - -nghttp3_buf *nghttp3_stream_get_chunk(nghttp3_stream *stream); - -int nghttp3_stream_is_blocked(nghttp3_stream *stream); - -int nghttp3_stream_add_outq_offset(nghttp3_stream *stream, size_t n); - -/* - * nghttp3_stream_outq_write_done returns nonzero if all contents in - * outq have been written. - */ -int nghttp3_stream_outq_write_done(nghttp3_stream *stream); - -int nghttp3_stream_add_ack_offset(nghttp3_stream *stream, uint64_t n); - -/* - * nghttp3_stream_is_active returns nonzero if |stream| is active. In - * other words, it has something to send. This function does not take - * into account its descendants. - */ -int nghttp3_stream_is_active(nghttp3_stream *stream); - -/* - * nghttp3_stream_require_schedule returns nonzero if |stream| should - * be scheduled. In other words, |stream| or its descendants have - * something to send. - */ -int nghttp3_stream_require_schedule(nghttp3_stream *stream); - -int nghttp3_stream_buffer_data(nghttp3_stream *stream, const uint8_t *src, - size_t srclen); - -size_t nghttp3_stream_get_buffered_datalen(nghttp3_stream *stream); - -int nghttp3_stream_ensure_qpack_stream_context(nghttp3_stream *stream); - -void nghttp3_stream_delete_qpack_stream_context(nghttp3_stream *stream); - -int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream, - nghttp3_stream_http_event event); - -int nghttp3_stream_empty_headers_allowed(nghttp3_stream *stream); - -/* - * nghttp3_stream_bidi_or_push returns nonzero if |stream| is - * bidirectional or push stream. - */ -int nghttp3_stream_bidi_or_push(nghttp3_stream *stream); - -/* - * nghttp3_stream_uni returns nonzero if stream identified by - * |stream_id| is unidirectional. - */ -int nghttp3_stream_uni(int64_t stream_id); - -/* - * nghttp3_client_stream_bidi returns nonzero if stream identified by - * |stream_id| is client initiated bidirectional stream. - */ -int nghttp3_client_stream_bidi(int64_t stream_id); - -/* - * nghttp3_client_stream_uni returns nonzero if stream identified by - * |stream_id| is client initiated unidirectional stream. - */ -int nghttp3_client_stream_uni(int64_t stream_id); - -/* - * nghttp3_server_stream_uni returns nonzero if stream identified by - * |stream_id| is server initiated unidirectional stream. - */ -int nghttp3_server_stream_uni(int64_t stream_id); - -#endif /* NGHTTP3_STREAM_H */ diff --git a/deps/nghttp3/lib/nghttp3_tnode.c b/deps/nghttp3/lib/nghttp3_tnode.c deleted file mode 100644 index 94dca7dbf76325..00000000000000 --- a/deps/nghttp3/lib/nghttp3_tnode.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_tnode.h" - -#include - -#include "nghttp3_macro.h" -#include "nghttp3_stream.h" -#include "nghttp3_conn.h" -#include "nghttp3_conv.h" - -nghttp3_node_id *nghttp3_node_id_init(nghttp3_node_id *nid, - nghttp3_node_id_type type, int64_t id) { - nid->type = type; - nid->id = id; - return nid; -} - -int nghttp3_node_id_eq(const nghttp3_node_id *a, const nghttp3_node_id *b) { - return a->type == b->type && a->id == b->id; -} - -void nghttp3_tnode_init(nghttp3_tnode *tnode, const nghttp3_node_id *nid, - uint64_t seq, uint8_t pri) { - assert(nghttp3_pri_uint8_urgency(pri) < NGHTTP3_URGENCY_LEVELS); - - tnode->pe.index = NGHTTP3_PQ_BAD_INDEX; - tnode->nid = *nid; - tnode->seq = seq; - tnode->cycle = 0; - tnode->pri = pri; -} - -void nghttp3_tnode_free(nghttp3_tnode *tnode) { (void)tnode; } - -static void tnode_unschedule(nghttp3_tnode *tnode, nghttp3_pq *pq) { - assert(tnode->pe.index != NGHTTP3_PQ_BAD_INDEX); - - nghttp3_pq_remove(pq, &tnode->pe); - tnode->pe.index = NGHTTP3_PQ_BAD_INDEX; -} - -void nghttp3_tnode_unschedule(nghttp3_tnode *tnode, nghttp3_pq *pq) { - if (tnode->pe.index == NGHTTP3_PQ_BAD_INDEX) { - return; - } - - tnode_unschedule(tnode, pq); -} - -static uint64_t pq_get_first_cycle(nghttp3_pq *pq) { - nghttp3_tnode *top; - - if (nghttp3_pq_empty(pq)) { - return 0; - } - - top = nghttp3_struct_of(nghttp3_pq_top(pq), nghttp3_tnode, pe); - return top->cycle; -} - -int nghttp3_tnode_schedule(nghttp3_tnode *tnode, nghttp3_pq *pq, - size_t nwrite) { - uint64_t penalty = nwrite / NGHTTP3_STREAM_MIN_WRITELEN; - - if (tnode->pe.index == NGHTTP3_PQ_BAD_INDEX) { - tnode->cycle = pq_get_first_cycle(pq) + - ((nwrite == 0 || !nghttp3_pri_uint8_inc(tnode->pri)) - ? 0 - : nghttp3_max(1, penalty)); - } else if (nwrite > 0) { - if (!nghttp3_pri_uint8_inc(tnode->pri) || nghttp3_pq_size(pq) == 1) { - return 0; - } - - nghttp3_pq_remove(pq, &tnode->pe); - tnode->pe.index = NGHTTP3_PQ_BAD_INDEX; - tnode->cycle += nghttp3_max(1, penalty); - } else { - return 0; - } - - return nghttp3_pq_push(pq, &tnode->pe); -} - -int nghttp3_tnode_is_scheduled(nghttp3_tnode *tnode) { - return tnode->pe.index != NGHTTP3_PQ_BAD_INDEX; -} diff --git a/deps/nghttp3/lib/nghttp3_tnode.h b/deps/nghttp3/lib/nghttp3_tnode.h deleted file mode 100644 index bf861ed04098aa..00000000000000 --- a/deps/nghttp3/lib/nghttp3_tnode.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_TNODE_H -#define NGHTTP3_TNODE_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "nghttp3_pq.h" - -#define NGHTTP3_TNODE_MAX_CYCLE_GAP (1llu << 24) - -typedef enum { - NGHTTP3_NODE_ID_TYPE_STREAM = 0x00, - NGHTTP3_NODE_ID_TYPE_PUSH = 0x01, -} nghttp3_node_id_type; - -typedef struct { - nghttp3_node_id_type type; - int64_t id; -} nghttp3_node_id; - -nghttp3_node_id *nghttp3_node_id_init(nghttp3_node_id *nid, - nghttp3_node_id_type type, int64_t id); - -int nghttp3_node_id_eq(const nghttp3_node_id *a, const nghttp3_node_id *b); - -struct nghttp3_tnode; -typedef struct nghttp3_tnode nghttp3_tnode; - -struct nghttp3_tnode { - nghttp3_pq_entry pe; - size_t num_children; - nghttp3_node_id nid; - uint64_t seq; - uint64_t cycle; - /* pri is a stream priority produced by nghttp3_pri_to_uint8. */ - uint8_t pri; -}; - -void nghttp3_tnode_init(nghttp3_tnode *tnode, const nghttp3_node_id *nid, - uint64_t seq, uint8_t pri); - -void nghttp3_tnode_free(nghttp3_tnode *tnode); - -void nghttp3_tnode_unschedule(nghttp3_tnode *tnode, nghttp3_pq *pq); - -/* - * nghttp3_tnode_schedule schedules |tnode| using |nwrite| as penalty. - * If |tnode| has already been scheduled, it is rescheduled by the - * amount of |nwrite|. - */ -int nghttp3_tnode_schedule(nghttp3_tnode *tnode, nghttp3_pq *pq, size_t nwrite); - -/* - * nghttp3_tnode_is_scheduled returns nonzero if |tnode| is scheduled. - */ -int nghttp3_tnode_is_scheduled(nghttp3_tnode *tnode); - -#endif /* NGHTTP3_TNODE_H */ diff --git a/deps/nghttp3/lib/nghttp3_vec.c b/deps/nghttp3/lib/nghttp3_vec.c deleted file mode 100644 index 8d530a060dd502..00000000000000 --- a/deps/nghttp3/lib/nghttp3_vec.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "nghttp3_vec.h" -#include "nghttp3_macro.h" - -size_t nghttp3_vec_len(const nghttp3_vec *vec, size_t n) { - size_t i; - size_t res = 0; - - for (i = 0; i < n; ++i) { - res += vec[i].len; - } - - return res; -} - -int nghttp3_vec_empty(const nghttp3_vec *vec, size_t cnt) { - size_t i; - - for (i = 0; i < cnt && vec[i].len == 0; ++i) - ; - - return i == cnt; -} - -void nghttp3_vec_consume(nghttp3_vec **pvec, size_t *pcnt, size_t len) { - nghttp3_vec *v = *pvec; - size_t cnt = *pcnt; - - for (; cnt > 0; --cnt, ++v) { - if (v->len > len) { - v->len -= len; - v->base += len; - break; - } - len -= v->len; - } - - *pvec = v; - *pcnt = cnt; -} diff --git a/deps/nghttp3/lib/nghttp3_vec.h b/deps/nghttp3/lib/nghttp3_vec.h deleted file mode 100644 index c1a928e3e1d1ab..00000000000000 --- a/deps/nghttp3/lib/nghttp3_vec.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGHTTP3_VEC_H -#define NGHTTP3_VEC_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#endif /* NGHTTP3_VEC_H */ diff --git a/deps/nghttp3/lib/nghttp3_version.c b/deps/nghttp3/lib/nghttp3_version.c deleted file mode 100644 index dfad4793c4bc11..00000000000000 --- a/deps/nghttp3/lib/nghttp3_version.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * nghttp3 - * - * Copyright (c) 2019 nghttp3 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -static nghttp3_info version = {NGHTTP3_VERSION_AGE, NGHTTP3_VERSION_NUM, - NGHTTP3_VERSION}; - -nghttp3_info *nghttp3_version(int least_version) { - if (least_version > NGHTTP3_VERSION_NUM) { - return NULL; - } - return &version; -} diff --git a/deps/nghttp3/nghttp3.gyp b/deps/nghttp3/nghttp3.gyp deleted file mode 100644 index 85ca26cbc8d820..00000000000000 --- a/deps/nghttp3/nghttp3.gyp +++ /dev/null @@ -1,67 +0,0 @@ -{ - 'target_defaults': { - 'defines': [ - '_U_=' - ] - }, - 'targets': [ - { - 'target_name': 'nghttp3', - 'type': 'static_library', - 'include_dirs': ['lib/includes'], - 'defines': [ - 'BUILDING_NGHTTP3', - 'NGHTTP3_STATICLIB', - ], - 'conditions': [ - ['OS=="win"', { - 'defines': [ - 'WIN32', - '_WINDOWS', - 'HAVE_CONFIG_H', - ], - 'msvs_settings': { - 'VCCLCompilerTool': { - 'CompileAs': '1' - }, - }, - }], - ['OS=="linux"', { - 'defines': [ - 'HAVE_ARPA_INET_H', - ], - }], - ], - 'direct_dependent_settings': { - 'defines': [ 'NGHTTP3_STATICLIB' ], - 'include_dirs': [ 'lib/includes' ] - }, - 'sources': [ - 'lib/nghttp3_buf.c', - 'lib/nghttp3_conv.c', - 'lib/nghttp3_err.c', - 'lib/nghttp3_gaptr.c', - 'lib/nghttp3_idtr.c', - 'lib/nghttp3_map.c', - 'lib/nghttp3_pq.c', - 'lib/nghttp3_qpack_huffman.c', - 'lib/nghttp3_range.c', - 'lib/nghttp3_ringbuf.c', - 'lib/nghttp3_stream.c', - 'lib/nghttp3_vec.c', - 'lib/nghttp3_conn.c', - 'lib/nghttp3_debug.c', - 'lib/nghttp3_frame.c', - 'lib/nghttp3_http.c', - 'lib/nghttp3_ksl.c', - 'lib/nghttp3_mem.c', - 'lib/nghttp3_qpack.c', - 'lib/nghttp3_qpack_huffman_data.c', - 'lib/nghttp3_rcbuf.c', - 'lib/nghttp3_str.c', - 'lib/nghttp3_tnode.c', - 'lib/nghttp3_version.c' - ] - } - ] -} diff --git a/deps/ngtcp2/.gitignore b/deps/ngtcp2/.gitignore deleted file mode 100644 index 118f2396034893..00000000000000 --- a/deps/ngtcp2/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -**/*/CMakeLists.txt -**/*/*.am -**/*/*.h.in -**/*/*.pc.in diff --git a/deps/ngtcp2/COPYING b/deps/ngtcp2/COPYING deleted file mode 100644 index 9b367cdce71384..00000000000000 --- a/deps/ngtcp2/COPYING +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License - -Copyright (c) 2016 ngtcp2 contributors - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deps/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto.h b/deps/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto.h deleted file mode 100644 index 4b6885a08e4dbe..00000000000000 --- a/deps/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto.h +++ /dev/null @@ -1,621 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_CRYPTO_H -#define NGTCP2_CRYPTO_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define NGTCP2_CRYPTO_INITIAL_SECRETLEN 32 -#define NGTCP2_CRYPTO_INITIAL_KEYLEN 16 -#define NGTCP2_CRYPTO_INITIAL_IVLEN 12 - -/** - * @function - * - * `ngtcp2_crypto_ctx_initial` initializes |ctx| for Initial packet - * encryption and decryption. - */ -NGTCP2_EXTERN ngtcp2_crypto_ctx * -ngtcp2_crypto_ctx_initial(ngtcp2_crypto_ctx *ctx); - -/** - * @function - * - * `ngtcp2_crypto_ctx_tls` initializes |ctx| by extracting negotiated - * ciphers and message digests from native TLS session - * |tls_native_handle|. This is used for encrypting/decrypting - * Handshake and Short packets. - * - * If libngtcp2_crypto_openssl is linked, |tls_native_handle| must be - * a pointer to SSL object. - */ -NGTCP2_EXTERN ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_tls(ngtcp2_crypto_ctx *ctx, - void *tls_native_handle); - -/** - * @function - * - * `ngtcp2_crypto_aead_retry` initializes |aead| with the AEAD cipher - * AEAD_AES_128_GCM for Retry packet integrity protection. - */ -NGTCP2_EXTERN ngtcp2_crypto_aead * -ngtcp2_crypto_aead_retry(ngtcp2_crypto_aead *aead); - -/** - * @function - * - * `ngtcp2_crypto_md_hashlen` returns the length of |md| output. - */ -NGTCP2_EXTERN size_t ngtcp2_crypto_md_hashlen(const ngtcp2_crypto_md *md); - -/** - * @function - * - * `ngtcp2_crypto_aead_keylen` returns the length of key for |aead|. - */ -NGTCP2_EXTERN size_t ngtcp2_crypto_aead_keylen(const ngtcp2_crypto_aead *aead); - -/** - * @function - * - * `ngtcp2_crypto_aead_noncelen` returns the length of nonce for - * |aead|. - */ -NGTCP2_EXTERN size_t -ngtcp2_crypto_aead_noncelen(const ngtcp2_crypto_aead *aead); - -/** - * @function - * - * `ngtcp2_crypto_aead_taglen` returns the length of tag for |aead|. - */ -NGTCP2_EXTERN size_t ngtcp2_crypto_aead_taglen(const ngtcp2_crypto_aead *aead); - -/** - * @function - * - * `ngtcp2_crypto_hkdf_extract` performs HKDF extract operation. The - * result is the length of |md| and is stored to the buffer pointed by - * |dest|. The caller is responsible to specify the buffer that can - * store the output. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN int -ngtcp2_crypto_hkdf_extract(uint8_t *dest, const ngtcp2_crypto_md *md, - const uint8_t *secret, size_t secretlen, - const uint8_t *salt, size_t saltlen); - -/** - * @function - * - * `ngtcp2_crypto_hkdf_expand` performs HKDF expand operation. The - * result is |destlen| bytes long and is stored to the buffer pointed - * by |dest|. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN int ngtcp2_crypto_hkdf_expand(uint8_t *dest, size_t destlen, - const ngtcp2_crypto_md *md, - const uint8_t *secret, - size_t secretlen, - const uint8_t *info, - size_t infolen); - -/** - * @function - * - * `ngtcp2_crypto_hkdf_expand_label` performs HKDF expand label. The - * result is |destlen| bytes long and is stored to the buffer pointed - * by |dest|. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN int ngtcp2_crypto_hkdf_expand_label(uint8_t *dest, size_t destlen, - const ngtcp2_crypto_md *md, - const uint8_t *secret, - size_t secretlen, - const uint8_t *label, - size_t labellen); - -/** - * @enum - * - * `ngtcp2_crypto_side` indicates which side the application - * implements; client or server. - */ -typedef enum ngtcp2_crypto_side { - /** - * ``NGTCP2_CRYPTO_SIDE_CLIENT`` indicates that the application is - * client. - */ - NGTCP2_CRYPTO_SIDE_CLIENT, - /** - * ``NGTCP2_CRYPTO_SIDE_SERVER`` indicates that the application is - * server. - */ - NGTCP2_CRYPTO_SIDE_SERVER -} ngtcp2_crypto_side; - -/** - * @function - * - * `ngtcp2_crypto_packet_protection_ivlen` returns the length of IV - * used to encrypt QUIC packet. - */ -NGTCP2_EXTERN size_t -ngtcp2_crypto_packet_protection_ivlen(const ngtcp2_crypto_aead *aead); - -/** - * @function - * - * `ngtcp2_crypto_derive_packet_protection_key` derives packet - * protection key. This function writes packet protection key into - * the buffer pointed by |key|. |key| must point to the buffer which - * is at least ngtcp2_crypto_aead_keylen(aead) bytes long. This - * function writes packet protection IV into |iv|. |iv| must point to - * the buffer which is at least - * ngtcp2_crypto_packet_protection_ivlen(aead). |key| is - * ngtcp2_crypto_aead_keylen(aead) bytes long. |iv| is - * ngtcp2_crypto_packet_protection_ivlen(aead) bytes long. - * - * If |hp| is not NULL, this function also derives packet header - * protection key and writes the key into the buffer pointed by |hp|. - * The length of key is ngtcp2_crypto_aead_keylen(aead) bytes long. - * |hp|, if not NULL, must have enough capacity to store the key. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN int ngtcp2_crypto_derive_packet_protection_key( - uint8_t *key, uint8_t *iv, uint8_t *hp, const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_md *md, const uint8_t *secret, size_t secretlen); - -/** - * @function - * - * `ngtcp2_crypto_encrypt` encrypts |plaintext| of length - * |plaintextlen| and writes the ciphertext into the buffer pointed by - * |dest|. The length of ciphertext is plaintextlen + - * ngtcp2_crypto_aead_taglen(aead) bytes long. |dest| must have - * enough capacity to store the ciphertext. It is allowed to specify - * the same value to |dest| and |plaintext|. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN int ngtcp2_crypto_encrypt(uint8_t *dest, - const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *plaintext, - size_t plaintextlen, - const uint8_t *nonce, size_t noncelen, - const uint8_t *ad, size_t adlen); - -/** - * @function - * - * `ngtcp2_crypto_encrypt_cb` is a wrapper function around - * `ngtcp2_crypto_encrypt`. It can be directly passed to encrypt - * callback to ngtcp2_callbacks. - * - * This function returns 0 if it succeeds, or - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE`. - */ -NGTCP2_EXTERN int -ngtcp2_crypto_encrypt_cb(uint8_t *dest, const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *plaintext, size_t plaintextlen, - const uint8_t *nonce, size_t noncelen, - const uint8_t *ad, size_t adlen); - -/** - * @function - * - * `ngtcp2_crypto_decrypt` decrypts |ciphertext| of length - * |ciphertextlen| and writes the plaintext into the buffer pointed by - * |dest|. The length of plaintext is ciphertextlen - - * ngtcp2_crypto_aead_taglen(aead) bytes long. |dest| must have enough - * capacity to store the plaintext. It is allowed to specify the same - * value to |dest| and |ciphertext|. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN int ngtcp2_crypto_decrypt(uint8_t *dest, - const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *ciphertext, - size_t ciphertextlen, - const uint8_t *nonce, size_t noncelen, - const uint8_t *ad, size_t adlen); - -/** - * @function - * - * `ngtcp2_crypto_decrypt_cb` is a wrapper function around - * `ngtcp2_crypto_decrypt`. It can be directly passed to decrypt - * callback to ngtcp2_callbacks. - * - * This function returns 0 if it succeeds, or - * :enum:`NGTCP2_ERR_TLS_DECRYPT`. - */ -NGTCP2_EXTERN int -ngtcp2_crypto_decrypt_cb(uint8_t *dest, const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *ciphertext, size_t ciphertextlen, - const uint8_t *nonce, size_t noncelen, - const uint8_t *ad, size_t adlen); - -/** - * @function - * - * `ngtcp2_crypto_hp_mask` generates mask which is used in packet - * header encryption. The mask is written to the buffer pointed by - * |dest|. The length of mask is 5 bytes. |dest| must have enough - * capacity to store the mask. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN int ngtcp2_crypto_hp_mask(uint8_t *dest, - const ngtcp2_crypto_cipher *hp, - const ngtcp2_crypto_cipher_ctx *hp_ctx, - const uint8_t *sample); - -/** - * @function - * - * `ngtcp2_crypto_hp_mask_cb` is a wrapper function around - * `ngtcp2_crypto_hp_mask`. It can be directly passed to hp_mask - * callback to ngtcp2_callbacks. - * - * This function returns 0 if it succeeds, or - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE`. - */ -NGTCP2_EXTERN int -ngtcp2_crypto_hp_mask_cb(uint8_t *dest, const ngtcp2_crypto_cipher *hp, - const ngtcp2_crypto_cipher_ctx *hp_ctx, - const uint8_t *sample); - -/** - * @function - * - * `ngtcp2_crypto_derive_and_install_rx_key` derives the rx keys from - * |secret| and installs new keys to |conn|. - * - * If |key| is not NULL, the derived packet protection key for - * decryption is written to the buffer pointed by |key|. If |iv| is - * not NULL, the derived packet protection IV for decryption is - * written to the buffer pointed by |iv|. If |hp| is not NULL, the - * derived header protection key for decryption is written to the - * buffer pointed by |hp|. - * - * |secretlen| specifies the length of |secret|. - * - * The length of packet protection key and header protection key is - * ngtcp2_crypto_aead(ctx->aead), and the length of packet protection - * IV is ngtcp2_crypto_packet_protection_ivlen(ctx->aead) where ctx - * can be obtained by `ngtcp2_crypto_ctx_tls`. - * - * In the first call of this function, it calls - * `ngtcp2_conn_set_crypto_ctx` to set negotiated AEAD and message - * digest algorithm. After the successful call of this function, - * application can use `ngtcp2_conn_get_crypto_ctx` to get the object. - * It also calls `ngtcp2_conn_set_aead_overhead` to set AEAD tag - * length. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN int ngtcp2_crypto_derive_and_install_rx_key( - ngtcp2_conn *conn, uint8_t *key, uint8_t *iv, uint8_t *hp, - ngtcp2_crypto_level level, const uint8_t *secret, size_t secretlen); - -/** - * @function - * - * `ngtcp2_crypto_derive_and_install_tx_key` derives the tx keys from - * |secret| and installs new keys to |conn|. - * - * If |key| is not NULL, the derived packet protection key for - * encryption is written to the buffer pointed by |key|. If |iv| is - * not NULL, the derived packet protection IV for encryption is - * written to the buffer pointed by |iv|. If |hp| is not NULL, the - * derived header protection key for encryption is written to the - * buffer pointed by |hp|. - * - * |secretlen| specifies the length of |secret|. - * - * The length of packet protection key and header protection key is - * ngtcp2_crypto_aead(ctx->aead), and the length of packet protection - * IV is ngtcp2_crypto_packet_protection_ivlen(ctx->aead) where ctx - * can be obtained by `ngtcp2_crypto_ctx_tls`. - * - * In the first call of this function, it calls - * `ngtcp2_conn_set_crypto_ctx` to set negotiated AEAD and message - * digest algorithm. After the successful call of this function, - * application can use `ngtcp2_conn_get_crypto_ctx` to get the object. - * It also calls `ngtcp2_conn_set_aead_overhead` to set AEAD tag - * length. - * - * If |level| is NGTCP2_CRYPTO_LEVEL_APP, this function retrieves a - * remote QUIC transport parameters extension from |tls| and sets it - * to |conn|. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN int ngtcp2_crypto_derive_and_install_tx_key( - ngtcp2_conn *conn, uint8_t *key, uint8_t *iv, uint8_t *hp, - ngtcp2_crypto_level level, const uint8_t *secret, size_t secretlen); - -/** - * @function - * - * `ngtcp2_crypto_update_key` updates traffic keying materials. - * - * The new traffic secret for decryption is written to the buffer - * pointed by |rx_secret|. The length of secret is |secretlen| bytes, - * and |rx_secret| must point to the buffer which has enough capacity. - * - * The new traffic secret for encryption is written to the buffer - * pointed by |tx_secret|. The length of secret is |secretlen| bytes, - * and |tx_secret| must point to the buffer which has enough capacity. - * - * The derived packet protection key for decryption is written to the - * buffer pointed by |rx_key|. The derived packet protection IV for - * decryption is written to the buffer pointed by |rx_iv|. - * |rx_aead_ctx| must be constructed with |rx_key|. - * - * The derived packet protection key for encryption is written to the - * buffer pointed by |tx_key|. The derived packet protection IV for - * encryption is written to the buffer pointed by |tx_iv|. - * |tx_aead_ctx| must be constructed with |rx_key|. - * - * |current_rx_secret| and |current_tx_secret| are the current traffic - * secrets for decryption and encryption. |secretlen| specifies the - * length of |rx_secret| and |tx_secret|. - * - * The length of packet protection key and header protection key is - * ngtcp2_crypto_aead(ctx->aead), and the length of packet protection - * IV is ngtcp2_crypto_packet_protection_ivlen(ctx->aead) where ctx - * can be obtained by `ngtcp2_conn_get_crypto_ctx`. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN int ngtcp2_crypto_update_key( - ngtcp2_conn *conn, uint8_t *rx_secret, uint8_t *tx_secret, - ngtcp2_crypto_aead_ctx *rx_aead_ctx, uint8_t *rx_key, uint8_t *rx_iv, - ngtcp2_crypto_aead_ctx *tx_aead_ctx, uint8_t *tx_key, uint8_t *tx_iv, - const uint8_t *current_rx_secret, const uint8_t *current_tx_secret, - size_t secretlen); - -/** - * @function - * - * `ngtcp2_crypto_update_key_cb` is a wrapper function around - * `ngtcp2_crypto_update_key`. It can be directly passed to - * update_key field in ngtcp2_callbacks. - * - * This function returns 0 if it succeeds, or - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE`. - */ -NGTCP2_EXTERN int ngtcp2_crypto_update_key_cb( - ngtcp2_conn *conn, uint8_t *rx_secret, uint8_t *tx_secret, - ngtcp2_crypto_aead_ctx *rx_aead_ctx, uint8_t *rx_iv, - ngtcp2_crypto_aead_ctx *tx_aead_ctx, uint8_t *tx_iv, - const uint8_t *current_rx_secret, const uint8_t *current_tx_secret, - size_t secretlen, void *user_data); - -/** - * @function - * - * `ngtcp2_crypto_client_initial_cb` installs initial secrets and - * encryption keys and sets QUIC transport parameters. - * - * This function can be directly passed to client_initial field in - * ngtcp2_callbacks. It is only used by client. - * - * This function returns 0 if it succeeds, or - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE`. - */ -NGTCP2_EXTERN int ngtcp2_crypto_client_initial_cb(ngtcp2_conn *conn, - void *user_data); - -/** - * @function - * - * `ngtcp2_crypto_recv_retry_cb` re-installs initial secrets in - * response to incoming Retry packet. - * - * This function can be directly passed to recv_retry field in - * ngtcp2_callbacks. It is only used by client. - * - * This function returns 0 if it succeeds, or - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE`. - */ -NGTCP2_EXTERN int ngtcp2_crypto_recv_retry_cb(ngtcp2_conn *conn, - const ngtcp2_pkt_hd *hd, - void *user_data); - -/** - * @function - * - * `ngtcp2_crypto_recv_client_initial_cb` installs initial secrets in - * response to an incoming Initial packet from client, and sets QUIC - * transport parameters. - * - * This function can be directly passed to recv_client_initial field - * in ngtcp2_callbacks. It is only used by server. - * - * This function returns 0 if it succeeds, or - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE`. - */ -NGTCP2_EXTERN int ngtcp2_crypto_recv_client_initial_cb(ngtcp2_conn *conn, - const ngtcp2_cid *dcid, - void *user_data); - -/** - * @function - * - * `ngtcp2_crypto_read_write_crypto_data` reads CRYPTO data |data| of - * length |datalen| in encryption level |crypto_level| and may feed - * outgoing CRYPTO data to |conn|. This function can drive handshake. - * This function can be also used after handshake completes. It is - * allowed to call this function with datalen == 0. In this case, no - * additional read operation is done. - * - * This function returns 0 if it succeeds, or a negative error code. - * The generic error code is -1 if a specific error code is not - * suitable. The error codes less than -10000 are specific to - * underlying TLS implementation. For OpenSSL, the error codes are - * defined in ngtcp2_crypto_openssl.h. - */ -NGTCP2_EXTERN int -ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn, - ngtcp2_crypto_level crypto_level, - const uint8_t *data, size_t datalen); - -/** - * @function - * - * `ngtcp2_crypto_generate_stateless_reset_token` generates a - * stateless reset token using HKDF extraction with |md| using the - * given |cid| and static key |secret| as input. The token will be - * written to the buffer pointed by |token| and it must have a - * capacity of at least NGTCP2_STATELESS_RESET_TOKENLEN bytes. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN int ngtcp2_crypto_generate_stateless_reset_token( - uint8_t *token, const ngtcp2_crypto_md *md, const uint8_t *secret, - size_t secretlen, const ngtcp2_cid *cid); - -/** - * @function - * - * `ngtcp2_crypto_write_connection_close` writes Initial packet - * containing CONNECTION_CLOSE with the given |error_code| to the - * buffer pointed by |dest| of length |destlen|. This function is - * designed for server to close connection without committing the - * state when validating Retry token fails. This function must not be - * used by client. The |dcid| must be the Source Connection ID in - * Initial packet from client. The |scid| must be the Destination - * Connection ID in Initial packet from client. |scid| is used to - * derive initial keying materials. - * - * This function wraps around `ngtcp2_pkt_write_connection_close` for - * easier use. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN ngtcp2_ssize ngtcp2_crypto_write_connection_close( - uint8_t *dest, size_t destlen, const ngtcp2_cid *dcid, - const ngtcp2_cid *scid, uint64_t error_code); - -/** - * @function - * - * `ngtcp2_crypto_write_retry` writes Retry packet to the buffer - * pointed by |dest| of length |destlen|. |odcid| specifies Original - * Destination Connection ID. |token| specifies Retry Token, and - * |tokenlen| specifies its length. - * - * This function wraps around `ngtcp2_pkt_write_retry` for easier use. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN ngtcp2_ssize -ngtcp2_crypto_write_retry(uint8_t *dest, size_t destlen, const ngtcp2_cid *dcid, - const ngtcp2_cid *scid, const ngtcp2_cid *odcid, - const uint8_t *token, size_t tokenlen); - -/** - * @function - * - * `ngtcp2_crypto_aead_ctx_encrypt_init` initializes |aead_ctx| with - * new AEAD cipher context object for encryption which is constructed - * to use |key| as encryption key. |aead| specifies AEAD cipher to - * use. |noncelen| is the length of nonce. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN int -ngtcp2_crypto_aead_ctx_encrypt_init(ngtcp2_crypto_aead_ctx *aead_ctx, - const ngtcp2_crypto_aead *aead, - const uint8_t *key, size_t noncelen); - -/** - * @function - * - * `ngtcp2_crypto_aead_ctx_decrypt_init` initializes |aead_ctx| with - * new AEAD cipher context object for decryption which is constructed - * to use |key| as encryption key. |aead| specifies AEAD cipher to - * use. |noncelen| is the length of nonce. - * - * This function returns 0 if it succeeds, or -1. - */ -NGTCP2_EXTERN int -ngtcp2_crypto_aead_ctx_decrypt_init(ngtcp2_crypto_aead_ctx *aead_ctx, - const ngtcp2_crypto_aead *aead, - const uint8_t *key, size_t noncelen); - -/** - * @function - * - * `ngtcp2_crypto_aead_ctx_free` frees up resources used by - * |aead_ctx|. This function does not free the memory pointed by - * |aead_ctx| itself. - */ -NGTCP2_EXTERN void -ngtcp2_crypto_aead_ctx_free(ngtcp2_crypto_aead_ctx *aead_ctx); - -/** - * @function - * - * `ngtcp2_crypto_delete_crypto_aead_ctx_cb` deletes the given |aead_ctx|. - * - * This function can be directly passed to delete_crypto_aead_ctx - * field in ngtcp2_callbacks. - */ -NGTCP2_EXTERN void ngtcp2_crypto_delete_crypto_aead_ctx_cb( - ngtcp2_conn *conn, ngtcp2_crypto_aead_ctx *aead_ctx, void *user_data); - -/** - * @function - * - * `ngtcp2_crypto_delete_crypto_cipher_ctx_cb` deletes the given - * |cipher_ctx|. - * - * This function can be directly passed to delete_crypto_cipher_ctx - * field in ngtcp2_callbacks. - */ -NGTCP2_EXTERN void ngtcp2_crypto_delete_crypto_cipher_ctx_cb( - ngtcp2_conn *conn, ngtcp2_crypto_cipher_ctx *cipher_ctx, void *user_data); - -#ifdef __cplusplus -} -#endif - -#endif /* NGTCP2_CRYPTO_H */ diff --git a/deps/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_openssl.h b/deps/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_openssl.h deleted file mode 100644 index 7ccb383e3c8069..00000000000000 --- a/deps/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_openssl.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_CRYPTO_OPENSSL_H -#define NGTCP2_CRYPTO_OPENSSL_H - -#include - -/* OpenSSL specific error codes */ -#define NGTCP2_CRYPTO_ERR_TLS_WANT_X509_LOOKUP -10001 -#define NGTCP2_CRYPTO_ERR_TLS_WANT_CLIENT_HELLO_CB -10002 - -#endif /* NGTCP2_CRYPTO_OPENSSL_H */ diff --git a/deps/ngtcp2/crypto/openssl/openssl.c b/deps/ngtcp2/crypto/openssl/openssl.c deleted file mode 100644 index d1937441efb7ef..00000000000000 --- a/deps/ngtcp2/crypto/openssl/openssl.c +++ /dev/null @@ -1,496 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include -#include - -#include -#include -#include - -#include "shared.h" - -ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_initial(ngtcp2_crypto_ctx *ctx) { - ctx->aead.native_handle = (void *)EVP_aes_128_gcm(); - ctx->md.native_handle = (void *)EVP_sha256(); - ctx->hp.native_handle = (void *)EVP_aes_128_ctr(); - ctx->max_encryption = 0; - ctx->max_decryption_failure = 0; - return ctx; -} - -ngtcp2_crypto_aead *ngtcp2_crypto_aead_retry(ngtcp2_crypto_aead *aead) { - aead->native_handle = (void *)EVP_aes_128_gcm(); - return aead; -} - -static const EVP_CIPHER *crypto_ssl_get_aead(SSL *ssl) { - switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) { - case TLS1_3_CK_AES_128_GCM_SHA256: - return EVP_aes_128_gcm(); - case TLS1_3_CK_AES_256_GCM_SHA384: - return EVP_aes_256_gcm(); - case TLS1_3_CK_CHACHA20_POLY1305_SHA256: - return EVP_chacha20_poly1305(); - case TLS1_3_CK_AES_128_CCM_SHA256: - return EVP_aes_128_ccm(); - default: - return NULL; - } -} - -static uint64_t crypto_ssl_get_aead_max_encryption(SSL *ssl) { - switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) { - case TLS1_3_CK_AES_128_GCM_SHA256: - case TLS1_3_CK_AES_256_GCM_SHA384: - return NGTCP2_CRYPTO_MAX_ENCRYPTION_AES_GCM; - case TLS1_3_CK_CHACHA20_POLY1305_SHA256: - return NGTCP2_CRYPTO_MAX_ENCRYPTION_CHACHA20_POLY1305; - case TLS1_3_CK_AES_128_CCM_SHA256: - return NGTCP2_CRYPTO_MAX_ENCRYPTION_AES_CCM; - default: - return 0; - } -} - -static uint64_t crypto_ssl_get_aead_max_decryption_failure(SSL *ssl) { - switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) { - case TLS1_3_CK_AES_128_GCM_SHA256: - case TLS1_3_CK_AES_256_GCM_SHA384: - return NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_AES_GCM; - case TLS1_3_CK_CHACHA20_POLY1305_SHA256: - return NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_CHACHA20_POLY1305; - case TLS1_3_CK_AES_128_CCM_SHA256: - return NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_AES_CCM; - default: - return 0; - } -} - -static const EVP_CIPHER *crypto_ssl_get_hp(SSL *ssl) { - switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) { - case TLS1_3_CK_AES_128_GCM_SHA256: - case TLS1_3_CK_AES_128_CCM_SHA256: - return EVP_aes_128_ctr(); - case TLS1_3_CK_AES_256_GCM_SHA384: - return EVP_aes_256_ctr(); - case TLS1_3_CK_CHACHA20_POLY1305_SHA256: - return EVP_chacha20(); - default: - return NULL; - } -} - -static const EVP_MD *crypto_ssl_get_md(SSL *ssl) { - switch (SSL_CIPHER_get_id(SSL_get_current_cipher(ssl))) { - case TLS1_3_CK_AES_128_GCM_SHA256: - case TLS1_3_CK_CHACHA20_POLY1305_SHA256: - case TLS1_3_CK_AES_128_CCM_SHA256: - return EVP_sha256(); - case TLS1_3_CK_AES_256_GCM_SHA384: - return EVP_sha384(); - default: - return NULL; - } -} - -ngtcp2_crypto_ctx *ngtcp2_crypto_ctx_tls(ngtcp2_crypto_ctx *ctx, - void *tls_native_handle) { - SSL *ssl = tls_native_handle; - ctx->aead.native_handle = (void *)crypto_ssl_get_aead(ssl); - ctx->md.native_handle = (void *)crypto_ssl_get_md(ssl); - ctx->hp.native_handle = (void *)crypto_ssl_get_hp(ssl); - ctx->max_encryption = crypto_ssl_get_aead_max_encryption(ssl); - ctx->max_decryption_failure = crypto_ssl_get_aead_max_decryption_failure(ssl); - return ctx; -} - -static size_t crypto_md_hashlen(const EVP_MD *md) { - return (size_t)EVP_MD_size(md); -} - -size_t ngtcp2_crypto_md_hashlen(const ngtcp2_crypto_md *md) { - return crypto_md_hashlen(md->native_handle); -} - -static size_t crypto_aead_keylen(const EVP_CIPHER *aead) { - return (size_t)EVP_CIPHER_key_length(aead); -} - -size_t ngtcp2_crypto_aead_keylen(const ngtcp2_crypto_aead *aead) { - return crypto_aead_keylen(aead->native_handle); -} - -static size_t crypto_aead_noncelen(const EVP_CIPHER *aead) { - return (size_t)EVP_CIPHER_iv_length(aead); -} - -size_t ngtcp2_crypto_aead_noncelen(const ngtcp2_crypto_aead *aead) { - return crypto_aead_noncelen(aead->native_handle); -} - -static size_t crypto_aead_taglen(const EVP_CIPHER *aead) { - if (aead == EVP_aes_128_gcm() || aead == EVP_aes_256_gcm()) { - return EVP_GCM_TLS_TAG_LEN; - } - if (aead == EVP_chacha20_poly1305()) { - return EVP_CHACHAPOLY_TLS_TAG_LEN; - } - if (aead == EVP_aes_128_ccm()) { - return EVP_CCM_TLS_TAG_LEN; - } - return 0; -} - -size_t ngtcp2_crypto_aead_taglen(const ngtcp2_crypto_aead *aead) { - return crypto_aead_taglen(aead->native_handle); -} - -int ngtcp2_crypto_aead_ctx_encrypt_init(ngtcp2_crypto_aead_ctx *aead_ctx, - const ngtcp2_crypto_aead *aead, - const uint8_t *key, size_t noncelen) { - const EVP_CIPHER *cipher = aead->native_handle; - EVP_CIPHER_CTX *actx; - - actx = EVP_CIPHER_CTX_new(); - if (actx == NULL) { - return -1; - } - - if (!EVP_EncryptInit_ex(actx, cipher, NULL, NULL, NULL) || - !EVP_CIPHER_CTX_ctrl(actx, EVP_CTRL_AEAD_SET_IVLEN, (int)noncelen, - NULL) || - (cipher == EVP_aes_128_ccm() && - !EVP_CIPHER_CTX_ctrl(actx, EVP_CTRL_AEAD_SET_TAG, - (int)crypto_aead_taglen(cipher), NULL)) || - !EVP_EncryptInit_ex(actx, NULL, NULL, key, NULL)) { - EVP_CIPHER_CTX_free(actx); - return -1; - } - - aead_ctx->native_handle = actx; - - return 0; -} - -int ngtcp2_crypto_aead_ctx_decrypt_init(ngtcp2_crypto_aead_ctx *aead_ctx, - const ngtcp2_crypto_aead *aead, - const uint8_t *key, size_t noncelen) { - const EVP_CIPHER *cipher = aead->native_handle; - EVP_CIPHER_CTX *actx; - - actx = EVP_CIPHER_CTX_new(); - if (actx == NULL) { - return -1; - } - - if (!EVP_DecryptInit_ex(actx, cipher, NULL, NULL, NULL) || - !EVP_CIPHER_CTX_ctrl(actx, EVP_CTRL_AEAD_SET_IVLEN, (int)noncelen, - NULL) || - (cipher == EVP_aes_128_ccm() && - !EVP_CIPHER_CTX_ctrl(actx, EVP_CTRL_AEAD_SET_TAG, - (int)crypto_aead_taglen(cipher), NULL)) || - !EVP_DecryptInit_ex(actx, NULL, NULL, key, NULL)) { - EVP_CIPHER_CTX_free(actx); - return -1; - } - - aead_ctx->native_handle = actx; - - return 0; -} - -void ngtcp2_crypto_aead_ctx_free(ngtcp2_crypto_aead_ctx *aead_ctx) { - if (aead_ctx->native_handle) { - EVP_CIPHER_CTX_free(aead_ctx->native_handle); - } -} - -int ngtcp2_crypto_cipher_ctx_encrypt_init(ngtcp2_crypto_cipher_ctx *cipher_ctx, - const ngtcp2_crypto_cipher *cipher, - const uint8_t *key) { - EVP_CIPHER_CTX *actx; - - actx = EVP_CIPHER_CTX_new(); - if (actx == NULL) { - return -1; - } - - if (!EVP_EncryptInit_ex(actx, cipher->native_handle, NULL, key, NULL)) { - EVP_CIPHER_CTX_free(actx); - return -1; - } - - cipher_ctx->native_handle = actx; - - return 0; -} - -void ngtcp2_crypto_cipher_ctx_free(ngtcp2_crypto_cipher_ctx *cipher_ctx) { - if (cipher_ctx->native_handle) { - EVP_CIPHER_CTX_free(cipher_ctx->native_handle); - } -} - -int ngtcp2_crypto_hkdf_extract(uint8_t *dest, const ngtcp2_crypto_md *md, - const uint8_t *secret, size_t secretlen, - const uint8_t *salt, size_t saltlen) { - const EVP_MD *prf = md->native_handle; - int rv = 0; - EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL); - size_t destlen = (size_t)EVP_MD_size(prf); - - if (pctx == NULL) { - return -1; - } - - if (EVP_PKEY_derive_init(pctx) != 1 || - EVP_PKEY_CTX_hkdf_mode(pctx, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY) != 1 || - EVP_PKEY_CTX_set_hkdf_md(pctx, prf) != 1 || - EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, (int)saltlen) != 1 || - EVP_PKEY_CTX_set1_hkdf_key(pctx, secret, (int)secretlen) != 1 || - EVP_PKEY_derive(pctx, dest, &destlen) != 1) { - rv = -1; - } - - EVP_PKEY_CTX_free(pctx); - - return rv; -} - -int ngtcp2_crypto_hkdf_expand(uint8_t *dest, size_t destlen, - const ngtcp2_crypto_md *md, const uint8_t *secret, - size_t secretlen, const uint8_t *info, - size_t infolen) { - const EVP_MD *prf = md->native_handle; - int rv = 0; - EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL); - if (pctx == NULL) { - return -1; - } - - if (EVP_PKEY_derive_init(pctx) != 1 || - EVP_PKEY_CTX_hkdf_mode(pctx, EVP_PKEY_HKDEF_MODE_EXPAND_ONLY) != 1 || - EVP_PKEY_CTX_set_hkdf_md(pctx, prf) != 1 || - EVP_PKEY_CTX_set1_hkdf_salt(pctx, "", 0) != 1 || - EVP_PKEY_CTX_set1_hkdf_key(pctx, secret, (int)secretlen) != 1 || - EVP_PKEY_CTX_add1_hkdf_info(pctx, info, (int)infolen) != 1 || - EVP_PKEY_derive(pctx, dest, &destlen) != 1) { - rv = -1; - } - - EVP_PKEY_CTX_free(pctx); - - return rv; -} - -int ngtcp2_crypto_encrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *plaintext, size_t plaintextlen, - const uint8_t *nonce, size_t noncelen, - const uint8_t *ad, size_t adlen) { - const EVP_CIPHER *cipher = aead->native_handle; - size_t taglen = crypto_aead_taglen(cipher); - EVP_CIPHER_CTX *actx = aead_ctx->native_handle; - int len; - - (void)noncelen; - - if (!EVP_EncryptInit_ex(actx, NULL, NULL, NULL, nonce) || - (cipher == EVP_aes_128_ccm() && - !EVP_EncryptUpdate(actx, NULL, &len, NULL, (int)plaintextlen)) || - !EVP_EncryptUpdate(actx, NULL, &len, ad, (int)adlen) || - !EVP_EncryptUpdate(actx, dest, &len, plaintext, (int)plaintextlen) || - !EVP_EncryptFinal_ex(actx, dest + len, &len) || - !EVP_CIPHER_CTX_ctrl(actx, EVP_CTRL_AEAD_GET_TAG, (int)taglen, - dest + plaintextlen)) { - return -1; - } - - return 0; -} - -int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *ciphertext, size_t ciphertextlen, - const uint8_t *nonce, size_t noncelen, - const uint8_t *ad, size_t adlen) { - const EVP_CIPHER *cipher = aead->native_handle; - size_t taglen = crypto_aead_taglen(cipher); - EVP_CIPHER_CTX *actx = aead_ctx->native_handle; - int len; - const uint8_t *tag; - - (void)noncelen; - - if (taglen > ciphertextlen) { - return -1; - } - - ciphertextlen -= taglen; - tag = ciphertext + ciphertextlen; - - if (!EVP_DecryptInit_ex(actx, NULL, NULL, NULL, nonce) || - !EVP_CIPHER_CTX_ctrl(actx, EVP_CTRL_AEAD_SET_TAG, (int)taglen, - (uint8_t *)tag) || - (cipher == EVP_aes_128_ccm() && - !EVP_DecryptUpdate(actx, NULL, &len, NULL, (int)ciphertextlen)) || - !EVP_DecryptUpdate(actx, NULL, &len, ad, (int)adlen) || - !EVP_DecryptUpdate(actx, dest, &len, ciphertext, (int)ciphertextlen) || - (cipher != EVP_aes_128_ccm() && - !EVP_DecryptFinal_ex(actx, dest + ciphertextlen, &len))) { - return -1; - } - - return 0; -} - -int ngtcp2_crypto_hp_mask(uint8_t *dest, const ngtcp2_crypto_cipher *hp, - const ngtcp2_crypto_cipher_ctx *hp_ctx, - const uint8_t *sample) { - static const uint8_t PLAINTEXT[] = "\x00\x00\x00\x00\x00"; - EVP_CIPHER_CTX *actx = hp_ctx->native_handle; - int len; - - (void)hp; - - if (!EVP_EncryptInit_ex(actx, NULL, NULL, NULL, sample) || - !EVP_EncryptUpdate(actx, dest, &len, PLAINTEXT, sizeof(PLAINTEXT) - 1) || - !EVP_EncryptFinal_ex(actx, dest + sizeof(PLAINTEXT) - 1, &len)) { - return -1; - } - - return 0; -} - -static OSSL_ENCRYPTION_LEVEL -from_ngtcp2_level(ngtcp2_crypto_level crypto_level) { - switch (crypto_level) { - case NGTCP2_CRYPTO_LEVEL_INITIAL: - return ssl_encryption_initial; - case NGTCP2_CRYPTO_LEVEL_HANDSHAKE: - return ssl_encryption_handshake; - case NGTCP2_CRYPTO_LEVEL_APP: - return ssl_encryption_application; - case NGTCP2_CRYPTO_LEVEL_EARLY: - return ssl_encryption_early_data; - default: - assert(0); - } -} - -int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn, - ngtcp2_crypto_level crypto_level, - const uint8_t *data, size_t datalen) { - SSL *ssl = ngtcp2_conn_get_tls_native_handle(conn); - int rv; - int err; - - if (SSL_provide_quic_data(ssl, from_ngtcp2_level(crypto_level), data, - datalen) != 1) { - return -1; - } - - if (!ngtcp2_conn_get_handshake_completed(conn)) { - rv = SSL_do_handshake(ssl); - if (rv <= 0) { - err = SSL_get_error(ssl, rv); - switch (err) { - case SSL_ERROR_WANT_READ: - case SSL_ERROR_WANT_WRITE: - return 0; - case SSL_ERROR_WANT_CLIENT_HELLO_CB: - return NGTCP2_CRYPTO_ERR_TLS_WANT_CLIENT_HELLO_CB; - case SSL_ERROR_WANT_X509_LOOKUP: - return NGTCP2_CRYPTO_ERR_TLS_WANT_X509_LOOKUP; - case SSL_ERROR_SSL: - return -1; - default: - return -1; - } - } - - ngtcp2_conn_handshake_completed(conn); - } - - rv = SSL_process_quic_post_handshake(ssl); - if (rv != 1) { - err = SSL_get_error(ssl, rv); - switch (err) { - case SSL_ERROR_WANT_READ: - case SSL_ERROR_WANT_WRITE: - return 0; - case SSL_ERROR_SSL: - case SSL_ERROR_ZERO_RETURN: - return -1; - default: - return -1; - } - } - - return 0; -} - -int ngtcp2_crypto_set_remote_transport_params(ngtcp2_conn *conn, void *tls) { - SSL *ssl = tls; - ngtcp2_transport_params_type exttype = - ngtcp2_conn_is_server(conn) - ? NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO - : NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS; - const uint8_t *tp; - size_t tplen; - ngtcp2_transport_params params; - int rv; - - SSL_get_peer_quic_transport_params(ssl, &tp, &tplen); - - rv = ngtcp2_decode_transport_params(¶ms, exttype, tp, tplen); - if (rv != 0) { - ngtcp2_conn_set_tls_error(conn, rv); - return -1; - } - - rv = ngtcp2_conn_set_remote_transport_params(conn, ¶ms); - if (rv != 0) { - ngtcp2_conn_set_tls_error(conn, rv); - return -1; - } - - return 0; -} - -int ngtcp2_crypto_set_local_transport_params(void *tls, const uint8_t *buf, - size_t len) { - if (SSL_set_quic_transport_params(tls, buf, len) != 1) { - return -1; - } - - return 0; -} diff --git a/deps/ngtcp2/crypto/shared.c b/deps/ngtcp2/crypto/shared.c deleted file mode 100644 index 7e5219c52f2957..00000000000000 --- a/deps/ngtcp2/crypto/shared.c +++ /dev/null @@ -1,786 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "shared.h" - -#include -#include - -#include "ngtcp2_macro.h" - -int ngtcp2_crypto_hkdf_expand_label(uint8_t *dest, size_t destlen, - const ngtcp2_crypto_md *md, - const uint8_t *secret, size_t secretlen, - const uint8_t *label, size_t labellen) { - static const uint8_t LABEL[] = "tls13 "; - uint8_t info[256]; - uint8_t *p = info; - - *p++ = (uint8_t)(destlen / 256); - *p++ = (uint8_t)(destlen % 256); - *p++ = (uint8_t)(sizeof(LABEL) - 1 + labellen); - memcpy(p, LABEL, sizeof(LABEL) - 1); - p += sizeof(LABEL) - 1; - memcpy(p, label, labellen); - p += labellen; - *p++ = 0; - - return ngtcp2_crypto_hkdf_expand(dest, destlen, md, secret, secretlen, info, - (size_t)(p - info)); -} - -#define NGTCP2_CRYPTO_INITIAL_SECRETLEN 32 - -int ngtcp2_crypto_derive_initial_secrets(uint8_t *rx_secret, uint8_t *tx_secret, - uint8_t *initial_secret, - const ngtcp2_cid *client_dcid, - ngtcp2_crypto_side side) { - static const uint8_t CLABEL[] = "client in"; - static const uint8_t SLABEL[] = "server in"; - uint8_t initial_secret_buf[NGTCP2_CRYPTO_INITIAL_SECRETLEN]; - uint8_t *client_secret; - uint8_t *server_secret; - ngtcp2_crypto_ctx ctx; - - if (!initial_secret) { - initial_secret = initial_secret_buf; - } - - ngtcp2_crypto_ctx_initial(&ctx); - - if (ngtcp2_crypto_hkdf_extract(initial_secret, &ctx.md, client_dcid->data, - client_dcid->datalen, - (const uint8_t *)NGTCP2_INITIAL_SALT, - sizeof(NGTCP2_INITIAL_SALT) - 1) != 0) { - return -1; - } - - if (side == NGTCP2_CRYPTO_SIDE_SERVER) { - client_secret = rx_secret; - server_secret = tx_secret; - } else { - client_secret = tx_secret; - server_secret = rx_secret; - } - - if (ngtcp2_crypto_hkdf_expand_label( - client_secret, NGTCP2_CRYPTO_INITIAL_SECRETLEN, &ctx.md, - initial_secret, NGTCP2_CRYPTO_INITIAL_SECRETLEN, CLABEL, - sizeof(CLABEL) - 1) != 0 || - ngtcp2_crypto_hkdf_expand_label( - server_secret, NGTCP2_CRYPTO_INITIAL_SECRETLEN, &ctx.md, - initial_secret, NGTCP2_CRYPTO_INITIAL_SECRETLEN, SLABEL, - sizeof(SLABEL) - 1) != 0) { - return -1; - } - - return 0; -} - -size_t ngtcp2_crypto_packet_protection_ivlen(const ngtcp2_crypto_aead *aead) { - size_t noncelen = ngtcp2_crypto_aead_noncelen(aead); - return ngtcp2_max(8, noncelen); -} - -int ngtcp2_crypto_derive_packet_protection_key( - uint8_t *key, uint8_t *iv, uint8_t *hp_key, const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_md *md, const uint8_t *secret, size_t secretlen) { - static const uint8_t KEY_LABEL[] = "quic key"; - static const uint8_t IV_LABEL[] = "quic iv"; - static const uint8_t HP_KEY_LABEL[] = "quic hp"; - size_t keylen = ngtcp2_crypto_aead_keylen(aead); - size_t ivlen = ngtcp2_crypto_packet_protection_ivlen(aead); - - if (ngtcp2_crypto_hkdf_expand_label(key, keylen, md, secret, secretlen, - KEY_LABEL, sizeof(KEY_LABEL) - 1) != 0) { - return -1; - } - - if (ngtcp2_crypto_hkdf_expand_label(iv, ivlen, md, secret, secretlen, - IV_LABEL, sizeof(IV_LABEL) - 1) != 0) { - return -1; - } - - if (hp_key != NULL && ngtcp2_crypto_hkdf_expand_label( - hp_key, keylen, md, secret, secretlen, HP_KEY_LABEL, - sizeof(HP_KEY_LABEL) - 1) != 0) { - return -1; - } - - return 0; -} - -int ngtcp2_crypto_update_traffic_secret(uint8_t *dest, - const ngtcp2_crypto_md *md, - const uint8_t *secret, - size_t secretlen) { - static const uint8_t LABEL[] = "quic ku"; - - if (ngtcp2_crypto_hkdf_expand_label(dest, secretlen, md, secret, secretlen, - LABEL, sizeof(LABEL) - 1) != 0) { - return -1; - } - - return 0; -} - -int ngtcp2_crypto_derive_and_install_rx_key(ngtcp2_conn *conn, uint8_t *key, - uint8_t *iv, uint8_t *hp_key, - ngtcp2_crypto_level level, - const uint8_t *secret, - size_t secretlen) { - const ngtcp2_crypto_ctx *ctx; - const ngtcp2_crypto_aead *aead; - const ngtcp2_crypto_md *md; - const ngtcp2_crypto_cipher *hp; - ngtcp2_crypto_aead_ctx aead_ctx = {0}; - ngtcp2_crypto_cipher_ctx hp_ctx = {0}; - void *tls = ngtcp2_conn_get_tls_native_handle(conn); - uint8_t keybuf[64], ivbuf[64], hp_keybuf[64]; - size_t ivlen; - int rv; - - if (level == NGTCP2_CRYPTO_LEVEL_EARLY && !ngtcp2_conn_is_server(conn)) { - return 0; - } - - if (!key) { - key = keybuf; - } - if (!iv) { - iv = ivbuf; - } - if (!hp_key) { - hp_key = hp_keybuf; - } - - ctx = ngtcp2_conn_get_crypto_ctx(conn); - - if (!ctx->aead.native_handle) { - ngtcp2_crypto_ctx cctx; - ngtcp2_crypto_ctx_tls(&cctx, tls); - ngtcp2_conn_set_aead_overhead(conn, ngtcp2_crypto_aead_taglen(&cctx.aead)); - ngtcp2_conn_set_crypto_ctx(conn, &cctx); - ctx = ngtcp2_conn_get_crypto_ctx(conn); - } - - aead = &ctx->aead; - md = &ctx->md; - hp = &ctx->hp; - ivlen = ngtcp2_crypto_packet_protection_ivlen(aead); - - if (ngtcp2_crypto_derive_packet_protection_key(key, iv, hp_key, aead, md, - secret, secretlen) != 0) { - return -1; - } - - if (ngtcp2_crypto_aead_ctx_decrypt_init(&aead_ctx, aead, key, ivlen) != 0) { - goto fail; - } - - if (ngtcp2_crypto_cipher_ctx_encrypt_init(&hp_ctx, hp, hp_key) != 0) { - goto fail; - } - - switch (level) { - case NGTCP2_CRYPTO_LEVEL_EARLY: - rv = ngtcp2_conn_install_early_key(conn, &aead_ctx, iv, ivlen, &hp_ctx); - if (rv != 0) { - goto fail; - } - break; - case NGTCP2_CRYPTO_LEVEL_HANDSHAKE: - rv = ngtcp2_conn_install_rx_handshake_key(conn, &aead_ctx, iv, ivlen, - &hp_ctx); - if (rv != 0) { - goto fail; - } - break; - case NGTCP2_CRYPTO_LEVEL_APP: - if (!ngtcp2_conn_is_server(conn)) { - rv = ngtcp2_crypto_set_remote_transport_params(conn, tls); - if (rv != 0) { - goto fail; - } - } - - rv = ngtcp2_conn_install_rx_key(conn, secret, secretlen, &aead_ctx, iv, - ivlen, &hp_ctx); - if (rv != 0) { - goto fail; - } - - break; - default: - goto fail; - } - - return 0; - -fail: - ngtcp2_crypto_cipher_ctx_free(&hp_ctx); - ngtcp2_crypto_aead_ctx_free(&aead_ctx); - - return -1; -} - -/* - * crypto_set_local_transport_params gets local QUIC transport - * parameters from |conn| and sets it to |tls|. - * - * This function returns 0 if it succeeds, or -1. - */ -static int crypto_set_local_transport_params(ngtcp2_conn *conn, void *tls) { - ngtcp2_transport_params_type exttype = - ngtcp2_conn_is_server(conn) - ? NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS - : NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO; - ngtcp2_transport_params params; - ngtcp2_ssize nwrite; - uint8_t buf[256]; - - ngtcp2_conn_get_local_transport_params(conn, ¶ms); - - nwrite = ngtcp2_encode_transport_params(buf, sizeof(buf), exttype, ¶ms); - if (nwrite < 0) { - return -1; - } - - if (ngtcp2_crypto_set_local_transport_params(tls, buf, (size_t)nwrite) != 0) { - return -1; - } - - return 0; -} - -int ngtcp2_crypto_derive_and_install_tx_key(ngtcp2_conn *conn, uint8_t *key, - uint8_t *iv, uint8_t *hp_key, - ngtcp2_crypto_level level, - const uint8_t *secret, - size_t secretlen) { - const ngtcp2_crypto_ctx *ctx; - const ngtcp2_crypto_aead *aead; - const ngtcp2_crypto_md *md; - const ngtcp2_crypto_cipher *hp; - ngtcp2_crypto_aead_ctx aead_ctx = {0}; - ngtcp2_crypto_cipher_ctx hp_ctx = {0}; - void *tls = ngtcp2_conn_get_tls_native_handle(conn); - uint8_t keybuf[64], ivbuf[64], hp_keybuf[64]; - size_t ivlen; - int rv; - - if (level == NGTCP2_CRYPTO_LEVEL_EARLY && ngtcp2_conn_is_server(conn)) { - return 0; - } - - if (!key) { - key = keybuf; - } - if (!iv) { - iv = ivbuf; - } - if (!hp_key) { - hp_key = hp_keybuf; - } - - ctx = ngtcp2_conn_get_crypto_ctx(conn); - - if (!ctx->aead.native_handle) { - ngtcp2_crypto_ctx cctx; - ngtcp2_crypto_ctx_tls(&cctx, tls); - ngtcp2_conn_set_aead_overhead(conn, ngtcp2_crypto_aead_taglen(&cctx.aead)); - ngtcp2_conn_set_crypto_ctx(conn, &cctx); - ctx = ngtcp2_conn_get_crypto_ctx(conn); - } - - aead = &ctx->aead; - md = &ctx->md; - hp = &ctx->hp; - ivlen = ngtcp2_crypto_packet_protection_ivlen(aead); - - if (ngtcp2_crypto_derive_packet_protection_key(key, iv, hp_key, aead, md, - secret, secretlen) != 0) { - return -1; - } - - if (ngtcp2_crypto_aead_ctx_encrypt_init(&aead_ctx, aead, key, ivlen) != 0) { - goto fail; - } - - if (ngtcp2_crypto_cipher_ctx_encrypt_init(&hp_ctx, hp, hp_key) != 0) { - goto fail; - } - - switch (level) { - case NGTCP2_CRYPTO_LEVEL_EARLY: - rv = ngtcp2_conn_install_early_key(conn, &aead_ctx, iv, ivlen, &hp_ctx); - if (rv != 0) { - goto fail; - } - break; - case NGTCP2_CRYPTO_LEVEL_HANDSHAKE: - rv = ngtcp2_conn_install_tx_handshake_key(conn, &aead_ctx, iv, ivlen, - &hp_ctx); - if (rv != 0) { - goto fail; - } - - if (ngtcp2_conn_is_server(conn)) { - rv = ngtcp2_crypto_set_remote_transport_params(conn, tls); - if (rv != 0) { - goto fail; - } - - if (crypto_set_local_transport_params(conn, tls) != 0) { - goto fail; - } - } - - break; - case NGTCP2_CRYPTO_LEVEL_APP: - rv = ngtcp2_conn_install_tx_key(conn, secret, secretlen, &aead_ctx, iv, - ivlen, &hp_ctx); - if (rv != 0) { - goto fail; - } - - break; - default: - goto fail; - } - - return 0; - -fail: - ngtcp2_crypto_cipher_ctx_free(&hp_ctx); - ngtcp2_crypto_aead_ctx_free(&aead_ctx); - - return -1; -} - -int ngtcp2_crypto_derive_and_install_initial_key( - ngtcp2_conn *conn, uint8_t *rx_secret, uint8_t *tx_secret, - uint8_t *initial_secret, uint8_t *rx_key, uint8_t *rx_iv, - uint8_t *rx_hp_key, uint8_t *tx_key, uint8_t *tx_iv, uint8_t *tx_hp_key, - const ngtcp2_cid *client_dcid) { - uint8_t rx_secretbuf[NGTCP2_CRYPTO_INITIAL_SECRETLEN]; - uint8_t tx_secretbuf[NGTCP2_CRYPTO_INITIAL_SECRETLEN]; - uint8_t initial_secretbuf[NGTCP2_CRYPTO_INITIAL_SECRETLEN]; - uint8_t rx_keybuf[NGTCP2_CRYPTO_INITIAL_KEYLEN]; - uint8_t rx_ivbuf[NGTCP2_CRYPTO_INITIAL_IVLEN]; - uint8_t rx_hp_keybuf[NGTCP2_CRYPTO_INITIAL_KEYLEN]; - uint8_t tx_keybuf[NGTCP2_CRYPTO_INITIAL_KEYLEN]; - uint8_t tx_ivbuf[NGTCP2_CRYPTO_INITIAL_IVLEN]; - uint8_t tx_hp_keybuf[NGTCP2_CRYPTO_INITIAL_KEYLEN]; - ngtcp2_crypto_ctx ctx; - ngtcp2_crypto_aead retry_aead; - ngtcp2_crypto_aead_ctx rx_aead_ctx = {0}; - ngtcp2_crypto_cipher_ctx rx_hp_ctx = {0}; - ngtcp2_crypto_aead_ctx tx_aead_ctx = {0}; - ngtcp2_crypto_cipher_ctx tx_hp_ctx = {0}; - ngtcp2_crypto_aead_ctx retry_aead_ctx = {0}; - int rv; - int server = ngtcp2_conn_is_server(conn); - - ngtcp2_crypto_ctx_initial(&ctx); - - if (!rx_secret) { - rx_secret = rx_secretbuf; - } - if (!tx_secret) { - tx_secret = tx_secretbuf; - } - if (!initial_secret) { - initial_secret = initial_secretbuf; - } - - if (!rx_key) { - rx_key = rx_keybuf; - } - if (!rx_iv) { - rx_iv = rx_ivbuf; - } - if (!rx_hp_key) { - rx_hp_key = rx_hp_keybuf; - } - if (!tx_key) { - tx_key = tx_keybuf; - } - if (!tx_iv) { - tx_iv = tx_ivbuf; - } - if (!tx_hp_key) { - tx_hp_key = tx_hp_keybuf; - } - - ngtcp2_conn_set_initial_crypto_ctx(conn, &ctx); - - if (ngtcp2_crypto_derive_initial_secrets( - rx_secret, tx_secret, initial_secret, client_dcid, - server ? NGTCP2_CRYPTO_SIDE_SERVER : NGTCP2_CRYPTO_SIDE_CLIENT) != - 0) { - return -1; - } - - if (ngtcp2_crypto_derive_packet_protection_key( - rx_key, rx_iv, rx_hp_key, &ctx.aead, &ctx.md, rx_secret, - NGTCP2_CRYPTO_INITIAL_SECRETLEN) != 0) { - return -1; - } - - if (ngtcp2_crypto_derive_packet_protection_key( - tx_key, tx_iv, tx_hp_key, &ctx.aead, &ctx.md, tx_secret, - NGTCP2_CRYPTO_INITIAL_SECRETLEN) != 0) { - return -1; - } - - if (ngtcp2_crypto_aead_ctx_decrypt_init(&rx_aead_ctx, &ctx.aead, rx_key, - NGTCP2_CRYPTO_INITIAL_IVLEN) != 0) { - goto fail; - } - - if (ngtcp2_crypto_cipher_ctx_encrypt_init(&rx_hp_ctx, &ctx.hp, rx_hp_key) != - 0) { - goto fail; - } - - if (ngtcp2_crypto_aead_ctx_encrypt_init(&tx_aead_ctx, &ctx.aead, tx_key, - NGTCP2_CRYPTO_INITIAL_IVLEN) != 0) { - goto fail; - } - - if (ngtcp2_crypto_cipher_ctx_encrypt_init(&tx_hp_ctx, &ctx.hp, tx_hp_key) != - 0) { - goto fail; - } - - if (!server && !ngtcp2_conn_after_retry(conn)) { - ngtcp2_crypto_aead_retry(&retry_aead); - - if (ngtcp2_crypto_aead_ctx_encrypt_init( - &retry_aead_ctx, &retry_aead, (const uint8_t *)NGTCP2_RETRY_KEY, - sizeof(NGTCP2_RETRY_NONCE) - 1) != 0) { - goto fail; - } - } - - rv = ngtcp2_conn_install_initial_key(conn, &rx_aead_ctx, rx_iv, &rx_hp_ctx, - &tx_aead_ctx, tx_iv, &tx_hp_ctx, - NGTCP2_CRYPTO_INITIAL_IVLEN); - if (rv != 0) { - goto fail; - } - - if (retry_aead_ctx.native_handle) { - ngtcp2_conn_set_retry_aead(conn, &retry_aead, &retry_aead_ctx); - } - - return 0; - -fail: - ngtcp2_crypto_aead_ctx_free(&retry_aead_ctx); - ngtcp2_crypto_cipher_ctx_free(&tx_hp_ctx); - ngtcp2_crypto_aead_ctx_free(&tx_aead_ctx); - ngtcp2_crypto_cipher_ctx_free(&rx_hp_ctx); - ngtcp2_crypto_aead_ctx_free(&rx_aead_ctx); - - return -1; -} - -int ngtcp2_crypto_update_key( - ngtcp2_conn *conn, uint8_t *rx_secret, uint8_t *tx_secret, - ngtcp2_crypto_aead_ctx *rx_aead_ctx, uint8_t *rx_key, uint8_t *rx_iv, - ngtcp2_crypto_aead_ctx *tx_aead_ctx, uint8_t *tx_key, uint8_t *tx_iv, - const uint8_t *current_rx_secret, const uint8_t *current_tx_secret, - size_t secretlen) { - const ngtcp2_crypto_ctx *ctx = ngtcp2_conn_get_crypto_ctx(conn); - const ngtcp2_crypto_aead *aead = &ctx->aead; - const ngtcp2_crypto_md *md = &ctx->md; - size_t ivlen = ngtcp2_crypto_packet_protection_ivlen(aead); - - if (ngtcp2_crypto_update_traffic_secret(rx_secret, md, current_rx_secret, - secretlen) != 0) { - return -1; - } - - if (ngtcp2_crypto_derive_packet_protection_key(rx_key, rx_iv, NULL, aead, md, - rx_secret, secretlen) != 0) { - return -1; - } - - if (ngtcp2_crypto_update_traffic_secret(tx_secret, md, current_tx_secret, - secretlen) != 0) { - return -1; - } - - if (ngtcp2_crypto_derive_packet_protection_key(tx_key, tx_iv, NULL, aead, md, - tx_secret, secretlen) != 0) { - return -1; - } - - if (ngtcp2_crypto_aead_ctx_decrypt_init(rx_aead_ctx, aead, rx_key, ivlen) != - 0) { - return -1; - } - - if (ngtcp2_crypto_aead_ctx_encrypt_init(tx_aead_ctx, aead, tx_key, ivlen) != - 0) { - ngtcp2_crypto_aead_ctx_free(rx_aead_ctx); - rx_aead_ctx->native_handle = NULL; - return -1; - } - - return 0; -} - -int ngtcp2_crypto_encrypt_cb(uint8_t *dest, const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *plaintext, size_t plaintextlen, - const uint8_t *nonce, size_t noncelen, - const uint8_t *ad, size_t adlen) { - if (ngtcp2_crypto_encrypt(dest, aead, aead_ctx, plaintext, plaintextlen, - nonce, noncelen, ad, adlen) != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - return 0; -} - -int ngtcp2_crypto_decrypt_cb(uint8_t *dest, const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *ciphertext, size_t ciphertextlen, - const uint8_t *nonce, size_t noncelen, - const uint8_t *ad, size_t adlen) { - if (ngtcp2_crypto_decrypt(dest, aead, aead_ctx, ciphertext, ciphertextlen, - nonce, noncelen, ad, adlen) != 0) { - return NGTCP2_ERR_TLS_DECRYPT; - } - return 0; -} - -int ngtcp2_crypto_hp_mask_cb(uint8_t *dest, const ngtcp2_crypto_cipher *hp, - const ngtcp2_crypto_cipher_ctx *hp_ctx, - const uint8_t *sample) { - if (ngtcp2_crypto_hp_mask(dest, hp, hp_ctx, sample) != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - return 0; -} - -int ngtcp2_crypto_update_key_cb( - ngtcp2_conn *conn, uint8_t *rx_secret, uint8_t *tx_secret, - ngtcp2_crypto_aead_ctx *rx_aead_ctx, uint8_t *rx_iv, - ngtcp2_crypto_aead_ctx *tx_aead_ctx, uint8_t *tx_iv, - const uint8_t *current_rx_secret, const uint8_t *current_tx_secret, - size_t secretlen, void *user_data) { - uint8_t rx_key[64]; - uint8_t tx_key[64]; - (void)conn; - (void)user_data; - - if (ngtcp2_crypto_update_key(conn, rx_secret, tx_secret, rx_aead_ctx, rx_key, - rx_iv, tx_aead_ctx, tx_key, tx_iv, - current_rx_secret, current_tx_secret, - secretlen) != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - return 0; -} - -int ngtcp2_crypto_generate_stateless_reset_token(uint8_t *token, - const ngtcp2_crypto_md *md, - const uint8_t *secret, - size_t secretlen, - const ngtcp2_cid *cid) { - uint8_t buf[64]; - int rv; - - assert(ngtcp2_crypto_md_hashlen(md) <= sizeof(buf)); - assert(NGTCP2_STATELESS_RESET_TOKENLEN <= sizeof(buf)); - - rv = ngtcp2_crypto_hkdf_extract(buf, md, secret, secretlen, cid->data, - cid->datalen); - if (rv != 0) { - return -1; - } - - memcpy(token, buf, NGTCP2_STATELESS_RESET_TOKENLEN); - - return 0; -} - -ngtcp2_ssize ngtcp2_crypto_write_connection_close(uint8_t *dest, size_t destlen, - const ngtcp2_cid *dcid, - const ngtcp2_cid *scid, - uint64_t error_code) { - uint8_t rx_secret[NGTCP2_CRYPTO_INITIAL_SECRETLEN]; - uint8_t tx_secret[NGTCP2_CRYPTO_INITIAL_SECRETLEN]; - uint8_t initial_secret[NGTCP2_CRYPTO_INITIAL_SECRETLEN]; - uint8_t tx_key[NGTCP2_CRYPTO_INITIAL_KEYLEN]; - uint8_t tx_iv[NGTCP2_CRYPTO_INITIAL_IVLEN]; - uint8_t tx_hp_key[NGTCP2_CRYPTO_INITIAL_KEYLEN]; - ngtcp2_crypto_ctx ctx; - ngtcp2_ssize spktlen; - ngtcp2_crypto_aead_ctx aead_ctx = {0}; - ngtcp2_crypto_cipher_ctx hp_ctx = {0}; - - ngtcp2_crypto_ctx_initial(&ctx); - - if (ngtcp2_crypto_derive_initial_secrets(rx_secret, tx_secret, initial_secret, - scid, - NGTCP2_CRYPTO_SIDE_SERVER) != 0) { - return -1; - } - - if (ngtcp2_crypto_derive_packet_protection_key( - tx_key, tx_iv, tx_hp_key, &ctx.aead, &ctx.md, tx_secret, - NGTCP2_CRYPTO_INITIAL_SECRETLEN) != 0) { - return -1; - } - - if (ngtcp2_crypto_aead_ctx_encrypt_init(&aead_ctx, &ctx.aead, tx_key, - NGTCP2_CRYPTO_INITIAL_IVLEN) != 0) { - spktlen = -1; - goto end; - } - - if (ngtcp2_crypto_cipher_ctx_encrypt_init(&hp_ctx, &ctx.hp, tx_hp_key) != 0) { - spktlen = -1; - goto end; - } - - spktlen = ngtcp2_pkt_write_connection_close( - dest, destlen, dcid, scid, error_code, ngtcp2_crypto_encrypt_cb, - &ctx.aead, &aead_ctx, tx_iv, ngtcp2_crypto_hp_mask_cb, &ctx.hp, &hp_ctx); - if (spktlen < 0) { - spktlen = -1; - } - -end: - ngtcp2_crypto_cipher_ctx_free(&hp_ctx); - ngtcp2_crypto_aead_ctx_free(&aead_ctx); - - return spktlen; -} - -ngtcp2_ssize ngtcp2_crypto_write_retry(uint8_t *dest, size_t destlen, - const ngtcp2_cid *dcid, - const ngtcp2_cid *scid, - const ngtcp2_cid *odcid, - const uint8_t *token, size_t tokenlen) { - ngtcp2_crypto_aead aead; - ngtcp2_ssize spktlen; - ngtcp2_crypto_aead_ctx aead_ctx = {0}; - - ngtcp2_crypto_aead_retry(&aead); - - if (ngtcp2_crypto_aead_ctx_encrypt_init(&aead_ctx, &aead, - (const uint8_t *)NGTCP2_RETRY_KEY, - NGTCP2_CRYPTO_INITIAL_IVLEN) != 0) { - return -1; - } - - spktlen = - ngtcp2_pkt_write_retry(dest, destlen, dcid, scid, odcid, token, tokenlen, - ngtcp2_crypto_encrypt_cb, &aead, &aead_ctx); - if (spktlen < 0) { - spktlen = -1; - } - - ngtcp2_crypto_aead_ctx_free(&aead_ctx); - - return spktlen; -} - -/* - * crypto_setup_initial_crypto establishes the initial secrets and - * encryption keys, and prepares local QUIC transport parameters. - */ -static int crypto_setup_initial_crypto(ngtcp2_conn *conn, - const ngtcp2_cid *dcid) { - return ngtcp2_crypto_derive_and_install_initial_key( - conn, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, dcid); -} - -int ngtcp2_crypto_client_initial_cb(ngtcp2_conn *conn, void *user_data) { - const ngtcp2_cid *dcid = ngtcp2_conn_get_dcid(conn); - void *tls = ngtcp2_conn_get_tls_native_handle(conn); - (void)user_data; - - if (crypto_setup_initial_crypto(conn, dcid) != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - if (crypto_set_local_transport_params(conn, tls) != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - if (ngtcp2_crypto_read_write_crypto_data(conn, NGTCP2_CRYPTO_LEVEL_INITIAL, - NULL, 0) != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -int ngtcp2_crypto_recv_retry_cb(ngtcp2_conn *conn, const ngtcp2_pkt_hd *hd, - void *user_data) { - (void)user_data; - - if (ngtcp2_crypto_derive_and_install_initial_key(conn, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - &hd->scid) != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -int ngtcp2_crypto_recv_client_initial_cb(ngtcp2_conn *conn, - const ngtcp2_cid *dcid, - void *user_data) { - (void)user_data; - - if (crypto_setup_initial_crypto(conn, dcid) != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -void ngtcp2_crypto_delete_crypto_aead_ctx_cb(ngtcp2_conn *conn, - ngtcp2_crypto_aead_ctx *aead_ctx, - void *user_data) { - (void)conn; - (void)user_data; - - ngtcp2_crypto_aead_ctx_free(aead_ctx); -} - -void ngtcp2_crypto_delete_crypto_cipher_ctx_cb( - ngtcp2_conn *conn, ngtcp2_crypto_cipher_ctx *cipher_ctx, void *user_data) { - (void)conn; - (void)user_data; - - ngtcp2_crypto_cipher_ctx_free(cipher_ctx); -} diff --git a/deps/ngtcp2/crypto/shared.h b/deps/ngtcp2/crypto/shared.h deleted file mode 100644 index b70513afb3a4b0..00000000000000 --- a/deps/ngtcp2/crypto/shared.h +++ /dev/null @@ -1,189 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_SHARED_H -#define NGTCP2_SHARED_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -/* Maximum key usage (encryption) limits */ -#define NGTCP2_CRYPTO_MAX_ENCRYPTION_AES_GCM (23726566ULL) -#define NGTCP2_CRYPTO_MAX_ENCRYPTION_CHACHA20_POLY1305 (1ULL << 62) -#define NGTCP2_CRYPTO_MAX_ENCRYPTION_AES_CCM (1ULL << 23) - -/* Maximum authentication failure (decryption) limits */ -#define NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_AES_GCM (1ULL << 36) -#define NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_CHACHA20_POLY1305 (1ULL << 36) -#define NGTCP2_CRYPTO_MAX_DECRYPTION_FAILURE_AES_CCM (11863283ULL) - -/** - * @function - * - * `ngtcp2_crypto_derive_initial_secrets` derives initial secrets. - * |rx_secret| and |tx_secret| must point to the buffer of at least 32 - * bytes capacity. rx for read and tx for write. This function - * writes rx and tx secrets into |rx_secret| and |tx_secret| - * respectively. The length of secret is 32 bytes long. - * |client_dcid| is the destination connection ID in first Initial - * packet of client. If |initial_secret| is not NULL, the initial - * secret is written to it. It must point to the buffer which has at - * least 32 bytes capacity. The initial secret is 32 bytes long. - * |side| specifies the side of application. - * - * This function returns 0 if it succeeds, or -1. - */ -int ngtcp2_crypto_derive_initial_secrets(uint8_t *rx_secret, uint8_t *tx_secret, - uint8_t *initial_secret, - const ngtcp2_cid *client_dcid, - ngtcp2_crypto_side side); - -/** - * @function - * - * `ngtcp2_crypto_update_traffic_secret` derives the next generation - * of the traffic secret. |secret| specifies the current secret and - * its length is given in |secretlen|. The length of new key is the - * same as the current key. This function writes new key into the - * buffer pointed by |dest|. |dest| must have the enough capacity to - * store the new key. - * - * This function returns 0 if it succeeds, or -1. - */ -int ngtcp2_crypto_update_traffic_secret(uint8_t *dest, - const ngtcp2_crypto_md *md, - const uint8_t *secret, - size_t secretlen); - -/** - * @function - * - * `ngtcp2_crypto_set_local_transport_params` sets QUIC transport - * parameter, which is encoded in wire format and stored in the buffer - * pointed by |buf| of length |len|, to the native handle |tls|. - * - * |tls| points to a implementation dependent TLS session object. If - * libngtcp2_crypto_openssl is linked, |tls| must be a pointer to SSL - * object. - * - * This function returns 0 if it succeeds, or -1. - */ -int ngtcp2_crypto_set_local_transport_params(void *tls, const uint8_t *buf, - size_t len); - -/** - * @function - * - * `ngtcp2_crypto_set_remote_transport_params` retrieves a remote QUIC - * transport parameters from |tls| and sets it to |conn| using - * `ngtcp2_conn_set_remote_transport_params`. - * - * |tls| points to a implementation dependent TLS session object. If - * libngtcp2_crypto_openssl is linked, |tls| must be a pointer to SSL - * object. - * - * This function returns 0 if it succeeds, or -1. - */ -int ngtcp2_crypto_set_remote_transport_params(ngtcp2_conn *conn, void *tls); - -/** - * @function - * - * `ngtcp2_crypto_derive_and_install_initial_key` derives initial - * keying materials and installs keys to |conn|. - * - * If |rx_secret| is not NULL, the secret for decryption is written to - * the buffer pointed by |rx_secret|. The length of secret is 32 - * bytes, and |rx_secret| must point to the buffer which has enough - * capacity. - * - * If |tx_secret| is not NULL, the secret for encryption is written to - * the buffer pointed by |tx_secret|. The length of secret is 32 - * bytes, and |tx_secret| must point to the buffer which has enough - * capacity. - * - * If |initial_secret| is not NULL, the initial secret is written to - * the buffer pointed by |initial_secret|. The length of secret is 32 - * bytes, and |initial_secret| must point to the buffer which has - * enough capacity. - * - * |client_dcid| is the destination connection ID in first Initial - * packet of client. - * - * If |rx_key| is not NULL, the derived packet protection key for - * decryption is written to the buffer pointed by |rx_key|. If - * |rx_iv| is not NULL, the derived packet protection IV for - * decryption is written to the buffer pointed by |rx_iv|. If |rx_hp| - * is not NULL, the derived header protection key for decryption is - * written to the buffer pointed by |rx_hp|. - * - * If |tx_key| is not NULL, the derived packet protection key for - * encryption is written to the buffer pointed by |tx_key|. If - * |tx_iv| is not NULL, the derived packet protection IV for - * encryption is written to the buffer pointed by |tx_iv|. If |tx_hp| - * is not NULL, the derived header protection key for encryption is - * written to the buffer pointed by |tx_hp|. - * - * The length of packet protection key and header protection key is 16 - * bytes long. The length of packet protection IV is 12 bytes long. - * - * This function calls `ngtcp2_conn_set_initial_crypto_ctx` to set - * initial AEAD and message digest algorithm. After the successful - * call of this function, application can use - * `ngtcp2_conn_get_initial_crypto_ctx` to get the object. - * - * This function returns 0 if it succeeds, or -1. - */ -int ngtcp2_crypto_derive_and_install_initial_key( - ngtcp2_conn *conn, uint8_t *rx_secret, uint8_t *tx_secret, - uint8_t *initial_secret, uint8_t *rx_key, uint8_t *rx_iv, uint8_t *rx_hp, - uint8_t *tx_key, uint8_t *tx_iv, uint8_t *tx_hp, - const ngtcp2_cid *client_dcid); - -/** - * @function - * - * `ngtcp2_crypto_cipher_ctx_encrypt_init` initializes |cipher_ctx| - * with new cipher context object for encryption which is constructed - * to use |key| as encryption key. |cipher| specifies cipher to use. - * - * This function returns 0 if it succeeds, or -1. - */ -int ngtcp2_crypto_cipher_ctx_encrypt_init(ngtcp2_crypto_cipher_ctx *cipher_ctx, - const ngtcp2_crypto_cipher *cipher, - const uint8_t *key); - -/** - * @function - * - * `ngtcp2_crypto_cipher_ctx_free` frees up resources used by - * |cipher_ctx|. This function does not free the memory pointed by - * |cipher_ctx| itself. - */ -void ngtcp2_crypto_cipher_ctx_free(ngtcp2_crypto_cipher_ctx *cipher_ctx); - -#endif /* NGTCP2_SHARED_H */ diff --git a/deps/ngtcp2/lib/includes/config.h b/deps/ngtcp2/lib/includes/config.h deleted file mode 100644 index 0aee7749bae78e..00000000000000 --- a/deps/ngtcp2/lib/includes/config.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Edited to match src/node.h. */ -#include - -#ifdef _WIN32 -#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED) -typedef intptr_t ssize_t; -# define _SSIZE_T_ -# define _SSIZE_T_DEFINED -#endif -#else // !_WIN32 -# include // size_t, ssize_t -#endif // _WIN32 - -#ifdef _MSC_VER -# include -# define __builtin_popcount __popcnt -#endif - -/* Define to 1 to enable debug output. */ -/* #undef DEBUGBUILD */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_ARPA_INET_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_STDDEF_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_UNISTD_H */ diff --git a/deps/ngtcp2/lib/includes/ngtcp2/ngtcp2.h b/deps/ngtcp2/lib/includes/ngtcp2/ngtcp2.h deleted file mode 100644 index 3373adb9f91a52..00000000000000 --- a/deps/ngtcp2/lib/includes/ngtcp2/ngtcp2.h +++ /dev/null @@ -1,3396 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2017 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_H -#define NGTCP2_H - -/* Define WIN32 when build target is Win32 API (borrowed from - libcurl) */ -#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) -# define WIN32 -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#if defined(_MSC_VER) && (_MSC_VER < 1800) -/* MSVC < 2013 does not have inttypes.h because it is not C99 - compliant. See compiler macros and version number in - https://sourceforge.net/p/predef/wiki/Compilers/ */ -# include -#else /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */ -# include -#endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */ -#include -#include -#include - -#ifdef WIN32 -# include -#else -# include -#endif - -#include - -#ifdef NGTCP2_STATICLIB -# define NGTCP2_EXTERN -#elif defined(WIN32) -# ifdef BUILDING_NGTCP2 -# define NGTCP2_EXTERN __declspec(dllexport) -# else /* !BUILDING_NGTCP2 */ -# define NGTCP2_EXTERN __declspec(dllimport) -# endif /* !BUILDING_NGTCP2 */ -#else /* !defined(WIN32) */ -# ifdef BUILDING_NGTCP2 -# define NGTCP2_EXTERN __attribute__((visibility("default"))) -# else /* !BUILDING_NGTCP2 */ -# define NGTCP2_EXTERN -# endif /* !BUILDING_NGTCP2 */ -#endif /* !defined(WIN32) */ - -typedef ptrdiff_t ngtcp2_ssize; - -/** - * @functypedef - * - * Custom memory allocator to replace malloc(). The |mem_user_data| - * is the mem_user_data member of :type:`ngtcp2_mem` structure. - */ -typedef void *(*ngtcp2_malloc)(size_t size, void *mem_user_data); - -/** - * @functypedef - * - * Custom memory allocator to replace free(). The |mem_user_data| is - * the mem_user_data member of :type:`ngtcp2_mem` structure. - */ -typedef void (*ngtcp2_free)(void *ptr, void *mem_user_data); - -/** - * @functypedef - * - * Custom memory allocator to replace calloc(). The |mem_user_data| - * is the mem_user_data member of :type:`ngtcp2_mem` structure. - */ -typedef void *(*ngtcp2_calloc)(size_t nmemb, size_t size, void *mem_user_data); - -/** - * @functypedef - * - * Custom memory allocator to replace realloc(). The |mem_user_data| - * is the mem_user_data member of :type:`ngtcp2_mem` structure. - */ -typedef void *(*ngtcp2_realloc)(void *ptr, size_t size, void *mem_user_data); - -/** - * @struct - * - * Custom memory allocator functions and user defined pointer. The - * |mem_user_data| member is passed to each allocator function. This - * can be used, for example, to achieve per-session memory pool. - * - * In the following example code, ``my_malloc``, ``my_free``, - * ``my_calloc`` and ``my_realloc`` are the replacement of the - * standard allocators ``malloc``, ``free``, ``calloc`` and - * ``realloc`` respectively:: - * - * void *my_malloc_cb(size_t size, void *mem_user_data) { - * return my_malloc(size); - * } - * - * void my_free_cb(void *ptr, void *mem_user_data) { my_free(ptr); } - * - * void *my_calloc_cb(size_t nmemb, size_t size, void *mem_user_data) { - * return my_calloc(nmemb, size); - * } - * - * void *my_realloc_cb(void *ptr, size_t size, void *mem_user_data) { - * return my_realloc(ptr, size); - * } - * - * void conn_new() { - * ngtcp2_mem mem = {NULL, my_malloc_cb, my_free_cb, my_calloc_cb, - * my_realloc_cb}; - * - * ... - * } - */ -typedef struct ngtcp2_mem { - /** - * An arbitrary user supplied data. This is passed to each - * allocator function. - */ - void *mem_user_data; - /** - * Custom allocator function to replace malloc(). - */ - ngtcp2_malloc malloc; - /** - * Custom allocator function to replace free(). - */ - ngtcp2_free free; - /** - * Custom allocator function to replace calloc(). - */ - ngtcp2_calloc calloc; - /** - * Custom allocator function to replace realloc(). - */ - ngtcp2_realloc realloc; -} ngtcp2_mem; - -/* NGTCP2_PROTO_VER is the supported QUIC protocol version. */ -#define NGTCP2_PROTO_VER 0xff00001du -/* NGTCP2_PROTO_VER_MAX is the highest QUIC version the library - supports. */ -#define NGTCP2_PROTO_VER_MAX NGTCP2_PROTO_VER - -#define NGTCP2_MAX_PKTLEN_IPV4 1252 -#define NGTCP2_MAX_PKTLEN_IPV6 1232 - -/* NGTCP2_MIN_INITIAL_PKTLEN is the minimum UDP packet size for a - packet sent by client which contains its first Initial packet. */ -#define NGTCP2_MIN_INITIAL_PKTLEN 1200 - -/* NGTCP2_DEFAULT_MAX_PKTLEN is the default maximum size of UDP - datagram payload that this endpoint transmits. It is used by - congestion controller to compute congestion window. */ -#define NGTCP2_DEFAULT_MAX_PKTLEN 1200 - -/* NGTCP2_STATELESS_RESET_TOKENLEN is the length of Stateless Reset - Token. */ -#define NGTCP2_STATELESS_RESET_TOKENLEN 16 - -/* NGTCP2_MIN_STATELESS_RESET_RANDLEN is the minimum length of random - bytes (Unpredictable Bits) in Stateless Retry packet */ -#define NGTCP2_MIN_STATELESS_RESET_RANDLEN 5 - -/* NGTCP2_INITIAL_SALT is a salt value which is used to derive initial - secret. */ -#define NGTCP2_INITIAL_SALT \ - "\xaf\xbf\xec\x28\x99\x93\xd2\x4c\x9e\x97\x86\xf1\x9c\x61\x11\xe0\x43\x90" \ - "\xa8\x99" - -/* NGTCP2_RETRY_KEY is an encryption key to create integrity tag of - Retry packet. */ -#define NGTCP2_RETRY_KEY \ - "\xcc\xce\x18\x7e\xd0\x9a\x09\xd0\x57\x28\x15\x5a\x6c\xb9\x6b\xe1" - -/* NGTCP2_RETRY_NONCE is nonce used when generating integrity tag of - Retry packet. */ -#define NGTCP2_RETRY_NONCE "\xe5\x49\x30\xf9\x7f\x21\x36\xf0\x53\x0a\x8c\x1c" - -/* NGTCP2_HP_MASKLEN is the length of header protection mask. */ -#define NGTCP2_HP_MASKLEN 5 - -/* NGTCP2_HP_SAMPLELEN is the number bytes sampled when encrypting a - packet header. */ -#define NGTCP2_HP_SAMPLELEN 16 - -/* NGTCP2_SECONDS is a count of tick which corresponds to 1 second. */ -#define NGTCP2_SECONDS ((uint64_t)1000000000ULL) - -/* NGTCP2_MILLISECONDS is a count of tick which corresponds to 1 - millisecond. */ -#define NGTCP2_MILLISECONDS ((uint64_t)1000000ULL) - -/* NGTCP2_MICROSECONDS is a count of tick which corresponds to 1 - microsecond. */ -#define NGTCP2_MICROSECONDS ((uint64_t)1000ULL) - -/* NGTCP2_NANOSECONDS is a count of tick which corresponds to 1 - nanosecond. */ -#define NGTCP2_NANOSECONDS ((uint64_t)1ULL) - -/* NGTCP2_DEFAULT_INITIAL_RTT is a default initial RTT. */ -#define NGTCP2_DEFAULT_INITIAL_RTT (333 * NGTCP2_MILLISECONDS) - -#if defined(__cplusplus) && __cplusplus >= 201103L -typedef enum ngtcp2_lib_error : int { -#else -typedef enum ngtcp2_lib_error { -#endif - NGTCP2_ERR_INVALID_ARGUMENT = -201, - NGTCP2_ERR_UNKNOWN_PKT_TYPE = -202, - NGTCP2_ERR_NOBUF = -203, - NGTCP2_ERR_PROTO = -205, - NGTCP2_ERR_INVALID_STATE = -206, - NGTCP2_ERR_ACK_FRAME = -207, - NGTCP2_ERR_STREAM_ID_BLOCKED = -208, - NGTCP2_ERR_STREAM_IN_USE = -209, - NGTCP2_ERR_STREAM_DATA_BLOCKED = -210, - NGTCP2_ERR_FLOW_CONTROL = -211, - NGTCP2_ERR_CONNECTION_ID_LIMIT = -212, - NGTCP2_ERR_STREAM_LIMIT = -213, - NGTCP2_ERR_FINAL_SIZE = -214, - NGTCP2_ERR_CRYPTO = -215, - NGTCP2_ERR_PKT_NUM_EXHAUSTED = -216, - NGTCP2_ERR_REQUIRED_TRANSPORT_PARAM = -217, - NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM = -218, - NGTCP2_ERR_FRAME_ENCODING = -219, - NGTCP2_ERR_TLS_DECRYPT = -220, - NGTCP2_ERR_STREAM_SHUT_WR = -221, - NGTCP2_ERR_STREAM_NOT_FOUND = -222, - NGTCP2_ERR_STREAM_STATE = -226, - NGTCP2_ERR_RECV_VERSION_NEGOTIATION = -229, - NGTCP2_ERR_CLOSING = -230, - NGTCP2_ERR_DRAINING = -231, - NGTCP2_ERR_TRANSPORT_PARAM = -234, - NGTCP2_ERR_DISCARD_PKT = -235, - NGTCP2_ERR_PATH_VALIDATION_FAILED = -236, - NGTCP2_ERR_CONN_ID_BLOCKED = -237, - NGTCP2_ERR_INTERNAL = -238, - NGTCP2_ERR_CRYPTO_BUFFER_EXCEEDED = -239, - NGTCP2_ERR_WRITE_MORE = -240, - NGTCP2_ERR_RETRY = -241, - NGTCP2_ERR_DROP_CONN = -242, - NGTCP2_ERR_FATAL = -500, - NGTCP2_ERR_NOMEM = -501, - NGTCP2_ERR_CALLBACK_FAILURE = -502, -} ngtcp2_lib_error; - -typedef enum ngtcp2_pkt_flag { - NGTCP2_PKT_FLAG_NONE = 0, - NGTCP2_PKT_FLAG_LONG_FORM = 0x01, - NGTCP2_PKT_FLAG_KEY_PHASE = 0x04 -} ngtcp2_pkt_flag; - -#if defined(__cplusplus) && __cplusplus >= 201103L -typedef enum ngtcp2_pkt_type : int { -#else -typedef enum ngtcp2_pkt_type { -#endif - /* NGTCP2_PKT_VERSION_NEGOTIATION is defined by libngtcp2 for - convenience. */ - NGTCP2_PKT_VERSION_NEGOTIATION = 0xf0, - NGTCP2_PKT_INITIAL = 0x0, - NGTCP2_PKT_0RTT = 0x1, - NGTCP2_PKT_HANDSHAKE = 0x2, - NGTCP2_PKT_RETRY = 0x3, - /* NGTCP2_PKT_SHORT is defined by libngtcp2 for convenience. */ - NGTCP2_PKT_SHORT = 0x70 -} ngtcp2_pkt_type; - -/* QUIC transport error code. */ -#define NGTCP2_NO_ERROR 0x0u -#define NGTCP2_INTERNAL_ERROR 0x1u -#define NGTCP2_CONNECTION_REFUSED 0x2u -#define NGTCP2_FLOW_CONTROL_ERROR 0x3u -#define NGTCP2_STREAM_LIMIT_ERROR 0x4u -#define NGTCP2_STREAM_STATE_ERROR 0x5u -#define NGTCP2_FINAL_SIZE_ERROR 0x6u -#define NGTCP2_FRAME_ENCODING_ERROR 0x7u -#define NGTCP2_TRANSPORT_PARAMETER_ERROR 0x8u -#define NGTCP2_CONNECTION_ID_LIMIT_ERROR 0x9u -#define NGTCP2_PROTOCOL_VIOLATION 0xau -#define NGTCP2_INVALID_TOKEN 0xbu -#define NGTCP2_APPLICATION_ERROR 0xcu -#define NGTCP2_CRYPTO_BUFFER_EXCEEDED 0xdu -#define NGTCP2_KEY_UPDATE_ERROR 0xeu -#define NGTCP2_CRYPTO_ERROR 0x100u - -#if defined(__cplusplus) && __cplusplus >= 201103L -typedef enum ngtcp2_path_validation_result : int { -#else -typedef enum ngtcp2_path_validation_result { -#endif - NGTCP2_PATH_VALIDATION_RESULT_SUCCESS, - NGTCP2_PATH_VALIDATION_RESULT_FAILURE, -} ngtcp2_path_validation_result; - -/* - * ngtcp2_tstamp is a timestamp with nanosecond resolution. - */ -typedef uint64_t ngtcp2_tstamp; - -/* - * ngtcp2_duration is a period of time in nanosecond resolution. - */ -typedef uint64_t ngtcp2_duration; - -/* NGTCP2_MAX_CIDLEN is the maximum length of Connection ID. */ -#define NGTCP2_MAX_CIDLEN 20 -/* NGTCP2_MIN_CIDLEN is the minimum length of Connection ID. */ -#define NGTCP2_MIN_CIDLEN 1 - -/* NGTCP2_MIN_INITIAL_DCIDLEN is the minimum length of Destination - Connection ID in Client Initial packet if it does not bear token - from Retry packet. */ -#define NGTCP2_MIN_INITIAL_DCIDLEN 8 - -/** - * @struct - * - * ngtcp2_cid holds a Connection ID. - */ -typedef struct ngtcp2_cid { - size_t datalen; - uint8_t data[NGTCP2_MAX_CIDLEN]; -} ngtcp2_cid; - -/** - * @struct - * - * ngtcp2_vec is struct iovec compatible structure to reference - * arbitrary array of bytes. - */ -typedef struct ngtcp2_vec { - /* base points to the data. */ - uint8_t *base; - /* len is the number of bytes which the buffer pointed by base - contains. */ - size_t len; -} ngtcp2_vec; - -/** - * @function - * - * `ngtcp2_cid_init` initializes Connection ID |cid| with the byte - * string pointed by |data| and its length is |datalen|. |datalen| - * must be at least :enum:`NGTCP2_MIN_CIDLEN`, and at most - * :enum:`NGTCP2_MAX_CIDLEN`. - */ -NGTCP2_EXTERN void ngtcp2_cid_init(ngtcp2_cid *cid, const uint8_t *data, - size_t datalen); - -typedef struct ngtcp2_pkt_hd { - ngtcp2_cid dcid; - ngtcp2_cid scid; - int64_t pkt_num; - ngtcp2_vec token; - /** - * pkt_numlen is the number of bytes spent to encode pkt_num. - */ - size_t pkt_numlen; - /** - * len is the sum of pkt_numlen and the length of QUIC packet - * payload. - */ - size_t len; - uint32_t version; - uint8_t type; - uint8_t flags; -} ngtcp2_pkt_hd; - -typedef struct ngtcp2_pkt_stateless_reset { - uint8_t stateless_reset_token[NGTCP2_STATELESS_RESET_TOKENLEN]; - const uint8_t *rand; - size_t randlen; -} ngtcp2_pkt_stateless_reset; - -#if defined(__cplusplus) && __cplusplus >= 201103L -typedef enum ngtcp2_transport_param_id : int { -#else -typedef enum ngtcp2_transport_param_id { -#endif - NGTCP2_TRANSPORT_PARAM_ORIGINAL_DESTINATION_CONNECTION_ID = 0x0000, - NGTCP2_TRANSPORT_PARAM_MAX_IDLE_TIMEOUT = 0x0001, - NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN = 0x0002, - NGTCP2_TRANSPORT_PARAM_MAX_UDP_PAYLOAD_SIZE = 0x0003, - NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_DATA = 0x0004, - NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL = 0x0005, - NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE = 0x0006, - NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_UNI = 0x0007, - NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_BIDI = 0x0008, - NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_UNI = 0x0009, - NGTCP2_TRANSPORT_PARAM_ACK_DELAY_EXPONENT = 0x000a, - NGTCP2_TRANSPORT_PARAM_MAX_ACK_DELAY = 0x000b, - NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION = 0x000c, - NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS = 0x000d, - NGTCP2_TRANSPORT_PARAM_ACTIVE_CONNECTION_ID_LIMIT = 0x000e, - NGTCP2_TRANSPORT_PARAM_INITIAL_SOURCE_CONNECTION_ID = 0x000f, - NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID = 0x0010 -} ngtcp2_transport_param_id; - -#if defined(__cplusplus) && __cplusplus >= 201103L -typedef enum ngtcp2_transport_params_type : int { -#else -typedef enum ngtcp2_transport_params_type { -#endif - NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO, - NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS -} ngtcp2_transport_params_type; - -/** - * @enum - * - * ngtcp2_rand_ctx is a context where generated random value is used. - */ -#if defined(__cplusplus) && __cplusplus >= 201103L -typedef enum ngtcp2_rand_ctx : int { -#else -typedef enum ngtcp2_rand_ctx { -#endif - NGTCP2_RAND_CTX_NONE, - /** - * NGTCP2_RAND_CTX_PATH_CHALLENGE indicates that random value is - * used for PATH_CHALLENGE. - */ - NGTCP2_RAND_CTX_PATH_CHALLENGE -} ngtcp2_rand_ctx; - -/* - * NGTCP2_DEFAULT_MAX_UDP_PAYLOAD_SIZE is the default value of - * max_udp_payload_size transport parameter. - */ -#define NGTCP2_DEFAULT_MAX_UDP_PAYLOAD_SIZE 65527 - -/** - * @macro - * - * NGTCP2_DEFAULT_ACK_DELAY_EXPONENT is a default value of scaling - * factor of ACK Delay field in ACK frame. - */ -#define NGTCP2_DEFAULT_ACK_DELAY_EXPONENT 3 - -/** - * @macro - * - * NGTCP2_DEFAULT_MAX_ACK_DELAY is a default value of the maximum - * amount of time in nanoseconds by which endpoint delays sending - * acknowledgement. - */ -#define NGTCP2_DEFAULT_MAX_ACK_DELAY (25 * NGTCP2_MILLISECONDS) - -/** - * @macro - * - * NGTCP2_DEFAULT_ACTIVE_CONNECTION_ID_LIMIT is the default value of - * active_connection_id_limit transport parameter value if omitted. - */ -#define NGTCP2_DEFAULT_ACTIVE_CONNECTION_ID_LIMIT 2 - -/** - * @macro - * - * NGTCP2_TLSEXT_QUIC_TRANSPORT_PARAMETERS is TLS extension type of - * quic_transport_parameters. - */ -#define NGTCP2_TLSEXT_QUIC_TRANSPORT_PARAMETERS 0xffa5u - -typedef struct ngtcp2_preferred_addr { - ngtcp2_cid cid; - uint16_t ipv4_port; - uint16_t ipv6_port; - uint8_t ipv4_addr[4]; - uint8_t ipv6_addr[16]; - uint8_t stateless_reset_token[NGTCP2_STATELESS_RESET_TOKENLEN]; -} ngtcp2_preferred_addr; - -typedef struct ngtcp2_transport_params { - ngtcp2_preferred_addr preferred_address; - /* original_dcid is the Destination Connection ID field from the - first Initial packet from client. Server must specify this - field. It is expected that application knows the original - Destination Connection ID even if it sends Retry packet, for - example, by including it in retry token. Otherwise, application - should not specify this field. */ - ngtcp2_cid original_dcid; - /* initial_scid is the Source Connection ID field from the first - Initial packet the endpoint sends. Application should not - specify this field. */ - ngtcp2_cid initial_scid; - /* retry_scid is the Source Connection ID field from Retry packet. - Only server uses this field. If server application received - Initial packet with retry token from client and server verified - its token, server application must set Destination Connection ID - field from the Initial packet to this field and set - retry_scid_present to nonzero. Server application must verify - that the Destination Connection ID from Initial packet was sent - in Retry packet by, for example, including the Connection ID in a - token, or including it in AAD when encrypting a token. */ - ngtcp2_cid retry_scid; - /* initial_max_stream_data_bidi_local is the size of flow control - window of locally initiated stream. This is the number of bytes - that the remote endpoint can send and the local endpoint must - ensure that it has enough buffer to receive them. */ - uint64_t initial_max_stream_data_bidi_local; - /* initial_max_stream_data_bidi_remote is the size of flow control - window of remotely initiated stream. This is the number of bytes - that the remote endpoint can send and the local endpoint must - ensure that it has enough buffer to receive them. */ - uint64_t initial_max_stream_data_bidi_remote; - /* initial_max_stream_data_uni is the size of flow control window of - remotely initiated unidirectional stream. This is the number of - bytes that the remote endpoint can send and the local endpoint - must ensure that it has enough buffer to receive them. */ - uint64_t initial_max_stream_data_uni; - /* initial_max_data is the connection level flow control window. */ - uint64_t initial_max_data; - /* initial_max_streams_bidi is the number of concurrent streams that - the remote endpoint can create. */ - uint64_t initial_max_streams_bidi; - /* initial_max_streams_uni is the number of concurrent - unidirectional streams that the remote endpoint can create. */ - uint64_t initial_max_streams_uni; - /* max_idle_timeout is a duration during which sender allows - quiescent. */ - ngtcp2_duration max_idle_timeout; - uint64_t max_udp_payload_size; - /* active_connection_id_limit is the maximum number of Connection ID - that sender can store. */ - uint64_t active_connection_id_limit; - uint64_t ack_delay_exponent; - ngtcp2_duration max_ack_delay; - uint8_t stateless_reset_token_present; - uint8_t disable_active_migration; - uint8_t retry_scid_present; - uint8_t preferred_address_present; - uint8_t stateless_reset_token[NGTCP2_STATELESS_RESET_TOKENLEN]; -} ngtcp2_transport_params; - -typedef struct ngtcp2_log ngtcp2_log; - -typedef enum ngtcp2_pktns_id { - /* NGTCP2_PKTNS_ID_INITIAL is the Initial packet number space. */ - NGTCP2_PKTNS_ID_INITIAL, - /* NGTCP2_PKTNS_ID_INITIAL is the Handshake packet number space. */ - NGTCP2_PKTNS_ID_HANDSHAKE, - /* NGTCP2_PKTNS_ID_INITIAL is the Application data packet number - space. */ - NGTCP2_PKTNS_ID_APP, - /* NGTCP2_PKTNS_ID_MAX is defined to get the number of packet number - spaces. */ - NGTCP2_PKTNS_ID_MAX -} ngtcp2_pktns_id; - -/** - * @struct - * - * ngtcp2_conn_stat holds various connection statistics, and computed - * data for recovery and congestion controller. - */ -typedef struct ngtcp2_conn_stat { - ngtcp2_duration latest_rtt; - ngtcp2_duration min_rtt; - ngtcp2_duration smoothed_rtt; - ngtcp2_duration rttvar; - ngtcp2_duration initial_rtt; - size_t pto_count; - ngtcp2_tstamp loss_detection_timer; - /* last_tx_pkt_ts corresponds to - time_of_last_sent_ack_eliciting_packet in - draft-ietf-quic-recovery-25. */ - ngtcp2_tstamp last_tx_pkt_ts[NGTCP2_PKTNS_ID_MAX]; - ngtcp2_tstamp loss_time[NGTCP2_PKTNS_ID_MAX]; - uint64_t cwnd; - uint64_t ssthresh; - ngtcp2_tstamp congestion_recovery_start_ts; - uint64_t bytes_in_flight; - /* max_udp_payload_size is the maximum size of UDP datagram payload - that this endpoint transmits. It is used by congestion - controller to compute congestion window. */ - size_t max_udp_payload_size; - /* bytes_sent is the number of bytes sent in this particular - connection. It only includes data written by - `ngtcp2_conn_writev_stream()` .*/ - uint64_t bytes_sent; - /* bytes_recv is the number of bytes received in this particular - connection, including discarded packets. */ - uint64_t bytes_recv; - /* delivery_rate_sec is the current sending rate measured per - second. */ - uint64_t delivery_rate_sec; - /* recv_rate_sec is the current receiving rate of application data - measured in per second. */ - uint64_t recv_rate_sec; -} ngtcp2_conn_stat; - -typedef enum ngtcp2_cc_algo { - NGTCP2_CC_ALGO_RENO = 0x00, - NGTCP2_CC_ALGO_CUBIC = 0x01, - NGTCP2_CC_ALGO_CUSTOM = 0xff -} ngtcp2_cc_algo; - -typedef struct ngtcp2_cc_base { - ngtcp2_log *log; -} ngtcp2_cc_base; - -/* ngtcp2_cc_pkt is a convenient structure to include acked/lost/sent - packet. */ -typedef struct { - /* pkt_num is the packet number */ - int64_t pkt_num; - /* pktlen is the length of packet. */ - size_t pktlen; - /* pktns_id is the ID of packet number space which this packet - belongs to. */ - ngtcp2_pktns_id pktns_id; - /* ts_sent is the timestamp when packet is sent. */ - ngtcp2_tstamp ts_sent; -} ngtcp2_cc_pkt; - -typedef struct ngtcp2_cc ngtcp2_cc; - -typedef void (*ngtcp2_cc_on_pkt_acked)(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - const ngtcp2_cc_pkt *pkt, - ngtcp2_tstamp ts); - -typedef void (*ngtcp2_cc_congestion_event)(ngtcp2_cc *cc, - ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts_sent, - ngtcp2_tstamp ts); - -typedef void (*ngtcp2_cc_on_persistent_congestion)(ngtcp2_cc *cc, - ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts); - -typedef void (*ngtcp2_cc_on_ack_recv)(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts); - -typedef void (*ngtcp2_cc_on_pkt_sent)(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - const ngtcp2_cc_pkt *pkt); - -typedef void (*ngtcp2_cc_new_rtt_sample)(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts); - -typedef void (*ngtcp2_cc_reset)(ngtcp2_cc *cc); - -typedef enum ngtcp2_cc_event_type { - /* NGTCP2_CC_EVENT_TX_START occurs when ack-eliciting packet is sent - and no other ack-eliciting packet is present. */ - NGTCP2_CC_EVENT_TYPE_TX_START -} ngtcp2_cc_event_type; - -typedef void (*ngtcp2_cc_event)(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - ngtcp2_cc_event_type event, ngtcp2_tstamp ts); - -typedef struct ngtcp2_cc { - ngtcp2_cc_base *ccb; - ngtcp2_cc_on_pkt_acked on_pkt_acked; - ngtcp2_cc_congestion_event congestion_event; - ngtcp2_cc_on_persistent_congestion on_persistent_congestion; - ngtcp2_cc_on_ack_recv on_ack_recv; - ngtcp2_cc_on_pkt_sent on_pkt_sent; - ngtcp2_cc_new_rtt_sample new_rtt_sample; - ngtcp2_cc_reset reset; - ngtcp2_cc_event event; -} ngtcp2_cc; - -/* user_data is the same object passed to ngtcp2_conn_client_new or - ngtcp2_conn_server_new. */ -typedef void (*ngtcp2_printf)(void *user_data, const char *format, ...); - -/** - * @enum - * - * :type:`ngtcp2_qlog_write_flag` defines the set of flags passed to - * :type:`ngtcp2_qlog_write` callback. - */ -typedef enum ngtcp2_qlog_write_flag { - NGTCP2_QLOG_WRITE_FLAG_NONE = 0, - /** - * NGTCP2_QLOG_WRITE_FLAG_FIN indicates that this is the final call - * to :type:`ngtcp2_qlog_write` in the current connection. - */ - NGTCP2_QLOG_WRITE_FLAG_FIN = 0x01 -} ngtcp2_qlog_write_flag; - -/** - * @functypedef - * - * :type:`ngtcp2_qlog_write` is a callback function which is called to - * write qlog |data| of length |datalen| bytes. |flags| is bitwise OR - * of zero or more of :type:`ngtcp2_qlog_write_flag`. - */ -typedef void (*ngtcp2_qlog_write)(void *user_data, uint32_t flags, - const void *data, size_t datalen); - -typedef struct ngtcp2_qlog_settings { - /* odcid is Original Destination Connection ID sent by client. It - is used as group_id and ODCID fields. Client ignores this field - and uses dcid parameter passed to `ngtcp2_conn_client_new()`. */ - ngtcp2_cid odcid; - /* write is a callback function to write qlog. Setting NULL - disables qlog. */ - ngtcp2_qlog_write write; -} ngtcp2_qlog_settings; - -typedef struct ngtcp2_settings { - /* transport_params is the QUIC transport parameters to send. */ - ngtcp2_transport_params transport_params; - ngtcp2_qlog_settings qlog; - ngtcp2_cc_algo cc_algo; - ngtcp2_cc *cc; - /* initial_ts is an initial timestamp given to the library. */ - ngtcp2_tstamp initial_ts; - /* initial_rtt is an initial RTT. */ - ngtcp2_duration initial_rtt; - /* log_printf is a function that the library uses to write logs. - NULL means no logging output. */ - ngtcp2_printf log_printf; - /* max_udp_payload_size is the maximum size of UDP datagram payload - that this endpoint transmits. It is used by congestion - controller to compute congestion window. If it is set to 0, it - defaults to NGTCP2_DEFAULT_MAX_PKTLEN. */ - size_t max_udp_payload_size; - /** - * token is a token from Retry packet or NEW_TOKEN frame. - * - * Server sets this field if it received the token in Client Initial - * packet and successfully validated. - * - * Client sets this field if it intends to send token in its Initial - * packet. - * - * `ngtcp2_conn_server_new` and `ngtcp2_conn_client_new` make a copy - * of token. - */ - ngtcp2_vec token; -} ngtcp2_settings; - -/** - * @struct - * - * ngtcp2_addr is the endpoint address. - */ -typedef struct ngtcp2_addr { - /* addrlen is the length of addr. */ - size_t addrlen; - /* addr points to the buffer which contains endpoint address. It - must not be NULL. */ - struct sockaddr *addr; - /* user_data is an arbitrary data and opaque to the library. */ - void *user_data; -} ngtcp2_addr; - -/** - * @struct - * - * ngtcp2_path is the network endpoints where a packet is sent and - * received. - */ -typedef struct ngtcp2_path { - /* local is the address of local endpoint. */ - ngtcp2_addr local; - /* remote is the address of remote endpoint. */ - ngtcp2_addr remote; -} ngtcp2_path; - -/** - * @struct - * - * ngtcp2_path_storage is a convenient struct to have buffers to store - * the longest addresses. - */ -typedef struct ngtcp2_path_storage { - struct sockaddr_storage local_addrbuf; - struct sockaddr_storage remote_addrbuf; - ngtcp2_path path; -} ngtcp2_path_storage; - -/** - * @struct - * - * `ngtcp2_crypto_md` is a wrapper around native message digest - * object. - * - * If libngtcp2_crypto_openssl is linked, native_handle must be a - * pointer to EVP_MD. - */ -typedef struct ngtcp2_crypto_md { - void *native_handle; -} ngtcp2_crypto_md; - -/** - * @struct - * - * `ngtcp2_crypto_aead` is a wrapper around native AEAD object. - * - * If libngtcp2_crypto_openssl is linked, native_handle must be a - * pointer to EVP_CIPHER. - */ -typedef struct ngtcp2_crypto_aead { - void *native_handle; -} ngtcp2_crypto_aead; - -/** - * @struct - * - * `ngtcp2_crypto_cipher` is a wrapper around native cipher object. - * - * If libngtcp2_crypto_openssl is linked, native_handle must be a - * pointer to EVP_CIPHER. - */ -typedef struct ngtcp2_crypto_cipher { - void *native_handle; -} ngtcp2_crypto_cipher; - -/** - * @struct - * - * `ngtcp2_crypto_aead_ctx` is a wrapper around native AEAD cipher - * context object. It should be initialized with a specific key. - * ngtcp2 library reuses this context object to encrypt or decrypt - * multiple packets. - */ -typedef struct ngtcp2_crypto_aead_ctx { - void *native_handle; -} ngtcp2_crypto_aead_ctx; - -/** - * @struct - * - * `ngtcp2_crypto_cipher_ctx` is a wrapper around native cipher - * context object. It should be initialized with a specific key. - * ngtcp2 library reuses this context object to encrypt or decrypt - * multiple packet headers. - */ -typedef struct ngtcp2_crypto_cipher_ctx { - void *native_handle; -} ngtcp2_crypto_cipher_ctx; - -/** - * @function - * - * `ngtcp2_crypto_ctx` is a convenient structure to bind all crypto - * related objects in one place. Use `ngtcp2_crypto_ctx_initial` to - * initialize this struct for Initial packet encryption. For - * Handshake and Shortpackets, use `ngtcp2_crypto_ctx_tls`. - */ -typedef struct ngtcp2_crypto_ctx { - ngtcp2_crypto_aead aead; - ngtcp2_crypto_md md; - ngtcp2_crypto_cipher hp; - /* max_encryption is the number of encryption which this key can be - used with. */ - uint64_t max_encryption; - /* max_decryption_failure is the number of decryption failure with - this key. */ - uint64_t max_decryption_failure; -} ngtcp2_crypto_ctx; - -/** - * @function - * - * `ngtcp2_encode_transport_params` encodes |params| in |dest| of - * length |destlen|. - * - * This function returns the number of written, or one of the - * following negative error codes: - * - * :enum:`NGTCP2_ERR_NOBUF` - * Buffer is too small. - * :enum:`NGTCP2_ERR_INVALID_ARGUMENT`: - * |exttype| is invalid. - */ -NGTCP2_EXTERN ngtcp2_ssize ngtcp2_encode_transport_params( - uint8_t *dest, size_t destlen, ngtcp2_transport_params_type exttype, - const ngtcp2_transport_params *params); - -/** - * @function - * - * `ngtcp2_decode_transport_params` decodes transport parameters in - * |data| of length |datalen|, and stores the result in the object - * pointed by |params|. - * - * If the optional parameters are missing, the default value is - * assigned. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_REQUIRED_TRANSPORT_PARAM` - * The required parameter is missing. - * :enum:`NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM` - * The input is malformed. - * :enum:`NGTCP2_ERR_INVALID_ARGUMENT`: - * |exttype| is invalid. - */ -NGTCP2_EXTERN int -ngtcp2_decode_transport_params(ngtcp2_transport_params *params, - ngtcp2_transport_params_type exttype, - const uint8_t *data, size_t datalen); - -/** - * @function - * - * `ngtcp2_pkt_decode_version_cid` extracts QUIC version, Destination - * Connection ID and Source Connection ID from the packet pointed by - * |data| of length |datalen|. This function can handle Connection ID - * up to 255 bytes unlike `ngtcp2_pkt_decode_hd_long` or - * `ngtcp2_pkt_decode_hd_short` which are only capable of handling - * Connection ID less than or equal to :macro:`NGTCP2_MAX_CIDLEN`. - * Longer Connection ID is only valid if the version is unsupported - * QUIC version. - * - * If the given packet is Long packet, this function extracts the - * version from the packet and assigns it to |*pversion|. It also - * extracts the pointer to the Destination Connection ID and its - * length and assigns them to |*pdcid| and |*pdcidlen| respectively. - * Similarly, it extracts the pointer to the Source Connection ID and - * its length and assigns them to |*pscid| and |*pscidlen| - * respectively. - * - * If the given packet is Short packet, |*pversion| will be - * :macro:`NGTCP2_PROTO_VER`, |*pscid| will be NULL, and |*pscidlen| - * will be 0. Because the Short packet does not have the length of - * Destination Connection ID, the caller has to pass the length in - * |short_dcidlen|. This function extracts the pointer to the - * Destination Connection ID and assigns it to |*pdcid|. - * |short_dcidlen| is assigned to |*pdcidlen|. - * - * This function returns 0 or 1 if it succeeds. It returns 1 if - * Version Negotiation packet should be sent. Otherwise, one of the - * following negative error code: - * - * :enum:`NGTCP2_ERR_INVALID_ARGUMENT` - * The function could not decode the packet header. - */ -NGTCP2_EXTERN int -ngtcp2_pkt_decode_version_cid(uint32_t *pversion, const uint8_t **pdcid, - size_t *pdcidlen, const uint8_t **pscid, - size_t *pscidlen, const uint8_t *data, - size_t datalen, size_t short_dcidlen); - -/** - * @function - * - * `ngtcp2_pkt_decode_hd_long` decodes QUIC long packet header in - * |pkt| of length |pktlen|. This function only parses the input just - * before packet number field. - * - * This function does not verify that length field is correct. In - * other words, this function succeeds even if length > |pktlen|. - * - * This function can handle Connection ID up to - * :enum:`NGTCP2_MAX_CIDLEN`. Consider to use - * `ngtcp2_pkt_decode_version_cid` to get longer Connection ID. - * - * This function handles Version Negotiation specially. If version - * field is 0, |pkt| must contain Version Negotiation packet. Version - * Negotiation packet has random type in wire format. For - * convenience, this function sets - * :enum:`NGTCP2_PKT_VERSION_NEGOTIATION` to dest->type, and set - * dest->payloadlen and dest->pkt_num to 0. Version Negotiation - * packet occupies a single packet. - * - * It stores the result in the object pointed by |dest|, and returns - * the number of bytes decoded to read the packet header if it - * succeeds, or one of the following error codes: - * - * :enum:`NGTCP2_ERR_INVALID_ARGUMENT` - * Packet is too short; or it is not a long header - * :enum:`NGTCP2_ERR_UNKNOWN_PKT_TYPE` - * Packet type is unknown - */ -NGTCP2_EXTERN ngtcp2_ssize ngtcp2_pkt_decode_hd_long(ngtcp2_pkt_hd *dest, - const uint8_t *pkt, - size_t pktlen); - -/** - * @function - * - * `ngtcp2_pkt_decode_hd_short` decodes QUIC short packet header in - * |pkt| of length |pktlen|. |dcidlen| is the length of DCID in - * packet header. Short packet does not encode the length of - * connection ID, thus we need the input from the outside. This - * function only parses the input just before packet number field. - * This function can handle Connection ID up to - * :enum:`NGTCP2_MAX_CIDLEN`. Consider to use - * `ngtcp2_pkt_decode_version_cid` to get longer Connection ID. It - * stores the result in the object pointed by |dest|, and returns the - * number of bytes decoded to read the packet header if it succeeds, - * or one of the following error codes: - * - * :enum:`NGTCP2_ERR_INVALID_ARGUMENT` - * Packet is too short; or it is not a short header - * :enum:`NGTCP2_ERR_UNKNOWN_PKT_TYPE` - * Packet type is unknown - */ -NGTCP2_EXTERN ngtcp2_ssize ngtcp2_pkt_decode_hd_short(ngtcp2_pkt_hd *dest, - const uint8_t *pkt, - size_t pktlen, - size_t dcidlen); - -/** - * @function - * - * `ngtcp2_pkt_write_stateless_reset` writes Stateless Reset packet in - * the buffer pointed by |dest| whose length is |destlen|. - * |stateless_reset_token| is a pointer to the Stateless Reset Token, - * and its length must be :macro:`NGTCP2_STATELESS_RESET_TOKENLEN` - * bytes long. |rand| specifies the random octets preceding Stateless - * Reset Token. The length of |rand| is specified by |randlen| which - * must be at least :macro:`NGTCP2_MIN_STATELESS_RETRY_RANDLEN` bytes - * long. - * - * If |randlen| is too long to write them all in the buffer, |rand| is - * written to the buffer as much as possible, and is truncated. - * - * This function returns the number of bytes written to the buffer, or - * one of the following negative error codes: - * - * :enum:`NGTCP2_ERR_NOBUF` - * Buffer is too small. - * :enum:`NGTCP2_ERR_INVALID_ARGUMENT` - * |randlen| is strictly less than - * :macro:`NGTCP2_MIN_STATELESS_RETRY_RANDLEN`. - */ -NGTCP2_EXTERN ngtcp2_ssize ngtcp2_pkt_write_stateless_reset( - uint8_t *dest, size_t destlen, const uint8_t *stateless_reset_token, - const uint8_t *rand, size_t randlen); - -/** - * @function - * - * `ngtcp2_pkt_write_version_negotiation` writes Version Negotiation - * packet in the buffer pointed by |dest| whose length is |destlen|. - * |unused_random| should be generated randomly. |dcid| is the - * destination connection ID which appears in a packet as a source - * connection ID sent by client which caused version negotiation. - * Similarly, |scid| is the source connection ID which appears in a - * packet as a destination connection ID sent by client. |sv| is a - * list of supported versions, and |nsv| specifies the number of - * supported versions included in |sv|. - * - * This function returns the number of bytes written to the buffer, or - * one of the following negative error codes: - * - * :enum:`NGTCP2_ERR_NOBUF` - * Buffer is too small. - */ -NGTCP2_EXTERN ngtcp2_ssize ngtcp2_pkt_write_version_negotiation( - uint8_t *dest, size_t destlen, uint8_t unused_random, const uint8_t *dcid, - size_t dcidlen, const uint8_t *scid, size_t scidlen, const uint32_t *sv, - size_t nsv); - -/** - * @function - * - * `ngtcp2_pkt_get_type_long` returns the long packet type. |c| is - * the first byte of Long packet header. - */ -NGTCP2_EXTERN uint8_t ngtcp2_pkt_get_type_long(uint8_t c); - -struct ngtcp2_conn; - -typedef struct ngtcp2_conn ngtcp2_conn; - -/** - * @functypedef - * - * :type:`ngtcp2_client_initial` is invoked when client application - * asks TLS stack to produce first TLS cryptographic handshake data. - * - * This implementation of this callback must get the first handshake - * data from TLS stack and pass it to ngtcp2 library using - * `ngtcp2_conn_submit_crypto_data` function. Make sure that before - * calling `ngtcp2_conn_submit_crypto_data` function, client - * application must create initial packet protection keys and IVs, and - * provide them to ngtcp2 library using `ngtcp2_conn_set_initial_key` - * and - * - * This callback function must return 0 if it succeeds, or - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` which makes the library call - * return immediately. - * - * TODO: Define error code for TLS stack failure. Suggestion: - * NGTCP2_ERR_CRYPTO. - */ -typedef int (*ngtcp2_client_initial)(ngtcp2_conn *conn, void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_recv_client_initial` is invoked when server receives - * Initial packet from client. An server application must implement - * this callback, and generate initial keys and IVs for both - * transmission and reception. Install them using - * `ngtcp2_conn_set_initial_key`. |dcid| is the destination - * connection ID which client generated randomly. It is used to - * derive initial packet protection keys. - * - * The callback function must return 0 if it succeeds. If an error - * occurs, return :enum:`NGTCP2_ERR_CALLBACK_FAILURE` which makes the - * library call return immediately. - * - * TODO: Define error code for TLS stack failure. Suggestion: - * NGTCP2_ERR_CRYPTO. - */ -typedef int (*ngtcp2_recv_client_initial)(ngtcp2_conn *conn, - const ngtcp2_cid *dcid, - void *user_data); - -/** - * @enum - * - * ngtcp2_crypto_level is encryption level. - */ -#if defined(__cplusplus) && __cplusplus >= 201103L -typedef enum ngtcp2_crypto_level : int { -#else -typedef enum ngtcp2_crypto_level { -#endif - /** - * NGTCP2_CRYPTO_LEVEL_INITIAL is Initial Keys encryption level. - */ - NGTCP2_CRYPTO_LEVEL_INITIAL, - /** - * NGTCP2_CRYPTO_LEVEL_HANDSHAKE is Handshake Keys encryption level. - */ - NGTCP2_CRYPTO_LEVEL_HANDSHAKE, - /** - * NGTCP2_CRYPTO_LEVEL_APP is Application Data (1-RTT) Keys - * encryption level. - */ - NGTCP2_CRYPTO_LEVEL_APP, - /** - * NGTCP2_CRYPTO_LEVEL_EARLY is Early Data (0-RTT) Keys encryption - * level. - */ - NGTCP2_CRYPTO_LEVEL_EARLY -} ngtcp2_crypto_level; - -/** - * @functypedef - * - * :type`ngtcp2_recv_crypto_data` is invoked when crypto data is - * received. The received data is pointed to by |data|, and its length - * is |datalen|. The |offset| specifies the offset where |data| is - * positioned. |user_data| is the arbitrary pointer passed to - * `ngtcp2_conn_client_new` or `ngtcp2_conn_server_new`. The ngtcp2 - * library ensures that the crypto data is passed to the application - * in the increasing order of |offset|. |datalen| is always strictly - * greater than 0. |crypto_level| indicates the encryption level - * where this data is received. Crypto data can never be received in - * :enum:`NGTCP2_CRYPTO_LEVEL_EARLY`. - * - * The application should provide the given data to TLS stack. - * - * The callback function must return 0 if it succeeds. If TLS stack - * reported error, return :enum:`NGTCP2_ERR_CRYPTO`. If application - * encounters fatal error, return :enum:`NGTCP2_ERR_CALLBACK_FAILURE` - * which makes the library call return immediately. If the other - * value is returned, it is treated as - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE`. - */ -typedef int (*ngtcp2_recv_crypto_data)(ngtcp2_conn *conn, - ngtcp2_crypto_level crypto_level, - uint64_t offset, const uint8_t *data, - size_t datalen, void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_handshake_completed` is invoked when QUIC - * cryptographic handshake has completed. - * - * The callback function must return 0 if it succeeds. Returning - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return - * immediately. - */ -typedef int (*ngtcp2_handshake_completed)(ngtcp2_conn *conn, void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_handshake_confirmed` is invoked when QUIC - * cryptographic handshake is confirmed. The handshake confirmation - * means that both endpoints agree that handshake has finished. - * - * The callback function must return 0 if it succeeds. Returning - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return - * immediately. - */ -typedef int (*ngtcp2_handshake_confirmed)(ngtcp2_conn *conn, void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_recv_version_negotiation` is invoked when Version - * Negotiation packet is received. |hd| is the pointer to the QUIC - * packet header object. The vector |sv| of |nsv| elements contains - * the QUIC version the server supports. Since Version Negotiation is - * only sent by server, this callback function is used by client only. - * - * The callback function must return 0 if it succeeds, or - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` which makes the library call - * return immediately. - */ -typedef int (*ngtcp2_recv_version_negotiation)(ngtcp2_conn *conn, - const ngtcp2_pkt_hd *hd, - const uint32_t *sv, size_t nsv, - void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_recv_retry` is invoked when Retry packet is received. - * This callback is client only. - * - * Application must regenerate packet protection key, IV, and header - * protection key for Initial packets using the destination connection - * ID obtained by `ngtcp2_conn_get_dcid()` and install them by calling - * `ngtcp2_conn_install_initial_key()`. - * - * 0-RTT data accepted by the ngtcp2 library will be retransmitted by - * the library automatically. - * - * The callback function must return 0 if it succeeds. Returning - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return - * immediately. - */ -typedef int (*ngtcp2_recv_retry)(ngtcp2_conn *conn, const ngtcp2_pkt_hd *hd, - void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_encrypt` is invoked when the ngtcp2 library asks the - * application to encrypt packet payload. The packet payload to - * encrypt is passed as |plaintext| of length |plaintextlen|. The - * AEAD cipher is |aead|. |aead_ctx| is the AEAD cipher context - * object which is initialized with encryption key. The nonce is - * passed as |nonce| of length |noncelen|. The ad, Additional Data to - * AEAD, is passed as |ad| of length |adlen|. - * - * The implementation of this callback must encrypt |plaintext| using - * the negotiated cipher suite and write the ciphertext into the - * buffer pointed by |dest|. |dest| has enough capacity to store the - * ciphertext. - * - * |dest| and |plaintext| may point to the same buffer. - * - * The callback function must return 0 if it succeeds, or - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` which makes the library call - * return immediately. - */ -typedef int (*ngtcp2_encrypt)(uint8_t *dest, const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *plaintext, size_t plaintextlen, - const uint8_t *nonce, size_t noncelen, - const uint8_t *ad, size_t adlen); - -/** - * @functypedef - * - * :type:`ngtcp2_decrypt` is invoked when the ngtcp2 library asks the - * application to decrypt packet payload. The packet payload to - * decrypt is passed as |ciphertext| of length |ciphertextlen|. The - * AEAD cipher is |aead|. |aead_ctx| is the AEAD cipher context - * object which is initialized with decryption key. The nonce is - * passed as |nonce| of length |noncelen|. The ad, Additional Data to - * AEAD, is passed as |ad| of length |adlen|. - * - * The implementation of this callback must decrypt |ciphertext| using - * the negotiated cipher suite and write the ciphertext into the - * buffer pointed by |dest|. |dest| has enough capacity to store the - * cleartext. - * - * |dest| and |ciphertext| may point to the same buffer. - * - * The callback function must return 0 if it succeeds. If TLS stack - * fails to decrypt data, return :enum:`NGTCP2_ERR_TLS_DECRYPT`. For - * any other errors, return :enum:`NGTCP2_ERR_CALLBACK_FAILURE` which - * makes the library call return immediately. - */ -typedef int (*ngtcp2_decrypt)(uint8_t *dest, const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *ciphertext, size_t ciphertextlen, - const uint8_t *nonce, size_t noncelen, - const uint8_t *ad, size_t adlen); - -/** - * @functypedef - * - * :type:`ngtcp2_hp_mask` is invoked when the ngtcp2 library asks the - * application to produce mask to encrypt or decrypt packet header. - * The encryption cipher is |hp|. |hp_ctx| is the cipher context - * object which is initialized with header protection key. The sample - * is passed as |sample|. - * - * The implementation of this callback must produce a mask using the - * header protection cipher suite specified by QUIC specification and - * write the result into the buffer pointed by |dest|. The length of - * mask must be :macro:`NGTCP2_HP_MASKLEN`. The library ensures that - * |dest| has enough capacity. - * - * The callback function must return 0 if it succeeds, or - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` which makes the library call - * return immediately. - */ -typedef int (*ngtcp2_hp_mask)(uint8_t *dest, const ngtcp2_crypto_cipher *hp, - const ngtcp2_crypto_cipher_ctx *hp_ctx, - const uint8_t *sample); - -/** - * @enum - * - * ngtcp2_stream_data_flag defines the properties of the data emitted - * via :type:`ngtcp2_recv_stream_data` callback function. - */ -typedef enum ngtcp2_stream_data_flag { - NGTCP2_STREAM_DATA_FLAG_NONE = 0x00, - /** - * NGTCP2_STREAM_DATA_FLAG_FIN indicates that this chunk of data is - * final piece of an incoming stream. - */ - NGTCP2_STREAM_DATA_FLAG_FIN = 0x01, - /** - * NGTCP2_STREAM_DATA_FLAG_0RTT indicates that this chunk of data - * contains data received in 0RTT packet and the handshake has not - * completed yet, which means that the data might be replayed. - */ - NGTCP2_STREAM_DATA_FLAG_0RTT = 0x02 -} ngtcp2_stream_data_flag; - -/** - * @functypedef - * - * :type:`ngtcp2_recv_stream_data` is invoked when stream data is - * received. The stream is specified by |stream_id|. |flags| is the - * bitwise-OR of zero or more of ngtcp2_stream_data_flag. If |flags| - * & :enum:`NGTCP2_STREAM_DATA_FLAG_FIN` is nonzero, this portion of - * the data is the last data in this stream. |offset| is the offset - * where this data begins. The library ensures that data is passed to - * the application in the non-decreasing order of |offset|. The data - * is passed as |data| of length |datalen|. |datalen| may be 0 if and - * only if |fin| is nonzero. - * - * The callback function must return 0 if it succeeds, or - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` which makes the library return - * immediately. - */ -typedef int (*ngtcp2_recv_stream_data)(ngtcp2_conn *conn, uint32_t flags, - int64_t stream_id, uint64_t offset, - const uint8_t *data, size_t datalen, - void *user_data, void *stream_user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_stream_open` is a callback function which is called - * when remote stream is opened by peer. This function is not called - * if stream is opened by implicitly (we might reconsider this - * behaviour). - * - * The implementation of this callback should return 0 if it succeeds. - * Returning :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library - * call return immediately. - */ -typedef int (*ngtcp2_stream_open)(ngtcp2_conn *conn, int64_t stream_id, - void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_stream_close` is invoked when a stream is closed. - * This callback is not called when QUIC connection is closed before - * existing streams are closed. |app_error_code| indicates the error - * code of this closure. - * - * The implementation of this callback should return 0 if it succeeds. - * Returning :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library - * call return immediately. - */ -typedef int (*ngtcp2_stream_close)(ngtcp2_conn *conn, int64_t stream_id, - uint64_t app_error_code, void *user_data, - void *stream_user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_stream_reset` is invoked when a stream identified by - * |stream_id| is reset by a remote endpoint. - * - * The implementation of this callback should return 0 if it succeeds. - * Returning :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library - * call return immediately. - */ -typedef int (*ngtcp2_stream_reset)(ngtcp2_conn *conn, int64_t stream_id, - uint64_t final_size, uint64_t app_error_code, - void *user_data, void *stream_user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_acked_stream_data_offset` is a callback function - * which is called when stream data is acked, and application can free - * the data. The acked range of data is [offset, offset + datalen). - * For a given stream_id, this callback is called sequentially in - * increasing order of |offset|. |datalen| is normally strictly - * greater than 0. One exception is that when a packet which includes - * STREAM frame which has fin flag set, and 0 length data, this - * callback is invoked with 0 passed as |datalen|. - * - * If a stream is closed prematurely and stream data is still - * in-flight, this callback function is not called for those data. - * - * The implementation of this callback should return 0 if it succeeds. - * Returning :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library - * call return immediately. - */ -typedef int (*ngtcp2_acked_stream_data_offset)( - ngtcp2_conn *conn, int64_t stream_id, uint64_t offset, uint64_t datalen, - void *user_data, void *stream_user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_acked_crypto_offset` is a callback function which is - * called when crypto stream data is acknowledged, and application can - * free the data. |crypto_level| indicates the encryption level where - * this data was sent. Crypto data never be sent in - * :enum:`NGTCP2_CRYPTO_LEVEL_EARLY`. This works like - * :type:`ngtcp2_acked_stream_data_offset` but crypto stream has no - * stream_id and stream_user_data, and |datalen| never become 0. - * - * The implementation of this callback should return 0 if it succeeds. - * Returning :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library - * call return immediately. - */ -typedef int (*ngtcp2_acked_crypto_offset)(ngtcp2_conn *conn, - ngtcp2_crypto_level crypto_level, - uint64_t offset, uint64_t datalen, - void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_recv_stateless_reset` is a callback function which is - * called when Stateless Reset packet is received. The stateless - * reset details are given in |sr|. - * - * The implementation of this callback should return 0 if it succeeds. - * Returning :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library - * call return immediately. - */ -typedef int (*ngtcp2_recv_stateless_reset)(ngtcp2_conn *conn, - const ngtcp2_pkt_stateless_reset *sr, - void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_extend_max_streams` is a callback function which is - * called every time max stream ID is strictly extended. - * |max_streams| is the cumulative number of streams which an endpoint - * can open. - * - * The callback function must return 0 if it succeeds. Returning - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return - * immediately. - */ -typedef int (*ngtcp2_extend_max_streams)(ngtcp2_conn *conn, - uint64_t max_streams, void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_extend_max_stream_data` is a callback function which - * is invoked when max stream data is extended. |stream_id| - * identifies the stream. |max_data| is a cumulative number of bytes - * the endpoint can send on this stream. - * - * The callback function must return 0 if it succeeds. Returning - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return - * immediately. - */ -typedef int (*ngtcp2_extend_max_stream_data)(ngtcp2_conn *conn, - int64_t stream_id, - uint64_t max_data, void *user_data, - void *stream_user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_rand` is a callback function to get randomized byte - * string from application. Application must fill random |destlen| - * bytes to the buffer pointed by |dest|. |ctx| provides the context - * how the provided random byte string is used. - * - * The callback function must return 0 if it succeeds. Returning - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return - * immediately. - */ -typedef int (*ngtcp2_rand)(uint8_t *dest, size_t destlen, ngtcp2_rand_ctx ctx); - -/** - * @functypedef - * - * :type:`ngtcp2_get_new_connection_id` is a callback function to ask - * an application for new connection ID. Application must generate - * new unused connection ID with the exact |cidlen| bytes and store it - * in |cid|. It also has to generate stateless reset token into - * |token|. The length of stateless reset token is - * :macro:`NGTCP2_STATELESS_RESET_TOKENLEN` and it is guaranteed that - * the buffer pointed by |cid| has the sufficient space to store the - * token. - * - * The callback function must return 0 if it succeeds. Returning - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return - * immediately. - */ -typedef int (*ngtcp2_get_new_connection_id)(ngtcp2_conn *conn, ngtcp2_cid *cid, - uint8_t *token, size_t cidlen, - void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_remove_connection_id` is a callback function which - * notifies the application that connection ID |cid| is no longer used - * by remote endpoint. - * - * The callback function must return 0 if it succeeds. Returning - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return - * immediately. - */ -typedef int (*ngtcp2_remove_connection_id)(ngtcp2_conn *conn, - const ngtcp2_cid *cid, - void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_update_key` is a callback function which tells the - * application that it must generate new packet protection keying - * materials and AEAD cipher context objects with new keys. The - * current set of secrets are given as |current_rx_secret| and - * |current_tx_secret| of length |secretlen|. They are decryption and - * encryption secrets respectively. - * - * The application has to generate new secrets and keys for both - * encryption and decryption, and write decryption secret and IV to - * the buffer pointed by |rx_secret| and |rx_iv| respectively. It - * also has to create new AEAD cipher context object with new - * decryption key and initialize |rx_aead_ctx| with it. Similarly, - * write encryption secret and IV to the buffer pointed by |tx_secret| - * and |tx_iv|. Create new AEAD cipher context object with new - * encryption key and initialize |tx_aead_ctx| with it. All given - * buffers have the enough capacity to store secret, key and IV. - * - * The callback function must return 0 if it succeeds. Returning - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return - * immediately. - */ -typedef int (*ngtcp2_update_key)( - ngtcp2_conn *conn, uint8_t *rx_secret, uint8_t *tx_secret, - ngtcp2_crypto_aead_ctx *rx_aead_ctx, uint8_t *rx_iv, - ngtcp2_crypto_aead_ctx *tx_aead_ctx, uint8_t *tx_iv, - const uint8_t *current_rx_secret, const uint8_t *current_tx_secret, - size_t secretlen, void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_path_validation` is a callback function which tells - * the application the outcome of path validation. |path| is the path - * that was validated. If |res| is - * :enum:`NGTCP2_PATH_VALIDATION_RESULT_SUCCESS`, the path validation - * succeeded. If |res| is - * :enum:`NGTCP2_PATH_VALIDATION_RESULT_FAILURE`, the path validation - * failed. - * - * The callback function must return 0 if it succeeds. Returning - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return - * immediately. - */ -typedef int (*ngtcp2_path_validation)(ngtcp2_conn *conn, - const ngtcp2_path *path, - ngtcp2_path_validation_result res, - void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_select_preferred_addr` is a callback function which - * asks a client application to choose server address from preferred - * addresses |paddr| received from server. An application should - * write preferred address in |dest|. If an application denies the - * preferred addresses, just leave |dest| unmodified (or set dest->len - * to 0) and return 0. - * - * The callback function must return 0 if it succeeds. Returning - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return - * immediately. - */ -typedef int (*ngtcp2_select_preferred_addr)(ngtcp2_conn *conn, - ngtcp2_addr *dest, - const ngtcp2_preferred_addr *paddr, - void *user_data); - -typedef enum ngtcp2_connection_id_status_type { - /* NGTCP2_CONNECTION_ID_STATUS_TYPE_ACTIVATE indicates that a local - endpoint starts using new destination Connection ID. */ - NGTCP2_CONNECTION_ID_STATUS_TYPE_ACTIVATE, - /* NGTCP2_CONNECTION_ID_STATUS_TYPE_DEACTIVATE indicates that a - local endpoint stops using a given destination Connection ID. */ - NGTCP2_CONNECTION_ID_STATUS_TYPE_DEACTIVATE -} ngtcp2_connection_id_status_type; - -/** - * @functypedef - * - * :type:`ngtcp2_connection_id_status` is a callback function which is - * called when the status of Connection ID changes. - * - * |token| is the associated stateless reset token and it is NULL if - * no token is present. - * - * |type| is the one of the value defined in - * :enum:`ngtcp2_connection_id_status_type`. The new value might be - * added in the future release. - * - * The callback function must return 0 if it succeeds. Returning - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return - * immediately. - */ -typedef int (*ngtcp2_connection_id_status)(ngtcp2_conn *conn, int type, - uint64_t seq, const ngtcp2_cid *cid, - const uint8_t *token, - void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_recv_new_token` is a callback function which is - * called when new token is received from server. - * - * |token| is the received token. - * - * The callback function must return 0 if it succeeds. Returning - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return - * immediately. - */ -typedef int (*ngtcp2_recv_new_token)(ngtcp2_conn *conn, const ngtcp2_vec *token, - void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_delete_crypto_aead_ctx` is a callback function which - * must delete the native object pointed by |aead_ctx|->native_handle. - */ -typedef void (*ngtcp2_delete_crypto_aead_ctx)(ngtcp2_conn *conn, - ngtcp2_crypto_aead_ctx *aead_ctx, - void *user_data); - -/** - * @functypedef - * - * :type:`ngtcp2_delete_crypto_cipher_ctx` is a callback function - * which must delete the native object pointed by - * |cipher_ctx|->native_handle. - */ -typedef void (*ngtcp2_delete_crypto_cipher_ctx)( - ngtcp2_conn *conn, ngtcp2_crypto_cipher_ctx *cipher_ctx, void *user_data); - -typedef struct ngtcp2_conn_callbacks { - /** - * client_initial is a callback function which is invoked when - * client asks TLS stack to produce first TLS cryptographic - * handshake message. This callback function must be specified. - */ - ngtcp2_client_initial client_initial; - /** - * recv_client_initial is a callback function which is invoked when - * a server receives the first packet from client. This callback - * function must be specified. - */ - ngtcp2_recv_client_initial recv_client_initial; - /** - * recv_crypto_data is a callback function which is invoked when - * cryptographic data (CRYPTO frame, in other words, TLS message) is - * received. This callback function must be specified. - */ - ngtcp2_recv_crypto_data recv_crypto_data; - /** - * handshake_completed is a callback function which is invoked when - * QUIC cryptographic handshake has completed. This callback - * function is optional. - */ - ngtcp2_handshake_completed handshake_completed; - /** - * recv_version_negotiation is a callback function which is invoked - * when Version Negotiation packet is received by a client. This - * callback function is optional. - */ - ngtcp2_recv_version_negotiation recv_version_negotiation; - /** - * encrypt is a callback function which is invoked to encrypt a QUIC - * packet. This callback function must be specified. - */ - ngtcp2_encrypt encrypt; - /** - * decrypt is a callback function which is invoked to decrypt a QUIC - * packet. This callback function must be specified. - */ - ngtcp2_decrypt decrypt; - /** - * hp_mask is a callback function which is invoked to get a mask to - * encrypt or decrypt packet header. This callback function must be - * specified. - */ - ngtcp2_hp_mask hp_mask; - /** - * recv_stream_data is a callback function which is invoked when - * STREAM data, which includes application data, is received. This - * callback function is optional. - */ - ngtcp2_recv_stream_data recv_stream_data; - /** - * acked_crypto_offset is a callback function which is invoked when - * CRYPTO data is acknowledged by a remote endpoint. It tells an - * application the largest offset of acknowledged CRYPTO data - * without a gap so that the application can free memory for the - * data. This callback function is optional. - */ - ngtcp2_acked_crypto_offset acked_crypto_offset; - /** - * acked_stream_data_offset is a callback function which is invoked - * when STREAM data, which includes application data, is - * acknowledged by a remote endpoint. It tells an application the - * largest offset of acknowledged STREAM data without a gap so that - * application can free memory for the data. This callback function - * is optional. - */ - ngtcp2_acked_stream_data_offset acked_stream_data_offset; - /** - * stream_open is a callback function which is invoked when new - * remote stream is opened by a remote endpoint. This callback - * function is optional. - */ - ngtcp2_stream_open stream_open; - /** - * stream_close is a callback function which is invoked when a - * stream is closed. This callback function is optional. - */ - ngtcp2_stream_close stream_close; - /** - * recv_stateless_reset is a callback function which is invoked when - * Stateless Reset packet is received. This callback function is - * optional. - */ - ngtcp2_recv_stateless_reset recv_stateless_reset; - /** - * recv_retry is a callback function which is invoked when a client - * receives Retry packet. For client, this callback function must - * be specified. Server never receive Retry packet. - */ - ngtcp2_recv_retry recv_retry; - /** - * extend_max_local_streams_bidi is a callback function which is - * invoked when the number of bidirectional stream which a local - * endpoint can open is increased. This callback function is - * optional. - */ - ngtcp2_extend_max_streams extend_max_local_streams_bidi; - /** - * extend_max_local_streams_uni is a callback function which is - * invoked when the number of unidirectional stream which a local - * endpoint can open is increased. This callback function is - * optional. - */ - ngtcp2_extend_max_streams extend_max_local_streams_uni; - /** - * rand is a callback function which is invoked when the library - * needs unpredictable sequence of random data. This callback - * function must be specified. - */ - ngtcp2_rand rand; - /** - * get_new_connection_id is a callback function which is invoked - * when the library needs new connection ID. This callback function - * must be specified. - */ - ngtcp2_get_new_connection_id get_new_connection_id; - /** - * remove_connection_id is a callback function which notifies an - * application that connection ID is no longer used by a remote - * endpoint. This callback function is optional. - */ - ngtcp2_remove_connection_id remove_connection_id; - /** - * update_key is a callback function which is invoked when the - * library tells an application that it must update keying materials - * and install new keys. This function must be specified. - */ - ngtcp2_update_key update_key; - /** - * path_validation is a callback function which is invoked when path - * validation completed. This function is optional. - */ - ngtcp2_path_validation path_validation; - /** - * select_preferred_addr is a callback function which is invoked - * when the library asks a client to select preferred address - * presented by a server. This function is optional. - */ - ngtcp2_select_preferred_addr select_preferred_addr; - /** - * stream_reset is a callback function which is invoked when a - * stream is reset by a remote endpoint. This callback function is - * optional. - */ - ngtcp2_stream_reset stream_reset; - /** - * extend_max_remote_streams_bidi is a callback function which is - * invoked when the number of bidirectional streams which a remote - * endpoint can open is increased. This callback function is - * optional. - */ - ngtcp2_extend_max_streams extend_max_remote_streams_bidi; - /** - * extend_max_remote_streams_uni is a callback function which is - * invoked when the number of unidirectional streams which a remote - * endpoint can open is increased. This callback function is - * optional. - */ - ngtcp2_extend_max_streams extend_max_remote_streams_uni; - /** - * extend_max_stream_data is callback function which is invoked when - * the maximum offset of STREAM data that a local endpoint can send - * is increased. This callback function is optional. - */ - ngtcp2_extend_max_stream_data extend_max_stream_data; - /** - * dcid_status is a callback function which is invoked when the new - * destination Connection ID is activated or the activated - * destination Connection ID is now deactivated. - */ - ngtcp2_connection_id_status dcid_status; - /** - * handshake_confirmed is a callback function which is invoked when - * both endpoints agree that handshake has finished. This field is - * ignored by server because handshake_completed indicates the - * handshake confirmation for server. - */ - ngtcp2_handshake_confirmed handshake_confirmed; - /** - * recv_new_token is a callback function which is invoked when new - * token is received from server. This field is ignored by server. - */ - ngtcp2_recv_new_token recv_new_token; - /** - * delete_crypto_aead_ctx is a callback function which deletes a - * given AEAD cipher context object. - */ - ngtcp2_delete_crypto_aead_ctx delete_crypto_aead_ctx; - /** - * delete_crypto_cipher_ctx is a callback function which deletes a - * given cipher context object. - */ - ngtcp2_delete_crypto_cipher_ctx delete_crypto_cipher_ctx; -} ngtcp2_conn_callbacks; - -/** - * @function - * - * `ngtcp2_pkt_write_connection_close` writes Initial packet - * containing CONNECTION_CLOSE frame with the given |error_code| to - * the buffer pointed by |dest| of length |destlen|. All encryption - * parameters are for Initial packet encryption. The packet number is - * always 0. - * - * The primary use case of this function is for server to send - * CONNECTION_CLOSE frame in Initial packet to close connection - * without committing the state when validating Retry token fails. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * :enum:`NGTCP2_ERR_NOBUF` - * Buffer is too small. - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE - * Callback function failed. - */ -NGTCP2_EXTERN ngtcp2_ssize ngtcp2_pkt_write_connection_close( - uint8_t *dest, size_t destlen, const ngtcp2_cid *dcid, - const ngtcp2_cid *scid, uint64_t error_code, ngtcp2_encrypt encrypt, - const ngtcp2_crypto_aead *aead, const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *iv, ngtcp2_hp_mask hp_mask, const ngtcp2_crypto_cipher *hp, - const ngtcp2_crypto_cipher_ctx *hp_ctx); - -/** - * @function - * - * `ngtcp2_pkt_write_retry` writes Retry packet in the buffer pointed - * by |dest| whose length is |destlen|. |odcid| specifies Original - * Destination Connection ID. |token| specifies Retry Token, and - * |tokenlen| specifies its length. |aead| must be AEAD_AES_128_GCM. - * |aead_ctx| must be initialized with :macro:`NGTCP2_RETRY_KEY` as an - * encryption key. - * - * This function returns the number of bytes written to the buffer, or - * one of the following negative error codes: - * - * :enum:`NGTCP2_ERR_NOBUF` - * Buffer is too small. - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE - * Callback function failed. - */ -NGTCP2_EXTERN ngtcp2_ssize ngtcp2_pkt_write_retry( - uint8_t *dest, size_t destlen, const ngtcp2_cid *dcid, - const ngtcp2_cid *scid, const ngtcp2_cid *odcid, const uint8_t *token, - size_t tokenlen, ngtcp2_encrypt encrypt, const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx); - -/** - * @function - * - * `ngtcp2_accept` is used by server implementation, and decides - * whether packet |pkt| of length |pktlen| is acceptable for initial - * packet from client. - * - * If it is acceptable, it returns 0. If it is not acceptable, and - * Version Negotiation packet is required to send, it returns 1. - * Otherwise, it returns -1. - * - * If |dest| is not NULL, and the return value is 0 or 1, the decoded - * packet header is stored to the object pointed by |dest|. - */ -NGTCP2_EXTERN int ngtcp2_accept(ngtcp2_pkt_hd *dest, const uint8_t *pkt, - size_t pktlen); - -/** - * @function - * - * `ngtcp2_conn_client_new` creates new :type:`ngtcp2_conn`, and - * initializes it as client. |dcid| is randomized destination - * connection ID. |scid| is source connection ID. |version| is a - * QUIC version to use. |path| is the network path where this QUIC - * connection is being established and must not be NULL. |callbacks|, - * and |settings| must not be NULL, and the function make a copy of - * each of them. |user_data| is the arbitrary pointer which is passed - * to the user-defined callback functions. If |mem| is NULL, the - * memory allocator returned by `ngtcp2_mem_default()` is used. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory. - */ -NGTCP2_EXTERN int -ngtcp2_conn_client_new(ngtcp2_conn **pconn, const ngtcp2_cid *dcid, - const ngtcp2_cid *scid, const ngtcp2_path *path, - uint32_t version, const ngtcp2_conn_callbacks *callbacks, - const ngtcp2_settings *settings, const ngtcp2_mem *mem, - void *user_data); - -/** - * @function - * - * `ngtcp2_conn_server_new` creates new :type:`ngtcp2_conn`, and - * initializes it as server. |dcid| is a destination connection ID. - * |scid| is a source connection ID. |path| is the network path where - * this QUIC connection is being established and must not be NULL. - * |version| is a QUIC version to use. |callbacks|, and |settings| - * must not be NULL, and the function make a copy of each of them. - * |user_data| is the arbitrary pointer which is passed to the - * user-defined callback functions. If |mem| is NULL, the memory - * allocator returned by `ngtcp2_mem_default()` is used. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory. - */ -NGTCP2_EXTERN int -ngtcp2_conn_server_new(ngtcp2_conn **pconn, const ngtcp2_cid *dcid, - const ngtcp2_cid *scid, const ngtcp2_path *path, - uint32_t version, const ngtcp2_conn_callbacks *callbacks, - const ngtcp2_settings *settings, const ngtcp2_mem *mem, - void *user_data); - -/** - * @function - * - * `ngtcp2_conn_del` frees resources allocated for |conn|. It also - * frees memory pointed by |conn|. - */ -NGTCP2_EXTERN void ngtcp2_conn_del(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_read_pkt` decrypts QUIC packet given in |pkt| of - * length |pktlen| and processes it. |path| is the network path the - * packet is delivered and must not be NULL. This function performs - * QUIC handshake as well. - * - * This function must not be called from inside the callback - * functions. - * - * This function returns 0 if it succeeds, or negative error codes. - * In general, if the error code which satisfies - * ngtcp2_erro_is_fatal(err) != 0 is returned, the application should - * just close the connection by calling - * `ngtcp2_conn_write_connection_close` or just delete the QUIC - * connection using `ngtcp2_conn_del`. It is undefined to call the - * other library functions. If :enum:`NGTCP2_ERR_RETRY` is returned, - * application must be a server and it must perform address validation - * by sending Retry packet and close the connection. If - * :enum:`NGTCP2_ERR_DROP_CONN` is returned, server application must - * drop the connection silently (without sending any CONNECTION_CLOSE - * frame) and discard connection state. - */ -NGTCP2_EXTERN int ngtcp2_conn_read_pkt(ngtcp2_conn *conn, - const ngtcp2_path *path, - const uint8_t *pkt, size_t pktlen, - ngtcp2_tstamp ts); - -/** - * @function - * - * `ngtcp2_conn_write_pkt` is equivalent to calling - * `ngtcp2_conn_writev_stream` without specifying stream data and - * :enum:`NGTCP2_WRITE_STREAM_FLAG_NONE` as flags. - */ -NGTCP2_EXTERN ngtcp2_ssize ngtcp2_conn_write_pkt(ngtcp2_conn *conn, - ngtcp2_path *path, - uint8_t *dest, size_t destlen, - ngtcp2_tstamp ts); - -/** - * @function - * - * `ngtcp2_conn_handshake_completed` tells |conn| that the QUIC - * handshake has completed. - */ -NGTCP2_EXTERN void ngtcp2_conn_handshake_completed(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_get_handshake_completed` returns nonzero if handshake - * has completed. - */ -NGTCP2_EXTERN int ngtcp2_conn_get_handshake_completed(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_install_initial_key` installs packet protection keying - * materials for Initial packets. |rx_aead_ctx| is AEAD cipher - * context object and must be initialized with decryption key, IV - * |rx_iv| of length |rx_ivlen|, and packet header protection cipher - * context object |rx_hp_ctx| to decrypt incoming Initial packets. - * Similarly, |tx_aead_ctx|, |tx_iv| and |tx_hp_ctx| are for - * encrypting outgoing packets and are the same length with the - * decryption counterpart . If they have already been set, they are - * overwritten. - * - * If this function succeeds, |conn| takes ownership of |rx_aead_ctx|, - * |rx_hp_ctx|, |tx_aead_ctx|, and |tx_hp_ctx|. - * :type:`ngtcp2_delete_crypto_aead_ctx` and - * :type:`ngtcp2_delete_crypto_cipher_ctx` will be called to delete - * these objects when they are no longer used. If this function - * fails, the caller is responsible to delete them. - * - * After receiving Retry packet, the DCID most likely changes. In - * that case, client application must generate these keying materials - * again based on new DCID and install them again. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory. - */ -NGTCP2_EXTERN int ngtcp2_conn_install_initial_key( - ngtcp2_conn *conn, const ngtcp2_crypto_aead_ctx *rx_aead_ctx, - const uint8_t *rx_iv, const ngtcp2_crypto_cipher_ctx *rx_hp_ctx, - const ngtcp2_crypto_aead_ctx *tx_aead_ctx, const uint8_t *tx_iv, - const ngtcp2_crypto_cipher_ctx *tx_hp_ctx, size_t ivlen); - -/** - * @function - * - * `ngtcp2_conn_install_rx_handshake_key` installs packet protection - * keying materials for decrypting incoming Handshake packets. - * |aead_ctx| is AEAD cipher context object which must be initialized - * with decryption key, IV |iv| of length |ivlen|, and packet header - * protection cipher context object |hp_ctx| to decrypt incoming - * Handshake packets. - * - * If this function succeeds, |conn| takes ownership of |aead_ctx|, - * and |hp_ctx|. :type:`ngtcp2_delete_crypto_aead_ctx` and - * :type:`ngtcp2_delete_crypto_cipher_ctx` will be called to delete - * these objects when they are no longer used. If this function - * fails, the caller is responsible to delete them. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory. - */ -NGTCP2_EXTERN int ngtcp2_conn_install_rx_handshake_key( - ngtcp2_conn *conn, const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *iv, size_t ivlen, const ngtcp2_crypto_cipher_ctx *hp_ctx); - -/** - * @function - * - * `ngtcp2_conn_install_tx_handshake_key` installs packet protection - * keying materials for encrypting outgoing Handshake packets. - * |aead_ctx| is AEAD cipher context object which must be initialized - * with encryption key, IV |iv| of length |ivlen|, and packet header - * protection cipher context object |hp_ctx| to encrypt outgoing - * Handshake packets. - * - * If this function succeeds, |conn| takes ownership of |aead_ctx| and - * |hp_ctx|. :type:`ngtcp2_delete_crypto_aead_ctx` and - * :type:`ngtcp2_delete_crypto_cipher_ctx` will be called to delete - * these objects when they are no longer used. If this function - * fails, the caller is responsible to delete them. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory. - */ -NGTCP2_EXTERN int ngtcp2_conn_install_tx_handshake_key( - ngtcp2_conn *conn, const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *iv, size_t ivlen, const ngtcp2_crypto_cipher_ctx *hp_ctx); - -/** - * @function - * - * `ngtcp2_conn_set_aead_overhead` tells the ngtcp2 library the length - * of AEAD tag which the negotiated cipher suites defines. This - * function must be called before encrypting or decrypting the - * incoming packets other than Initial packets. - */ -NGTCP2_EXTERN void ngtcp2_conn_set_aead_overhead(ngtcp2_conn *conn, - size_t aead_overhead); - -/** - * @function - * - * `ngtcp2_conn_get_aead_overhead` returns the aead overhead passed to - * `ngtcp2_conn_set_aead_overhead`. If `ngtcp2_conn_set_aead_overhead` hasn't - * been called yet this function returns 0. - */ -NGTCP2_EXTERN size_t ngtcp2_conn_get_aead_overhead(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_install_early_key` installs packet protection AEAD - * cipher context object |aead_ctx|, IV |iv| of length |ivlen|, and - * packet header protection cipher context object |hp_ctx| to encrypt - * (for client) or decrypt (for server) 0RTT packets. - * - * If this function succeeds, |conn| takes ownership of |aead_ctx| and - * |hp_ctx|. :type:`ngtcp2_delete_crypto_aead_ctx` and - * :type:`ngtcp2_delete_crypto_cipher_ctx` will be called to delete - * these objects when they are no longer used. If this function - * fails, the caller is responsible to delete them. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory. - */ -NGTCP2_EXTERN int ngtcp2_conn_install_early_key( - ngtcp2_conn *conn, const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *iv, size_t ivlen, const ngtcp2_crypto_cipher_ctx *hp_ctx); - -/** - * @function - * - * `ngtcp2_conn_install_rx_key` installs packet protection keying - * materials for decrypting Short packets. |secret| of length - * |secretlen| is the decryption secret which is used to derive keying - * materials passed to this function. |aead_ctx| is AEAD cipher - * context object which must be initialized with decryption key, IV - * |iv| of length |ivlen|, and packet header protection cipher context - * object |hp_ctx| to decrypt incoming Short packets. - * - * If this function succeeds, |conn| takes ownership of |aead_ctx| and - * |hp_ctx|. :type:`ngtcp2_delete_crypto_aead_ctx` and - * :type:`ngtcp2_delete_crypto_cipher_ctx` will be called to delete - * these objects when they are no longer used. If this function - * fails, the caller is responsible to delete them. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory. - */ -NGTCP2_EXTERN int ngtcp2_conn_install_rx_key( - ngtcp2_conn *conn, const uint8_t *secret, size_t secretlen, - const ngtcp2_crypto_aead_ctx *aead_ctx, const uint8_t *iv, size_t ivlen, - const ngtcp2_crypto_cipher_ctx *hp_ctx); - -/** - * @function - * - * `ngtcp2_conn_install_tx_key` installs packet protection keying - * materials for encrypting Short packets. |secret| of length - * |secretlen| is the encryption secret which is used to derive keying - * materials passed to this function. |aead_ctx| is AEAD cipher - * context object which must be initialized with encryption key, IV - * |iv| of length |ivlen|, and packet header protection cipher context - * object |hp_ctx| to encrypt outgoing Short packets. - * - * If this function succeeds, |conn| takes ownership of |aead_ctx| and - * |hp_ctx|. :type:`ngtcp2_delete_crypto_aead_ctx` and - * :type:`ngtcp2_delete_crypto_cipher_ctx` will be called to delete - * these objects when they are no longer used. If this function - * fails, the caller is responsible to delete them. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory. - */ -NGTCP2_EXTERN int ngtcp2_conn_install_tx_key( - ngtcp2_conn *conn, const uint8_t *secret, size_t secretlen, - const ngtcp2_crypto_aead_ctx *aead_ctx, const uint8_t *iv, size_t ivlen, - const ngtcp2_crypto_cipher_ctx *hp_ctx); - -/** - * @function - * - * `ngtcp2_conn_initiate_key_update` initiates the key update. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_INVALID_STATE` - * The previous key update has not been confirmed yet; or key - * update is too frequent; or new keys are not available yet. - */ -NGTCP2_EXTERN int ngtcp2_conn_initiate_key_update(ngtcp2_conn *conn, - ngtcp2_tstamp ts); - -/** - * @function - * - * `ngtcp2_conn_set_tls_error` sets the TLS related error in |conn|. - * In general, error code should be propagated via return value, but - * sometimes ngtcp2 API is called inside callback function of TLS - * stack and it does not allow to return ngtcp2 error code directly. - * In this case, implementation can set the error code (e.g., - * NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM) using this function. - */ -NGTCP2_EXTERN void ngtcp2_conn_set_tls_error(ngtcp2_conn *conn, int liberr); - -/** - * @function - * - * `ngtcp2_conn_get_tls_error` returns the value set by - * `ngtcp2_conn_set_tls_error`. If no value is set, this function - * returns 0. - */ -NGTCP2_EXTERN int ngtcp2_conn_get_tls_error(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_loss_detection_expiry` returns the expiry time point - * of loss detection timer. Application should call - * `ngtcp2_conn_on_loss_detection_timer` and `ngtcp2_conn_write_pkt` - * (or `ngtcp2_conn_writev_stream`) when it expires. It returns - * UINT64_MAX if loss detection timer is not armed. - */ -NGTCP2_EXTERN ngtcp2_tstamp -ngtcp2_conn_loss_detection_expiry(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_ack_delay_expiry` returns the expiry time point of - * delayed protected ACK. Application should call - * ngtcp2_conn_cancel_expired_ack_delay_timer() and - * `ngtcp2_conn_write_pkt` (or `ngtcp2_conn_writev_stream`) when it - * expires. It returns UINT64_MAX if there is no expiry. - */ -NGTCP2_EXTERN ngtcp2_tstamp ngtcp2_conn_ack_delay_expiry(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_get_expiry` returns the next expiry time. This - * function returns the timestamp such that - * min(ngtcp2_conn_loss_detection_expiry(conn), - * ngtcp2_conn_ack_delay_expiry(conn), other timers in |conn|). - * - * Call `ngtcp2_conn_handle_expiry()` and `ngtcp2_conn_write_pkt` (or - * `ngtcp2_conn_writev_stream`) if expiry time is passed. - */ -NGTCP2_EXTERN ngtcp2_tstamp ngtcp2_conn_get_expiry(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_handle_expiry` handles expired timer. It does nothing - * if timer is not expired. - */ -NGTCP2_EXTERN int ngtcp2_conn_handle_expiry(ngtcp2_conn *conn, - ngtcp2_tstamp ts); - -/** - * @function - * - * `ngtcp2_conn_cancel_expired_ack_delay_timer` stops expired ACK - * delay timer. |ts| is the current time. This function must be - * called when ngtcp2_conn_ack_delay_expiry() <= ts. - */ -NGTCP2_EXTERN void ngtcp2_conn_cancel_expired_ack_delay_timer(ngtcp2_conn *conn, - ngtcp2_tstamp ts); - -/** - * @function - * - * `ngtcp2_conn_get_idle_expiry` returns the time when a connection - * should be closed if it continues to be idle. If idle timeout is - * disabled, this function returns UINT64_MAX. - */ -NGTCP2_EXTERN ngtcp2_tstamp ngtcp2_conn_get_idle_expiry(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_get_pto` returns Probe Timeout (PTO). - */ -NGTCP2_EXTERN ngtcp2_duration ngtcp2_conn_get_pto(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_set_remote_transport_params` sets transport parameter - * |params| to |conn|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_PROTO` - * If |conn| is server, and negotiated_version field is not the - * same as the used version. - */ -NGTCP2_EXTERN int -ngtcp2_conn_set_remote_transport_params(ngtcp2_conn *conn, - const ngtcp2_transport_params *params); - -/** - * @function - * - * `ngtcp2_conn_get_remote_transport_params` fills settings values in - * |params|. original_connection_id and - * original_connection_id_present are always zero filled. - */ -NGTCP2_EXTERN void -ngtcp2_conn_get_remote_transport_params(ngtcp2_conn *conn, - ngtcp2_transport_params *params); - -/** - * @function - * - * `ngtcp2_conn_set_early_remote_transport_params` sets |params| as - * transport parameter previously received from a server. The - * parameters are used to send 0-RTT data. QUIC requires that client - * application should remember transport parameter as well as session - * ticket. - * - * At least following fields must be set: - * - * * initial_max_stream_id_bidi - * * initial_max_stream_id_uni - * * initial_max_stream_data_bidi_local - * * initial_max_stream_data_bidi_remote - * * initial_max_stream_data_uni - * * initial_max_data - */ -NGTCP2_EXTERN void ngtcp2_conn_set_early_remote_transport_params( - ngtcp2_conn *conn, const ngtcp2_transport_params *params); - -/** - * @function - * - * `ngtcp2_conn_set_local_transport_params` sets the local transport - * parameters |params|. This function can only be called by server. - * Although the local transport parameters are passed to - * `ngtcp2_conn_server_new`, server might want to update them after - * ALPN is chosen. In that case, server can update the transport - * parameter with this function. Server must call this function - * before calling `ngtcp2_conn_install_tx_handshake_key`. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_INVALID_STATE` - * `ngtcp2_conn_install_tx_handshake_key` has been called. - */ -NGTCP2_EXTERN int -ngtcp2_conn_set_local_transport_params(ngtcp2_conn *conn, - const ngtcp2_transport_params *params); - -/** - * @function - * - * `ngtcp2_conn_get_local_transport_params` fills settings values in - * |params|. - */ -NGTCP2_EXTERN void -ngtcp2_conn_get_local_transport_params(ngtcp2_conn *conn, - ngtcp2_transport_params *params); - -/** - * @function - * - * `ngtcp2_conn_open_bidi_stream` opens new bidirectional stream. The - * |stream_user_data| is the user data specific to the stream. The - * open stream ID is stored in |*pstream_id|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory - * :enum:`NGTCP2_ERR_STREAM_ID_BLOCKED` - * The remote peer does not allow |stream_id| yet. - */ -NGTCP2_EXTERN int ngtcp2_conn_open_bidi_stream(ngtcp2_conn *conn, - int64_t *pstream_id, - void *stream_user_data); - -/** - * @function - * - * `ngtcp2_conn_open_uni_stream` opens new unidirectional stream. The - * |stream_user_data| is the user data specific to the stream. The - * open stream ID is stored in |*pstream_id|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory - * :enum:`NGTCP2_ERR_STREAM_ID_BLOCKED` - * The remote peer does not allow |stream_id| yet. - */ -NGTCP2_EXTERN int ngtcp2_conn_open_uni_stream(ngtcp2_conn *conn, - int64_t *pstream_id, - void *stream_user_data); - -/** - * @function - * - * `ngtcp2_conn_shutdown_stream` closes stream denoted by |stream_id| - * abruptly. |app_error_code| is one of application error codes, and - * indicates the reason of shutdown. Successful call of this function - * does not immediately erase the state of the stream. The actual - * deletion is done when the remote endpoint sends acknowledgement. - * Calling this function is equivalent to call - * `ngtcp2_conn_shutdown_stream_read`, and - * `ngtcp2_conn_shutdown_stream_write` sequentially. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory - * :enum:`NGTCP2_ERR_STREAM_NOT_FOUND` - * Stream does not exist - */ -NGTCP2_EXTERN int ngtcp2_conn_shutdown_stream(ngtcp2_conn *conn, - int64_t stream_id, - uint64_t app_error_code); - -/** - * @function - * - * `ngtcp2_conn_shutdown_stream_write` closes write-side of stream - * denoted by |stream_id| abruptly. |app_error_code| is one of - * application error codes, and indicates the reason of shutdown. If - * this function succeeds, no application data is sent to the remote - * endpoint. It discards all data which has not been acknowledged - * yet. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory - * :enum:`NGTCP2_ERR_STREAM_NOT_FOUND` - * Stream does not exist - */ -NGTCP2_EXTERN int ngtcp2_conn_shutdown_stream_write(ngtcp2_conn *conn, - int64_t stream_id, - uint64_t app_error_code); - -/** - * @function - * - * `ngtcp2_conn_shutdown_stream_read` closes read-side of stream - * denoted by |stream_id| abruptly. |app_error_code| is one of - * application error codes, and indicates the reason of shutdown. If - * this function succeeds, no application data is forwarded to an - * application layer. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory - * :enum:`NGTCP2_ERR_STREAM_NOT_FOUND` - * Stream does not exist - */ -NGTCP2_EXTERN int ngtcp2_conn_shutdown_stream_read(ngtcp2_conn *conn, - int64_t stream_id, - uint64_t app_error_code); - -/** - * @enum - * - * ngtcp2_write_stream_flag defines extra behaviour for - * `ngtcp2_conn_writev_stream()`. - */ -typedef enum ngtcp2_write_stream_flag { - NGTCP2_WRITE_STREAM_FLAG_NONE = 0x00, - /** - * NGTCP2_WRITE_STREAM_FLAG_MORE indicates that more stream data may - * come and should be coalesced into the same packet if possible. - */ - NGTCP2_WRITE_STREAM_FLAG_MORE = 0x01, - /** - * NGTCP2_WRITE_STREAM_FLAG_FIN indicates that the passed data is - * the final part of a stream. - */ - NGTCP2_WRITE_STREAM_FLAG_FIN = 0x02 -} ngtcp2_write_stream_flag; - -/** - * @function - * - * `ngtcp2_conn_write_stream` is just like - * `ngtcp2_conn_writev_stream`. The only difference is that it - * conveniently accepts a single buffer. - */ -NGTCP2_EXTERN ngtcp2_ssize ngtcp2_conn_write_stream( - ngtcp2_conn *conn, ngtcp2_path *path, uint8_t *dest, size_t destlen, - ngtcp2_ssize *pdatalen, uint32_t flags, int64_t stream_id, - const uint8_t *data, size_t datalen, ngtcp2_tstamp ts); - -/** - * @function - * - * `ngtcp2_conn_writev_stream` writes a packet containing stream data - * of stream denoted by |stream_id|. The buffer of the packet is - * pointed by |dest| of length |destlen|. This function performs QUIC - * handshake as well. - * - * Specifying -1 to |stream_id| means no new stream data to send. - * - * If |path| is not NULL, this function stores the network path with - * which the packet should be sent. Each addr field must point to the - * buffer which is at least 128 bytes. ``sizeof(struct - * sockaddr_storage)`` is enough. The assignment might not be done if - * nothing is written to |dest|. - * - * If the all given data is encoded as STREAM frame in |dest|, and if - * |flags| & NGTCP2_WRITE_STREAM_FLAG_FIN is nonzero, fin flag is set - * to outgoing STREAM frame. Otherwise, fin flag in STREAM frame is - * not set. - * - * This packet may contain frames other than STREAM frame. The packet - * might not contain STREAM frame if other frames occupy the packet. - * In that case, |*pdatalen| would be -1 if |pdatalen| is not NULL. - * - * If |flags| & NGTCP2_WRITE_STREAM_FLAG_FIN is nonzero, and 0 length - * STREAM frame is successfully serialized, |*pdatalen| would be 0. - * - * The number of data encoded in STREAM frame is stored in |*pdatalen| - * if it is not NULL. The caller must keep the portion of data - * covered by |*pdatalen| bytes in tact until - * :type:`ngtcp2_acked_stream_data_offset` indicates that they are - * acknowledged by a remote endpoint or the stream is closed. - * - * If |flags| equals to :enum:`NGTCP2_WRITE_STREAM_FLAG_NONE`, this - * function produces a single payload of UDP packet. If the given - * stream data is small (e.g., few bytes), the packet might be - * severely under filled. Too many small packet might increase - * overall packet processing costs. Unless there are retransmissions, - * by default, application can only send 1 STREAM frame in one QUIC - * packet. In order to include more than 1 STREAM frame in one QUIC - * packet, specify :enum:`NGTCP2_WRITE_STREAM_FLAG_MORE` in |flags|. - * This is analogous to ``MSG_MORE`` flag in ``send(2)``. If the - * :enum:`NGTCP2_WRITE_STREAM_FLAG_MORE` is used, there are 4 - * outcomes: - * - * - The function returns the written length of packet just like - * without :enum:`NGTCP2_WRITE_STREAM_FLAG_MORE`. This is because - * packet is nearly full and the library decided to make a complete - * packet. In this case, |*pdatalen| == -1 is asserted. - * - * - The function returns :enum:`NGTCP2_ERR_WRITE_MORE`. In this - * case, |*pdatalen| >= 0 is asserted. This indicates that - * application can call this function with different stream data to - * pack them into the same packet. Application has to specify the - * same |conn|, |path|, |dest|, |destlen|, |pdatalen|, and |ts| - * parameters, otherwise the behaviour is undefined. The - * application can change |flags|. - * - * - The function returns :enum:`NGTCP2_ERR_STREAM_DATA_BLOCKED` which - * indicates that stream is blocked because of flow control. - * - * - The other error might be returned just like without - * :enum:`NGTCP2_WRITE_STREAM_FLAG_MORE`. - * - * When application sees :enum:`NGTCP2_ERR_WRITE_MORE`, it must not - * call other ngtcp2 API functions (application can still call - * `ngtcp2_conn_write_connection_close` or - * `ngtcp2_conn_write_application_close` to handle error from this - * function). Just keep calling `ngtcp2_conn_writev_stream` or - * `ngtcp2_conn_write_pkt` until it returns a positive number (which - * indicates a complete packet is ready). If |*pdatalen| >= 0, the - * function always return :enum:`NGTCP2_ERR_WRITE_MORE`. - * - * This function returns 0 if it cannot write any frame because buffer - * is too small, or packet is congestion limited. Application should - * keep reading and wait for congestion window to grow. - * - * This function must not be called from inside the callback - * functions. - * - * This function returns the number of bytes written in |dest| if it - * succeeds, or one of the following negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory - * :enum:`NGTCP2_ERR_STREAM_NOT_FOUND` - * Stream does not exist - * :enum:`NGTCP2_ERR_STREAM_SHUT_WR` - * Stream is half closed (local); or stream is being reset. - * :enum:`NGTCP2_ERR_PKT_NUM_EXHAUSTED` - * Packet number is exhausted, and cannot send any more packet. - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` - * User callback failed - * :enum:`NGTCP2_ERR_STREAM_DATA_BLOCKED` - * Stream is blocked because of flow control. - * :enum:`NGTCP2_ERR_WRITE_MORE` - * (Only when :enum:`NGTCP2_WRITE_STREAM_FLAG_MORE` is specified) - * Application can call this function to pack more stream data - * into the same packet. See above to know how it works. - * - * In general, if the error code which satisfies - * ngtcp2_err_is_fatal(err) != 0 is returned, the application should - * just close the connection by calling - * `ngtcp2_conn_write_connection_close` or just delete the QUIC - * connection using `ngtcp2_conn_del`. It is undefined to call the - * other library functions. - */ -NGTCP2_EXTERN ngtcp2_ssize ngtcp2_conn_writev_stream( - ngtcp2_conn *conn, ngtcp2_path *path, uint8_t *dest, size_t destlen, - ngtcp2_ssize *pdatalen, uint32_t flags, int64_t stream_id, - const ngtcp2_vec *datav, size_t datavcnt, ngtcp2_tstamp ts); - -/** - * @function - * - * `ngtcp2_conn_write_connection_close` writes a packet which contains - * a CONNECTION_CLOSE frame (type 0x1c) in the buffer pointed by - * |dest| whose capacity is |datalen|. - * - * If |path| is not NULL, this function stores the network path with - * which the packet should be sent. Each addr field must point to the - * buffer which is at least 128 bytes. ``sizeof(struct - * sockaddr_storage)`` is enough. The assignment might not be done if - * nothing is written to |dest|. - * - * This function must not be called from inside the callback - * functions. - * - * At the moment, successful call to this function makes connection - * close. We may change this behaviour in the future to allow - * graceful shutdown. - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory - * :enum:`NGTCP2_ERR_NOBUF` - * Buffer is too small - * :enum:`NGTCP2_ERR_INVALID_STATE` - * The current state does not allow sending CONNECTION_CLOSE. - * :enum:`NGTCP2_ERR_PKT_NUM_EXHAUSTED` - * Packet number is exhausted, and cannot send any more packet. - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` - * User callback failed - */ -NGTCP2_EXTERN ngtcp2_ssize ngtcp2_conn_write_connection_close( - ngtcp2_conn *conn, ngtcp2_path *path, uint8_t *dest, size_t destlen, - uint64_t error_code, ngtcp2_tstamp ts); - -/** - * @function - * - * `ngtcp2_conn_write_application_close` writes a packet which - * contains a CONNECTION_CLOSE frame (type 0x1d) in the buffer pointed - * by |dest| whose capacity is |datalen|. - * - * If |path| is not NULL, this function stores the network path with - * which the packet should be sent. Each addr field must point to the - * buffer which is at least 128 bytes. ``sizeof(struct - * sockaddr_storage)`` is enough. The assignment might not be done if - * nothing is written to |dest|. - * - * If handshake has not been confirmed yet, CONNECTION_CLOSE (type - * 0x1c) with error code :macro:`NGTCP2_APPLICATION_ERROR` is written - * instead. - * - * This function must not be called from inside the callback - * functions. - * - * At the moment, successful call to this function makes connection - * close. We may change this behaviour in the future to allow - * graceful shutdown. - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory - * :enum:`NGTCP2_ERR_NOBUF` - * Buffer is too small - * :enum:`NGTCP2_ERR_INVALID_STATE` - * The current state does not allow sending CONNECTION_CLOSE. - * :enum:`NGTCP2_ERR_PKT_NUM_EXHAUSTED` - * Packet number is exhausted, and cannot send any more packet. - * :enum:`NGTCP2_ERR_CALLBACK_FAILURE` - * User callback failed - */ -NGTCP2_EXTERN ngtcp2_ssize ngtcp2_conn_write_application_close( - ngtcp2_conn *conn, ngtcp2_path *path, uint8_t *dest, size_t destlen, - uint64_t app_error_code, ngtcp2_tstamp ts); - -/** - * @function - * - * `ngtcp2_conn_is_in_closing_period` returns nonzero if |conn| is in - * closing period. - */ -NGTCP2_EXTERN int ngtcp2_conn_is_in_closing_period(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_is_in_draining_period` returns nonzero if |conn| is in - * draining period. - */ -NGTCP2_EXTERN int ngtcp2_conn_is_in_draining_period(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_extend_max_stream_offset` extends stream's max stream - * data value by |datalen|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_STREAM_NOT_FOUND` - * Stream was not found - */ -NGTCP2_EXTERN int ngtcp2_conn_extend_max_stream_offset(ngtcp2_conn *conn, - int64_t stream_id, - uint64_t datalen); - -/** - * @function - * - * `ngtcp2_conn_extend_max_offset` extends max data offset by - * |datalen|. - */ -NGTCP2_EXTERN void ngtcp2_conn_extend_max_offset(ngtcp2_conn *conn, - uint64_t datalen); - -/** - * @function - * - * `ngtcp2_conn_extend_max_streams_bidi` extends the number of maximum - * local bidirectional streams that a remote endpoint can open by |n|. - * - * The library does not increase maximum stream limit automatically. - * The exception is when a stream is closed without - * :type:`ngtcp2_stream_open` callback being called. In this case, - * stream limit is increased automatically. - */ -NGTCP2_EXTERN void ngtcp2_conn_extend_max_streams_bidi(ngtcp2_conn *conn, - size_t n); - -/** - * @function - * - * `ngtcp2_conn_extend_max_streams_uni` extends the number of maximum - * local unidirectional streams that a remote endpoint can open by - * |n|. - * - * The library does not increase maximum stream limit automatically. - * The exception is when a stream is closed without - * :type:`ngtcp2_stream_open` callback being called. In this case, - * stream limit is increased automatically. - */ -NGTCP2_EXTERN void ngtcp2_conn_extend_max_streams_uni(ngtcp2_conn *conn, - size_t n); - -/** - * @function - * - * `ngtcp2_conn_get_dcid` returns the non-NULL pointer to destination - * connection ID. If no destination connection ID is present, the - * return value is not ``NULL``, and its datalen field is 0. - */ -NGTCP2_EXTERN const ngtcp2_cid *ngtcp2_conn_get_dcid(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_get_num_scid` returns the number of source connection - * IDs which the local endpoint has provided to the peer and have not - * retired. - */ -NGTCP2_EXTERN size_t ngtcp2_conn_get_num_scid(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_get_scid` writes the all source connection IDs which - * the local endpoint has provided to the peer and have not retired in - * |dest|. The buffer pointed by |dest| must have - * ``sizeof(ngtcp2_cid) * n`` bytes available, where n is the return - * value of `ngtcp2_conn_get_num_scid()`. - */ -NGTCP2_EXTERN size_t ngtcp2_conn_get_scid(ngtcp2_conn *conn, ngtcp2_cid *dest); - -/** - * @function - * - * `ngtcp2_conn_get_num_active_dcid` returns the number of the active - * destination connection ID. - */ -NGTCP2_EXTERN size_t ngtcp2_conn_get_num_active_dcid(ngtcp2_conn *conn); - -/** - * @struct - * - * :type:`ngtcp2_cid_token` is the convenient struct to store - * Connection ID, its associated path, and stateless reset token. - */ -typedef struct ngtcp2_cid_token { - /* seq is the sequence number of this Connection ID. */ - uint64_t seq; - /* cid is Connection ID. */ - ngtcp2_cid cid; - /* ps is the path which is associated to this Connection ID. */ - ngtcp2_path_storage ps; - /* token is the stateless reset token for this Connection ID. */ - uint8_t token[NGTCP2_STATELESS_RESET_TOKENLEN]; - /* token_resent is nonzero if token contains stateless reset - token. */ - uint8_t token_present; -} ngtcp2_cid_token; - -/** - * @function - * - * `ngtcp2_conn_get_active_dcid` writes the all active destination - * connection IDs and tokens to |dest|. The buffer pointed by |dest| - * must have ``sizeof(ngtcp2_cid_token) * n`` bytes available, where n - * is the return value of `ngtcp2_conn_get_num_active_dcid()`. - */ -NGTCP2_EXTERN size_t ngtcp2_conn_get_active_dcid(ngtcp2_conn *conn, - ngtcp2_cid_token *dest); - -/** - * @function - * - * `ngtcp2_conn_get_negotiated_version` returns the negotiated version. - */ -NGTCP2_EXTERN uint32_t ngtcp2_conn_get_negotiated_version(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_early_data_rejected` tells |conn| that 0-RTT data was - * rejected by a server. - */ -NGTCP2_EXTERN int ngtcp2_conn_early_data_rejected(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_get_conn_stat` assigns connection statistics data to - * |*cstat|. - */ -NGTCP2_EXTERN void ngtcp2_conn_get_conn_stat(ngtcp2_conn *conn, - ngtcp2_conn_stat *cstat); - -/** - * @function - * - * `ngtcp2_conn_on_loss_detection_timer` should be called when a timer - * returned from `ngtcp2_conn_earliest_expiry` fires. - * - * Application should call `ngtcp2_conn_handshake` if handshake has - * not completed, otherwise `ngtcp2_conn_write_pkt` (or - * `ngtcp2_conn_write_stream` if it has data to send) to send TLP/RTO - * probe packets. - * - * This function must not be called from inside the callback - * functions. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory - */ -NGTCP2_EXTERN int ngtcp2_conn_on_loss_detection_timer(ngtcp2_conn *conn, - ngtcp2_tstamp ts); - -/** - * @function - * - * `ngtcp2_conn_submit_crypto_data` submits crypto stream data |data| - * of length |datalen| to the library for transmission. The - * encryption level is given in |crypto_level|. - * - * Application should keep the buffer pointed by |data| alive until - * the data is acknowledged. The acknowledgement is notified by - * :type:`ngtcp2_acked_crypto_offset` callback. - */ -NGTCP2_EXTERN int -ngtcp2_conn_submit_crypto_data(ngtcp2_conn *conn, - ngtcp2_crypto_level crypto_level, - const uint8_t *data, const size_t datalen); - -/** - * @function - * - * `ngtcp2_conn_submit_new_token` submits address validation token. - * It is sent in NEW_TOKEN frame. Only server can call this function. - * |tokenlen| must not be 0. - * - * This function makes a copy of the buffer pointed by |token| of - * length |tokenlen|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory. - */ -NGTCP2_EXTERN int ngtcp2_conn_submit_new_token(ngtcp2_conn *conn, - const uint8_t *token, - size_t tokenlen); - -/** - * @function - * - * `ngtcp2_conn_set_local_addr` sets local endpoint address |addr| to - * |conn|. - */ -NGTCP2_EXTERN void ngtcp2_conn_set_local_addr(ngtcp2_conn *conn, - const ngtcp2_addr *addr); - -/** - * @function - * - * `ngtcp2_conn_set_remote_addr` sets remote endpoint address |addr| - * to |conn|. - */ -NGTCP2_EXTERN void ngtcp2_conn_set_remote_addr(ngtcp2_conn *conn, - const ngtcp2_addr *addr); - -/** - * @function - * - * `ngtcp2_conn_get_remote_addr` returns the remote endpoint address - * set in |conn|. - */ -NGTCP2_EXTERN const ngtcp2_addr *ngtcp2_conn_get_remote_addr(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_initiate_migration` starts connection migration to the - * given |path| which must not be NULL. Only client can initiate - * migration. This function does immediate migration; it does not - * probe peer reachability from a new local address. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_INVALID_STATE` - * Migration is disabled. - * :enum:`NGTCP2_ERR_CONN_ID_BLOCKED` - * No unused connection ID is available. - * :enum:`NGTCP2_ERR_INVALID_ARGUMENT` - * |path| equals the current path. - * :enum:`NGTCP2_ERR_NOMEM` - * Out of memory - */ -NGTCP2_EXTERN int ngtcp2_conn_initiate_migration(ngtcp2_conn *conn, - const ngtcp2_path *path, - ngtcp2_tstamp ts); - -/** - * @function - * - * `ngtcp2_conn_get_max_local_streams_uni` returns the cumulative - * number of streams which local endpoint can open. - */ -NGTCP2_EXTERN uint64_t ngtcp2_conn_get_max_local_streams_uni(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_get_max_data_left` returns the number of bytes that - * this local endpoint can send in this connection. - */ -NGTCP2_EXTERN uint64_t ngtcp2_conn_get_max_data_left(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_get_streams_bidi_left` returns the number of - * bidirectional streams which the local endpoint can open without - * violating stream concurrency limit. - */ -NGTCP2_EXTERN uint64_t ngtcp2_conn_get_streams_bidi_left(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_get_streams_uni_left` returns the number of - * unidirectional streams which the local endpoint can open without - * violating stream concurrency limit. - */ -NGTCP2_EXTERN uint64_t ngtcp2_conn_get_streams_uni_left(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_set_initial_crypto_ctx` sets |ctx| for Initial packet - * encryption. The passed data will be passed to - * :type:`ngtcp2_encrypt`, :type:`ngtcp2_decrypt` and - * :type:`ngtcp2_hp_mask` callbacks. - */ -NGTCP2_EXTERN void -ngtcp2_conn_set_initial_crypto_ctx(ngtcp2_conn *conn, - const ngtcp2_crypto_ctx *ctx); - -/** - * @function - * - * `ngtcp2_conn_get_initial_crypto_ctx` returns - * :type:`ngtcp2_crypto_ctx` object for Initial packet encryption. - */ -NGTCP2_EXTERN const ngtcp2_crypto_ctx * -ngtcp2_conn_get_initial_crypto_ctx(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_set_initial_crypto_ctx` sets |ctx| for - * 0RTT/Handshake/Short packet encryption. In other words, this - * crypto context is used for all packets except for Initial packets. - * The passed data will be passed to :type:`ngtcp2_encrypt`, - * :type:`ngtcp2_decrypt` and :type:`ngtcp2_hp_mask` callbacks. - */ -NGTCP2_EXTERN void ngtcp2_conn_set_crypto_ctx(ngtcp2_conn *conn, - const ngtcp2_crypto_ctx *ctx); - -/** - * @function - * - * `ngtcp2_conn_get_tls_native_handle` returns TLS native handle set by - * `ngtcp2_conn_set_tls_native_handle()`. - */ -NGTCP2_EXTERN void *ngtcp2_conn_get_tls_native_handle(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_set_tls_native_handle` sets TLS native handle - * |tls_native_handle| to |conn|. Internally, it is used as an opaque - * pointer. - */ -NGTCP2_EXTERN void ngtcp2_conn_set_tls_native_handle(ngtcp2_conn *conn, - void *tls_native_handle); - -/** - * @function - * - * `ngtcp2_conn_set_retry_aead` sets |aead| and |aead_ctx| for Retry - * integrity tag verification. |aead| must be AEAD_AES_128_GCM. - * |aead_ctx| must be initialized with :macro:`NGTCP2_RETRY_KEY` as - * encryption key. This function must be called if |conn| is - * initialized as client. Server does not verify the tag and has no - * need to call this function. - * - * If this function succeeds, |conn| takes ownership of |aead_ctx|. - * :type:`ngtcp2_delete_crypto_aead_ctx` will be called to delete this - * object when it is no longer used. If this function fails, the - * caller is responsible to delete it. - */ -NGTCP2_EXTERN void -ngtcp2_conn_set_retry_aead(ngtcp2_conn *conn, const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx); - -/** - * @function - * - * `ngtcp2_conn_get_crypto_ctx` returns :type:`ngtcp2_crypto_ctx` - * object for 0RTT/Handshake/Short packet encryption. - */ -NGTCP2_EXTERN const ngtcp2_crypto_ctx * -ngtcp2_conn_get_crypto_ctx(ngtcp2_conn *conn); - -typedef enum ngtcp2_connection_close_error_code_type { - /* NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT indicates the - error code is QUIC transport error code. */ - NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT, - /* NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION indicates the - error code is application error code. */ - NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION, -} ngtcp2_connection_close_error_code_type; - -typedef struct ngtcp2_connection_close_error_code { - /* error_code is the error code for connection closure. */ - uint64_t error_code; - /* type is the type of error_code. */ - ngtcp2_connection_close_error_code_type type; -} ngtcp2_connection_close_error_code; - -/** - * @function - * - * `ngtcp2_conn_get_connection_close_error_code` stores the received - * connection close error code in |ccec|. - */ -NGTCP2_EXTERN void ngtcp2_conn_get_connection_close_error_code( - ngtcp2_conn *conn, ngtcp2_connection_close_error_code *ccec); - -/** - * @function - * - * `ngtcp2_conn_is_local_stream` returns nonzero if |stream_id| denotes the - * stream which a local endpoint issues. - */ -NGTCP2_EXTERN int ngtcp2_conn_is_local_stream(ngtcp2_conn *conn, - int64_t stream_id); - -/** - * @function - * - * `ngtcp2_conn_is_server` returns nonzero if |conn| is initialized as - * server. - */ -NGTCP2_EXTERN int ngtcp2_conn_is_server(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_after_retry` returns nonzero if |conn| as a client has - * received Retry packet from server and successfully validated it. - */ -NGTCP2_EXTERN int ngtcp2_conn_after_retry(ngtcp2_conn *conn); - -/** - * @function - * - * `ngtcp2_conn_set_stream_user_data` sets |stream_user_data| to the - * stream identified by |stream_id|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`NGTCP2_ERR_STREAM_NOT_FOUND` - * Stream does not exist - */ -NGTCP2_EXTERN int ngtcp2_conn_set_stream_user_data(ngtcp2_conn *conn, - int64_t stream_id, - void *stream_user_data); - -/** - * @function - * - * `ngtcp2_strerror` returns the text representation of |liberr|. - */ -NGTCP2_EXTERN const char *ngtcp2_strerror(int liberr); - -/** - * @function - * - * `ngtcp2_err_is_fatal` returns nonzero if |liberr| is a fatal error. - */ -NGTCP2_EXTERN int ngtcp2_err_is_fatal(int liberr); - -/** - * @function - * - * `ngtcp2_err_infer_quic_transport_error_code` returns a QUIC - * transport error code which corresponds to |liberr|. - */ -NGTCP2_EXTERN uint64_t ngtcp2_err_infer_quic_transport_error_code(int liberr); - -/** - * @function - * - * `ngtcp2_addr_init` initializes |dest| with the given arguments and - * returns |dest|. - */ -NGTCP2_EXTERN ngtcp2_addr *ngtcp2_addr_init(ngtcp2_addr *dest, - const struct sockaddr *addr, - size_t addrlen, void *user_data); - -/** - * @function - * - * `ngtcp2_path_storage_init` initializes |ps| with the given - * arguments. This function copies |local_addr| and |remote_addr|. - */ -NGTCP2_EXTERN void ngtcp2_path_storage_init(ngtcp2_path_storage *ps, - const struct sockaddr *local_addr, - size_t local_addrlen, - void *local_user_data, - const struct sockaddr *remote_addr, - size_t remote_addrlen, - void *remote_user_data); - -/** - * @function - * - * `ngtcp2_path_storage_zero` initializes |ps| with the zero length - * addresses. - */ -NGTCP2_EXTERN void ngtcp2_path_storage_zero(ngtcp2_path_storage *ps); - -/** - * @function - * - * `ngtcp2_settings_default` initializes |settings| with the default - * values. First this function fills |settings| with 0 and set the - * default value to the following fields: - * - * * cc_algo = NGTCP2_CC_ALGO_CUBIC - * * initial_rtt = NGTCP2_DEFAULT_INITIAL_RTT - * * transport_params.max_udp_payload_size = NGTCP2_DEFAULT_MAX_UDP_PAYLOAD_SIZE - * * transport_params.ack_delay_component = NGTCP2_DEFAULT_ACK_DELAY_EXPONENT - * * transport_params.max_ack_delay = NGTCP2_DEFAULT_MAX_ACK_DELAY - * * transport_params.active_connection_id_limit = - * NGTCP2_DEFAULT_ACTIVE_CONNECTION_ID_LIMIT - */ -NGTCP2_EXTERN void ngtcp2_settings_default(ngtcp2_settings *settings); - -/* - * @function - * - * `ngtcp2_mem_default` returns the default, system standard memory - * allocator. - */ -NGTCP2_EXTERN const ngtcp2_mem *ngtcp2_mem_default(void); - -/** - * @macro - * - * The age of :type:`ngtcp2_info` - */ -#define NGTCP2_VERSION_AGE 1 - -/** - * @struct - * - * This struct is what `ngtcp2_version()` returns. It holds - * information about the particular ngtcp2 version. - */ -typedef struct ngtcp2_info { - /** - * Age of this struct. This instance of ngtcp2 sets it to - * :macro:`NGTCP2_VERSION_AGE` but a future version may bump it and - * add more struct fields at the bottom - */ - int age; - /** - * the :macro:`NGTCP2_VERSION_NUM` number (since age ==1) - */ - int version_num; - /** - * points to the :macro:`NGTCP2_VERSION` string (since age ==1) - */ - const char *version_str; - /* -------- the above fields all exist when age == 1 */ -} ngtcp2_info; - -/** - * @function - * - * Returns a pointer to a ngtcp2_info struct with version information - * about the run-time library in use. The |least_version| argument - * can be set to a 24 bit numerical value for the least accepted - * version number and if the condition is not met, this function will - * return a ``NULL``. Pass in 0 to skip the version checking. - */ -NGTCP2_EXTERN ngtcp2_info *ngtcp2_version(int least_version); - -/** - * @function - * - * `ngtcp2_is_bidi_stream` returns nonzero if |stream_id| denotes - * bidirectional stream. - */ -NGTCP2_EXTERN int ngtcp2_is_bidi_stream(int64_t stream_id); - -typedef enum { - NGTCP2_LOG_EVENT_NONE, - /* connection (catch-all) event */ - NGTCP2_LOG_EVENT_CON, - /* packet event */ - NGTCP2_LOG_EVENT_PKT, - /* frame event */ - NGTCP2_LOG_EVENT_FRM, - /* recovery event */ - NGTCP2_LOG_EVENT_RCV, - /* crypto event */ - NGTCP2_LOG_EVENT_CRY, - /* path validation event */ - NGTCP2_LOG_EVENT_PTV, -} ngtcp2_log_event; - -/** - * @function - * - * `ngtcp2_log_info` writes info level log. - */ -NGTCP2_EXTERN void ngtcp2_log_info(ngtcp2_log *log, ngtcp2_log_event ev, - const char *fmt, ...); - -#ifdef __cplusplus -} -#endif - -#endif /* NGTCP2_H */ diff --git a/deps/ngtcp2/lib/includes/ngtcp2/version.h b/deps/ngtcp2/lib/includes/ngtcp2/version.h deleted file mode 100644 index 3782959c286a85..00000000000000 --- a/deps/ngtcp2/lib/includes/ngtcp2/version.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2016 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef VERSION_H -#define VERSION_H - -/** - * @macro - * - * Version number of the ngtcp2 library release. - */ -#define NGTCP2_VERSION "0.1.0-DEV" - -/** - * @macro - * - * Numerical representation of the version number of the ngtcp2 - * library release. This is a 24 bit number with 8 bits for major - * number, 8 bits for minor and 8 bits for patch. Version 1.2.3 - * becomes 0x010203. - */ -#define NGTCP2_VERSION_NUM 0x000100 - -#endif /* VERSION_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_acktr.c b/deps/ngtcp2/lib/ngtcp2_acktr.c deleted file mode 100644 index 7a7f3e469a2f0e..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_acktr.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_acktr.h" - -#include - -int ngtcp2_acktr_entry_new(ngtcp2_acktr_entry **ent, int64_t pkt_num, - ngtcp2_tstamp tstamp, const ngtcp2_mem *mem) { - *ent = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_acktr_entry)); - if (*ent == NULL) { - return NGTCP2_ERR_NOMEM; - } - - (*ent)->pkt_num = pkt_num; - (*ent)->len = 1; - (*ent)->tstamp = tstamp; - - return 0; -} - -void ngtcp2_acktr_entry_del(ngtcp2_acktr_entry *ent, const ngtcp2_mem *mem) { - ngtcp2_mem_free(mem, ent); -} - -static int greater(const ngtcp2_ksl_key *lhs, const ngtcp2_ksl_key *rhs) { - return *(int64_t *)lhs > *(int64_t *)rhs; -} - -int ngtcp2_acktr_init(ngtcp2_acktr *acktr, ngtcp2_log *log, - const ngtcp2_mem *mem) { - int rv; - - rv = ngtcp2_ringbuf_init(&acktr->acks, 128, sizeof(ngtcp2_acktr_ack_entry), - mem); - if (rv != 0) { - return rv; - } - - rv = ngtcp2_ksl_init(&acktr->ents, greater, sizeof(int64_t), mem); - if (rv != 0) { - ngtcp2_ringbuf_free(&acktr->acks); - return rv; - } - - acktr->log = log; - acktr->mem = mem; - acktr->flags = NGTCP2_ACKTR_FLAG_NONE; - acktr->first_unacked_ts = UINT64_MAX; - acktr->rx_npkt = 0; - - return 0; -} - -void ngtcp2_acktr_free(ngtcp2_acktr *acktr) { - ngtcp2_ksl_it it; - - if (acktr == NULL) { - return; - } - - for (it = ngtcp2_ksl_begin(&acktr->ents); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - ngtcp2_acktr_entry_del(ngtcp2_ksl_it_get(&it), acktr->mem); - } - ngtcp2_ksl_free(&acktr->ents); - - ngtcp2_ringbuf_free(&acktr->acks); -} - -int ngtcp2_acktr_add(ngtcp2_acktr *acktr, int64_t pkt_num, int active_ack, - ngtcp2_tstamp ts) { - ngtcp2_ksl_it it; - ngtcp2_acktr_entry *ent, *prev_ent, *delent; - int rv; - int added = 0; - - if (ngtcp2_ksl_len(&acktr->ents)) { - it = ngtcp2_ksl_lower_bound(&acktr->ents, &pkt_num); - if (ngtcp2_ksl_it_end(&it)) { - ngtcp2_ksl_it_prev(&it); - ent = ngtcp2_ksl_it_get(&it); - - assert(ent->pkt_num >= pkt_num + (int64_t)ent->len); - - if (ent->pkt_num == pkt_num + (int64_t)ent->len) { - ++ent->len; - added = 1; - } - } else { - ent = ngtcp2_ksl_it_get(&it); - - assert(ent->pkt_num != pkt_num); - - if (ngtcp2_ksl_it_begin(&it)) { - if (ent->pkt_num + 1 == pkt_num) { - ngtcp2_ksl_update_key(&acktr->ents, &ent->pkt_num, &pkt_num); - ent->pkt_num = pkt_num; - ent->tstamp = ts; - ++ent->len; - added = 1; - } - } else { - ngtcp2_ksl_it_prev(&it); - prev_ent = ngtcp2_ksl_it_get(&it); - - assert(prev_ent->pkt_num >= pkt_num + (int64_t)prev_ent->len); - - if (ent->pkt_num + 1 == pkt_num) { - if (prev_ent->pkt_num == pkt_num + (int64_t)prev_ent->len) { - prev_ent->len += ent->len + 1; - ngtcp2_ksl_remove(&acktr->ents, NULL, &ent->pkt_num); - ngtcp2_acktr_entry_del(ent, acktr->mem); - added = 1; - } else { - ngtcp2_ksl_update_key(&acktr->ents, &ent->pkt_num, &pkt_num); - ent->pkt_num = pkt_num; - ent->tstamp = ts; - ++ent->len; - added = 1; - } - } else if (prev_ent->pkt_num == pkt_num + (int64_t)prev_ent->len) { - ++prev_ent->len; - added = 1; - } - } - } - } - - if (!added) { - rv = ngtcp2_acktr_entry_new(&ent, pkt_num, ts, acktr->mem); - if (rv != 0) { - return rv; - } - rv = ngtcp2_ksl_insert(&acktr->ents, NULL, &ent->pkt_num, ent); - if (rv != 0) { - ngtcp2_acktr_entry_del(ent, acktr->mem); - return rv; - } - } - - if (active_ack) { - acktr->flags |= NGTCP2_ACKTR_FLAG_ACTIVE_ACK; - if (acktr->first_unacked_ts == UINT64_MAX) { - acktr->first_unacked_ts = ts; - } - } - - if (ngtcp2_ksl_len(&acktr->ents) > NGTCP2_ACKTR_MAX_ENT) { - it = ngtcp2_ksl_end(&acktr->ents); - ngtcp2_ksl_it_prev(&it); - delent = ngtcp2_ksl_it_get(&it); - ngtcp2_ksl_remove(&acktr->ents, NULL, &delent->pkt_num); - ngtcp2_acktr_entry_del(delent, acktr->mem); - } - - return 0; -} - -void ngtcp2_acktr_forget(ngtcp2_acktr *acktr, ngtcp2_acktr_entry *ent) { - ngtcp2_ksl_it it; - - it = ngtcp2_ksl_lower_bound(&acktr->ents, &ent->pkt_num); - assert(*(int64_t *)ngtcp2_ksl_it_key(&it) == (int64_t)ent->pkt_num); - - for (; !ngtcp2_ksl_it_end(&it);) { - ent = ngtcp2_ksl_it_get(&it); - ngtcp2_ksl_remove(&acktr->ents, &it, &ent->pkt_num); - ngtcp2_acktr_entry_del(ent, acktr->mem); - } -} - -ngtcp2_ksl_it ngtcp2_acktr_get(ngtcp2_acktr *acktr) { - return ngtcp2_ksl_begin(&acktr->ents); -} - -int ngtcp2_acktr_empty(ngtcp2_acktr *acktr) { - ngtcp2_ksl_it it = ngtcp2_ksl_begin(&acktr->ents); - return ngtcp2_ksl_it_end(&it); -} - -ngtcp2_acktr_ack_entry *ngtcp2_acktr_add_ack(ngtcp2_acktr *acktr, - int64_t pkt_num, - int64_t largest_ack) { - ngtcp2_acktr_ack_entry *ent = ngtcp2_ringbuf_push_front(&acktr->acks); - - ent->largest_ack = largest_ack; - ent->pkt_num = pkt_num; - - return ent; -} - -/* - * acktr_remove removes |ent| from |acktr|. The iterator which points - * to the entry next to |ent| is assigned to |it|. - */ -static void acktr_remove(ngtcp2_acktr *acktr, ngtcp2_ksl_it *it, - ngtcp2_acktr_entry *ent) { - ngtcp2_ksl_remove(&acktr->ents, it, &ent->pkt_num); - ngtcp2_acktr_entry_del(ent, acktr->mem); -} - -static void acktr_on_ack(ngtcp2_acktr *acktr, ngtcp2_ringbuf *rb, - size_t ack_ent_offset) { - ngtcp2_acktr_ack_entry *ack_ent; - ngtcp2_acktr_entry *ent; - ngtcp2_ksl_it it; - - assert(ngtcp2_ringbuf_len(rb)); - - ack_ent = ngtcp2_ringbuf_get(rb, ack_ent_offset); - - /* Assume that ngtcp2_pkt_validate_ack(fr) returns 0 */ - it = ngtcp2_ksl_lower_bound(&acktr->ents, &ack_ent->largest_ack); - for (; !ngtcp2_ksl_it_end(&it);) { - ent = ngtcp2_ksl_it_get(&it); - acktr_remove(acktr, &it, ent); - } - - if (ngtcp2_ksl_len(&acktr->ents)) { - assert(ngtcp2_ksl_it_end(&it)); - - ngtcp2_ksl_it_prev(&it); - ent = ngtcp2_ksl_it_get(&it); - if (ent->pkt_num > ack_ent->largest_ack && - ack_ent->largest_ack >= ent->pkt_num - (int64_t)(ent->len - 1)) { - ent->len = (size_t)(ent->pkt_num - ack_ent->largest_ack); - } - } - - ngtcp2_ringbuf_resize(rb, ack_ent_offset); -} - -void ngtcp2_acktr_recv_ack(ngtcp2_acktr *acktr, const ngtcp2_ack *fr) { - ngtcp2_acktr_ack_entry *ent; - int64_t largest_ack = fr->largest_ack, min_ack; - size_t i, j; - ngtcp2_ringbuf *rb = &acktr->acks; - size_t nacks = ngtcp2_ringbuf_len(rb); - - /* Assume that ngtcp2_pkt_validate_ack(fr) returns 0 */ - for (j = 0; j < nacks; ++j) { - ent = ngtcp2_ringbuf_get(rb, j); - if (largest_ack >= ent->pkt_num) { - break; - } - } - if (j == nacks) { - return; - } - - min_ack = largest_ack - (int64_t)fr->first_ack_blklen; - - if (min_ack <= ent->pkt_num && ent->pkt_num <= largest_ack) { - acktr_on_ack(acktr, rb, j); - return; - } - - for (i = 0; i < fr->num_blks && j < nacks; ++i) { - largest_ack = min_ack - (int64_t)fr->blks[i].gap - 2; - min_ack = largest_ack - (int64_t)fr->blks[i].blklen; - - for (;;) { - if (ent->pkt_num > largest_ack) { - ++j; - if (j == nacks) { - return; - } - ent = ngtcp2_ringbuf_get(rb, j); - continue; - } - if (ent->pkt_num < min_ack) { - break; - } - acktr_on_ack(acktr, rb, j); - return; - } - } -} - -void ngtcp2_acktr_commit_ack(ngtcp2_acktr *acktr) { - acktr->flags &= (uint16_t) ~(NGTCP2_ACKTR_FLAG_ACTIVE_ACK | - NGTCP2_ACKTR_FLAG_IMMEDIATE_ACK | - NGTCP2_ACKTR_FLAG_CANCEL_TIMER); - acktr->first_unacked_ts = UINT64_MAX; - acktr->rx_npkt = 0; -} - -int ngtcp2_acktr_require_active_ack(ngtcp2_acktr *acktr, - ngtcp2_duration max_ack_delay, - ngtcp2_tstamp ts) { - return acktr->first_unacked_ts <= ts - max_ack_delay; -} - -void ngtcp2_acktr_immediate_ack(ngtcp2_acktr *acktr) { - acktr->flags |= NGTCP2_ACKTR_FLAG_IMMEDIATE_ACK; -} diff --git a/deps/ngtcp2/lib/ngtcp2_acktr.h b/deps/ngtcp2/lib/ngtcp2_acktr.h deleted file mode 100644 index 38c1ebe2cfd3ff..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_acktr.h +++ /dev/null @@ -1,221 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_ACKTR_H -#define NGTCP2_ACKTR_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_mem.h" -#include "ngtcp2_ringbuf.h" -#include "ngtcp2_ksl.h" -#include "ngtcp2_pkt.h" - -/* NGTCP2_ACKTR_MAX_ENT is the maximum number of ngtcp2_acktr_entry - which ngtcp2_acktr stores. */ -#define NGTCP2_ACKTR_MAX_ENT 1024 - -/* NGTCP2_NUM_IMMEDIATE_ACK_PKT is the maximum number of received - packets which triggers the immediate ACK. */ -#define NGTCP2_NUM_IMMEDIATE_ACK_PKT 2 - -struct ngtcp2_acktr_entry; -typedef struct ngtcp2_acktr_entry ngtcp2_acktr_entry; - -struct ngtcp2_log; -typedef struct ngtcp2_log ngtcp2_log; - -/* - * ngtcp2_acktr_entry is a range of packets which need to be acked. - */ -struct ngtcp2_acktr_entry { - /* pkt_num is the largest packet number to acknowledge in this - range. */ - int64_t pkt_num; - /* len is the consecutive packets started from pkt_num which - includes pkt_num itself counting in decreasing order. So pkt_num - = 987 and len = 2, this entry includes packet 987 and 986. */ - size_t len; - /* tstamp is the timestamp when a packet denoted by pkt_num is - received. */ - ngtcp2_tstamp tstamp; -}; - -/* - * ngtcp2_acktr_entry_new allocates memory for ent, and initializes it - * with the given parameters. The pointer to the allocated object is - * stored to |*ent|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_acktr_entry_new(ngtcp2_acktr_entry **ent, int64_t pkt_num, - ngtcp2_tstamp tstamp, const ngtcp2_mem *mem); - -/* - * ngtcp2_acktr_entry_del deallocates memory allocated for |ent|. It - * deallocates memory pointed by |ent|. - */ -void ngtcp2_acktr_entry_del(ngtcp2_acktr_entry *ent, const ngtcp2_mem *mem); - -typedef struct { - /* largest_ack is the largest packet number in outgoing ACK frame */ - int64_t largest_ack; - /* pkt_num is the packet number that ACK frame is included. */ - int64_t pkt_num; -} ngtcp2_acktr_ack_entry; - -typedef enum { - NGTCP2_ACKTR_FLAG_NONE = 0x00, - /* NGTCP2_ACKTR_FLAG_IMMEDIATE_ACK indicates that immediate - acknowledgement is required. */ - NGTCP2_ACKTR_FLAG_IMMEDIATE_ACK = 0x01, - /* NGTCP2_ACKTR_FLAG_ACTIVE_ACK indicates that there are - pending protected packet to be acknowledged. */ - NGTCP2_ACKTR_FLAG_ACTIVE_ACK = 0x02, - /* NGTCP2_ACKTR_FLAG_ACK_FINISHED_ACK is set when server received - acknowledgement for ACK which acknowledges the last handshake - packet from client (which contains TLSv1.3 Finished message). */ - NGTCP2_ACKTR_FLAG_ACK_FINISHED_ACK = 0x80, - /* NGTCP2_ACKTR_FLAG_CANCEL_TIMER is set when ACK delay timer is - expired and canceled. */ - NGTCP2_ACKTR_FLAG_CANCEL_TIMER = 0x0100, -} ngtcp2_acktr_flag; - -/* - * ngtcp2_acktr tracks received packets which we have to send ack. - */ -typedef struct { - ngtcp2_ringbuf acks; - /* ents includes ngtcp2_acktr_entry sorted by decreasing order of - packet number. */ - ngtcp2_ksl ents; - ngtcp2_log *log; - const ngtcp2_mem *mem; - /* flags is bitwise OR of zero, or more of ngtcp2_ack_flag. */ - uint16_t flags; - /* first_unacked_ts is timestamp when ngtcp2_acktr_entry is added - first time after the last outgoing ACK frame. */ - ngtcp2_tstamp first_unacked_ts; - /* rx_npkt is the number of packets received without sending ACK. */ - size_t rx_npkt; -} ngtcp2_acktr; - -/* - * ngtcp2_acktr_init initializes |acktr|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_acktr_init(ngtcp2_acktr *acktr, ngtcp2_log *log, - const ngtcp2_mem *mem); - -/* - * ngtcp2_acktr_free frees resources allocated for |acktr|. It frees - * any ngtcp2_acktr_entry added to |acktr|. - */ -void ngtcp2_acktr_free(ngtcp2_acktr *acktr); - -/* - * ngtcp2_acktr_add adds packet number |pkt_num| to |acktr|. - * |active_ack| is nonzero if |pkt_num| is retransmittable packet. - * - * This function assumes that |acktr| does not contain |pkt_num|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * OUt of memory. - */ -int ngtcp2_acktr_add(ngtcp2_acktr *acktr, int64_t pkt_num, int active_ack, - ngtcp2_tstamp ts); - -/* - * ngtcp2_acktr_forget removes all entries which have the packet - * number that is equal to or less than ent->pkt_num. This function - * assumes that |acktr| includes |ent|. - */ -void ngtcp2_acktr_forget(ngtcp2_acktr *acktr, ngtcp2_acktr_entry *ent); - -/* - * ngtcp2_acktr_get returns the pointer to pointer to the entry which - * has the largest packet number to be acked. If there is no entry, - * returned value satisfies ngtcp2_ksl_it_end(&it) != 0. - */ -ngtcp2_ksl_it ngtcp2_acktr_get(ngtcp2_acktr *acktr); - -/* - * ngtcp2_acktr_empty returns nonzero if it has no packet to - * acknowledge. - */ -int ngtcp2_acktr_empty(ngtcp2_acktr *acktr); - -/* - * ngtcp2_acktr_add_ack records outgoing ACK frame whose largest - * acknowledged packet number is |largest_ack|. |pkt_num| is the - * packet number of a packet in which ACK frame is included. This - * function returns a pointer to the object it adds. - */ -ngtcp2_acktr_ack_entry * -ngtcp2_acktr_add_ack(ngtcp2_acktr *acktr, int64_t pkt_num, int64_t largest_ack); - -/* - * ngtcp2_acktr_recv_ack processes the incoming ACK frame |fr|. - * |pkt_num| is a packet number which includes |fr|. If we receive - * ACK which acknowledges the ACKs added by ngtcp2_acktr_add_ack, - * ngtcp2_acktr_entry which the outgoing ACK acknowledges is removed. - */ -void ngtcp2_acktr_recv_ack(ngtcp2_acktr *acktr, const ngtcp2_ack *fr); - -/* - * ngtcp2_acktr_commit_ack tells |acktr| that ACK frame is generated. - */ -void ngtcp2_acktr_commit_ack(ngtcp2_acktr *acktr); - -/* - * ngtcp2_acktr_require_active_ack returns nonzero if ACK frame should - * be generated actively. - */ -int ngtcp2_acktr_require_active_ack(ngtcp2_acktr *acktr, - ngtcp2_duration max_ack_delay, - ngtcp2_tstamp ts); - -/* - * ngtcp2_acktr_immediate_ack tells |acktr| that immediate - * acknowledgement is required. - */ -void ngtcp2_acktr_immediate_ack(ngtcp2_acktr *acktr); - -#endif /* NGTCP2_ACKTR_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_addr.c b/deps/ngtcp2/lib/ngtcp2_addr.c deleted file mode 100644 index cfc91c41e2c38e..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_addr.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_addr.h" - -#include -#include - -#ifdef WIN32 -# include -# include -#else -# include -# include -# include -# include -# include -# include -#endif - -ngtcp2_addr *ngtcp2_addr_init(ngtcp2_addr *dest, const struct sockaddr *addr, - size_t addrlen, void *user_data) { - dest->addrlen = addrlen; - dest->addr = (struct sockaddr *)addr; - dest->user_data = user_data; - return dest; -} - -void ngtcp2_addr_copy(ngtcp2_addr *dest, const ngtcp2_addr *src) { - dest->addrlen = src->addrlen; - if (src->addrlen) { - memcpy(dest->addr, src->addr, src->addrlen); - } - dest->user_data = src->user_data; -} - -void ngtcp2_addr_copy_byte(ngtcp2_addr *dest, const struct sockaddr *addr, - size_t addrlen) { - dest->addrlen = addrlen; - if (addrlen) { - memcpy(dest->addr, addr, addrlen); - } -} - -static int sockaddr_eq(const struct sockaddr *a, const struct sockaddr *b) { - assert(a->sa_family == b->sa_family); - - switch (a->sa_family) { - case AF_INET: { - const struct sockaddr_in *ai = (const struct sockaddr_in *)(void *)a, - *bi = (const struct sockaddr_in *)(void *)b; - return ai->sin_port == bi->sin_port && - memcmp(&ai->sin_addr, &bi->sin_addr, sizeof(ai->sin_addr)) == 0; - } - case AF_INET6: { - const struct sockaddr_in6 *ai = (const struct sockaddr_in6 *)(void *)a, - *bi = (const struct sockaddr_in6 *)(void *)b; - return ai->sin6_port == bi->sin6_port && - memcmp(&ai->sin6_addr, &bi->sin6_addr, sizeof(ai->sin6_addr)) == 0; - } - default: - assert(0); - } -} - -int ngtcp2_addr_eq(const ngtcp2_addr *a, const ngtcp2_addr *b) { - return a->addr->sa_family == b->addr->sa_family && - sockaddr_eq(a->addr, b->addr); -} - -int ngtcp2_addr_empty(const ngtcp2_addr *addr) { return addr->addrlen == 0; } diff --git a/deps/ngtcp2/lib/ngtcp2_addr.h b/deps/ngtcp2/lib/ngtcp2_addr.h deleted file mode 100644 index 238bb435183c20..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_addr.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_ADDR_H -#define NGTCP2_ADDR_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -/* - * ngtcp2_addr_copy copies |src| to |dest|. This function assumes - * that dest->addr points to a buffer which have sufficient size to - * store the copy. - */ -void ngtcp2_addr_copy(ngtcp2_addr *dest, const ngtcp2_addr *src); - -/* - * ngtcp2_addr_copy_byte copies |addr| of length |addrlen| into the - * buffer pointed by dest->addr. dest->len is updated to have - * |addrlen|. This function assumes that dest->addr points to a - * buffer which have sufficient size to store the copy. - */ -void ngtcp2_addr_copy_byte(ngtcp2_addr *dest, const struct sockaddr *addr, - size_t addrlen); - -/* - * ngtcp2_addr_eq returns nonzero if |a| equals |b|. - */ -int ngtcp2_addr_eq(const ngtcp2_addr *a, const ngtcp2_addr *b); - -/* - * ngtcp2_addr_empty returns nonzero if |addr| has zero length - * address. - */ -int ngtcp2_addr_empty(const ngtcp2_addr *addr); - -#endif /* NGTCP2_ADDR_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_buf.c b/deps/ngtcp2/lib/ngtcp2_buf.c deleted file mode 100644 index 373f23d91aed7c..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_buf.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_buf.h" - -void ngtcp2_buf_init(ngtcp2_buf *buf, uint8_t *begin, size_t len) { - buf->begin = buf->pos = buf->last = begin; - buf->end = begin + len; -} - -void ngtcp2_buf_reset(ngtcp2_buf *buf) { buf->pos = buf->last = buf->begin; } - -size_t ngtcp2_buf_left(const ngtcp2_buf *buf) { - return (size_t)(buf->end - buf->last); -} - -size_t ngtcp2_buf_len(const ngtcp2_buf *buf) { - return (size_t)(buf->last - buf->pos); -} - -size_t ngtcp2_buf_cap(const ngtcp2_buf *buf) { - return (size_t)(buf->end - buf->begin); -} diff --git a/deps/ngtcp2/lib/ngtcp2_buf.h b/deps/ngtcp2/lib/ngtcp2_buf.h deleted file mode 100644 index fe3d06a1c9733d..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_buf.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_BUF_H -#define NGTCP2_BUF_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -typedef struct { - /* begin points to the beginning of the buffer. */ - uint8_t *begin; - /* end points to the one beyond of the last byte of the buffer */ - uint8_t *end; - /* pos pointers to the start of data. Typically, this points to the - point that next data should be read. Initially, it points to - |begin|. */ - uint8_t *pos; - /* last points to the one beyond of the last data of the buffer. - Typically, new data is written at this point. Initially, it - points to |begin|. */ - uint8_t *last; -} ngtcp2_buf; - -/* - * ngtcp2_buf_init initializes |buf| with the given buffer. - */ -void ngtcp2_buf_init(ngtcp2_buf *buf, uint8_t *begin, size_t len); - -/* - * ngtcp2_buf_reset resets pos and last fields to match begin field to - * make ngtcp2_buf_len(buf) return 0. - */ -void ngtcp2_buf_reset(ngtcp2_buf *buf); - -/* - * ngtcp2_buf_left returns the number of additional bytes which can be - * written to the underlying buffer. In other words, it returns - * buf->end - buf->last. - */ -size_t ngtcp2_buf_left(const ngtcp2_buf *buf); - -/* - * ngtcp2_buf_len returns the number of bytes left to read. In other - * words, it returns buf->last - buf->pos. - */ -size_t ngtcp2_buf_len(const ngtcp2_buf *buf); - -/* - * ngtcp2_buf_cap returns the capacity of the buffer. In other words, - * it returns buf->end - buf->begin. - */ -size_t ngtcp2_buf_cap(const ngtcp2_buf *buf); - -#endif /* NGTCP2_BUF_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_cc.c b/deps/ngtcp2/lib/ngtcp2_cc.c deleted file mode 100644 index ef2e63a0efdac0..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_cc.c +++ /dev/null @@ -1,526 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_cc.h" - -#include - -#if defined(_MSC_VER) -# include -#endif - -#include "ngtcp2_log.h" -#include "ngtcp2_macro.h" -#include "ngtcp2_mem.h" -#include "ngtcp2_rcvry.h" - -uint64_t ngtcp2_cc_compute_initcwnd(size_t max_udp_payload_size) { - uint64_t n = 2 * max_udp_payload_size; - n = ngtcp2_max(n, 14720); - return ngtcp2_min(10 * max_udp_payload_size, n); -} - -ngtcp2_cc_pkt *ngtcp2_cc_pkt_init(ngtcp2_cc_pkt *pkt, int64_t pkt_num, - size_t pktlen, ngtcp2_pktns_id pktns_id, - ngtcp2_tstamp ts_sent) { - pkt->pkt_num = pkt_num; - pkt->pktlen = pktlen; - pkt->pktns_id = pktns_id; - pkt->ts_sent = ts_sent; - - return pkt; -} - -static void reno_cc_reset(ngtcp2_reno_cc *cc) { - cc->max_delivery_rate_sec = 0; - cc->target_cwnd = 0; -} - -void ngtcp2_reno_cc_init(ngtcp2_reno_cc *cc, ngtcp2_log *log) { - cc->ccb.log = log; - reno_cc_reset(cc); -} - -void ngtcp2_reno_cc_free(ngtcp2_reno_cc *cc) { (void)cc; } - -int ngtcp2_cc_reno_cc_init(ngtcp2_cc *cc, ngtcp2_log *log, - const ngtcp2_mem *mem) { - ngtcp2_reno_cc *reno_cc; - - reno_cc = ngtcp2_mem_calloc(mem, 1, sizeof(ngtcp2_reno_cc)); - if (reno_cc == NULL) { - return NGTCP2_ERR_NOMEM; - } - - ngtcp2_reno_cc_init(reno_cc, log); - - cc->ccb = &reno_cc->ccb; - cc->on_pkt_acked = ngtcp2_cc_reno_cc_on_pkt_acked; - cc->congestion_event = ngtcp2_cc_reno_cc_congestion_event; - cc->on_persistent_congestion = ngtcp2_cc_reno_cc_on_persistent_congestion; - cc->on_ack_recv = ngtcp2_cc_reno_cc_on_ack_recv; - cc->reset = ngtcp2_cc_reno_cc_reset; - - return 0; -} - -void ngtcp2_cc_reno_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem) { - ngtcp2_reno_cc *reno_cc = ngtcp2_struct_of(cc->ccb, ngtcp2_reno_cc, ccb); - - ngtcp2_reno_cc_free(reno_cc); - ngtcp2_mem_free(mem, reno_cc); -} - -static int in_congestion_recovery(const ngtcp2_conn_stat *cstat, - ngtcp2_tstamp sent_time) { - return sent_time <= cstat->congestion_recovery_start_ts; -} - -void ngtcp2_cc_reno_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat, - const ngtcp2_cc_pkt *pkt, - ngtcp2_tstamp ts) { - ngtcp2_reno_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_reno_cc, ccb); - (void)ts; - - if (in_congestion_recovery(cstat, pkt->ts_sent)) { - return; - } - - if (cc->target_cwnd && cc->target_cwnd < cstat->cwnd) { - return; - } - - if (cstat->cwnd < cstat->ssthresh) { - cstat->cwnd += pkt->pktlen; - ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV, - "pkn=%" PRId64 " acked, slow start cwnd=%" PRIu64, - pkt->pkt_num, cstat->cwnd); - return; - } - - cstat->cwnd += cstat->max_udp_payload_size * pkt->pktlen / cstat->cwnd; -} - -void ngtcp2_cc_reno_cc_congestion_event(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts_sent, - ngtcp2_tstamp ts) { - ngtcp2_reno_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_reno_cc, ccb); - uint64_t min_cwnd; - - if (in_congestion_recovery(cstat, ts_sent)) { - return; - } - - cstat->congestion_recovery_start_ts = ts; - cstat->cwnd >>= NGTCP2_LOSS_REDUCTION_FACTOR_BITS; - min_cwnd = 2 * cstat->max_udp_payload_size; - cstat->cwnd = ngtcp2_max(cstat->cwnd, min_cwnd); - cstat->ssthresh = cstat->cwnd; - - ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV, - "reduce cwnd because of packet loss cwnd=%" PRIu64, - cstat->cwnd); -} - -void ngtcp2_cc_reno_cc_on_persistent_congestion(ngtcp2_cc *ccx, - ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts) { - (void)ccx; - (void)ts; - - cstat->cwnd = 2 * cstat->max_udp_payload_size; -} - -void ngtcp2_cc_reno_cc_on_ack_recv(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts) { - ngtcp2_reno_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_reno_cc, ccb); - uint64_t target_cwnd, initcwnd; - (void)ts; - - /* TODO Use sliding window for min rtt measurement */ - /* TODO Use sliding window */ - cc->max_delivery_rate_sec = - ngtcp2_max(cc->max_delivery_rate_sec, cstat->delivery_rate_sec); - - if (cstat->min_rtt != UINT64_MAX && cc->max_delivery_rate_sec) { - target_cwnd = cc->max_delivery_rate_sec * cstat->min_rtt / NGTCP2_SECONDS; - initcwnd = ngtcp2_cc_compute_initcwnd(cstat->max_udp_payload_size); - cc->target_cwnd = ngtcp2_max(initcwnd, target_cwnd) * 289 / 100; - - ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV, - "target_cwnd=%" PRIu64 " max_delivery_rate_sec=%" PRIu64 - " min_rtt=%" PRIu64, - cc->target_cwnd, cc->max_delivery_rate_sec, cstat->min_rtt); - } -} - -void ngtcp2_cc_reno_cc_reset(ngtcp2_cc *ccx) { - ngtcp2_reno_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_reno_cc, ccb); - reno_cc_reset(cc); -} - -static void cubic_cc_reset(ngtcp2_cubic_cc *cc) { - cc->max_delivery_rate_sec = 0; - cc->target_cwnd = 0; - cc->w_last_max = 0; - cc->w_tcp = 0; - cc->origin_point = 0; - cc->epoch_start = UINT64_MAX; - cc->k = 0; - - cc->rtt_sample_count = 0; - cc->current_round_min_rtt = UINT64_MAX; - cc->last_round_min_rtt = UINT64_MAX; - cc->window_end = -1; -} - -void ngtcp2_cubic_cc_init(ngtcp2_cubic_cc *cc, ngtcp2_log *log) { - cc->ccb.log = log; - cubic_cc_reset(cc); -} - -void ngtcp2_cubic_cc_free(ngtcp2_cubic_cc *cc) { (void)cc; } - -int ngtcp2_cc_cubic_cc_init(ngtcp2_cc *cc, ngtcp2_log *log, - const ngtcp2_mem *mem) { - ngtcp2_cubic_cc *cubic_cc; - - cubic_cc = ngtcp2_mem_calloc(mem, 1, sizeof(ngtcp2_cubic_cc)); - if (cubic_cc == NULL) { - return NGTCP2_ERR_NOMEM; - } - - ngtcp2_cubic_cc_init(cubic_cc, log); - - cc->ccb = &cubic_cc->ccb; - cc->on_pkt_acked = ngtcp2_cc_cubic_cc_on_pkt_acked; - cc->congestion_event = ngtcp2_cc_cubic_cc_congestion_event; - cc->on_persistent_congestion = ngtcp2_cc_cubic_cc_on_persistent_congestion; - cc->on_ack_recv = ngtcp2_cc_cubic_cc_on_ack_recv; - cc->on_pkt_sent = ngtcp2_cc_cubic_cc_on_pkt_sent; - cc->new_rtt_sample = ngtcp2_cc_cubic_cc_new_rtt_sample; - cc->reset = ngtcp2_cc_cubic_cc_reset; - cc->event = ngtcp2_cc_cubic_cc_event; - - return 0; -} - -void ngtcp2_cc_cubic_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem) { - ngtcp2_cubic_cc *cubic_cc = ngtcp2_struct_of(cc->ccb, ngtcp2_cubic_cc, ccb); - - ngtcp2_cubic_cc_free(cubic_cc); - ngtcp2_mem_free(mem, cubic_cc); -} - -static uint64_t ngtcp2_cbrt(uint64_t n) { - int d; - uint64_t a; - - if (n == 0) { - return 0; - } - -#if defined(_MSC_VER) -# if defined(_M_X64) - d = (int)__lzcnt64(n); -# elif defined(_M_ARM64) - { - unsigned long index; - d = sizeof(uint64_t) * CHAR_BIT; - if (_BitScanReverse64(&index, n)) { - d = d - 1 - index; - } - } -# else - if ((n >> 32) != 0) { - d = __lzcnt((unsigned int)(n >> 32)); - } else { - d = 32 + __lzcnt((unsigned int)n); - } -# endif -#else - d = __builtin_clzll(n); -#endif - a = 1ULL << ((64 - d) / 3 + 1); - - for (; a * a * a > n;) { - a = (2 * a + n / a / a) / 3; - } - return a; -} - -/* HyStart++ constants */ -#define NGTCP2_HS_MIN_SSTHRESH 16 -#define NGTCP2_HS_N_RTT_SAMPLE 8 -#define NGTCP2_HS_MIN_ETA (4 * NGTCP2_MILLISECONDS) -#define NGTCP2_HS_MAX_ETA (16 * NGTCP2_MILLISECONDS) - -void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat, - const ngtcp2_cc_pkt *pkt, - ngtcp2_tstamp ts) { - ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb); - ngtcp2_duration t, min_rtt, eta; - uint64_t target; - uint64_t tx, kx, time_delta, delta; - uint64_t add, tcp_add; - uint64_t m; - - if (pkt->pktns_id == NGTCP2_PKTNS_ID_APP && cc->window_end != -1 && - cc->window_end <= pkt->pkt_num) { - cc->window_end = -1; - } - - if (in_congestion_recovery(cstat, pkt->ts_sent)) { - return; - } - - if (cc->target_cwnd && cc->target_cwnd < cstat->cwnd) { - return; - } - - if (cstat->cwnd < cstat->ssthresh) { - /* slow-start */ - cstat->cwnd += pkt->pktlen; - - ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV, - "pkn=%" PRId64 " acked, slow start cwnd=%" PRIu64, - pkt->pkt_num, cstat->cwnd); - - if (cc->last_round_min_rtt != UINT64_MAX && - cc->current_round_min_rtt != UINT64_MAX && - cstat->cwnd >= NGTCP2_HS_MIN_SSTHRESH * cstat->max_udp_payload_size && - cc->rtt_sample_count >= NGTCP2_HS_N_RTT_SAMPLE) { - eta = cc->last_round_min_rtt / 8; - - if (eta < NGTCP2_HS_MIN_ETA) { - eta = NGTCP2_HS_MIN_ETA; - } else if (eta > NGTCP2_HS_MAX_ETA) { - eta = NGTCP2_HS_MAX_ETA; - } - - if (cc->current_round_min_rtt >= cc->last_round_min_rtt + eta) { - ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV, - "HyStart++ exit slow start"); - - cc->w_last_max = cstat->cwnd; - cstat->ssthresh = cstat->cwnd; - } - } - - return; - } - - /* congestion avoidance */ - - if (cc->epoch_start == UINT64_MAX) { - cc->epoch_start = ts; - if (cstat->cwnd < cc->w_last_max) { - cc->k = ngtcp2_cbrt((cc->w_last_max - cstat->cwnd) * 10 / 4 / - cstat->max_udp_payload_size); - cc->origin_point = cc->w_last_max; - } else { - cc->k = 0; - cc->origin_point = cstat->cwnd; - } - - cc->w_tcp = cstat->cwnd; - - ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV, - "cubic-ca epoch_start=%" PRIu64 " k=%" PRIu64 - " origin_point=%" PRIu64, - cc->epoch_start, cc->k, cc->origin_point); - - cc->pending_add = 0; - cc->pending_w_add = 0; - } - - min_rtt = cstat->min_rtt == UINT64_MAX ? cstat->initial_rtt : cstat->min_rtt; - - t = ts + min_rtt - cc->epoch_start; - - tx = (t << 4) / NGTCP2_SECONDS; - kx = (cc->k << 4); - - if (tx > kx) { - time_delta = tx - kx; - } else { - time_delta = kx - tx; - } - - delta = cstat->max_udp_payload_size * - ((((time_delta * time_delta) >> 4) * time_delta) >> 8) * 4 / 10; - - if (tx > kx) { - target = cc->origin_point + delta; - } else { - target = cc->origin_point - delta; - } - - if (target > cstat->cwnd) { - m = cc->pending_add + cstat->max_udp_payload_size * (target - cstat->cwnd); - add = m / cstat->cwnd; - cc->pending_add = m % cstat->cwnd; - } else { - m = cc->pending_add + cstat->max_udp_payload_size; - add = m / (100 * cstat->cwnd); - cc->pending_add = m % (100 * cstat->cwnd); - } - - m = cc->pending_w_add + cstat->max_udp_payload_size * pkt->pktlen; - - cc->w_tcp += m / cstat->cwnd; - cc->pending_w_add = m % cstat->cwnd; - - if (cc->w_tcp > cstat->cwnd) { - tcp_add = - cstat->max_udp_payload_size * (cc->w_tcp - cstat->cwnd) / cstat->cwnd; - if (tcp_add > add) { - add = tcp_add; - } - } - - cstat->cwnd += add; - - ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV, - "pkn=%" PRId64 " acked, cubic-ca cwnd=%" PRIu64 " t=%" PRIu64 - " k=%" PRIi64 " time_delta=%" PRIu64 " delta=%" PRIu64 - " target=%" PRIu64 " w_tcp=%" PRIu64, - pkt->pkt_num, cstat->cwnd, t, cc->k, time_delta >> 4, delta, - target, cc->w_tcp); -} - -void ngtcp2_cc_cubic_cc_congestion_event(ngtcp2_cc *ccx, - ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts_sent, - ngtcp2_tstamp ts) { - ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb); - uint64_t min_cwnd; - - if (in_congestion_recovery(cstat, ts_sent)) { - return; - } - - cstat->congestion_recovery_start_ts = ts; - - cc->epoch_start = UINT64_MAX; - if (cstat->cwnd < cc->w_last_max) { - cc->w_last_max = cstat->cwnd * 17 / 10 / 2; - } else { - cc->w_last_max = cstat->cwnd; - } - - min_cwnd = 2 * cstat->max_udp_payload_size; - cstat->ssthresh = cstat->cwnd * 7 / 10; - cstat->ssthresh = ngtcp2_max(cstat->ssthresh, min_cwnd); - cstat->cwnd = cstat->ssthresh; - - ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV, - "reduce cwnd because of packet loss cwnd=%" PRIu64, - cstat->cwnd); -} - -void ngtcp2_cc_cubic_cc_on_persistent_congestion(ngtcp2_cc *ccx, - ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts) { - (void)ccx; - (void)ts; - - cstat->cwnd = 2 * cstat->max_udp_payload_size; -} - -void ngtcp2_cc_cubic_cc_on_ack_recv(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts) { - ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb); - uint64_t target_cwnd, initcwnd; - (void)ts; - - /* TODO Use sliding window for min rtt measurement */ - /* TODO Use sliding window */ - cc->max_delivery_rate_sec = - ngtcp2_max(cc->max_delivery_rate_sec, cstat->delivery_rate_sec); - - if (cstat->min_rtt != UINT64_MAX && cc->max_delivery_rate_sec) { - target_cwnd = cc->max_delivery_rate_sec * cstat->min_rtt / NGTCP2_SECONDS; - initcwnd = ngtcp2_cc_compute_initcwnd(cstat->max_udp_payload_size); - cc->target_cwnd = ngtcp2_max(initcwnd, target_cwnd) * 289 / 100; - - ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV, - "target_cwnd=%" PRIu64 " max_delivery_rate_sec=%" PRIu64 - " min_rtt=%" PRIu64, - cc->target_cwnd, cc->max_delivery_rate_sec, cstat->min_rtt); - } -} - -void ngtcp2_cc_cubic_cc_on_pkt_sent(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat, - const ngtcp2_cc_pkt *pkt) { - ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb); - (void)cstat; - - if (pkt->pktns_id != NGTCP2_PKTNS_ID_APP || cc->window_end != -1) { - return; - } - - cc->window_end = pkt->pkt_num; - cc->last_round_min_rtt = cc->current_round_min_rtt; - cc->current_round_min_rtt = UINT64_MAX; - cc->rtt_sample_count = 0; -} - -void ngtcp2_cc_cubic_cc_new_rtt_sample(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts) { - ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb); - (void)ts; - - if (cc->window_end == -1) { - return; - } - - cc->current_round_min_rtt = - ngtcp2_min(cc->current_round_min_rtt, cstat->latest_rtt); - ++cc->rtt_sample_count; -} - -void ngtcp2_cc_cubic_cc_reset(ngtcp2_cc *ccx) { - ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb); - cubic_cc_reset(cc); -} - -void ngtcp2_cc_cubic_cc_event(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat, - ngtcp2_cc_event_type event, ngtcp2_tstamp ts) { - ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb); - ngtcp2_tstamp last_ts; - - if (event != NGTCP2_CC_EVENT_TYPE_TX_START || cc->epoch_start == UINT64_MAX) { - return; - } - - last_ts = cstat->last_tx_pkt_ts[NGTCP2_PKTNS_ID_APP]; - if (last_ts == UINT64_MAX || last_ts <= cc->epoch_start) { - return; - } - - assert(ts >= last_ts); - - cc->epoch_start += ts - last_ts; -} diff --git a/deps/ngtcp2/lib/ngtcp2_cc.h b/deps/ngtcp2/lib/ngtcp2_cc.h deleted file mode 100644 index 05010d57251c39..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_cc.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_CC_H -#define NGTCP2_CC_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#define NGTCP2_LOSS_REDUCTION_FACTOR_BITS 1 -#define NGTCP2_PERSISTENT_CONGESTION_THRESHOLD 3 - -struct ngtcp2_log; -typedef struct ngtcp2_log ngtcp2_log; - -/* - * ngtcp2_cc_compute_initcwnd computes initial cwnd. - */ -uint64_t ngtcp2_cc_compute_initcwnd(size_t max_packet_size); - -ngtcp2_cc_pkt *ngtcp2_cc_pkt_init(ngtcp2_cc_pkt *pkt, int64_t pkt_num, - size_t pktlen, ngtcp2_pktns_id pktns_id, - ngtcp2_tstamp ts_sent); - -/* ngtcp2_reno_cc is the RENO congestion controller. */ -struct ngtcp2_reno_cc { - ngtcp2_cc_base ccb; - uint64_t max_delivery_rate_sec; - uint64_t target_cwnd; -}; - -typedef struct ngtcp2_reno_cc ngtcp2_reno_cc; - -int ngtcp2_cc_reno_cc_init(ngtcp2_cc *cc, ngtcp2_log *log, - const ngtcp2_mem *mem); - -void ngtcp2_cc_reno_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem); - -void ngtcp2_reno_cc_init(ngtcp2_reno_cc *cc, ngtcp2_log *log); - -void ngtcp2_reno_cc_free(ngtcp2_reno_cc *cc); - -void ngtcp2_cc_reno_cc_on_pkt_acked(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - const ngtcp2_cc_pkt *pkt, ngtcp2_tstamp ts); - -void ngtcp2_cc_reno_cc_congestion_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts_sent, - ngtcp2_tstamp ts); - -void ngtcp2_cc_reno_cc_on_persistent_congestion(ngtcp2_cc *cc, - ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts); - -void ngtcp2_cc_reno_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts); - -void ngtcp2_cc_reno_cc_reset(ngtcp2_cc *cc); - -/* ngtcp2_cubic_cc is CUBIC congestion controller. */ -typedef struct ngtcp2_cubic_cc { - ngtcp2_cc_base ccb; - uint64_t max_delivery_rate_sec; - uint64_t target_cwnd; - uint64_t w_last_max; - uint64_t w_tcp; - uint64_t origin_point; - ngtcp2_tstamp epoch_start; - uint64_t k; - /* HyStart++ variables */ - size_t rtt_sample_count; - uint64_t current_round_min_rtt; - uint64_t last_round_min_rtt; - int64_t window_end; - uint64_t pending_add; - uint64_t pending_w_add; -} ngtcp2_cubic_cc; - -int ngtcp2_cc_cubic_cc_init(ngtcp2_cc *cc, ngtcp2_log *log, - const ngtcp2_mem *mem); - -void ngtcp2_cc_cubic_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem); - -void ngtcp2_cubic_cc_init(ngtcp2_cubic_cc *cc, ngtcp2_log *log); - -void ngtcp2_cubic_cc_free(ngtcp2_cubic_cc *cc); - -void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - const ngtcp2_cc_pkt *pkt, - ngtcp2_tstamp ts); - -void ngtcp2_cc_cubic_cc_congestion_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts_sent, - ngtcp2_tstamp ts); - -void ngtcp2_cc_cubic_cc_on_persistent_congestion(ngtcp2_cc *cc, - ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts); - -void ngtcp2_cc_cubic_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts); - -void ngtcp2_cc_cubic_cc_on_pkt_sent(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - const ngtcp2_cc_pkt *pkt); - -void ngtcp2_cc_cubic_cc_new_rtt_sample(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - ngtcp2_tstamp ts); - -void ngtcp2_cc_cubic_cc_reset(ngtcp2_cc *cc); - -void ngtcp2_cc_cubic_cc_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, - ngtcp2_cc_event_type event, ngtcp2_tstamp ts); - -#endif /* NGTCP2_CC_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_cid.c b/deps/ngtcp2/lib/ngtcp2_cid.c deleted file mode 100644 index 126e3c4a512e80..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_cid.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_cid.h" - -#include -#include - -#include "ngtcp2_path.h" -#include "ngtcp2_str.h" - -void ngtcp2_cid_zero(ngtcp2_cid *cid) { cid->datalen = 0; } - -void ngtcp2_cid_init(ngtcp2_cid *cid, const uint8_t *data, size_t datalen) { - assert(datalen <= NGTCP2_MAX_CIDLEN); - - cid->datalen = datalen; - if (datalen) { - ngtcp2_cpymem(cid->data, data, datalen); - } -} - -int ngtcp2_cid_eq(const ngtcp2_cid *cid, const ngtcp2_cid *other) { - return cid->datalen == other->datalen && - 0 == memcmp(cid->data, other->data, cid->datalen); -} - -int ngtcp2_cid_less(const ngtcp2_cid *lhs, const ngtcp2_cid *rhs) { - int s = lhs->datalen < rhs->datalen; - size_t n = s ? lhs->datalen : rhs->datalen; - int c = memcmp(lhs->data, rhs->data, n); - - return c < 0 || (c == 0 && s); -} - -int ngtcp2_cid_empty(const ngtcp2_cid *cid) { return cid->datalen == 0; } - -void ngtcp2_scid_init(ngtcp2_scid *scid, uint64_t seq, const ngtcp2_cid *cid, - const uint8_t *token) { - scid->pe.index = NGTCP2_PQ_BAD_INDEX; - scid->seq = seq; - scid->cid = *cid; - scid->ts_retired = UINT64_MAX; - scid->flags = NGTCP2_SCID_FLAG_NONE; - if (token) { - memcpy(scid->token, token, NGTCP2_STATELESS_RESET_TOKENLEN); - } else { - memset(scid->token, 0, NGTCP2_STATELESS_RESET_TOKENLEN); - } -} - -void ngtcp2_scid_copy(ngtcp2_scid *dest, const ngtcp2_scid *src) { - ngtcp2_scid_init(dest, src->seq, &src->cid, src->token); - dest->ts_retired = src->ts_retired; - dest->flags = src->flags; -} - -void ngtcp2_dcid_init(ngtcp2_dcid *dcid, uint64_t seq, const ngtcp2_cid *cid, - const uint8_t *token) { - dcid->seq = seq; - dcid->cid = *cid; - if (token) { - memcpy(dcid->token, token, NGTCP2_STATELESS_RESET_TOKENLEN); - } else { - memset(dcid->token, 0, NGTCP2_STATELESS_RESET_TOKENLEN); - } - ngtcp2_path_storage_zero(&dcid->ps); - dcid->ts_retired = UINT64_MAX; -} - -void ngtcp2_dcid_copy(ngtcp2_dcid *dest, const ngtcp2_dcid *src) { - ngtcp2_dcid_init(dest, src->seq, &src->cid, src->token); - ngtcp2_path_copy(&dest->ps.path, &src->ps.path); - dest->ts_retired = src->ts_retired; -} - -void ngtcp2_dcid_copy_no_path(ngtcp2_dcid *dest, const ngtcp2_dcid *src) { - dest->seq = src->seq; - dest->cid = src->cid; - memcpy(dest->token, src->token, NGTCP2_STATELESS_RESET_TOKENLEN); - - dest->ts_retired = src->ts_retired; -} - -int ngtcp2_dcid_verify_uniqueness(ngtcp2_dcid *dcid, uint64_t seq, - const ngtcp2_cid *cid, const uint8_t *token) { - if (dcid->seq == seq) { - return ngtcp2_cid_eq(&dcid->cid, cid) && - memcmp(dcid->token, token, - NGTCP2_STATELESS_RESET_TOKENLEN) == 0 - ? 0 - : NGTCP2_ERR_PROTO; - } - - return !ngtcp2_cid_eq(&dcid->cid, cid) ? 0 : NGTCP2_ERR_PROTO; -} diff --git a/deps/ngtcp2/lib/ngtcp2_cid.h b/deps/ngtcp2/lib/ngtcp2_cid.h deleted file mode 100644 index fe5576ae468efa..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_cid.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_CID_H -#define NGTCP2_CID_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_pq.h" -#include "ngtcp2_path.h" - -typedef enum { - NGTCP2_SCID_FLAG_NONE, - NGTCP2_SCID_FLAG_USED = 0x01, - NGTCP2_SCID_FLAG_RETIRED = 0x02, -} ngtcp2_scid_flag; - -typedef struct { - ngtcp2_pq_entry pe; - /* seq is the sequence number associated to the CID. */ - uint64_t seq; - /* cid is a connection ID */ - ngtcp2_cid cid; - /* ts_retired is the timestamp when peer tells that this CID is - retired. */ - ngtcp2_tstamp ts_retired; - /* flags is the bitwise OR of zero or more of ngtcp2_scid_flag. */ - uint8_t flags; - /* token is a stateless reset token associated to this CID. - Actually, the stateless reset token is tied to the connection, - not to the particular connection ID. */ - uint8_t token[NGTCP2_STATELESS_RESET_TOKENLEN]; -} ngtcp2_scid; - -typedef struct { - /* seq is the sequence number associated to the CID. */ - uint64_t seq; - /* cid is a connection ID */ - ngtcp2_cid cid; - /* path is a path which cid is bound to. The addresses are zero - length if cid has not been bound to a particular path yet. */ - ngtcp2_path_storage ps; - /* ts_retired is the timestamp when peer tells that this CID is - retired. */ - ngtcp2_tstamp ts_retired; - /* token is a stateless reset token associated to this CID. - Actually, the stateless reset token is tied to the connection, - not to the particular connection ID. */ - uint8_t token[NGTCP2_STATELESS_RESET_TOKENLEN]; -} ngtcp2_dcid; - -/* ngtcp2_cid_zero makes |cid| zero-length. */ -void ngtcp2_cid_zero(ngtcp2_cid *cid); - -/* - * ngtcp2_cid_eq returns nonzero if |cid| and |other| share the same - * connection ID. - */ -int ngtcp2_cid_eq(const ngtcp2_cid *cid, const ngtcp2_cid *other); - -/* - * ngtcp2_cid_less returns nonzero if |lhs| is lexicographical smaller - * than |rhs|. - */ -int ngtcp2_cid_less(const ngtcp2_cid *lhs, const ngtcp2_cid *rhs); - -/* - * ngtcp2_cid_empty returns nonzero if |cid| includes empty connection - * ID. - */ -int ngtcp2_cid_empty(const ngtcp2_cid *cid); - -/* - * ngtcp2_scid_init initializes |scid| with the given parameters. If - * |token| is NULL, the function fills scid->token it with 0. |token| - * must be NGTCP2_STATELESS_RESET_TOKENLEN bytes long. - */ -void ngtcp2_scid_init(ngtcp2_scid *scid, uint64_t seq, const ngtcp2_cid *cid, - const uint8_t *token); - -/* - * ngtcp2_scid_copy copies |src| into |dest|. - */ -void ngtcp2_scid_copy(ngtcp2_scid *dest, const ngtcp2_scid *src); - -/* - * ngtcp2_dcid_init initializes |dcid| with the given parameters. If - * |token| is NULL, the function fills dcid->token it with 0. |token| - * must be NGTCP2_STATELESS_RESET_TOKENLEN bytes long. - */ -void ngtcp2_dcid_init(ngtcp2_dcid *dcid, uint64_t seq, const ngtcp2_cid *cid, - const uint8_t *token); - -/* - * ngtcp2_dcid_copy copies |src| into |dest|. - */ -void ngtcp2_dcid_copy(ngtcp2_dcid *dest, const ngtcp2_dcid *src); - -/* - * ngtcp2_dcid_copy_no_path behaves like ngtcp2_dcid_copy, but it does - * not copy path. - */ -void ngtcp2_dcid_copy_no_path(ngtcp2_dcid *dest, const ngtcp2_dcid *src); - -/* - * ngtcp2_dcid_verify_uniqueness verifies uniqueness of (|seq|, |cid|, - * |token|) tuple against |dcid|. - */ -int ngtcp2_dcid_verify_uniqueness(ngtcp2_dcid *dcid, uint64_t seq, - const ngtcp2_cid *cid, const uint8_t *token); - -#endif /* NGTCP2_CID_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_conn.c b/deps/ngtcp2/lib/ngtcp2_conn.c deleted file mode 100644 index ff8c608b776dac..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_conn.c +++ /dev/null @@ -1,10100 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_conn.h" - -#include -#include -#include - -#include "ngtcp2_macro.h" -#include "ngtcp2_log.h" -#include "ngtcp2_cid.h" -#include "ngtcp2_conv.h" -#include "ngtcp2_vec.h" -#include "ngtcp2_addr.h" -#include "ngtcp2_path.h" -#include "ngtcp2_rcvry.h" - -/* - * conn_local_stream returns nonzero if |stream_id| indicates that it - * is the stream initiated by local endpoint. - */ -static int conn_local_stream(ngtcp2_conn *conn, int64_t stream_id) { - return (uint8_t)(stream_id & 1) == conn->server; -} - -/* - * bidi_stream returns nonzero if |stream_id| is a bidirectional - * stream ID. - */ -static int bidi_stream(int64_t stream_id) { return (stream_id & 0x2) == 0; } - -static int conn_call_recv_client_initial(ngtcp2_conn *conn, - const ngtcp2_cid *dcid) { - int rv; - - assert(conn->callbacks.recv_client_initial); - - rv = conn->callbacks.recv_client_initial(conn, dcid, conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_handshake_completed(ngtcp2_conn *conn) { - int rv; - - if (!conn->callbacks.handshake_completed) { - return 0; - } - - rv = conn->callbacks.handshake_completed(conn, conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_recv_stream_data(ngtcp2_conn *conn, ngtcp2_strm *strm, - uint32_t flags, uint64_t offset, - const uint8_t *data, size_t datalen) { - int rv; - - if (!conn->callbacks.recv_stream_data) { - return 0; - } - - rv = conn->callbacks.recv_stream_data(conn, flags, strm->stream_id, offset, - data, datalen, conn->user_data, - strm->stream_user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_recv_crypto_data(ngtcp2_conn *conn, - ngtcp2_crypto_level crypto_level, - uint64_t offset, const uint8_t *data, - size_t datalen) { - int rv; - - assert(conn->callbacks.recv_crypto_data); - - rv = conn->callbacks.recv_crypto_data(conn, crypto_level, offset, data, - datalen, conn->user_data); - switch (rv) { - case 0: - case NGTCP2_ERR_CRYPTO: - case NGTCP2_ERR_REQUIRED_TRANSPORT_PARAM: - case NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM: - case NGTCP2_ERR_TRANSPORT_PARAM: - case NGTCP2_ERR_PROTO: - case NGTCP2_ERR_CALLBACK_FAILURE: - return rv; - default: - return NGTCP2_ERR_CALLBACK_FAILURE; - } -} - -static int conn_call_stream_open(ngtcp2_conn *conn, ngtcp2_strm *strm) { - int rv; - - if (!conn->callbacks.stream_open) { - return 0; - } - - rv = conn->callbacks.stream_open(conn, strm->stream_id, conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_stream_close(ngtcp2_conn *conn, ngtcp2_strm *strm, - uint64_t app_error_code) { - int rv; - - if (!conn->callbacks.stream_close) { - return 0; - } - - rv = conn->callbacks.stream_close(conn, strm->stream_id, app_error_code, - conn->user_data, strm->stream_user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_stream_reset(ngtcp2_conn *conn, int64_t stream_id, - uint64_t final_size, uint64_t app_error_code, - void *stream_user_data) { - int rv; - - if (!conn->callbacks.stream_reset) { - return 0; - } - - rv = conn->callbacks.stream_reset(conn, stream_id, final_size, app_error_code, - conn->user_data, stream_user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_extend_max_local_streams_bidi(ngtcp2_conn *conn, - uint64_t max_streams) { - int rv; - - if (!conn->callbacks.extend_max_local_streams_bidi) { - return 0; - } - - rv = conn->callbacks.extend_max_local_streams_bidi(conn, max_streams, - conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_extend_max_local_streams_uni(ngtcp2_conn *conn, - uint64_t max_streams) { - int rv; - - if (!conn->callbacks.extend_max_local_streams_uni) { - return 0; - } - - rv = conn->callbacks.extend_max_local_streams_uni(conn, max_streams, - conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_get_new_connection_id(ngtcp2_conn *conn, ngtcp2_cid *cid, - uint8_t *token, size_t cidlen) { - int rv; - - assert(conn->callbacks.get_new_connection_id); - - rv = conn->callbacks.get_new_connection_id(conn, cid, token, cidlen, - conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_remove_connection_id(ngtcp2_conn *conn, - const ngtcp2_cid *cid) { - int rv; - - if (!conn->callbacks.remove_connection_id) { - return 0; - } - - rv = conn->callbacks.remove_connection_id(conn, cid, conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_path_validation(ngtcp2_conn *conn, const ngtcp2_path *path, - ngtcp2_path_validation_result res) { - int rv; - - if (!conn->callbacks.path_validation) { - return 0; - } - - rv = conn->callbacks.path_validation(conn, path, res, conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_select_preferred_addr(ngtcp2_conn *conn, - ngtcp2_addr *dest) { - int rv; - - if (!conn->callbacks.select_preferred_addr) { - return 0; - } - - assert(conn->remote.transport_params.preferred_address_present); - - rv = conn->callbacks.select_preferred_addr( - conn, dest, &conn->remote.transport_params.preferred_address, - conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_extend_max_remote_streams_bidi(ngtcp2_conn *conn, - uint64_t max_streams) { - int rv; - - if (!conn->callbacks.extend_max_remote_streams_bidi) { - return 0; - } - - rv = conn->callbacks.extend_max_remote_streams_bidi(conn, max_streams, - conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_extend_max_remote_streams_uni(ngtcp2_conn *conn, - uint64_t max_streams) { - int rv; - - if (!conn->callbacks.extend_max_remote_streams_uni) { - return 0; - } - - rv = conn->callbacks.extend_max_remote_streams_uni(conn, max_streams, - conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_extend_max_stream_data(ngtcp2_conn *conn, - ngtcp2_strm *strm, - int64_t stream_id, - uint64_t datalen) { - int rv; - - if (!conn->callbacks.extend_max_stream_data) { - return 0; - } - - rv = conn->callbacks.extend_max_stream_data( - conn, stream_id, datalen, conn->user_data, strm->stream_user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_dcid_status(ngtcp2_conn *conn, - ngtcp2_connection_id_status_type type, - const ngtcp2_dcid *dcid) { - int rv; - - if (!conn->callbacks.dcid_status) { - return 0; - } - - rv = conn->callbacks.dcid_status( - conn, (int)type, dcid->seq, &dcid->cid, - ngtcp2_check_invalid_stateless_reset_token(dcid->token) ? NULL - : dcid->token, - conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -static int conn_call_activate_dcid(ngtcp2_conn *conn, const ngtcp2_dcid *dcid) { - return conn_call_dcid_status(conn, NGTCP2_CONNECTION_ID_STATUS_TYPE_ACTIVATE, - dcid); -} - -static int conn_call_deactivate_dcid(ngtcp2_conn *conn, - const ngtcp2_dcid *dcid) { - return conn_call_dcid_status( - conn, NGTCP2_CONNECTION_ID_STATUS_TYPE_DEACTIVATE, dcid); -} - -static void conn_call_delete_crypto_aead_ctx(ngtcp2_conn *conn, - ngtcp2_crypto_aead_ctx *aead_ctx) { - if (!aead_ctx->native_handle) { - return; - } - - assert(conn->callbacks.delete_crypto_aead_ctx); - - conn->callbacks.delete_crypto_aead_ctx(conn, aead_ctx, conn->user_data); -} - -static void -conn_call_delete_crypto_cipher_ctx(ngtcp2_conn *conn, - ngtcp2_crypto_cipher_ctx *cipher_ctx) { - if (!cipher_ctx->native_handle) { - return; - } - - assert(conn->callbacks.delete_crypto_cipher_ctx); - - conn->callbacks.delete_crypto_cipher_ctx(conn, cipher_ctx, conn->user_data); -} - -static int crypto_offset_less(const ngtcp2_ksl_key *lhs, - const ngtcp2_ksl_key *rhs) { - return *(int64_t *)lhs < *(int64_t *)rhs; -} - -static int pktns_init(ngtcp2_pktns *pktns, ngtcp2_pktns_id pktns_id, - ngtcp2_rst *rst, ngtcp2_cc *cc, ngtcp2_log *log, - ngtcp2_qlog *qlog, const ngtcp2_mem *mem) { - int rv; - - memset(pktns, 0, sizeof(*pktns)); - - rv = ngtcp2_gaptr_init(&pktns->rx.pngap, mem); - if (rv != 0) { - return rv; - } - - pktns->tx.last_pkt_num = -1; - pktns->rx.max_pkt_num = -1; - - rv = ngtcp2_acktr_init(&pktns->acktr, log, mem); - if (rv != 0) { - goto fail_acktr_init; - } - - rv = ngtcp2_strm_init(&pktns->crypto.strm, 0, NGTCP2_STRM_FLAG_NONE, 0, 0, - NULL, mem); - if (rv != 0) { - goto fail_crypto_init; - } - - rv = ngtcp2_ksl_init(&pktns->crypto.tx.frq, crypto_offset_less, - sizeof(uint64_t), mem); - if (rv != 0) { - goto fail_tx_frq_init; - } - - ngtcp2_rtb_init(&pktns->rtb, pktns_id, &pktns->crypto.strm, rst, cc, log, - qlog, mem); - - return 0; - -fail_tx_frq_init: - ngtcp2_strm_free(&pktns->crypto.strm); -fail_crypto_init: - ngtcp2_acktr_free(&pktns->acktr); -fail_acktr_init: - ngtcp2_gaptr_free(&pktns->rx.pngap); - - return rv; -} - -static int pktns_new(ngtcp2_pktns **ppktns, ngtcp2_pktns_id pktns_id, - ngtcp2_rst *rst, ngtcp2_cc *cc, ngtcp2_log *log, - ngtcp2_qlog *qlog, const ngtcp2_mem *mem) { - int rv; - - *ppktns = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_pktns)); - if (*ppktns == NULL) { - return NGTCP2_ERR_NOMEM; - } - - rv = pktns_init(*ppktns, pktns_id, rst, cc, log, qlog, mem); - if (rv != 0) { - ngtcp2_mem_free(mem, *ppktns); - } - - return rv; -} - -static int cycle_less(const ngtcp2_pq_entry *lhs, const ngtcp2_pq_entry *rhs) { - ngtcp2_strm *ls = ngtcp2_struct_of(lhs, ngtcp2_strm, pe); - ngtcp2_strm *rs = ngtcp2_struct_of(rhs, ngtcp2_strm, pe); - - if (ls->cycle == rs->cycle) { - return ls->stream_id < rs->stream_id; - } - - return rs->cycle - ls->cycle <= 1; -} - -static void delete_buffed_pkts(ngtcp2_pkt_chain *pc, const ngtcp2_mem *mem) { - ngtcp2_pkt_chain *next; - - for (; pc;) { - next = pc->next; - ngtcp2_pkt_chain_del(pc, mem); - pc = next; - } -} - -static void pktns_free(ngtcp2_pktns *pktns, const ngtcp2_mem *mem) { - ngtcp2_frame_chain *frc; - ngtcp2_ksl_it it; - - delete_buffed_pkts(pktns->rx.buffed_pkts, mem); - - ngtcp2_frame_chain_list_del(pktns->tx.frq, mem); - - ngtcp2_crypto_km_del(pktns->crypto.rx.ckm, mem); - ngtcp2_crypto_km_del(pktns->crypto.tx.ckm, mem); - - for (it = ngtcp2_ksl_begin(&pktns->crypto.tx.frq); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - frc = ngtcp2_ksl_it_get(&it); - ngtcp2_frame_chain_del(frc, mem); - } - - ngtcp2_ksl_free(&pktns->crypto.tx.frq); - ngtcp2_rtb_free(&pktns->rtb); - ngtcp2_strm_free(&pktns->crypto.strm); - ngtcp2_acktr_free(&pktns->acktr); - ngtcp2_gaptr_free(&pktns->rx.pngap); -} - -static void pktns_del(ngtcp2_pktns *pktns, const ngtcp2_mem *mem) { - if (pktns == NULL) { - return; - } - - pktns_free(pktns, mem); - - ngtcp2_mem_free(mem, pktns); -} - -static void cc_del(ngtcp2_cc *cc, ngtcp2_cc_algo cc_algo, - const ngtcp2_mem *mem) { - switch (cc_algo) { - case NGTCP2_CC_ALGO_RENO: - ngtcp2_cc_reno_cc_free(cc, mem); - break; - case NGTCP2_CC_ALGO_CUBIC: - ngtcp2_cc_cubic_cc_free(cc, mem); - break; - default: - break; - } -} - -static int cid_less(const ngtcp2_ksl_key *lhs, const ngtcp2_ksl_key *rhs) { - return ngtcp2_cid_less(lhs, rhs); -} - -static int ts_retired_less(const ngtcp2_pq_entry *lhs, - const ngtcp2_pq_entry *rhs) { - const ngtcp2_scid *a = ngtcp2_struct_of(lhs, ngtcp2_scid, pe); - const ngtcp2_scid *b = ngtcp2_struct_of(rhs, ngtcp2_scid, pe); - - return a->ts_retired < b->ts_retired; -} - -/* - * conn_reset_conn_stat_cc resets congestion state in |cstat|. - */ -static void conn_reset_conn_stat_cc(ngtcp2_conn *conn, - ngtcp2_conn_stat *cstat) { - cstat->latest_rtt = 0; - cstat->min_rtt = UINT64_MAX; - cstat->smoothed_rtt = conn->local.settings.initial_rtt; - cstat->rttvar = conn->local.settings.initial_rtt / 2; - cstat->pto_count = 0; - cstat->loss_detection_timer = 0; - cstat->cwnd = - ngtcp2_cc_compute_initcwnd(conn->local.settings.max_udp_payload_size); - cstat->ssthresh = UINT64_MAX; - cstat->congestion_recovery_start_ts = 0; - cstat->bytes_in_flight = 0; - cstat->delivery_rate_sec = 0; - cstat->recv_rate_sec = 0; -} - -/* - * reset_conn_stat_recovery resets the fields related to the recovery - * function - */ -static void reset_conn_stat_recovery(ngtcp2_conn_stat *cstat) { - // Initializes them with UINT64_MAX. - memset(cstat->loss_time, 0xff, sizeof(cstat->loss_time)); - memset(cstat->last_tx_pkt_ts, 0xff, sizeof(cstat->last_tx_pkt_ts)); -} - -/* - * conn_reset_conn_stat resets |cstat|. The following fields are not - * reset: initial_rtt, max_udp_payload_size, bytes_sent, and - * bytes_recv. - */ -static void conn_reset_conn_stat(ngtcp2_conn *conn, ngtcp2_conn_stat *cstat) { - conn_reset_conn_stat_cc(conn, cstat); - reset_conn_stat_recovery(cstat); -} - -static void conn_reset_rx_rate(ngtcp2_conn *conn) { - conn->rx.rate.start_ts = UINT64_MAX; - conn->rx.rate.received = 0; -} - -static void conn_update_recv_rate(ngtcp2_conn *conn, size_t datalen, - ngtcp2_tstamp ts) { - uint64_t bps; - ngtcp2_duration window; - - conn->rx.rate.received += datalen; - - if (conn->rx.rate.start_ts == UINT64_MAX) { - conn->rx.rate.start_ts = ts; - return; - } - - assert(conn->cstat.min_rtt); - - window = conn->cstat.min_rtt == UINT64_MAX ? conn->cstat.initial_rtt - : conn->cstat.min_rtt * 2; - - /* If settings.initial_rtt is zero for whatever reason then window - can be zero and we can end up with a division by zero error when - bps is set below. If this assert fails, check that - settings.initial_rtt is not zero. */ - assert(window); - - if (window > ts - conn->rx.rate.start_ts) { - return; - } - - bps = conn->rx.rate.received * NGTCP2_SECONDS / (ts - conn->rx.rate.start_ts); - - if (conn->cstat.recv_rate_sec == 0) { - conn->cstat.recv_rate_sec = bps; - } else { - conn->cstat.recv_rate_sec = (conn->cstat.recv_rate_sec * 3 + bps) / 4; - } - - conn_reset_rx_rate(conn); - - if (conn->cstat.min_rtt != UINT64_MAX) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, - "recv_rate_sec=%" PRIu64 " bytes/min_rtt=%" PRIu64, - conn->cstat.recv_rate_sec, - conn->cstat.recv_rate_sec * conn->cstat.min_rtt / - NGTCP2_SECONDS); - } -} - -static void delete_scid(ngtcp2_ksl *scids, const ngtcp2_mem *mem) { - ngtcp2_ksl_it it; - - for (it = ngtcp2_ksl_begin(scids); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - ngtcp2_mem_free(mem, ngtcp2_ksl_it_get(&it)); - } -} - -static int conn_new(ngtcp2_conn **pconn, const ngtcp2_cid *dcid, - const ngtcp2_cid *scid, const ngtcp2_path *path, - uint32_t version, const ngtcp2_conn_callbacks *callbacks, - const ngtcp2_settings *settings, const ngtcp2_mem *mem, - void *user_data, int server) { - int rv; - ngtcp2_scid *scident; - const ngtcp2_transport_params *params = &settings->transport_params; - uint8_t *buf; - - assert(params->active_connection_id_limit <= NGTCP2_MAX_DCID_POOL_SIZE); - - if (mem == NULL) { - mem = ngtcp2_mem_default(); - } - - *pconn = ngtcp2_mem_calloc(mem, 1, sizeof(ngtcp2_conn)); - if (*pconn == NULL) { - rv = NGTCP2_ERR_NOMEM; - goto fail_conn; - } - - rv = ngtcp2_ringbuf_init(&(*pconn)->dcid.unused, NGTCP2_MAX_DCID_POOL_SIZE, - sizeof(ngtcp2_dcid), mem); - if (rv != 0) { - goto fail_dcid_unused_init; - } - - rv = - ngtcp2_ringbuf_init(&(*pconn)->dcid.retired, NGTCP2_MAX_DCID_RETIRED_SIZE, - sizeof(ngtcp2_dcid), mem); - if (rv != 0) { - goto fail_dcid_retired_init; - } - - rv = ngtcp2_gaptr_init(&(*pconn)->dcid.seqgap, mem); - if (rv != 0) { - goto fail_seqgap_init; - } - - rv = ngtcp2_ksl_init(&(*pconn)->scid.set, cid_less, sizeof(ngtcp2_cid), mem); - if (rv != 0) { - goto fail_scid_set_init; - } - - ngtcp2_pq_init(&(*pconn)->scid.used, ts_retired_less, mem); - - rv = ngtcp2_map_init(&(*pconn)->strms, mem); - if (rv != 0) { - goto fail_strms_init; - } - - ngtcp2_pq_init(&(*pconn)->tx.strmq, cycle_less, mem); - - rv = ngtcp2_idtr_init(&(*pconn)->remote.bidi.idtr, !server, mem); - if (rv != 0) { - goto fail_remote_bidi_idtr_init; - } - - rv = ngtcp2_idtr_init(&(*pconn)->remote.uni.idtr, !server, mem); - if (rv != 0) { - goto fail_remote_uni_idtr_init; - } - - rv = ngtcp2_ringbuf_init(&(*pconn)->rx.path_challenge, 4, - sizeof(ngtcp2_path_challenge_entry), mem); - if (rv != 0) { - goto fail_rx_path_challenge_init; - } - - ngtcp2_log_init(&(*pconn)->log, scid, settings->log_printf, - settings->initial_ts, user_data); - ngtcp2_qlog_init(&(*pconn)->qlog, settings->qlog.write, settings->initial_ts, - user_data); - if ((*pconn)->qlog.write) { - buf = ngtcp2_mem_malloc(mem, NGTCP2_QLOG_BUFLEN); - if (buf == NULL) { - goto fail_qlog_buf; - } - ngtcp2_buf_init(&(*pconn)->qlog.buf, buf, NGTCP2_QLOG_BUFLEN); - } - - (*pconn)->local.settings = *settings; - - if (settings->token.len) { - buf = ngtcp2_mem_malloc(mem, settings->token.len); - if (buf == NULL) { - goto fail_token; - } - memcpy(buf, settings->token.base, settings->token.len); - (*pconn)->local.settings.token.base = buf; - } else { - (*pconn)->local.settings.token.base = NULL; - (*pconn)->local.settings.token.len = 0; - } - - if (settings->max_udp_payload_size == 0) { - (*pconn)->local.settings.max_udp_payload_size = NGTCP2_DEFAULT_MAX_PKTLEN; - } - - conn_reset_conn_stat(*pconn, &(*pconn)->cstat); - (*pconn)->cstat.initial_rtt = settings->initial_rtt; - (*pconn)->cstat.max_udp_payload_size = - (*pconn)->local.settings.max_udp_payload_size; - - ngtcp2_rst_init(&(*pconn)->rst); - - (*pconn)->cc_algo = settings->cc_algo; - - switch (settings->cc_algo) { - case NGTCP2_CC_ALGO_RENO: - rv = ngtcp2_cc_reno_cc_init(&(*pconn)->cc, &(*pconn)->log, mem); - if (rv != 0) { - goto fail_cc_init; - } - break; - case NGTCP2_CC_ALGO_CUBIC: - rv = ngtcp2_cc_cubic_cc_init(&(*pconn)->cc, &(*pconn)->log, mem); - if (rv != 0) { - goto fail_cc_init; - } - break; - case NGTCP2_CC_ALGO_CUSTOM: - assert(settings->cc); - (*pconn)->cc = *settings->cc; - (*pconn)->cc.ccb->log = &(*pconn)->log; - break; - default: - assert(0); - } - - conn_reset_rx_rate(*pconn); - - rv = pktns_new(&(*pconn)->in_pktns, NGTCP2_PKTNS_ID_INITIAL, &(*pconn)->rst, - &(*pconn)->cc, &(*pconn)->log, &(*pconn)->qlog, mem); - if (rv != 0) { - goto fail_in_pktns_init; - } - - rv = pktns_new(&(*pconn)->hs_pktns, NGTCP2_PKTNS_ID_HANDSHAKE, &(*pconn)->rst, - &(*pconn)->cc, &(*pconn)->log, &(*pconn)->qlog, mem); - if (rv != 0) { - goto fail_hs_pktns_init; - } - - rv = pktns_init(&(*pconn)->pktns, NGTCP2_PKTNS_ID_APP, &(*pconn)->rst, - &(*pconn)->cc, &(*pconn)->log, &(*pconn)->qlog, mem); - if (rv != 0) { - goto fail_pktns_init; - } - - scident = ngtcp2_mem_malloc(mem, sizeof(*scident)); - if (scident == NULL) { - rv = NGTCP2_ERR_NOMEM; - goto fail_scident; - } - - /* Set stateless reset token later if it is available in the local - transport parameters */ - ngtcp2_scid_init(scident, 0, scid, NULL); - - rv = ngtcp2_ksl_insert(&(*pconn)->scid.set, NULL, &scident->cid, scident); - if (rv != 0) { - goto fail_scid_set_insert; - } - - scident = NULL; - - ngtcp2_dcid_init(&(*pconn)->dcid.current, 0, dcid, NULL); - ngtcp2_path_copy(&(*pconn)->dcid.current.ps.path, path); - - rv = ngtcp2_gaptr_push(&(*pconn)->dcid.seqgap, 0, 1); - if (rv != 0) { - goto fail_seqgap_push; - } - - (*pconn)->server = server; - (*pconn)->oscid = *scid; - (*pconn)->callbacks = *callbacks; - (*pconn)->version = version; - (*pconn)->mem = mem; - (*pconn)->user_data = user_data; - (*pconn)->idle_ts = settings->initial_ts; - (*pconn)->crypto.key_update.confirmed_ts = UINT64_MAX; - - ngtcp2_qlog_start(&(*pconn)->qlog, server ? &settings->qlog.odcid : dcid, - server); - - return 0; - -fail_seqgap_push: -fail_scid_set_insert: - ngtcp2_mem_free(mem, scident); -fail_scident: - ngtcp2_mem_free(mem, (*pconn)->local.settings.token.base); -fail_token: - pktns_free(&(*pconn)->pktns, mem); -fail_pktns_init: - pktns_del((*pconn)->hs_pktns, mem); -fail_hs_pktns_init: - pktns_del((*pconn)->in_pktns, mem); -fail_in_pktns_init: - cc_del(&(*pconn)->cc, settings->cc_algo, mem); -fail_cc_init: - ngtcp2_mem_free(mem, (*pconn)->qlog.buf.begin); -fail_qlog_buf: - ngtcp2_ringbuf_free(&(*pconn)->rx.path_challenge); -fail_rx_path_challenge_init: - ngtcp2_idtr_free(&(*pconn)->remote.uni.idtr); -fail_remote_uni_idtr_init: - ngtcp2_idtr_free(&(*pconn)->remote.bidi.idtr); -fail_remote_bidi_idtr_init: - ngtcp2_map_free(&(*pconn)->strms); -fail_strms_init: - delete_scid(&(*pconn)->scid.set, mem); - ngtcp2_ksl_free(&(*pconn)->scid.set); -fail_scid_set_init: - ngtcp2_gaptr_free(&(*pconn)->dcid.seqgap); -fail_seqgap_init: - ngtcp2_ringbuf_free(&(*pconn)->dcid.retired); -fail_dcid_retired_init: - ngtcp2_ringbuf_free(&(*pconn)->dcid.unused); -fail_dcid_unused_init: - ngtcp2_mem_free(mem, *pconn); -fail_conn: - return rv; -} - -int ngtcp2_conn_client_new(ngtcp2_conn **pconn, const ngtcp2_cid *dcid, - const ngtcp2_cid *scid, const ngtcp2_path *path, - uint32_t version, - const ngtcp2_conn_callbacks *callbacks, - const ngtcp2_settings *settings, - const ngtcp2_mem *mem, void *user_data) { - int rv; - rv = conn_new(pconn, dcid, scid, path, version, callbacks, settings, mem, - user_data, 0); - if (rv != 0) { - return rv; - } - (*pconn)->rcid = *dcid; - (*pconn)->state = NGTCP2_CS_CLIENT_INITIAL; - (*pconn)->local.bidi.next_stream_id = 0; - (*pconn)->local.uni.next_stream_id = 2; - - rv = ngtcp2_conn_commit_local_transport_params(*pconn); - if (rv != 0) { - ngtcp2_conn_del(*pconn); - return rv; - } - - ngtcp2_qlog_parameters_set_transport_params( - &(*pconn)->qlog, &(*pconn)->local.settings.transport_params, - (*pconn)->server, NGTCP2_QLOG_SIDE_LOCAL); - - return 0; -} - -int ngtcp2_conn_server_new(ngtcp2_conn **pconn, const ngtcp2_cid *dcid, - const ngtcp2_cid *scid, const ngtcp2_path *path, - uint32_t version, - const ngtcp2_conn_callbacks *callbacks, - const ngtcp2_settings *settings, - const ngtcp2_mem *mem, void *user_data) { - int rv; - rv = conn_new(pconn, dcid, scid, path, version, callbacks, settings, mem, - user_data, 1); - if (rv != 0) { - return rv; - } - (*pconn)->state = NGTCP2_CS_SERVER_INITIAL; - (*pconn)->local.bidi.next_stream_id = 1; - (*pconn)->local.uni.next_stream_id = 3; - - if ((*pconn)->local.settings.token.len) { - /* Usage of token lifts amplification limit */ - (*pconn)->flags |= NGTCP2_CONN_FLAG_SADDR_VERIFIED; - } - - return 0; -} - -/* - * conn_fc_credits returns the number of bytes allowed to be sent to - * the given stream. Both connection and stream level flow control - * credits are considered. - */ -static uint64_t conn_fc_credits(ngtcp2_conn *conn, ngtcp2_strm *strm) { - return ngtcp2_min(strm->tx.max_offset - strm->tx.offset, - conn->tx.max_offset - conn->tx.offset); -} - -/* - * conn_enforce_flow_control returns the number of bytes allowed to be - * sent to the given stream. |len| might be shorted because of - * available flow control credits. - */ -static size_t conn_enforce_flow_control(ngtcp2_conn *conn, ngtcp2_strm *strm, - size_t len) { - uint64_t fc_credits = conn_fc_credits(conn, strm); - return (size_t)ngtcp2_min((uint64_t)len, fc_credits); -} - -static int delete_strms_each(ngtcp2_map_entry *ent, void *ptr) { - const ngtcp2_mem *mem = ptr; - ngtcp2_strm *s = ngtcp2_struct_of(ent, ngtcp2_strm, me); - - ngtcp2_strm_free(s); - ngtcp2_mem_free(mem, s); - - return 0; -} - -void ngtcp2_conn_del(ngtcp2_conn *conn) { - if (conn == NULL) { - return; - } - - ngtcp2_qlog_end(&conn->qlog); - - if (conn->early.ckm) { - conn_call_delete_crypto_aead_ctx(conn, &conn->early.ckm->aead_ctx); - } - conn_call_delete_crypto_cipher_ctx(conn, &conn->early.hp_ctx); - - if (conn->crypto.key_update.old_rx_ckm) { - conn_call_delete_crypto_aead_ctx( - conn, &conn->crypto.key_update.old_rx_ckm->aead_ctx); - } - if (conn->crypto.key_update.new_rx_ckm) { - conn_call_delete_crypto_aead_ctx( - conn, &conn->crypto.key_update.new_rx_ckm->aead_ctx); - } - if (conn->crypto.key_update.new_tx_ckm) { - conn_call_delete_crypto_aead_ctx( - conn, &conn->crypto.key_update.new_tx_ckm->aead_ctx); - } - - if (conn->pktns.crypto.rx.ckm) { - conn_call_delete_crypto_aead_ctx(conn, - &conn->pktns.crypto.rx.ckm->aead_ctx); - } - conn_call_delete_crypto_cipher_ctx(conn, &conn->pktns.crypto.rx.hp_ctx); - - if (conn->pktns.crypto.tx.ckm) { - conn_call_delete_crypto_aead_ctx(conn, - &conn->pktns.crypto.tx.ckm->aead_ctx); - } - conn_call_delete_crypto_cipher_ctx(conn, &conn->pktns.crypto.tx.hp_ctx); - - if (conn->hs_pktns) { - if (conn->hs_pktns->crypto.rx.ckm) { - conn_call_delete_crypto_aead_ctx( - conn, &conn->hs_pktns->crypto.rx.ckm->aead_ctx); - } - conn_call_delete_crypto_cipher_ctx(conn, &conn->hs_pktns->crypto.rx.hp_ctx); - - if (conn->hs_pktns->crypto.tx.ckm) { - conn_call_delete_crypto_aead_ctx( - conn, &conn->hs_pktns->crypto.tx.ckm->aead_ctx); - } - conn_call_delete_crypto_cipher_ctx(conn, &conn->hs_pktns->crypto.tx.hp_ctx); - } - if (conn->in_pktns) { - if (conn->in_pktns->crypto.rx.ckm) { - conn_call_delete_crypto_aead_ctx( - conn, &conn->in_pktns->crypto.rx.ckm->aead_ctx); - } - conn_call_delete_crypto_cipher_ctx(conn, &conn->in_pktns->crypto.rx.hp_ctx); - - if (conn->in_pktns->crypto.tx.ckm) { - conn_call_delete_crypto_aead_ctx( - conn, &conn->in_pktns->crypto.tx.ckm->aead_ctx); - } - conn_call_delete_crypto_cipher_ctx(conn, &conn->in_pktns->crypto.tx.hp_ctx); - } - - conn_call_delete_crypto_aead_ctx(conn, &conn->crypto.retry_aead_ctx); - - ngtcp2_mem_free(conn->mem, conn->crypto.decrypt_buf.base); - ngtcp2_mem_free(conn->mem, conn->local.settings.token.base); - - ngtcp2_crypto_km_del(conn->crypto.key_update.old_rx_ckm, conn->mem); - ngtcp2_crypto_km_del(conn->crypto.key_update.new_rx_ckm, conn->mem); - ngtcp2_crypto_km_del(conn->crypto.key_update.new_tx_ckm, conn->mem); - ngtcp2_crypto_km_del(conn->early.ckm, conn->mem); - - pktns_free(&conn->pktns, conn->mem); - pktns_del(conn->hs_pktns, conn->mem); - pktns_del(conn->in_pktns, conn->mem); - - cc_del(&conn->cc, conn->cc_algo, conn->mem); - - ngtcp2_mem_free(conn->mem, conn->qlog.buf.begin); - - ngtcp2_ringbuf_free(&conn->rx.path_challenge); - - ngtcp2_pv_del(conn->pv); - - ngtcp2_idtr_free(&conn->remote.uni.idtr); - ngtcp2_idtr_free(&conn->remote.bidi.idtr); - ngtcp2_mem_free(conn->mem, conn->tx.ack); - ngtcp2_pq_free(&conn->tx.strmq); - ngtcp2_map_each_free(&conn->strms, delete_strms_each, (void *)conn->mem); - ngtcp2_map_free(&conn->strms); - - ngtcp2_pq_free(&conn->scid.used); - delete_scid(&conn->scid.set, conn->mem); - ngtcp2_ksl_free(&conn->scid.set); - ngtcp2_gaptr_free(&conn->dcid.seqgap); - ngtcp2_ringbuf_free(&conn->dcid.retired); - ngtcp2_ringbuf_free(&conn->dcid.unused); - - ngtcp2_mem_free(conn->mem, conn); -} - -/* - * conn_ensure_ack_blks makes sure that conn->tx.ack->ack.blks can - * contain at least |n| additional ngtcp2_ack_blk. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int conn_ensure_ack_blks(ngtcp2_conn *conn, size_t n) { - ngtcp2_frame *fr; - size_t max = conn->tx.max_ack_blks; - - if (n <= max) { - return 0; - } - - max *= 2; - - assert(max >= n); - - fr = ngtcp2_mem_realloc(conn->mem, conn->tx.ack, - sizeof(ngtcp2_ack) + sizeof(ngtcp2_ack_blk) * max); - if (fr == NULL) { - return NGTCP2_ERR_NOMEM; - } - - conn->tx.ack = fr; - conn->tx.max_ack_blks = max; - - return 0; -} - -/* - * conn_compute_ack_delay computes ACK delay for outgoing protected - * ACK. - */ -static ngtcp2_duration conn_compute_ack_delay(ngtcp2_conn *conn) { - return ngtcp2_min(conn->local.settings.transport_params.max_ack_delay, - conn->cstat.smoothed_rtt / 8); -} - -/* - * conn_create_ack_frame creates ACK frame, and assigns its pointer to - * |*pfr| if there are any received packets to acknowledge. If there - * are no packets to acknowledge, this function returns 0, and |*pfr| - * is untouched. The caller is advised to set |*pfr| to NULL before - * calling this function, and check it after this function returns. - * If |nodelay| is nonzero, delayed ACK timer is ignored. - * - * The memory for ACK frame is dynamically allocated by this function. - * A caller is responsible to free it. - * - * Call ngtcp2_acktr_commit_ack after a created ACK frame is - * successfully serialized into a packet. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int conn_create_ack_frame(ngtcp2_conn *conn, ngtcp2_frame **pfr, - ngtcp2_pktns *pktns, uint8_t type, - ngtcp2_tstamp ts, ngtcp2_duration ack_delay, - uint64_t ack_delay_exponent) { - /* TODO Measure an actual size of ACK blocks to find the best - default value. */ - const size_t initial_max_ack_blks = 8; - int64_t last_pkt_num; - ngtcp2_acktr *acktr = &pktns->acktr; - ngtcp2_ack_blk *blk; - ngtcp2_ksl_it it; - ngtcp2_acktr_entry *rpkt; - ngtcp2_ack *ack; - size_t blk_idx; - ngtcp2_tstamp largest_ack_ts; - int rv; - - if (acktr->flags & NGTCP2_ACKTR_FLAG_IMMEDIATE_ACK) { - ack_delay = 0; - } - - if (!ngtcp2_acktr_require_active_ack(acktr, ack_delay, ts)) { - return 0; - } - - it = ngtcp2_acktr_get(acktr); - if (ngtcp2_ksl_it_end(&it)) { - ngtcp2_acktr_commit_ack(acktr); - return 0; - } - - if (conn->tx.ack == NULL) { - conn->tx.ack = ngtcp2_mem_malloc( - conn->mem, - sizeof(ngtcp2_ack) + sizeof(ngtcp2_ack_blk) * initial_max_ack_blks); - if (conn->tx.ack == NULL) { - return NGTCP2_ERR_NOMEM; - } - conn->tx.max_ack_blks = initial_max_ack_blks; - } - - ack = &conn->tx.ack->ack; - - ack->type = NGTCP2_FRAME_ACK; - ack->num_blks = 0; - - rpkt = ngtcp2_ksl_it_get(&it); - - if (rpkt->pkt_num == pktns->rx.max_pkt_num) { - last_pkt_num = rpkt->pkt_num - (int64_t)(rpkt->len - 1); - largest_ack_ts = rpkt->tstamp; - ack->largest_ack = rpkt->pkt_num; - ack->first_ack_blklen = rpkt->len - 1; - - ngtcp2_ksl_it_next(&it); - } else { - assert(rpkt->pkt_num < pktns->rx.max_pkt_num); - - last_pkt_num = pktns->rx.max_pkt_num; - largest_ack_ts = pktns->rx.max_pkt_ts; - ack->largest_ack = pktns->rx.max_pkt_num; - ack->first_ack_blklen = 0; - } - - if (type == NGTCP2_PKT_SHORT) { - ack->ack_delay_unscaled = ts - largest_ack_ts; - ack->ack_delay = ack->ack_delay_unscaled / NGTCP2_MICROSECONDS / - (1UL << ack_delay_exponent); - } else { - ack->ack_delay_unscaled = 0; - ack->ack_delay = 0; - } - - for (; !ngtcp2_ksl_it_end(&it); ngtcp2_ksl_it_next(&it)) { - if (ack->num_blks == NGTCP2_MAX_ACK_BLKS) { - break; - } - - rpkt = ngtcp2_ksl_it_get(&it); - - blk_idx = ack->num_blks++; - rv = conn_ensure_ack_blks(conn, ack->num_blks); - if (rv != 0) { - return rv; - } - ack = &conn->tx.ack->ack; - blk = &ack->blks[blk_idx]; - blk->gap = (uint64_t)(last_pkt_num - rpkt->pkt_num - 2); - blk->blklen = rpkt->len - 1; - - last_pkt_num = rpkt->pkt_num - (int64_t)(rpkt->len - 1); - } - - /* TODO Just remove entries which cannot fit into a single ACK frame - for now. */ - if (!ngtcp2_ksl_it_end(&it)) { - ngtcp2_acktr_forget(acktr, ngtcp2_ksl_it_get(&it)); - } - - *pfr = conn->tx.ack; - - return 0; -} - -/* - * conn_ppe_write_frame writes |fr| to |ppe|. If |hd_logged| is not - * NULL and |*hd_logged| is zero, packet header is logged, and 1 is - * assigned to |*hd_logged|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer is too small. - */ -static int conn_ppe_write_frame_hd_log(ngtcp2_conn *conn, ngtcp2_ppe *ppe, - int *hd_logged, const ngtcp2_pkt_hd *hd, - ngtcp2_frame *fr) { - int rv; - - rv = ngtcp2_ppe_encode_frame(ppe, fr); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - return rv; - } - - if (hd_logged && !*hd_logged) { - *hd_logged = 1; - ngtcp2_log_tx_pkt_hd(&conn->log, hd); - ngtcp2_qlog_pkt_sent_start(&conn->qlog, hd); - } - - ngtcp2_log_tx_fr(&conn->log, hd, fr); - ngtcp2_qlog_write_frame(&conn->qlog, fr); - - return 0; -} - -/* - * conn_ppe_write_frame writes |fr| to |ppe|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer is too small. - */ -static int conn_ppe_write_frame(ngtcp2_conn *conn, ngtcp2_ppe *ppe, - const ngtcp2_pkt_hd *hd, ngtcp2_frame *fr) { - return conn_ppe_write_frame_hd_log(conn, ppe, NULL, hd, fr); -} - -/* - * conn_on_pkt_sent is called when new non-ACK-only packet is sent. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -static int conn_on_pkt_sent(ngtcp2_conn *conn, ngtcp2_rtb *rtb, - ngtcp2_rtb_entry *ent) { - int rv; - - /* This function implements OnPacketSent, but it handles only - non-ACK-only packet. */ - rv = ngtcp2_rtb_add(rtb, ent, &conn->cstat); - if (rv != 0) { - return rv; - } - - if (ent->flags & NGTCP2_RTB_FLAG_ACK_ELICITING) { - conn->cstat.last_tx_pkt_ts[rtb->pktns_id] = ent->ts; - } - - ngtcp2_conn_set_loss_detection_timer(conn, ent->ts); - - return 0; -} - -/* - * pktns_select_pkt_numlen selects shortest packet number encoding for - * the next packet number based on the largest acknowledged packet - * number. It returns the number of bytes to encode the packet - * number. - */ -static size_t pktns_select_pkt_numlen(ngtcp2_pktns *pktns) { - int64_t pkt_num = pktns->tx.last_pkt_num + 1; - ngtcp2_rtb *rtb = &pktns->rtb; - int64_t n = pkt_num - rtb->largest_acked_tx_pkt_num; - - if (NGTCP2_MAX_PKT_NUM / 2 <= pkt_num) { - return 4; - } - - n = n * 2 + 1; - - if (n > 0xffffff) { - return 4; - } - if (n > 0xffff) { - return 3; - } - if (n > 0xff) { - return 2; - } - return 1; -} - -/* - * conn_cwnd_is_zero returns nonzero if the number of bytes the local - * endpoint can sent at this time is zero. - */ -static uint64_t conn_cwnd_is_zero(ngtcp2_conn *conn) { - uint64_t bytes_in_flight = conn->cstat.bytes_in_flight; - uint64_t cwnd = - conn->pv && (conn->pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE) - ? ngtcp2_cc_compute_initcwnd(conn->cstat.max_udp_payload_size) - : conn->cstat.cwnd; - - return bytes_in_flight >= cwnd; -} - -/* - * conn_retry_early_payloadlen returns the estimated wire length of - * the first STREAM frame of 0-RTT packet which should be - * retransmitted due to Retry frame - */ -static size_t conn_retry_early_payloadlen(ngtcp2_conn *conn) { - ngtcp2_frame_chain *frc; - ngtcp2_strm *strm; - - for (; !ngtcp2_pq_empty(&conn->tx.strmq);) { - strm = ngtcp2_conn_tx_strmq_top(conn); - if (ngtcp2_strm_streamfrq_empty(strm)) { - ngtcp2_conn_tx_strmq_pop(conn); - continue; - } - - frc = ngtcp2_strm_streamfrq_top(strm); - return ngtcp2_vec_len(frc->fr.stream.data, frc->fr.stream.datacnt) + - NGTCP2_STREAM_OVERHEAD; - } - - return 0; -} - -static void conn_cryptofrq_clear(ngtcp2_conn *conn, ngtcp2_pktns *pktns) { - ngtcp2_frame_chain *frc; - ngtcp2_ksl_it it; - - for (it = ngtcp2_ksl_begin(&pktns->crypto.tx.frq); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - frc = ngtcp2_ksl_it_get(&it); - ngtcp2_frame_chain_del(frc, conn->mem); - } - ngtcp2_ksl_clear(&pktns->crypto.tx.frq); -} - -/* - * conn_cryptofrq_unacked_offset returns the CRYPTO frame offset by - * taking into account acknowledged offset. If there is no data to - * send, this function returns (uint64_t)-1. - */ -static uint64_t conn_cryptofrq_unacked_offset(ngtcp2_conn *conn, - ngtcp2_pktns *pktns) { - ngtcp2_frame_chain *frc; - ngtcp2_crypto *fr; - ngtcp2_range gap; - ngtcp2_rtb *rtb = &pktns->rtb; - ngtcp2_ksl_it it; - size_t datalen; - - (void)conn; - - for (it = ngtcp2_ksl_begin(&pktns->crypto.tx.frq); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - frc = ngtcp2_ksl_it_get(&it); - fr = &frc->fr.crypto; - - gap = ngtcp2_strm_get_unacked_range_after(rtb->crypto, fr->offset); - - datalen = ngtcp2_vec_len(fr->data, fr->datacnt); - - if (gap.begin <= fr->offset) { - return fr->offset; - } - if (gap.begin < fr->offset + datalen) { - return gap.begin; - } - } - - return (uint64_t)-1; -} - -static int conn_cryptofrq_unacked_pop(ngtcp2_conn *conn, ngtcp2_pktns *pktns, - ngtcp2_frame_chain **pfrc) { - ngtcp2_frame_chain *frc, *nfrc; - ngtcp2_crypto *fr, *nfr; - uint64_t offset, end_offset; - size_t idx, end_idx; - uint64_t base_offset, end_base_offset; - ngtcp2_range gap; - ngtcp2_rtb *rtb = &pktns->rtb; - ngtcp2_vec *v; - int rv; - ngtcp2_ksl_it it; - - *pfrc = NULL; - - for (it = ngtcp2_ksl_begin(&pktns->crypto.tx.frq); !ngtcp2_ksl_it_end(&it);) { - frc = ngtcp2_ksl_it_get(&it); - fr = &frc->fr.crypto; - - ngtcp2_ksl_remove(&pktns->crypto.tx.frq, &it, &fr->offset); - - idx = 0; - offset = fr->offset; - base_offset = 0; - - gap = ngtcp2_strm_get_unacked_range_after(rtb->crypto, offset); - if (gap.begin < offset) { - gap.begin = offset; - } - - for (; idx < fr->datacnt && offset < gap.begin; ++idx) { - v = &fr->data[idx]; - if (offset + v->len > gap.begin) { - base_offset = gap.begin - offset; - break; - } - - offset += v->len; - } - - if (idx == fr->datacnt) { - ngtcp2_frame_chain_del(frc, conn->mem); - continue; - } - - assert(gap.begin == offset + base_offset); - - end_idx = idx; - end_offset = offset; - end_base_offset = 0; - - for (; end_idx < fr->datacnt; ++end_idx) { - v = &fr->data[end_idx]; - if (end_offset + v->len > gap.end) { - end_base_offset = gap.end - end_offset; - break; - } - - end_offset += v->len; - } - - if (fr->offset == offset && base_offset == 0 && fr->datacnt == end_idx) { - *pfrc = frc; - return 0; - } - - if (fr->datacnt == end_idx) { - memmove(fr->data, fr->data + idx, sizeof(fr->data[0]) * (end_idx - idx)); - - assert(fr->data[0].len > base_offset); - - fr->offset = offset + base_offset; - fr->datacnt = end_idx - idx; - fr->data[0].base += base_offset; - fr->data[0].len -= (size_t)base_offset; - - *pfrc = frc; - return 0; - } - - rv = ngtcp2_frame_chain_crypto_datacnt_new(&nfrc, fr->datacnt - end_idx, - conn->mem); - if (rv != 0) { - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - - nfr = &nfrc->fr.crypto; - nfr->type = NGTCP2_FRAME_CRYPTO; - memcpy(nfr->data, fr->data + end_idx, - sizeof(nfr->data[0]) * (fr->datacnt - end_idx)); - - assert(nfr->data[0].len > end_base_offset); - - nfr->offset = end_offset + end_base_offset; - nfr->datacnt = fr->datacnt - end_idx; - nfr->data[0].base += end_base_offset; - nfr->data[0].len -= (size_t)end_base_offset; - - rv = ngtcp2_ksl_insert(&pktns->crypto.tx.frq, NULL, &nfr->offset, nfrc); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(nfrc, conn->mem); - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - - if (end_base_offset) { - ++end_idx; - } - - memmove(fr->data, fr->data + idx, sizeof(fr->data[0]) * (end_idx - idx)); - - assert(fr->data[0].len > base_offset); - - fr->offset = offset + base_offset; - fr->datacnt = end_idx - idx; - if (end_base_offset) { - assert(fr->data[fr->datacnt - 1].len > end_base_offset); - fr->data[fr->datacnt - 1].len = (size_t)end_base_offset; - } - fr->data[0].base += base_offset; - fr->data[0].len -= (size_t)base_offset; - - *pfrc = frc; - return 0; - } - - return 0; -} -static int conn_cryptofrq_pop(ngtcp2_conn *conn, ngtcp2_frame_chain **pfrc, - ngtcp2_pktns *pktns, size_t left) { - ngtcp2_crypto *fr, *nfr; - ngtcp2_frame_chain *frc, *nfrc; - int rv; - size_t nmerged; - size_t datalen; - ngtcp2_vec a[NGTCP2_MAX_CRYPTO_DATACNT]; - ngtcp2_vec b[NGTCP2_MAX_CRYPTO_DATACNT]; - size_t acnt, bcnt; - ngtcp2_ksl_it it; - - rv = conn_cryptofrq_unacked_pop(conn, pktns, &frc); - if (rv != 0) { - return rv; - } - if (frc == NULL) { - *pfrc = NULL; - return 0; - } - - fr = &frc->fr.crypto; - datalen = ngtcp2_vec_len(fr->data, fr->datacnt); - - if (datalen > left) { - ngtcp2_vec_copy(a, fr->data, fr->datacnt); - acnt = fr->datacnt; - - bcnt = 0; - ngtcp2_vec_split(a, &acnt, b, &bcnt, left, NGTCP2_MAX_CRYPTO_DATACNT); - - assert(acnt > 0); - assert(bcnt > 0); - - rv = ngtcp2_frame_chain_crypto_datacnt_new(&nfrc, bcnt, conn->mem); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - - nfr = &nfrc->fr.crypto; - nfr->type = NGTCP2_FRAME_CRYPTO; - nfr->offset = fr->offset + left; - nfr->datacnt = bcnt; - ngtcp2_vec_copy(nfr->data, b, bcnt); - - rv = ngtcp2_ksl_insert(&pktns->crypto.tx.frq, NULL, &nfr->offset, nfrc); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(nfrc, conn->mem); - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - - rv = ngtcp2_frame_chain_crypto_datacnt_new(&nfrc, acnt, conn->mem); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - - nfr = &nfrc->fr.crypto; - *nfr = *fr; - nfr->datacnt = acnt; - ngtcp2_vec_copy(nfr->data, a, acnt); - - ngtcp2_frame_chain_del(frc, conn->mem); - - *pfrc = nfrc; - - return 0; - } - - left -= datalen; - - ngtcp2_vec_copy(a, fr->data, fr->datacnt); - acnt = fr->datacnt; - - for (; left && ngtcp2_ksl_len(&pktns->crypto.tx.frq);) { - it = ngtcp2_ksl_begin(&pktns->crypto.tx.frq); - nfrc = ngtcp2_ksl_it_get(&it); - nfr = &nfrc->fr.crypto; - - if (nfr->offset != fr->offset + datalen) { - assert(fr->offset + datalen < nfr->offset); - break; - } - - rv = conn_cryptofrq_unacked_pop(conn, pktns, &nfrc); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - if (nfrc == NULL) { - break; - } - - nfr = &nfrc->fr.crypto; - - nmerged = ngtcp2_vec_merge(a, &acnt, nfr->data, &nfr->datacnt, left, - NGTCP2_MAX_CRYPTO_DATACNT); - if (nmerged == 0) { - rv = ngtcp2_ksl_insert(&pktns->crypto.tx.frq, NULL, &nfr->offset, nfrc); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(nfrc, conn->mem); - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - break; - } - - datalen += nmerged; - left -= nmerged; - - if (nfr->datacnt == 0) { - ngtcp2_frame_chain_del(nfrc, conn->mem); - continue; - } - - nfr->offset += nmerged; - - rv = ngtcp2_ksl_insert(&pktns->crypto.tx.frq, NULL, &nfr->offset, nfrc); - if (rv != 0) { - ngtcp2_frame_chain_del(nfrc, conn->mem); - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - - break; - } - - if (acnt == fr->datacnt) { - assert(acnt > 0); - fr->data[acnt - 1] = a[acnt - 1]; - - *pfrc = frc; - return 0; - } - - assert(acnt > fr->datacnt); - - rv = ngtcp2_frame_chain_crypto_datacnt_new(&nfrc, acnt, conn->mem); - if (rv != 0) { - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - - nfr = &nfrc->fr.crypto; - *nfr = *fr; - nfr->datacnt = acnt; - ngtcp2_vec_copy(nfr->data, a, acnt); - - ngtcp2_frame_chain_del(frc, conn->mem); - - *pfrc = nfrc; - - return 0; -} - -/* - * conn_verify_dcid verifies that destination connection ID in |hd| is - * valid for the connection. If it is successfully verified and the - * remote endpoint uses new DCID in the packet, nonzero value is - * assigned to |*pnew_cid_used| if it is not NULL. Otherwise 0 is - * assigned to it. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_INVALID_ARGUMENT - * |dcid| is not known to the local endpoint. - */ -static int conn_verify_dcid(ngtcp2_conn *conn, int *pnew_cid_used, - const ngtcp2_pkt_hd *hd) { - ngtcp2_ksl_it it; - ngtcp2_scid *scid; - int rv; - - it = ngtcp2_ksl_lower_bound(&conn->scid.set, &hd->dcid); - if (ngtcp2_ksl_it_end(&it)) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - scid = ngtcp2_ksl_it_get(&it); - if (!ngtcp2_cid_eq(&scid->cid, &hd->dcid)) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - if (!(scid->flags & NGTCP2_SCID_FLAG_USED)) { - scid->flags |= NGTCP2_SCID_FLAG_USED; - - if (scid->pe.index == NGTCP2_PQ_BAD_INDEX) { - rv = ngtcp2_pq_push(&conn->scid.used, &scid->pe); - if (rv != 0) { - return rv; - } - } - - if (pnew_cid_used) { - *pnew_cid_used = 1; - } - } else if (pnew_cid_used) { - *pnew_cid_used = 0; - } - - return 0; -} - -/* - * conn_should_pad_pkt returns nonzero if the packet should be padded. - * |type| is the type of packet. |left| is the space left in packet - * buffer. |early_datalen| is the number of bytes which will be sent - * in the next, coalesced 0-RTT packet. - */ -static int conn_should_pad_pkt(ngtcp2_conn *conn, uint8_t type, size_t left, - size_t early_datalen) { - size_t min_payloadlen; - - if (conn->server) { - return 0; - } - - if (type == NGTCP2_PKT_HANDSHAKE) { - return conn->in_pktns != NULL; - } - - if (conn->hs_pktns->crypto.tx.ckm && - (conn->hs_pktns->rtb.probe_pkt_left || - ngtcp2_ksl_len(&conn->hs_pktns->crypto.tx.frq) || - !ngtcp2_acktr_empty(&conn->hs_pktns->acktr))) { - /* If we have something to send in Handshake packet, then add - PADDING in Handshake packet. */ - min_payloadlen = 128; - } else if (!conn->early.ckm || early_datalen == 0) { - return 1; - } else { - /* If we have something to send in 0RTT packet, then add PADDING - in 0RTT packet. */ - min_payloadlen = ngtcp2_min(early_datalen, 128); - } - - return left < - /* TODO Assuming that pkt_num is encoded in 1 byte. */ - NGTCP2_MIN_LONG_HEADERLEN + conn->dcid.current.cid.datalen + - conn->oscid.datalen + 1 /* payloadlen bytes - 1 */ + - min_payloadlen + NGTCP2_MAX_AEAD_OVERHEAD; -} - -static void conn_restart_timer_on_write(ngtcp2_conn *conn, ngtcp2_tstamp ts) { - conn->idle_ts = ts; - conn->flags &= (uint16_t)~NGTCP2_CONN_FLAG_RESTART_IDLE_TIMER_ON_WRITE; -} - -static void conn_restart_timer_on_read(ngtcp2_conn *conn, ngtcp2_tstamp ts) { - conn->idle_ts = ts; - conn->flags |= NGTCP2_CONN_FLAG_RESTART_IDLE_TIMER_ON_WRITE; -} - -/* - * conn_write_handshake_pkt writes handshake packet in the buffer - * pointed by |dest| whose length is |destlen|. |type| specifies long - * packet type. It should be either NGTCP2_PKT_INITIAL or - * NGTCP2_PKT_HANDSHAKE_PKT. - * - * This function returns the number of bytes written in |dest| if it - * succeeds, or one of the following negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -static ngtcp2_ssize conn_write_handshake_pkt(ngtcp2_conn *conn, uint8_t *dest, - size_t destlen, uint8_t type, - size_t early_datalen, - ngtcp2_tstamp ts) { - int rv; - ngtcp2_ppe ppe; - ngtcp2_pkt_hd hd; - ngtcp2_frame_chain *frq = NULL, **pfrc = &frq; - ngtcp2_frame_chain *nfrc; - ngtcp2_frame *ackfr = NULL, lfr; - ngtcp2_ssize spktlen; - ngtcp2_crypto_cc cc; - ngtcp2_rtb_entry *rtbent; - ngtcp2_pktns *pktns; - size_t left; - uint8_t rtb_entry_flags = NGTCP2_RTB_FLAG_NONE; - int pkt_empty = 1; - int padded = 0; - int hd_logged = 0; - uint64_t crypto_offset; - ngtcp2_ssize num_reclaimed; - - switch (type) { - case NGTCP2_PKT_INITIAL: - if (!conn->in_pktns) { - return 0; - } - assert(conn->in_pktns->crypto.tx.ckm); - pktns = conn->in_pktns; - cc.aead_overhead = NGTCP2_INITIAL_AEAD_OVERHEAD; - break; - case NGTCP2_PKT_HANDSHAKE: - if (!conn->hs_pktns || !conn->hs_pktns->crypto.tx.ckm) { - return 0; - } - pktns = conn->hs_pktns; - cc.aead_overhead = conn->crypto.aead_overhead; - break; - default: - assert(0); - } - - cc.aead = pktns->crypto.ctx.aead; - cc.hp = pktns->crypto.ctx.hp; - cc.ckm = pktns->crypto.tx.ckm; - cc.hp_ctx = pktns->crypto.tx.hp_ctx; - cc.encrypt = conn->callbacks.encrypt; - cc.hp_mask = conn->callbacks.hp_mask; - - ngtcp2_pkt_hd_init(&hd, NGTCP2_PKT_FLAG_LONG_FORM, type, - &conn->dcid.current.cid, &conn->oscid, - pktns->tx.last_pkt_num + 1, pktns_select_pkt_numlen(pktns), - conn->version, 0); - - if (!conn->server && type == NGTCP2_PKT_INITIAL && - conn->local.settings.token.len) { - hd.token = conn->local.settings.token; - } - - ngtcp2_ppe_init(&ppe, dest, destlen, &cc); - - rv = ngtcp2_ppe_encode_hd(&ppe, &hd); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - return 0; - } - - if (!ngtcp2_ppe_ensure_hp_sample(&ppe)) { - return 0; - } - - rv = conn_create_ack_frame(conn, &ackfr, pktns, type, ts, - /* ack_delay = */ 0, - NGTCP2_DEFAULT_ACK_DELAY_EXPONENT); - if (rv != 0) { - ngtcp2_frame_chain_list_del(frq, conn->mem); - return rv; - } - - if (ackfr) { - rv = conn_ppe_write_frame_hd_log(conn, &ppe, &hd_logged, &hd, ackfr); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - } else { - ngtcp2_acktr_commit_ack(&pktns->acktr); - ngtcp2_acktr_add_ack(&pktns->acktr, hd.pkt_num, ackfr->ack.largest_ack); - pkt_empty = 0; - } - } - -build_pkt: - for (; ngtcp2_ksl_len(&pktns->crypto.tx.frq);) { - left = ngtcp2_ppe_left(&ppe); - - crypto_offset = conn_cryptofrq_unacked_offset(conn, pktns); - if (crypto_offset == (size_t)-1) { - conn_cryptofrq_clear(conn, pktns); - break; - } - - left = ngtcp2_pkt_crypto_max_datalen(crypto_offset, left, left); - if (left == (size_t)-1) { - break; - } - - rv = conn_cryptofrq_pop(conn, &nfrc, pktns, left); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_list_del(frq, conn->mem); - return rv; - } - - if (nfrc == NULL) { - break; - } - - rv = conn_ppe_write_frame_hd_log(conn, &ppe, &hd_logged, &hd, &nfrc->fr); - if (rv != 0) { - assert(0); - } - - *pfrc = nfrc; - pfrc = &(*pfrc)->next; - - pkt_empty = 0; - rtb_entry_flags |= - NGTCP2_RTB_FLAG_ACK_ELICITING | NGTCP2_RTB_FLAG_RETRANSMITTABLE; - } - - if (!(rtb_entry_flags & NGTCP2_RTB_FLAG_ACK_ELICITING) && - pktns->rtb.num_retransmittable && pktns->rtb.probe_pkt_left) { - num_reclaimed = ngtcp2_rtb_reclaim_on_pto(&pktns->rtb, conn, pktns, - pktns->rtb.probe_pkt_left + 1); - if (num_reclaimed < 0) { - ngtcp2_frame_chain_list_del(frq, conn->mem); - return rv; - } - if (num_reclaimed) { - goto build_pkt; - } - /* We had pktns->rtb.num_retransmittable > 0 but the contents of - those packets have been acknowledged (i.e., retransmission in - another packet). For server, in this case, we don't have to - send any probe packet. Client needs to send probe packets - until it knows that server has completed address validation or - handshake has been confirmed. */ - if (pktns->rtb.num_retransmittable == 0 && - (conn->server || - (conn->flags & (NGTCP2_CONN_FLAG_SERVER_ADDR_VERIFIED | - NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED)))) { - pktns->rtb.probe_pkt_left = 0; - ngtcp2_conn_set_loss_detection_timer(conn, ts); - } - } - - /* Don't send any PING frame if client Initial has not been - acknowledged yet. */ - if (!(rtb_entry_flags & NGTCP2_RTB_FLAG_ACK_ELICITING) && - pktns->rtb.probe_pkt_left && - (type != NGTCP2_PKT_INITIAL || - ngtcp2_strm_is_all_tx_data_acked(&pktns->crypto.strm))) { - lfr.type = NGTCP2_FRAME_PING; - - rv = conn_ppe_write_frame_hd_log(conn, &ppe, &hd_logged, &hd, &lfr); - if (rv != 0) { - assert(rv == NGTCP2_ERR_NOBUF); - } else { - rtb_entry_flags |= NGTCP2_RTB_FLAG_ACK_ELICITING | NGTCP2_RTB_FLAG_PROBE; - pkt_empty = 0; - } - } - - if (!pkt_empty) { - if (!(rtb_entry_flags & NGTCP2_RTB_FLAG_ACK_ELICITING)) { - /* The intention of smaller limit is get more chance to measure - RTT samples in early phase. */ - if (pktns->rtb.probe_pkt_left || pktns->tx.num_non_ack_pkt >= 1) { - lfr.type = NGTCP2_FRAME_PING; - - rv = conn_ppe_write_frame_hd_log(conn, &ppe, &hd_logged, &hd, &lfr); - if (rv != 0) { - assert(rv == NGTCP2_ERR_NOBUF); - } else { - rtb_entry_flags |= NGTCP2_RTB_FLAG_ACK_ELICITING; - pktns->tx.num_non_ack_pkt = 0; - } - } else { - ++pktns->tx.num_non_ack_pkt; - } - } else { - pktns->tx.num_non_ack_pkt = 0; - } - } - - if (pkt_empty) { - return 0; - } - - /* If we cannot write another packet, then we need to add padding to - Initial here. */ - if (conn_should_pad_pkt(conn, type, ngtcp2_ppe_left(&ppe), early_datalen)) { - lfr.type = NGTCP2_FRAME_PADDING; - lfr.padding.len = ngtcp2_ppe_padding(&ppe); - } else { - lfr.type = NGTCP2_FRAME_PADDING; - lfr.padding.len = ngtcp2_ppe_padding_hp_sample(&ppe); - } - - if (lfr.padding.len) { - padded = 1; - ngtcp2_log_tx_fr(&conn->log, &hd, &lfr); - ngtcp2_qlog_write_frame(&conn->qlog, &lfr); - } - - spktlen = ngtcp2_ppe_final(&ppe, NULL); - if (spktlen < 0) { - assert(ngtcp2_err_is_fatal((int)spktlen)); - ngtcp2_frame_chain_list_del(frq, conn->mem); - return spktlen; - } - - ngtcp2_qlog_pkt_sent_end(&conn->qlog, &hd, (size_t)spktlen); - - if ((rtb_entry_flags & NGTCP2_RTB_FLAG_ACK_ELICITING) || padded) { - rv = ngtcp2_rtb_entry_new(&rtbent, &hd, frq, ts, (size_t)spktlen, - rtb_entry_flags, conn->mem); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_list_del(frq, conn->mem); - return rv; - } - - rv = conn_on_pkt_sent(conn, &pktns->rtb, rtbent); - if (rv != 0) { - ngtcp2_rtb_entry_del(rtbent, conn->mem); - return rv; - } - - if ((rtb_entry_flags & NGTCP2_RTB_FLAG_ACK_ELICITING) && - (conn->flags & NGTCP2_CONN_FLAG_RESTART_IDLE_TIMER_ON_WRITE)) { - conn_restart_timer_on_write(conn, ts); - } - } - - if (pktns->rtb.probe_pkt_left && - (rtb_entry_flags & NGTCP2_RTB_FLAG_ACK_ELICITING)) { - --pktns->rtb.probe_pkt_left; - } - - ngtcp2_qlog_metrics_updated(&conn->qlog, &conn->cstat); - - ++pktns->tx.last_pkt_num; - - return spktlen; -} - -/* - * conn_write_ack_pkt writes QUIC packet for type |type| which only - * includes ACK frame in the buffer pointed by |dest| whose length is - * |destlen|. - * - * This function returns the number of bytes written in |dest| if it - * succeeds, or one of the following negative error codes: - * - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static ngtcp2_ssize conn_write_ack_pkt(ngtcp2_conn *conn, uint8_t *dest, - size_t destlen, uint8_t type, - ngtcp2_tstamp ts) { - int rv; - ngtcp2_frame *ackfr; - ngtcp2_pktns *pktns; - ngtcp2_duration ack_delay; - uint64_t ack_delay_exponent; - - assert(!(conn->flags & NGTCP2_CONN_FLAG_PPE_PENDING)); - - switch (type) { - case NGTCP2_PKT_INITIAL: - assert(conn->server); - pktns = conn->in_pktns; - ack_delay = 0; - ack_delay_exponent = NGTCP2_DEFAULT_ACK_DELAY_EXPONENT; - break; - case NGTCP2_PKT_HANDSHAKE: - pktns = conn->hs_pktns; - ack_delay = 0; - ack_delay_exponent = NGTCP2_DEFAULT_ACK_DELAY_EXPONENT; - break; - case NGTCP2_PKT_SHORT: - pktns = &conn->pktns; - ack_delay = conn_compute_ack_delay(conn); - ack_delay_exponent = - conn->local.settings.transport_params.ack_delay_exponent; - break; - default: - assert(0); - } - - if (!pktns->crypto.tx.ckm) { - return 0; - } - - ackfr = NULL; - rv = conn_create_ack_frame(conn, &ackfr, pktns, type, ts, ack_delay, - ack_delay_exponent); - if (rv != 0) { - return rv; - } - - if (!ackfr) { - return 0; - } - - return ngtcp2_conn_write_single_frame_pkt(conn, dest, destlen, type, - &conn->dcid.current.cid, ackfr, - NGTCP2_RTB_FLAG_NONE, ts); -} - -static void conn_discard_pktns(ngtcp2_conn *conn, ngtcp2_pktns **ppktns, - ngtcp2_tstamp ts) { - ngtcp2_pktns *pktns = *ppktns; - uint64_t bytes_in_flight; - - bytes_in_flight = pktns->rtb.cc_bytes_in_flight; - - assert(conn->cstat.bytes_in_flight >= bytes_in_flight); - - conn->cstat.bytes_in_flight -= bytes_in_flight; - conn->cstat.pto_count = 0; - conn->cstat.last_tx_pkt_ts[pktns->rtb.pktns_id] = UINT64_MAX; - conn->cstat.loss_time[pktns->rtb.pktns_id] = UINT64_MAX; - - conn_call_delete_crypto_aead_ctx(conn, &pktns->crypto.rx.ckm->aead_ctx); - conn_call_delete_crypto_cipher_ctx(conn, &pktns->crypto.rx.hp_ctx); - conn_call_delete_crypto_aead_ctx(conn, &pktns->crypto.tx.ckm->aead_ctx); - conn_call_delete_crypto_cipher_ctx(conn, &pktns->crypto.tx.hp_ctx); - - pktns_del(pktns, conn->mem); - *ppktns = NULL; - - ngtcp2_conn_set_loss_detection_timer(conn, ts); -} - -/* - * conn_discard_initial_state discards state for Initial packet number - * space. - */ -static void conn_discard_initial_state(ngtcp2_conn *conn, ngtcp2_tstamp ts) { - if (!conn->in_pktns) { - return; - } - - conn_discard_pktns(conn, &conn->in_pktns, ts); -} - -/* - * conn_discard_handshake_state discards state for Handshake packet - * number space. - */ -static void conn_discard_handshake_state(ngtcp2_conn *conn, ngtcp2_tstamp ts) { - if (!conn->hs_pktns) { - return; - } - - conn_discard_pktns(conn, &conn->hs_pktns, ts); -} - -/* - * conn_write_handshake_ack_pkts writes packets which contain ACK - * frame only. This function writes at most 2 packets for each - * Initial and Handshake packet. - */ -static ngtcp2_ssize conn_write_handshake_ack_pkts(ngtcp2_conn *conn, - uint8_t *dest, size_t destlen, - ngtcp2_tstamp ts) { - ngtcp2_ssize res = 0, nwrite = 0; - - /* In the most cases, client sends ACK in conn_write_handshake_pkt. - This function is only called when it is CWND limited. It is not - required for client to send ACK for server Initial. This is - because once it gets server Initial, it gets Handshake tx key and - discards Initial key. The only good reason to send ACK is give - server RTT measurement early. */ - if (conn->server && conn->in_pktns) { - nwrite = conn_write_ack_pkt(conn, dest, destlen, NGTCP2_PKT_INITIAL, ts); - if (nwrite < 0) { - assert(nwrite != NGTCP2_ERR_NOBUF); - return nwrite; - } - - res += nwrite; - dest += nwrite; - destlen -= (size_t)nwrite; - } - - if (conn->hs_pktns->crypto.tx.ckm) { - nwrite = conn_write_ack_pkt(conn, dest, destlen, NGTCP2_PKT_HANDSHAKE, ts); - if (nwrite < 0) { - assert(nwrite != NGTCP2_ERR_NOBUF); - return nwrite; - } - - res += nwrite; - - if (!conn->server && nwrite) { - conn_discard_initial_state(conn, ts); - } - } - - return res; -} - -/* - * conn_write_client_initial writes Initial packet in the buffer - * pointed by |dest| whose length is |destlen|. - * - * This function returns the number of bytes written in |dest| if it - * succeeds, or one of the following negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -static ngtcp2_ssize conn_write_client_initial(ngtcp2_conn *conn, uint8_t *dest, - size_t destlen, - size_t early_datalen, - ngtcp2_tstamp ts) { - int rv; - - assert(conn->callbacks.client_initial); - - rv = conn->callbacks.client_initial(conn, conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return conn_write_handshake_pkt(conn, dest, destlen, NGTCP2_PKT_INITIAL, - early_datalen, ts); -} - -/* - * conn_write_handshake_pkts writes Initial and Handshake packets in - * the buffer pointed by |dest| whose length is |destlen|. - * - * This function returns the number of bytes written in |dest| if it - * succeeds, or one of the following negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -static ngtcp2_ssize conn_write_handshake_pkts(ngtcp2_conn *conn, uint8_t *dest, - size_t destlen, - size_t early_datalen, - ngtcp2_tstamp ts) { - ngtcp2_ssize nwrite; - ngtcp2_ssize res = 0; - - if (!conn->server && conn->hs_pktns->crypto.tx.ckm && - !ngtcp2_acktr_empty(&conn->hs_pktns->acktr)) { - /* Discard Initial state here so that Handshake packet is not - padded. */ - conn_discard_initial_state(conn, ts); - } else { - nwrite = conn_write_handshake_pkt(conn, dest, destlen, NGTCP2_PKT_INITIAL, - early_datalen, ts); - if (nwrite < 0) { - assert(nwrite != NGTCP2_ERR_NOBUF); - return nwrite; - } - - res += nwrite; - dest += nwrite; - destlen -= (size_t)nwrite; - } - - nwrite = conn_write_handshake_pkt(conn, dest, destlen, NGTCP2_PKT_HANDSHAKE, - 0, ts); - if (nwrite < 0) { - assert(nwrite != NGTCP2_ERR_NOBUF); - return nwrite; - } - - res += nwrite; - - if (!conn->server && conn->hs_pktns->crypto.tx.ckm && nwrite) { - /* We don't need to send further Initial packet if we have - Handshake key and sent something with it. So discard initial - state here. */ - conn_discard_initial_state(conn, ts); - } - - return res; -} - -/* - * conn_initial_stream_rx_offset returns the initial maximum offset of - * data for a stream denoted by |stream_id|. - */ -static uint64_t conn_initial_stream_rx_offset(ngtcp2_conn *conn, - int64_t stream_id) { - int local_stream = conn_local_stream(conn, stream_id); - - if (bidi_stream(stream_id)) { - if (local_stream) { - return conn->local.settings.transport_params - .initial_max_stream_data_bidi_local; - } - return conn->local.settings.transport_params - .initial_max_stream_data_bidi_remote; - } - - if (local_stream) { - return 0; - } - return conn->local.settings.transport_params.initial_max_stream_data_uni; -} - -/* - * conn_should_send_max_stream_data returns nonzero if MAX_STREAM_DATA - * frame should be send for |strm|. - */ -static int conn_should_send_max_stream_data(ngtcp2_conn *conn, - ngtcp2_strm *strm) { - uint64_t win = conn_initial_stream_rx_offset(conn, strm->stream_id); - uint64_t inc = strm->rx.unsent_max_offset - strm->rx.max_offset; - ngtcp2_conn_stat *cstat = &conn->cstat; - - return win < 2 * inc || - (cstat->min_rtt != UINT64_MAX && - 2 * cstat->recv_rate_sec * cstat->min_rtt / NGTCP2_SECONDS > - win - inc); -} - -/* - * conn_should_send_max_data returns nonzero if MAX_DATA frame should - * be sent. - */ -static int conn_should_send_max_data(ngtcp2_conn *conn) { - uint64_t inc = conn->rx.unsent_max_offset - conn->rx.max_offset; - ngtcp2_conn_stat *cstat = &conn->cstat; - - return conn->local.settings.transport_params.initial_max_data < 2 * inc || - (cstat->min_rtt != UINT64_MAX && - 2 * cstat->recv_rate_sec * cstat->min_rtt / NGTCP2_SECONDS > - conn->local.settings.transport_params.initial_max_data - inc); -} - -/* - * conn_required_num_new_connection_id returns the number of - * additional connection ID the local endpoint has to provide to the - * remote endpoint. - */ -static size_t conn_required_num_new_connection_id(ngtcp2_conn *conn) { - uint64_t n; - size_t len = ngtcp2_ksl_len(&conn->scid.set); - - if (len >= NGTCP2_MAX_SCID_POOL_SIZE) { - return 0; - } - - /* len includes retired CID. We don't provide extra CID if doing so - excceds NGTCP2_MAX_SCID_POOL_SIZE. */ - - n = conn->remote.transport_params.active_connection_id_limit + - conn->scid.num_retired; - - return (size_t)ngtcp2_min(NGTCP2_MAX_SCID_POOL_SIZE, n) - len; -} - -/* - * conn_enqueue_new_connection_id generates additional connection IDs - * and prepares to send them to the remote endpoint. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -static int conn_enqueue_new_connection_id(ngtcp2_conn *conn) { - size_t i, need = conn_required_num_new_connection_id(conn); - size_t cidlen = conn->oscid.datalen; - ngtcp2_cid cid; - uint64_t seq; - int rv; - uint8_t token[NGTCP2_STATELESS_RESET_TOKENLEN]; - ngtcp2_frame_chain *nfrc; - ngtcp2_pktns *pktns = &conn->pktns; - ngtcp2_scid *scid; - ngtcp2_ksl_it it; - - for (i = 0; i < need; ++i) { - rv = conn_call_get_new_connection_id(conn, &cid, token, cidlen); - if (rv != 0) { - return rv; - } - - if (cid.datalen != cidlen) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - /* Assert uniqueness */ - it = ngtcp2_ksl_lower_bound(&conn->scid.set, &cid); - if (!ngtcp2_ksl_it_end(&it) && - ngtcp2_cid_eq(ngtcp2_ksl_it_key(&it), &cid)) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - seq = ++conn->scid.last_seq; - - scid = ngtcp2_mem_malloc(conn->mem, sizeof(*scid)); - if (scid == NULL) { - return NGTCP2_ERR_NOMEM; - } - - ngtcp2_scid_init(scid, seq, &cid, token); - - rv = ngtcp2_ksl_insert(&conn->scid.set, NULL, &scid->cid, scid); - if (rv != 0) { - ngtcp2_mem_free(conn->mem, scid); - return rv; - } - - rv = ngtcp2_frame_chain_new(&nfrc, conn->mem); - if (rv != 0) { - return rv; - } - - nfrc->fr.type = NGTCP2_FRAME_NEW_CONNECTION_ID; - nfrc->fr.new_connection_id.seq = seq; - nfrc->fr.new_connection_id.retire_prior_to = 0; - nfrc->fr.new_connection_id.cid = cid; - memcpy(nfrc->fr.new_connection_id.stateless_reset_token, token, - sizeof(token)); - nfrc->next = pktns->tx.frq; - pktns->tx.frq = nfrc; - } - - return 0; -} - -/* - * conn_compute_pto computes the current PTO. - */ -static ngtcp2_duration conn_compute_pto(ngtcp2_conn *conn, - ngtcp2_pktns *pktns) { - ngtcp2_conn_stat *cstat = &conn->cstat; - ngtcp2_duration var = ngtcp2_max(4 * cstat->rttvar, NGTCP2_GRANULARITY); - ngtcp2_duration max_ack_delay = - pktns->rtb.pktns_id == NGTCP2_PKTNS_ID_APP - ? conn->remote.transport_params.max_ack_delay - : 0; - return cstat->smoothed_rtt + var + max_ack_delay; -} - -/* - * conn_remove_retired_connection_id removes the already retired - * connection ID. It waits PTO before actually removing a connection - * ID after it receives RETIRE_CONNECTION_ID from peer to catch - * reordered packets. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -static int conn_remove_retired_connection_id(ngtcp2_conn *conn, - ngtcp2_tstamp ts) { - ngtcp2_duration timeout = conn_compute_pto(conn, &conn->pktns); - ngtcp2_scid *scid; - ngtcp2_dcid *dcid; - int rv; - - for (; !ngtcp2_pq_empty(&conn->scid.used);) { - scid = ngtcp2_struct_of(ngtcp2_pq_top(&conn->scid.used), ngtcp2_scid, pe); - - if (scid->ts_retired == UINT64_MAX || scid->ts_retired + timeout >= ts) { - break; - } - - assert(scid->flags & NGTCP2_SCID_FLAG_RETIRED); - - rv = conn_call_remove_connection_id(conn, &scid->cid); - if (rv != 0) { - return rv; - } - - ngtcp2_ksl_remove(&conn->scid.set, NULL, &scid->cid); - ngtcp2_pq_pop(&conn->scid.used); - ngtcp2_mem_free(conn->mem, scid); - - assert(conn->scid.num_retired); - --conn->scid.num_retired; - } - - for (; ngtcp2_ringbuf_len(&conn->dcid.retired);) { - dcid = ngtcp2_ringbuf_get(&conn->dcid.retired, 0); - if (dcid->ts_retired + timeout >= ts) { - break; - } - - rv = conn_call_deactivate_dcid(conn, dcid); - if (rv != 0) { - return rv; - } - - ngtcp2_ringbuf_pop_front(&conn->dcid.retired); - } - - return 0; -} - -/* - * conn_min_short_pktlen returns the minimum length of Short packet - * this endpoint sends. - */ -static size_t conn_min_short_pktlen(ngtcp2_conn *conn) { - return conn->dcid.current.cid.datalen + NGTCP2_MIN_PKT_EXPANDLEN; -} - -typedef enum { - NGTCP2_WRITE_PKT_FLAG_NONE = 0x00, - /* NGTCP2_WRITE_PKT_FLAG_REQUIRE_PADDING indicates that packet - should be padded */ - NGTCP2_WRITE_PKT_FLAG_REQUIRE_PADDING = 0x01, - /* NGTCP2_WRITE_PKT_FLAG_MORE indicates that more frames might come - and it should be encoded into the current packet. */ - NGTCP2_WRITE_PKT_FLAG_MORE = 0x02, -} ngtcp2_write_pkt_flag; - -/* - * conn_write_pkt writes a protected packet in the buffer pointed by - * |dest| whose length if |destlen|. |type| specifies the type of - * packet. It can be NGTCP2_PKT_SHORT or NGTCP2_PKT_0RTT. - * - * This function can send new stream data. In order to send stream - * data, specify the underlying stream and parameters to - * |vmsg|->stream. If |vmsg|->stream.fin is set to nonzero, it - * signals that the given data is the final portion of the stream. - * |vmsg|->stream.data vector of length |vmsg|->stream.datacnt - * specifies stream data to send. The number of bytes sent to the - * stream is assigned to *|vmsg|->stream.pdatalen. If 0 length STREAM - * data is sent, 0 is assigned to it. The caller should initialize - * *|vmsg|->stream.pdatalen to -1. - * - * If |require_padding| is nonzero, padding bytes are added to occupy - * the remaining packet payload. - * - * This function returns the number of bytes written in |dest| if it - * succeeds, or one of the following negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - * NGTCP2_ERR_STREAM_DATA_BLOCKED - * Stream data could not be written because of flow control. - */ -static ngtcp2_ssize conn_write_pkt(ngtcp2_conn *conn, uint8_t *dest, - size_t destlen, ngtcp2_vmsg *vmsg, - uint8_t type, uint8_t flags, - ngtcp2_tstamp ts) { - int rv = 0; - ngtcp2_crypto_cc *cc = &conn->pkt.cc; - ngtcp2_ppe *ppe = &conn->pkt.ppe; - ngtcp2_pkt_hd *hd = &conn->pkt.hd; - ngtcp2_frame *ackfr = NULL, lfr; - ngtcp2_ssize nwrite; - ngtcp2_frame_chain **pfrc, *nfrc, *frc; - ngtcp2_rtb_entry *ent; - ngtcp2_strm *strm; - int pkt_empty = 1; - size_t ndatalen = 0; - int send_stream = 0; - int stream_blocked = 0; - ngtcp2_pktns *pktns = &conn->pktns; - size_t left; - size_t datalen = 0; - ngtcp2_vec data[NGTCP2_MAX_STREAM_DATACNT]; - size_t datacnt; - uint8_t rtb_entry_flags = NGTCP2_RTB_FLAG_NONE; - int hd_logged = 0; - ngtcp2_path_challenge_entry *pcent; - uint8_t hd_flags; - int require_padding = (flags & NGTCP2_WRITE_PKT_FLAG_REQUIRE_PADDING) != 0; - int write_more = (flags & NGTCP2_WRITE_PKT_FLAG_MORE) != 0; - int ppe_pending = (conn->flags & NGTCP2_CONN_FLAG_PPE_PENDING) != 0; - size_t min_pktlen = conn_min_short_pktlen(conn); - int padded = 0; - int credit_expanded = 0; - ngtcp2_cc_pkt cc_pkt; - uint64_t crypto_offset; - uint64_t stream_offset; - ngtcp2_ssize num_reclaimed; - int fin; - - /* Return 0 if destlen is less than minimum packet length which can - trigger Stateless Reset */ - if (destlen < min_pktlen) { - return 0; - } - - if (vmsg) { - switch (vmsg->type) { - case NGTCP2_VMSG_TYPE_STREAM: - datalen = ngtcp2_vec_len(vmsg->stream.data, vmsg->stream.datacnt); - ndatalen = conn_enforce_flow_control(conn, vmsg->stream.strm, datalen); - /* 0 length STREAM frame is allowed */ - if (ndatalen || datalen == 0) { - send_stream = 1; - } else { - stream_blocked = 1; - } - break; - default: - break; - } - } - - if (!ppe_pending) { - switch (type) { - case NGTCP2_PKT_SHORT: - hd_flags = - (pktns->crypto.tx.ckm->flags & NGTCP2_CRYPTO_KM_FLAG_KEY_PHASE_ONE) - ? NGTCP2_PKT_FLAG_KEY_PHASE - : NGTCP2_PKT_FLAG_NONE; - cc->ckm = pktns->crypto.tx.ckm; - cc->hp_ctx = pktns->crypto.tx.hp_ctx; - - /* transport parameter is only valid after handshake completion - which means we don't know how many connection ID that remote - peer can accept before handshake completion. */ - if (conn->oscid.datalen && - (conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED)) { - rv = conn_enqueue_new_connection_id(conn); - if (rv != 0) { - return rv; - } - } - - break; - case NGTCP2_PKT_0RTT: - assert(!conn->server); - if (!conn->early.ckm) { - return 0; - } - hd_flags = NGTCP2_PKT_FLAG_LONG_FORM; - cc->ckm = conn->early.ckm; - cc->hp_ctx = conn->early.hp_ctx; - break; - default: - /* Unreachable */ - assert(0); - } - - cc->aead = pktns->crypto.ctx.aead; - cc->hp = pktns->crypto.ctx.hp; - cc->aead_overhead = conn->crypto.aead_overhead; - cc->encrypt = conn->callbacks.encrypt; - cc->hp_mask = conn->callbacks.hp_mask; - - /* TODO Take into account stream frames */ - if ((pktns->tx.frq || send_stream || - ngtcp2_ringbuf_len(&conn->rx.path_challenge) || - conn_should_send_max_data(conn)) && - conn->rx.unsent_max_offset > conn->rx.max_offset) { - rv = ngtcp2_frame_chain_new(&nfrc, conn->mem); - if (rv != 0) { - return rv; - } - nfrc->fr.type = NGTCP2_FRAME_MAX_DATA; - nfrc->fr.max_data.max_data = conn->rx.unsent_max_offset; - nfrc->next = pktns->tx.frq; - pktns->tx.frq = nfrc; - - conn->rx.max_offset = conn->rx.unsent_max_offset; - credit_expanded = 1; - } - - ngtcp2_pkt_hd_init(hd, hd_flags, type, &conn->dcid.current.cid, - &conn->oscid, pktns->tx.last_pkt_num + 1, - pktns_select_pkt_numlen(pktns), conn->version, 0); - - ngtcp2_ppe_init(ppe, dest, destlen, cc); - - rv = ngtcp2_ppe_encode_hd(ppe, hd); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - return 0; - } - - if (!ngtcp2_ppe_ensure_hp_sample(ppe)) { - return 0; - } - - if (ngtcp2_ringbuf_len(&conn->rx.path_challenge)) { - pcent = ngtcp2_ringbuf_get(&conn->rx.path_challenge, 0); - - lfr.type = NGTCP2_FRAME_PATH_RESPONSE; - memcpy(lfr.path_response.data, pcent->data, - sizeof(lfr.path_response.data)); - - rv = conn_ppe_write_frame_hd_log(conn, ppe, &hd_logged, hd, &lfr); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - } else { - ngtcp2_ringbuf_pop_front(&conn->rx.path_challenge); - - pkt_empty = 0; - rtb_entry_flags |= NGTCP2_RTB_FLAG_ACK_ELICITING; - /* We don't retransmit PATH_RESPONSE. */ - } - } - - rv = conn_create_ack_frame( - conn, &ackfr, pktns, type, ts, conn_compute_ack_delay(conn), - conn->local.settings.transport_params.ack_delay_exponent); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - - if (ackfr) { - rv = conn_ppe_write_frame_hd_log(conn, ppe, &hd_logged, hd, ackfr); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - } else { - ngtcp2_acktr_commit_ack(&pktns->acktr); - ngtcp2_acktr_add_ack(&pktns->acktr, hd->pkt_num, - ackfr->ack.largest_ack); - pkt_empty = 0; - } - } - - build_pkt: - for (pfrc = &pktns->tx.frq; *pfrc;) { - if ((*pfrc)->binder && - ((*pfrc)->binder->flags & NGTCP2_FRAME_CHAIN_BINDER_FLAG_ACK)) { - frc = *pfrc; - *pfrc = (*pfrc)->next; - ngtcp2_frame_chain_del(frc, conn->mem); - continue; - } - - switch ((*pfrc)->fr.type) { - case NGTCP2_FRAME_STOP_SENDING: - strm = - ngtcp2_conn_find_stream(conn, (*pfrc)->fr.stop_sending.stream_id); - if (strm == NULL || (strm->flags & NGTCP2_STRM_FLAG_SHUT_RD)) { - frc = *pfrc; - *pfrc = (*pfrc)->next; - ngtcp2_frame_chain_del(frc, conn->mem); - continue; - } - break; - case NGTCP2_FRAME_STREAM: - assert(0); - break; - case NGTCP2_FRAME_MAX_STREAMS_BIDI: - if ((*pfrc)->fr.max_streams.max_streams < - conn->remote.bidi.max_streams) { - frc = *pfrc; - *pfrc = (*pfrc)->next; - ngtcp2_frame_chain_del(frc, conn->mem); - continue; - } - break; - case NGTCP2_FRAME_MAX_STREAMS_UNI: - if ((*pfrc)->fr.max_streams.max_streams < - conn->remote.uni.max_streams) { - frc = *pfrc; - *pfrc = (*pfrc)->next; - ngtcp2_frame_chain_del(frc, conn->mem); - continue; - } - break; - case NGTCP2_FRAME_MAX_STREAM_DATA: - strm = ngtcp2_conn_find_stream(conn, - (*pfrc)->fr.max_stream_data.stream_id); - if (strm == NULL || (strm->flags & NGTCP2_STRM_FLAG_SHUT_RD) || - (*pfrc)->fr.max_stream_data.max_stream_data < strm->rx.max_offset) { - frc = *pfrc; - *pfrc = (*pfrc)->next; - ngtcp2_frame_chain_del(frc, conn->mem); - continue; - } - break; - case NGTCP2_FRAME_MAX_DATA: - if ((*pfrc)->fr.max_data.max_data < conn->rx.max_offset) { - frc = *pfrc; - *pfrc = (*pfrc)->next; - ngtcp2_frame_chain_del(frc, conn->mem); - continue; - } - break; - case NGTCP2_FRAME_CRYPTO: - assert(0); - break; - } - - rv = conn_ppe_write_frame_hd_log(conn, ppe, &hd_logged, hd, &(*pfrc)->fr); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - break; - } - - pkt_empty = 0; - rtb_entry_flags |= - NGTCP2_RTB_FLAG_ACK_ELICITING | NGTCP2_RTB_FLAG_RETRANSMITTABLE; - pfrc = &(*pfrc)->next; - } - - if (rv != NGTCP2_ERR_NOBUF) { - for (; ngtcp2_ksl_len(&pktns->crypto.tx.frq);) { - left = ngtcp2_ppe_left(ppe); - - crypto_offset = conn_cryptofrq_unacked_offset(conn, pktns); - if (crypto_offset == (size_t)-1) { - conn_cryptofrq_clear(conn, pktns); - break; - } - - left = ngtcp2_pkt_crypto_max_datalen(crypto_offset, left, left); - - if (left == (size_t)-1) { - break; - } - - rv = conn_cryptofrq_pop(conn, &nfrc, pktns, left); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - - if (nfrc == NULL) { - break; - } - - rv = conn_ppe_write_frame_hd_log(conn, ppe, &hd_logged, hd, &nfrc->fr); - if (rv != 0) { - assert(0); - } - - *pfrc = nfrc; - pfrc = &(*pfrc)->next; - - pkt_empty = 0; - rtb_entry_flags |= - NGTCP2_RTB_FLAG_ACK_ELICITING | NGTCP2_RTB_FLAG_RETRANSMITTABLE; - } - } - - /* Write MAX_STREAM_ID after RESET_STREAM so that we can extend stream - ID space in one packet. */ - if (rv != NGTCP2_ERR_NOBUF && *pfrc == NULL && - conn->remote.bidi.unsent_max_streams > conn->remote.bidi.max_streams) { - rv = conn_call_extend_max_remote_streams_bidi( - conn, conn->remote.bidi.unsent_max_streams); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - - rv = ngtcp2_frame_chain_new(&nfrc, conn->mem); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - nfrc->fr.type = NGTCP2_FRAME_MAX_STREAMS_BIDI; - nfrc->fr.max_streams.max_streams = conn->remote.bidi.unsent_max_streams; - *pfrc = nfrc; - - conn->remote.bidi.max_streams = conn->remote.bidi.unsent_max_streams; - - rv = conn_ppe_write_frame_hd_log(conn, ppe, &hd_logged, hd, &(*pfrc)->fr); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - } else { - pkt_empty = 0; - rtb_entry_flags |= - NGTCP2_RTB_FLAG_ACK_ELICITING | NGTCP2_RTB_FLAG_RETRANSMITTABLE; - pfrc = &(*pfrc)->next; - } - } - - if (rv != NGTCP2_ERR_NOBUF && *pfrc == NULL) { - if (conn->remote.uni.unsent_max_streams > conn->remote.uni.max_streams) { - rv = conn_call_extend_max_remote_streams_uni( - conn, conn->remote.uni.unsent_max_streams); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - - rv = ngtcp2_frame_chain_new(&nfrc, conn->mem); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - nfrc->fr.type = NGTCP2_FRAME_MAX_STREAMS_UNI; - nfrc->fr.max_streams.max_streams = conn->remote.uni.unsent_max_streams; - *pfrc = nfrc; - - conn->remote.uni.max_streams = conn->remote.uni.unsent_max_streams; - - rv = conn_ppe_write_frame_hd_log(conn, ppe, &hd_logged, hd, - &(*pfrc)->fr); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - } else { - pkt_empty = 0; - rtb_entry_flags |= - NGTCP2_RTB_FLAG_ACK_ELICITING | NGTCP2_RTB_FLAG_RETRANSMITTABLE; - pfrc = &(*pfrc)->next; - } - } - } - - if (rv != NGTCP2_ERR_NOBUF) { - for (; !ngtcp2_pq_empty(&conn->tx.strmq);) { - strm = ngtcp2_conn_tx_strmq_top(conn); - - if (!(strm->flags & NGTCP2_STRM_FLAG_SHUT_RD) && - strm->rx.max_offset < strm->rx.unsent_max_offset) { - rv = ngtcp2_frame_chain_new(&nfrc, conn->mem); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - nfrc->fr.type = NGTCP2_FRAME_MAX_STREAM_DATA; - nfrc->fr.max_stream_data.stream_id = strm->stream_id; - nfrc->fr.max_stream_data.max_stream_data = strm->rx.unsent_max_offset; - ngtcp2_list_insert(nfrc, pfrc); - - rv = - conn_ppe_write_frame_hd_log(conn, ppe, &hd_logged, hd, &nfrc->fr); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - break; - } - - pkt_empty = 0; - credit_expanded = 1; - rtb_entry_flags |= - NGTCP2_RTB_FLAG_ACK_ELICITING | NGTCP2_RTB_FLAG_RETRANSMITTABLE; - pfrc = &(*pfrc)->next; - strm->rx.max_offset = strm->rx.unsent_max_offset; - } - - if (ngtcp2_strm_streamfrq_empty(strm)) { - ngtcp2_conn_tx_strmq_pop(conn); - continue; - } - - stream_offset = ngtcp2_strm_streamfrq_unacked_offset(strm); - if (stream_offset == (uint64_t)-1) { - ngtcp2_strm_streamfrq_clear(strm); - ngtcp2_conn_tx_strmq_pop(conn); - continue; - } - - left = ngtcp2_ppe_left(ppe); - - left = ngtcp2_pkt_stream_max_datalen(strm->stream_id, stream_offset, - left, left); - - if (left == (size_t)-1) { - break; - } - - rv = ngtcp2_strm_streamfrq_pop(strm, &nfrc, left); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - - if (nfrc == NULL) { - /* TODO Why? */ - break; - } - - rv = conn_ppe_write_frame_hd_log(conn, ppe, &hd_logged, hd, &nfrc->fr); - if (rv != 0) { - assert(0); - } - - *pfrc = nfrc; - pfrc = &(*pfrc)->next; - - pkt_empty = 0; - rtb_entry_flags |= - NGTCP2_RTB_FLAG_ACK_ELICITING | NGTCP2_RTB_FLAG_RETRANSMITTABLE; - - if (ngtcp2_strm_streamfrq_empty(strm)) { - ngtcp2_conn_tx_strmq_pop(conn); - continue; - } - - ngtcp2_conn_tx_strmq_pop(conn); - ++strm->cycle; - rv = ngtcp2_conn_tx_strmq_push(conn, strm); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - } - } - - /* Add ACK if MAX_DATA or MAX_STREAM_DATA frame is encoded to - decrease packet count. */ - if (ackfr == NULL && credit_expanded) { - rv = conn_create_ack_frame( - conn, &ackfr, pktns, type, ts, /* ack_delay = */ 0, - conn->local.settings.transport_params.ack_delay_exponent); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - - if (ackfr) { - rv = conn_ppe_write_frame_hd_log(conn, ppe, &hd_logged, hd, ackfr); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - } else { - ngtcp2_acktr_commit_ack(&pktns->acktr); - ngtcp2_acktr_add_ack(&pktns->acktr, hd->pkt_num, - ackfr->ack.largest_ack); - } - } - } - - if (rv != NGTCP2_ERR_NOBUF && !send_stream && - !(rtb_entry_flags & NGTCP2_RTB_FLAG_ACK_ELICITING) && - pktns->rtb.num_retransmittable && pktns->tx.frq == NULL && - pktns->rtb.probe_pkt_left) { - num_reclaimed = ngtcp2_rtb_reclaim_on_pto(&pktns->rtb, conn, pktns, - pktns->rtb.probe_pkt_left + 1); - if (num_reclaimed < 0) { - return rv; - } - if (num_reclaimed) { - goto build_pkt; - } - - /* We had pktns->rtb.num_retransmittable > 0 but the contents of - those packets have been acknowledged (i.e., retransmission in - another packet). In this case, we don't have to send any - probe packet. */ - if (pktns->rtb.num_retransmittable == 0) { - pktns->rtb.probe_pkt_left = 0; - ngtcp2_conn_set_loss_detection_timer(conn, ts); - } - } - } else { - pfrc = conn->pkt.pfrc; - rtb_entry_flags |= conn->pkt.rtb_entry_flags; - pkt_empty = conn->pkt.pkt_empty; - hd_logged = conn->pkt.hd_logged; - } - - left = ngtcp2_ppe_left(ppe); - - if (rv != NGTCP2_ERR_NOBUF && send_stream && *pfrc == NULL && - (ndatalen = ngtcp2_pkt_stream_max_datalen( - vmsg->stream.strm->stream_id, vmsg->stream.strm->tx.offset, ndatalen, - left)) != (size_t)-1 && - (ndatalen || datalen == 0)) { - datacnt = ngtcp2_vec_copy_at_most( - data, &ndatalen, NGTCP2_MAX_STREAM_DATACNT, vmsg->stream.data, - vmsg->stream.datacnt, ndatalen); - - rv = ngtcp2_frame_chain_stream_datacnt_new(&nfrc, datacnt, conn->mem); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - - nfrc->fr.stream.type = NGTCP2_FRAME_STREAM; - nfrc->fr.stream.flags = 0; - nfrc->fr.stream.stream_id = vmsg->stream.strm->stream_id; - nfrc->fr.stream.offset = vmsg->stream.strm->tx.offset; - nfrc->fr.stream.datacnt = datacnt; - ngtcp2_vec_copy(nfrc->fr.stream.data, data, datacnt); - - fin = (vmsg->stream.flags & NGTCP2_WRITE_STREAM_FLAG_FIN) && - ndatalen == datalen; - nfrc->fr.stream.fin = (uint8_t)fin; - - rv = conn_ppe_write_frame_hd_log(conn, ppe, &hd_logged, hd, &nfrc->fr); - if (rv != 0) { - assert(0); - } - - *pfrc = nfrc; - pfrc = &(*pfrc)->next; - - pkt_empty = 0; - rtb_entry_flags |= - NGTCP2_RTB_FLAG_ACK_ELICITING | NGTCP2_RTB_FLAG_RETRANSMITTABLE; - - vmsg->stream.strm->tx.offset += ndatalen; - conn->tx.offset += ndatalen; - - if (fin) { - ngtcp2_strm_shutdown(vmsg->stream.strm, NGTCP2_STRM_FLAG_SHUT_WR); - } - - if (vmsg->stream.pdatalen) { - *vmsg->stream.pdatalen = (ngtcp2_ssize)ndatalen; - } - } else { - send_stream = 0; - } - - if (pkt_empty) { - assert(rv == 0 || NGTCP2_ERR_NOBUF == rv); - if (rv == 0 && stream_blocked && ngtcp2_conn_get_max_data_left(conn)) { - return NGTCP2_ERR_STREAM_DATA_BLOCKED; - } - - if (conn->pktns.rtb.probe_pkt_left == 0) { - return 0; - } - } else if (write_more) { - conn->pkt.pfrc = pfrc; - conn->pkt.pkt_empty = pkt_empty; - conn->pkt.rtb_entry_flags = rtb_entry_flags; - conn->pkt.hd_logged = hd_logged; - conn->flags |= NGTCP2_CONN_FLAG_PPE_PENDING; - - if (send_stream) { - return NGTCP2_ERR_WRITE_MORE; - } - - if (ngtcp2_conn_get_max_data_left(conn) && stream_blocked) { - return NGTCP2_ERR_STREAM_DATA_BLOCKED; - } - } - - if (!(rtb_entry_flags & NGTCP2_RTB_FLAG_ACK_ELICITING)) { - if (pktns->tx.num_non_ack_pkt >= NGTCP2_MAX_NON_ACK_TX_PKT) { - lfr.type = NGTCP2_FRAME_PING; - - rv = conn_ppe_write_frame_hd_log(conn, ppe, &hd_logged, hd, &lfr); - if (rv != 0) { - assert(rv == NGTCP2_ERR_NOBUF); - /* TODO If buffer is too small, PING cannot be written if - packet is still empty. */ - } else { - rtb_entry_flags |= NGTCP2_RTB_FLAG_ACK_ELICITING; - pktns->tx.num_non_ack_pkt = 0; - } - } else { - ++pktns->tx.num_non_ack_pkt; - } - } else { - pktns->tx.num_non_ack_pkt = 0; - } - - /* TODO Push STREAM frame back to ngtcp2_strm if there is an error - before ngtcp2_rtb_entry is safely created and added. */ - lfr.type = NGTCP2_FRAME_PADDING; - if ((require_padding || - /* Making full sized packet will help GSO a bit */ - ngtcp2_ppe_left(ppe) < 10 || - (type == NGTCP2_PKT_0RTT && conn->state == NGTCP2_CS_CLIENT_INITIAL)) && - ngtcp2_ppe_left(ppe)) { - lfr.padding.len = ngtcp2_ppe_padding(ppe); - } else { - lfr.padding.len = ngtcp2_ppe_padding_size(ppe, min_pktlen); - } - - if (lfr.padding.len) { - padded = 1; - ngtcp2_log_tx_fr(&conn->log, hd, &lfr); - ngtcp2_qlog_write_frame(&conn->qlog, &lfr); - } - - nwrite = ngtcp2_ppe_final(ppe, NULL); - if (nwrite < 0) { - assert(ngtcp2_err_is_fatal((int)nwrite)); - return nwrite; - } - - ++cc->ckm->use_count; - - ngtcp2_qlog_pkt_sent_end(&conn->qlog, hd, (size_t)nwrite); - - /* TODO ack-eliciting vs needs-tracking */ - /* probe packet needs tracking but it does not need ACK, could be lost. */ - if ((rtb_entry_flags & NGTCP2_RTB_FLAG_ACK_ELICITING) || padded) { - rv = ngtcp2_rtb_entry_new(&ent, hd, NULL, ts, (size_t)nwrite, - rtb_entry_flags, conn->mem); - if (rv != 0) { - assert(ngtcp2_err_is_fatal((int)nwrite)); - return rv; - } - - if (*pfrc != pktns->tx.frq) { - ent->frc = pktns->tx.frq; - pktns->tx.frq = *pfrc; - *pfrc = NULL; - } - - if ((rtb_entry_flags & NGTCP2_RTB_FLAG_ACK_ELICITING) && - pktns->rtb.num_ack_eliciting == 0 && conn->cc.event) { - conn->cc.event(&conn->cc, &conn->cstat, NGTCP2_CC_EVENT_TYPE_TX_START, - ts); - } - - rv = conn_on_pkt_sent(conn, &pktns->rtb, ent); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_rtb_entry_del(ent, conn->mem); - return rv; - } - - if (rtb_entry_flags & NGTCP2_RTB_FLAG_ACK_ELICITING) { - if (conn->cc.on_pkt_sent) { - conn->cc.on_pkt_sent(&conn->cc, &conn->cstat, - ngtcp2_cc_pkt_init(&cc_pkt, hd->pkt_num, - (size_t)nwrite, - NGTCP2_PKTNS_ID_APP, ts)); - } - - if (conn->flags & NGTCP2_CONN_FLAG_RESTART_IDLE_TIMER_ON_WRITE) { - conn_restart_timer_on_write(conn, ts); - } - } - } - - conn->flags &= (uint16_t)~NGTCP2_CONN_FLAG_PPE_PENDING; - - if (pktns->rtb.probe_pkt_left && - (rtb_entry_flags & NGTCP2_RTB_FLAG_ACK_ELICITING)) { - --pktns->rtb.probe_pkt_left; - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, "probe pkt size=%td", - nwrite); - } - - ngtcp2_qlog_metrics_updated(&conn->qlog, &conn->cstat); - - ++pktns->tx.last_pkt_num; - - return nwrite; -} - -ngtcp2_ssize -ngtcp2_conn_write_single_frame_pkt(ngtcp2_conn *conn, uint8_t *dest, - size_t destlen, uint8_t type, - const ngtcp2_cid *dcid, ngtcp2_frame *fr, - uint8_t rtb_flags, ngtcp2_tstamp ts) { - int rv; - ngtcp2_ppe ppe; - ngtcp2_pkt_hd hd; - ngtcp2_frame lfr; - ngtcp2_ssize nwrite; - ngtcp2_crypto_cc cc; - ngtcp2_pktns *pktns; - uint8_t flags; - ngtcp2_rtb_entry *rtbent; - int padded = 0; - - switch (type) { - case NGTCP2_PKT_INITIAL: - pktns = conn->in_pktns; - cc.aead_overhead = NGTCP2_INITIAL_AEAD_OVERHEAD; - flags = NGTCP2_PKT_FLAG_LONG_FORM; - break; - case NGTCP2_PKT_HANDSHAKE: - pktns = conn->hs_pktns; - cc.aead_overhead = conn->crypto.aead_overhead; - flags = NGTCP2_PKT_FLAG_LONG_FORM; - break; - case NGTCP2_PKT_SHORT: - /* 0 means Short packet. */ - pktns = &conn->pktns; - cc.aead_overhead = conn->crypto.aead_overhead; - flags = (pktns->crypto.tx.ckm->flags & NGTCP2_CRYPTO_KM_FLAG_KEY_PHASE_ONE) - ? NGTCP2_PKT_FLAG_KEY_PHASE - : NGTCP2_PKT_FLAG_NONE; - break; - default: - /* We don't support 0-RTT packet in this function. */ - assert(0); - } - - cc.aead = pktns->crypto.ctx.aead; - cc.hp = pktns->crypto.ctx.hp; - cc.ckm = pktns->crypto.tx.ckm; - cc.hp_ctx = pktns->crypto.tx.hp_ctx; - cc.encrypt = conn->callbacks.encrypt; - cc.hp_mask = conn->callbacks.hp_mask; - - ngtcp2_pkt_hd_init(&hd, flags, type, dcid, &conn->oscid, - pktns->tx.last_pkt_num + 1, pktns_select_pkt_numlen(pktns), - conn->version, 0); - - ngtcp2_ppe_init(&ppe, dest, destlen, &cc); - - rv = ngtcp2_ppe_encode_hd(&ppe, &hd); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - return 0; - } - - if (!ngtcp2_ppe_ensure_hp_sample(&ppe)) { - return 0; - } - - ngtcp2_log_tx_pkt_hd(&conn->log, &hd); - ngtcp2_qlog_pkt_sent_start(&conn->qlog, &hd); - - rv = conn_ppe_write_frame(conn, &ppe, &hd, fr); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - return 0; - } - - lfr.type = NGTCP2_FRAME_PADDING; - if (type == NGTCP2_PKT_SHORT) { - lfr.padding.len = - ngtcp2_ppe_padding_size(&ppe, conn_min_short_pktlen(conn)); - } else { - lfr.padding.len = ngtcp2_ppe_padding_hp_sample(&ppe); - } - if (lfr.padding.len) { - padded = 1; - ngtcp2_log_tx_fr(&conn->log, &hd, &lfr); - ngtcp2_qlog_write_frame(&conn->qlog, &lfr); - } - - nwrite = ngtcp2_ppe_final(&ppe, NULL); - if (nwrite < 0) { - return nwrite; - } - - ++cc.ckm->use_count; - - ngtcp2_qlog_pkt_sent_end(&conn->qlog, &hd, (size_t)nwrite); - - /* Do this when we are sure that there is no error. */ - if (fr->type == NGTCP2_FRAME_ACK) { - ngtcp2_acktr_commit_ack(&pktns->acktr); - ngtcp2_acktr_add_ack(&pktns->acktr, hd.pkt_num, fr->ack.largest_ack); - } - - if ((rtb_flags & NGTCP2_RTB_FLAG_ACK_ELICITING) || padded) { - rv = ngtcp2_rtb_entry_new(&rtbent, &hd, NULL, ts, (size_t)nwrite, rtb_flags, - conn->mem); - if (rv != 0) { - return rv; - } - - rv = conn_on_pkt_sent(conn, &pktns->rtb, rtbent); - if (rv != 0) { - ngtcp2_rtb_entry_del(rtbent, conn->mem); - return rv; - } - - if ((rtb_flags & NGTCP2_RTB_FLAG_ACK_ELICITING) && - (conn->flags & NGTCP2_CONN_FLAG_RESTART_IDLE_TIMER_ON_WRITE)) { - conn_restart_timer_on_write(conn, ts); - } - } - - ngtcp2_qlog_metrics_updated(&conn->qlog, &conn->cstat); - - ++pktns->tx.last_pkt_num; - - return nwrite; -} - -/* - * conn_process_early_rtb makes any pending 0RTT packet Short packet. - */ -static void conn_process_early_rtb(ngtcp2_conn *conn) { - ngtcp2_rtb_entry *ent; - ngtcp2_rtb *rtb = &conn->pktns.rtb; - ngtcp2_ksl_it it; - - for (it = ngtcp2_rtb_head(rtb); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - ent = ngtcp2_ksl_it_get(&it); - - if ((ent->hd.flags & NGTCP2_PKT_FLAG_LONG_FORM) == 0 || - ent->hd.type != NGTCP2_PKT_0RTT) { - continue; - } - - /* 0-RTT packet is retransmitted as a Short packet. */ - ent->hd.flags &= (uint8_t)~NGTCP2_PKT_FLAG_LONG_FORM; - ent->hd.type = NGTCP2_PKT_SHORT; - } -} - -/* - * conn_handshake_remnants_left returns nonzero if there may be - * handshake packets the local endpoint has to send, including new - * packets and lost ones. - */ -static int conn_handshake_remnants_left(ngtcp2_conn *conn) { - ngtcp2_pktns *in_pktns = conn->in_pktns; - ngtcp2_pktns *hs_pktns = conn->hs_pktns; - - return !(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED) || - (in_pktns && (in_pktns->rtb.num_retransmittable || - ngtcp2_ksl_len(&in_pktns->crypto.tx.frq))) || - (hs_pktns && (hs_pktns->rtb.num_retransmittable || - ngtcp2_ksl_len(&hs_pktns->crypto.tx.frq))); -} - -/* - * conn_retire_dcid_seq retires destination connection ID denoted by - * |seq|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int conn_retire_dcid_seq(ngtcp2_conn *conn, uint64_t seq) { - ngtcp2_pktns *pktns = &conn->pktns; - ngtcp2_frame_chain *nfrc; - int rv; - - rv = ngtcp2_frame_chain_new(&nfrc, conn->mem); - if (rv != 0) { - return rv; - } - - nfrc->fr.type = NGTCP2_FRAME_RETIRE_CONNECTION_ID; - nfrc->fr.retire_connection_id.seq = seq; - nfrc->next = pktns->tx.frq; - pktns->tx.frq = nfrc; - - ++conn->dcid.num_retire_queued; - - return 0; -} - -/* - * conn_retire_dcid retires |dcid|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -static int conn_retire_dcid(ngtcp2_conn *conn, const ngtcp2_dcid *dcid, - ngtcp2_tstamp ts) { - ngtcp2_ringbuf *rb = &conn->dcid.retired; - ngtcp2_dcid *dest, *stale_dcid; - int rv; - - if (ngtcp2_ringbuf_full(rb)) { - stale_dcid = ngtcp2_ringbuf_get(rb, 0); - rv = conn_call_deactivate_dcid(conn, stale_dcid); - if (rv != 0) { - return rv; - } - - ngtcp2_ringbuf_pop_front(rb); - } - - dest = ngtcp2_ringbuf_push_back(rb); - ngtcp2_dcid_copy(dest, dcid); - dest->ts_retired = ts; - - return conn_retire_dcid_seq(conn, dcid->seq); -} - -/* - * conn_stop_pv stops the path validation which is currently running. - * This function does nothing if no path validation is currently being - * performed. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -static int conn_stop_pv(ngtcp2_conn *conn, ngtcp2_tstamp ts) { - int rv = 0; - ngtcp2_pv *pv = conn->pv; - - if (pv == NULL) { - return 0; - } - - if (pv->dcid.seq != conn->dcid.current.seq) { - rv = conn_retire_dcid(conn, &pv->dcid, ts); - if (rv != 0) { - goto fin; - } - } - - if ((pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE) && - pv->fallback_dcid.seq != conn->dcid.current.seq && - pv->fallback_dcid.seq != pv->dcid.seq) { - rv = conn_retire_dcid(conn, &pv->fallback_dcid, ts); - if (rv != 0) { - goto fin; - } - } - -fin: - ngtcp2_pv_del(pv); - conn->pv = NULL; - - return rv; -} - -static void conn_reset_congestion_state(ngtcp2_conn *conn); - -/* - * conn_on_path_validation_failed is called when path validation - * fails. This function may delete |pv|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -static int conn_on_path_validation_failed(ngtcp2_conn *conn, ngtcp2_pv *pv, - ngtcp2_tstamp ts) { - int rv; - - rv = conn_call_path_validation(conn, &pv->dcid.ps.path, - NGTCP2_PATH_VALIDATION_RESULT_FAILURE); - if (rv != 0) { - return rv; - } - - if (pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE) { - ngtcp2_dcid_copy(&conn->dcid.current, &pv->fallback_dcid); - conn_reset_congestion_state(conn); - } - - return conn_stop_pv(conn, ts); -} - -/* - * conn_write_path_challenge writes a packet which includes - * PATH_CHALLENGE frame into |dest| of length |destlen|. - * - * This function returns the number of bytes written to |dest|, or one - * of the following negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -static ngtcp2_ssize conn_write_path_challenge(ngtcp2_conn *conn, - ngtcp2_path *path, uint8_t *dest, - size_t destlen, - ngtcp2_tstamp ts) { - int rv; - ngtcp2_tstamp expiry; - ngtcp2_pv *pv = conn->pv; - ngtcp2_frame lfr; - - ngtcp2_pv_ensure_start(pv, ts); - - if (ngtcp2_pv_validation_timed_out(pv, ts)) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PTV, - "path validation was timed out"); - return conn_on_path_validation_failed(conn, pv, ts); - } - - ngtcp2_pv_handle_entry_expiry(pv, ts); - - if (ngtcp2_pv_full(pv)) { - return 0; - } - - if (path) { - ngtcp2_path_copy(path, &pv->dcid.ps.path); - } - - assert(conn->callbacks.rand); - rv = conn->callbacks.rand(lfr.path_challenge.data, - sizeof(lfr.path_challenge.data), - NGTCP2_RAND_CTX_PATH_CHALLENGE); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - lfr.type = NGTCP2_FRAME_PATH_CHALLENGE; - - /* TODO reconsider this. This might get larger pretty quickly than - validation timeout which is just around 3*PTO. */ - expiry = ts + 6ULL * conn->cstat.initial_rtt * (1ULL << pv->loss_count); - - ngtcp2_pv_add_entry(pv, lfr.path_challenge.data, expiry); - - return ngtcp2_conn_write_single_frame_pkt( - conn, dest, destlen, NGTCP2_PKT_SHORT, &pv->dcid.cid, &lfr, - NGTCP2_RTB_FLAG_ACK_ELICITING, ts); -} - -ngtcp2_ssize ngtcp2_conn_write_pkt(ngtcp2_conn *conn, ngtcp2_path *path, - uint8_t *dest, size_t destlen, - ngtcp2_tstamp ts) { - return ngtcp2_conn_writev_stream(conn, path, dest, destlen, - /* pdatalen = */ NULL, - NGTCP2_WRITE_STREAM_FLAG_NONE, - /* stream_id = */ -1, - /* datav = */ NULL, /* datavcnt = */ 0, ts); -} - -/* - * conn_on_version_negotiation is called when Version Negotiation - * packet is received. The function decodes the data in the buffer - * pointed by |payload| whose length is |payloadlen| as Version - * Negotiation packet payload. The packet header is given in |hd|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - * NGTCP2_ERR_INVALID_ARGUMENT - * Packet payload is badly formatted. - */ -static int conn_on_version_negotiation(ngtcp2_conn *conn, - const ngtcp2_pkt_hd *hd, - const uint8_t *payload, - size_t payloadlen) { - uint32_t sv[16]; - uint32_t *p; - int rv = 0; - size_t nsv; - size_t i; - - if (payloadlen % sizeof(uint32_t)) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - if (payloadlen > sizeof(sv)) { - p = ngtcp2_mem_malloc(conn->mem, payloadlen); - if (p == NULL) { - return NGTCP2_ERR_NOMEM; - } - } else { - p = sv; - } - - nsv = ngtcp2_pkt_decode_version_negotiation(p, payload, payloadlen); - - ngtcp2_log_rx_vn(&conn->log, hd, p, nsv); - - for (i = 0; i < nsv; ++i) { - if (p[i] == conn->version) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "ignore Version Negotiation because it contains version " - "selected by client"); - - rv = NGTCP2_ERR_INVALID_ARGUMENT; - goto fin; - } - } - - if (conn->callbacks.recv_version_negotiation) { - rv = conn->callbacks.recv_version_negotiation(conn, hd, p, nsv, - conn->user_data); - if (rv != 0) { - rv = NGTCP2_ERR_CALLBACK_FAILURE; - } - } - - if (rv == 0) { - /* TODO Just move to the terminal state for now in order not to - send CONNECTION_CLOSE frame. */ - conn->state = NGTCP2_CS_DRAINING; - } - -fin: - if (p != sv) { - ngtcp2_mem_free(conn->mem, p); - } - - return rv; -} - -static uint64_t conn_tx_strmq_first_cycle(ngtcp2_conn *conn) { - ngtcp2_strm *strm; - - if (ngtcp2_pq_empty(&conn->tx.strmq)) { - return 0; - } - - strm = ngtcp2_struct_of(ngtcp2_pq_top(&conn->tx.strmq), ngtcp2_strm, pe); - return strm->cycle; -} - -uint64_t ngtcp2_conn_tx_strmq_first_cycle(ngtcp2_conn *conn) { - ngtcp2_strm *strm; - - if (ngtcp2_pq_empty(&conn->tx.strmq)) { - return 0; - } - - strm = ngtcp2_struct_of(ngtcp2_pq_top(&conn->tx.strmq), ngtcp2_strm, pe); - return strm->cycle; -} - -int ngtcp2_conn_resched_frames(ngtcp2_conn *conn, ngtcp2_pktns *pktns, - ngtcp2_frame_chain **pfrc) { - ngtcp2_frame_chain **first = pfrc; - ngtcp2_frame_chain *frc; - ngtcp2_stream *sfr; - ngtcp2_strm *strm; - int rv; - - if (*pfrc == NULL) { - return 0; - } - - for (; *pfrc;) { - switch ((*pfrc)->fr.type) { - case NGTCP2_FRAME_STREAM: - frc = *pfrc; - - *pfrc = frc->next; - frc->next = NULL; - sfr = &frc->fr.stream; - - strm = ngtcp2_conn_find_stream(conn, sfr->stream_id); - if (!strm) { - ngtcp2_frame_chain_del(frc, conn->mem); - break; - } - rv = ngtcp2_strm_streamfrq_push(strm, frc); - if (rv != 0) { - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - if (!ngtcp2_strm_is_tx_queued(strm)) { - strm->cycle = conn_tx_strmq_first_cycle(conn); - rv = ngtcp2_conn_tx_strmq_push(conn, strm); - if (rv != 0) { - return rv; - } - } - break; - case NGTCP2_FRAME_CRYPTO: - frc = *pfrc; - - *pfrc = frc->next; - frc->next = NULL; - - rv = ngtcp2_ksl_insert(&pktns->crypto.tx.frq, NULL, - &frc->fr.crypto.offset, frc); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - break; - default: - pfrc = &(*pfrc)->next; - } - } - - *pfrc = pktns->tx.frq; - pktns->tx.frq = *first; - - return 0; -} - -/* - * conn_on_retry is called when Retry packet is received. The - * function decodes the data in the buffer pointed by |pkt| whose - * length is |pktlen| as Retry packet. The length of long packet - * header is given in |hdpktlen|. |pkt| includes packet header. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - * NGTCP2_ERR_INVALID_ARGUMENT - * Packet payload is badly formatted. - * NGTCP2_ERR_PROTO - * ODCID does not match; or Token is empty. - */ -static int conn_on_retry(ngtcp2_conn *conn, const ngtcp2_pkt_hd *hd, - size_t hdpktlen, const uint8_t *pkt, size_t pktlen) { - int rv; - ngtcp2_pkt_retry retry; - ngtcp2_pktns *in_pktns = conn->in_pktns; - ngtcp2_rtb *rtb = &conn->pktns.rtb; - ngtcp2_rtb *in_rtb; - uint8_t cidbuf[sizeof(retry.odcid.data) * 2 + 1]; - ngtcp2_vec *token; - - if (!in_pktns || conn->flags & NGTCP2_CONN_FLAG_RECV_RETRY) { - return 0; - } - - in_rtb = &in_pktns->rtb; - - rv = ngtcp2_pkt_decode_retry(&retry, pkt + hdpktlen, pktlen - hdpktlen); - if (rv != 0) { - return rv; - } - - retry.odcid = conn->dcid.current.cid; - - rv = ngtcp2_pkt_verify_retry_tag(&retry, pkt, pktlen, conn->callbacks.encrypt, - &conn->crypto.retry_aead, - &conn->crypto.retry_aead_ctx); - if (rv != 0) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "unable to verify Retry packet integrity"); - return rv; - } - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, "odcid=0x%s", - (const char *)ngtcp2_encode_hex(cidbuf, retry.odcid.data, - retry.odcid.datalen)); - - if (retry.token.len == 0) { - return NGTCP2_ERR_PROTO; - } - - if (ngtcp2_cid_eq(&conn->dcid.current.cid, &hd->scid)) { - return 0; - } - - /* DCID must be updated before invoking callback because client - generates new initial keys there. */ - conn->dcid.current.cid = hd->scid; - conn->retry_scid = hd->scid; - - conn->flags |= NGTCP2_CONN_FLAG_RECV_RETRY; - - assert(conn->callbacks.recv_retry); - - rv = conn->callbacks.recv_retry(conn, hd, conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - conn->state = NGTCP2_CS_CLIENT_INITIAL; - - /* Just freeing memory is dangerous because we might free twice. */ - - rv = ngtcp2_rtb_remove_all(rtb, conn, &conn->pktns, &conn->cstat); - if (rv != 0) { - return rv; - } - - rv = ngtcp2_rtb_remove_all(in_rtb, conn, in_pktns, &conn->cstat); - if (rv != 0) { - return rv; - } - - token = &conn->local.settings.token; - - ngtcp2_mem_free(conn->mem, token->base); - token->base = NULL; - token->len = 0; - - token->base = ngtcp2_mem_malloc(conn->mem, retry.token.len); - if (token->base == NULL) { - return NGTCP2_ERR_NOMEM; - } - token->len = retry.token.len; - - ngtcp2_cpymem(token->base, retry.token.base, retry.token.len); - - reset_conn_stat_recovery(&conn->cstat); - conn_reset_congestion_state(conn); - - return 0; -} - -int ngtcp2_conn_detect_lost_pkt(ngtcp2_conn *conn, ngtcp2_pktns *pktns, - ngtcp2_conn_stat *cstat, ngtcp2_tstamp ts) { - int rv; - ngtcp2_duration pto = conn_compute_pto(conn, pktns); - - rv = ngtcp2_rtb_detect_lost_pkt(&pktns->rtb, conn, pktns, cstat, pto, ts); - if (rv != 0) { - return rv; - } - - return 0; -} - -/* - * conn_recv_ack processes received ACK frame |fr|. |pkt_ts| is the - * timestamp when packet is received. |ts| should be the current - * time. Usually they are the same, but for buffered packets, - * |pkt_ts| would be earlier than |ts|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - * NGTCP2_ERR_ACK_FRAME - * ACK frame is malformed. - * NGTCP2_ERR_PROTO - * |fr| acknowledges a packet this endpoint has not sent. - * NGTCP2_ERR_CALLBACK_FAILURE - * User callback failed. - */ -static int conn_recv_ack(ngtcp2_conn *conn, ngtcp2_pktns *pktns, ngtcp2_ack *fr, - ngtcp2_tstamp pkt_ts, ngtcp2_tstamp ts) { - int rv; - ngtcp2_frame_chain *frc = NULL; - ngtcp2_ssize num_acked; - ngtcp2_conn_stat *cstat = &conn->cstat; - - if (pktns->tx.last_pkt_num < fr->largest_ack) { - return NGTCP2_ERR_PROTO; - } - - rv = ngtcp2_pkt_validate_ack(fr); - if (rv != 0) { - return rv; - } - - ngtcp2_acktr_recv_ack(&pktns->acktr, fr); - - num_acked = - ngtcp2_rtb_recv_ack(&pktns->rtb, fr, &conn->cstat, conn, pkt_ts, ts); - if (num_acked < 0) { - /* TODO assert this */ - assert(ngtcp2_err_is_fatal((int)num_acked)); - ngtcp2_frame_chain_list_del(frc, conn->mem); - return (int)num_acked; - } - - if (num_acked == 0) { - return 0; - } - - rv = ngtcp2_conn_detect_lost_pkt(conn, pktns, &conn->cstat, ts); - if (rv != 0) { - return rv; - } - - pktns->rtb.probe_pkt_left = 0; - - if (cstat->pto_count && - (conn->server || (conn->flags & NGTCP2_CONN_FLAG_SERVER_ADDR_VERIFIED))) { - /* Reset PTO count but no less than 2 to avoid frequent probe - packet transmission. */ - cstat->pto_count = ngtcp2_min(cstat->pto_count, 2); - } - - ngtcp2_conn_set_loss_detection_timer(conn, ts); - - return 0; -} - -/* - * conn_assign_recved_ack_delay_unscaled assigns - * fr->ack_delay_unscaled. - */ -static void assign_recved_ack_delay_unscaled(ngtcp2_ack *fr, - uint64_t ack_delay_exponent) { - fr->ack_delay_unscaled = - fr->ack_delay * (1UL << ack_delay_exponent) * NGTCP2_MICROSECONDS; -} - -/* - * conn_recv_max_stream_data processes received MAX_STREAM_DATA frame - * |fr|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_STREAM_STATE - * Stream ID indicates that it is a local stream, and the local - * endpoint has not initiated it; or stream is peer initiated - * unidirectional stream. - * NGTCP2_ERR_STREAM_LIMIT - * Stream ID exceeds allowed limit. - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int conn_recv_max_stream_data(ngtcp2_conn *conn, - const ngtcp2_max_stream_data *fr) { - ngtcp2_strm *strm; - ngtcp2_idtr *idtr; - int local_stream = conn_local_stream(conn, fr->stream_id); - int bidi = bidi_stream(fr->stream_id); - int rv; - - if (bidi) { - if (local_stream) { - if (conn->local.bidi.next_stream_id <= fr->stream_id) { - return NGTCP2_ERR_STREAM_STATE; - } - } else if (conn->remote.bidi.max_streams < - ngtcp2_ord_stream_id(fr->stream_id)) { - return NGTCP2_ERR_STREAM_LIMIT; - } - - idtr = &conn->remote.bidi.idtr; - } else { - if (!local_stream || conn->local.uni.next_stream_id <= fr->stream_id) { - return NGTCP2_ERR_STREAM_STATE; - } - - idtr = &conn->remote.uni.idtr; - } - - strm = ngtcp2_conn_find_stream(conn, fr->stream_id); - if (strm == NULL) { - if (local_stream) { - /* Stream has been closed. */ - return 0; - } - - rv = ngtcp2_idtr_open(idtr, fr->stream_id); - if (rv != 0) { - if (ngtcp2_err_is_fatal(rv)) { - return rv; - } - assert(rv == NGTCP2_ERR_STREAM_IN_USE); - /* Stream has been closed. */ - return 0; - } - - strm = ngtcp2_mem_malloc(conn->mem, sizeof(ngtcp2_strm)); - if (strm == NULL) { - return NGTCP2_ERR_NOMEM; - } - rv = ngtcp2_conn_init_stream(conn, strm, fr->stream_id, NULL); - if (rv != 0) { - ngtcp2_mem_free(conn->mem, strm); - return rv; - } - } - - if (strm->tx.max_offset < fr->max_stream_data) { - strm->tx.max_offset = fr->max_stream_data; - - /* Don't call callback if stream is half-closed local */ - if (strm->flags & NGTCP2_STRM_FLAG_SHUT_WR) { - return 0; - } - - rv = conn_call_extend_max_stream_data(conn, strm, fr->stream_id, - fr->max_stream_data); - if (rv != 0) { - return rv; - } - } - - return 0; -} - -/* - * conn_recv_max_data processes received MAX_DATA frame |fr|. - */ -static void conn_recv_max_data(ngtcp2_conn *conn, const ngtcp2_max_data *fr) { - conn->tx.max_offset = ngtcp2_max(conn->tx.max_offset, fr->max_data); -} - -/* - * conn_buffer_pkt buffers |pkt| of length |pktlen|, chaining it from - * |*ppc|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int conn_buffer_pkt(ngtcp2_conn *conn, ngtcp2_pktns *pktns, - const ngtcp2_path *path, const uint8_t *pkt, - size_t pktlen, ngtcp2_tstamp ts) { - int rv; - ngtcp2_pkt_chain **ppc = &pktns->rx.buffed_pkts, *pc; - size_t i; - for (i = 0; *ppc && i < NGTCP2_MAX_NUM_BUFFED_RX_PKTS; - ppc = &(*ppc)->next, ++i) - ; - - if (i == NGTCP2_MAX_NUM_BUFFED_RX_PKTS) { - return 0; - } - - rv = ngtcp2_pkt_chain_new(&pc, path, pkt, pktlen, ts, conn->mem); - if (rv != 0) { - return rv; - } - - *ppc = pc; - - return 0; -} - -/* - * conn_ensure_decrypt_buffer ensures that conn->crypto.decrypt_buf - * has at least |n| bytes space. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int conn_ensure_decrypt_buffer(ngtcp2_conn *conn, size_t n) { - uint8_t *nbuf; - size_t len; - ngtcp2_vec *decrypt_buf = &conn->crypto.decrypt_buf; - - if (decrypt_buf->len >= n) { - return 0; - } - - len = decrypt_buf->len == 0 ? 2048 : decrypt_buf->len * 2; - for (; len < n; len *= 2) - ; - nbuf = ngtcp2_mem_realloc(conn->mem, decrypt_buf->base, len); - if (nbuf == NULL) { - return NGTCP2_ERR_NOMEM; - } - decrypt_buf->base = nbuf; - decrypt_buf->len = len; - - return 0; -} - -/* - * decrypt_pkt decrypts the data pointed by |payload| whose length is - * |payloadlen|, and writes plaintext data to the buffer pointed by - * |dest|. The buffer pointed by |ad| is the Additional Data, and its - * length is |adlen|. |pkt_num| is used to create a nonce. |ckm| is - * the cryptographic key, and iv to use. |decrypt| is a callback - * function which actually decrypts a packet. - * - * This function returns the number of bytes written in |dest| if it - * succeeds, or one of the following negative error codes: - * - * NGTCP2_ERR_CALLBACK_FAILURE - * User callback failed. - * NGTCP2_ERR_TLS_DECRYPT - * TLS backend failed to decrypt data. - */ -static ngtcp2_ssize decrypt_pkt(uint8_t *dest, const ngtcp2_crypto_aead *aead, - const uint8_t *payload, size_t payloadlen, - const uint8_t *ad, size_t adlen, - int64_t pkt_num, ngtcp2_crypto_km *ckm, - ngtcp2_decrypt decrypt, size_t aead_overhead) { - /* TODO nonce is limited to 64 bytes. */ - uint8_t nonce[64]; - int rv; - - assert(sizeof(nonce) >= ckm->iv.len); - - ngtcp2_crypto_create_nonce(nonce, ckm->iv.base, ckm->iv.len, pkt_num); - - rv = decrypt(dest, aead, &ckm->aead_ctx, payload, payloadlen, nonce, - ckm->iv.len, ad, adlen); - - if (rv != 0) { - if (rv == NGTCP2_ERR_TLS_DECRYPT) { - return rv; - } - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - assert(payloadlen >= aead_overhead); - - return (ngtcp2_ssize)(payloadlen - aead_overhead); -} - -/* - * decrypt_hp decryptes packet header. The packet number starts at - * |pkt| + |pkt_num_offset|. The entire plaintext QUIC packet header - * will be written to the buffer pointed by |dest| whose capacity is - * |destlen|. - * - * This function returns the number of bytes written to |dest|, or one - * of the following negative error codes: - * - * NGTCP2_ERR_PROTO - * Packet is badly formatted - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed; or it does not return - * expected result. - */ -static ngtcp2_ssize decrypt_hp(ngtcp2_pkt_hd *hd, uint8_t *dest, size_t destlen, - const ngtcp2_crypto_cipher *hp, - const uint8_t *pkt, size_t pktlen, - size_t pkt_num_offset, ngtcp2_crypto_km *ckm, - const ngtcp2_crypto_cipher_ctx *hp_ctx, - ngtcp2_hp_mask hp_mask) { - size_t sample_offset; - uint8_t *p = dest; - uint8_t mask[NGTCP2_HP_MASKLEN]; - size_t i; - int rv; - - assert(hp_mask); - assert(ckm); - assert(destlen >= pkt_num_offset + 4); - - if (pkt_num_offset + 4 + NGTCP2_HP_SAMPLELEN > pktlen) { - return NGTCP2_ERR_PROTO; - } - - p = ngtcp2_cpymem(p, pkt, pkt_num_offset); - - sample_offset = pkt_num_offset + 4; - - rv = hp_mask(mask, hp, hp_ctx, pkt + sample_offset); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - if (hd->flags & NGTCP2_PKT_FLAG_LONG_FORM) { - dest[0] = (uint8_t)(dest[0] ^ (mask[0] & 0x0f)); - } else { - dest[0] = (uint8_t)(dest[0] ^ (mask[0] & 0x1f)); - if (dest[0] & NGTCP2_SHORT_KEY_PHASE_BIT) { - hd->flags |= NGTCP2_PKT_FLAG_KEY_PHASE; - } - } - - hd->pkt_numlen = (size_t)((dest[0] & NGTCP2_PKT_NUMLEN_MASK) + 1); - - for (i = 0; i < hd->pkt_numlen; ++i) { - *p++ = *(pkt + pkt_num_offset + i) ^ mask[i + 1]; - } - - hd->pkt_num = ngtcp2_get_pkt_num(p - hd->pkt_numlen, hd->pkt_numlen); - - return p - dest; -} - -/* - * conn_emit_pending_crypto_data delivers pending stream data to the - * application due to packet reordering. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_CALLBACK_FAILURE - * User callback failed - * NGTCP2_ERR_CRYPTO - * TLS backend reported error - */ -static int conn_emit_pending_crypto_data(ngtcp2_conn *conn, - ngtcp2_crypto_level crypto_level, - ngtcp2_strm *strm, - uint64_t rx_offset) { - size_t datalen; - const uint8_t *data; - int rv; - uint64_t offset; - - if (!strm->rx.rob) { - return 0; - } - - for (;;) { - datalen = ngtcp2_rob_data_at(strm->rx.rob, &data, rx_offset); - if (datalen == 0) { - assert(rx_offset == ngtcp2_strm_rx_offset(strm)); - return 0; - } - - offset = rx_offset; - rx_offset += datalen; - - rv = conn_call_recv_crypto_data(conn, crypto_level, offset, data, datalen); - if (rv != 0) { - return rv; - } - - ngtcp2_rob_pop(strm->rx.rob, rx_offset - datalen, datalen); - } -} - -/* - * conn_recv_connection_close is called when CONNECTION_CLOSE or - * APPLICATION_CLOSE frame is received. - */ -static void conn_recv_connection_close(ngtcp2_conn *conn, - ngtcp2_connection_close *fr) { - conn->state = NGTCP2_CS_DRAINING; - if (fr->type == NGTCP2_FRAME_CONNECTION_CLOSE) { - conn->rx.ccec.type = NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT; - } else { - conn->rx.ccec.type = NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION; - } - conn->rx.ccec.error_code = fr->error_code; -} - -static void conn_recv_path_challenge(ngtcp2_conn *conn, - ngtcp2_path_challenge *fr) { - ngtcp2_path_challenge_entry *ent; - - ent = ngtcp2_ringbuf_push_front(&conn->rx.path_challenge); - ngtcp2_path_challenge_entry_init(ent, fr->data); -} - -/* - * conn_reset_congestion_state resets congestion state. - */ -static void conn_reset_congestion_state(ngtcp2_conn *conn) { - conn_reset_conn_stat_cc(conn, &conn->cstat); - - conn_reset_rx_rate(conn); - - conn->cc.reset(&conn->cc); - - if (conn->hs_pktns) { - ngtcp2_rtb_reset_cc_state(&conn->hs_pktns->rtb, - conn->hs_pktns->tx.last_pkt_num + 1); - } - ngtcp2_rtb_reset_cc_state(&conn->pktns.rtb, conn->pktns.tx.last_pkt_num + 1); - ngtcp2_rst_init(&conn->rst); -} - -static int conn_recv_path_response(ngtcp2_conn *conn, ngtcp2_path_response *fr, - ngtcp2_tstamp ts) { - int rv; - ngtcp2_pv *pv = conn->pv; - - if (!pv) { - return 0; - } - - rv = ngtcp2_pv_validate(pv, fr->data); - if (rv != 0) { - if (rv == NGTCP2_ERR_PATH_VALIDATION_FAILED) { - return conn_on_path_validation_failed(conn, pv, ts); - } - return 0; - } - - if (!(pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE)) { - rv = conn_retire_dcid(conn, &conn->dcid.current, ts); - if (rv != 0) { - goto fail; - } - ngtcp2_dcid_copy(&conn->dcid.current, &pv->dcid); - conn_reset_congestion_state(conn); - } - - rv = conn_call_path_validation(conn, &pv->dcid.ps.path, - NGTCP2_PATH_VALIDATION_RESULT_SUCCESS); - if (rv != 0) { - goto fail; - } - -fail: - return conn_stop_pv(conn, ts); -} - -/* - * pkt_num_bits returns the number of bits available when packet - * number is encoded in |pkt_numlen| bytes. - */ -static size_t pkt_num_bits(size_t pkt_numlen) { - switch (pkt_numlen) { - case 1: - return 8; - case 2: - return 16; - case 3: - return 24; - case 4: - return 32; - default: - assert(0); - } -} - -/* - * pktns_pkt_num_is_duplicate returns nonzero if |pkt_num| is - * duplicated packet number. - */ -static int pktns_pkt_num_is_duplicate(ngtcp2_pktns *pktns, int64_t pkt_num) { - return ngtcp2_gaptr_is_pushed(&pktns->rx.pngap, (uint64_t)pkt_num, 1); -} - -/* - * pktns_commit_recv_pkt_num marks packet number |pkt_num| as - * received. - */ -static int pktns_commit_recv_pkt_num(ngtcp2_pktns *pktns, int64_t pkt_num, - ngtcp2_tstamp ts) { - int rv; - - if (pktns->rx.max_pkt_num + 1 != pkt_num) { - ngtcp2_acktr_immediate_ack(&pktns->acktr); - } - if (pktns->rx.max_pkt_num < pkt_num) { - pktns->rx.max_pkt_num = pkt_num; - pktns->rx.max_pkt_ts = ts; - } - - rv = ngtcp2_gaptr_push(&pktns->rx.pngap, (uint64_t)pkt_num, 1); - if (rv != 0) { - return rv; - } - - if (ngtcp2_ksl_len(&pktns->rx.pngap.gap) > 256) { - ngtcp2_gaptr_drop_first_gap(&pktns->rx.pngap); - } - - return 0; -} - -/* - * verify_token verifies |hd| contains |token| in its token field. It - * returns 0 if it succeeds, or NGTCP2_ERR_PROTO. - */ -static int verify_token(const ngtcp2_vec *token, const ngtcp2_pkt_hd *hd) { - if (token->len == hd->token.len && - ngtcp2_cmemeq(token->base, hd->token.base, token->len)) { - return 0; - } - return NGTCP2_ERR_PROTO; -} - -static int conn_recv_crypto(ngtcp2_conn *conn, ngtcp2_crypto_level crypto_level, - ngtcp2_strm *strm, const ngtcp2_crypto *fr); - -static ngtcp2_ssize conn_recv_pkt(ngtcp2_conn *conn, const ngtcp2_path *path, - const uint8_t *pkt, size_t pktlen, - ngtcp2_tstamp pkt_ts, ngtcp2_tstamp ts); - -static int conn_process_buffered_protected_pkt(ngtcp2_conn *conn, - ngtcp2_pktns *pktns, - ngtcp2_tstamp ts); - -/* - * conn_recv_handshake_pkt processes received packet |pkt| whose - * length is |pktlen| during handshake period. The buffer pointed by - * |pkt| might contain multiple packets. This function only processes - * one packet. |pkt_ts| is the timestamp when packet is received. - * |ts| should be the current time. Usually they are the same, but - * for buffered packets, |pkt_ts| would be earlier than |ts|. - * - * This function returns the number of bytes it reads if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_RECV_VERSION_NEGOTIATION - * Version Negotiation packet is received. - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - * NGTCP2_ERR_DISCARD_PKT - * Packet was discarded because plain text header was malformed; - * or its payload could not be decrypted. - * NGTCP2_ERR_FRAME_FORMAT - * Frame is badly formatted - * NGTCP2_ERR_ACK_FRAME - * ACK frame is malformed. - * NGTCP2_ERR_CRYPTO - * TLS stack reported error. - * NGTCP2_ERR_PROTO - * Generic QUIC protocol error. - * - * In addition to the above error codes, error codes returned from - * conn_recv_pkt are also returned. - */ -static ngtcp2_ssize conn_recv_handshake_pkt(ngtcp2_conn *conn, - const ngtcp2_path *path, - const uint8_t *pkt, size_t pktlen, - ngtcp2_tstamp pkt_ts, - ngtcp2_tstamp ts) { - ngtcp2_ssize nread; - ngtcp2_pkt_hd hd; - ngtcp2_max_frame mfr; - ngtcp2_frame *fr = &mfr.fr; - int rv; - int require_ack = 0; - size_t hdpktlen; - const uint8_t *payload; - size_t payloadlen; - ngtcp2_ssize nwrite; - uint8_t plain_hdpkt[1500]; - ngtcp2_crypto_aead *aead; - ngtcp2_crypto_cipher *hp; - ngtcp2_crypto_km *ckm; - ngtcp2_crypto_cipher_ctx *hp_ctx; - ngtcp2_hp_mask hp_mask; - ngtcp2_decrypt decrypt; - size_t aead_overhead; - ngtcp2_pktns *pktns; - ngtcp2_strm *crypto; - ngtcp2_crypto_level crypto_level; - int invalid_reserved_bits = 0; - - if (pktlen == 0) { - return 0; - } - - if (!(pkt[0] & NGTCP2_HEADER_FORM_BIT)) { - if (conn->state == NGTCP2_CS_SERVER_INITIAL) { - /* Ignore Short packet unless server's first Handshake packet - has been transmitted. */ - return (ngtcp2_ssize)pktlen; - } - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, - "buffering Short packet len=%zu", pktlen); - - rv = conn_buffer_pkt(conn, &conn->pktns, path, pkt, pktlen, ts); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - return (ngtcp2_ssize)pktlen; - } - - nread = ngtcp2_pkt_decode_hd_long(&hd, pkt, pktlen); - if (nread < 0) { - return NGTCP2_ERR_DISCARD_PKT; - } - - switch (hd.type) { - case NGTCP2_PKT_VERSION_NEGOTIATION: - hdpktlen = (size_t)nread; - - ngtcp2_log_rx_pkt_hd(&conn->log, &hd); - - if (conn->server) { - return NGTCP2_ERR_DISCARD_PKT; - } - - /* Receiving Version Negotiation packet after getting Handshake - packet from server is invalid. */ - if (conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED) { - return NGTCP2_ERR_DISCARD_PKT; - } - - if (!ngtcp2_cid_eq(&conn->oscid, &hd.dcid)) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was ignored because of mismatched DCID"); - return NGTCP2_ERR_DISCARD_PKT; - } - - if (!ngtcp2_cid_eq(&conn->dcid.current.cid, &hd.scid)) { - /* Just discard invalid Version Negotiation packet */ - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was ignored because of mismatched SCID"); - return NGTCP2_ERR_DISCARD_PKT; - } - rv = conn_on_version_negotiation(conn, &hd, pkt + hdpktlen, - pktlen - hdpktlen); - if (rv != 0) { - if (ngtcp2_err_is_fatal(rv)) { - return rv; - } - return NGTCP2_ERR_DISCARD_PKT; - } - return NGTCP2_ERR_RECV_VERSION_NEGOTIATION; - case NGTCP2_PKT_RETRY: - hdpktlen = (size_t)nread; - - ngtcp2_log_rx_pkt_hd(&conn->log, &hd); - - if (conn->server) { - return NGTCP2_ERR_DISCARD_PKT; - } - - /* Receiving Retry packet after getting Initial packet from server - is invalid. */ - if (conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED) { - return NGTCP2_ERR_DISCARD_PKT; - } - - rv = conn_on_retry(conn, &hd, hdpktlen, pkt, pktlen); - if (rv != 0) { - if (ngtcp2_err_is_fatal(rv)) { - return rv; - } - return NGTCP2_ERR_DISCARD_PKT; - } - return (ngtcp2_ssize)pktlen; - } - - if (pktlen < (size_t)nread + hd.len) { - return NGTCP2_ERR_DISCARD_PKT; - } - - pktlen = (size_t)nread + hd.len; - - if (conn->version != hd.version) { - return NGTCP2_ERR_DISCARD_PKT; - } - - /* Quoted from spec: if subsequent packets of those types include a - different Source Connection ID, they MUST be discarded. */ - if ((conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED) && - !ngtcp2_cid_eq(&conn->dcid.current.cid, &hd.scid)) { - ngtcp2_log_rx_pkt_hd(&conn->log, &hd); - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was ignored because of mismatched SCID"); - return NGTCP2_ERR_DISCARD_PKT; - } - - switch (hd.type) { - case NGTCP2_PKT_0RTT: - if (!conn->server) { - return NGTCP2_ERR_DISCARD_PKT; - } - if (conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED) { - if (conn->early.ckm) { - ngtcp2_ssize nread2; - /* TODO Avoid to parse header twice. */ - nread2 = conn_recv_pkt(conn, &conn->dcid.current.ps.path, pkt, pktlen, - pkt_ts, ts); - if (nread2 < 0) { - return nread2; - } - } - - /* Discard 0-RTT packet if we don't have a key to decrypt it. */ - return (ngtcp2_ssize)pktlen; - } - - /* Buffer re-ordered 0-RTT packet. */ - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, - "buffering 0-RTT packet len=%zu", pktlen); - - rv = conn_buffer_pkt(conn, conn->in_pktns, path, pkt, pktlen, ts); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - - return (ngtcp2_ssize)pktlen; - case NGTCP2_PKT_INITIAL: - if (!conn->in_pktns) { - ngtcp2_log_info( - &conn->log, NGTCP2_LOG_EVENT_PKT, - "Initial packet is discarded because keys have been discarded"); - return (ngtcp2_ssize)pktlen; - } - - assert(conn->in_pktns); - - if (conn->server) { - if (conn->local.settings.token.len) { - rv = verify_token(&conn->local.settings.token, &hd); - if (rv != 0) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was ignored because token is invalid"); - return NGTCP2_ERR_DISCARD_PKT; - } - } - if ((conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED) == 0) { - /* Set rcid here so that it is available to callback. If this - packet is discarded later in this function and no packet is - processed in this connection attempt so far, connection - will be dropped. */ - conn->rcid = hd.dcid; - - rv = conn_call_recv_client_initial(conn, &hd.dcid); - if (rv != 0) { - return rv; - } - } - } else if (hd.token.len != 0) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was ignored because token is not empty"); - return NGTCP2_ERR_DISCARD_PKT; - } - - pktns = conn->in_pktns; - aead_overhead = NGTCP2_INITIAL_AEAD_OVERHEAD; - crypto = &pktns->crypto.strm; - crypto_level = NGTCP2_CRYPTO_LEVEL_INITIAL; - - break; - case NGTCP2_PKT_HANDSHAKE: - if (!conn->hs_pktns->crypto.rx.ckm) { - if (conn->server) { - ngtcp2_log_info( - &conn->log, NGTCP2_LOG_EVENT_PKT, - "Handshake packet at this point is unexpected and discarded"); - return (ngtcp2_ssize)pktlen; - } - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, - "buffering Handshake packet len=%zu", pktlen); - - rv = conn_buffer_pkt(conn, conn->hs_pktns, path, pkt, pktlen, ts); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - return rv; - } - return (ngtcp2_ssize)pktlen; - } - - pktns = conn->hs_pktns; - aead_overhead = conn->crypto.aead_overhead; - crypto = &pktns->crypto.strm; - crypto_level = NGTCP2_CRYPTO_LEVEL_HANDSHAKE; - - break; - default: - /* unknown packet type */ - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was ignored because of unknown packet type"); - return (ngtcp2_ssize)pktlen; - } - - hp_mask = conn->callbacks.hp_mask; - decrypt = conn->callbacks.decrypt; - aead = &pktns->crypto.ctx.aead; - hp = &pktns->crypto.ctx.hp; - ckm = pktns->crypto.rx.ckm; - hp_ctx = &pktns->crypto.rx.hp_ctx; - - assert(ckm); - assert(hp_mask); - assert(decrypt); - - nwrite = decrypt_hp(&hd, plain_hdpkt, sizeof(plain_hdpkt), hp, pkt, pktlen, - (size_t)nread, ckm, hp_ctx, hp_mask); - if (nwrite < 0) { - if (ngtcp2_err_is_fatal((int)nwrite)) { - return nwrite; - } - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "could not decrypt packet number"); - return NGTCP2_ERR_DISCARD_PKT; - } - - hdpktlen = (size_t)nwrite; - payload = pkt + hdpktlen; - payloadlen = hd.len - hd.pkt_numlen; - - hd.pkt_num = ngtcp2_pkt_adjust_pkt_num(pktns->rx.max_pkt_num, hd.pkt_num, - pkt_num_bits(hd.pkt_numlen)); - if (hd.pkt_num > NGTCP2_MAX_PKT_NUM) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "pkn=%" PRId64 " is greater than maximum pkn", hd.pkt_num); - return NGTCP2_ERR_DISCARD_PKT; - } - - ngtcp2_log_rx_pkt_hd(&conn->log, &hd); - - rv = ngtcp2_pkt_verify_reserved_bits(plain_hdpkt[0]); - if (rv != 0) { - invalid_reserved_bits = 1; - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet has incorrect reserved bits"); - - /* Will return error after decrypting payload */ - } - - if (pktns_pkt_num_is_duplicate(pktns, hd.pkt_num)) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was discarded because of duplicated packet number"); - return NGTCP2_ERR_DISCARD_PKT; - } - - rv = conn_ensure_decrypt_buffer(conn, payloadlen); - if (rv != 0) { - return rv; - } - - nwrite = decrypt_pkt(conn->crypto.decrypt_buf.base, aead, payload, payloadlen, - plain_hdpkt, hdpktlen, hd.pkt_num, ckm, decrypt, - aead_overhead); - if (nwrite < 0) { - if (ngtcp2_err_is_fatal((int)nwrite)) { - return nwrite; - } - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "could not decrypt packet payload"); - return NGTCP2_ERR_DISCARD_PKT; - } - - if (invalid_reserved_bits) { - return NGTCP2_ERR_PROTO; - } - - payload = conn->crypto.decrypt_buf.base; - payloadlen = (size_t)nwrite; - - switch (hd.type) { - case NGTCP2_PKT_INITIAL: - if (!conn->server || ((conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED) && - !ngtcp2_cid_eq(&conn->rcid, &hd.dcid))) { - rv = conn_verify_dcid(conn, NULL, &hd); - if (rv != 0) { - if (ngtcp2_err_is_fatal(rv)) { - return rv; - } - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was ignored because of mismatched DCID"); - return NGTCP2_ERR_DISCARD_PKT; - } - } - break; - case NGTCP2_PKT_HANDSHAKE: - rv = conn_verify_dcid(conn, NULL, &hd); - if (rv != 0) { - if (ngtcp2_err_is_fatal(rv)) { - return rv; - } - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was ignored because of mismatched DCID"); - return NGTCP2_ERR_DISCARD_PKT; - } - break; - default: - assert(0); - } - - if (payloadlen == 0) { - /* QUIC packet must contain at least one frame */ - return NGTCP2_ERR_DISCARD_PKT; - } - - if (hd.type == NGTCP2_PKT_INITIAL && - !(conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED)) { - conn->flags |= NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED; - if (!conn->server) { - conn->dcid.current.cid = hd.scid; - } - } - - ngtcp2_qlog_pkt_received_start(&conn->qlog, &hd); - - for (; payloadlen;) { - nread = ngtcp2_pkt_decode_frame(fr, payload, payloadlen); - if (nread < 0) { - return nread; - } - - payload += nread; - payloadlen -= (size_t)nread; - - if (fr->type == NGTCP2_FRAME_ACK) { - fr->ack.ack_delay = 0; - fr->ack.ack_delay_unscaled = 0; - } - - ngtcp2_log_rx_fr(&conn->log, &hd, fr); - - switch (fr->type) { - case NGTCP2_FRAME_ACK: - case NGTCP2_FRAME_ACK_ECN: - if (!conn->server && hd.type == NGTCP2_PKT_HANDSHAKE) { - conn->flags |= NGTCP2_CONN_FLAG_SERVER_ADDR_VERIFIED; - } - rv = conn_recv_ack(conn, pktns, &fr->ack, pkt_ts, ts); - if (rv != 0) { - return rv; - } - break; - case NGTCP2_FRAME_PADDING: - break; - case NGTCP2_FRAME_CRYPTO: - rv = conn_recv_crypto(conn, crypto_level, crypto, &fr->crypto); - if (rv != 0) { - return rv; - } - require_ack = 1; - break; - case NGTCP2_FRAME_CONNECTION_CLOSE: - conn_recv_connection_close(conn, &fr->connection_close); - break; - case NGTCP2_FRAME_PING: - require_ack = 1; - break; - default: - return NGTCP2_ERR_PROTO; - } - - ngtcp2_qlog_write_frame(&conn->qlog, fr); - } - - if (conn->server && hd.type == NGTCP2_PKT_HANDSHAKE) { - /* Successful processing of Handshake packet from client verifies - source address. */ - conn->flags |= NGTCP2_CONN_FLAG_SADDR_VERIFIED; - } - - ngtcp2_qlog_pkt_received_end(&conn->qlog, &hd, pktlen); - - rv = pktns_commit_recv_pkt_num(pktns, hd.pkt_num, pkt_ts); - if (rv != 0) { - return rv; - } - - if (require_ack && ++pktns->acktr.rx_npkt >= NGTCP2_NUM_IMMEDIATE_ACK_PKT) { - ngtcp2_acktr_immediate_ack(&pktns->acktr); - } - - rv = ngtcp2_conn_sched_ack(conn, &pktns->acktr, hd.pkt_num, require_ack, - pkt_ts); - if (rv != 0) { - return rv; - } - - conn_restart_timer_on_read(conn, ts); - - ngtcp2_qlog_metrics_updated(&conn->qlog, &conn->cstat); - - return conn->state == NGTCP2_CS_DRAINING ? NGTCP2_ERR_DRAINING - : (ngtcp2_ssize)pktlen; -} - -/* - * conn_recv_handshake_cpkt processes compound packet during - * handshake. The buffer pointed by |pkt| might contain multiple - * packets. The Short packet must be the last one because it does not - * have payload length field. - * - * This function returns the same error code returned by - * conn_recv_handshake_pkt. - */ -static int conn_recv_handshake_cpkt(ngtcp2_conn *conn, const ngtcp2_path *path, - const uint8_t *pkt, size_t pktlen, - ngtcp2_tstamp ts) { - ngtcp2_ssize nread; - - conn->cstat.bytes_recv += pktlen; - - while (pktlen) { - nread = conn_recv_handshake_pkt(conn, path, pkt, pktlen, ts, ts); - if (nread < 0) { - if (ngtcp2_err_is_fatal((int)nread)) { - return (int)nread; - } - - if (nread == NGTCP2_ERR_DRAINING) { - return NGTCP2_ERR_DRAINING; - } - - if ((pkt[0] & NGTCP2_HEADER_FORM_BIT) && - /* Not a Version Negotiation packet */ - pktlen > 4 && ngtcp2_get_uint32(&pkt[1]) > 0 && - ngtcp2_pkt_get_type_long(pkt[0]) == NGTCP2_PKT_INITIAL) { - if (conn->server) { - /* If server discards first Initial, then drop connection - state. This is because SCID in packet might be corrupted - and the current connection state might wrongly discard - valid packet and prevent the handshake from - completing. */ - if (conn->in_pktns && conn->in_pktns->rx.max_pkt_num == -1) { - /* If this is crypto related error, then return normally - in order to send CONNECTION_CLOSE with TLS alert (e.g., - no_application_protocol). */ - if (nread == NGTCP2_ERR_CRYPTO) { - return (int)nread; - } - return NGTCP2_ERR_DROP_CONN; - } - } else if (nread == NGTCP2_ERR_CRYPTO) { - /* If client gets crypto error from TLS stack, it is - unrecoverable, therefore drop connection. */ - return (int)nread; - } - return 0; - } - - if (nread == NGTCP2_ERR_DISCARD_PKT) { - return 0; - } - - return (int)nread; - } - - assert(pktlen >= (size_t)nread); - pkt += nread; - pktlen -= (size_t)nread; - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "read packet %td left %zu", nread, pktlen); - } - - return 0; -} - -int ngtcp2_conn_init_stream(ngtcp2_conn *conn, ngtcp2_strm *strm, - int64_t stream_id, void *stream_user_data) { - int rv; - uint64_t max_rx_offset; - uint64_t max_tx_offset; - int local_stream = conn_local_stream(conn, stream_id); - - if (bidi_stream(stream_id)) { - if (local_stream) { - max_rx_offset = conn->local.settings.transport_params - .initial_max_stream_data_bidi_local; - max_tx_offset = - conn->remote.transport_params.initial_max_stream_data_bidi_remote; - } else { - max_rx_offset = conn->local.settings.transport_params - .initial_max_stream_data_bidi_remote; - max_tx_offset = - conn->remote.transport_params.initial_max_stream_data_bidi_local; - } - } else if (local_stream) { - max_rx_offset = 0; - max_tx_offset = conn->remote.transport_params.initial_max_stream_data_uni; - } else { - max_rx_offset = - conn->local.settings.transport_params.initial_max_stream_data_uni; - max_tx_offset = 0; - } - - rv = ngtcp2_strm_init(strm, stream_id, NGTCP2_STRM_FLAG_NONE, max_rx_offset, - max_tx_offset, stream_user_data, conn->mem); - if (rv != 0) { - return rv; - } - - rv = ngtcp2_map_insert(&conn->strms, &strm->me); - if (rv != 0) { - assert(rv != NGTCP2_ERR_INVALID_ARGUMENT); - goto fail; - } - - if (!conn_local_stream(conn, stream_id)) { - rv = conn_call_stream_open(conn, strm); - if (rv != 0) { - goto fail; - } - } - - return 0; - -fail: - ngtcp2_strm_free(strm); - return rv; -} - -/* - * conn_emit_pending_stream_data passes buffered ordered stream data - * to the application. |rx_offset| is the first offset to deliver to - * the application. This function assumes that the data up to - * |rx_offset| has been delivered already. This function only passes - * the ordered data without any gap. If there is a gap, it stops - * providing the data to the application, and returns. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_CALLBACK_FAILURE - * User callback failed. - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int conn_emit_pending_stream_data(ngtcp2_conn *conn, ngtcp2_strm *strm, - uint64_t rx_offset) { - size_t datalen; - const uint8_t *data; - int rv; - uint64_t offset; - uint32_t sdflags; - int handshake_completed = conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED; - - if (!strm->rx.rob) { - return 0; - } - - for (;;) { - /* Stop calling callback if application has called - ngtcp2_conn_shutdown_stream_read() inside the callback. - Because it doubly counts connection window. */ - if (strm->flags & (NGTCP2_STRM_FLAG_STOP_SENDING)) { - return 0; - } - - datalen = ngtcp2_rob_data_at(strm->rx.rob, &data, rx_offset); - if (datalen == 0) { - assert(rx_offset == ngtcp2_strm_rx_offset(strm)); - return 0; - } - - offset = rx_offset; - rx_offset += datalen; - - sdflags = NGTCP2_STREAM_DATA_FLAG_NONE; - if ((strm->flags & NGTCP2_STRM_FLAG_SHUT_RD) && - rx_offset == strm->rx.last_offset) { - sdflags |= NGTCP2_STREAM_DATA_FLAG_FIN; - } - if (!handshake_completed) { - sdflags |= NGTCP2_STREAM_DATA_FLAG_0RTT; - } - - rv = conn_call_recv_stream_data(conn, strm, sdflags, offset, data, datalen); - if (rv != 0) { - return rv; - } - - ngtcp2_rob_pop(strm->rx.rob, rx_offset - datalen, datalen); - } -} - -/* - * conn_recv_crypto is called when CRYPTO frame |fr| is received. - * |rx_offset_base| is the offset in the entire TLS handshake stream. - * fr->offset specifies the offset in each encryption level. - * |max_rx_offset| is, if it is nonzero, the maximum offset in the - * entire TLS handshake stream that |fr| can carry. |crypto_level| is - * the encryption level where this data is received. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_PROTO - * CRYPTO frame has invalid offset. - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CRYPTO - * TLS stack reported error. - * NGTCP2_ERR_FRAME_ENCODING - * The end offset exceeds the maximum value. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -static int conn_recv_crypto(ngtcp2_conn *conn, ngtcp2_crypto_level crypto_level, - ngtcp2_strm *crypto, const ngtcp2_crypto *fr) { - uint64_t fr_end_offset; - uint64_t rx_offset; - int rv; - - if (fr->datacnt == 0) { - return 0; - } - - fr_end_offset = fr->offset + fr->data[0].len; - - if (NGTCP2_MAX_VARINT < fr_end_offset) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - rx_offset = ngtcp2_strm_rx_offset(crypto); - - if (fr_end_offset <= rx_offset) { - if (conn->server && crypto_level == NGTCP2_CRYPTO_LEVEL_INITIAL) { - /* recovery draft: Speeding Up Handshake Completion - - When a server receives an Initial packet containing duplicate - CRYPTO data, it can assume the client did not receive all of - the server's CRYPTO data sent in Initial packets, or the - client's estimated RTT is too small. ... To speed up - handshake completion under these conditions, an endpoint MAY - send a packet containing unacknowledged CRYPTO data earlier - than the PTO expiry, subject to address validation limits; - ... */ - conn->in_pktns->rtb.probe_pkt_left = 1; - conn->hs_pktns->rtb.probe_pkt_left = 1; - } - return 0; - } - - crypto->rx.last_offset = ngtcp2_max(crypto->rx.last_offset, fr_end_offset); - - /* TODO Before dispatching incoming data to TLS stack, make sure - that previous data in previous encryption level has been - completely sent to TLS stack. Usually, if data is left, it is an - error because key is generated after consuming all data in the - previous encryption level. */ - if (fr->offset <= rx_offset) { - size_t ncut = (size_t)(rx_offset - fr->offset); - const uint8_t *data = fr->data[0].base + ncut; - size_t datalen = fr->data[0].len - ncut; - uint64_t offset = rx_offset; - - rx_offset += datalen; - rv = ngtcp2_strm_update_rx_offset(crypto, rx_offset); - if (rv != 0) { - return rv; - } - - rv = conn_call_recv_crypto_data(conn, crypto_level, offset, data, datalen); - if (rv != 0) { - return rv; - } - - rv = conn_emit_pending_crypto_data(conn, crypto_level, crypto, rx_offset); - if (rv != 0) { - return rv; - } - } else if (fr_end_offset - rx_offset > NGTCP2_MAX_REORDERED_CRYPTO_DATA) { - return NGTCP2_ERR_CRYPTO_BUFFER_EXCEEDED; - } else { - rv = ngtcp2_strm_recv_reordering(crypto, fr->data[0].base, fr->data[0].len, - fr->offset); - if (rv != 0) { - return rv; - } - } - - return 0; -} - -/* - * conn_max_data_violated returns nonzero if receiving |datalen| - * violates connection flow control on local endpoint. - */ -static int conn_max_data_violated(ngtcp2_conn *conn, uint64_t datalen) { - return conn->rx.max_offset - conn->rx.offset < datalen; -} - -/* - * conn_recv_stream is called when STREAM frame |fr| is received. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_STREAM_STATE - * STREAM frame is received for a local stream which is not - * initiated; or STREAM frame is received for a local - * unidirectional stream - * NGTCP2_ERR_STREAM_LIMIT - * STREAM frame has remote stream ID which is strictly greater - * than the allowed limit. - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - * NGTCP2_ERR_FLOW_CONTROL - * Flow control limit is violated; or the end offset of stream - * data is beyond the NGTCP2_MAX_VARINT. - * NGTCP2_ERR_FINAL_SIZE - * STREAM frame has strictly larger end offset than it is - * permitted. - */ -static int conn_recv_stream(ngtcp2_conn *conn, const ngtcp2_stream *fr, - ngtcp2_tstamp ts) { - int rv; - ngtcp2_strm *strm; - ngtcp2_idtr *idtr; - uint64_t rx_offset, fr_end_offset; - int local_stream; - int bidi; - size_t datalen = ngtcp2_vec_len(fr->data, fr->datacnt); - uint32_t sdflags = NGTCP2_STREAM_DATA_FLAG_NONE; - - local_stream = conn_local_stream(conn, fr->stream_id); - bidi = bidi_stream(fr->stream_id); - - if (bidi) { - if (local_stream) { - if (conn->local.bidi.next_stream_id <= fr->stream_id) { - return NGTCP2_ERR_STREAM_STATE; - } - } else if (conn->remote.bidi.max_streams < - ngtcp2_ord_stream_id(fr->stream_id)) { - return NGTCP2_ERR_STREAM_LIMIT; - } - - idtr = &conn->remote.bidi.idtr; - } else { - if (local_stream) { - return NGTCP2_ERR_STREAM_STATE; - } - if (conn->remote.uni.max_streams < ngtcp2_ord_stream_id(fr->stream_id)) { - return NGTCP2_ERR_STREAM_LIMIT; - } - - idtr = &conn->remote.uni.idtr; - } - - if (NGTCP2_MAX_VARINT - datalen < fr->offset) { - return NGTCP2_ERR_FLOW_CONTROL; - } - - strm = ngtcp2_conn_find_stream(conn, fr->stream_id); - if (strm == NULL) { - if (local_stream) { - /* TODO The stream has been closed. This should be responded - with RESET_STREAM, or simply ignored. */ - return 0; - } - - rv = ngtcp2_idtr_open(idtr, fr->stream_id); - if (rv != 0) { - if (ngtcp2_err_is_fatal(rv)) { - return rv; - } - assert(rv == NGTCP2_ERR_STREAM_IN_USE); - /* TODO The stream has been closed. This should be responded - with RESET_STREAM, or simply ignored. */ - return 0; - } - - strm = ngtcp2_mem_malloc(conn->mem, sizeof(ngtcp2_strm)); - if (strm == NULL) { - return NGTCP2_ERR_NOMEM; - } - /* TODO Perhaps, call new_stream callback? */ - rv = ngtcp2_conn_init_stream(conn, strm, fr->stream_id, NULL); - if (rv != 0) { - ngtcp2_mem_free(conn->mem, strm); - return rv; - } - if (!bidi) { - ngtcp2_strm_shutdown(strm, NGTCP2_STRM_FLAG_SHUT_WR); - } - } - - fr_end_offset = fr->offset + datalen; - - if (strm->rx.max_offset < fr_end_offset) { - return NGTCP2_ERR_FLOW_CONTROL; - } - - if (strm->rx.last_offset < fr_end_offset) { - uint64_t len = fr_end_offset - strm->rx.last_offset; - - if (conn_max_data_violated(conn, len)) { - return NGTCP2_ERR_FLOW_CONTROL; - } - - conn->rx.offset += len; - - if (strm->flags & NGTCP2_STRM_FLAG_STOP_SENDING) { - ngtcp2_conn_extend_max_offset(conn, len); - } - } - - rx_offset = ngtcp2_strm_rx_offset(strm); - - if (fr->fin) { - if (strm->flags & NGTCP2_STRM_FLAG_SHUT_RD) { - if (strm->rx.last_offset != fr_end_offset) { - return NGTCP2_ERR_FINAL_SIZE; - } - - if (strm->flags & - (NGTCP2_STRM_FLAG_STOP_SENDING | NGTCP2_STRM_FLAG_RECV_RST)) { - return 0; - } - - if (rx_offset == fr_end_offset) { - return 0; - } - } else if (strm->rx.last_offset > fr_end_offset) { - return NGTCP2_ERR_FINAL_SIZE; - } else { - strm->rx.last_offset = fr_end_offset; - - ngtcp2_strm_shutdown(strm, NGTCP2_STRM_FLAG_SHUT_RD); - - if (strm->flags & NGTCP2_STRM_FLAG_STOP_SENDING) { - return ngtcp2_conn_close_stream_if_shut_rdwr(conn, strm, - strm->app_error_code); - } - } - } else { - if ((strm->flags & NGTCP2_STRM_FLAG_SHUT_RD) && - strm->rx.last_offset < fr_end_offset) { - return NGTCP2_ERR_FINAL_SIZE; - } - - strm->rx.last_offset = ngtcp2_max(strm->rx.last_offset, fr_end_offset); - - if (fr_end_offset <= rx_offset) { - return 0; - } - - if (strm->flags & - (NGTCP2_STRM_FLAG_STOP_SENDING | NGTCP2_STRM_FLAG_RECV_RST)) { - return 0; - } - } - - conn_update_recv_rate(conn, fr_end_offset - fr->offset, ts); - - if (fr->offset <= rx_offset) { - size_t ncut = (size_t)(rx_offset - fr->offset); - uint64_t offset = rx_offset; - const uint8_t *data; - int fin; - - if (fr->datacnt) { - data = fr->data[0].base + ncut; - datalen -= ncut; - - rx_offset += datalen; - rv = ngtcp2_strm_update_rx_offset(strm, rx_offset); - if (rv != 0) { - return rv; - } - } else { - data = NULL; - datalen = 0; - } - - fin = (strm->flags & NGTCP2_STRM_FLAG_SHUT_RD) && - rx_offset == strm->rx.last_offset; - - if (fin || datalen) { - if (fin) { - sdflags |= NGTCP2_STREAM_DATA_FLAG_FIN; - } - if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED)) { - sdflags |= NGTCP2_STREAM_DATA_FLAG_0RTT; - } - rv = conn_call_recv_stream_data(conn, strm, sdflags, offset, data, - datalen); - if (rv != 0) { - return rv; - } - - rv = conn_emit_pending_stream_data(conn, strm, rx_offset); - if (rv != 0) { - return rv; - } - } - } else if (fr->datacnt) { - rv = ngtcp2_strm_recv_reordering(strm, fr->data[0].base, fr->data[0].len, - fr->offset); - if (rv != 0) { - return rv; - } - } - return ngtcp2_conn_close_stream_if_shut_rdwr(conn, strm, NGTCP2_NO_ERROR); -} - -/* - * conn_reset_stream adds RESET_STREAM frame to the transmission - * queue. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int conn_reset_stream(ngtcp2_conn *conn, ngtcp2_strm *strm, - uint64_t app_error_code) { - int rv; - ngtcp2_frame_chain *frc; - ngtcp2_pktns *pktns = &conn->pktns; - - rv = ngtcp2_frame_chain_new(&frc, conn->mem); - if (rv != 0) { - return rv; - } - - frc->fr.type = NGTCP2_FRAME_RESET_STREAM; - frc->fr.reset_stream.stream_id = strm->stream_id; - frc->fr.reset_stream.app_error_code = app_error_code; - frc->fr.reset_stream.final_size = strm->tx.offset; - - /* TODO This prepends RESET_STREAM to pktns->tx.frq. */ - frc->next = pktns->tx.frq; - pktns->tx.frq = frc; - - return 0; -} - -/* - * conn_stop_sending adds STOP_SENDING frame to the transmission - * queue. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int conn_stop_sending(ngtcp2_conn *conn, ngtcp2_strm *strm, - uint64_t app_error_code) { - int rv; - ngtcp2_frame_chain *frc; - ngtcp2_pktns *pktns = &conn->pktns; - - rv = ngtcp2_frame_chain_new(&frc, conn->mem); - if (rv != 0) { - return rv; - } - - frc->fr.type = NGTCP2_FRAME_STOP_SENDING; - frc->fr.stop_sending.stream_id = strm->stream_id; - frc->fr.stop_sending.app_error_code = app_error_code; - - /* TODO This prepends STOP_SENDING to pktns->tx.frq. */ - frc->next = pktns->tx.frq; - pktns->tx.frq = frc; - - return 0; -} - -/* - * handle_max_remote_streams_extension extends - * |*punsent_max_remote_streams| by |n| if a condition allows it. - */ -static void -handle_max_remote_streams_extension(uint64_t *punsent_max_remote_streams, - size_t n) { - if ( -#if SIZE_MAX > UINT32_MAX - NGTCP2_MAX_STREAMS < n || -#endif /* SIZE_MAX > UINT32_MAX */ - *punsent_max_remote_streams > (uint64_t)(NGTCP2_MAX_STREAMS - n)) { - *punsent_max_remote_streams = NGTCP2_MAX_STREAMS; - } else { - *punsent_max_remote_streams += n; - } -} - -/* - * conn_recv_reset_stream is called when RESET_STREAM |fr| is - * received. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_STREAM_STATE - * RESET_STREAM frame is received to the local stream which is not - * initiated. - * NGTCP2_ERR_STREAM_LIMIT - * RESET_STREAM frame has remote stream ID which is strictly - * greater than the allowed limit. - * NGTCP2_ERR_PROTO - * RESET_STREAM frame is received to the local unidirectional - * stream - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - * NGTCP2_ERR_FLOW_CONTROL - * Flow control limit is violated; or the final size is beyond the - * NGTCP2_MAX_VARINT. - * NGTCP2_ERR_FINAL_SIZE - * The final offset is strictly larger than it is permitted. - */ -static int conn_recv_reset_stream(ngtcp2_conn *conn, - const ngtcp2_reset_stream *fr) { - ngtcp2_strm *strm; - int local_stream = conn_local_stream(conn, fr->stream_id); - int bidi = bidi_stream(fr->stream_id); - uint64_t datalen; - ngtcp2_idtr *idtr; - int rv; - - /* TODO share this piece of code */ - if (bidi) { - if (local_stream) { - if (conn->local.bidi.next_stream_id <= fr->stream_id) { - return NGTCP2_ERR_STREAM_STATE; - } - } else if (conn->remote.bidi.max_streams < - ngtcp2_ord_stream_id(fr->stream_id)) { - return NGTCP2_ERR_STREAM_LIMIT; - } - - idtr = &conn->remote.bidi.idtr; - } else { - if (local_stream) { - return NGTCP2_ERR_PROTO; - } - if (conn->remote.uni.max_streams < ngtcp2_ord_stream_id(fr->stream_id)) { - return NGTCP2_ERR_STREAM_LIMIT; - } - - idtr = &conn->remote.uni.idtr; - } - - if (NGTCP2_MAX_VARINT < fr->final_size) { - return NGTCP2_ERR_FLOW_CONTROL; - } - - strm = ngtcp2_conn_find_stream(conn, fr->stream_id); - if (strm == NULL) { - if (local_stream) { - return 0; - } - - if (conn_initial_stream_rx_offset(conn, fr->stream_id) < fr->final_size || - conn_max_data_violated(conn, fr->final_size)) { - return NGTCP2_ERR_FLOW_CONTROL; - } - rv = ngtcp2_idtr_open(idtr, fr->stream_id); - if (rv != 0) { - if (ngtcp2_err_is_fatal(rv)) { - return rv; - } - assert(rv == NGTCP2_ERR_STREAM_IN_USE); - return 0; - } - - /* Stream is reset before we create ngtcp2_strm object. */ - conn->rx.offset += fr->final_size; - ngtcp2_conn_extend_max_offset(conn, fr->final_size); - - rv = conn_call_stream_reset(conn, fr->stream_id, fr->final_size, - fr->app_error_code, NULL); - if (rv != 0) { - return rv; - } - - /* There will be no activity in this stream because we got - RESET_STREAM and don't write stream data any further. This - effectively allows another new stream for peer. */ - if (bidi) { - handle_max_remote_streams_extension(&conn->remote.bidi.unsent_max_streams, - 1); - } else { - handle_max_remote_streams_extension(&conn->remote.uni.unsent_max_streams, - 1); - } - - return 0; - } - - if ((strm->flags & NGTCP2_STRM_FLAG_SHUT_RD)) { - if (strm->rx.last_offset != fr->final_size) { - return NGTCP2_ERR_FINAL_SIZE; - } - } else if (strm->rx.last_offset > fr->final_size) { - return NGTCP2_ERR_FINAL_SIZE; - } - - datalen = fr->final_size - strm->rx.last_offset; - - if (strm->rx.max_offset < fr->final_size || - conn_max_data_violated(conn, datalen)) { - return NGTCP2_ERR_FLOW_CONTROL; - } - - if (!(strm->flags & NGTCP2_STRM_FLAG_RECV_RST)) { - rv = conn_call_stream_reset(conn, fr->stream_id, fr->final_size, - fr->app_error_code, strm->stream_user_data); - if (rv != 0) { - return rv; - } - - /* Extend connection flow control window for the amount of data - which are not passed to application. */ - if (!(strm->flags & NGTCP2_STRM_FLAG_STOP_SENDING)) { - ngtcp2_conn_extend_max_offset(conn, strm->rx.last_offset - - ngtcp2_strm_rx_offset(strm)); - } - } - - conn->rx.offset += datalen; - ngtcp2_conn_extend_max_offset(conn, datalen); - - strm->rx.last_offset = fr->final_size; - strm->flags |= NGTCP2_STRM_FLAG_SHUT_RD | NGTCP2_STRM_FLAG_RECV_RST; - - return ngtcp2_conn_close_stream_if_shut_rdwr(conn, strm, fr->app_error_code); -} - -/* - * conn_recv_stop_sending is called when STOP_SENDING |fr| is received. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_STREAM_STATE - * STOP_SENDING frame is received for a local stream which is not - * initiated; or STOP_SENDING frame is received for a local - * unidirectional stream. - * NGTCP2_ERR_STREAM_LIMIT - * STOP_SENDING frame has remote stream ID which is strictly - * greater than the allowed limit. - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -static int conn_recv_stop_sending(ngtcp2_conn *conn, - const ngtcp2_stop_sending *fr) { - int rv; - ngtcp2_strm *strm; - ngtcp2_idtr *idtr; - int local_stream = conn_local_stream(conn, fr->stream_id); - int bidi = bidi_stream(fr->stream_id); - - if (bidi) { - if (local_stream) { - if (conn->local.bidi.next_stream_id <= fr->stream_id) { - return NGTCP2_ERR_STREAM_STATE; - } - } else if (conn->remote.bidi.max_streams < - ngtcp2_ord_stream_id(fr->stream_id)) { - return NGTCP2_ERR_STREAM_LIMIT; - } - - idtr = &conn->remote.bidi.idtr; - } else { - if (!local_stream || conn->local.uni.next_stream_id <= fr->stream_id) { - return NGTCP2_ERR_STREAM_STATE; - } - - idtr = &conn->remote.uni.idtr; - } - - strm = ngtcp2_conn_find_stream(conn, fr->stream_id); - if (strm == NULL) { - if (local_stream) { - return 0; - } - rv = ngtcp2_idtr_open(idtr, fr->stream_id); - if (rv != 0) { - if (ngtcp2_err_is_fatal(rv)) { - return rv; - } - assert(rv == NGTCP2_ERR_STREAM_IN_USE); - return 0; - } - - /* Frame is received reset before we create ngtcp2_strm - object. */ - strm = ngtcp2_mem_malloc(conn->mem, sizeof(ngtcp2_strm)); - if (strm == NULL) { - return NGTCP2_ERR_NOMEM; - } - rv = ngtcp2_conn_init_stream(conn, strm, fr->stream_id, NULL); - if (rv != 0) { - ngtcp2_mem_free(conn->mem, strm); - return rv; - } - } - - /* No RESET_STREAM is required if we have sent FIN and all data have - been acknowledged. */ - if ((strm->flags & NGTCP2_STRM_FLAG_SHUT_WR) && - ngtcp2_strm_is_all_tx_data_acked(strm)) { - return 0; - } - - rv = conn_reset_stream(conn, strm, fr->app_error_code); - if (rv != 0) { - return rv; - } - - strm->flags |= NGTCP2_STRM_FLAG_SHUT_WR | NGTCP2_STRM_FLAG_SENT_RST; - - ngtcp2_strm_streamfrq_clear(strm); - - return ngtcp2_conn_close_stream_if_shut_rdwr(conn, strm, fr->app_error_code); -} - -/* - * check_stateless_reset returns nonzero if Stateless Reset |sr| - * coming via |path| is valid against |dcid|. - */ -static int check_stateless_reset(const ngtcp2_dcid *dcid, - const ngtcp2_path *path, - const ngtcp2_pkt_stateless_reset *sr) { - return ngtcp2_path_eq(&dcid->ps.path, path) && - ngtcp2_verify_stateless_reset_token(dcid->token, - sr->stateless_reset_token) == 0; -} - -/* - * conn_on_stateless_reset decodes Stateless Reset from the buffer - * pointed by |payload| whose length is |payloadlen|. |payload| - * should start after first byte of packet. - * - * If Stateless Reset is decoded, and the Stateless Reset Token is - * validated, the connection is closed. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_INVALID_ARGUMENT - * Could not decode Stateless Reset; or Stateless Reset Token does - * not match; or No stateless reset token is available. - * NGTCP2_ERR_CALLBACK_FAILURE - * User callback failed. - */ -static int conn_on_stateless_reset(ngtcp2_conn *conn, const ngtcp2_path *path, - const uint8_t *payload, size_t payloadlen) { - int rv = 1; - ngtcp2_pv *pv = conn->pv; - ngtcp2_dcid *dcid; - ngtcp2_pkt_stateless_reset sr; - size_t len, i; - - rv = ngtcp2_pkt_decode_stateless_reset(&sr, payload, payloadlen); - if (rv != 0) { - return rv; - } - - if (!check_stateless_reset(&conn->dcid.current, path, &sr) && - (!pv || (!check_stateless_reset(&pv->dcid, path, &sr) && - (!(pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE) || - !check_stateless_reset(&pv->fallback_dcid, path, &sr))))) { - len = ngtcp2_ringbuf_len(&conn->dcid.retired); - for (i = 0; i < len; ++i) { - dcid = ngtcp2_ringbuf_get(&conn->dcid.retired, i); - if (check_stateless_reset(dcid, path, &sr)) { - break; - } - } - - if (i == len) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - } - - conn->state = NGTCP2_CS_DRAINING; - - ngtcp2_log_rx_sr(&conn->log, &sr); - - if (!conn->callbacks.recv_stateless_reset) { - return 0; - } - - rv = conn->callbacks.recv_stateless_reset(conn, &sr, conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - return 0; -} - -/* - * conn_recv_max_streams processes the incoming MAX_STREAMS frame - * |fr|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_CALLBACK_FAILURE - * User callback failed. - * NGTCP2_ERR_FRAME_ENCODING - * The maximum streams field exceeds the maximum value. - */ -static int conn_recv_max_streams(ngtcp2_conn *conn, - const ngtcp2_max_streams *fr) { - uint64_t n; - - if (fr->max_streams > NGTCP2_MAX_STREAMS) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - n = ngtcp2_min(fr->max_streams, NGTCP2_MAX_STREAMS); - - if (fr->type == NGTCP2_FRAME_MAX_STREAMS_BIDI) { - if (conn->local.bidi.max_streams < n) { - conn->local.bidi.max_streams = n; - return conn_call_extend_max_local_streams_bidi(conn, n); - } - return 0; - } - - if (conn->local.uni.max_streams < n) { - conn->local.uni.max_streams = n; - return conn_call_extend_max_local_streams_uni(conn, n); - } - return 0; -} - -static int conn_retire_dcid_prior_to(ngtcp2_conn *conn, ngtcp2_ringbuf *rb, - uint64_t retire_prior_to) { - size_t i; - ngtcp2_dcid *dcid, *last; - int rv; - - for (i = 0; i < ngtcp2_ringbuf_len(rb);) { - dcid = ngtcp2_ringbuf_get(rb, i); - if (dcid->seq >= retire_prior_to) { - ++i; - continue; - } - - rv = conn_retire_dcid_seq(conn, dcid->seq); - if (rv != 0) { - return rv; - } - if (i == 0) { - ngtcp2_ringbuf_pop_front(rb); - } else if (i == ngtcp2_ringbuf_len(rb) - 1) { - ngtcp2_ringbuf_pop_back(rb); - break; - } else { - last = ngtcp2_ringbuf_get(rb, ngtcp2_ringbuf_len(rb) - 1); - ngtcp2_dcid_copy(dcid, last); - ngtcp2_ringbuf_pop_back(rb); - } - } - - return 0; -} - -/* - * conn_recv_new_connection_id processes the incoming - * NEW_CONNECTION_ID frame |fr|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_PROTO - * |fr| has the duplicated sequence number with different CID or - * token; or DCID is zero-length. - */ -static int conn_recv_new_connection_id(ngtcp2_conn *conn, - const ngtcp2_new_connection_id *fr) { - size_t i, len; - ngtcp2_dcid *dcid; - ngtcp2_pv *pv = conn->pv; - int rv; - int found = 0; - size_t extra_dcid = 0; - - if (conn->dcid.current.cid.datalen == 0) { - return NGTCP2_ERR_PROTO; - } - - if (fr->retire_prior_to > fr->seq) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - rv = ngtcp2_dcid_verify_uniqueness(&conn->dcid.current, fr->seq, &fr->cid, - fr->stateless_reset_token); - if (rv != 0) { - return rv; - } - if (ngtcp2_cid_eq(&conn->dcid.current.cid, &fr->cid)) { - found = 1; - } - - if (pv) { - rv = ngtcp2_dcid_verify_uniqueness(&pv->dcid, fr->seq, &fr->cid, - fr->stateless_reset_token); - if (rv != 0) { - return rv; - } - if (ngtcp2_cid_eq(&pv->dcid.cid, &fr->cid)) { - found = 1; - } - } - - len = ngtcp2_ringbuf_len(&conn->dcid.unused); - - for (i = 0; i < len; ++i) { - dcid = ngtcp2_ringbuf_get(&conn->dcid.unused, i); - rv = ngtcp2_dcid_verify_uniqueness(dcid, fr->seq, &fr->cid, - fr->stateless_reset_token); - if (rv != 0) { - return NGTCP2_ERR_PROTO; - } - if (ngtcp2_cid_eq(&dcid->cid, &fr->cid)) { - found = 1; - } - } - - if (conn->dcid.retire_prior_to < fr->retire_prior_to) { - conn->dcid.retire_prior_to = fr->retire_prior_to; - - rv = conn_retire_dcid_prior_to(conn, &conn->dcid.unused, - conn->dcid.retire_prior_to); - if (rv != 0) { - return rv; - } - } else if (fr->seq < conn->dcid.retire_prior_to) { - /* If packets are reordered, we might have retire_prior_to which - is larger than fr->seq. - - A malicious peer might send crafted NEW_CONNECTION_ID to force - local endpoint to create lots of RETIRE_CONNECTION_ID frames. - For example, a peer might send seq = 50000 and retire_prior_to - = 50000. Then send NEW_CONNECTION_ID frames with seq < - 50000. */ - if (conn->dcid.num_retire_queued < NGTCP2_MAX_DCID_POOL_SIZE * 2) { - return conn_retire_dcid_seq(conn, fr->seq); - } - return 0; - } - - if (found) { - return 0; - } - - if (ngtcp2_gaptr_is_pushed(&conn->dcid.seqgap, fr->seq, 1)) { - return 0; - } - - rv = ngtcp2_gaptr_push(&conn->dcid.seqgap, fr->seq, 1); - if (rv != 0) { - return rv; - } - - if (ngtcp2_ksl_len(&conn->dcid.seqgap.gap) > 32) { - ngtcp2_gaptr_drop_first_gap(&conn->dcid.seqgap); - } - - len = ngtcp2_ringbuf_len(&conn->dcid.unused); - - if (conn->dcid.current.seq >= conn->dcid.retire_prior_to) { - ++extra_dcid; - } - if (pv) { - if (pv->dcid.seq != conn->dcid.current.seq && - pv->dcid.seq >= conn->dcid.retire_prior_to) { - ++extra_dcid; - } - if ((pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE) && - pv->fallback_dcid.seq != conn->dcid.current.seq && - pv->fallback_dcid.seq >= conn->dcid.retire_prior_to) { - ++extra_dcid; - } - } - - if (conn->local.settings.transport_params.active_connection_id_limit <= - len + extra_dcid) { - return NGTCP2_ERR_CONNECTION_ID_LIMIT; - } - - if (len >= NGTCP2_MAX_DCID_POOL_SIZE) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, "too many connection ID"); - return 0; - } - - dcid = ngtcp2_ringbuf_push_back(&conn->dcid.unused); - ngtcp2_dcid_init(dcid, fr->seq, &fr->cid, fr->stateless_reset_token); - - return 0; -} - -/* - * conn_post_process_recv_new_connection_id handles retirement request - * of active DCIDs. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -static int conn_post_process_recv_new_connection_id(ngtcp2_conn *conn, - ngtcp2_tstamp ts) { - ngtcp2_pv *pv = conn->pv; - ngtcp2_dcid *dcid; - int rv; - - if (conn->dcid.current.seq < conn->dcid.retire_prior_to) { - if (ngtcp2_ringbuf_len(&conn->dcid.unused) == 0) { - return 0; - } - - rv = conn_retire_dcid(conn, &conn->dcid.current, ts); - if (rv != 0) { - return rv; - } - - dcid = ngtcp2_ringbuf_get(&conn->dcid.unused, 0); - if (pv) { - if (conn->dcid.current.seq == pv->dcid.seq) { - ngtcp2_dcid_copy_no_path(&pv->dcid, dcid); - } - if ((pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE) && - conn->dcid.current.seq == pv->fallback_dcid.seq) { - ngtcp2_dcid_copy_no_path(&pv->fallback_dcid, dcid); - } - } - - ngtcp2_dcid_copy_no_path(&conn->dcid.current, dcid); - ngtcp2_ringbuf_pop_front(&conn->dcid.unused); - - rv = conn_call_activate_dcid(conn, &conn->dcid.current); - if (rv != 0) { - return rv; - } - } - - if (pv) { - if (pv->dcid.seq < conn->dcid.retire_prior_to) { - if (ngtcp2_ringbuf_len(&conn->dcid.unused)) { - rv = conn_retire_dcid(conn, &pv->dcid, ts); - if (rv != 0) { - return rv; - } - - dcid = ngtcp2_ringbuf_get(&conn->dcid.unused, 0); - - if ((pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE) && - pv->dcid.seq == pv->fallback_dcid.seq) { - ngtcp2_dcid_copy_no_path(&pv->fallback_dcid, dcid); - } - - ngtcp2_dcid_copy_no_path(&pv->dcid, dcid); - ngtcp2_ringbuf_pop_front(&conn->dcid.unused); - - rv = conn_call_activate_dcid(conn, &pv->dcid); - if (rv != 0) { - return rv; - } - } else { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PTV, - "path migration is aborted because connection ID is" - "retired and no unused connection ID is available"); - - return conn_stop_pv(conn, ts); - } - } - if ((pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE) && - pv->fallback_dcid.seq < conn->dcid.retire_prior_to) { - if (ngtcp2_ringbuf_len(&conn->dcid.unused)) { - rv = conn_retire_dcid(conn, &pv->fallback_dcid, ts); - if (rv != 0) { - return rv; - } - - dcid = ngtcp2_ringbuf_get(&conn->dcid.unused, 0); - ngtcp2_dcid_copy_no_path(&pv->fallback_dcid, dcid); - ngtcp2_ringbuf_pop_front(&conn->dcid.unused); - - rv = conn_call_activate_dcid(conn, &pv->fallback_dcid); - if (rv != 0) { - return rv; - } - } else { - /* Now we have no fallback dcid. */ - return conn_stop_pv(conn, ts); - } - } - } - - return 0; -} - -/* - * conn_recv_retire_connection_id processes the incoming - * RETIRE_CONNECTION_ID frame |fr|. |hd| is a packet header which - * |fr| is included. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_PROTO - * SCID is zero-length. - * NGTCP2_ERR_FRAME_ENCODING - * Attempt to retire CID which is used as DCID to send this frame. - */ -static int conn_recv_retire_connection_id(ngtcp2_conn *conn, - const ngtcp2_pkt_hd *hd, - const ngtcp2_retire_connection_id *fr, - ngtcp2_tstamp ts) { - ngtcp2_ksl_it it; - ngtcp2_scid *scid; - - if (conn->oscid.datalen == 0 || conn->scid.last_seq < fr->seq) { - return NGTCP2_ERR_PROTO; - } - - for (it = ngtcp2_ksl_begin(&conn->scid.set); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - scid = ngtcp2_ksl_it_get(&it); - if (scid->seq == fr->seq) { - if (ngtcp2_cid_eq(&scid->cid, &hd->dcid)) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - if (!(scid->flags & NGTCP2_SCID_FLAG_RETIRED)) { - scid->flags |= NGTCP2_SCID_FLAG_RETIRED; - ++conn->scid.num_retired; - } - - if (scid->pe.index != NGTCP2_PQ_BAD_INDEX) { - ngtcp2_pq_remove(&conn->scid.used, &scid->pe); - scid->pe.index = NGTCP2_PQ_BAD_INDEX; - } - - scid->ts_retired = ts; - - return ngtcp2_pq_push(&conn->scid.used, &scid->pe); - } - } - - return 0; -} - -/* - * conn_recv_new_token processes the incoming NEW_TOKEN frame |fr|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Token is empty - * NGTCP2_ERR_PROTO: - * Server received NEW_TOKEN. - */ -static int conn_recv_new_token(ngtcp2_conn *conn, const ngtcp2_new_token *fr) { - int rv; - - if (conn->server) { - return NGTCP2_ERR_PROTO; - } - - if (fr->token.len == 0) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - if (conn->callbacks.recv_new_token) { - rv = conn->callbacks.recv_new_token(conn, &fr->token, conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - } - - return 0; -} - -/* - * conn_select_preferred_addr asks a client application to select a - * server address from preferred addresses received from server. If a - * client chooses the address, path validation will start. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -static int conn_select_preferred_addr(ngtcp2_conn *conn) { - struct sockaddr_storage buf; - ngtcp2_addr addr; - int rv; - ngtcp2_duration timeout; - ngtcp2_pv *pv; - ngtcp2_dcid *dcid; - - ngtcp2_addr_init(&addr, (struct sockaddr *)&buf, 0, NULL); - - if (ngtcp2_ringbuf_len(&conn->dcid.unused) == 0) { - return 0; - } - - rv = conn_call_select_preferred_addr(conn, &addr); - if (rv != 0) { - return rv; - } - - if (addr.addrlen == 0 || - ngtcp2_addr_eq(&conn->dcid.current.ps.path.remote, &addr)) { - return 0; - } - - assert(conn->pv == NULL); - - dcid = ngtcp2_ringbuf_get(&conn->dcid.unused, 0); - timeout = 3 * conn_compute_pto(conn, &conn->pktns); - timeout = ngtcp2_max(timeout, 6 * conn->cstat.initial_rtt); - - rv = ngtcp2_pv_new(&pv, dcid, timeout, NGTCP2_PV_FLAG_NONE, &conn->log, - conn->mem); - if (rv != 0) { - /* TODO Call ngtcp2_dcid_free here if it is introduced */ - return rv; - } - - ngtcp2_ringbuf_pop_front(&conn->dcid.unused); - conn->pv = pv; - - ngtcp2_addr_copy(&pv->dcid.ps.path.local, &conn->dcid.current.ps.path.local); - ngtcp2_addr_copy(&pv->dcid.ps.path.remote, &addr); - - return conn_call_activate_dcid(conn, &pv->dcid); -} - -/* - * conn_recv_handshake_done processes the incoming HANDSHAKE_DONE - * frame |fr|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_PROTO - * Server received HANDSHAKE_DONE frame. - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -static int conn_recv_handshake_done(ngtcp2_conn *conn, ngtcp2_tstamp ts) { - int rv; - - if (conn->server) { - return NGTCP2_ERR_PROTO; - } - - if (conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED) { - return 0; - } - - conn->flags |= NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED | - NGTCP2_CONN_FLAG_SERVER_ADDR_VERIFIED; - - conn->pktns.rtb.persistent_congestion_start_ts = ts; - - conn_discard_handshake_state(conn, ts); - - if (conn->remote.transport_params.preferred_address_present) { - rv = conn_select_preferred_addr(conn); - if (rv != 0) { - return rv; - } - } - - if (conn->callbacks.handshake_confirmed) { - rv = conn->callbacks.handshake_confirmed(conn, conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - } - - /* Re-arm loss detection timer after handshake has been - confirmed. */ - ngtcp2_conn_set_loss_detection_timer(conn, ts); - - return 0; -} - -/* - * conn_key_phase_changed returns nonzero if |hd| indicates that the - * key phase has unexpected value. - */ -static int conn_key_phase_changed(ngtcp2_conn *conn, const ngtcp2_pkt_hd *hd) { - ngtcp2_pktns *pktns = &conn->pktns; - - return !(pktns->crypto.rx.ckm->flags & NGTCP2_CRYPTO_KM_FLAG_KEY_PHASE_ONE) ^ - !(hd->flags & NGTCP2_PKT_FLAG_KEY_PHASE); -} - -/* - * conn_prepare_key_update installs new updated keys. - */ -static int conn_prepare_key_update(ngtcp2_conn *conn, ngtcp2_tstamp ts) { - int rv; - ngtcp2_tstamp confirmed_ts = conn->crypto.key_update.confirmed_ts; - ngtcp2_duration pto = conn_compute_pto(conn, &conn->pktns); - ngtcp2_pktns *pktns = &conn->pktns; - ngtcp2_crypto_km *rx_ckm = pktns->crypto.rx.ckm; - ngtcp2_crypto_km *tx_ckm = pktns->crypto.tx.ckm; - ngtcp2_crypto_km *new_rx_ckm, *new_tx_ckm; - ngtcp2_crypto_aead_ctx rx_aead_ctx = {0}, tx_aead_ctx = {0}; - size_t secretlen, ivlen; - - if ((conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED) && - (tx_ckm->use_count >= pktns->crypto.ctx.max_encryption || - rx_ckm->use_count >= pktns->crypto.ctx.max_decryption_failure)) { - ngtcp2_conn_initiate_key_update(conn, ts); - } - - if ((conn->flags & NGTCP2_CONN_FLAG_KEY_UPDATE_NOT_CONFIRMED) || - (confirmed_ts != UINT64_MAX && confirmed_ts + pto > ts)) { - return 0; - } - - if (conn->crypto.key_update.new_rx_ckm || - conn->crypto.key_update.new_tx_ckm) { - assert(conn->crypto.key_update.new_rx_ckm); - assert(conn->crypto.key_update.new_tx_ckm); - return 0; - } - - secretlen = rx_ckm->secret.len; - ivlen = rx_ckm->iv.len; - - rv = ngtcp2_crypto_km_nocopy_new(&conn->crypto.key_update.new_rx_ckm, - secretlen, ivlen, conn->mem); - if (rv != 0) { - return rv; - } - - rv = ngtcp2_crypto_km_nocopy_new(&conn->crypto.key_update.new_tx_ckm, - secretlen, ivlen, conn->mem); - if (rv != 0) { - return rv; - } - - new_rx_ckm = conn->crypto.key_update.new_rx_ckm; - new_tx_ckm = conn->crypto.key_update.new_tx_ckm; - - assert(conn->callbacks.update_key); - - rv = conn->callbacks.update_key( - conn, new_rx_ckm->secret.base, new_tx_ckm->secret.base, &rx_aead_ctx, - new_rx_ckm->iv.base, &tx_aead_ctx, new_tx_ckm->iv.base, - rx_ckm->secret.base, tx_ckm->secret.base, secretlen, conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - new_rx_ckm->aead_ctx = rx_aead_ctx; - new_tx_ckm->aead_ctx = tx_aead_ctx; - - if (!(rx_ckm->flags & NGTCP2_CRYPTO_KM_FLAG_KEY_PHASE_ONE)) { - new_rx_ckm->flags |= NGTCP2_CRYPTO_KM_FLAG_KEY_PHASE_ONE; - new_tx_ckm->flags |= NGTCP2_CRYPTO_KM_FLAG_KEY_PHASE_ONE; - } - - if (conn->crypto.key_update.old_rx_ckm) { - conn_call_delete_crypto_aead_ctx( - conn, &conn->crypto.key_update.old_rx_ckm->aead_ctx); - ngtcp2_crypto_km_del(conn->crypto.key_update.old_rx_ckm, conn->mem); - conn->crypto.key_update.old_rx_ckm = NULL; - } - - return 0; -} - -/* - * conn_rotate_keys rotates keys. The current key moves to old key, - * and new key moves to the current key. - */ -static void conn_rotate_keys(ngtcp2_conn *conn, int64_t pkt_num) { - ngtcp2_pktns *pktns = &conn->pktns; - - assert(conn->crypto.key_update.new_rx_ckm); - assert(conn->crypto.key_update.new_tx_ckm); - assert(!conn->crypto.key_update.old_rx_ckm); - assert(!(conn->flags & NGTCP2_CONN_FLAG_PPE_PENDING)); - - conn->crypto.key_update.old_rx_ckm = pktns->crypto.rx.ckm; - - pktns->crypto.rx.ckm = conn->crypto.key_update.new_rx_ckm; - conn->crypto.key_update.new_rx_ckm = NULL; - pktns->crypto.rx.ckm->pkt_num = pkt_num; - - assert(pktns->crypto.tx.ckm); - - conn_call_delete_crypto_aead_ctx(conn, &pktns->crypto.tx.ckm->aead_ctx); - ngtcp2_crypto_km_del(pktns->crypto.tx.ckm, conn->mem); - - pktns->crypto.tx.ckm = conn->crypto.key_update.new_tx_ckm; - conn->crypto.key_update.new_tx_ckm = NULL; - pktns->crypto.tx.ckm->pkt_num = pktns->tx.last_pkt_num + 1; - - conn->flags |= NGTCP2_CONN_FLAG_KEY_UPDATE_NOT_CONFIRMED; -} - -/* - * conn_path_validation_in_progress returns nonzero if path validation - * against |path| is underway. - */ -static int conn_path_validation_in_progress(ngtcp2_conn *conn, - const ngtcp2_path *path) { - ngtcp2_pv *pv = conn->pv; - - return pv && ngtcp2_path_eq(&pv->dcid.ps.path, path); -} - -/* - * conn_recv_non_probing_pkt_on_new_path is called when non-probing - * packet is received via new path. It starts path validation against - * the new path. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_CONN_ID_BLOCKED - * No DCID is available - * NGTCP2_ERR_NOMEM - * Out of memory - */ -static int conn_recv_non_probing_pkt_on_new_path(ngtcp2_conn *conn, - const ngtcp2_path *path, - int new_cid_used, - ngtcp2_tstamp ts) { - - ngtcp2_dcid dcid; - ngtcp2_pv *pv; - int rv; - ngtcp2_duration timeout; - int require_new_cid; - - assert(conn->server); - - if (conn->pv && (conn->pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE) && - ngtcp2_path_eq(&conn->pv->fallback_dcid.ps.path, path)) { - /* If new path equals fallback path, that means connection - migrated back to the original path. Fallback path is - considered to be validated. */ - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PTV, - "path is migrated back to the original path"); - ngtcp2_dcid_copy(&conn->dcid.current, &conn->pv->fallback_dcid); - conn_reset_congestion_state(conn); - rv = conn_stop_pv(conn, ts); - if (rv != 0) { - return rv; - } - return 0; - } - - /* The transport specification draft-27 says: - * - * An endpoint MUST use a new connection ID if it initiates - * connection migration as described in Section 9.2 or probes a new - * network path as described in Section 9.1. An endpoint MUST use a - * new connection ID in response to a change in the address of a - * peer if the packet with the new peer address uses an active - * connection ID that has not been previously used by the peer. - */ - require_new_cid = - (new_cid_used && - !ngtcp2_addr_eq(&conn->dcid.current.ps.path.remote, &path->remote)) || - !ngtcp2_addr_eq(&conn->dcid.current.ps.path.local, &path->local); - - /* If the remote endpoint uses new DCID, server has to change its - DCID as well. */ - if (require_new_cid && ngtcp2_ringbuf_len(&conn->dcid.unused) == 0) { - return NGTCP2_ERR_CONN_ID_BLOCKED; - } - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, - "non-probing packet was received from new remote address"); - - timeout = 3 * conn_compute_pto(conn, &conn->pktns); - timeout = ngtcp2_max(timeout, 6 * conn->cstat.initial_rtt); - - if (require_new_cid) { - dcid = *(ngtcp2_dcid *)ngtcp2_ringbuf_get(&conn->dcid.unused, 0); - ngtcp2_ringbuf_pop_front(&conn->dcid.unused); - - rv = conn_call_activate_dcid(conn, &dcid); - if (rv != 0) { - return rv; - } - } else { - /* Use the current DCID if a remote endpoint does not change - DCID. */ - dcid = conn->dcid.current; - } - - ngtcp2_path_copy(&dcid.ps.path, path); - - rv = ngtcp2_pv_new(&pv, &dcid, timeout, NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE, - &conn->log, conn->mem); - if (rv != 0) { - return rv; - } - - if (conn->pv && (conn->pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE)) { - ngtcp2_dcid_copy(&pv->fallback_dcid, &conn->pv->fallback_dcid); - } else { - ngtcp2_dcid_copy(&pv->fallback_dcid, &conn->dcid.current); - } - - ngtcp2_dcid_copy(&conn->dcid.current, &dcid); - - conn_reset_congestion_state(conn); - - if (conn->pv) { - ngtcp2_log_info( - &conn->log, NGTCP2_LOG_EVENT_PTV, - "path migration is aborted because new migration has started"); - rv = conn_stop_pv(conn, ts); - if (rv != 0) { - return rv; - } - } - - conn->pv = pv; - - return 0; -} - -/* - * conn_recv_delayed_handshake_pkt processes the received Handshake - * packet which is received after handshake completed. This function - * does the minimal job, and its purpose is send acknowledgement of - * this packet to the peer. We assume that hd->type == - * NGTCP2_PKT_HANDSHAKE. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Frame is badly formatted; or frame type is unknown. - * NGTCP2_ERR_NOMEM - * Out of memory - * NGTCP2_ERR_DISCARD_PKT - * Packet was discarded. - * NGTCP2_ERR_ACK_FRAME - * ACK frame is malformed. - * NGTCP2_ERR_PROTO - * Frame that is not allowed in Handshake packet is received. - */ -static int -conn_recv_delayed_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_pkt_hd *hd, - size_t pktlen, const uint8_t *payload, - size_t payloadlen, ngtcp2_tstamp pkt_ts, - ngtcp2_tstamp ts) { - ngtcp2_ssize nread; - ngtcp2_max_frame mfr; - ngtcp2_frame *fr = &mfr.fr; - int rv; - int require_ack = 0; - ngtcp2_pktns *pktns; - - assert(hd->type == NGTCP2_PKT_HANDSHAKE); - - pktns = conn->hs_pktns; - - if (payloadlen == 0) { - /* QUIC packet must contain at least one frame */ - return NGTCP2_ERR_DISCARD_PKT; - } - - ngtcp2_qlog_pkt_received_start(&conn->qlog, hd); - - for (; payloadlen;) { - nread = ngtcp2_pkt_decode_frame(fr, payload, payloadlen); - if (nread < 0) { - return (int)nread; - } - - payload += nread; - payloadlen -= (size_t)nread; - - if (fr->type == NGTCP2_FRAME_ACK) { - fr->ack.ack_delay = 0; - fr->ack.ack_delay_unscaled = 0; - } - - ngtcp2_log_rx_fr(&conn->log, hd, fr); - - switch (fr->type) { - case NGTCP2_FRAME_ACK: - case NGTCP2_FRAME_ACK_ECN: - if (!conn->server) { - conn->flags |= NGTCP2_CONN_FLAG_SERVER_ADDR_VERIFIED; - } - rv = conn_recv_ack(conn, pktns, &fr->ack, pkt_ts, ts); - if (rv != 0) { - return rv; - } - break; - case NGTCP2_FRAME_PADDING: - break; - case NGTCP2_FRAME_CONNECTION_CLOSE: - conn_recv_connection_close(conn, &fr->connection_close); - break; - case NGTCP2_FRAME_CRYPTO: - case NGTCP2_FRAME_PING: - require_ack = 1; - break; - default: - return NGTCP2_ERR_PROTO; - } - - ngtcp2_qlog_write_frame(&conn->qlog, fr); - } - - ngtcp2_qlog_pkt_received_end(&conn->qlog, hd, pktlen); - - rv = pktns_commit_recv_pkt_num(pktns, hd->pkt_num, pkt_ts); - if (rv != 0) { - return rv; - } - - if (require_ack && ++pktns->acktr.rx_npkt >= NGTCP2_NUM_IMMEDIATE_ACK_PKT) { - ngtcp2_acktr_immediate_ack(&pktns->acktr); - } - - rv = ngtcp2_conn_sched_ack(conn, &pktns->acktr, hd->pkt_num, require_ack, - pkt_ts); - if (rv != 0) { - return rv; - } - - conn_restart_timer_on_read(conn, ts); - - ngtcp2_qlog_metrics_updated(&conn->qlog, &conn->cstat); - - return 0; -} - -/* - * conn_recv_pkt processes a packet contained in the buffer pointed by - * |pkt| of length |pktlen|. |pkt| may contain multiple QUIC packets. - * This function only processes the first packet. |pkt_ts| is the - * timestamp when packet is received. |ts| should be the current - * time. Usually they are the same, but for buffered packets, - * |pkt_ts| would be earlier than |ts|. - * - * This function returns the number of bytes processed if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_DISCARD_PKT - * Packet was discarded because plain text header was malformed; - * or its payload could not be decrypted. - * NGTCP2_ERR_PROTO - * Packet is badly formatted; or 0RTT packet contains other than - * PADDING or STREAM frames; or other QUIC protocol violation is - * found. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_FRAME_ENCODING - * Frame is badly formatted; or frame type is unknown. - * NGTCP2_ERR_ACK_FRAME - * ACK frame is malformed. - * NGTCP2_ERR_STREAM_STATE - * Frame is received to the local stream which is not initiated. - * NGTCP2_ERR_STREAM_LIMIT - * Frame has remote stream ID which is strictly greater than the - * allowed limit. - * NGTCP2_ERR_FLOW_CONTROL - * Flow control limit is violated. - * NGTCP2_ERR_FINAL_SIZE - * Frame has strictly larger end offset than it is permitted. - */ -static ngtcp2_ssize conn_recv_pkt(ngtcp2_conn *conn, const ngtcp2_path *path, - const uint8_t *pkt, size_t pktlen, - ngtcp2_tstamp pkt_ts, ngtcp2_tstamp ts) { - ngtcp2_pkt_hd hd; - int rv = 0; - size_t hdpktlen; - const uint8_t *payload; - size_t payloadlen; - ngtcp2_ssize nread, nwrite; - ngtcp2_max_frame mfr; - ngtcp2_frame *fr = &mfr.fr; - int require_ack = 0; - ngtcp2_crypto_aead *aead; - ngtcp2_crypto_cipher *hp; - ngtcp2_crypto_km *ckm; - ngtcp2_crypto_cipher_ctx *hp_ctx; - uint8_t plain_hdpkt[1500]; - ngtcp2_hp_mask hp_mask; - ngtcp2_decrypt decrypt; - size_t aead_overhead; - ngtcp2_pktns *pktns; - int non_probing_pkt = 0; - int key_phase_bit_changed = 0; - int force_decrypt_failure = 0; - int recv_ncid = 0; - int new_cid_used = 0; - - if (pkt[0] & NGTCP2_HEADER_FORM_BIT) { - nread = ngtcp2_pkt_decode_hd_long(&hd, pkt, pktlen); - if (nread < 0) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "could not decode long header"); - return NGTCP2_ERR_DISCARD_PKT; - } - - if (pktlen < (size_t)nread + hd.len || conn->version != hd.version) { - return NGTCP2_ERR_DISCARD_PKT; - } - - pktlen = (size_t)nread + hd.len; - - /* Quoted from spec: if subsequent packets of those types include - a different Source Connection ID, they MUST be discarded. */ - if (!ngtcp2_cid_eq(&conn->dcid.current.cid, &hd.scid)) { - ngtcp2_log_rx_pkt_hd(&conn->log, &hd); - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was ignored because of mismatched SCID"); - return NGTCP2_ERR_DISCARD_PKT; - } - - switch (hd.type) { - case NGTCP2_PKT_INITIAL: - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "delayed Initial packet was discarded"); - return (ngtcp2_ssize)pktlen; - case NGTCP2_PKT_HANDSHAKE: - if (!conn->hs_pktns) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "delayed Handshake packet was discarded"); - return (ngtcp2_ssize)pktlen; - } - - pktns = conn->hs_pktns; - ckm = pktns->crypto.rx.ckm; - hp_ctx = &pktns->crypto.rx.hp_ctx; - hp_mask = conn->callbacks.hp_mask; - decrypt = conn->callbacks.decrypt; - aead_overhead = conn->crypto.aead_overhead; - break; - case NGTCP2_PKT_0RTT: - if (!conn->server || !conn->early.ckm) { - return NGTCP2_ERR_DISCARD_PKT; - } - - pktns = &conn->pktns; - ckm = conn->early.ckm; - hp_ctx = &conn->early.hp_ctx; - hp_mask = conn->callbacks.hp_mask; - decrypt = conn->callbacks.decrypt; - aead_overhead = conn->crypto.aead_overhead; - break; - default: - ngtcp2_log_rx_pkt_hd(&conn->log, &hd); - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet type 0x%02x was ignored", hd.type); - return (ngtcp2_ssize)pktlen; - } - } else { - nread = ngtcp2_pkt_decode_hd_short(&hd, pkt, pktlen, conn->oscid.datalen); - if (nread < 0) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "could not decode short header"); - return NGTCP2_ERR_DISCARD_PKT; - } - - pktns = &conn->pktns; - ckm = pktns->crypto.rx.ckm; - hp_ctx = &pktns->crypto.rx.hp_ctx; - hp_mask = conn->callbacks.hp_mask; - decrypt = conn->callbacks.decrypt; - aead_overhead = conn->crypto.aead_overhead; - } - - aead = &pktns->crypto.ctx.aead; - hp = &pktns->crypto.ctx.hp; - - nwrite = decrypt_hp(&hd, plain_hdpkt, sizeof(plain_hdpkt), hp, pkt, pktlen, - (size_t)nread, ckm, hp_ctx, hp_mask); - if (nwrite < 0) { - if (ngtcp2_err_is_fatal((int)nwrite)) { - return nwrite; - } - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "could not decrypt packet number"); - return NGTCP2_ERR_DISCARD_PKT; - } - - hdpktlen = (size_t)nwrite; - payload = pkt + hdpktlen; - payloadlen = pktlen - hdpktlen; - - hd.pkt_num = ngtcp2_pkt_adjust_pkt_num(pktns->rx.max_pkt_num, hd.pkt_num, - pkt_num_bits(hd.pkt_numlen)); - if (hd.pkt_num > NGTCP2_MAX_PKT_NUM) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "pkn=%" PRId64 " is greater than maximum pkn", hd.pkt_num); - return NGTCP2_ERR_DISCARD_PKT; - } - - ngtcp2_log_rx_pkt_hd(&conn->log, &hd); - - if (hd.type == NGTCP2_PKT_SHORT) { - key_phase_bit_changed = conn_key_phase_changed(conn, &hd); - } - - rv = conn_ensure_decrypt_buffer(conn, payloadlen); - if (rv != 0) { - return rv; - } - - if (key_phase_bit_changed) { - assert(hd.type == NGTCP2_PKT_SHORT); - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, "unexpected KEY_PHASE"); - - if (ckm->pkt_num > hd.pkt_num) { - if (conn->crypto.key_update.old_rx_ckm) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "decrypting with old key"); - ckm = conn->crypto.key_update.old_rx_ckm; - } else { - force_decrypt_failure = 1; - } - } else if (pktns->rx.max_pkt_num < hd.pkt_num) { - assert(ckm->pkt_num < hd.pkt_num); - if (!conn->crypto.key_update.new_rx_ckm) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "new key is not available"); - force_decrypt_failure = 1; - } else { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "decrypting with new key"); - ckm = conn->crypto.key_update.new_rx_ckm; - } - } else { - force_decrypt_failure = 1; - } - } - - nwrite = decrypt_pkt(conn->crypto.decrypt_buf.base, aead, payload, payloadlen, - plain_hdpkt, hdpktlen, hd.pkt_num, ckm, decrypt, - aead_overhead); - - if (force_decrypt_failure) { - nwrite = NGTCP2_ERR_TLS_DECRYPT; - } - - if (nwrite < 0) { - if (ngtcp2_err_is_fatal((int)nwrite)) { - return nwrite; - } - - assert(NGTCP2_ERR_TLS_DECRYPT == nwrite); - - ++ckm->use_count; - - if (hd.flags & NGTCP2_PKT_FLAG_LONG_FORM) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "could not decrypt packet payload"); - return NGTCP2_ERR_DISCARD_PKT; - } - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "could not decrypt packet payload"); - return NGTCP2_ERR_DISCARD_PKT; - } - - rv = ngtcp2_pkt_verify_reserved_bits(plain_hdpkt[0]); - if (rv != 0) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet has incorrect reserved bits"); - - return NGTCP2_ERR_PROTO; - } - - if (pktns_pkt_num_is_duplicate(pktns, hd.pkt_num)) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was discarded because of duplicated packet number"); - return NGTCP2_ERR_DISCARD_PKT; - } - - payload = conn->crypto.decrypt_buf.base; - payloadlen = (size_t)nwrite; - - if (payloadlen == 0) { - /* QUIC packet must contain at least one frame */ - return NGTCP2_ERR_DISCARD_PKT; - } - - if (hd.flags & NGTCP2_PKT_FLAG_LONG_FORM) { - switch (hd.type) { - case NGTCP2_PKT_HANDSHAKE: - rv = conn_verify_dcid(conn, NULL, &hd); - if (rv != 0) { - if (ngtcp2_err_is_fatal(rv)) { - return rv; - } - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was ignored because of mismatched DCID"); - return NGTCP2_ERR_DISCARD_PKT; - } - - rv = conn_recv_delayed_handshake_pkt(conn, &hd, pktlen, payload, - payloadlen, pkt_ts, ts); - if (rv < 0) { - return (ngtcp2_ssize)rv; - } - - return (ngtcp2_ssize)pktlen; - case NGTCP2_PKT_0RTT: - if (!ngtcp2_cid_eq(&conn->rcid, &hd.dcid)) { - rv = conn_verify_dcid(conn, NULL, &hd); - if (rv != 0) { - if (ngtcp2_err_is_fatal(rv)) { - return rv; - } - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was ignored because of mismatched DCID"); - return NGTCP2_ERR_DISCARD_PKT; - } - } - break; - default: - /* Unreachable */ - assert(0); - } - } else { - rv = conn_verify_dcid(conn, &new_cid_used, &hd); - if (rv != 0) { - if (ngtcp2_err_is_fatal(rv)) { - return rv; - } - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "packet was ignored because of mismatched DCID"); - return NGTCP2_ERR_DISCARD_PKT; - } - - conn->flags |= NGTCP2_CONN_FLAG_RECV_PROTECTED_PKT; - } - - ngtcp2_qlog_pkt_received_start(&conn->qlog, &hd); - - for (; payloadlen;) { - nread = ngtcp2_pkt_decode_frame(fr, payload, payloadlen); - if (nread < 0) { - return nread; - } - - payload += nread; - payloadlen -= (size_t)nread; - - if (fr->type == NGTCP2_FRAME_ACK) { - if ((hd.flags & NGTCP2_PKT_FLAG_LONG_FORM) && - hd.type == NGTCP2_PKT_0RTT) { - return NGTCP2_ERR_PROTO; - } - assign_recved_ack_delay_unscaled( - &fr->ack, conn->remote.transport_params.ack_delay_exponent); - } - - ngtcp2_log_rx_fr(&conn->log, &hd, fr); - - if (hd.type == NGTCP2_PKT_0RTT) { - switch (fr->type) { - case NGTCP2_FRAME_PADDING: - case NGTCP2_FRAME_PING: - case NGTCP2_FRAME_RESET_STREAM: - case NGTCP2_FRAME_STOP_SENDING: - case NGTCP2_FRAME_STREAM: - case NGTCP2_FRAME_MAX_DATA: - case NGTCP2_FRAME_MAX_STREAM_DATA: - case NGTCP2_FRAME_MAX_STREAMS_BIDI: - case NGTCP2_FRAME_MAX_STREAMS_UNI: - case NGTCP2_FRAME_DATA_BLOCKED: - case NGTCP2_FRAME_STREAM_DATA_BLOCKED: - case NGTCP2_FRAME_STREAMS_BLOCKED_BIDI: - case NGTCP2_FRAME_STREAMS_BLOCKED_UNI: - case NGTCP2_FRAME_NEW_CONNECTION_ID: - case NGTCP2_FRAME_RETIRE_CONNECTION_ID: - case NGTCP2_FRAME_PATH_CHALLENGE: - case NGTCP2_FRAME_PATH_RESPONSE: - case NGTCP2_FRAME_CONNECTION_CLOSE: - case NGTCP2_FRAME_CONNECTION_CLOSE_APP: - break; - default: - return NGTCP2_ERR_PROTO; - } - } - - switch (fr->type) { - case NGTCP2_FRAME_ACK: - case NGTCP2_FRAME_ACK_ECN: - case NGTCP2_FRAME_PADDING: - case NGTCP2_FRAME_CONNECTION_CLOSE: - case NGTCP2_FRAME_CONNECTION_CLOSE_APP: - break; - default: - require_ack = 1; - } - - switch (fr->type) { - case NGTCP2_FRAME_ACK: - case NGTCP2_FRAME_ACK_ECN: - if (!conn->server) { - conn->flags |= NGTCP2_CONN_FLAG_SERVER_ADDR_VERIFIED; - } - rv = conn_recv_ack(conn, pktns, &fr->ack, pkt_ts, ts); - if (rv != 0) { - return rv; - } - non_probing_pkt = 1; - break; - case NGTCP2_FRAME_STREAM: - rv = conn_recv_stream(conn, &fr->stream, ts); - if (rv != 0) { - return rv; - } - non_probing_pkt = 1; - break; - case NGTCP2_FRAME_CRYPTO: - rv = conn_recv_crypto(conn, NGTCP2_CRYPTO_LEVEL_APP, &pktns->crypto.strm, - &fr->crypto); - if (rv != 0) { - return rv; - } - non_probing_pkt = 1; - break; - case NGTCP2_FRAME_RESET_STREAM: - rv = conn_recv_reset_stream(conn, &fr->reset_stream); - if (rv != 0) { - return rv; - } - non_probing_pkt = 1; - break; - case NGTCP2_FRAME_STOP_SENDING: - rv = conn_recv_stop_sending(conn, &fr->stop_sending); - if (rv != 0) { - return rv; - } - non_probing_pkt = 1; - break; - case NGTCP2_FRAME_MAX_STREAM_DATA: - rv = conn_recv_max_stream_data(conn, &fr->max_stream_data); - if (rv != 0) { - return rv; - } - non_probing_pkt = 1; - break; - case NGTCP2_FRAME_MAX_DATA: - conn_recv_max_data(conn, &fr->max_data); - non_probing_pkt = 1; - break; - case NGTCP2_FRAME_MAX_STREAMS_BIDI: - case NGTCP2_FRAME_MAX_STREAMS_UNI: - rv = conn_recv_max_streams(conn, &fr->max_streams); - if (rv != 0) { - return rv; - } - non_probing_pkt = 1; - break; - case NGTCP2_FRAME_CONNECTION_CLOSE: - case NGTCP2_FRAME_CONNECTION_CLOSE_APP: - conn_recv_connection_close(conn, &fr->connection_close); - break; - case NGTCP2_FRAME_PING: - non_probing_pkt = 1; - break; - case NGTCP2_FRAME_PATH_CHALLENGE: - conn_recv_path_challenge(conn, &fr->path_challenge); - break; - case NGTCP2_FRAME_PATH_RESPONSE: - rv = conn_recv_path_response(conn, &fr->path_response, ts); - if (rv != 0) { - return rv; - } - break; - case NGTCP2_FRAME_NEW_CONNECTION_ID: - rv = conn_recv_new_connection_id(conn, &fr->new_connection_id); - if (rv != 0) { - return rv; - } - recv_ncid = 1; - break; - case NGTCP2_FRAME_RETIRE_CONNECTION_ID: - rv = conn_recv_retire_connection_id(conn, &hd, &fr->retire_connection_id, - ts); - if (rv != 0) { - return rv; - } - non_probing_pkt = 1; - break; - case NGTCP2_FRAME_NEW_TOKEN: - rv = conn_recv_new_token(conn, &fr->new_token); - if (rv != 0) { - return rv; - } - non_probing_pkt = 1; - break; - case NGTCP2_FRAME_HANDSHAKE_DONE: - rv = conn_recv_handshake_done(conn, ts); - if (rv != 0) { - return rv; - } - non_probing_pkt = 1; - break; - case NGTCP2_FRAME_DATA_BLOCKED: - case NGTCP2_FRAME_STREAMS_BLOCKED_BIDI: - case NGTCP2_FRAME_STREAMS_BLOCKED_UNI: - /* TODO Not implemented yet */ - non_probing_pkt = 1; - break; - } - - ngtcp2_qlog_write_frame(&conn->qlog, fr); - } - - ngtcp2_qlog_pkt_received_end(&conn->qlog, &hd, pktlen); - - if (recv_ncid) { - rv = conn_post_process_recv_new_connection_id(conn, ts); - if (rv != 0) { - return rv; - } - } - - if (conn->server && hd.type == NGTCP2_PKT_SHORT && non_probing_pkt && - pktns->rx.max_pkt_num < hd.pkt_num && - !ngtcp2_path_eq(&conn->dcid.current.ps.path, path) && - !conn_path_validation_in_progress(conn, path)) { - rv = conn_recv_non_probing_pkt_on_new_path(conn, path, new_cid_used, ts); - if (rv != 0) { - if (ngtcp2_err_is_fatal(rv)) { - return rv; - } - - /* DCID is not available. Just continue. */ - assert(NGTCP2_ERR_CONN_ID_BLOCKED == rv); - } - } - - if (hd.type == NGTCP2_PKT_SHORT) { - if (ckm == conn->crypto.key_update.new_rx_ckm) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, "rotate keys"); - conn_rotate_keys(conn, hd.pkt_num); - } else if (ckm->pkt_num > hd.pkt_num) { - ckm->pkt_num = hd.pkt_num; - } - } - - rv = pktns_commit_recv_pkt_num(pktns, hd.pkt_num, pkt_ts); - if (rv != 0) { - return rv; - } - - if (require_ack && ++pktns->acktr.rx_npkt >= NGTCP2_NUM_IMMEDIATE_ACK_PKT) { - ngtcp2_acktr_immediate_ack(&pktns->acktr); - } - - rv = ngtcp2_conn_sched_ack(conn, &pktns->acktr, hd.pkt_num, require_ack, - pkt_ts); - if (rv != 0) { - return rv; - } - - conn_restart_timer_on_read(conn, ts); - - ngtcp2_qlog_metrics_updated(&conn->qlog, &conn->cstat); - - return conn->state == NGTCP2_CS_DRAINING ? NGTCP2_ERR_DRAINING - : (ngtcp2_ssize)pktlen; -} - -/* - * conn_process_buffered_protected_pkt processes buffered 0RTT or - * Short packets. - * - * This function returns 0 if it succeeds, or the same negative error - * codes from conn_recv_pkt. - */ -static int conn_process_buffered_protected_pkt(ngtcp2_conn *conn, - ngtcp2_pktns *pktns, - ngtcp2_tstamp ts) { - ngtcp2_ssize nread; - ngtcp2_pkt_chain **ppc, *next; - int rv; - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, - "processing buffered protected packet"); - - for (ppc = &pktns->rx.buffed_pkts; *ppc;) { - next = (*ppc)->next; - nread = conn_recv_pkt(conn, &(*ppc)->path.path, (*ppc)->pkt, (*ppc)->pktlen, - (*ppc)->ts, ts); - if (nread < 0 && !ngtcp2_err_is_fatal((int)nread) && - nread != NGTCP2_ERR_DRAINING) { - /* TODO We don't know this is the first QUIC packet in a - datagram. */ - rv = conn_on_stateless_reset(conn, &(*ppc)->path.path, (*ppc)->pkt, - (*ppc)->pktlen); - if (rv == 0) { - ngtcp2_pkt_chain_del(*ppc, conn->mem); - *ppc = next; - return NGTCP2_ERR_DRAINING; - } - } - - ngtcp2_pkt_chain_del(*ppc, conn->mem); - *ppc = next; - if (nread < 0) { - if (nread == NGTCP2_ERR_DISCARD_PKT) { - continue; - } - return (int)nread; - } - } - - return 0; -} - -/* - * conn_process_buffered_handshake_pkt processes buffered Handshake - * packets. - * - * This function returns 0 if it succeeds, or the same negative error - * codes from conn_recv_handshake_pkt. - */ -static int conn_process_buffered_handshake_pkt(ngtcp2_conn *conn, - ngtcp2_tstamp ts) { - ngtcp2_pktns *pktns = conn->hs_pktns; - ngtcp2_ssize nread; - ngtcp2_pkt_chain **ppc, *next; - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, - "processing buffered handshake packet"); - - for (ppc = &pktns->rx.buffed_pkts; *ppc;) { - next = (*ppc)->next; - nread = conn_recv_handshake_pkt(conn, &(*ppc)->path.path, (*ppc)->pkt, - (*ppc)->pktlen, (*ppc)->ts, ts); - ngtcp2_pkt_chain_del(*ppc, conn->mem); - *ppc = next; - if (nread < 0) { - if (nread == NGTCP2_ERR_DISCARD_PKT) { - continue; - } - return (int)nread; - } - } - - return 0; -} - -static void conn_sync_stream_id_limit(ngtcp2_conn *conn) { - ngtcp2_transport_params *params = &conn->remote.transport_params; - - conn->local.bidi.max_streams = params->initial_max_streams_bidi; - conn->local.uni.max_streams = params->initial_max_streams_uni; -} - -/* - * conn_handshake_completed is called once cryptographic handshake has - * completed. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_CALLBACK_FAILURE - * User callback failed. - */ -static int conn_handshake_completed(ngtcp2_conn *conn) { - int rv; - - conn->flags |= NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED; - - rv = conn_call_handshake_completed(conn); - if (rv != 0) { - return rv; - } - - if (conn->local.bidi.max_streams > 0) { - rv = conn_call_extend_max_local_streams_bidi(conn, - conn->local.bidi.max_streams); - if (rv != 0) { - return rv; - } - } - if (conn->local.uni.max_streams > 0) { - rv = conn_call_extend_max_local_streams_uni(conn, - conn->local.uni.max_streams); - if (rv != 0) { - return rv; - } - } - - return 0; -} - -/* - * conn_recv_cpkt processes compound packet after handshake. The - * buffer pointed by |pkt| might contain multiple packets. The Short - * packet must be the last one because it does not have payload length - * field. - * - * This function returns 0 if it succeeds, or the same negative error - * codes from conn_recv_pkt except for NGTCP2_ERR_DISCARD_PKT. - */ -static int conn_recv_cpkt(ngtcp2_conn *conn, const ngtcp2_path *path, - const uint8_t *pkt, size_t pktlen, ngtcp2_tstamp ts) { - ngtcp2_ssize nread; - int rv; - const uint8_t *origpkt = pkt; - size_t origpktlen = pktlen; - - conn->cstat.bytes_recv += pktlen; - - while (pktlen) { - nread = conn_recv_pkt(conn, path, pkt, pktlen, ts, ts); - if (nread < 0) { - if (ngtcp2_err_is_fatal((int)nread)) { - return (int)nread; - } - - if (nread == NGTCP2_ERR_DRAINING) { - return NGTCP2_ERR_DRAINING; - } - - if (origpkt == pkt) { - rv = conn_on_stateless_reset(conn, path, origpkt, origpktlen); - if (rv == 0) { - return NGTCP2_ERR_DRAINING; - } - } - if (nread == NGTCP2_ERR_DISCARD_PKT) { - return 0; - } - return (int)nread; - } - - assert(pktlen >= (size_t)nread); - pkt += nread; - pktlen -= (size_t)nread; - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT, - "read packet %td left %zu", nread, pktlen); - } - - return 0; -} - -/* - * conn_is_retired_path returns nonzero if |path| is included in - * retired path list. - */ -static int conn_is_retired_path(ngtcp2_conn *conn, const ngtcp2_path *path) { - size_t i, len = ngtcp2_ringbuf_len(&conn->dcid.retired); - ngtcp2_dcid *dcid; - - for (i = 0; i < len; ++i) { - dcid = ngtcp2_ringbuf_get(&conn->dcid.retired, i); - if (ngtcp2_path_eq(&dcid->ps.path, path)) { - return 1; - } - } - - return 0; -} - -/* - * conn_enqueue_handshake_done enqueues HANDSHAKE_DONE frame for - * transmission. - */ -static int conn_enqueue_handshake_done(ngtcp2_conn *conn) { - ngtcp2_pktns *pktns = &conn->pktns; - ngtcp2_frame_chain *nfrc; - int rv; - - assert(conn->server); - - rv = ngtcp2_frame_chain_new(&nfrc, conn->mem); - if (rv != 0) { - return rv; - } - - nfrc->fr.type = NGTCP2_FRAME_HANDSHAKE_DONE; - nfrc->next = pktns->tx.frq; - pktns->tx.frq = nfrc; - - return 0; -} - -/** - * @function - * - * `conn_read_handshake` performs QUIC cryptographic handshake by - * reading given data. |pkt| points to the buffer to read and - * |pktlen| is the length of the buffer. |path| is the network path. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: (TBD). - */ -static int conn_read_handshake(ngtcp2_conn *conn, const ngtcp2_path *path, - const uint8_t *pkt, size_t pktlen, - ngtcp2_tstamp ts) { - int rv; - - switch (conn->state) { - case NGTCP2_CS_CLIENT_INITIAL: - /* TODO Better to log something when we ignore input */ - return 0; - case NGTCP2_CS_CLIENT_WAIT_HANDSHAKE: - rv = conn_recv_handshake_cpkt(conn, path, pkt, pktlen, ts); - if (rv < 0) { - return rv; - } - - if (conn->state == NGTCP2_CS_CLIENT_INITIAL) { - /* Retry packet was received */ - return 0; - } - - assert(conn->hs_pktns); - - if (conn->hs_pktns->crypto.rx.ckm && conn->in_pktns) { - rv = conn_process_buffered_handshake_pkt(conn, ts); - if (rv != 0) { - return rv; - } - } - - return 0; - case NGTCP2_CS_SERVER_INITIAL: - rv = conn_recv_handshake_cpkt(conn, path, pkt, pktlen, ts); - if (rv < 0) { - return rv; - } - - /* - * Client ServerHello might not fit into single Initial packet - * (e.g., resuming session with client authentication). If we get - * Client Initial which does not increase offset or it is 0RTT - * packet buffered, perform address validation in order to buffer - * validated data only. - */ - if (ngtcp2_strm_rx_offset(&conn->in_pktns->crypto.strm) == 0) { - if (conn->in_pktns->crypto.strm.rx.rob && - ngtcp2_rob_data_buffered(conn->in_pktns->crypto.strm.rx.rob)) { - /* Address has been validated with token */ - if (conn->local.settings.token.len) { - return 0; - } - return NGTCP2_ERR_RETRY; - } - if (conn->in_pktns->rx.buffed_pkts) { - /* 0RTT is buffered, force retry */ - return NGTCP2_ERR_RETRY; - } - /* If neither CRYPTO frame nor 0RTT packet is processed, just - drop connection. */ - return NGTCP2_ERR_PROTO; - } - - /* Process re-ordered 0-RTT packets which arrived before Initial - packet. */ - if (conn->early.ckm) { - assert(conn->in_pktns); - - rv = conn_process_buffered_protected_pkt(conn, conn->in_pktns, ts); - if (rv != 0) { - return rv; - } - } - - return 0; - case NGTCP2_CS_SERVER_WAIT_HANDSHAKE: - rv = conn_recv_handshake_cpkt(conn, path, pkt, pktlen, ts); - if (rv < 0) { - return rv; - } - - if (conn->hs_pktns->crypto.rx.ckm) { - rv = conn_process_buffered_handshake_pkt(conn, ts); - if (rv != 0) { - return rv; - } - } - - if (conn->hs_pktns->rx.max_pkt_num != -1) { - conn_discard_initial_state(conn, ts); - } - - if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED)) { - /* If server hits amplification limit, it cancels loss detection - timer. If server receives a packet from client, the limit is - increased and server can send more. If server has - ack-eliciting Initial or Handshake packets, it should resend - it if timer fired but timer is not armed in this case. So - instead of resending Initial/Handshake packets, if server has - 1RTT data to send, it might send them and then might hit - amplification limit again until it hits stream data limit. - Initial/Handshake data is not resent. In order to avoid this - situation, try to arm loss detection and check the expiry - here so that on next write call, we can resend - Initial/Handshake first. */ - if (!conn->cstat.loss_detection_timer) { - ngtcp2_conn_set_loss_detection_timer(conn, ts); - if (ngtcp2_conn_loss_detection_expiry(conn) <= ts) { - rv = ngtcp2_conn_on_loss_detection_timer(conn, ts); - if (rv != 0) { - return rv; - } - } - } - - return 0; - } - - if (!(conn->flags & NGTCP2_CONN_FLAG_TRANSPORT_PARAM_RECVED)) { - return NGTCP2_ERR_REQUIRED_TRANSPORT_PARAM; - } - - rv = conn_handshake_completed(conn); - if (rv != 0) { - return rv; - } - conn->state = NGTCP2_CS_POST_HANDSHAKE; - - rv = conn_call_activate_dcid(conn, &conn->dcid.current); - if (rv != 0) { - return rv; - } - - rv = conn_process_buffered_protected_pkt(conn, &conn->pktns, ts); - if (rv != 0) { - return rv; - } - - conn_discard_handshake_state(conn, ts); - - rv = conn_enqueue_handshake_done(conn); - if (rv != 0) { - return rv; - } - - conn->pktns.rtb.persistent_congestion_start_ts = ts; - - /* Re-arm loss detection timer here after handshake has been - confirmed. */ - ngtcp2_conn_set_loss_detection_timer(conn, ts); - - return 0; - case NGTCP2_CS_CLOSING: - return NGTCP2_ERR_CLOSING; - case NGTCP2_CS_DRAINING: - return NGTCP2_ERR_DRAINING; - default: - return 0; - } -} - -int ngtcp2_conn_read_pkt(ngtcp2_conn *conn, const ngtcp2_path *path, - const uint8_t *pkt, size_t pktlen, ngtcp2_tstamp ts) { - int rv = 0; - - conn->log.last_ts = ts; - conn->qlog.last_ts = ts; - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, "recv packet len=%zu", - pktlen); - - if (pktlen == 0) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - /* client does not expect a packet from unknown path. */ - if (!conn->server && !ngtcp2_path_eq(&conn->dcid.current.ps.path, path) && - (!conn->pv || !ngtcp2_path_eq(&conn->pv->dcid.ps.path, path)) && - !conn_is_retired_path(conn, path)) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, - "ignore packet from unknown path"); - return 0; - } - - switch (conn->state) { - case NGTCP2_CS_CLIENT_INITIAL: - case NGTCP2_CS_CLIENT_WAIT_HANDSHAKE: - case NGTCP2_CS_CLIENT_TLS_HANDSHAKE_FAILED: - case NGTCP2_CS_SERVER_INITIAL: - case NGTCP2_CS_SERVER_WAIT_HANDSHAKE: - case NGTCP2_CS_SERVER_TLS_HANDSHAKE_FAILED: - return conn_read_handshake(conn, path, pkt, pktlen, ts); - case NGTCP2_CS_CLOSING: - return NGTCP2_ERR_CLOSING; - case NGTCP2_CS_DRAINING: - return NGTCP2_ERR_DRAINING; - case NGTCP2_CS_POST_HANDSHAKE: - rv = conn_prepare_key_update(conn, ts); - if (rv != 0) { - return rv; - } - return conn_recv_cpkt(conn, path, pkt, pktlen, ts); - default: - assert(0); - } -} - -/* - * conn_check_pkt_num_exhausted returns nonzero if packet number is - * exhausted in at least one of packet number space. - */ -static int conn_check_pkt_num_exhausted(ngtcp2_conn *conn) { - ngtcp2_pktns *in_pktns = conn->in_pktns; - ngtcp2_pktns *hs_pktns = conn->hs_pktns; - - return (in_pktns && in_pktns->tx.last_pkt_num == NGTCP2_MAX_PKT_NUM) || - (hs_pktns && hs_pktns->tx.last_pkt_num == NGTCP2_MAX_PKT_NUM) || - conn->pktns.tx.last_pkt_num == NGTCP2_MAX_PKT_NUM; -} - -/* - * conn_server_hs_tx_left returns the maximum number of bytes that - * server is allowed to send during handshake. - */ -static size_t conn_server_hs_tx_left(ngtcp2_conn *conn) { - if (conn->flags & NGTCP2_CONN_FLAG_SADDR_VERIFIED) { - return SIZE_MAX; - } - /* From QUIC spec: Prior to validating the client address, servers - MUST NOT send more than three times as many bytes as the number - of bytes they have received. */ - assert(conn->cstat.bytes_recv * 3 >= conn->cstat.bytes_sent); - - return conn->cstat.bytes_recv * 3 - conn->cstat.bytes_sent; -} - -/* - * conn_retransmit_retry_early retransmits 0RTT packet after Retry is - * received from server. - */ -static ngtcp2_ssize conn_retransmit_retry_early(ngtcp2_conn *conn, - uint8_t *dest, size_t destlen, - ngtcp2_tstamp ts) { - return conn_write_pkt(conn, dest, destlen, NULL, NGTCP2_PKT_0RTT, - NGTCP2_WRITE_PKT_FLAG_NONE, ts); -} - -/* - * conn_handshake_probe_left returns nonzero if there are probe - * packets to be sent for Initial or Handshake packet number space - * left. - */ -static int conn_handshake_probe_left(ngtcp2_conn *conn) { - return (conn->in_pktns && conn->in_pktns->rtb.probe_pkt_left) || - conn->hs_pktns->rtb.probe_pkt_left; -} - -/* - * conn_write_handshake writes QUIC handshake packets to the buffer - * pointed by |dest| of length |destlen|. |early_datalen| specifies - * the expected length of early data to send. Specify 0 to - * |early_datalen| if there is no early data. - * - * This function returns the number of bytes written to the buffer, or - * one of the following negative error codes: - * - * NGTCP2_ERR_PKT_NUM_EXHAUSTED - * Packet number is exhausted. - * NGTCP2_ERR_NOMEM - * Out of memory - * NGTCP2_ERR_REQUIRED_TRANSPORT_PARAM - * Required transport parameter is missing. - * NGTCP2_CS_CLOSING - * Connection is in closing state. - * NGTCP2_CS_DRAINING - * Connection is in draining state. - * - * In addition to the above negative error codes, the same error codes - * from conn_recv_pkt may also be returned. - */ -static ngtcp2_ssize conn_write_handshake(ngtcp2_conn *conn, uint8_t *dest, - size_t destlen, size_t early_datalen, - ngtcp2_tstamp ts) { - int rv; - ngtcp2_ssize res = 0, nwrite = 0, early_spktlen = 0; - size_t origlen = destlen; - size_t server_hs_tx_left; - ngtcp2_conn_stat *cstat = &conn->cstat; - size_t pending_early_datalen; - ngtcp2_dcid *dcid; - ngtcp2_preferred_addr *paddr; - - switch (conn->state) { - case NGTCP2_CS_CLIENT_INITIAL: - pending_early_datalen = conn_retry_early_payloadlen(conn); - if (pending_early_datalen) { - early_datalen = pending_early_datalen; - } - - if (!(conn->flags & NGTCP2_CONN_FLAG_RECV_RETRY)) { - nwrite = - conn_write_client_initial(conn, dest, destlen, early_datalen, ts); - if (nwrite <= 0) { - return nwrite; - } - } else { - nwrite = conn_write_handshake_pkt(conn, dest, destlen, NGTCP2_PKT_INITIAL, - early_datalen, ts); - if (nwrite < 0) { - return nwrite; - } - } - - if (pending_early_datalen) { - early_spktlen = conn_retransmit_retry_early(conn, dest + nwrite, - destlen - (size_t)nwrite, ts); - - if (early_spktlen < 0) { - assert(ngtcp2_err_is_fatal((int)early_spktlen)); - return early_spktlen; - } - } - - conn->state = NGTCP2_CS_CLIENT_WAIT_HANDSHAKE; - - res = nwrite + early_spktlen; - cstat->bytes_sent += (size_t)res; - - return res; - case NGTCP2_CS_CLIENT_WAIT_HANDSHAKE: - if (!conn_handshake_probe_left(conn) && conn_cwnd_is_zero(conn)) { - destlen = 0; - } else { - if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED)) { - pending_early_datalen = conn_retry_early_payloadlen(conn); - if (pending_early_datalen) { - early_datalen = pending_early_datalen; - } - } - - nwrite = - conn_write_handshake_pkts(conn, dest, destlen, early_datalen, ts); - if (nwrite < 0) { - return nwrite; - } - - res += nwrite; - dest += nwrite; - destlen -= (size_t)nwrite; - } - - if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED)) { - nwrite = conn_retransmit_retry_early(conn, dest, destlen, ts); - if (nwrite < 0) { - return nwrite; - } - - res += nwrite; - - if (res == 0) { - nwrite = conn_write_handshake_ack_pkts(conn, dest, origlen, ts); - if (nwrite < 0) { - return nwrite; - } - res = nwrite; - } - - cstat->bytes_sent += (size_t)res; - - return res; - } - - if (!(conn->flags & NGTCP2_CONN_FLAG_TRANSPORT_PARAM_RECVED)) { - return NGTCP2_ERR_REQUIRED_TRANSPORT_PARAM; - } - - rv = conn_handshake_completed(conn); - if (rv != 0) { - return (ngtcp2_ssize)rv; - } - - conn->state = NGTCP2_CS_POST_HANDSHAKE; - - if (conn->remote.transport_params.preferred_address_present) { - assert(!ngtcp2_ringbuf_full(&conn->dcid.unused)); - - paddr = &conn->remote.transport_params.preferred_address; - dcid = ngtcp2_ringbuf_push_back(&conn->dcid.unused); - ngtcp2_dcid_init(dcid, 1, &paddr->cid, paddr->stateless_reset_token); - - rv = ngtcp2_gaptr_push(&conn->dcid.seqgap, 1, 1); - if (rv != 0) { - return (ngtcp2_ssize)rv; - } - } - - if (conn->remote.transport_params.stateless_reset_token_present) { - assert(conn->dcid.current.seq == 0); - memcpy(conn->dcid.current.token, - conn->remote.transport_params.stateless_reset_token, - sizeof(conn->dcid.current.token)); - } - - rv = conn_call_activate_dcid(conn, &conn->dcid.current); - if (rv != 0) { - return rv; - } - - conn_process_early_rtb(conn); - - rv = conn_process_buffered_protected_pkt(conn, &conn->pktns, ts); - if (rv != 0) { - return (ngtcp2_ssize)rv; - } - - cstat->bytes_sent += (size_t)res; - - return res; - case NGTCP2_CS_SERVER_INITIAL: - nwrite = conn_write_handshake_pkts(conn, dest, destlen, - /* early_datalen = */ 0, ts); - if (nwrite < 0) { - return nwrite; - } - - if (nwrite) { - conn->state = NGTCP2_CS_SERVER_WAIT_HANDSHAKE; - cstat->bytes_sent += (size_t)nwrite; - } - - return nwrite; - case NGTCP2_CS_SERVER_WAIT_HANDSHAKE: - if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED)) { - server_hs_tx_left = conn_server_hs_tx_left(conn); - if (server_hs_tx_left == 0) { - if (cstat->loss_detection_timer) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_RCV, - "loss detection timer canceled"); - cstat->loss_detection_timer = 0; - cstat->pto_count = 0; - } - return 0; - } - - if (conn_handshake_probe_left(conn) || !conn_cwnd_is_zero(conn)) { - nwrite = conn_write_handshake_pkts(conn, dest, destlen, - /* early_datalen = */ 0, ts); - if (nwrite < 0) { - return nwrite; - } - - res += nwrite; - dest += nwrite; - destlen -= (size_t)nwrite; - } - - if (res == 0) { - nwrite = conn_write_handshake_ack_pkts(conn, dest, origlen, ts); - if (nwrite < 0) { - return nwrite; - } - - res += nwrite; - dest += nwrite; - origlen -= (size_t)nwrite; - } - - cstat->bytes_sent += (size_t)res; - return res; - } - - return 0; - case NGTCP2_CS_CLOSING: - return NGTCP2_ERR_CLOSING; - case NGTCP2_CS_DRAINING: - return NGTCP2_ERR_DRAINING; - default: - return 0; - } -} - -/** - * @function - * - * `conn_client_write_handshake` writes client side handshake data and - * 0RTT packet. - * - * In order to send STREAM data in 0RTT packet, specify - * |vmsg|->stream. |vmsg|->stream.strm, |vmsg|->stream.fin, - * |vmsg|->stream.data, and |vmsg|->stream.datacnt are stream to which - * 0-RTT data is sent, whether it is a last data chunk in this stream, - * a vector of 0-RTT data, and its number of elements respectively. - * The amount of 0RTT data sent is assigned to - * *|vmsg|->stream.pdatalen. If no data is sent, -1 is assigned. - * Note that 0 length STREAM frame is allowed in QUIC, so 0 might be - * assigned to *|vmsg|->stream.pdatalen. - * - * This function returns 0 if it cannot write any frame because buffer - * is too small, or packet is congestion limited. Application should - * keep reading and wait for congestion window to grow. - * - * This function returns the number of bytes written to the buffer - * pointed by |dest| if it succeeds, or one of the following negative - * error codes: (TBD). - */ -static ngtcp2_ssize conn_client_write_handshake(ngtcp2_conn *conn, - uint8_t *dest, size_t destlen, - ngtcp2_vmsg *vmsg, - ngtcp2_tstamp ts) { - int send_stream = 0; - ngtcp2_ssize spktlen, early_spktlen; - int was_client_initial; - size_t datalen; - size_t early_datalen = 0; - uint8_t wflags = NGTCP2_WRITE_PKT_FLAG_NONE; - int ppe_pending = (conn->flags & NGTCP2_CONN_FLAG_PPE_PENDING) != 0; - - assert(!conn->server); - - /* conn->early.ckm might be created in the first call of - conn_handshake(). Check it later. */ - if (vmsg && vmsg->type == NGTCP2_VMSG_TYPE_STREAM && - !(conn->flags & NGTCP2_CONN_FLAG_EARLY_DATA_REJECTED)) { - datalen = ngtcp2_vec_len(vmsg->stream.data, vmsg->stream.datacnt); - send_stream = - conn_retry_early_payloadlen(conn) == 0 && - /* 0 length STREAM frame is allowed */ - (datalen == 0 || - (datalen > 0 && - (vmsg->stream.strm->tx.max_offset - vmsg->stream.strm->tx.offset) && - (conn->tx.max_offset - conn->tx.offset))); - if (send_stream) { - early_datalen = - conn_enforce_flow_control(conn, vmsg->stream.strm, datalen) + - NGTCP2_STREAM_OVERHEAD; - - if (vmsg->stream.flags & NGTCP2_WRITE_STREAM_FLAG_MORE) { - wflags |= NGTCP2_WRITE_PKT_FLAG_MORE; - } - } else { - vmsg = NULL; - } - } - - if (!ppe_pending) { - was_client_initial = conn->state == NGTCP2_CS_CLIENT_INITIAL; - spktlen = conn_write_handshake(conn, dest, destlen, early_datalen, ts); - - if (spktlen < 0) { - return spktlen; - } - - if (conn->pktns.crypto.tx.ckm || !conn->early.ckm || !send_stream) { - return spktlen; - } - } else { - assert(!conn->pktns.crypto.tx.ckm); - assert(conn->early.ckm); - - was_client_initial = conn->pkt.was_client_initial; - spktlen = conn->pkt.hs_spktlen; - } - - /* If spktlen > 0, we are making a compound packet. If Initial - packet is written, we have to pad bytes to 0-RTT packet. */ - - if (spktlen && was_client_initial) { - wflags |= NGTCP2_WRITE_PKT_FLAG_REQUIRE_PADDING; - } - - dest += spktlen; - destlen -= (size_t)spktlen; - - if (conn_cwnd_is_zero(conn)) { - return spktlen; - } - - early_spktlen = - conn_write_pkt(conn, dest, destlen, vmsg, NGTCP2_PKT_0RTT, wflags, ts); - - if (early_spktlen < 0) { - switch (early_spktlen) { - case NGTCP2_ERR_STREAM_DATA_BLOCKED: - return spktlen; - case NGTCP2_ERR_WRITE_MORE: - conn->pkt.was_client_initial = was_client_initial; - conn->pkt.hs_spktlen = spktlen; - break; - } - return early_spktlen; - } - - conn->cstat.bytes_sent += (size_t)early_spktlen; - - return spktlen + early_spktlen; -} - -void ngtcp2_conn_handshake_completed(ngtcp2_conn *conn) { - conn->flags |= NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED; - if (conn->server) { - conn->flags |= NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED; - } -} - -int ngtcp2_conn_get_handshake_completed(ngtcp2_conn *conn) { - return (conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED) && - (conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED); -} - -int ngtcp2_conn_sched_ack(ngtcp2_conn *conn, ngtcp2_acktr *acktr, - int64_t pkt_num, int active_ack, ngtcp2_tstamp ts) { - int rv; - (void)conn; - - rv = ngtcp2_acktr_add(acktr, pkt_num, active_ack, ts); - if (rv != 0) { - assert(rv != NGTCP2_ERR_INVALID_ARGUMENT); - return rv; - } - - return 0; -} - -int ngtcp2_accept(ngtcp2_pkt_hd *dest, const uint8_t *pkt, size_t pktlen) { - ngtcp2_ssize nread; - ngtcp2_pkt_hd hd, *p; - - if (dest) { - p = dest; - } else { - p = &hd; - } - - if (pktlen == 0 || (pkt[0] & NGTCP2_HEADER_FORM_BIT) == 0) { - return -1; - } - - nread = ngtcp2_pkt_decode_hd_long(p, pkt, pktlen); - if (nread < 0) { - return -1; - } - - switch (p->type) { - case NGTCP2_PKT_INITIAL: - if (pktlen < NGTCP2_MIN_INITIAL_PKTLEN) { - return -1; - } - if (p->token.len == 0 && p->dcid.datalen < NGTCP2_MIN_INITIAL_DCIDLEN) { - return -1; - } - break; - case NGTCP2_PKT_0RTT: - /* 0-RTT packet may arrive before Initial packet due to - re-ordering. */ - break; - default: - return -1; - } - - switch (p->version) { - case NGTCP2_PROTO_VER: - break; - default: - return 1; - } - - return 0; -} - -void ngtcp2_conn_set_aead_overhead(ngtcp2_conn *conn, size_t aead_overhead) { - conn->crypto.aead_overhead = aead_overhead; -} - -size_t ngtcp2_conn_get_aead_overhead(ngtcp2_conn *conn) { - return conn->crypto.aead_overhead; -} - -int ngtcp2_conn_install_initial_key( - ngtcp2_conn *conn, const ngtcp2_crypto_aead_ctx *rx_aead_ctx, - const uint8_t *rx_iv, const ngtcp2_crypto_cipher_ctx *rx_hp_ctx, - const ngtcp2_crypto_aead_ctx *tx_aead_ctx, const uint8_t *tx_iv, - const ngtcp2_crypto_cipher_ctx *tx_hp_ctx, size_t ivlen) { - ngtcp2_pktns *pktns = conn->in_pktns; - int rv; - - assert(pktns); - - conn_call_delete_crypto_cipher_ctx(conn, &pktns->crypto.rx.hp_ctx); - pktns->crypto.rx.hp_ctx.native_handle = NULL; - - if (pktns->crypto.rx.ckm) { - conn_call_delete_crypto_aead_ctx(conn, &pktns->crypto.rx.ckm->aead_ctx); - ngtcp2_crypto_km_del(pktns->crypto.rx.ckm, conn->mem); - pktns->crypto.rx.ckm = NULL; - } - - conn_call_delete_crypto_cipher_ctx(conn, &pktns->crypto.tx.hp_ctx); - pktns->crypto.tx.hp_ctx.native_handle = NULL; - - if (pktns->crypto.tx.ckm) { - conn_call_delete_crypto_aead_ctx(conn, &pktns->crypto.tx.ckm->aead_ctx); - ngtcp2_crypto_km_del(pktns->crypto.tx.ckm, conn->mem); - pktns->crypto.tx.ckm = NULL; - } - - rv = ngtcp2_crypto_km_new(&pktns->crypto.rx.ckm, NULL, 0, NULL, rx_iv, ivlen, - conn->mem); - if (rv != 0) { - return rv; - } - - rv = ngtcp2_crypto_km_new(&pktns->crypto.tx.ckm, NULL, 0, NULL, tx_iv, ivlen, - conn->mem); - if (rv != 0) { - return rv; - } - - /* Take owner ship after we are sure that no failure occurs, so that - caller can delete these contexts on failure. */ - pktns->crypto.rx.ckm->aead_ctx = *rx_aead_ctx; - pktns->crypto.rx.hp_ctx = *rx_hp_ctx; - pktns->crypto.tx.ckm->aead_ctx = *tx_aead_ctx; - pktns->crypto.tx.hp_ctx = *tx_hp_ctx; - - return 0; -} - -int ngtcp2_conn_install_rx_handshake_key( - ngtcp2_conn *conn, const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *iv, size_t ivlen, const ngtcp2_crypto_cipher_ctx *hp_ctx) { - ngtcp2_pktns *pktns = conn->hs_pktns; - int rv; - - assert(pktns); - assert(!pktns->crypto.rx.hp_ctx.native_handle); - assert(!pktns->crypto.rx.ckm); - - rv = ngtcp2_crypto_km_new(&pktns->crypto.rx.ckm, NULL, 0, aead_ctx, iv, ivlen, - conn->mem); - if (rv != 0) { - return rv; - } - - pktns->crypto.rx.hp_ctx = *hp_ctx; - - return 0; -} - -int ngtcp2_conn_install_tx_handshake_key( - ngtcp2_conn *conn, const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *iv, size_t ivlen, const ngtcp2_crypto_cipher_ctx *hp_ctx) { - ngtcp2_pktns *pktns = conn->hs_pktns; - int rv; - - assert(pktns); - assert(!pktns->crypto.tx.hp_ctx.native_handle); - assert(!pktns->crypto.tx.ckm); - - rv = ngtcp2_crypto_km_new(&pktns->crypto.tx.ckm, NULL, 0, aead_ctx, iv, ivlen, - conn->mem); - if (rv != 0) { - return rv; - } - - pktns->crypto.tx.hp_ctx = *hp_ctx; - - if (conn->server) { - return ngtcp2_conn_commit_local_transport_params(conn); - } - - return 0; -} - -int ngtcp2_conn_install_early_key(ngtcp2_conn *conn, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *iv, size_t ivlen, - const ngtcp2_crypto_cipher_ctx *hp_ctx) { - int rv; - - assert(!conn->early.hp_ctx.native_handle); - assert(!conn->early.ckm); - - rv = ngtcp2_crypto_km_new(&conn->early.ckm, NULL, 0, aead_ctx, iv, ivlen, - conn->mem); - if (rv != 0) { - return rv; - } - - conn->early.hp_ctx = *hp_ctx; - - return 0; -} - -int ngtcp2_conn_install_rx_key(ngtcp2_conn *conn, const uint8_t *secret, - size_t secretlen, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *iv, size_t ivlen, - const ngtcp2_crypto_cipher_ctx *hp_ctx) { - ngtcp2_pktns *pktns = &conn->pktns; - int rv; - - assert(!pktns->crypto.rx.hp_ctx.native_handle); - assert(!pktns->crypto.rx.ckm); - - rv = ngtcp2_crypto_km_new(&pktns->crypto.rx.ckm, secret, secretlen, aead_ctx, - iv, ivlen, conn->mem); - if (rv != 0) { - return rv; - } - - pktns->crypto.rx.hp_ctx = *hp_ctx; - - return 0; -} - -int ngtcp2_conn_install_tx_key(ngtcp2_conn *conn, const uint8_t *secret, - size_t secretlen, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *iv, size_t ivlen, - const ngtcp2_crypto_cipher_ctx *hp_ctx) { - ngtcp2_pktns *pktns = &conn->pktns; - int rv; - - assert(!pktns->crypto.tx.hp_ctx.native_handle); - assert(!pktns->crypto.tx.ckm); - - rv = ngtcp2_crypto_km_new(&pktns->crypto.tx.ckm, secret, secretlen, aead_ctx, - iv, ivlen, conn->mem); - if (rv != 0) { - return rv; - } - - pktns->crypto.tx.hp_ctx = *hp_ctx; - - conn->remote.transport_params = conn->remote.pending_transport_params; - conn_sync_stream_id_limit(conn); - conn->tx.max_offset = conn->remote.transport_params.initial_max_data; - - return 0; -} - -int ngtcp2_conn_initiate_key_update(ngtcp2_conn *conn, ngtcp2_tstamp ts) { - ngtcp2_tstamp confirmed_ts = conn->crypto.key_update.confirmed_ts; - ngtcp2_duration pto = conn_compute_pto(conn, &conn->pktns); - - assert(conn->state == NGTCP2_CS_POST_HANDSHAKE); - - if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED) || - (conn->flags & NGTCP2_CONN_FLAG_KEY_UPDATE_NOT_CONFIRMED) || - !conn->crypto.key_update.new_tx_ckm || - !conn->crypto.key_update.new_rx_ckm || - (confirmed_ts != UINT64_MAX && confirmed_ts + 3 * pto > ts)) { - return NGTCP2_ERR_INVALID_STATE; - } - - conn_rotate_keys(conn, NGTCP2_MAX_PKT_NUM); - - return 0; -} - -ngtcp2_tstamp ngtcp2_conn_loss_detection_expiry(ngtcp2_conn *conn) { - if (conn->cstat.loss_detection_timer) { - return conn->cstat.loss_detection_timer; - } - return UINT64_MAX; -} - -ngtcp2_tstamp ngtcp2_conn_internal_expiry(ngtcp2_conn *conn) { - ngtcp2_tstamp res = UINT64_MAX; - ngtcp2_duration pto = conn_compute_pto(conn, &conn->pktns); - ngtcp2_scid *scid; - ngtcp2_dcid *dcid; - - if (conn->pv) { - res = ngtcp2_pv_next_expiry(conn->pv); - } - - if (!ngtcp2_pq_empty(&conn->scid.used)) { - scid = ngtcp2_struct_of(ngtcp2_pq_top(&conn->scid.used), ngtcp2_scid, pe); - if (scid->ts_retired != UINT64_MAX) { - res = ngtcp2_min(res, scid->ts_retired + pto); - } - } - - if (ngtcp2_ringbuf_len(&conn->dcid.retired)) { - dcid = ngtcp2_ringbuf_get(&conn->dcid.retired, 0); - res = ngtcp2_min(res, dcid->ts_retired + pto); - } - - return res; -} - -ngtcp2_tstamp ngtcp2_conn_ack_delay_expiry(ngtcp2_conn *conn) { - ngtcp2_acktr *acktr = &conn->pktns.acktr; - - if (!(acktr->flags & NGTCP2_ACKTR_FLAG_CANCEL_TIMER) && - acktr->first_unacked_ts != UINT64_MAX) { - return acktr->first_unacked_ts + conn_compute_ack_delay(conn); - } - return UINT64_MAX; -} - -ngtcp2_tstamp ngtcp2_conn_get_expiry(ngtcp2_conn *conn) { - ngtcp2_tstamp t1 = ngtcp2_conn_loss_detection_expiry(conn); - ngtcp2_tstamp t2 = ngtcp2_conn_ack_delay_expiry(conn); - ngtcp2_tstamp t3 = ngtcp2_conn_internal_expiry(conn); - ngtcp2_tstamp t4 = ngtcp2_conn_lost_pkt_expiry(conn); - ngtcp2_tstamp res = ngtcp2_min(t1, t2); - res = ngtcp2_min(res, t3); - return ngtcp2_min(res, t4); -} - -int ngtcp2_conn_handle_expiry(ngtcp2_conn *conn, ngtcp2_tstamp ts) { - int rv; - - ngtcp2_conn_cancel_expired_ack_delay_timer(conn, ts); - - ngtcp2_conn_remove_lost_pkt(conn, ts); - - if (ngtcp2_conn_loss_detection_expiry(conn) <= ts) { - rv = ngtcp2_conn_on_loss_detection_timer(conn, ts); - if (rv != 0) { - return rv; - } - } - - return 0; -} - -static void acktr_cancel_expired_ack_delay_timer(ngtcp2_acktr *acktr, - ngtcp2_tstamp ts) { - if (!(acktr->flags & NGTCP2_ACKTR_FLAG_CANCEL_TIMER) && - acktr->first_unacked_ts <= ts) { - acktr->flags |= NGTCP2_ACKTR_FLAG_CANCEL_TIMER; - } -} - -void ngtcp2_conn_cancel_expired_ack_delay_timer(ngtcp2_conn *conn, - ngtcp2_tstamp ts) { - if (conn->in_pktns) { - acktr_cancel_expired_ack_delay_timer(&conn->in_pktns->acktr, ts); - } - if (conn->hs_pktns) { - acktr_cancel_expired_ack_delay_timer(&conn->hs_pktns->acktr, ts); - } - acktr_cancel_expired_ack_delay_timer(&conn->pktns.acktr, ts); -} - -ngtcp2_tstamp ngtcp2_conn_lost_pkt_expiry(ngtcp2_conn *conn) { - ngtcp2_tstamp res = UINT64_MAX, ts; - - if (conn->in_pktns) { - ts = ngtcp2_rtb_lost_pkt_ts(&conn->in_pktns->rtb); - if (ts != UINT64_MAX) { - ts += conn_compute_pto(conn, conn->in_pktns); - res = ngtcp2_min(res, ts); - } - } - - if (conn->hs_pktns) { - ts = ngtcp2_rtb_lost_pkt_ts(&conn->hs_pktns->rtb); - if (ts != UINT64_MAX) { - ts += conn_compute_pto(conn, conn->hs_pktns); - res = ngtcp2_min(res, ts); - } - } - - ts = ngtcp2_rtb_lost_pkt_ts(&conn->pktns.rtb); - if (ts != UINT64_MAX) { - ts += conn_compute_pto(conn, &conn->pktns); - res = ngtcp2_min(res, ts); - } - - return res; -} - -void ngtcp2_conn_remove_lost_pkt(ngtcp2_conn *conn, ngtcp2_tstamp ts) { - ngtcp2_tstamp pto; - - if (conn->in_pktns) { - pto = conn_compute_pto(conn, conn->in_pktns); - ngtcp2_rtb_remove_expired_lost_pkt(&conn->in_pktns->rtb, pto, ts); - } - if (conn->hs_pktns) { - pto = conn_compute_pto(conn, conn->hs_pktns); - ngtcp2_rtb_remove_expired_lost_pkt(&conn->hs_pktns->rtb, pto, ts); - } - pto = conn_compute_pto(conn, &conn->pktns); - ngtcp2_rtb_remove_expired_lost_pkt(&conn->pktns.rtb, pto, ts); -} - -/* - * conn_client_validate_transport_params validates |params| as client. - * |params| must be sent with Encrypted Extensions. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_PROTO - * Validation against either of original_dcid and retry_scid is - * failed. - * NGTCP2_ERR_TRANSPORT_PARAM - * params contains preferred address but server chose zero-length - * connection ID. - */ -static int -conn_client_validate_transport_params(ngtcp2_conn *conn, - const ngtcp2_transport_params *params) { - if (!ngtcp2_cid_eq(&conn->rcid, ¶ms->original_dcid)) { - return NGTCP2_ERR_TRANSPORT_PARAM; - } - - if (conn->flags & NGTCP2_CONN_FLAG_RECV_RETRY) { - if (!params->retry_scid_present) { - return NGTCP2_ERR_TRANSPORT_PARAM; - } - if (!ngtcp2_cid_eq(&conn->retry_scid, ¶ms->retry_scid)) { - return NGTCP2_ERR_TRANSPORT_PARAM; - } - } else if (params->retry_scid_present) { - return NGTCP2_ERR_TRANSPORT_PARAM; - } - - if (params->preferred_address_present && - conn->dcid.current.cid.datalen == 0) { - return NGTCP2_ERR_TRANSPORT_PARAM; - } - - return 0; -} - -int ngtcp2_conn_set_remote_transport_params( - ngtcp2_conn *conn, const ngtcp2_transport_params *params) { - int rv; - - assert(!(conn->flags & NGTCP2_CONN_FLAG_TRANSPORT_PARAM_RECVED)); - - /* Assume that ngtcp2_decode_transport_params sets default value if - active_connection_id_limit is omitted. */ - if (params->active_connection_id_limit < - NGTCP2_DEFAULT_ACTIVE_CONNECTION_ID_LIMIT) { - return NGTCP2_ERR_TRANSPORT_PARAM; - } - - /* We assume that conn->dcid.current.cid is still the initial one. - This requires that transport parameter must be fed into - ngtcp2_conn as early as possible. */ - if (!ngtcp2_cid_eq(&conn->dcid.current.cid, ¶ms->initial_scid)) { - return NGTCP2_ERR_TRANSPORT_PARAM; - } - - if (!conn->server) { - rv = conn_client_validate_transport_params(conn, params); - if (rv != 0) { - return rv; - } - } - - ngtcp2_log_remote_tp(&conn->log, - conn->server - ? NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO - : NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS, - params); - - ngtcp2_qlog_parameters_set_transport_params(&conn->qlog, params, conn->server, - NGTCP2_QLOG_SIDE_REMOTE); - - if (conn->pktns.crypto.tx.ckm) { - conn->remote.transport_params = *params; - conn_sync_stream_id_limit(conn); - conn->tx.max_offset = conn->remote.transport_params.initial_max_data; - } else { - conn->remote.pending_transport_params = *params; - } - - conn->flags |= NGTCP2_CONN_FLAG_TRANSPORT_PARAM_RECVED; - - return 0; -} - -void ngtcp2_conn_get_remote_transport_params(ngtcp2_conn *conn, - ngtcp2_transport_params *params) { - if (conn->pktns.crypto.rx.ckm) { - *params = conn->remote.transport_params; - } else { - *params = conn->remote.pending_transport_params; - } -} - -void ngtcp2_conn_set_early_remote_transport_params( - ngtcp2_conn *conn, const ngtcp2_transport_params *params) { - ngtcp2_transport_params *p = &conn->remote.transport_params; - - assert(!conn->server); - - memset(p, 0, sizeof(*p)); - - p->initial_max_streams_bidi = params->initial_max_streams_bidi; - p->initial_max_streams_uni = params->initial_max_streams_uni; - p->initial_max_stream_data_bidi_local = - params->initial_max_stream_data_bidi_local; - p->initial_max_stream_data_bidi_remote = - params->initial_max_stream_data_bidi_remote; - p->initial_max_stream_data_uni = params->initial_max_stream_data_uni; - p->initial_max_data = params->initial_max_data; - - conn_sync_stream_id_limit(conn); - - conn->tx.max_offset = p->initial_max_data; - - ngtcp2_qlog_parameters_set_transport_params(&conn->qlog, p, conn->server, - NGTCP2_QLOG_SIDE_REMOTE); -} - -int ngtcp2_conn_set_local_transport_params( - ngtcp2_conn *conn, const ngtcp2_transport_params *params) { - assert(conn->server); - assert(params->active_connection_id_limit <= NGTCP2_MAX_DCID_POOL_SIZE); - - if (conn->hs_pktns == NULL || conn->hs_pktns->crypto.tx.ckm) { - return NGTCP2_ERR_INVALID_STATE; - } - - conn->local.settings.transport_params = *params; - - return 0; -} - -int ngtcp2_conn_commit_local_transport_params(ngtcp2_conn *conn) { - const ngtcp2_mem *mem = conn->mem; - ngtcp2_transport_params *params = &conn->local.settings.transport_params; - ngtcp2_scid *scident; - ngtcp2_ksl_it it; - int rv; - - assert(1 == ngtcp2_ksl_len(&conn->scid.set)); - - if (params->active_connection_id_limit == 0) { - params->active_connection_id_limit = - NGTCP2_DEFAULT_ACTIVE_CONNECTION_ID_LIMIT; - } - - params->initial_scid = conn->oscid; - - if (conn->oscid.datalen == 0) { - params->preferred_address_present = 0; - } - - if (conn->server) { - if (params->stateless_reset_token_present) { - it = ngtcp2_ksl_begin(&conn->scid.set); - scident = ngtcp2_ksl_it_get(&it); - - memcpy(scident->token, params->stateless_reset_token, - NGTCP2_STATELESS_RESET_TOKENLEN); - } - - if (params->preferred_address_present) { - scident = ngtcp2_mem_malloc(mem, sizeof(*scident)); - if (scident == NULL) { - return NGTCP2_ERR_NOMEM; - } - - ngtcp2_scid_init(scident, 1, ¶ms->preferred_address.cid, - params->preferred_address.stateless_reset_token); - - rv = ngtcp2_ksl_insert(&conn->scid.set, NULL, &scident->cid, scident); - if (rv != 0) { - ngtcp2_mem_free(mem, scident); - return rv; - } - - conn->scid.last_seq = 1; - } - } - - conn->rx.unsent_max_offset = conn->rx.max_offset = params->initial_max_data; - conn->remote.bidi.unsent_max_streams = params->initial_max_streams_bidi; - conn->remote.bidi.max_streams = params->initial_max_streams_bidi; - conn->remote.uni.unsent_max_streams = params->initial_max_streams_uni; - conn->remote.uni.max_streams = params->initial_max_streams_uni; - - ngtcp2_qlog_parameters_set_transport_params(&conn->qlog, params, conn->server, - NGTCP2_QLOG_SIDE_LOCAL); - - return 0; -} - -void ngtcp2_conn_get_local_transport_params(ngtcp2_conn *conn, - ngtcp2_transport_params *params) { - *params = conn->local.settings.transport_params; -} - -int ngtcp2_conn_open_bidi_stream(ngtcp2_conn *conn, int64_t *pstream_id, - void *stream_user_data) { - int rv; - ngtcp2_strm *strm; - - if (ngtcp2_conn_get_streams_bidi_left(conn) == 0) { - return NGTCP2_ERR_STREAM_ID_BLOCKED; - } - - strm = ngtcp2_mem_malloc(conn->mem, sizeof(ngtcp2_strm)); - if (strm == NULL) { - return NGTCP2_ERR_NOMEM; - } - - rv = ngtcp2_conn_init_stream(conn, strm, conn->local.bidi.next_stream_id, - stream_user_data); - if (rv != 0) { - ngtcp2_mem_free(conn->mem, strm); - return rv; - } - - *pstream_id = conn->local.bidi.next_stream_id; - conn->local.bidi.next_stream_id += 4; - - return 0; -} - -int ngtcp2_conn_open_uni_stream(ngtcp2_conn *conn, int64_t *pstream_id, - void *stream_user_data) { - int rv; - ngtcp2_strm *strm; - - if (ngtcp2_conn_get_streams_uni_left(conn) == 0) { - return NGTCP2_ERR_STREAM_ID_BLOCKED; - } - - strm = ngtcp2_mem_malloc(conn->mem, sizeof(ngtcp2_strm)); - if (strm == NULL) { - return NGTCP2_ERR_NOMEM; - } - - rv = ngtcp2_conn_init_stream(conn, strm, conn->local.uni.next_stream_id, - stream_user_data); - if (rv != 0) { - ngtcp2_mem_free(conn->mem, strm); - return rv; - } - ngtcp2_strm_shutdown(strm, NGTCP2_STRM_FLAG_SHUT_RD); - - *pstream_id = conn->local.uni.next_stream_id; - conn->local.uni.next_stream_id += 4; - - return 0; -} - -ngtcp2_strm *ngtcp2_conn_find_stream(ngtcp2_conn *conn, int64_t stream_id) { - ngtcp2_map_entry *me; - - me = ngtcp2_map_find(&conn->strms, (uint64_t)stream_id); - if (me == NULL) { - return NULL; - } - - return ngtcp2_struct_of(me, ngtcp2_strm, me); -} - -ngtcp2_ssize ngtcp2_conn_write_stream(ngtcp2_conn *conn, ngtcp2_path *path, - uint8_t *dest, size_t destlen, - ngtcp2_ssize *pdatalen, uint32_t flags, - int64_t stream_id, const uint8_t *data, - size_t datalen, ngtcp2_tstamp ts) { - ngtcp2_vec datav; - - datav.len = datalen; - datav.base = (uint8_t *)data; - - return ngtcp2_conn_writev_stream(conn, path, dest, destlen, pdatalen, flags, - stream_id, &datav, 1, ts); -} - -ngtcp2_ssize ngtcp2_conn_writev_stream(ngtcp2_conn *conn, ngtcp2_path *path, - uint8_t *dest, size_t destlen, - ngtcp2_ssize *pdatalen, uint32_t flags, - int64_t stream_id, - const ngtcp2_vec *datav, size_t datavcnt, - ngtcp2_tstamp ts) { - ngtcp2_vmsg vmsg, *pvmsg; - ngtcp2_strm *strm; - - if (pdatalen) { - *pdatalen = -1; - } - - if (stream_id != -1) { - strm = ngtcp2_conn_find_stream(conn, stream_id); - if (strm == NULL) { - return NGTCP2_ERR_STREAM_NOT_FOUND; - } - - if (strm->flags & NGTCP2_STRM_FLAG_SHUT_WR) { - return NGTCP2_ERR_STREAM_SHUT_WR; - } - - vmsg.type = NGTCP2_VMSG_TYPE_STREAM; - vmsg.stream.strm = strm; - vmsg.stream.flags = flags; - vmsg.stream.data = datav; - vmsg.stream.datacnt = datavcnt; - vmsg.stream.pdatalen = pdatalen; - - pvmsg = &vmsg; - } else { - pvmsg = NULL; - } - - return ngtcp2_conn_write_vmsg(conn, path, dest, destlen, pvmsg, ts); -} - -ngtcp2_ssize ngtcp2_conn_write_vmsg(ngtcp2_conn *conn, ngtcp2_path *path, - uint8_t *dest, size_t destlen, - ngtcp2_vmsg *vmsg, ngtcp2_tstamp ts) { - ngtcp2_ssize nwrite; - ngtcp2_pktns *pktns = &conn->pktns; - size_t origlen = destlen; - int rv; - uint8_t wflags = NGTCP2_WRITE_PKT_FLAG_NONE; - int ppe_pending = (conn->flags & NGTCP2_CONN_FLAG_PPE_PENDING) != 0; - ngtcp2_ssize res = 0; - size_t server_hs_tx_left; - - conn->log.last_ts = ts; - conn->qlog.last_ts = ts; - - if (path) { - ngtcp2_path_copy(path, &conn->dcid.current.ps.path); - } - - switch (conn->state) { - case NGTCP2_CS_CLIENT_INITIAL: - case NGTCP2_CS_CLIENT_WAIT_HANDSHAKE: - case NGTCP2_CS_CLIENT_TLS_HANDSHAKE_FAILED: - nwrite = conn_client_write_handshake(conn, dest, destlen, vmsg, ts); - if (nwrite < 0 || conn->state != NGTCP2_CS_POST_HANDSHAKE) { - return nwrite; - } - res = nwrite; - dest += nwrite; - destlen -= (size_t)nwrite; - /* Break here so that we can coalesces Short packets. */ - break; - case NGTCP2_CS_SERVER_INITIAL: - case NGTCP2_CS_SERVER_WAIT_HANDSHAKE: - case NGTCP2_CS_SERVER_TLS_HANDSHAKE_FAILED: - if (!ppe_pending) { - server_hs_tx_left = conn_server_hs_tx_left(conn); - destlen = ngtcp2_min(destlen, server_hs_tx_left); - - nwrite = conn_write_handshake(conn, dest, destlen, 0, ts); - if (nwrite < 0) { - return nwrite; - } - - if (conn->flags & NGTCP2_CONN_FLAG_SADDR_VERIFIED) { - destlen = origlen; - } else { - origlen = destlen; - } - - res = nwrite; - dest += nwrite; - destlen -= (size_t)nwrite; - } - if (conn->state != NGTCP2_CS_POST_HANDSHAKE && - conn->pktns.crypto.tx.ckm == NULL) { - return res; - } - break; - case NGTCP2_CS_POST_HANDSHAKE: - break; - case NGTCP2_CS_CLOSING: - return NGTCP2_ERR_CLOSING; - case NGTCP2_CS_DRAINING: - return NGTCP2_ERR_DRAINING; - default: - return 0; - } - - assert(pktns->crypto.tx.ckm); - - if (conn_check_pkt_num_exhausted(conn)) { - return NGTCP2_ERR_PKT_NUM_EXHAUSTED; - } - - rv = conn_remove_retired_connection_id(conn, ts); - if (rv != 0) { - return rv; - } - - if (vmsg) { - switch (vmsg->type) { - case NGTCP2_VMSG_TYPE_STREAM: - if (vmsg->stream.flags & NGTCP2_WRITE_STREAM_FLAG_MORE) { - wflags |= NGTCP2_WRITE_PKT_FLAG_MORE; - } - break; - default: - break; - } - } - - if (ppe_pending) { - res = conn->pkt.hs_spktlen; - conn->pkt.hs_spktlen = 0; - /* dest and destlen have already been adjusted in ppe in the first - run. They are adjusted for probe packet later. */ - nwrite = - conn_write_pkt(conn, dest, destlen, vmsg, NGTCP2_PKT_SHORT, wflags, ts); - goto fin; - } else { - if (conn->state == NGTCP2_CS_POST_HANDSHAKE) { - rv = conn_prepare_key_update(conn, ts); - if (rv != 0) { - return rv; - } - } - - if (!conn->pktns.rtb.probe_pkt_left && conn_cwnd_is_zero(conn)) { - destlen = 0; - } else if (conn->pv) { - nwrite = conn_write_path_challenge(conn, path, dest, destlen, ts); - if (nwrite) { - goto fin; - } - } - } - - if (res == 0) { - if (conn_handshake_remnants_left(conn)) { - if (conn_handshake_probe_left(conn)) { - destlen = origlen; - } - nwrite = conn_write_handshake_pkts(conn, dest, destlen, 0, ts); - if (nwrite < 0) { - return nwrite; - } - if (nwrite > 0) { - res = nwrite; - dest += nwrite; - destlen -= (size_t)nwrite; - } - } - } - - if (conn->pktns.rtb.probe_pkt_left) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_CON, - "transmit probe pkt left=%zu", - conn->pktns.rtb.probe_pkt_left); - - nwrite = - conn_write_pkt(conn, dest, destlen, vmsg, NGTCP2_PKT_SHORT, wflags, ts); - - goto fin; - } - - nwrite = - conn_write_pkt(conn, dest, destlen, vmsg, NGTCP2_PKT_SHORT, wflags, ts); - if (nwrite) { - assert(nwrite != NGTCP2_ERR_NOBUF); - goto fin; - } - - if (res == 0) { - nwrite = conn_write_ack_pkt(conn, dest, origlen, NGTCP2_PKT_SHORT, ts); - } - -fin: - conn->pkt.hs_spktlen = 0; - - if (nwrite >= 0) { - conn->cstat.bytes_sent += (size_t)nwrite; - return res + nwrite; - } - /* NGTCP2_CONN_FLAG_PPE_PENDING is set in conn_write_pkt above. - ppe_pending cannot be used here. */ - if (conn->flags & NGTCP2_CONN_FLAG_PPE_PENDING) { - conn->pkt.hs_spktlen = res; - } - - return nwrite; -} - -static ngtcp2_ssize conn_write_connection_close(ngtcp2_conn *conn, - uint8_t *dest, size_t destlen, - uint8_t pkt_type, - uint64_t error_code, - ngtcp2_tstamp ts) { - ngtcp2_pktns *in_pktns = conn->in_pktns; - ngtcp2_pktns *hs_pktns = conn->hs_pktns; - ngtcp2_ssize res = 0, nwrite; - ngtcp2_frame fr; - - fr.type = NGTCP2_FRAME_CONNECTION_CLOSE; - fr.connection_close.error_code = error_code; - fr.connection_close.frame_type = 0; - fr.connection_close.reasonlen = 0; - fr.connection_close.reason = NULL; - - if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED) && - pkt_type != NGTCP2_PKT_INITIAL) { - if (in_pktns && conn->server) { - nwrite = ngtcp2_conn_write_single_frame_pkt( - conn, dest, destlen, NGTCP2_PKT_INITIAL, &conn->dcid.current.cid, &fr, - NGTCP2_RTB_FLAG_NONE, ts); - if (nwrite < 0) { - return nwrite; - } - - dest += nwrite; - destlen -= (size_t)nwrite; - res += nwrite; - } - - if (pkt_type != NGTCP2_PKT_HANDSHAKE && hs_pktns && - hs_pktns->crypto.tx.ckm) { - nwrite = ngtcp2_conn_write_single_frame_pkt( - conn, dest, destlen, NGTCP2_PKT_HANDSHAKE, &conn->dcid.current.cid, - &fr, NGTCP2_RTB_FLAG_NONE, ts); - if (nwrite < 0) { - return nwrite; - } - - dest += nwrite; - destlen -= (size_t)nwrite; - res += nwrite; - } - } - - nwrite = ngtcp2_conn_write_single_frame_pkt(conn, dest, destlen, pkt_type, - &conn->dcid.current.cid, &fr, - NGTCP2_RTB_FLAG_NONE, ts); - - if (nwrite < 0) { - return nwrite; - } - - res += nwrite; - - if (res == 0) { - return NGTCP2_ERR_NOBUF; - } - - return res; -} - -ngtcp2_ssize ngtcp2_conn_write_connection_close(ngtcp2_conn *conn, - ngtcp2_path *path, - uint8_t *dest, size_t destlen, - uint64_t error_code, - ngtcp2_tstamp ts) { - ngtcp2_pktns *in_pktns = conn->in_pktns; - ngtcp2_pktns *hs_pktns = conn->hs_pktns; - uint8_t pkt_type; - ngtcp2_ssize nwrite; - - conn->log.last_ts = ts; - conn->qlog.last_ts = ts; - - if (conn_check_pkt_num_exhausted(conn)) { - return NGTCP2_ERR_PKT_NUM_EXHAUSTED; - } - - switch (conn->state) { - case NGTCP2_CS_CLIENT_INITIAL: - case NGTCP2_CS_CLOSING: - case NGTCP2_CS_DRAINING: - return NGTCP2_ERR_INVALID_STATE; - default: - break; - } - - if (path) { - ngtcp2_path_copy(path, &conn->dcid.current.ps.path); - } - - if (conn->state == NGTCP2_CS_POST_HANDSHAKE || - (conn->server && conn->pktns.crypto.tx.ckm)) { - pkt_type = NGTCP2_PKT_SHORT; - } else if (hs_pktns && hs_pktns->crypto.tx.ckm) { - pkt_type = NGTCP2_PKT_HANDSHAKE; - } else if (in_pktns && in_pktns->crypto.tx.ckm) { - pkt_type = NGTCP2_PKT_INITIAL; - } else { - /* This branch is taken if server has not read any Initial packet - from client. */ - return NGTCP2_ERR_INVALID_STATE; - } - - nwrite = conn_write_connection_close(conn, dest, destlen, pkt_type, - error_code, ts); - if (nwrite < 0) { - return nwrite; - } - - conn->state = NGTCP2_CS_CLOSING; - - return nwrite; -} - -ngtcp2_ssize ngtcp2_conn_write_application_close(ngtcp2_conn *conn, - ngtcp2_path *path, - uint8_t *dest, size_t destlen, - uint64_t app_error_code, - ngtcp2_tstamp ts) { - ngtcp2_ssize nwrite; - ngtcp2_ssize res = 0; - ngtcp2_frame fr; - - conn->log.last_ts = ts; - conn->qlog.last_ts = ts; - - if (conn_check_pkt_num_exhausted(conn)) { - return NGTCP2_ERR_PKT_NUM_EXHAUSTED; - } - - switch (conn->state) { - case NGTCP2_CS_CLIENT_INITIAL: - case NGTCP2_CS_CLOSING: - case NGTCP2_CS_DRAINING: - return NGTCP2_ERR_INVALID_STATE; - default: - break; - } - - if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED)) { - nwrite = conn_write_connection_close(conn, dest, destlen, - conn->hs_pktns->crypto.tx.ckm - ? NGTCP2_PKT_HANDSHAKE - : NGTCP2_PKT_INITIAL, - NGTCP2_APPLICATION_ERROR, ts); - if (nwrite < 0) { - return nwrite; - } - res = nwrite; - dest += nwrite; - destlen -= (size_t)nwrite; - } - - if (conn->state != NGTCP2_CS_POST_HANDSHAKE) { - assert(res); - - if (!conn->server || !conn->pktns.crypto.tx.ckm) { - return res; - } - } - - assert(conn->pktns.crypto.tx.ckm); - - if (path) { - ngtcp2_path_copy(path, &conn->dcid.current.ps.path); - } - - fr.type = NGTCP2_FRAME_CONNECTION_CLOSE_APP; - fr.connection_close.error_code = app_error_code; - fr.connection_close.frame_type = 0; - fr.connection_close.reasonlen = 0; - fr.connection_close.reason = NULL; - - nwrite = ngtcp2_conn_write_single_frame_pkt( - conn, dest, destlen, NGTCP2_PKT_SHORT, &conn->dcid.current.cid, &fr, - NGTCP2_RTB_FLAG_NONE, ts); - - if (nwrite < 0) { - return nwrite; - } - - res += nwrite; - - if (res == 0) { - return NGTCP2_ERR_NOBUF; - } - - conn->state = NGTCP2_CS_CLOSING; - - return res; -} - -int ngtcp2_conn_is_in_closing_period(ngtcp2_conn *conn) { - return conn->state == NGTCP2_CS_CLOSING; -} - -int ngtcp2_conn_is_in_draining_period(ngtcp2_conn *conn) { - return conn->state == NGTCP2_CS_DRAINING; -} - -int ngtcp2_conn_close_stream(ngtcp2_conn *conn, ngtcp2_strm *strm, - uint64_t app_error_code) { - int rv; - - if (!strm->app_error_code) { - app_error_code = strm->app_error_code; - } - - rv = ngtcp2_map_remove(&conn->strms, strm->me.key); - if (rv != 0) { - assert(rv != NGTCP2_ERR_INVALID_ARGUMENT); - return rv; - } - - rv = conn_call_stream_close(conn, strm, app_error_code); - if (rv != 0) { - goto fin; - } - - if (ngtcp2_strm_is_tx_queued(strm)) { - ngtcp2_pq_remove(&conn->tx.strmq, &strm->pe); - } - -fin: - ngtcp2_strm_free(strm); - ngtcp2_mem_free(conn->mem, strm); - - return rv; -} - -int ngtcp2_conn_close_stream_if_shut_rdwr(ngtcp2_conn *conn, ngtcp2_strm *strm, - uint64_t app_error_code) { - if ((strm->flags & NGTCP2_STRM_FLAG_SHUT_RDWR) == - NGTCP2_STRM_FLAG_SHUT_RDWR && - ((strm->flags & NGTCP2_STRM_FLAG_RECV_RST) || - ngtcp2_strm_rx_offset(strm) == strm->rx.last_offset) && - (((strm->flags & NGTCP2_STRM_FLAG_SENT_RST) && - (strm->flags & NGTCP2_STRM_FLAG_RST_ACKED)) || - (!(strm->flags & NGTCP2_STRM_FLAG_SENT_RST) && - ngtcp2_strm_is_all_tx_data_acked(strm)))) { - return ngtcp2_conn_close_stream(conn, strm, app_error_code); - } - return 0; -} - -/* - * conn_shutdown_stream_write closes send stream with error code - * |app_error_code|. RESET_STREAM frame is scheduled. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int conn_shutdown_stream_write(ngtcp2_conn *conn, ngtcp2_strm *strm, - uint64_t app_error_code) { - if (strm->flags & NGTCP2_STRM_FLAG_SENT_RST) { - return 0; - } - - /* Set this flag so that we don't accidentally send DATA to this - stream. */ - strm->flags |= NGTCP2_STRM_FLAG_SHUT_WR | NGTCP2_STRM_FLAG_SENT_RST; - strm->app_error_code = app_error_code; - - ngtcp2_strm_streamfrq_clear(strm); - - return conn_reset_stream(conn, strm, app_error_code); -} - -/* - * conn_shutdown_stream_read closes read stream with error code - * |app_error_code|. STOP_SENDING frame is scheduled. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int conn_shutdown_stream_read(ngtcp2_conn *conn, ngtcp2_strm *strm, - uint64_t app_error_code) { - if (strm->flags & NGTCP2_STRM_FLAG_STOP_SENDING) { - return 0; - } - if ((strm->flags & NGTCP2_STRM_FLAG_SHUT_RD) && - ngtcp2_strm_rx_offset(strm) == strm->rx.last_offset) { - return 0; - } - - /* Extend connection flow control window for the amount of data - which are not passed to application. */ - if (!(strm->flags & - (NGTCP2_STRM_FLAG_STOP_SENDING | NGTCP2_STRM_FLAG_RECV_RST))) { - ngtcp2_conn_extend_max_offset(conn, strm->rx.last_offset - - ngtcp2_strm_rx_offset(strm)); - } - - strm->flags |= NGTCP2_STRM_FLAG_STOP_SENDING; - strm->app_error_code = app_error_code; - - return conn_stop_sending(conn, strm, app_error_code); -} - -int ngtcp2_conn_shutdown_stream(ngtcp2_conn *conn, int64_t stream_id, - uint64_t app_error_code) { - int rv; - ngtcp2_strm *strm; - - strm = ngtcp2_conn_find_stream(conn, stream_id); - if (strm == NULL) { - return NGTCP2_ERR_STREAM_NOT_FOUND; - } - - rv = conn_shutdown_stream_read(conn, strm, app_error_code); - if (rv != 0) { - return rv; - } - - rv = conn_shutdown_stream_write(conn, strm, app_error_code); - if (rv != 0) { - return rv; - } - - return 0; -} - -int ngtcp2_conn_shutdown_stream_write(ngtcp2_conn *conn, int64_t stream_id, - uint64_t app_error_code) { - ngtcp2_strm *strm; - - strm = ngtcp2_conn_find_stream(conn, stream_id); - if (strm == NULL) { - return NGTCP2_ERR_STREAM_NOT_FOUND; - } - - return conn_shutdown_stream_write(conn, strm, app_error_code); -} - -int ngtcp2_conn_shutdown_stream_read(ngtcp2_conn *conn, int64_t stream_id, - uint64_t app_error_code) { - ngtcp2_strm *strm; - - strm = ngtcp2_conn_find_stream(conn, stream_id); - if (strm == NULL) { - return NGTCP2_ERR_STREAM_NOT_FOUND; - } - - return conn_shutdown_stream_read(conn, strm, app_error_code); -} - -/* - * conn_extend_max_stream_offset extends stream level flow control - * window by |datalen| of the stream denoted by |strm|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int conn_extend_max_stream_offset(ngtcp2_conn *conn, ngtcp2_strm *strm, - uint64_t datalen) { - ngtcp2_strm *top; - - if (datalen > NGTCP2_MAX_VARINT || - strm->rx.unsent_max_offset > NGTCP2_MAX_VARINT - datalen) { - strm->rx.unsent_max_offset = NGTCP2_MAX_VARINT; - } else { - strm->rx.unsent_max_offset += datalen; - } - - if (!(strm->flags & - (NGTCP2_STRM_FLAG_SHUT_RD | NGTCP2_STRM_FLAG_STOP_SENDING)) && - !ngtcp2_strm_is_tx_queued(strm) && - conn_should_send_max_stream_data(conn, strm)) { - if (!ngtcp2_pq_empty(&conn->tx.strmq)) { - top = ngtcp2_conn_tx_strmq_top(conn); - strm->cycle = top->cycle; - } - strm->cycle = conn_tx_strmq_first_cycle(conn); - return ngtcp2_conn_tx_strmq_push(conn, strm); - } - - return 0; -} - -int ngtcp2_conn_extend_max_stream_offset(ngtcp2_conn *conn, int64_t stream_id, - uint64_t datalen) { - ngtcp2_strm *strm; - - strm = ngtcp2_conn_find_stream(conn, stream_id); - if (strm == NULL) { - return NGTCP2_ERR_STREAM_NOT_FOUND; - } - - return conn_extend_max_stream_offset(conn, strm, datalen); -} - -void ngtcp2_conn_extend_max_offset(ngtcp2_conn *conn, uint64_t datalen) { - if (NGTCP2_MAX_VARINT < datalen || - conn->rx.unsent_max_offset > NGTCP2_MAX_VARINT - datalen) { - conn->rx.unsent_max_offset = NGTCP2_MAX_VARINT; - return; - } - - conn->rx.unsent_max_offset += datalen; -} - -void ngtcp2_conn_extend_max_streams_bidi(ngtcp2_conn *conn, size_t n) { - handle_max_remote_streams_extension(&conn->remote.bidi.unsent_max_streams, n); -} - -void ngtcp2_conn_extend_max_streams_uni(ngtcp2_conn *conn, size_t n) { - handle_max_remote_streams_extension(&conn->remote.uni.unsent_max_streams, n); -} - -const ngtcp2_cid *ngtcp2_conn_get_dcid(ngtcp2_conn *conn) { - return &conn->dcid.current.cid; -} - -uint32_t ngtcp2_conn_get_negotiated_version(ngtcp2_conn *conn) { - return conn->version; -} - -int ngtcp2_conn_early_data_rejected(ngtcp2_conn *conn) { - ngtcp2_pktns *pktns = &conn->pktns; - ngtcp2_rtb *rtb = &conn->pktns.rtb; - int rv; - - conn->flags |= NGTCP2_CONN_FLAG_EARLY_DATA_REJECTED; - - rv = ngtcp2_rtb_remove_all(rtb, conn, pktns, &conn->cstat); - if (rv != 0) { - return rv; - } - - return rv; -} - -void ngtcp2_conn_update_rtt(ngtcp2_conn *conn, ngtcp2_duration rtt, - ngtcp2_duration ack_delay) { - ngtcp2_conn_stat *cstat = &conn->cstat; - - rtt = ngtcp2_max(rtt, NGTCP2_GRANULARITY); - - cstat->latest_rtt = rtt; - - if (cstat->min_rtt == UINT64_MAX) { - cstat->min_rtt = rtt; - cstat->smoothed_rtt = rtt; - cstat->rttvar = rtt / 2; - } else { - cstat->min_rtt = ngtcp2_min(cstat->min_rtt, rtt); - if (conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED) { - ack_delay = - ngtcp2_min(ack_delay, conn->remote.transport_params.max_ack_delay); - } else { - ack_delay = ngtcp2_min(ack_delay, NGTCP2_DEFAULT_MAX_ACK_DELAY); - } - if (rtt > cstat->min_rtt + ack_delay) { - rtt -= ack_delay; - } - - cstat->rttvar = (cstat->rttvar * 3 + (cstat->smoothed_rtt < rtt - ? rtt - cstat->smoothed_rtt - : cstat->smoothed_rtt - rtt)) / - 4; - cstat->smoothed_rtt = (cstat->smoothed_rtt * 7 + rtt) / 8; - } - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_RCV, - "latest_rtt=%" PRIu64 " min_rtt=%" PRIu64 - " smoothed_rtt=%" PRIu64 " rttvar=%" PRIu64 - " ack_delay=%" PRIu64, - (uint64_t)(cstat->latest_rtt / NGTCP2_MILLISECONDS), - (uint64_t)(cstat->min_rtt / NGTCP2_MILLISECONDS), - cstat->smoothed_rtt / NGTCP2_MILLISECONDS, - cstat->rttvar / NGTCP2_MILLISECONDS, - (uint64_t)(ack_delay / NGTCP2_MILLISECONDS)); -} - -void ngtcp2_conn_get_conn_stat(ngtcp2_conn *conn, ngtcp2_conn_stat *cstat) { - *cstat = conn->cstat; -} - -static ngtcp2_pktns *conn_get_earliest_pktns(ngtcp2_conn *conn, - ngtcp2_tstamp *pts, - const ngtcp2_tstamp *times) { - ngtcp2_pktns *ns[] = {conn->in_pktns, conn->hs_pktns, &conn->pktns}; - ngtcp2_pktns *res = ns[0]; - size_t i; - ngtcp2_tstamp earliest_ts = times[NGTCP2_PKTNS_ID_INITIAL]; - - for (i = NGTCP2_PKTNS_ID_HANDSHAKE; i < NGTCP2_PKTNS_ID_MAX; ++i) { - if (ns[i] == NULL || ns[i]->rtb.num_retransmittable == 0 || - (times[i] == UINT64_MAX || - (earliest_ts != UINT64_MAX && times[i] >= earliest_ts) || - (i == NGTCP2_PKTNS_ID_APP && - !(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED)))) { - continue; - } - - earliest_ts = times[i]; - res = ns[i]; - } - - if (res == NULL && !conn->server) { - earliest_ts = UINT64_MAX; - - if (conn->hs_pktns && conn->hs_pktns->crypto.tx.ckm) { - res = conn->hs_pktns; - } else { - res = conn->in_pktns; - } - } - - if (pts) { - *pts = earliest_ts; - } - return res; -} - -void ngtcp2_conn_set_loss_detection_timer(ngtcp2_conn *conn, ngtcp2_tstamp ts) { - ngtcp2_conn_stat *cstat = &conn->cstat; - ngtcp2_duration timeout; - ngtcp2_pktns *in_pktns = conn->in_pktns; - ngtcp2_pktns *hs_pktns = conn->hs_pktns; - ngtcp2_pktns *pktns = &conn->pktns; - ngtcp2_pktns *earliest_pktns; - ngtcp2_tstamp earliest_loss_time; - ngtcp2_tstamp last_tx_pkt_ts; - - conn_get_earliest_pktns(conn, &earliest_loss_time, cstat->loss_time); - - if (earliest_loss_time != UINT64_MAX) { - cstat->loss_detection_timer = earliest_loss_time; - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_RCV, - "loss_detection_timer=%" PRIu64 " nonzero crypto loss time", - cstat->loss_detection_timer); - return; - } - - if ((!in_pktns || in_pktns->rtb.num_retransmittable == 0) && - (!hs_pktns || hs_pktns->rtb.num_retransmittable == 0) && - (pktns->rtb.num_retransmittable == 0 || - !(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED)) && - (conn->server || - (conn->flags & (NGTCP2_CONN_FLAG_SERVER_ADDR_VERIFIED | - NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED)))) { - if (cstat->loss_detection_timer) { - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_RCV, - "loss detection timer canceled"); - cstat->loss_detection_timer = 0; - cstat->pto_count = 0; - } - return; - } - - earliest_pktns = - conn_get_earliest_pktns(conn, &last_tx_pkt_ts, cstat->last_tx_pkt_ts); - - assert(earliest_pktns); - - if (last_tx_pkt_ts == UINT64_MAX) { - last_tx_pkt_ts = ts; - } - - timeout = conn_compute_pto(conn, earliest_pktns) * (1ULL << cstat->pto_count); - - cstat->loss_detection_timer = last_tx_pkt_ts + timeout; - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_RCV, - "loss_detection_timer=%" PRIu64 " last_tx_pkt_ts=%" PRIu64 - " timeout=%" PRIu64, - cstat->loss_detection_timer, last_tx_pkt_ts, - (uint64_t)(timeout / NGTCP2_MILLISECONDS)); -} - -int ngtcp2_conn_on_loss_detection_timer(ngtcp2_conn *conn, ngtcp2_tstamp ts) { - ngtcp2_conn_stat *cstat = &conn->cstat; - int rv; - ngtcp2_pktns *in_pktns = conn->in_pktns; - ngtcp2_pktns *hs_pktns = conn->hs_pktns; - ngtcp2_tstamp earliest_loss_time; - ngtcp2_pktns *loss_pktns = - conn_get_earliest_pktns(conn, &earliest_loss_time, cstat->loss_time); - ngtcp2_pktns *earliest_pktns; - - conn->log.last_ts = ts; - conn->qlog.last_ts = ts; - - switch (conn->state) { - case NGTCP2_CS_CLOSING: - case NGTCP2_CS_DRAINING: - cstat->loss_detection_timer = 0; - cstat->pto_count = 0; - return 0; - default: - break; - } - - if (!cstat->loss_detection_timer) { - return 0; - } - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_RCV, - "loss detection timer fired"); - - if (earliest_loss_time != UINT64_MAX) { - rv = ngtcp2_conn_detect_lost_pkt(conn, loss_pktns, cstat, ts); - if (rv != 0) { - return rv; - } - ngtcp2_conn_set_loss_detection_timer(conn, ts); - return 0; - } - - if (!conn->server && !(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED)) { - if (hs_pktns->crypto.tx.ckm) { - hs_pktns->rtb.probe_pkt_left = 1; - } else { - in_pktns->rtb.probe_pkt_left = 1; - } - } else { - earliest_pktns = conn_get_earliest_pktns(conn, NULL, cstat->last_tx_pkt_ts); - - assert(earliest_pktns); - - switch (earliest_pktns->rtb.pktns_id) { - case NGTCP2_PKTNS_ID_INITIAL: - assert(in_pktns); - in_pktns->rtb.probe_pkt_left = 1; - if (!conn->server) { - break; - } - /* fall through for server so that it can coalesce packets. */ - /* fall through */ - case NGTCP2_PKTNS_ID_HANDSHAKE: - assert(hs_pktns); - hs_pktns->rtb.probe_pkt_left = 1; - break; - case NGTCP2_PKTNS_ID_APP: - conn->pktns.rtb.probe_pkt_left = 2; - break; - default: - assert(0); - } - } - - ++cstat->pto_count; - - ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_RCV, "pto_count=%zu", - cstat->pto_count); - - ngtcp2_conn_set_loss_detection_timer(conn, ts); - - return 0; -} - -int ngtcp2_conn_submit_crypto_data(ngtcp2_conn *conn, - ngtcp2_crypto_level crypto_level, - const uint8_t *data, const size_t datalen) { - ngtcp2_pktns *pktns; - ngtcp2_frame_chain *frc; - ngtcp2_crypto *fr; - int rv; - - if (datalen == 0) { - return 0; - } - - switch (crypto_level) { - case NGTCP2_CRYPTO_LEVEL_INITIAL: - assert(conn->in_pktns); - pktns = conn->in_pktns; - break; - case NGTCP2_CRYPTO_LEVEL_HANDSHAKE: - assert(conn->hs_pktns); - pktns = conn->hs_pktns; - break; - case NGTCP2_CRYPTO_LEVEL_APP: - pktns = &conn->pktns; - break; - default: - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - rv = ngtcp2_frame_chain_new(&frc, conn->mem); - if (rv != 0) { - return rv; - } - - fr = &frc->fr.crypto; - - fr->type = NGTCP2_FRAME_CRYPTO; - fr->offset = pktns->crypto.tx.offset; - fr->datacnt = 1; - fr->data[0].len = datalen; - fr->data[0].base = (uint8_t *)data; - - rv = ngtcp2_ksl_insert(&pktns->crypto.tx.frq, NULL, &fr->offset, frc); - if (rv != 0) { - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - - pktns->crypto.strm.tx.offset += datalen; - pktns->crypto.tx.offset += datalen; - - return 0; -} - -int ngtcp2_conn_submit_new_token(ngtcp2_conn *conn, const uint8_t *token, - size_t tokenlen) { - int rv; - ngtcp2_frame_chain *nfrc; - uint8_t *p; - - assert(conn->server); - assert(token); - assert(tokenlen); - - rv = ngtcp2_frame_chain_extralen_new(&nfrc, tokenlen, conn->mem); - if (rv != 0) { - return rv; - } - - nfrc->fr.type = NGTCP2_FRAME_NEW_TOKEN; - - p = (uint8_t *)nfrc + sizeof(*nfrc); - memcpy(p, token, tokenlen); - - ngtcp2_vec_init(&nfrc->fr.new_token.token, p, tokenlen); - - nfrc->next = conn->pktns.tx.frq; - conn->pktns.tx.frq = nfrc; - - return 0; -} - -ngtcp2_strm *ngtcp2_conn_tx_strmq_top(ngtcp2_conn *conn) { - assert(!ngtcp2_pq_empty(&conn->tx.strmq)); - return ngtcp2_struct_of(ngtcp2_pq_top(&conn->tx.strmq), ngtcp2_strm, pe); -} - -void ngtcp2_conn_tx_strmq_pop(ngtcp2_conn *conn) { - ngtcp2_strm *strm = ngtcp2_conn_tx_strmq_top(conn); - assert(strm); - ngtcp2_pq_pop(&conn->tx.strmq); - strm->pe.index = NGTCP2_PQ_BAD_INDEX; -} - -int ngtcp2_conn_tx_strmq_push(ngtcp2_conn *conn, ngtcp2_strm *strm) { - return ngtcp2_pq_push(&conn->tx.strmq, &strm->pe); -} - -size_t ngtcp2_conn_get_num_scid(ngtcp2_conn *conn) { - return ngtcp2_ksl_len(&conn->scid.set); -} - -size_t ngtcp2_conn_get_scid(ngtcp2_conn *conn, ngtcp2_cid *dest) { - ngtcp2_ksl_it it; - ngtcp2_scid *scid; - - for (it = ngtcp2_ksl_begin(&conn->scid.set); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - scid = ngtcp2_ksl_it_get(&it); - *dest++ = scid->cid; - } - - return ngtcp2_ksl_len(&conn->scid.set); -} - -size_t ngtcp2_conn_get_num_active_dcid(ngtcp2_conn *conn) { - size_t n = 1; /* for conn->dcid.current */ - ngtcp2_pv *pv = conn->pv; - - if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED)) { - return 0; - } - - if (pv) { - if (pv->dcid.seq != conn->dcid.current.seq) { - ++n; - } - if ((pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE) && - pv->fallback_dcid.seq != conn->dcid.current.seq && - pv->fallback_dcid.seq != pv->dcid.seq) { - ++n; - } - } - - n += ngtcp2_ringbuf_len(&conn->dcid.retired); - - return n; -} - -static void copy_dcid_to_cid_token(ngtcp2_cid_token *dest, - const ngtcp2_dcid *src) { - dest->seq = src->seq; - dest->cid = src->cid; - ngtcp2_path_storage_init2(&dest->ps, &src->ps.path); - dest->token_present = - (uint8_t)!ngtcp2_check_invalid_stateless_reset_token(src->token); - memcpy(dest->token, src->token, NGTCP2_STATELESS_RESET_TOKENLEN); -} - -size_t ngtcp2_conn_get_active_dcid(ngtcp2_conn *conn, ngtcp2_cid_token *dest) { - ngtcp2_pv *pv = conn->pv; - ngtcp2_cid_token *orig = dest; - ngtcp2_dcid *dcid; - size_t len, i; - - if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED)) { - return 0; - } - - copy_dcid_to_cid_token(dest, &conn->dcid.current); - ++dest; - - if (pv) { - if (pv->dcid.seq != conn->dcid.current.seq) { - copy_dcid_to_cid_token(dest, &pv->dcid); - ++dest; - } - if ((pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE) && - pv->fallback_dcid.seq != conn->dcid.current.seq && - pv->fallback_dcid.seq != pv->dcid.seq) { - copy_dcid_to_cid_token(dest, &pv->fallback_dcid); - ++dest; - } - } - - len = ngtcp2_ringbuf_len(&conn->dcid.retired); - for (i = 0; i < len; ++i) { - dcid = ngtcp2_ringbuf_get(&conn->dcid.retired, i); - copy_dcid_to_cid_token(dest, dcid); - ++dest; - } - - return (size_t)(dest - orig); -} - -void ngtcp2_conn_set_local_addr(ngtcp2_conn *conn, const ngtcp2_addr *addr) { - ngtcp2_addr *dest = &conn->dcid.current.ps.path.local; - - assert(addr->addrlen <= sizeof(conn->dcid.current.ps.local_addrbuf)); - ngtcp2_addr_copy(dest, addr); -} - -void ngtcp2_conn_set_remote_addr(ngtcp2_conn *conn, const ngtcp2_addr *addr) { - ngtcp2_addr *dest = &conn->dcid.current.ps.path.remote; - - assert(addr->addrlen <= sizeof(conn->dcid.current.ps.remote_addrbuf)); - ngtcp2_addr_copy(dest, addr); -} - -const ngtcp2_addr *ngtcp2_conn_get_remote_addr(ngtcp2_conn *conn) { - return &conn->dcid.current.ps.path.remote; -} - -int ngtcp2_conn_initiate_migration(ngtcp2_conn *conn, const ngtcp2_path *path, - ngtcp2_tstamp ts) { - int rv; - ngtcp2_dcid *dcid; - - assert(!conn->server); - - conn->log.last_ts = ts; - conn->qlog.last_ts = ts; - - if (conn->remote.transport_params.disable_active_migration || - !(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED)) { - return NGTCP2_ERR_INVALID_STATE; - } - if (ngtcp2_ringbuf_len(&conn->dcid.unused) == 0) { - return NGTCP2_ERR_CONN_ID_BLOCKED; - } - - if (ngtcp2_path_eq(&conn->dcid.current.ps.path, path)) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - dcid = ngtcp2_ringbuf_get(&conn->dcid.unused, 0); - - rv = conn_stop_pv(conn, ts); - if (rv != 0) { - return rv; - } - - rv = conn_retire_dcid(conn, &conn->dcid.current, ts); - if (rv != 0) { - return rv; - } - - ngtcp2_dcid_copy(&conn->dcid.current, dcid); - ngtcp2_path_copy(&conn->dcid.current.ps.path, path); - ngtcp2_ringbuf_pop_front(&conn->dcid.unused); - - rv = conn_call_activate_dcid(conn, &conn->dcid.current); - if (rv != 0) { - return rv; - } - - conn_reset_congestion_state(conn); - - return 0; -} - -uint64_t ngtcp2_conn_get_max_local_streams_uni(ngtcp2_conn *conn) { - return conn->local.uni.max_streams; -} - -uint64_t ngtcp2_conn_get_max_data_left(ngtcp2_conn *conn) { - return conn->tx.max_offset - conn->tx.offset; -} - -uint64_t ngtcp2_conn_get_streams_bidi_left(ngtcp2_conn *conn) { - uint64_t n = ngtcp2_ord_stream_id(conn->local.bidi.next_stream_id); - - return n > conn->local.bidi.max_streams - ? 0 - : conn->local.bidi.max_streams - n + 1; -} - -uint64_t ngtcp2_conn_get_streams_uni_left(ngtcp2_conn *conn) { - uint64_t n = ngtcp2_ord_stream_id(conn->local.uni.next_stream_id); - - return n > conn->local.uni.max_streams ? 0 - : conn->local.uni.max_streams - n + 1; -} - -ngtcp2_tstamp ngtcp2_conn_get_idle_expiry(ngtcp2_conn *conn) { - ngtcp2_duration trpto; - ngtcp2_duration idle_timeout; - - /* TODO Remote max_idle_timeout becomes effective after handshake - completion. */ - - if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED) || - conn->remote.transport_params.max_idle_timeout == 0 || - (conn->local.settings.transport_params.max_idle_timeout && - conn->local.settings.transport_params.max_idle_timeout < - conn->remote.transport_params.max_idle_timeout)) { - idle_timeout = conn->local.settings.transport_params.max_idle_timeout; - } else { - idle_timeout = conn->remote.transport_params.max_idle_timeout; - } - - if (idle_timeout == 0) { - return UINT64_MAX; - } - - trpto = 3 * conn_compute_pto( - conn, (conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED) - ? &conn->pktns - : conn->hs_pktns); - - return conn->idle_ts + ngtcp2_max(idle_timeout, trpto); -} - -ngtcp2_duration ngtcp2_conn_get_pto(ngtcp2_conn *conn) { - return conn_compute_pto(conn, - (conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED) - ? &conn->pktns - : conn->hs_pktns); -} - -void ngtcp2_conn_set_initial_crypto_ctx(ngtcp2_conn *conn, - const ngtcp2_crypto_ctx *ctx) { - assert(conn->in_pktns); - conn->in_pktns->crypto.ctx = *ctx; -} - -const ngtcp2_crypto_ctx *ngtcp2_conn_get_initial_crypto_ctx(ngtcp2_conn *conn) { - assert(conn->in_pktns); - return &conn->in_pktns->crypto.ctx; -} - -void ngtcp2_conn_set_retry_aead(ngtcp2_conn *conn, - const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx) { - assert(!conn->crypto.retry_aead_ctx.native_handle); - - conn->crypto.retry_aead = *aead; - conn->crypto.retry_aead_ctx = *aead_ctx; -} - -void ngtcp2_conn_set_crypto_ctx(ngtcp2_conn *conn, - const ngtcp2_crypto_ctx *ctx) { - assert(conn->hs_pktns); - conn->hs_pktns->crypto.ctx = *ctx; - conn->pktns.crypto.ctx = *ctx; -} - -const ngtcp2_crypto_ctx *ngtcp2_conn_get_crypto_ctx(ngtcp2_conn *conn) { - return &conn->pktns.crypto.ctx; -} - -void *ngtcp2_conn_get_tls_native_handle(ngtcp2_conn *conn) { - return conn->crypto.tls_native_handle; -} - -void ngtcp2_conn_set_tls_native_handle(ngtcp2_conn *conn, - void *tls_native_handle) { - conn->crypto.tls_native_handle = tls_native_handle; -} - -void ngtcp2_conn_get_connection_close_error_code( - ngtcp2_conn *conn, ngtcp2_connection_close_error_code *ccec) { - *ccec = conn->rx.ccec; -} - -void ngtcp2_conn_set_tls_error(ngtcp2_conn *conn, int liberr) { - conn->crypto.tls_error = liberr; -} - -int ngtcp2_conn_get_tls_error(ngtcp2_conn *conn) { - return conn->crypto.tls_error; -} - -int ngtcp2_conn_is_local_stream(ngtcp2_conn *conn, int64_t stream_id) { - return conn_local_stream(conn, stream_id); -} - -int ngtcp2_conn_is_server(ngtcp2_conn *conn) { return conn->server; } - -int ngtcp2_conn_after_retry(ngtcp2_conn *conn) { - return (conn->flags & NGTCP2_CONN_FLAG_RECV_RETRY) != 0; -} - -int ngtcp2_conn_set_stream_user_data(ngtcp2_conn *conn, int64_t stream_id, - void *stream_user_data) { - ngtcp2_strm *strm = ngtcp2_conn_find_stream(conn, stream_id); - - if (strm == NULL) { - return NGTCP2_ERR_STREAM_NOT_FOUND; - } - - strm->stream_user_data = stream_user_data; - - return 0; -} - -void ngtcp2_path_challenge_entry_init(ngtcp2_path_challenge_entry *pcent, - const uint8_t *data) { - memcpy(pcent->data, data, sizeof(pcent->data)); -} - -void ngtcp2_settings_default(ngtcp2_settings *settings) { - memset(settings, 0, sizeof(*settings)); - settings->cc_algo = NGTCP2_CC_ALGO_CUBIC; - settings->initial_rtt = NGTCP2_DEFAULT_INITIAL_RTT; - settings->transport_params.max_udp_payload_size = - NGTCP2_DEFAULT_MAX_UDP_PAYLOAD_SIZE; - settings->transport_params.ack_delay_exponent = - NGTCP2_DEFAULT_ACK_DELAY_EXPONENT; - settings->transport_params.max_ack_delay = NGTCP2_DEFAULT_MAX_ACK_DELAY; - settings->transport_params.active_connection_id_limit = - NGTCP2_DEFAULT_ACTIVE_CONNECTION_ID_LIMIT; -} - -/* The functions prefixed with ngtcp2_pkt_ are usually put inside - ngtcp2_pkt.c. This function uses encryption construct and uses - test data defined only in ngtcp2_conn_test.c, so it is written - here. */ -ngtcp2_ssize ngtcp2_pkt_write_connection_close( - uint8_t *dest, size_t destlen, const ngtcp2_cid *dcid, - const ngtcp2_cid *scid, uint64_t error_code, ngtcp2_encrypt encrypt, - const ngtcp2_crypto_aead *aead, const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *iv, ngtcp2_hp_mask hp_mask, const ngtcp2_crypto_cipher *hp, - const ngtcp2_crypto_cipher_ctx *hp_ctx) { - ngtcp2_pkt_hd hd; - ngtcp2_crypto_km ckm; - ngtcp2_crypto_cc cc; - ngtcp2_ppe ppe; - ngtcp2_frame fr = {0}; - int rv; - - ngtcp2_pkt_hd_init(&hd, NGTCP2_PKT_FLAG_LONG_FORM, NGTCP2_PKT_INITIAL, dcid, - scid, /* pkt_num = */ 0, /* pkt_numlen = */ 1, - NGTCP2_PROTO_VER, /* len = */ 0); - - ngtcp2_vec_init(&ckm.secret, NULL, 0); - ngtcp2_vec_init(&ckm.iv, iv, 12); - ckm.aead_ctx = *aead_ctx; - ckm.pkt_num = 0; - ckm.flags = NGTCP2_CRYPTO_KM_FLAG_NONE; - - cc.aead_overhead = NGTCP2_INITIAL_AEAD_OVERHEAD; - cc.aead = *aead; - cc.hp = *hp; - cc.ckm = &ckm; - cc.hp_ctx = *hp_ctx; - cc.encrypt = encrypt; - cc.hp_mask = hp_mask; - - ngtcp2_ppe_init(&ppe, dest, destlen, &cc); - - rv = ngtcp2_ppe_encode_hd(&ppe, &hd); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - return rv; - } - - if (!ngtcp2_ppe_ensure_hp_sample(&ppe)) { - return NGTCP2_ERR_NOBUF; - } - - fr.type = NGTCP2_FRAME_CONNECTION_CLOSE; - fr.connection_close.error_code = error_code; - - rv = ngtcp2_ppe_encode_frame(&ppe, &fr); - if (rv != 0) { - assert(NGTCP2_ERR_NOBUF == rv); - return rv; - } - - return ngtcp2_ppe_final(&ppe, NULL); -} - -int ngtcp2_is_bidi_stream(int64_t stream_id) { return bidi_stream(stream_id); } diff --git a/deps/ngtcp2/lib/ngtcp2_conn.h b/deps/ngtcp2/lib/ngtcp2_conn.h deleted file mode 100644 index d7782b1114a53d..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_conn.h +++ /dev/null @@ -1,698 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_CONN_H -#define NGTCP2_CONN_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_mem.h" -#include "ngtcp2_crypto.h" -#include "ngtcp2_acktr.h" -#include "ngtcp2_rtb.h" -#include "ngtcp2_strm.h" -#include "ngtcp2_mem.h" -#include "ngtcp2_idtr.h" -#include "ngtcp2_str.h" -#include "ngtcp2_pkt.h" -#include "ngtcp2_log.h" -#include "ngtcp2_pq.h" -#include "ngtcp2_cc.h" -#include "ngtcp2_pv.h" -#include "ngtcp2_cid.h" -#include "ngtcp2_buf.h" -#include "ngtcp2_ppe.h" -#include "ngtcp2_qlog.h" -#include "ngtcp2_rst.h" - -typedef enum { - /* Client specific handshake states */ - NGTCP2_CS_CLIENT_INITIAL, - NGTCP2_CS_CLIENT_WAIT_HANDSHAKE, - NGTCP2_CS_CLIENT_TLS_HANDSHAKE_FAILED, - /* Server specific handshake states */ - NGTCP2_CS_SERVER_INITIAL, - NGTCP2_CS_SERVER_WAIT_HANDSHAKE, - NGTCP2_CS_SERVER_TLS_HANDSHAKE_FAILED, - /* Shared by both client and server */ - NGTCP2_CS_POST_HANDSHAKE, - NGTCP2_CS_CLOSING, - NGTCP2_CS_DRAINING, -} ngtcp2_conn_state; - -/* NGTCP2_MAX_STREAMS is the maximum number of streams. */ -#define NGTCP2_MAX_STREAMS (1LL << 60) - -/* NGTCP2_MAX_NUM_BUFFED_RX_PKTS is the maximum number of buffered - reordered packets. */ -#define NGTCP2_MAX_NUM_BUFFED_RX_PKTS 4 - -/* NGTCP2_MAX_REORDERED_CRYPTO_DATA is the maximum offset of crypto - data which is not continuous. In other words, there is a gap of - unreceived data. */ -#define NGTCP2_MAX_REORDERED_CRYPTO_DATA 65536 - -/* NGTCP2_MAX_RX_INITIAL_CRYPTO_DATA is the maximum offset of received - crypto stream in Initial packet. We set this hard limit here - because crypto stream is unbounded. */ -#define NGTCP2_MAX_RX_INITIAL_CRYPTO_DATA 65536 -/* NGTCP2_MAX_RX_HANDSHAKE_CRYPTO_DATA is the maximum offset of - received crypto stream in Handshake packet. We set this hard limit - here because crypto stream is unbounded. */ -#define NGTCP2_MAX_RX_HANDSHAKE_CRYPTO_DATA 65536 - -/* NGTCP2_MAX_RETRIES is the number of Retry packet which client can - accept. */ -#define NGTCP2_MAX_RETRIES 3 - -/* NGTCP2_MAX_DCID_POOL_SIZE is the maximum number of destination - connection ID the remote endpoint provides to store. It must be - the power of 2. */ -#define NGTCP2_MAX_DCID_POOL_SIZE 8 -/* NGTCP2_MAX_DCID_RETIRED_SIZE is the maximum number of retired DCID - kept to catch in-flight packet on retired path. */ -#define NGTCP2_MAX_DCID_RETIRED_SIZE 2 -/* NGTCP2_MAX_SCID_POOL_SIZE is the maximum number of source - connection ID the local endpoint provides to the remote endpoint. - The chosen value was described in old draft. Now a remote endpoint - tells the maximum value. The value can be quite large, and we have - to put the sane limit.*/ -#define NGTCP2_MAX_SCID_POOL_SIZE 8 - -/* NGTCP2_MAX_NON_ACK_TX_PKT is the maximum number of continuous non - ACK-eliciting packets. */ -#define NGTCP2_MAX_NON_ACK_TX_PKT 3 - -/* - * ngtcp2_max_frame is defined so that it covers the largest ACK - * frame. - */ -typedef union { - ngtcp2_frame fr; - struct { - ngtcp2_ack ack; - /* ack includes 1 ngtcp2_ack_blk. */ - ngtcp2_ack_blk blks[NGTCP2_MAX_ACK_BLKS - 1]; - } ackfr; -} ngtcp2_max_frame; - -typedef struct { - uint8_t data[8]; -} ngtcp2_path_challenge_entry; - -void ngtcp2_path_challenge_entry_init(ngtcp2_path_challenge_entry *pcent, - const uint8_t *data); - -typedef enum { - NGTCP2_CONN_FLAG_NONE = 0x00, - /* NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED is set if handshake - completed. */ - NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED = 0x01, - /* NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED is set if connection ID is - negotiated. This is only used for client. */ - NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED = 0x02, - /* NGTCP2_CONN_FLAG_TRANSPORT_PARAM_RECVED is set if transport - parameters are received. */ - NGTCP2_CONN_FLAG_TRANSPORT_PARAM_RECVED = 0x04, - /* NGTCP2_CONN_FLAG_RECV_PROTECTED_PKT is set when a protected - packet is received, and decrypted successfully. This flag is - used to stop retransmitting handshake packets. It might be - replaced with an another mechanism when we implement key - update. */ - NGTCP2_CONN_FLAG_RECV_PROTECTED_PKT = 0x08, - /* NGTCP2_CONN_FLAG_RECV_RETRY is set when a client receives Retry - packet. */ - NGTCP2_CONN_FLAG_RECV_RETRY = 0x10, - /* NGTCP2_CONN_FLAG_EARLY_DATA_REJECTED is set when 0-RTT packet is - rejected by a peer. */ - NGTCP2_CONN_FLAG_EARLY_DATA_REJECTED = 0x20, - /* NGTCP2_CONN_FLAG_SADDR_VERIFIED is set when source address is - verified. */ - NGTCP2_CONN_FLAG_SADDR_VERIFIED = 0x40, - /* NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED is set when an endpoint - confirmed completion of handshake. */ - NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED = 0x80, - /* NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED is set when the - library transitions its state to "post handshake". */ - NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED = 0x0100, - /* NGTCP2_CONN_FLAG_KEY_UPDATE_NOT_CONFIRMED is set when key update - is not confirmed by the local endpoint. That is, it has not - received ACK frame which acknowledges packet which is encrypted - with new key. */ - NGTCP2_CONN_FLAG_KEY_UPDATE_NOT_CONFIRMED = 0x0800, - /* NGTCP2_CONN_FLAG_PPE_PENDING is set when - NGTCP2_WRITE_STREAM_FLAG_MORE is used and the intermediate state - of ngtcp2_ppe is stored in pkt struct of ngtcp2_conn. */ - NGTCP2_CONN_FLAG_PPE_PENDING = 0x1000, - /* NGTCP2_CONN_FLAG_RESTART_IDLE_TIMER_ON_WRITE is set when idle - timer should be restarted on next write. */ - NGTCP2_CONN_FLAG_RESTART_IDLE_TIMER_ON_WRITE = 0x2000, - /* NGTCP2_CONN_FLAG_SERVER_ADDR_VERIFIED indicates that server as - peer verified client address. This flag is only used by - client. */ - NGTCP2_CONN_FLAG_SERVER_ADDR_VERIFIED = 0x4000, -} ngtcp2_conn_flag; - -typedef struct { - ngtcp2_buf buf; - /* pkt_type is the type of packet to send data in buf. If it is 0, - it must be sent in Short packet. Otherwise, it is sent the long - packet type denoted by pkt_type. */ - uint8_t pkt_type; -} ngtcp2_crypto_data; - -typedef struct ngtcp2_pktns { - struct { - /* last_pkt_num is the packet number which the local endpoint sent - last time.*/ - int64_t last_pkt_num; - ngtcp2_frame_chain *frq; - /* num_non_ack_pkt is the number of continuous non ACK-eliciting - packets. */ - size_t num_non_ack_pkt; - } tx; - - struct { - /* pngap tracks received packet number in order to suppress - duplicated packet number. */ - ngtcp2_gaptr pngap; - /* max_pkt_num is the largest packet number received so far. */ - int64_t max_pkt_num; - /* max_pkt_ts is the timestamp when max_pkt_num packet is - received. */ - ngtcp2_tstamp max_pkt_ts; - /* - * buffed_pkts is buffered packets which cannot be decrypted with - * the current encryption level. - * - * In server Initial encryption level, 0-RTT packet may be buffered. - * In server Handshake encryption level, Short packet may be buffered. - * - * In client Initial encryption level, Handshake or Short packet may - * be buffered. In client Handshake encryption level, Short packet - * may be buffered. - * - * - 0-RTT packet is only buffered in server Initial encryption - * level ngtcp2_pktns. - * - * - Handshake packet is only buffered in client Handshake - * encryption level ngtcp2_pktns. - * - * - Short packet is only buffered in Short encryption level - * ngtcp2_pktns. - */ - ngtcp2_pkt_chain *buffed_pkts; - } rx; - - struct { - struct { - /* frq contains crypto data sorted by their offset. */ - ngtcp2_ksl frq; - /* offset is the offset of crypto stream in this packet number - space. */ - uint64_t offset; - /* ckm is a cryptographic key, and iv to encrypt outgoing - packets. */ - ngtcp2_crypto_km *ckm; - /* hp_ctx is cipher context for packet header protection. */ - ngtcp2_crypto_cipher_ctx hp_ctx; - } tx; - - struct { - /* ckm is a cryptographic key, and iv to decrypt incoming - packets. */ - ngtcp2_crypto_km *ckm; - /* hp_ctx is cipher context for packet header protection. */ - ngtcp2_crypto_cipher_ctx hp_ctx; - } rx; - - ngtcp2_strm strm; - ngtcp2_crypto_ctx ctx; - } crypto; - - ngtcp2_acktr acktr; - ngtcp2_rtb rtb; -} ngtcp2_pktns; - -struct ngtcp2_conn { - ngtcp2_conn_state state; - ngtcp2_conn_callbacks callbacks; - /* rcid is a connection ID present in Initial or 0-RTT packet from - client as destination connection ID. Server uses this field to - check that duplicated Initial or 0-RTT packet are indeed sent to - this connection. It is also sent to client as - original_destination_connection_id transport parameter. Client - uses this field to validate original_destination_connection_id - transport parameter if no Retry packet is involved. */ - ngtcp2_cid rcid; - /* oscid is the source connection ID initially used by the local - endpoint. */ - ngtcp2_cid oscid; - /* retry_scid is the source connection ID from Retry packet. Client - records it in order to verify retry_source_connection_id - transport parameter. Server does not use this field. */ - ngtcp2_cid retry_scid; - ngtcp2_pktns *in_pktns; - ngtcp2_pktns *hs_pktns; - ngtcp2_pktns pktns; - - struct { - /* current is the current destination connection ID. */ - ngtcp2_dcid current; - /* unused is a set of unused CID received from peer. */ - ngtcp2_ringbuf unused; - /* retired is a set of CID retired by local endpoint. Keep them - in 3*PTO to catch packets in flight along the old path. */ - ngtcp2_ringbuf retired; - /* seqgap tracks received sequence numbers in order to ignore - retransmitted duplicated NEW_CONNECTION_ID frame. */ - ngtcp2_gaptr seqgap; - /* retire_prior_to is the largest retire_prior_to received so - far. */ - uint64_t retire_prior_to; - /* num_retire_queued is the number of RETIRE_CONNECTION_ID frames - queued for transmission. */ - size_t num_retire_queued; - } dcid; - - struct { - /* set is a set of CID sent to peer. The peer can use any CIDs in - this set. This includes used CID as well as unused ones. */ - ngtcp2_ksl set; - /* used is a set of CID used by peer. The sort function of this - priority queue takes timestamp when CID is retired and sorts - them in ascending order. */ - ngtcp2_pq used; - /* last_seq is the last sequence number of connection ID. */ - uint64_t last_seq; - /* num_retired is the number of retired Connection ID still - included in set. */ - size_t num_retired; - } scid; - - struct { - /* strmq contains ngtcp2_strm which has frames to send. */ - ngtcp2_pq strmq; - /* ack is ACK frame. The underlying buffer is resused. */ - ngtcp2_frame *ack; - /* max_ack_blks is the number of additional ngtcp2_ack_blk which - ack can contain. */ - size_t max_ack_blks; - /* offset is the offset the local endpoint has sent to the remote - endpoint. */ - uint64_t offset; - /* max_offset is the maximum offset that local endpoint can - send. */ - uint64_t max_offset; - } tx; - - struct { - /* unsent_max_offset is the maximum offset that remote endpoint - can send without extending MAX_DATA. This limit is not yet - notified to the remote endpoint. */ - uint64_t unsent_max_offset; - /* offset is the cumulative sum of stream data received for this - connection. */ - uint64_t offset; - /* max_offset is the maximum offset that remote endpoint can - send. */ - uint64_t max_offset; - /* path_challenge stores received PATH_CHALLENGE data. */ - ngtcp2_ringbuf path_challenge; - /* ccec is the received connection close error code. */ - ngtcp2_connection_close_error_code ccec; - struct { - /* start_ts is the time instant when receiving rate measurement - is started. */ - ngtcp2_tstamp start_ts; - /* received is the number of bytes received in the current - measurement period. */ - uint64_t received; - } rate; - } rx; - - struct { - ngtcp2_crypto_km *ckm; - ngtcp2_crypto_cipher_ctx hp_ctx; - } early; - - struct { - ngtcp2_settings settings; - struct { - /* max_streams is the maximum number of bidirectional streams which - the local endpoint can open. */ - uint64_t max_streams; - /* next_stream_id is the bidirectional stream ID which the local - endpoint opens next. */ - int64_t next_stream_id; - } bidi; - - struct { - /* max_streams is the maximum number of unidirectional streams - which the local endpoint can open. */ - uint64_t max_streams; - /* next_stream_id is the unidirectional stream ID which the - local endpoint opens next. */ - int64_t next_stream_id; - } uni; - } local; - - struct { - /* transport_params is the received transport parameters during - handshake. It is used for Short packet only. */ - ngtcp2_transport_params transport_params; - /* pending_transport_params is received transport parameters - during handshake. It is copied to transport_params when 1RTT - key is available. */ - ngtcp2_transport_params pending_transport_params; - struct { - ngtcp2_idtr idtr; - /* unsent_max_streams is the maximum number of streams of peer - initiated bidirectional stream which the local endpoint can - accept. This limit is not yet notified to the remote - endpoint. */ - uint64_t unsent_max_streams; - /* max_streams is the maximum number of streams of peer - initiated bidirectional stream which the local endpoint can - accept. */ - uint64_t max_streams; - } bidi; - - struct { - ngtcp2_idtr idtr; - /* unsent_max_streams is the maximum number of streams of peer - initiated unidirectional stream which the local endpoint can - accept. This limit is not yet notified to the remote - endpoint. */ - uint64_t unsent_max_streams; - /* max_streams is the maximum number of streams of peer - initiated unidirectional stream which the local endpoint can - accept. */ - uint64_t max_streams; - } uni; - } remote; - - struct { - struct { - /* new_tx_ckm is a new sender 1RTT key which has not been - used. */ - ngtcp2_crypto_km *new_tx_ckm; - /* new_rx_ckm is a new receiver 1RTT key which has not - successfully decrypted incoming packet yet. */ - ngtcp2_crypto_km *new_rx_ckm; - /* old_rx_ckm is an old receiver 1RTT key. */ - ngtcp2_crypto_km *old_rx_ckm; - /* confirmed_ts is the time instant when the key update is - confirmed by the local endpoint last time. UINT64_MAX means - undefined value. */ - ngtcp2_tstamp confirmed_ts; - } key_update; - - /* tls_native_handle is a native handle to TLS session object. */ - void *tls_native_handle; - size_t aead_overhead; - /* decrypt_buf is a buffer which is used to write decrypted data. */ - ngtcp2_vec decrypt_buf; - /* retry_aead is AEAD to verify Retry packet integrity. It is - used by client only. */ - ngtcp2_crypto_aead retry_aead; - /* retry_aead_ctx is AEAD cipher context to verify Retry packet - integrity. It is used by client only. */ - ngtcp2_crypto_aead_ctx retry_aead_ctx; - /* tls_error is TLS related error. */ - int tls_error; - } crypto; - - /* pkt contains the packet intermediate construction data to support - NGTCP2_WRITE_STREAM_FLAG_MORE */ - struct { - ngtcp2_crypto_cc cc; - ngtcp2_pkt_hd hd; - ngtcp2_ppe ppe; - ngtcp2_frame_chain **pfrc; - int pkt_empty; - int hd_logged; - uint8_t rtb_entry_flags; - int was_client_initial; - ngtcp2_ssize hs_spktlen; - } pkt; - - ngtcp2_map strms; - ngtcp2_conn_stat cstat; - ngtcp2_pv *pv; - ngtcp2_log log; - ngtcp2_qlog qlog; - ngtcp2_rst rst; - ngtcp2_cc_algo cc_algo; - ngtcp2_cc cc; - const ngtcp2_mem *mem; - /* idle_ts is the time instant when idle timer started. */ - ngtcp2_tstamp idle_ts; - void *user_data; - uint32_t version; - /* flags is bitwise OR of zero or more of ngtcp2_conn_flag. */ - uint16_t flags; - int server; -}; - -typedef enum ngtcp2_vmsg_type { - NGTCP2_VMSG_TYPE_STREAM, -} ngtcp2_vmsg_type; - -typedef struct ngtcp2_vmsg_stream { - /* strm is a stream that data is sent to. */ - ngtcp2_strm *strm; - /* flags is bitwise OR of zero or more of - ngtcp2_write_stream_flag. */ - uint32_t flags; - /* data is the pointer to ngtcp2_vec array which contains the stream - data to send. */ - const ngtcp2_vec *data; - /* datacnt is the number of ngtcp2_vec pointed by data. */ - size_t datacnt; - /* *pdatalen is the pointer to the variable which the number of - bytes written is assigned to if pdatalen is not NULL. */ - ngtcp2_ssize *pdatalen; -} ngtcp2_vmsg_stream; - -typedef struct ngtcp2_vmsg { - ngtcp2_vmsg_type type; - union { - ngtcp2_vmsg_stream stream; - }; -} ngtcp2_vmsg; - -/* - * ngtcp2_conn_sched_ack stores packet number |pkt_num| and its - * reception timestamp |ts| in order to send its ACK. - * - * It returns 0 if it succeeds, or one of the following negative error - * codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - * NGTCP2_ERR_PROTO - * Same packet number has already been added. - */ -int ngtcp2_conn_sched_ack(ngtcp2_conn *conn, ngtcp2_acktr *acktr, - int64_t pkt_num, int active_ack, ngtcp2_tstamp ts); - -/* - * ngtcp2_conn_find_stream returns a stream whose stream ID is - * |stream_id|. If no such stream is found, it returns NULL. - */ -ngtcp2_strm *ngtcp2_conn_find_stream(ngtcp2_conn *conn, int64_t stream_id); - -/* - * conn_init_stream initializes |strm|. Its stream ID is |stream_id|. - * This function adds |strm| to conn->strms. |strm| must be allocated - * by the caller. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - * NGTCP2_ERR_CALLBACK_FAILURE - * User-callback function failed. - */ -int ngtcp2_conn_init_stream(ngtcp2_conn *conn, ngtcp2_strm *strm, - int64_t stream_id, void *stream_user_data); - -/* - * ngtcp2_conn_close_stream closes stream |strm|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_INVALID_ARGUMENT - * Stream is not found. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -int ngtcp2_conn_close_stream(ngtcp2_conn *conn, ngtcp2_strm *strm, - uint64_t app_error_code); - -/* - * ngtcp2_conn_close_stream closes stream |strm| if no further - * transmission and reception are allowed, and all reordered incoming - * data are emitted to the application, and the transmitted data are - * acked. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_INVALID_ARGUMENT - * Stream is not found. - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -int ngtcp2_conn_close_stream_if_shut_rdwr(ngtcp2_conn *conn, ngtcp2_strm *strm, - uint64_t app_error_code); - -/* - * ngtcp2_conn_update_rtt updates RTT measurements. |rtt| is a latest - * RTT which is not adjusted by ack delay. |ack_delay| is unscaled - * ack_delay included in ACK frame. |ack_delay| is actually tainted - * (sent by peer), so don't assume that |ack_delay| is always smaller - * than, or equals to |rtt|. - */ -void ngtcp2_conn_update_rtt(ngtcp2_conn *conn, ngtcp2_duration rtt, - ngtcp2_duration ack_delay); - -void ngtcp2_conn_set_loss_detection_timer(ngtcp2_conn *conn, ngtcp2_tstamp ts); - -/* - * ngtcp2_conn_detect_lost_pkt detects lost packets. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_conn_detect_lost_pkt(ngtcp2_conn *conn, ngtcp2_pktns *pktns, - ngtcp2_conn_stat *cstat, ngtcp2_tstamp ts); - -/* - * ngtcp2_conn_tx_strmq_top returns the ngtcp2_strm which sits on the - * top of queue. tx_strmq must not be empty. - */ -ngtcp2_strm *ngtcp2_conn_tx_strmq_top(ngtcp2_conn *conn); - -/* - * ngtcp2_conn_tx_strmq_pop pops the ngtcp2_strm from the queue. - * tx_strmq must not be empty. - */ -void ngtcp2_conn_tx_strmq_pop(ngtcp2_conn *conn); - -/* - * ngtcp2_conn_tx_strmq_push pushes |strm| into tx_strmq. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_conn_tx_strmq_push(ngtcp2_conn *conn, ngtcp2_strm *strm); - -/* - * ngtcp2_conn_internal_expiry returns the minimum expiry time among - * all timers in |conn|. - */ -ngtcp2_tstamp ngtcp2_conn_internal_expiry(ngtcp2_conn *conn); - -ngtcp2_ssize ngtcp2_conn_write_vmsg(ngtcp2_conn *conn, ngtcp2_path *path, - uint8_t *dest, size_t destlen, - ngtcp2_vmsg *vmsg, ngtcp2_tstamp ts); - -/* - * ngtcp2_conn_write_single_frame_pkt writes a packet which contains |fr| - * frame only in the buffer pointed by |dest| whose length if - * |destlen|. |type| is a long packet type to send. If |type| is 0, - * Short packet is used. |dcid| is used as a destination connection - * ID. - * - * The packet written by this function will not be retransmitted. - * - * This function returns the number of bytes written in |dest| if it - * succeeds, or one of the following negative error codes: - * - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -ngtcp2_ssize -ngtcp2_conn_write_single_frame_pkt(ngtcp2_conn *conn, uint8_t *dest, - size_t destlen, uint8_t type, - const ngtcp2_cid *dcid, ngtcp2_frame *fr, - uint8_t rtb_flags, ngtcp2_tstamp ts); - -/* - * ngtcp2_conn_commit_local_transport_params commits the local - * transport parameters, which is currently set to - * conn->local.settings.transport_params. This function will do some - * amends on transport parameters for adjusting default values. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_INVALID_ARGUMENT - * CID in preferred address equals to the original SCID. - */ -int ngtcp2_conn_commit_local_transport_params(ngtcp2_conn *conn); - -/* - * ngtcp2_conn_lost_pkt_expiry returns the earliest expiry time of - * lost packet. - */ -ngtcp2_tstamp ngtcp2_conn_lost_pkt_expiry(ngtcp2_conn *conn); - -/* - * ngtcp2_conn_remove_lost_pkt removes the expired lost packet. - */ -void ngtcp2_conn_remove_lost_pkt(ngtcp2_conn *conn, ngtcp2_tstamp ts); - -/* - * ngtcp2_conn_resched_frames reschedules frames linked from |*pfrc| - * for retransmission. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_conn_resched_frames(ngtcp2_conn *conn, ngtcp2_pktns *pktns, - ngtcp2_frame_chain **pfrc); - -uint64_t ngtcp2_conn_tx_strmq_first_cycle(ngtcp2_conn *conn); - -#endif /* NGTCP2_CONN_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_conv.c b/deps/ngtcp2/lib/ngtcp2_conv.c deleted file mode 100644 index 18cf314791384d..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_conv.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_conv.h" - -#include -#include - -#include "ngtcp2_str.h" -#include "ngtcp2_pkt.h" - -uint64_t ngtcp2_get_uint64(const uint8_t *p) { - uint64_t n; - memcpy(&n, p, 8); - return ngtcp2_ntohl64(n); -} - -uint64_t ngtcp2_get_uint48(const uint8_t *p) { - uint64_t n = 0; - memcpy(((uint8_t *)&n) + 2, p, 6); - return ngtcp2_ntohl64(n); -} - -uint32_t ngtcp2_get_uint32(const uint8_t *p) { - uint32_t n; - memcpy(&n, p, 4); - return ngtcp2_ntohl(n); -} - -uint32_t ngtcp2_get_uint24(const uint8_t *p) { - uint32_t n = 0; - memcpy(((uint8_t *)&n) + 1, p, 3); - return ngtcp2_ntohl(n); -} - -uint16_t ngtcp2_get_uint16(const uint8_t *p) { - uint16_t n; - memcpy(&n, p, 2); - return ngtcp2_ntohs(n); -} - -uint64_t ngtcp2_get_varint(size_t *plen, const uint8_t *p) { - union { - char b[8]; - uint16_t n16; - uint32_t n32; - uint64_t n64; - } n; - - *plen = 1u << (*p >> 6); - - switch (*plen) { - case 1: - return *p; - case 2: - memcpy(&n, p, 2); - n.b[0] &= 0x3f; - return ngtcp2_ntohs(n.n16); - case 4: - memcpy(&n, p, 4); - n.b[0] &= 0x3f; - return ngtcp2_ntohl(n.n32); - case 8: - memcpy(&n, p, 8); - n.b[0] &= 0x3f; - return ngtcp2_ntohl64(n.n64); - } - - assert(0); -} - -int64_t ngtcp2_get_pkt_num(const uint8_t *p, size_t pkt_numlen) { - switch (pkt_numlen) { - case 1: - return *p; - case 2: - return (int64_t)ngtcp2_get_uint16(p); - case 3: - return (int64_t)ngtcp2_get_uint24(p); - case 4: - return (int64_t)ngtcp2_get_uint32(p); - default: - assert(0); - } -} - -uint8_t *ngtcp2_put_uint64be(uint8_t *p, uint64_t n) { - n = ngtcp2_htonl64(n); - return ngtcp2_cpymem(p, (const uint8_t *)&n, sizeof(n)); -} - -uint8_t *ngtcp2_put_uint48be(uint8_t *p, uint64_t n) { - n = ngtcp2_htonl64(n); - return ngtcp2_cpymem(p, ((const uint8_t *)&n) + 2, 6); -} - -uint8_t *ngtcp2_put_uint32be(uint8_t *p, uint32_t n) { - n = ngtcp2_htonl(n); - return ngtcp2_cpymem(p, (const uint8_t *)&n, sizeof(n)); -} - -uint8_t *ngtcp2_put_uint24be(uint8_t *p, uint32_t n) { - n = ngtcp2_htonl(n); - return ngtcp2_cpymem(p, ((const uint8_t *)&n) + 1, 3); -} - -uint8_t *ngtcp2_put_uint16be(uint8_t *p, uint16_t n) { - n = ngtcp2_htons(n); - return ngtcp2_cpymem(p, (const uint8_t *)&n, sizeof(n)); -} - -uint8_t *ngtcp2_put_varint(uint8_t *p, uint64_t n) { - uint8_t *rv; - if (n < 64) { - *p++ = (uint8_t)n; - return p; - } - if (n < 16384) { - rv = ngtcp2_put_uint16be(p, (uint16_t)n); - *p |= 0x40; - return rv; - } - if (n < 1073741824) { - rv = ngtcp2_put_uint32be(p, (uint32_t)n); - *p |= 0x80; - return rv; - } - assert(n < 4611686018427387904ULL); - rv = ngtcp2_put_uint64be(p, n); - *p |= 0xc0; - return rv; -} - -uint8_t *ngtcp2_put_varint14(uint8_t *p, uint16_t n) { - uint8_t *rv; - - assert(n < 16384); - - rv = ngtcp2_put_uint16be(p, n); - *p |= 0x40; - - return rv; -} - -uint8_t *ngtcp2_put_pkt_num(uint8_t *p, int64_t pkt_num, size_t len) { - switch (len) { - case 1: - *p++ = (uint8_t)pkt_num; - return p; - case 2: - ngtcp2_put_uint16be(p, (uint16_t)pkt_num); - return p + 2; - case 3: - ngtcp2_put_uint24be(p, (uint32_t)pkt_num); - return p + 3; - case 4: - ngtcp2_put_uint32be(p, (uint32_t)pkt_num); - return p + 4; - default: - assert(0); - } -} - -size_t ngtcp2_get_varint_len(const uint8_t *p) { return 1u << (*p >> 6); } - -size_t ngtcp2_put_varint_len(uint64_t n) { - if (n < 64) { - return 1; - } - if (n < 16384) { - return 2; - } - if (n < 1073741824) { - return 4; - } - assert(n < 4611686018427387904ULL); - return 8; -} - -int64_t ngtcp2_nth_server_bidi_id(uint64_t n) { - if (n == 0) { - return 0; - } - - if ((NGTCP2_MAX_VARINT >> 2) < n - 1) { - return NGTCP2_MAX_SERVER_STREAM_ID_BIDI; - } - - return (int64_t)(((n - 1) << 2) | 0x01); -} - -int64_t ngtcp2_nth_client_bidi_id(uint64_t n) { - if (n == 0) { - return 0; - } - - if ((NGTCP2_MAX_VARINT >> 2) < n - 1) { - return NGTCP2_MAX_CLIENT_STREAM_ID_BIDI; - } - - return (int64_t)((n - 1) << 2); -} - -int64_t ngtcp2_nth_server_uni_id(uint64_t n) { - if (n == 0) { - return 0; - } - - if ((NGTCP2_MAX_VARINT >> 2) < n - 1) { - return NGTCP2_MAX_SERVER_STREAM_ID_UNI; - } - - return (int64_t)(((n - 1) << 2) | 0x03); -} - -int64_t ngtcp2_nth_client_uni_id(uint64_t n) { - if (n == 0) { - return 0; - } - - if ((NGTCP2_MAX_VARINT >> 2) < n - 1) { - return NGTCP2_MAX_CLIENT_STREAM_ID_UNI; - } - - return (int64_t)(((n - 1) << 2) | 0x02); -} - -uint64_t ngtcp2_ord_stream_id(int64_t stream_id) { - return (uint64_t)(stream_id >> 2) + 1; -} diff --git a/deps/ngtcp2/lib/ngtcp2_conv.h b/deps/ngtcp2/lib/ngtcp2_conv.h deleted file mode 100644 index 227470b91927b8..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_conv.h +++ /dev/null @@ -1,282 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_CONV_H -#define NGTCP2_CONV_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#ifdef HAVE_ARPA_INET_H -# include -#endif /* HAVE_ARPA_INET_H */ - -#ifdef HAVE_NETINET_IN_H -# include -#endif /* HAVE_NETINET_IN_H */ - -#ifdef HAVE_BYTESWAP_H -# include -#endif /* HAVE_BYTESWAP_H */ - -#ifdef HAVE_ENDIAN_H -# include -#endif /* HAVE_ENDIAN_H */ - -#ifdef HAVE_SYS_ENDIAN_H -# include -#endif /* HAVE_SYS_ENDIAN_H */ - -#include - -#if defined HAVE_BSWAP_64 || HAVE_DECL_BSWAP_64 -# define ngtcp2_bswap64 bswap_64 -#else /* !HAVE_BSWAP_64 */ -# define ngtcp2_bswap64(N) \ - ((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32))) -#endif /* !HAVE_BSWAP_64 */ - -#if defined HAVE_BE64TOH || HAVE_DECL_BE64TOH -# define ngtcp2_ntohl64(N) be64toh(N) -# define ngtcp2_htonl64(N) htobe64(N) -#else /* !HAVE_BE64TOH */ -# if defined WORDS_BIGENDIAN -# define ngtcp2_ntohl64(N) (N) -# define ngtcp2_htonl64(N) (N) -# else /* !WORDS_BIGENDIAN */ -# define ngtcp2_ntohl64(N) ngtcp2_bswap64(N) -# define ngtcp2_htonl64(N) ngtcp2_bswap64(N) -# endif /* !WORDS_BIGENDIAN */ -#endif /* !HAVE_BE64TOH */ - -#if defined(WIN32) -/* Windows requires ws2_32 library for ntonl family functions. We - define inline functions for those function so that we don't have - dependeny on that lib. */ - -# ifdef _MSC_VER -# define STIN static __inline -# else -# define STIN static inline -# endif - -STIN uint32_t ngtcp2_htonl(uint32_t hostlong) { - uint32_t res; - unsigned char *p = (unsigned char *)&res; - *p++ = hostlong >> 24; - *p++ = (hostlong >> 16) & 0xffu; - *p++ = (hostlong >> 8) & 0xffu; - *p = hostlong & 0xffu; - return res; -} - -STIN uint16_t ngtcp2_htons(uint16_t hostshort) { - uint16_t res; - unsigned char *p = (unsigned char *)&res; - *p++ = hostshort >> 8; - *p = hostshort & 0xffu; - return res; -} - -STIN uint32_t ngtcp2_ntohl(uint32_t netlong) { - uint32_t res; - unsigned char *p = (unsigned char *)&netlong; - res = *p++ << 24; - res += *p++ << 16; - res += *p++ << 8; - res += *p; - return res; -} - -STIN uint16_t ngtcp2_ntohs(uint16_t netshort) { - uint16_t res; - unsigned char *p = (unsigned char *)&netshort; - res = *p++ << 8; - res += *p; - return res; -} - -#else /* !WIN32 */ - -# define ngtcp2_htonl htonl -# define ngtcp2_htons htons -# define ngtcp2_ntohl ntohl -# define ngtcp2_ntohs ntohs - -#endif /* !WIN32 */ - -/* - * ngtcp2_get_uint64 reads 8 bytes from |p| as 64 bits unsigned - * integer encoded as network byte order, and returns it in host byte - * order. - */ -uint64_t ngtcp2_get_uint64(const uint8_t *p); - -/* - * ngtcp2_get_uint48 reads 6 bytes from |p| as 48 bits unsigned - * integer encoded as network byte order, and returns it in host byte - * order. - */ -uint64_t ngtcp2_get_uint48(const uint8_t *p); - -/* - * ngtcp2_get_uint32 reads 4 bytes from |p| as 32 bits unsigned - * integer encoded as network byte order, and returns it in host byte - * order. - */ -uint32_t ngtcp2_get_uint32(const uint8_t *p); - -/* - * ngtcp2_get_uint24 reads 3 bytes from |p| as 24 bits unsigned - * integer encoded as network byte order, and returns it in host byte - * order. - */ -uint32_t ngtcp2_get_uint24(const uint8_t *p); - -/* - * ngtcp2_get_uint16 reads 2 bytes from |p| as 16 bits unsigned - * integer encoded as network byte order, and returns it in host byte - * order. - */ -uint16_t ngtcp2_get_uint16(const uint8_t *p); - -/* - * ngtcp2_get_varint reads variable-length integer from |p|, and - * returns it in host byte order. The number of bytes read is stored - * in |*plen|. - */ -uint64_t ngtcp2_get_varint(size_t *plen, const uint8_t *p); - -/* - * ngtcp2_get_pkt_num reads encoded packet number from |p|. The - * packet number is encoed in |pkt_numlen| bytes. - */ -int64_t ngtcp2_get_pkt_num(const uint8_t *p, size_t pkt_numlen); - -/* - * ngtcp2_put_uint64be writes |n| in host byte order in |p| in network - * byte order. It returns the one beyond of the last written - * position. - */ -uint8_t *ngtcp2_put_uint64be(uint8_t *p, uint64_t n); - -/* - * ngtcp2_put_uint48be writes |n| in host byte order in |p| in network - * byte order. It writes only least significant 48 bits. It returns - * the one beyond of the last written position. - */ -uint8_t *ngtcp2_put_uint48be(uint8_t *p, uint64_t n); - -/* - * ngtcp2_put_uint32be writes |n| in host byte order in |p| in network - * byte order. It returns the one beyond of the last written - * position. - */ -uint8_t *ngtcp2_put_uint32be(uint8_t *p, uint32_t n); - -/* - * ngtcp2_put_uint24be writes |n| in host byte order in |p| in network - * byte order. It writes only least significant 24 bits. It returns - * the one beyond of the last written position. - */ -uint8_t *ngtcp2_put_uint24be(uint8_t *p, uint32_t n); - -/* - * ngtcp2_put_uint16be writes |n| in host byte order in |p| in network - * byte order. It returns the one beyond of the last written - * position. - */ -uint8_t *ngtcp2_put_uint16be(uint8_t *p, uint16_t n); - -/* - * ngtcp2_put_varint writes |n| in |p| using variable-length integer - * encoding. It returns the one beyond of the last written position. - */ -uint8_t *ngtcp2_put_varint(uint8_t *p, uint64_t n); - -/* - * ngtcp2_put_varint14 writes |n| in |p| using variable-length integer - * encoding. |n| must be strictly less than 16384. The function - * always encodes |n| in 2 bytes. It returns the one beyond of the - * last written position. - */ -uint8_t *ngtcp2_put_varint14(uint8_t *p, uint16_t n); - -/* - * ngtcp2_put_pkt_num encodes |pkt_num| using |len| bytes. It - * returns the one beyond of the last written position. - */ -uint8_t *ngtcp2_put_pkt_num(uint8_t *p, int64_t pkt_num, size_t len); - -/* - * ngtcp2_get_varint_len returns the required number of bytes to read - * variable-length integer starting at |p|. - */ -size_t ngtcp2_get_varint_len(const uint8_t *p); - -/* - * ngtcp2_put_varint_len returns the required number of bytes to - * encode |n|. - */ -size_t ngtcp2_put_varint_len(uint64_t n); - -/* - * ngtcp2_nth_server_bidi_id returns |n|-th server bidirectional - * stream ID. If |n| is 0, it returns 0. If the |n|-th stream ID is - * larger than NGTCP2_MAX_SERVER_STREAM_ID_BIDI, this function returns - * NGTCP2_MAX_SERVER_STREAM_ID_BIDI. - */ -int64_t ngtcp2_nth_server_bidi_id(uint64_t n); - -/* - * ngtcp2_nth_client_bidi_id returns |n|-th client bidirectional - * stream ID. If |n| is 0, it returns 0. If the |n|-th stream ID is - * larger than NGTCP2_MAX_CLIENT_STREAM_ID_BIDI, this function returns - * NGTCP2_MAX_CLIENT_STREAM_ID_BIDI. - */ -int64_t ngtcp2_nth_client_bidi_id(uint64_t n); - -/* - * ngtcp2_nth_server_uni_id returns |n|-th server unidirectional - * stream ID. If |n| is 0, it returns 0. If the |n|-th stream ID is - * larger than NGTCP2_MAX_SERVER_STREAM_ID_UNI, this function returns - * NGTCP2_MAX_SERVER_STREAM_ID_UNI. - */ -int64_t ngtcp2_nth_server_uni_id(uint64_t n); - -/* - * ngtcp2_nth_client_uni_id returns |n|-th client unidirectional - * stream ID. If |n| is 0, it returns 0. If the |n|-th stream ID is - * larger than NGTCP2_MAX_CLIENT_STREAM_ID_UNI, this function returns - * NGTCP2_MAX_CLIENT_STREAM_ID_UNI. - */ -int64_t ngtcp2_nth_client_uni_id(uint64_t n); - -/* - * ngtcp2_ord_stream_id returns the ordinal number of |stream_id|. - */ -uint64_t ngtcp2_ord_stream_id(int64_t stream_id); - -#endif /* NGTCP2_CONV_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_crypto.c b/deps/ngtcp2/lib/ngtcp2_crypto.c deleted file mode 100644 index 5cfe145ec9b6a8..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_crypto.c +++ /dev/null @@ -1,732 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_crypto.h" - -#include -#include - -#include "ngtcp2_str.h" -#include "ngtcp2_conv.h" -#include "ngtcp2_conn.h" - -int ngtcp2_crypto_km_new(ngtcp2_crypto_km **pckm, const uint8_t *secret, - size_t secretlen, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *iv, size_t ivlen, - const ngtcp2_mem *mem) { - int rv = ngtcp2_crypto_km_nocopy_new(pckm, secretlen, ivlen, mem); - if (rv != 0) { - return rv; - } - - if (secretlen) { - memcpy((*pckm)->secret.base, secret, secretlen); - } - if (aead_ctx) { - (*pckm)->aead_ctx = *aead_ctx; - } - memcpy((*pckm)->iv.base, iv, ivlen); - - return 0; -} - -int ngtcp2_crypto_km_nocopy_new(ngtcp2_crypto_km **pckm, size_t secretlen, - size_t ivlen, const ngtcp2_mem *mem) { - size_t len; - uint8_t *p; - - len = sizeof(ngtcp2_crypto_km) + secretlen + ivlen; - - *pckm = ngtcp2_mem_malloc(mem, len); - if (*pckm == NULL) { - return NGTCP2_ERR_NOMEM; - } - - p = (uint8_t *)(*pckm) + sizeof(ngtcp2_crypto_km); - (*pckm)->secret.base = p; - (*pckm)->secret.len = secretlen; - p += secretlen; - (*pckm)->iv.base = p; - (*pckm)->iv.len = ivlen; - (*pckm)->aead_ctx.native_handle = NULL; - (*pckm)->pkt_num = -1; - (*pckm)->use_count = 0; - (*pckm)->flags = NGTCP2_CRYPTO_KM_FLAG_NONE; - - return 0; -} - -void ngtcp2_crypto_km_del(ngtcp2_crypto_km *ckm, const ngtcp2_mem *mem) { - if (ckm == NULL) { - return; - } - - ngtcp2_mem_free(mem, ckm); -} - -void ngtcp2_crypto_create_nonce(uint8_t *dest, const uint8_t *iv, size_t ivlen, - int64_t pkt_num) { - size_t i; - uint64_t n; - - memcpy(dest, iv, ivlen); - n = ngtcp2_htonl64((uint64_t)pkt_num); - - for (i = 0; i < 8; ++i) { - dest[ivlen - 8 + i] ^= ((uint8_t *)&n)[i]; - } -} - -/* - * varint_paramlen returns the length of a single transport parameter - * which has variable integer in its parameter. - */ -static size_t varint_paramlen(ngtcp2_transport_param_id id, uint64_t param) { - size_t valuelen = ngtcp2_put_varint_len(param); - return ngtcp2_put_varint_len(id) + ngtcp2_put_varint_len(valuelen) + valuelen; -} - -/* - * write_varint_param writes parameter |id| of the given |value| in - * varint encoding. It returns p + the number of bytes written. - */ -static uint8_t *write_varint_param(uint8_t *p, ngtcp2_transport_param_id id, - uint64_t value) { - p = ngtcp2_put_varint(p, id); - p = ngtcp2_put_varint(p, ngtcp2_put_varint_len(value)); - return ngtcp2_put_varint(p, value); -} - -/* - * cid_paramlen returns the length of a single transport parameter - * which has |cid| as value. - */ -static size_t cid_paramlen(ngtcp2_transport_param_id id, - const ngtcp2_cid *cid) { - return ngtcp2_put_varint_len(id) + ngtcp2_put_varint_len(cid->datalen) + - cid->datalen; -} - -/* - * write_cid_param writes parameter |id| of the given |cid|. It - * returns p + the number of bytes written. - */ -static uint8_t *write_cid_param(uint8_t *p, ngtcp2_transport_param_id id, - const ngtcp2_cid *cid) { - assert(cid->datalen == 0 || cid->datalen >= NGTCP2_MIN_CIDLEN); - assert(cid->datalen <= NGTCP2_MAX_CIDLEN); - - p = ngtcp2_put_varint(p, id); - p = ngtcp2_put_varint(p, cid->datalen); - if (cid->datalen) { - p = ngtcp2_cpymem(p, cid->data, cid->datalen); - } - return p; -} - -ngtcp2_ssize -ngtcp2_encode_transport_params(uint8_t *dest, size_t destlen, - ngtcp2_transport_params_type exttype, - const ngtcp2_transport_params *params) { - uint8_t *p; - size_t len = 0; - /* For some reason, gcc 7.3.0 requires this initialization. */ - size_t preferred_addrlen = 0; - - switch (exttype) { - case NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO: - break; - case NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS: - len += - cid_paramlen(NGTCP2_TRANSPORT_PARAM_ORIGINAL_DESTINATION_CONNECTION_ID, - ¶ms->original_dcid); - - if (params->stateless_reset_token_present) { - len += - ngtcp2_put_varint_len(NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN) + - ngtcp2_put_varint_len(NGTCP2_STATELESS_RESET_TOKENLEN) + - NGTCP2_STATELESS_RESET_TOKENLEN; - } - if (params->preferred_address_present) { - assert(params->preferred_address.cid.datalen >= NGTCP2_MIN_CIDLEN); - assert(params->preferred_address.cid.datalen <= NGTCP2_MAX_CIDLEN); - preferred_addrlen = 4 /* ipv4Address */ + 2 /* ipv4Port */ + - 16 /* ipv6Address */ + 2 /* ipv6Port */ - + 1 + - params->preferred_address.cid.datalen /* CID */ + - NGTCP2_STATELESS_RESET_TOKENLEN; - len += ngtcp2_put_varint_len(NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS) + - ngtcp2_put_varint_len(preferred_addrlen) + preferred_addrlen; - } - if (params->retry_scid_present) { - len += cid_paramlen(NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID, - ¶ms->retry_scid); - } - break; - default: - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - len += cid_paramlen(NGTCP2_TRANSPORT_PARAM_INITIAL_SOURCE_CONNECTION_ID, - ¶ms->initial_scid); - - if (params->initial_max_stream_data_bidi_local) { - len += varint_paramlen( - NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL, - params->initial_max_stream_data_bidi_local); - } - if (params->initial_max_stream_data_bidi_remote) { - len += varint_paramlen( - NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE, - params->initial_max_stream_data_bidi_remote); - } - if (params->initial_max_stream_data_uni) { - len += varint_paramlen(NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_UNI, - params->initial_max_stream_data_uni); - } - if (params->initial_max_data) { - len += varint_paramlen(NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_DATA, - params->initial_max_data); - } - if (params->initial_max_streams_bidi) { - len += varint_paramlen(NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_BIDI, - params->initial_max_streams_bidi); - } - if (params->initial_max_streams_uni) { - len += varint_paramlen(NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_UNI, - params->initial_max_streams_uni); - } - if (params->max_udp_payload_size != NGTCP2_DEFAULT_MAX_UDP_PAYLOAD_SIZE) { - len += varint_paramlen(NGTCP2_TRANSPORT_PARAM_MAX_UDP_PAYLOAD_SIZE, - params->max_udp_payload_size); - } - if (params->ack_delay_exponent != NGTCP2_DEFAULT_ACK_DELAY_EXPONENT) { - len += varint_paramlen(NGTCP2_TRANSPORT_PARAM_ACK_DELAY_EXPONENT, - params->ack_delay_exponent); - } - if (params->disable_active_migration) { - len += - ngtcp2_put_varint_len(NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION) + - ngtcp2_put_varint_len(0); - } - if (params->max_ack_delay != NGTCP2_DEFAULT_MAX_ACK_DELAY) { - len += varint_paramlen(NGTCP2_TRANSPORT_PARAM_MAX_ACK_DELAY, - params->max_ack_delay / NGTCP2_MILLISECONDS); - } - if (params->max_idle_timeout) { - len += varint_paramlen(NGTCP2_TRANSPORT_PARAM_MAX_IDLE_TIMEOUT, - params->max_idle_timeout / NGTCP2_MILLISECONDS); - } - if (params->active_connection_id_limit && - params->active_connection_id_limit != - NGTCP2_DEFAULT_ACTIVE_CONNECTION_ID_LIMIT) { - len += varint_paramlen(NGTCP2_TRANSPORT_PARAM_ACTIVE_CONNECTION_ID_LIMIT, - params->active_connection_id_limit); - } - - if (destlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = dest; - - if (exttype == NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) { - p = write_cid_param( - p, NGTCP2_TRANSPORT_PARAM_ORIGINAL_DESTINATION_CONNECTION_ID, - ¶ms->original_dcid); - - if (params->stateless_reset_token_present) { - p = ngtcp2_put_varint(p, NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN); - p = ngtcp2_put_varint(p, sizeof(params->stateless_reset_token)); - p = ngtcp2_cpymem(p, params->stateless_reset_token, - sizeof(params->stateless_reset_token)); - } - if (params->preferred_address_present) { - p = ngtcp2_put_varint(p, NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS); - p = ngtcp2_put_varint(p, preferred_addrlen); - - p = ngtcp2_cpymem(p, params->preferred_address.ipv4_addr, - sizeof(params->preferred_address.ipv4_addr)); - p = ngtcp2_put_uint16be(p, params->preferred_address.ipv4_port); - - p = ngtcp2_cpymem(p, params->preferred_address.ipv6_addr, - sizeof(params->preferred_address.ipv6_addr)); - p = ngtcp2_put_uint16be(p, params->preferred_address.ipv6_port); - - *p++ = (uint8_t)params->preferred_address.cid.datalen; - if (params->preferred_address.cid.datalen) { - p = ngtcp2_cpymem(p, params->preferred_address.cid.data, - params->preferred_address.cid.datalen); - } - p = ngtcp2_cpymem( - p, params->preferred_address.stateless_reset_token, - sizeof(params->preferred_address.stateless_reset_token)); - } - if (params->retry_scid_present) { - p = write_cid_param(p, NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID, - ¶ms->retry_scid); - } - } - - p = write_cid_param(p, NGTCP2_TRANSPORT_PARAM_INITIAL_SOURCE_CONNECTION_ID, - ¶ms->initial_scid); - - if (params->initial_max_stream_data_bidi_local) { - p = write_varint_param( - p, NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL, - params->initial_max_stream_data_bidi_local); - } - - if (params->initial_max_stream_data_bidi_remote) { - p = write_varint_param( - p, NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE, - params->initial_max_stream_data_bidi_remote); - } - - if (params->initial_max_stream_data_uni) { - p = write_varint_param(p, - NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_UNI, - params->initial_max_stream_data_uni); - } - - if (params->initial_max_data) { - p = write_varint_param(p, NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_DATA, - params->initial_max_data); - } - - if (params->initial_max_streams_bidi) { - p = write_varint_param(p, NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_BIDI, - params->initial_max_streams_bidi); - } - - if (params->initial_max_streams_uni) { - p = write_varint_param(p, NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_UNI, - params->initial_max_streams_uni); - } - - if (params->max_udp_payload_size != NGTCP2_DEFAULT_MAX_UDP_PAYLOAD_SIZE) { - p = write_varint_param(p, NGTCP2_TRANSPORT_PARAM_MAX_UDP_PAYLOAD_SIZE, - params->max_udp_payload_size); - } - - if (params->ack_delay_exponent != NGTCP2_DEFAULT_ACK_DELAY_EXPONENT) { - p = write_varint_param(p, NGTCP2_TRANSPORT_PARAM_ACK_DELAY_EXPONENT, - params->ack_delay_exponent); - } - - if (params->disable_active_migration) { - p = ngtcp2_put_varint(p, NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION); - p = ngtcp2_put_varint(p, 0); - } - - if (params->max_ack_delay != NGTCP2_DEFAULT_MAX_ACK_DELAY) { - p = write_varint_param(p, NGTCP2_TRANSPORT_PARAM_MAX_ACK_DELAY, - params->max_ack_delay / NGTCP2_MILLISECONDS); - } - - if (params->max_idle_timeout) { - p = write_varint_param(p, NGTCP2_TRANSPORT_PARAM_MAX_IDLE_TIMEOUT, - params->max_idle_timeout / NGTCP2_MILLISECONDS); - } - - if (params->active_connection_id_limit && - params->active_connection_id_limit != - NGTCP2_DEFAULT_ACTIVE_CONNECTION_ID_LIMIT) { - p = write_varint_param(p, NGTCP2_TRANSPORT_PARAM_ACTIVE_CONNECTION_ID_LIMIT, - params->active_connection_id_limit); - } - - assert((size_t)(p - dest) == len); - - return (ngtcp2_ssize)len; -} - -/* - * decode_varint decodes a single varint from the buffer pointed by - * |p| of length |end - p|. If it decodes an integer successfully, it - * stores the integer in |*pdest| and returns 0. Otherwise it returns - * -1. - */ -static ngtcp2_ssize decode_varint(uint64_t *pdest, const uint8_t *p, - const uint8_t *end) { - size_t len; - - if (p == end) { - return -1; - } - - len = ngtcp2_get_varint_len(p); - if ((uint64_t)(end - p) < len) { - return -1; - } - - *pdest = ngtcp2_get_varint(&len, p); - - return (ngtcp2_ssize)len; -} - -/* - * decode_varint_param decodes length prefixed value from the buffer - * pointed by |p| of length |end - p|. The length and value are - * encoded in varint form. If it decodes a value successfully, it - * stores the value in |*pdest| and returns 0. Otherwise it returns - * -1. - */ -static ngtcp2_ssize decode_varint_param(uint64_t *pdest, const uint8_t *p, - const uint8_t *end) { - const uint8_t *begin = p; - ngtcp2_ssize nread; - uint64_t valuelen; - size_t n; - - nread = decode_varint(&valuelen, p, end); - if (nread < 0) { - return -1; - } - - p += nread; - - if (p == end) { - return -1; - } - - if ((uint64_t)(end - p) < valuelen) { - return -1; - } - - if (ngtcp2_get_varint_len(p) != valuelen) { - return -1; - } - - *pdest = ngtcp2_get_varint(&n, p); - - p += valuelen; - - return (ngtcp2_ssize)(p - begin); -} - -/* - * decode_cid_param decodes length prefixed ngtcp2_cid from the buffer - * pointed by |p| of length |end - p|. The length is encoded in - * varint form. If it decodes a value successfully, it stores the - * value in |*pdest| and returns the number of bytes read. Otherwise - * it returns -1. - */ -static ngtcp2_ssize decode_cid_param(ngtcp2_cid *pdest, const uint8_t *p, - const uint8_t *end) { - const uint8_t *begin = p; - uint64_t valuelen; - ngtcp2_ssize nread = decode_varint(&valuelen, p, end); - - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - - p += nread; - - if ((valuelen != 0 && valuelen < NGTCP2_MIN_CIDLEN) || - valuelen > NGTCP2_MAX_CIDLEN || (size_t)(end - p) < valuelen) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - - ngtcp2_cid_init(pdest, p, (size_t)valuelen); - - p += valuelen; - - return (ngtcp2_ssize)(p - begin); -} - -int ngtcp2_decode_transport_params(ngtcp2_transport_params *params, - ngtcp2_transport_params_type exttype, - const uint8_t *data, size_t datalen) { - const uint8_t *p, *end; - size_t len; - uint64_t param_type; - uint64_t valuelen; - ngtcp2_ssize nread; - int initial_scid_present = 0; - int original_dcid_present = 0; - - p = data; - end = data + datalen; - - /* Set default values */ - memset(params, 0, sizeof(*params)); - params->initial_max_streams_bidi = 0; - params->initial_max_streams_uni = 0; - params->initial_max_stream_data_bidi_local = 0; - params->initial_max_stream_data_bidi_remote = 0; - params->initial_max_stream_data_uni = 0; - params->max_udp_payload_size = NGTCP2_DEFAULT_MAX_UDP_PAYLOAD_SIZE; - params->ack_delay_exponent = NGTCP2_DEFAULT_ACK_DELAY_EXPONENT; - params->stateless_reset_token_present = 0; - params->preferred_address_present = 0; - params->disable_active_migration = 0; - params->max_ack_delay = NGTCP2_DEFAULT_MAX_ACK_DELAY; - params->max_idle_timeout = 0; - params->active_connection_id_limit = - NGTCP2_DEFAULT_ACTIVE_CONNECTION_ID_LIMIT; - params->retry_scid_present = 0; - memset(¶ms->retry_scid, 0, sizeof(params->retry_scid)); - memset(¶ms->initial_scid, 0, sizeof(params->initial_scid)); - memset(¶ms->original_dcid, 0, sizeof(params->original_dcid)); - - if (datalen == 0) { - return 0; - } - - for (; (size_t)(end - p) >= 2;) { - nread = decode_varint(¶m_type, p, end); - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - p += nread; - - switch (param_type) { - case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL: - nread = decode_varint_param(¶ms->initial_max_stream_data_bidi_local, - p, end); - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - p += nread; - break; - case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE: - nread = decode_varint_param(¶ms->initial_max_stream_data_bidi_remote, - p, end); - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - p += nread; - break; - case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_UNI: - nread = decode_varint_param(¶ms->initial_max_stream_data_uni, p, end); - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - p += nread; - break; - case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_DATA: - nread = decode_varint_param(¶ms->initial_max_data, p, end); - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - p += nread; - break; - case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_BIDI: - nread = decode_varint_param(¶ms->initial_max_streams_bidi, p, end); - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - if (params->initial_max_streams_bidi > NGTCP2_MAX_STREAMS) { - return NGTCP2_ERR_STREAM_LIMIT; - } - p += nread; - break; - case NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_UNI: - nread = decode_varint_param(¶ms->initial_max_streams_uni, p, end); - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - if (params->initial_max_streams_uni > NGTCP2_MAX_STREAMS) { - return NGTCP2_ERR_STREAM_LIMIT; - } - p += nread; - break; - case NGTCP2_TRANSPORT_PARAM_MAX_IDLE_TIMEOUT: - nread = decode_varint_param(¶ms->max_idle_timeout, p, end); - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - params->max_idle_timeout *= NGTCP2_MILLISECONDS; - p += nread; - break; - case NGTCP2_TRANSPORT_PARAM_MAX_UDP_PAYLOAD_SIZE: - nread = decode_varint_param(¶ms->max_udp_payload_size, p, end); - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - p += nread; - break; - case NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN: - if (exttype != NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - nread = decode_varint(&valuelen, p, end); - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - p += nread; - if ((size_t)valuelen != sizeof(params->stateless_reset_token)) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - if ((size_t)(end - p) < sizeof(params->stateless_reset_token)) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - - memcpy(params->stateless_reset_token, p, - sizeof(params->stateless_reset_token)); - params->stateless_reset_token_present = 1; - - p += sizeof(params->stateless_reset_token); - break; - case NGTCP2_TRANSPORT_PARAM_ACK_DELAY_EXPONENT: - nread = decode_varint_param(¶ms->ack_delay_exponent, p, end); - if (nread < 0 || params->ack_delay_exponent > 20) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - p += nread; - break; - case NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS: - if (exttype != NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - nread = decode_varint(&valuelen, p, end); - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - p += nread; - if ((size_t)(end - p) < valuelen) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - len = 4 /* ipv4Address */ + 2 /* ipv4Port */ + 16 /* ipv6Address */ + - 2 /* ipv6Port */ - + 1 /* cid length */ + NGTCP2_STATELESS_RESET_TOKENLEN; - if (valuelen < len) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - - memcpy(params->preferred_address.ipv4_addr, p, - sizeof(params->preferred_address.ipv4_addr)); - p += sizeof(params->preferred_address.ipv4_addr); - params->preferred_address.ipv4_port = ngtcp2_get_uint16(p); - p += sizeof(uint16_t); - - memcpy(params->preferred_address.ipv6_addr, p, - sizeof(params->preferred_address.ipv6_addr)); - p += sizeof(params->preferred_address.ipv6_addr); - params->preferred_address.ipv6_port = ngtcp2_get_uint16(p); - p += sizeof(uint16_t); - - /* cid */ - params->preferred_address.cid.datalen = *p++; - len += params->preferred_address.cid.datalen; - if (valuelen != len || - params->preferred_address.cid.datalen > NGTCP2_MAX_CIDLEN || - params->preferred_address.cid.datalen < NGTCP2_MIN_CIDLEN) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - if (params->preferred_address.cid.datalen) { - memcpy(params->preferred_address.cid.data, p, - params->preferred_address.cid.datalen); - p += params->preferred_address.cid.datalen; - } - - /* stateless reset token */ - memcpy(params->preferred_address.stateless_reset_token, p, - sizeof(params->preferred_address.stateless_reset_token)); - p += sizeof(params->preferred_address.stateless_reset_token); - params->preferred_address_present = 1; - break; - case NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION: - nread = decode_varint(&valuelen, p, end); - if (nread < 0 || valuelen != 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - p += nread; - params->disable_active_migration = 1; - break; - case NGTCP2_TRANSPORT_PARAM_ORIGINAL_DESTINATION_CONNECTION_ID: - if (exttype != NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - nread = decode_cid_param(¶ms->original_dcid, p, end); - if (nread < 0) { - return (int)nread; - } - original_dcid_present = 1; - p += nread; - break; - case NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID: - if (exttype != NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - nread = decode_cid_param(¶ms->retry_scid, p, end); - if (nread < 0) { - return (int)nread; - } - params->retry_scid_present = 1; - p += nread; - break; - case NGTCP2_TRANSPORT_PARAM_INITIAL_SOURCE_CONNECTION_ID: - nread = decode_cid_param(¶ms->initial_scid, p, end); - if (nread < 0) { - return (int)nread; - } - initial_scid_present = 1; - p += nread; - break; - case NGTCP2_TRANSPORT_PARAM_MAX_ACK_DELAY: - nread = decode_varint_param(¶ms->max_ack_delay, p, end); - if (nread < 0 || params->max_ack_delay >= 16384) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - params->max_ack_delay *= NGTCP2_MILLISECONDS; - p += nread; - break; - case NGTCP2_TRANSPORT_PARAM_ACTIVE_CONNECTION_ID_LIMIT: - nread = decode_varint_param(¶ms->active_connection_id_limit, p, end); - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - p += nread; - break; - default: - /* Ignore unknown parameter */ - nread = decode_varint(&valuelen, p, end); - if (nread < 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - p += nread; - if ((size_t)(end - p) < valuelen) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - p += valuelen; - break; - } - } - - if (end - p != 0) { - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; - } - - if (!initial_scid_present || - (exttype == NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS && - !original_dcid_present)) { - return NGTCP2_ERR_REQUIRED_TRANSPORT_PARAM; - } - - return 0; -} diff --git a/deps/ngtcp2/lib/ngtcp2_crypto.h b/deps/ngtcp2/lib/ngtcp2_crypto.h deleted file mode 100644 index b1baf30a85f6fc..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_crypto.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_CRYPTO_H -#define NGTCP2_CRYPTO_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_mem.h" - -/* NGTCP2_INITIAL_AEAD_OVERHEAD is an overhead of AEAD used by Initial - packets. Because QUIC uses AEAD_AES_128_GCM, the overhead is 16 - bytes. */ -#define NGTCP2_INITIAL_AEAD_OVERHEAD 16 - -/* NGTCP2_MAX_AEAD_OVERHEAD is expected maximum AEAD overhead. */ -#define NGTCP2_MAX_AEAD_OVERHEAD 16 - -typedef enum { - NGTCP2_CRYPTO_KM_FLAG_NONE, - /* NGTCP2_CRYPTO_KM_FLAG_KEY_PHASE_ONE is set if key phase bit is - set. */ - NGTCP2_CRYPTO_KM_FLAG_KEY_PHASE_ONE = 0x01, -} ngtcp2_crypto_km_flag; - -typedef struct { - ngtcp2_vec secret; - ngtcp2_crypto_aead_ctx aead_ctx; - ngtcp2_vec iv; - /* pkt_num is a packet number of a packet which uses this keying - material. For encryption key, it is the lowest packet number of - a packet. For decryption key, it is the lowest packet number of - a packet which can be decrypted with this keying material. */ - int64_t pkt_num; - /* use_count is the number of encryption or decryption failure. For - tx key, this is the number of encryption. For rx key, this is - the number of decryption failure. */ - uint64_t use_count; - /* flags is the bitwise OR of zero or more of - ngtcp2_crypto_km_flag. */ - uint8_t flags; -} ngtcp2_crypto_km; - -/* - * ngtcp2_crypto_km_new creates new ngtcp2_crypto_km object and - * assigns its pointer to |*pckm|. The |secret| of length - * |secretlen|, the |key| of length |keylen| and the |iv| of length - * |ivlen| are copied to |*pckm|. If |secretlen| == 0, the function - * assumes no secret is given which is acceptable. The sole reason to - * store secret is update keys. Only 1RTT key can be updated. - */ -int ngtcp2_crypto_km_new(ngtcp2_crypto_km **pckm, const uint8_t *secret, - size_t secretlen, - const ngtcp2_crypto_aead_ctx *aead_ctx, - const uint8_t *iv, size_t ivlen, - const ngtcp2_mem *mem); - -/* - * ngtcp2_crypto_km_nocopy_new is similar to ngtcp2_crypto_km_new, but - * it does not copy secret, key and IV. - */ -int ngtcp2_crypto_km_nocopy_new(ngtcp2_crypto_km **pckm, size_t secretlen, - size_t ivlen, const ngtcp2_mem *mem); - -void ngtcp2_crypto_km_del(ngtcp2_crypto_km *ckm, const ngtcp2_mem *mem); - -typedef struct { - ngtcp2_crypto_aead aead; - ngtcp2_crypto_cipher hp; - ngtcp2_crypto_km *ckm; - ngtcp2_crypto_cipher_ctx hp_ctx; - size_t aead_overhead; - ngtcp2_encrypt encrypt; - ngtcp2_decrypt decrypt; - ngtcp2_hp_mask hp_mask; -} ngtcp2_crypto_cc; - -void ngtcp2_crypto_create_nonce(uint8_t *dest, const uint8_t *iv, size_t ivlen, - int64_t pkt_num); - -#endif /* NGTCP2_CRYPTO_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_err.c b/deps/ngtcp2/lib/ngtcp2_err.c deleted file mode 100644 index 5a2425367d48a8..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_err.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_err.h" - -const char *ngtcp2_strerror(int liberr) { - switch (liberr) { - case 0: - return "NO_ERROR"; - case NGTCP2_ERR_INVALID_ARGUMENT: - return "ERR_INVALID_ARGUMENT"; - case NGTCP2_ERR_UNKNOWN_PKT_TYPE: - return "ERR_UNKNOWN_PKT_TYPE"; - case NGTCP2_ERR_NOBUF: - return "ERR_NOBUF"; - case NGTCP2_ERR_PROTO: - return "ERR_PROTO"; - case NGTCP2_ERR_INVALID_STATE: - return "ERR_INVALID_STATE"; - case NGTCP2_ERR_ACK_FRAME: - return "ERR_ACK_FRAME"; - case NGTCP2_ERR_STREAM_ID_BLOCKED: - return "ERR_STREAM_ID_BLOCKED"; - case NGTCP2_ERR_STREAM_IN_USE: - return "ERR_STREAM_IN_USE"; - case NGTCP2_ERR_STREAM_DATA_BLOCKED: - return "ERR_STREAM_DATA_BLOCKED"; - case NGTCP2_ERR_FLOW_CONTROL: - return "ERR_FLOW_CONTROL"; - case NGTCP2_ERR_CONNECTION_ID_LIMIT: - return "ERR_CONNECTION_ID_LIMIT"; - case NGTCP2_ERR_STREAM_LIMIT: - return "ERR_STREAM_LIMIT"; - case NGTCP2_ERR_FINAL_SIZE: - return "ERR_FINAL_SIZE"; - case NGTCP2_ERR_CRYPTO: - return "ERR_CRYPTO"; - case NGTCP2_ERR_PKT_NUM_EXHAUSTED: - return "ERR_PKT_NUM_EXHAUSTED"; - case NGTCP2_ERR_NOMEM: - return "ERR_NOMEM"; - case NGTCP2_ERR_REQUIRED_TRANSPORT_PARAM: - return "ERR_REQUIRED_TRANSPORT_PARAM"; - case NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM: - return "ERR_MALFORMED_TRANSPORT_PARAM"; - case NGTCP2_ERR_FRAME_ENCODING: - return "ERR_FRAME_ENCODING"; - case NGTCP2_ERR_TLS_DECRYPT: - return "ERR_TLS_DECRYPT"; - case NGTCP2_ERR_STREAM_SHUT_WR: - return "ERR_STREAM_SHUT_WR"; - case NGTCP2_ERR_STREAM_NOT_FOUND: - return "ERR_STREAM_NOT_FOUND"; - case NGTCP2_ERR_STREAM_STATE: - return "ERR_STREAM_STATE"; - case NGTCP2_ERR_RECV_VERSION_NEGOTIATION: - return "ERR_RECV_VERSION_NEGOTIATION"; - case NGTCP2_ERR_CLOSING: - return "ERR_CLOSING"; - case NGTCP2_ERR_DRAINING: - return "ERR_DRAINING"; - case NGTCP2_ERR_TRANSPORT_PARAM: - return "ERR_TRANSPORT_PARAM"; - case NGTCP2_ERR_DISCARD_PKT: - return "ERR_DISCARD_PKT"; - case NGTCP2_ERR_PATH_VALIDATION_FAILED: - return "ERR_PATH_VALIDATION_FAILED"; - case NGTCP2_ERR_CONN_ID_BLOCKED: - return "ERR_CONN_ID_BLOCKED"; - case NGTCP2_ERR_CALLBACK_FAILURE: - return "ERR_CALLBACK_FAILURE"; - case NGTCP2_ERR_INTERNAL: - return "ERR_INTERNAL"; - case NGTCP2_ERR_CRYPTO_BUFFER_EXCEEDED: - return "ERR_CRYPTO_BUFFER_EXCEEDED"; - case NGTCP2_ERR_WRITE_MORE: - return "ERR_WRITE_MORE"; - case NGTCP2_ERR_RETRY: - return "ERR_RETRY"; - case NGTCP2_ERR_DROP_CONN: - return "ERR_DROP_CONN"; - default: - return "(unknown)"; - } -} - -int ngtcp2_err_is_fatal(int liberr) { return liberr < NGTCP2_ERR_FATAL; } - -uint64_t ngtcp2_err_infer_quic_transport_error_code(int liberr) { - switch (liberr) { - case 0: - return NGTCP2_NO_ERROR; - case NGTCP2_ERR_ACK_FRAME: - case NGTCP2_ERR_FRAME_ENCODING: - return NGTCP2_FRAME_ENCODING_ERROR; - case NGTCP2_ERR_FLOW_CONTROL: - return NGTCP2_FLOW_CONTROL_ERROR; - case NGTCP2_ERR_CONNECTION_ID_LIMIT: - return NGTCP2_CONNECTION_ID_LIMIT_ERROR; - case NGTCP2_ERR_STREAM_LIMIT: - return NGTCP2_STREAM_LIMIT_ERROR; - case NGTCP2_ERR_FINAL_SIZE: - return NGTCP2_FINAL_SIZE_ERROR; - case NGTCP2_ERR_REQUIRED_TRANSPORT_PARAM: - case NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM: - case NGTCP2_ERR_TRANSPORT_PARAM: - return NGTCP2_TRANSPORT_PARAMETER_ERROR; - case NGTCP2_ERR_INVALID_ARGUMENT: - return NGTCP2_INTERNAL_ERROR; - case NGTCP2_ERR_STREAM_STATE: - return NGTCP2_STREAM_STATE_ERROR; - case NGTCP2_ERR_CRYPTO_BUFFER_EXCEEDED: - return NGTCP2_CRYPTO_BUFFER_EXCEEDED; - default: - return NGTCP2_PROTOCOL_VIOLATION; - } -} diff --git a/deps/ngtcp2/lib/ngtcp2_err.h b/deps/ngtcp2/lib/ngtcp2_err.h deleted file mode 100644 index 9229f5425a63cf..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_err.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_ERR_H -#define NGTCP2_ERR_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#endif /* NGTCP2_ERR_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_gaptr.c b/deps/ngtcp2/lib/ngtcp2_gaptr.c deleted file mode 100644 index 6e7f3b7e554826..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_gaptr.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_gaptr.h" -#include "ngtcp2_range.h" - -#include -#include - -int ngtcp2_gaptr_init(ngtcp2_gaptr *gaptr, const ngtcp2_mem *mem) { - int rv; - ngtcp2_range range = {0, UINT64_MAX}; - - rv = ngtcp2_ksl_init(&gaptr->gap, ngtcp2_ksl_range_compar, - sizeof(ngtcp2_range), mem); - if (rv != 0) { - return rv; - } - - rv = ngtcp2_ksl_insert(&gaptr->gap, NULL, &range, NULL); - if (rv != 0) { - ngtcp2_ksl_free(&gaptr->gap); - return rv; - } - - gaptr->mem = mem; - - return 0; -} - -void ngtcp2_gaptr_free(ngtcp2_gaptr *gaptr) { - if (gaptr == NULL) { - return; - } - - ngtcp2_ksl_free(&gaptr->gap); -} - -int ngtcp2_gaptr_push(ngtcp2_gaptr *gaptr, uint64_t offset, size_t datalen) { - int rv; - ngtcp2_range k, m, l, r, q = {offset, offset + datalen}; - ngtcp2_ksl_it it; - - it = ngtcp2_ksl_lower_bound_compar(&gaptr->gap, &q, - ngtcp2_ksl_range_exclusive_compar); - - for (; !ngtcp2_ksl_it_end(&it);) { - k = *(ngtcp2_range *)ngtcp2_ksl_it_key(&it); - m = ngtcp2_range_intersect(&q, &k); - if (!ngtcp2_range_len(&m)) { - break; - } - - if (ngtcp2_range_eq(&k, &m)) { - ngtcp2_ksl_remove(&gaptr->gap, &it, &k); - continue; - } - ngtcp2_range_cut(&l, &r, &k, &m); - if (ngtcp2_range_len(&l)) { - ngtcp2_ksl_update_key(&gaptr->gap, &k, &l); - - if (ngtcp2_range_len(&r)) { - rv = ngtcp2_ksl_insert(&gaptr->gap, &it, &r, NULL); - if (rv != 0) { - return rv; - } - } - } else if (ngtcp2_range_len(&r)) { - ngtcp2_ksl_update_key(&gaptr->gap, &k, &r); - } - ngtcp2_ksl_it_next(&it); - } - return 0; -} - -uint64_t ngtcp2_gaptr_first_gap_offset(ngtcp2_gaptr *gaptr) { - ngtcp2_ksl_it it = ngtcp2_ksl_begin(&gaptr->gap); - ngtcp2_range r = *(ngtcp2_range *)ngtcp2_ksl_it_key(&it); - return r.begin; -} - -ngtcp2_ksl_it ngtcp2_gaptr_get_first_gap_after(ngtcp2_gaptr *gaptr, - uint64_t offset) { - ngtcp2_range q = {offset, offset + 1}; - return ngtcp2_ksl_lower_bound_compar(&gaptr->gap, &q, - ngtcp2_ksl_range_exclusive_compar); -} - -int ngtcp2_gaptr_is_pushed(ngtcp2_gaptr *gaptr, uint64_t offset, - size_t datalen) { - ngtcp2_range q = {offset, offset + datalen}; - ngtcp2_ksl_it it = ngtcp2_ksl_lower_bound_compar( - &gaptr->gap, &q, ngtcp2_ksl_range_exclusive_compar); - ngtcp2_range k = *(ngtcp2_range *)ngtcp2_ksl_it_key(&it); - ngtcp2_range m = ngtcp2_range_intersect(&q, &k); - return ngtcp2_range_len(&m) == 0; -} - -void ngtcp2_gaptr_drop_first_gap(ngtcp2_gaptr *gaptr) { - ngtcp2_ksl_it it = ngtcp2_ksl_begin(&gaptr->gap); - ngtcp2_range r; - - assert(!ngtcp2_ksl_it_end(&it)); - - r = *(ngtcp2_range *)ngtcp2_ksl_it_key(&it); - - ngtcp2_ksl_remove(&gaptr->gap, NULL, &r); -} diff --git a/deps/ngtcp2/lib/ngtcp2_gaptr.h b/deps/ngtcp2/lib/ngtcp2_gaptr.h deleted file mode 100644 index 9e7fa03086e295..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_gaptr.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_GAPTR_H -#define NGTCP2_GAPTR_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_mem.h" -#include "ngtcp2_ksl.h" - -/* - * ngtcp2_gaptr maintains the gap in the range [0, UINT64_MAX). - */ -typedef struct { - /* gap maintains the range of offset which is not received - yet. Initially, its range is [0, UINT64_MAX). */ - ngtcp2_ksl gap; - /* mem is custom memory allocator */ - const ngtcp2_mem *mem; -} ngtcp2_gaptr; - -/* - * ngtcp2_gaptr_init initializes |gaptr|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_gaptr_init(ngtcp2_gaptr *gaptr, const ngtcp2_mem *mem); - -/* - * ngtcp2_gaptr_free frees resources allocated for |gaptr|. - */ -void ngtcp2_gaptr_free(ngtcp2_gaptr *gaptr); - -/* - * ngtcp2_gaptr_push adds new data of length |datalen| at the stream - * offset |offset|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -int ngtcp2_gaptr_push(ngtcp2_gaptr *gaptr, uint64_t offset, size_t datalen); - -/* - * ngtcp2_gaptr_first_gap_offset returns the offset to the first gap. - * If there is no gap, it returns UINT64_MAX. - */ -uint64_t ngtcp2_gaptr_first_gap_offset(ngtcp2_gaptr *gaptr); - -/* - * ngtcp2_gaptr_get_first_gap_after returns the iterator pointing to - * the first gap which overlaps or comes after |offset|. - */ -ngtcp2_ksl_it ngtcp2_gaptr_get_first_gap_after(ngtcp2_gaptr *gaptr, - uint64_t offset); - -/* - * ngtcp2_gaptr_is_pushed returns nonzero if range [offset, offset + - * datalen) is completely pushed into this object. - */ -int ngtcp2_gaptr_is_pushed(ngtcp2_gaptr *gaptr, uint64_t offset, - size_t datalen); - -/* - * ngtcp2_gaptr_drop_first_gap deletes the first gap entirely as if - * the range is pushed. This function assumes that at least one gap - * exists. - */ -void ngtcp2_gaptr_drop_first_gap(ngtcp2_gaptr *gaptr); - -#endif /* NGTCP2_GAPTR_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_idtr.c b/deps/ngtcp2/lib/ngtcp2_idtr.c deleted file mode 100644 index f04806b4a8b22f..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_idtr.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_idtr.h" - -#include - -int ngtcp2_idtr_init(ngtcp2_idtr *idtr, int server, const ngtcp2_mem *mem) { - int rv; - - rv = ngtcp2_gaptr_init(&idtr->gap, mem); - if (rv != 0) { - return rv; - } - - idtr->server = server; - - return 0; -} - -void ngtcp2_idtr_free(ngtcp2_idtr *idtr) { - if (idtr == NULL) { - return; - } - - ngtcp2_gaptr_free(&idtr->gap); -} - -/* - * id_from_stream_id translates |stream_id| to id space used by - * ngtcp2_idtr. - */ -static uint64_t id_from_stream_id(int64_t stream_id) { - return (uint64_t)(stream_id >> 2); -} - -int ngtcp2_idtr_open(ngtcp2_idtr *idtr, int64_t stream_id) { - uint64_t q; - - assert((idtr->server && (stream_id % 2)) || - (!idtr->server && (stream_id % 2)) == 0); - - q = id_from_stream_id(stream_id); - - if (ngtcp2_gaptr_is_pushed(&idtr->gap, q, 1)) { - return NGTCP2_ERR_STREAM_IN_USE; - } - - return ngtcp2_gaptr_push(&idtr->gap, q, 1); -} - -int ngtcp2_idtr_is_open(ngtcp2_idtr *idtr, int64_t stream_id) { - uint64_t q; - - assert((idtr->server && (stream_id % 2)) || - (!idtr->server && (stream_id % 2)) == 0); - - q = id_from_stream_id(stream_id); - - return ngtcp2_gaptr_is_pushed(&idtr->gap, q, 1); -} - -uint64_t ngtcp2_idtr_first_gap(ngtcp2_idtr *idtr) { - return ngtcp2_gaptr_first_gap_offset(&idtr->gap); -} diff --git a/deps/ngtcp2/lib/ngtcp2_idtr.h b/deps/ngtcp2/lib/ngtcp2_idtr.h deleted file mode 100644 index 63f332e64f9cd0..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_idtr.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_IDTR_H -#define NGTCP2_IDTR_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_mem.h" -#include "ngtcp2_gaptr.h" - -/* - * ngtcp2_idtr tracks the usage of stream ID. - */ -typedef struct { - /* gap maintains the range of ID which is not used yet. Initially, - its range is [0, UINT64_MAX). */ - ngtcp2_gaptr gap; - /* server is nonzero if this object records server initiated stream - ID. */ - int server; -} ngtcp2_idtr; - -/* - * ngtcp2_idtr_init initializes |idtr|. - * - * If this object records server initiated ID (even number), set - * |server| to nonzero. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_idtr_init(ngtcp2_idtr *idtr, int server, const ngtcp2_mem *mem); - -/* - * ngtcp2_idtr_free frees resources allocated for |idtr|. - */ -void ngtcp2_idtr_free(ngtcp2_idtr *idtr); - -/* - * ngtcp2_idtr_open claims that |stream_id| is in used. - * - * It returns 0 if it succeeds, or one of the following negative error - * codes: - * - * NGTCP2_ERR_STREAM_IN_USE - * ID has already been used. - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_idtr_open(ngtcp2_idtr *idtr, int64_t stream_id); - -/* - * ngtcp2_idtr_open tells whether ID |stream_id| is in used or not. - * - * It returns nonzero if |stream_id| is used. - */ -int ngtcp2_idtr_is_open(ngtcp2_idtr *idtr, int64_t stream_id); - -/* - * ngtcp2_idtr_first_gap returns the first id of first gap. If there - * is no gap, it returns UINT64_MAX. The returned id is an id space - * used in this object internally, and not stream ID. - */ -uint64_t ngtcp2_idtr_first_gap(ngtcp2_idtr *idtr); - -#endif /* NGTCP2_IDTR_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_ksl.c b/deps/ngtcp2/lib/ngtcp2_ksl.c deleted file mode 100644 index 0c47150cb143e7..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_ksl.c +++ /dev/null @@ -1,715 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_ksl.h" - -#include -#include -#include -#include - -#include "ngtcp2_macro.h" -#include "ngtcp2_mem.h" -#include "ngtcp2_range.h" - -static size_t ksl_nodelen(size_t keylen) { - return (sizeof(ngtcp2_ksl_node) + keylen - sizeof(uint64_t) + 0xf) & - (size_t)~0xf; -} - -static size_t ksl_blklen(size_t nodelen) { - return sizeof(ngtcp2_ksl_blk) + nodelen * NGTCP2_KSL_MAX_NBLK - - sizeof(uint64_t); -} - -/* - * ksl_node_set_key sets |key| to |node|. - */ -static void ksl_node_set_key(ngtcp2_ksl *ksl, ngtcp2_ksl_node *node, - const void *key) { - memcpy(node->key, key, ksl->keylen); -} - -int ngtcp2_ksl_init(ngtcp2_ksl *ksl, ngtcp2_ksl_compar compar, size_t keylen, - const ngtcp2_mem *mem) { - size_t nodelen = ksl_nodelen(keylen); - size_t blklen = ksl_blklen(nodelen); - ngtcp2_ksl_blk *head; - - ksl->head = ngtcp2_mem_malloc(mem, blklen); - if (!ksl->head) { - return NGTCP2_ERR_NOMEM; - } - ksl->front = ksl->back = ksl->head; - ksl->compar = compar; - ksl->keylen = keylen; - ksl->nodelen = nodelen; - ksl->n = 0; - ksl->mem = mem; - - head = ksl->head; - head->next = head->prev = NULL; - head->n = 0; - head->leaf = 1; - - return 0; -} - -/* - * ksl_free_blk frees |blk| recursively. - */ -static void ksl_free_blk(ngtcp2_ksl *ksl, ngtcp2_ksl_blk *blk) { - size_t i; - - if (!blk->leaf) { - for (i = 0; i < blk->n; ++i) { - ksl_free_blk(ksl, ngtcp2_ksl_nth_node(ksl, blk, i)->blk); - } - } - - ngtcp2_mem_free(ksl->mem, blk); -} - -void ngtcp2_ksl_free(ngtcp2_ksl *ksl) { - if (!ksl) { - return; - } - - ksl_free_blk(ksl, ksl->head); -} - -/* - * ksl_split_blk splits |blk| into 2 ngtcp2_ksl_blk objects. The new - * ngtcp2_ksl_blk is always the "right" block. - * - * It returns the pointer to the ngtcp2_ksl_blk created which is the - * located at the right of |blk|, or NULL which indicates out of - * memory error. - */ -static ngtcp2_ksl_blk *ksl_split_blk(ngtcp2_ksl *ksl, ngtcp2_ksl_blk *blk) { - ngtcp2_ksl_blk *rblk; - - rblk = ngtcp2_mem_malloc(ksl->mem, ksl_blklen(ksl->nodelen)); - if (rblk == NULL) { - return NULL; - } - - rblk->next = blk->next; - blk->next = rblk; - if (rblk->next) { - rblk->next->prev = rblk; - } else if (ksl->back == blk) { - ksl->back = rblk; - } - rblk->prev = blk; - rblk->leaf = blk->leaf; - - rblk->n = blk->n / 2; - - memcpy(rblk->nodes, blk->nodes + ksl->nodelen * (blk->n - rblk->n), - ksl->nodelen * rblk->n); - - blk->n -= rblk->n; - - assert(blk->n >= NGTCP2_KSL_MIN_NBLK); - assert(rblk->n >= NGTCP2_KSL_MIN_NBLK); - - return rblk; -} - -/* - * ksl_split_node splits a node included in |blk| at the position |i| - * into 2 adjacent nodes. The new node is always inserted at the - * position |i+1|. - * - * It returns 0 if it succeeds, or one of the following negative error - * codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int ksl_split_node(ngtcp2_ksl *ksl, ngtcp2_ksl_blk *blk, size_t i) { - ngtcp2_ksl_node *node; - ngtcp2_ksl_blk *lblk = ngtcp2_ksl_nth_node(ksl, blk, i)->blk, *rblk; - - rblk = ksl_split_blk(ksl, lblk); - if (rblk == NULL) { - return NGTCP2_ERR_NOMEM; - } - - memmove(blk->nodes + (i + 2) * ksl->nodelen, - blk->nodes + (i + 1) * ksl->nodelen, - ksl->nodelen * (blk->n - (i + 1))); - - node = ngtcp2_ksl_nth_node(ksl, blk, i + 1); - node->blk = rblk; - ++blk->n; - ksl_node_set_key(ksl, node, ngtcp2_ksl_nth_node(ksl, rblk, rblk->n - 1)->key); - - node = ngtcp2_ksl_nth_node(ksl, blk, i); - ksl_node_set_key(ksl, node, ngtcp2_ksl_nth_node(ksl, lblk, lblk->n - 1)->key); - - return 0; -} - -/* - * ksl_split_head splits a head (root) block. It increases the height - * of skip list by 1. - * - * It returns 0 if it succeeds, or one of the following negative error - * codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -static int ksl_split_head(ngtcp2_ksl *ksl) { - ngtcp2_ksl_blk *rblk = NULL, *lblk, *nhead = NULL; - ngtcp2_ksl_node *node; - - rblk = ksl_split_blk(ksl, ksl->head); - if (rblk == NULL) { - return NGTCP2_ERR_NOMEM; - } - - lblk = ksl->head; - - nhead = ngtcp2_mem_malloc(ksl->mem, ksl_blklen(ksl->nodelen)); - if (nhead == NULL) { - ngtcp2_mem_free(ksl->mem, rblk); - return NGTCP2_ERR_NOMEM; - } - nhead->next = nhead->prev = NULL; - nhead->n = 2; - nhead->leaf = 0; - - node = ngtcp2_ksl_nth_node(ksl, nhead, 0); - ksl_node_set_key(ksl, node, ngtcp2_ksl_nth_node(ksl, lblk, lblk->n - 1)->key); - node->blk = lblk; - - node = ngtcp2_ksl_nth_node(ksl, nhead, 1); - ksl_node_set_key(ksl, node, ngtcp2_ksl_nth_node(ksl, rblk, rblk->n - 1)->key); - node->blk = rblk; - - ksl->head = nhead; - - return 0; -} - -/* - * insert_node inserts a node whose key is |key| with the associated - * |data| at the index of |i|. This function assumes that the number - * of nodes contained by |blk| is strictly less than - * NGTCP2_KSL_MAX_NBLK. - */ -static void ksl_insert_node(ngtcp2_ksl *ksl, ngtcp2_ksl_blk *blk, size_t i, - const ngtcp2_ksl_key *key, void *data) { - ngtcp2_ksl_node *node; - - assert(blk->n < NGTCP2_KSL_MAX_NBLK); - - memmove(blk->nodes + (i + 1) * ksl->nodelen, blk->nodes + i * ksl->nodelen, - ksl->nodelen * (blk->n - i)); - - node = ngtcp2_ksl_nth_node(ksl, blk, i); - ksl_node_set_key(ksl, node, key); - node->data = data; - - ++blk->n; -} - -static size_t ksl_bsearch(ngtcp2_ksl *ksl, ngtcp2_ksl_blk *blk, - const ngtcp2_ksl_key *key, ngtcp2_ksl_compar compar) { - ngtcp2_ssize left = -1, right = (ngtcp2_ssize)blk->n, mid; - ngtcp2_ksl_node *node; - - while (right - left > 1) { - mid = (left + right) / 2; - node = ngtcp2_ksl_nth_node(ksl, blk, (size_t)mid); - if (compar((ngtcp2_ksl_key *)node->key, key)) { - left = mid; - } else { - right = mid; - } - } - - return (size_t)right; -} - -int ngtcp2_ksl_insert(ngtcp2_ksl *ksl, ngtcp2_ksl_it *it, - const ngtcp2_ksl_key *key, void *data) { - ngtcp2_ksl_blk *blk = ksl->head; - ngtcp2_ksl_node *node; - size_t i; - int rv; - - if (blk->n == NGTCP2_KSL_MAX_NBLK) { - rv = ksl_split_head(ksl); - if (rv != 0) { - return rv; - } - blk = ksl->head; - } - - for (;;) { - i = ksl_bsearch(ksl, blk, key, ksl->compar); - - if (blk->leaf) { - if (i < blk->n && - !ksl->compar(key, ngtcp2_ksl_nth_node(ksl, blk, i)->key)) { - if (it) { - *it = ngtcp2_ksl_end(ksl); - } - return NGTCP2_ERR_INVALID_ARGUMENT; - } - ksl_insert_node(ksl, blk, i, key, data); - ++ksl->n; - if (it) { - ngtcp2_ksl_it_init(it, ksl, blk, i); - } - return 0; - } - - if (i == blk->n) { - /* This insertion extends the largest key in this subtree. */ - for (; !blk->leaf;) { - node = ngtcp2_ksl_nth_node(ksl, blk, blk->n - 1); - if (node->blk->n == NGTCP2_KSL_MAX_NBLK) { - rv = ksl_split_node(ksl, blk, blk->n - 1); - if (rv != 0) { - return rv; - } - node = ngtcp2_ksl_nth_node(ksl, blk, blk->n - 1); - } - ksl_node_set_key(ksl, node, key); - blk = node->blk; - } - ksl_insert_node(ksl, blk, blk->n, key, data); - ++ksl->n; - if (it) { - ngtcp2_ksl_it_init(it, ksl, blk, blk->n - 1); - } - return 0; - } - - node = ngtcp2_ksl_nth_node(ksl, blk, i); - - if (node->blk->n == NGTCP2_KSL_MAX_NBLK) { - rv = ksl_split_node(ksl, blk, i); - if (rv != 0) { - return rv; - } - if (ksl->compar((ngtcp2_ksl_key *)node->key, key)) { - node = ngtcp2_ksl_nth_node(ksl, blk, i + 1); - if (ksl->compar((ngtcp2_ksl_key *)node->key, key)) { - ksl_node_set_key(ksl, node, key); - } - } - } - - blk = node->blk; - } -} - -/* - * ksl_remove_node removes the node included in |blk| at the index of - * |i|. - */ -static void ksl_remove_node(ngtcp2_ksl *ksl, ngtcp2_ksl_blk *blk, size_t i) { - memmove(blk->nodes + i * ksl->nodelen, blk->nodes + (i + 1) * ksl->nodelen, - ksl->nodelen * (blk->n - (i + 1))); - - --blk->n; -} - -/* - * ksl_merge_node merges 2 nodes which are the nodes at the index of - * |i| and |i + 1|. - * - * If |blk| is the direct descendant of head (root) block and the head - * block contains just 2 nodes, the merged block becomes head block, - * which decreases the height of |ksl| by 1. - * - * This function returns the pointer to the merged block. - */ -static ngtcp2_ksl_blk *ksl_merge_node(ngtcp2_ksl *ksl, ngtcp2_ksl_blk *blk, - size_t i) { - ngtcp2_ksl_blk *lblk, *rblk; - - assert(i + 1 < blk->n); - - lblk = ngtcp2_ksl_nth_node(ksl, blk, i)->blk; - rblk = ngtcp2_ksl_nth_node(ksl, blk, i + 1)->blk; - - assert(lblk->n + rblk->n < NGTCP2_KSL_MAX_NBLK); - - memcpy(lblk->nodes + ksl->nodelen * lblk->n, rblk->nodes, - ksl->nodelen * rblk->n); - - lblk->n += rblk->n; - lblk->next = rblk->next; - if (lblk->next) { - lblk->next->prev = lblk; - } else if (ksl->back == rblk) { - ksl->back = lblk; - } - - ngtcp2_mem_free(ksl->mem, rblk); - - if (ksl->head == blk && blk->n == 2) { - ngtcp2_mem_free(ksl->mem, ksl->head); - ksl->head = lblk; - } else { - ksl_remove_node(ksl, blk, i + 1); - ksl_node_set_key(ksl, ngtcp2_ksl_nth_node(ksl, blk, i), - ngtcp2_ksl_nth_node(ksl, lblk, lblk->n - 1)->key); - } - - return lblk; -} - -/* - * ksl_shift_left moves the first node in blk->nodes[i]->blk->nodes to - * blk->nodes[i - 1]->blk->nodes. - */ -static void ksl_shift_left(ngtcp2_ksl *ksl, ngtcp2_ksl_blk *blk, size_t i) { - ngtcp2_ksl_node *lnode, *rnode, *dest, *src; - - assert(i > 0); - - lnode = ngtcp2_ksl_nth_node(ksl, blk, i - 1); - rnode = ngtcp2_ksl_nth_node(ksl, blk, i); - - assert(lnode->blk->n < NGTCP2_KSL_MAX_NBLK); - assert(rnode->blk->n > NGTCP2_KSL_MIN_NBLK); - - dest = ngtcp2_ksl_nth_node(ksl, lnode->blk, lnode->blk->n); - src = ngtcp2_ksl_nth_node(ksl, rnode->blk, 0); - - memcpy(dest, src, ksl->nodelen); - ksl_node_set_key(ksl, lnode, dest->key); - ++lnode->blk->n; - - --rnode->blk->n; - memmove(rnode->blk->nodes, rnode->blk->nodes + ksl->nodelen, - ksl->nodelen * rnode->blk->n); -} - -/* - * ksl_shift_right moves the last node in blk->nodes[i]->blk->nodes to - * blk->nodes[i + 1]->blk->nodes. - */ -static void ksl_shift_right(ngtcp2_ksl *ksl, ngtcp2_ksl_blk *blk, size_t i) { - ngtcp2_ksl_node *lnode, *rnode, *dest, *src; - - assert(i < blk->n - 1); - - lnode = ngtcp2_ksl_nth_node(ksl, blk, i); - rnode = ngtcp2_ksl_nth_node(ksl, blk, i + 1); - - assert(lnode->blk->n > NGTCP2_KSL_MIN_NBLK); - assert(rnode->blk->n < NGTCP2_KSL_MAX_NBLK); - - memmove(rnode->blk->nodes + ksl->nodelen, rnode->blk->nodes, - ksl->nodelen * rnode->blk->n); - ++rnode->blk->n; - - dest = ngtcp2_ksl_nth_node(ksl, rnode->blk, 0); - src = ngtcp2_ksl_nth_node(ksl, lnode->blk, lnode->blk->n - 1); - - memcpy(dest, src, ksl->nodelen); - - --lnode->blk->n; - ksl_node_set_key( - ksl, lnode, ngtcp2_ksl_nth_node(ksl, lnode->blk, lnode->blk->n - 1)->key); -} - -/* - * key_equal returns nonzero if |lhs| and |rhs| are equal using the - * function |compar|. - */ -static int key_equal(ngtcp2_ksl_compar compar, const ngtcp2_ksl_key *lhs, - const ngtcp2_ksl_key *rhs) { - return !compar(lhs, rhs) && !compar(rhs, lhs); -} - -int ngtcp2_ksl_remove(ngtcp2_ksl *ksl, ngtcp2_ksl_it *it, - const ngtcp2_ksl_key *key) { - ngtcp2_ksl_blk *blk = ksl->head; - ngtcp2_ksl_node *node; - size_t i; - - if (!blk->leaf && blk->n == 2 && - ngtcp2_ksl_nth_node(ksl, blk, 0)->blk->n == NGTCP2_KSL_MIN_NBLK && - ngtcp2_ksl_nth_node(ksl, blk, 1)->blk->n == NGTCP2_KSL_MIN_NBLK) { - blk = ksl_merge_node(ksl, ksl->head, 0); - } - - for (;;) { - i = ksl_bsearch(ksl, blk, key, ksl->compar); - - if (i == blk->n) { - if (it) { - *it = ngtcp2_ksl_end(ksl); - } - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - if (blk->leaf) { - if (ksl->compar(key, ngtcp2_ksl_nth_node(ksl, blk, i)->key)) { - if (it) { - *it = ngtcp2_ksl_end(ksl); - } - return NGTCP2_ERR_INVALID_ARGUMENT; - } - ksl_remove_node(ksl, blk, i); - --ksl->n; - if (it) { - if (blk->n == i && blk->next) { - ngtcp2_ksl_it_init(it, ksl, blk->next, 0); - } else { - ngtcp2_ksl_it_init(it, ksl, blk, i); - } - } - return 0; - } - - node = ngtcp2_ksl_nth_node(ksl, blk, i); - - if (node->blk->n == NGTCP2_KSL_MIN_NBLK) { - if (i > 0 && - ngtcp2_ksl_nth_node(ksl, blk, i - 1)->blk->n > NGTCP2_KSL_MIN_NBLK) { - ksl_shift_right(ksl, blk, i - 1); - blk = node->blk; - } else if (i + 1 < blk->n && - ngtcp2_ksl_nth_node(ksl, blk, i + 1)->blk->n > - NGTCP2_KSL_MIN_NBLK) { - ksl_shift_left(ksl, blk, i + 1); - blk = node->blk; - } else if (i > 0) { - blk = ksl_merge_node(ksl, blk, i - 1); - } else { - assert(i + 1 < blk->n); - blk = ksl_merge_node(ksl, blk, i); - } - } else { - blk = node->blk; - } - } -} - -ngtcp2_ksl_it ngtcp2_ksl_lower_bound(ngtcp2_ksl *ksl, - const ngtcp2_ksl_key *key) { - ngtcp2_ksl_blk *blk = ksl->head; - ngtcp2_ksl_it it; - size_t i; - - for (;;) { - i = ksl_bsearch(ksl, blk, key, ksl->compar); - - if (blk->leaf) { - if (i == blk->n && blk->next) { - blk = blk->next; - i = 0; - } - ngtcp2_ksl_it_init(&it, ksl, blk, i); - return it; - } - - if (i == blk->n) { - /* This happens if descendant has smaller key. Fast forward to - find last node in this subtree. */ - for (; !blk->leaf; blk = ngtcp2_ksl_nth_node(ksl, blk, blk->n - 1)->blk) - ; - if (blk->next) { - blk = blk->next; - i = 0; - } else { - i = blk->n; - } - ngtcp2_ksl_it_init(&it, ksl, blk, i); - return it; - } - blk = ngtcp2_ksl_nth_node(ksl, blk, i)->blk; - } -} - -ngtcp2_ksl_it ngtcp2_ksl_lower_bound_compar(ngtcp2_ksl *ksl, - const ngtcp2_ksl_key *key, - ngtcp2_ksl_compar compar) { - ngtcp2_ksl_blk *blk = ksl->head; - ngtcp2_ksl_it it; - size_t i; - - for (;;) { - i = ksl_bsearch(ksl, blk, key, compar); - - if (blk->leaf) { - if (i == blk->n && blk->next) { - blk = blk->next; - i = 0; - } - ngtcp2_ksl_it_init(&it, ksl, blk, i); - return it; - } - - if (i == blk->n) { - /* This happens if descendant has smaller key. Fast forward to - find last node in this subtree. */ - for (; !blk->leaf; blk = ngtcp2_ksl_nth_node(ksl, blk, blk->n - 1)->blk) - ; - if (blk->next) { - blk = blk->next; - i = 0; - } else { - i = blk->n; - } - ngtcp2_ksl_it_init(&it, ksl, blk, i); - return it; - } - blk = ngtcp2_ksl_nth_node(ksl, blk, i)->blk; - } -} - -void ngtcp2_ksl_update_key(ngtcp2_ksl *ksl, const ngtcp2_ksl_key *old_key, - const ngtcp2_ksl_key *new_key) { - ngtcp2_ksl_blk *blk = ksl->head; - ngtcp2_ksl_node *node; - size_t i; - - for (;;) { - i = ksl_bsearch(ksl, blk, old_key, ksl->compar); - - assert(i < blk->n); - node = ngtcp2_ksl_nth_node(ksl, blk, i); - - if (blk->leaf) { - assert(key_equal(ksl->compar, (ngtcp2_ksl_key *)node->key, old_key)); - ksl_node_set_key(ksl, node, new_key); - return; - } - - if (key_equal(ksl->compar, (ngtcp2_ksl_key *)node->key, old_key) || - ksl->compar((ngtcp2_ksl_key *)node->key, new_key)) { - ksl_node_set_key(ksl, node, new_key); - } - - blk = node->blk; - } -} - -static void ksl_print(ngtcp2_ksl *ksl, ngtcp2_ksl_blk *blk, size_t level) { - size_t i; - ngtcp2_ksl_node *node; - - fprintf(stderr, "LV=%zu n=%zu\n", level, blk->n); - - if (blk->leaf) { - for (i = 0; i < blk->n; ++i) { - node = ngtcp2_ksl_nth_node(ksl, blk, i); - fprintf(stderr, " %" PRId64, *(int64_t *)(void *)node->key); - } - fprintf(stderr, "\n"); - return; - } - - for (i = 0; i < blk->n; ++i) { - ksl_print(ksl, ngtcp2_ksl_nth_node(ksl, blk, i)->blk, level + 1); - } -} - -size_t ngtcp2_ksl_len(ngtcp2_ksl *ksl) { return ksl->n; } - -void ngtcp2_ksl_clear(ngtcp2_ksl *ksl) { - size_t i; - ngtcp2_ksl_blk *head; - - if (!ksl->head->leaf) { - for (i = 0; i < ksl->head->n; ++i) { - ksl_free_blk(ksl, ngtcp2_ksl_nth_node(ksl, ksl->head, i)->blk); - } - } - - ksl->front = ksl->back = ksl->head; - ksl->n = 0; - - head = ksl->head; - - head->next = head->prev = NULL; - head->n = 0; - head->leaf = 1; -} - -void ngtcp2_ksl_print(ngtcp2_ksl *ksl) { ksl_print(ksl, ksl->head, 0); } - -ngtcp2_ksl_it ngtcp2_ksl_begin(const ngtcp2_ksl *ksl) { - ngtcp2_ksl_it it; - ngtcp2_ksl_it_init(&it, ksl, ksl->front, 0); - return it; -} - -ngtcp2_ksl_it ngtcp2_ksl_end(const ngtcp2_ksl *ksl) { - ngtcp2_ksl_it it; - ngtcp2_ksl_it_init(&it, ksl, ksl->back, ksl->back->n); - return it; -} - -void ngtcp2_ksl_it_init(ngtcp2_ksl_it *it, const ngtcp2_ksl *ksl, - ngtcp2_ksl_blk *blk, size_t i) { - it->ksl = ksl; - it->blk = blk; - it->i = i; -} - -void *ngtcp2_ksl_it_get(const ngtcp2_ksl_it *it) { - assert(it->i < it->blk->n); - return ngtcp2_ksl_nth_node(it->ksl, it->blk, it->i)->data; -} - -void ngtcp2_ksl_it_prev(ngtcp2_ksl_it *it) { - assert(!ngtcp2_ksl_it_begin(it)); - - if (it->i == 0) { - it->blk = it->blk->prev; - it->i = it->blk->n - 1; - } else { - --it->i; - } -} - -int ngtcp2_ksl_it_begin(const ngtcp2_ksl_it *it) { - return it->i == 0 && it->blk->prev == NULL; -} - -int ngtcp2_ksl_range_compar(const ngtcp2_ksl_key *lhs, - const ngtcp2_ksl_key *rhs) { - const ngtcp2_range *a = lhs, *b = rhs; - return a->begin < b->begin; -} - -int ngtcp2_ksl_range_exclusive_compar(const ngtcp2_ksl_key *lhs, - const ngtcp2_ksl_key *rhs) { - const ngtcp2_range *a = lhs, *b = rhs; - return a->begin < b->begin && - !(ngtcp2_max(a->begin, b->begin) < ngtcp2_min(a->end, b->end)); -} diff --git a/deps/ngtcp2/lib/ngtcp2_ksl.h b/deps/ngtcp2/lib/ngtcp2_ksl.h deleted file mode 100644 index 071e10dce1b40e..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_ksl.h +++ /dev/null @@ -1,333 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_KSL_H -#define NGTCP2_KSL_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include - -/* - * Skip List using single key instead of range. - */ - -#define NGTCP2_KSL_DEGR 16 -/* NGTCP2_KSL_MAX_NBLK is the maximum number of nodes which a single - block can contain. */ -#define NGTCP2_KSL_MAX_NBLK (2 * NGTCP2_KSL_DEGR - 1) -/* NGTCP2_KSL_MIN_NBLK is the minimum number of nodes which a single - block other than root must contains. */ -#define NGTCP2_KSL_MIN_NBLK (NGTCP2_KSL_DEGR - 1) - -/* - * ngtcp2_ksl_key represents key in ngtcp2_ksl. - */ -typedef void ngtcp2_ksl_key; - -struct ngtcp2_ksl_node; -typedef struct ngtcp2_ksl_node ngtcp2_ksl_node; - -struct ngtcp2_ksl_blk; -typedef struct ngtcp2_ksl_blk ngtcp2_ksl_blk; - -/* - * ngtcp2_ksl_node is a node which contains either ngtcp2_ksl_blk or - * opaque data. If a node is an internal node, it contains - * ngtcp2_ksl_blk. Otherwise, it has data. The key is stored at the - * location starting at key. - */ -struct ngtcp2_ksl_node { - union { - ngtcp2_ksl_blk *blk; - void *data; - }; - union { - uint64_t align; - /* key is a buffer to include key associated to this node. - Because the length of key is unknown until ngtcp2_ksl_init is - called, the actual buffer will be allocated after this - field. */ - uint8_t key[1]; - }; -}; - -/* - * ngtcp2_ksl_blk contains ngtcp2_ksl_node objects. - */ -struct ngtcp2_ksl_blk { - /* next points to the next block if leaf field is nonzero. */ - ngtcp2_ksl_blk *next; - /* prev points to the previous block if leaf field is nonzero. */ - ngtcp2_ksl_blk *prev; - /* n is the number of nodes this object contains in nodes. */ - size_t n; - /* leaf is nonzero if this block contains leaf nodes. */ - int leaf; - union { - uint64_t align; - /* nodes is a buffer to contain NGTCP2_KSL_MAX_NBLK - ngtcp2_ksl_node objects. Because ngtcp2_ksl_node object is - allocated along with the additional variable length key - storage, the size of buffer is unknown until ngtcp2_ksl_init is - called. */ - uint8_t nodes[1]; - }; -}; - -/* - * ngtcp2_ksl_compar is a function type which returns nonzero if key - * |lhs| should be placed before |rhs|. It returns 0 otherwise. - */ -typedef int (*ngtcp2_ksl_compar)(const ngtcp2_ksl_key *lhs, - const ngtcp2_ksl_key *rhs); - -struct ngtcp2_ksl; -typedef struct ngtcp2_ksl ngtcp2_ksl; - -struct ngtcp2_ksl_it; -typedef struct ngtcp2_ksl_it ngtcp2_ksl_it; - -/* - * ngtcp2_ksl_it is a forward iterator to iterate nodes. - */ -struct ngtcp2_ksl_it { - const ngtcp2_ksl *ksl; - ngtcp2_ksl_blk *blk; - size_t i; -}; - -/* - * ngtcp2_ksl is a deterministic paged skip list. - */ -struct ngtcp2_ksl { - /* head points to the root block. */ - ngtcp2_ksl_blk *head; - /* front points to the first leaf block. */ - ngtcp2_ksl_blk *front; - /* back points to the last leaf block. */ - ngtcp2_ksl_blk *back; - ngtcp2_ksl_compar compar; - size_t n; - /* keylen is the size of key */ - size_t keylen; - /* nodelen is the actual size of ngtcp2_ksl_node including key - storage. */ - size_t nodelen; - const ngtcp2_mem *mem; -}; - -/* - * ngtcp2_ksl_init initializes |ksl|. |compar| specifies compare - * function. |keylen| is the length of key. - * - * It returns 0 if it succeeds, or one of the following negative error - * codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_ksl_init(ngtcp2_ksl *ksl, ngtcp2_ksl_compar compar, size_t keylen, - const ngtcp2_mem *mem); - -/* - * ngtcp2_ksl_free frees resources allocated for |ksl|. If |ksl| is - * NULL, this function does nothing. It does not free the memory - * region pointed by |ksl| itself. - */ -void ngtcp2_ksl_free(ngtcp2_ksl *ksl); - -/* - * ngtcp2_ksl_insert inserts |key| with its associated |data|. On - * successful insertion, the iterator points to the inserted node is - * stored in |*it|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - * NGTCP2_ERR_INVALID_ARGUMENT - * |key| already exists. - */ -int ngtcp2_ksl_insert(ngtcp2_ksl *ksl, ngtcp2_ksl_it *it, - const ngtcp2_ksl_key *key, void *data); - -/* - * ngtcp2_ksl_remove removes the |key| from |ksl|. - * - * This function assigns the iterator to |*it|, which points to the - * node which is located at the right next of the removed node if |it| - * is not NULL. If |key| is not found, no deletion takes place and - * the return value of ngtcp2_ksl_end(ksl) is assigned to |*it|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_INVALID_ARGUMENT - * |key| does not exist. - */ -int ngtcp2_ksl_remove(ngtcp2_ksl *ksl, ngtcp2_ksl_it *it, - const ngtcp2_ksl_key *key); - -/* - * ngtcp2_ksl_lower_bound returns the iterator which points to the - * first node which has the key which is equal to |key| or the last - * node which satisfies !compar(&node->key, key). If there is no such - * node, it returns the iterator which satisfies ngtcp2_ksl_it_end(it) - * != 0. - */ -ngtcp2_ksl_it ngtcp2_ksl_lower_bound(ngtcp2_ksl *ksl, - const ngtcp2_ksl_key *key); - -/* - * ngtcp2_ksl_lower_bound_compar works like ngtcp2_ksl_lower_bound, - * but it takes custom function |compar| to do lower bound search. - */ -ngtcp2_ksl_it ngtcp2_ksl_lower_bound_compar(ngtcp2_ksl *ksl, - const ngtcp2_ksl_key *key, - ngtcp2_ksl_compar compar); - -/* - * ngtcp2_ksl_update_key replaces the key of nodes which has |old_key| - * with |new_key|. |new_key| must be strictly greater than the - * previous node and strictly smaller than the next node. - */ -void ngtcp2_ksl_update_key(ngtcp2_ksl *ksl, const ngtcp2_ksl_key *old_key, - const ngtcp2_ksl_key *new_key); - -/* - * ngtcp2_ksl_begin returns the iterator which points to the first - * node. If there is no node in |ksl|, it returns the iterator which - * satisfies ngtcp2_ksl_it_end(it) != 0. - */ -ngtcp2_ksl_it ngtcp2_ksl_begin(const ngtcp2_ksl *ksl); - -/* - * ngtcp2_ksl_end returns the iterator which points to the node - * following the last node. The returned object satisfies - * ngtcp2_ksl_it_end(). If there is no node in |ksl|, it returns the - * iterator which satisfies ngtcp2_ksl_it_begin(it) != 0. - */ -ngtcp2_ksl_it ngtcp2_ksl_end(const ngtcp2_ksl *ksl); - -/* - * ngtcp2_ksl_len returns the number of elements stored in |ksl|. - */ -size_t ngtcp2_ksl_len(ngtcp2_ksl *ksl); - -/* - * ngtcp2_ksl_clear removes all elements stored in |ksl|. - */ -void ngtcp2_ksl_clear(ngtcp2_ksl *ksl); - -/* - * ngtcp2_ksl_nth_node returns the |n|th node under |blk|. - */ -#define ngtcp2_ksl_nth_node(KSL, BLK, N) \ - ((ngtcp2_ksl_node *)(void *)((BLK)->nodes + (KSL)->nodelen * (N))) - -/* - * ngtcp2_ksl_print prints its internal state in stderr. It assumes - * that the key is of type int64_t. This function should be used for - * the debugging purpose only. - */ -void ngtcp2_ksl_print(ngtcp2_ksl *ksl); - -/* - * ngtcp2_ksl_it_init initializes |it|. - */ -void ngtcp2_ksl_it_init(ngtcp2_ksl_it *it, const ngtcp2_ksl *ksl, - ngtcp2_ksl_blk *blk, size_t i); - -/* - * ngtcp2_ksl_it_get returns the data associated to the node which - * |it| points to. It is undefined to call this function when - * ngtcp2_ksl_it_end(it) returns nonzero. - */ -void *ngtcp2_ksl_it_get(const ngtcp2_ksl_it *it); - -/* - * ngtcp2_ksl_it_next advances the iterator by one. It is undefined - * if this function is called when ngtcp2_ksl_it_end(it) returns - * nonzero. - */ -#define ngtcp2_ksl_it_next(IT) \ - (++(IT)->i == (IT)->blk->n && (IT)->blk->next \ - ? ((IT)->blk = (IT)->blk->next, (IT)->i = 0) \ - : 0) - -/* - * ngtcp2_ksl_it_prev moves backward the iterator by one. It is - * undefined if this function is called when ngtcp2_ksl_it_begin(it) - * returns nonzero. - */ -void ngtcp2_ksl_it_prev(ngtcp2_ksl_it *it); - -/* - * ngtcp2_ksl_it_end returns nonzero if |it| points to the beyond the - * last node. - */ -#define ngtcp2_ksl_it_end(IT) \ - ((IT)->blk->n == (IT)->i && (IT)->blk->next == NULL) - -/* - * ngtcp2_ksl_it_begin returns nonzero if |it| points to the first - * node. |it| might satisfy both ngtcp2_ksl_it_begin(&it) and - * ngtcp2_ksl_it_end(&it) if the skip list has no node. - */ -int ngtcp2_ksl_it_begin(const ngtcp2_ksl_it *it); - -/* - * ngtcp2_ksl_key returns the key of the node which |it| points to. - * It is undefined to call this function when ngtcp2_ksl_it_end(it) - * returns nonzero. - */ -#define ngtcp2_ksl_it_key(IT) \ - ((ngtcp2_ksl_key *)ngtcp2_ksl_nth_node((IT)->ksl, (IT)->blk, (IT)->i)->key) - -/* - * ngtcp2_ksl_range_compar is an implementation of ngtcp2_ksl_compar. - * lhs->ptr and rhs->ptr must point to ngtcp2_range object and the - * function returns nonzero if (const ngtcp2_range *)(lhs->ptr)->begin - * < (const ngtcp2_range *)(rhs->ptr)->begin. - */ -int ngtcp2_ksl_range_compar(const ngtcp2_ksl_key *lhs, - const ngtcp2_ksl_key *rhs); - -/* - * ngtcp2_ksl_range_exclusive_compar is an implementation of - * ngtcp2_ksl_compar. lhs->ptr and rhs->ptr must point to - * ngtcp2_range object and the function returns nonzero if (const - * ngtcp2_range *)(lhs->ptr)->begin < (const ngtcp2_range - * *)(rhs->ptr)->begin and the 2 ranges do not intersect. - */ -int ngtcp2_ksl_range_exclusive_compar(const ngtcp2_ksl_key *lhs, - const ngtcp2_ksl_key *rhs); - -#endif /* NGTCP2_KSL_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_log.c b/deps/ngtcp2/lib/ngtcp2_log.c deleted file mode 100644 index 8b7ec0def65baf..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_log.c +++ /dev/null @@ -1,747 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_log.h" - -#include -#ifdef HAVE_UNISTD_H -# include -#endif -#include -#include - -#include "ngtcp2_str.h" -#include "ngtcp2_vec.h" -#include "ngtcp2_macro.h" - -void ngtcp2_log_init(ngtcp2_log *log, const ngtcp2_cid *scid, - ngtcp2_printf log_printf, ngtcp2_tstamp ts, - void *user_data) { - if (scid) { - ngtcp2_encode_hex(log->scid, scid->data, scid->datalen); - } else { - log->scid[0] = '\0'; - } - log->log_printf = log_printf; - log->ts = log->last_ts = ts; - log->user_data = user_data; -} - -/* - * # Log header - * - * - * - * : - * Log level. I=Info, W=Warning, E=Error - * - * : - * Timestamp relative to ngtcp2_log.ts field in milliseconds - * resolution. - * - * : - * Source Connection ID in hex string. - * - * : - * Event. pkt=packet, frm=frame, rcv=recovery, cry=crypto, - * con=connection(catch all) - * - * # Frame event - * - * () () - * - * : - * Flow direction. tx=transmission, rx=reception - * - * : - * Packet number. - * - * : - * Packet name. (e.g., Initial, Handshake, S01) - * - * : - * Packet type in hex string. - * - * : - * Frame name. (e.g., STREAM, ACK, PING) - * - * : - * Frame type in hex string. - */ - -#define NGTCP2_LOG_BUFLEN 4096 - -/* TODO Split second and remaining fraction with comma */ -#define NGTCP2_LOG_HD "I%08" PRIu64 " 0x%s %s" -#define NGTCP2_LOG_PKT NGTCP2_LOG_HD " %s %" PRId64 " %s(0x%02x)" -#define NGTCP2_LOG_TP NGTCP2_LOG_HD " remote transport_parameters" - -#define NGTCP2_LOG_FRM_HD_FIELDS(DIR) \ - timestamp_cast(log->last_ts - log->ts), (const char *)log->scid, "frm", \ - (DIR), hd->pkt_num, strpkttype(hd), hd->type - -#define NGTCP2_LOG_PKT_HD_FIELDS(DIR) \ - timestamp_cast(log->last_ts - log->ts), (const char *)log->scid, "pkt", \ - (DIR), hd->pkt_num, strpkttype(hd), hd->type - -#define NGTCP2_LOG_TP_HD_FIELDS \ - timestamp_cast(log->last_ts - log->ts), (const char *)log->scid, "cry" - -static const char *strerrorcode(uint64_t error_code) { - switch (error_code) { - case NGTCP2_NO_ERROR: - return "NO_ERROR"; - case NGTCP2_INTERNAL_ERROR: - return "INTERNAL_ERROR"; - case NGTCP2_CONNECTION_REFUSED: - return "CONNECTION_REFUSED"; - case NGTCP2_FLOW_CONTROL_ERROR: - return "FLOW_CONTROL_ERROR"; - case NGTCP2_STREAM_LIMIT_ERROR: - return "STREAM_LIMIT_ERROR"; - case NGTCP2_STREAM_STATE_ERROR: - return "STREAM_STATE_ERROR"; - case NGTCP2_FINAL_SIZE_ERROR: - return "FINAL_SIZE_ERROR"; - case NGTCP2_FRAME_ENCODING_ERROR: - return "FRAME_ENCODING_ERROR"; - case NGTCP2_TRANSPORT_PARAMETER_ERROR: - return "TRANSPORT_PARAMETER_ERROR"; - case NGTCP2_CONNECTION_ID_LIMIT_ERROR: - return "CONNECTION_ID_LIMIT_ERROR"; - case NGTCP2_PROTOCOL_VIOLATION: - return "PROTOCOL_VIOLATION"; - case NGTCP2_INVALID_TOKEN: - return "INVALID_TOKEN"; - case NGTCP2_APPLICATION_ERROR: - return "APPLICATION_ERROR"; - case NGTCP2_CRYPTO_BUFFER_EXCEEDED: - return "CRYPTO_BUFFER_EXCEEDED"; - case NGTCP2_KEY_UPDATE_ERROR: - return "KEY_UPDATE_ERROR"; - default: - if (0x100u <= error_code && error_code <= 0x1ffu) { - return "CRYPTO_ERROR"; - } - return "(unknown)"; - } -} - -static const char *strapperrorcode(uint64_t app_error_code) { - (void)app_error_code; - return "(unknown)"; -} - -static const char *strpkttype_long(uint8_t type) { - switch (type) { - case NGTCP2_PKT_VERSION_NEGOTIATION: - return "VN"; - case NGTCP2_PKT_INITIAL: - return "Initial"; - case NGTCP2_PKT_RETRY: - return "Retry"; - case NGTCP2_PKT_HANDSHAKE: - return "Handshake"; - case NGTCP2_PKT_0RTT: - return "0RTT"; - default: - return "(unknown)"; - } -} - -static const char *strpkttype(const ngtcp2_pkt_hd *hd) { - if (hd->flags & NGTCP2_PKT_FLAG_LONG_FORM) { - return strpkttype_long(hd->type); - } - return "Short"; -} - -static const char *strevent(ngtcp2_log_event ev) { - switch (ev) { - case NGTCP2_LOG_EVENT_CON: - return "con"; - case NGTCP2_LOG_EVENT_PKT: - return "pkt"; - case NGTCP2_LOG_EVENT_FRM: - return "frm"; - case NGTCP2_LOG_EVENT_RCV: - return "rcv"; - case NGTCP2_LOG_EVENT_CRY: - return "cry"; - case NGTCP2_LOG_EVENT_PTV: - return "ptv"; - case NGTCP2_LOG_EVENT_NONE: - default: - return "non"; - } -} - -static uint64_t timestamp_cast(uint64_t ns) { return ns / NGTCP2_MILLISECONDS; } - -static void log_fr_stream(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_stream *fr, const char *dir) { - log->log_printf(log->user_data, - (NGTCP2_LOG_PKT " STREAM(0x%02x) id=0x%" PRIx64 - " fin=%d offset=%" PRIu64 " len=%zu uni=%d"), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type | fr->flags, - fr->stream_id, fr->fin, fr->offset, - ngtcp2_vec_len(fr->data, fr->datacnt), - (fr->stream_id & 0x2) != 0); -} - -static void log_fr_ack(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_ack *fr, const char *dir) { - int64_t largest_ack, min_ack; - size_t i; - - log->log_printf(log->user_data, - (NGTCP2_LOG_PKT " ACK(0x%02x) largest_ack=%" PRId64 - " ack_delay=%" PRIu64 "(%" PRIu64 - ") ack_block_count=%zu"), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->largest_ack, - fr->ack_delay_unscaled / NGTCP2_MILLISECONDS, fr->ack_delay, - fr->num_blks); - - largest_ack = fr->largest_ack; - min_ack = fr->largest_ack - (int64_t)fr->first_ack_blklen; - - log->log_printf(log->user_data, - (NGTCP2_LOG_PKT " ACK(0x%02x) block=[%" PRId64 "..%" PRId64 - "] block_count=%" PRIu64), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, largest_ack, min_ack, - fr->first_ack_blklen); - - for (i = 0; i < fr->num_blks; ++i) { - const ngtcp2_ack_blk *blk = &fr->blks[i]; - largest_ack = min_ack - (int64_t)blk->gap - 2; - min_ack = largest_ack - (int64_t)blk->blklen; - log->log_printf(log->user_data, - (NGTCP2_LOG_PKT " ACK(0x%02x) block=[%" PRId64 "..%" PRId64 - "] gap=%" PRIu64 " block_count=%" PRIu64), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, largest_ack, - min_ack, blk->gap, blk->blklen); - } -} - -static void log_fr_padding(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_padding *fr, const char *dir) { - log->log_printf(log->user_data, (NGTCP2_LOG_PKT " PADDING(0x%02x) len=%zu"), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->len); -} - -static void log_fr_reset_stream(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_reset_stream *fr, - const char *dir) { - log->log_printf( - log->user_data, - (NGTCP2_LOG_PKT " RESET_STREAM(0x%02x) id=0x%" PRIx64 - " app_error_code=%s(0x%" PRIx64 ") final_size=%" PRIu64), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->stream_id, - strapperrorcode(fr->app_error_code), fr->app_error_code, fr->final_size); -} - -static void log_fr_connection_close(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_connection_close *fr, - const char *dir) { - char reason[256]; - size_t reasonlen = ngtcp2_min(sizeof(reason) - 1, fr->reasonlen); - - log->log_printf(log->user_data, - (NGTCP2_LOG_PKT - " CONNECTION_CLOSE(0x%02x) error_code=%s(0x%" PRIx64 ") " - "frame_type=%" PRIx64 " reason_len=%zu reason=[%s]"), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, - fr->type == NGTCP2_FRAME_CONNECTION_CLOSE - ? strerrorcode(fr->error_code) - : strapperrorcode(fr->error_code), - fr->error_code, fr->frame_type, fr->reasonlen, - ngtcp2_encode_printable_ascii(reason, fr->reason, reasonlen)); -} - -static void log_fr_max_data(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_max_data *fr, const char *dir) { - log->log_printf(log->user_data, - (NGTCP2_LOG_PKT " MAX_DATA(0x%02x) max_data=%" PRIu64), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->max_data); -} - -static void log_fr_max_stream_data(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_max_stream_data *fr, - const char *dir) { - log->log_printf(log->user_data, - (NGTCP2_LOG_PKT " MAX_STREAM_DATA(0x%02x) id=0x%" PRIx64 - " max_stream_data=%" PRIu64), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->stream_id, - fr->max_stream_data); -} - -static void log_fr_max_streams(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_max_streams *fr, const char *dir) { - log->log_printf(log->user_data, - (NGTCP2_LOG_PKT " MAX_STREAMS(0x%02x) max_streams=%" PRIu64), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->max_streams); -} - -static void log_fr_ping(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_ping *fr, const char *dir) { - log->log_printf(log->user_data, (NGTCP2_LOG_PKT " PING(0x%02x)"), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type); -} - -static void log_fr_data_blocked(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_data_blocked *fr, - const char *dir) { - log->log_printf(log->user_data, - (NGTCP2_LOG_PKT " DATA_BLOCKED(0x%02x) offset=%" PRIu64), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->offset); -} - -static void log_fr_stream_data_blocked(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_stream_data_blocked *fr, - const char *dir) { - log->log_printf(log->user_data, - (NGTCP2_LOG_PKT " STREAM_DATA_BLOCKED(0x%02x) id=0x%" PRIx64 - " offset=%" PRIu64), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->stream_id, - fr->offset); -} - -static void log_fr_streams_blocked(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_streams_blocked *fr, - const char *dir) { - log->log_printf( - log->user_data, - (NGTCP2_LOG_PKT " STREAMS_BLOCKED(0x%02x) stream_limit=%" PRIu64), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->stream_limit); -} - -static void log_fr_new_connection_id(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_new_connection_id *fr, - const char *dir) { - uint8_t buf[sizeof(fr->stateless_reset_token) * 2 + 1]; - uint8_t cid[sizeof(fr->cid.data) * 2 + 1]; - - log->log_printf( - log->user_data, - (NGTCP2_LOG_PKT " NEW_CONNECTION_ID(0x%02x) seq=%" PRIu64 - " cid=0x%s retire_prior_to=%" PRIu64 - " stateless_reset_token=0x%s"), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->seq, - (const char *)ngtcp2_encode_hex(cid, fr->cid.data, fr->cid.datalen), - fr->retire_prior_to, - (const char *)ngtcp2_encode_hex(buf, fr->stateless_reset_token, - sizeof(fr->stateless_reset_token))); -} - -static void log_fr_stop_sending(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_stop_sending *fr, - const char *dir) { - log->log_printf(log->user_data, - (NGTCP2_LOG_PKT " STOP_SENDING(0x%02x) id=0x%" PRIx64 - " app_error_code=%s(0x%" PRIx64 ")"), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->stream_id, - strapperrorcode(fr->app_error_code), fr->app_error_code); -} - -static void log_fr_path_challenge(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_path_challenge *fr, - const char *dir) { - uint8_t buf[sizeof(fr->data) * 2 + 1]; - - log->log_printf( - log->user_data, (NGTCP2_LOG_PKT " PATH_CHALLENGE(0x%02x) data=0x%s"), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, - (const char *)ngtcp2_encode_hex(buf, fr->data, sizeof(fr->data))); -} - -static void log_fr_path_response(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_path_response *fr, - const char *dir) { - uint8_t buf[sizeof(fr->data) * 2 + 1]; - - log->log_printf( - log->user_data, (NGTCP2_LOG_PKT " PATH_RESPONSE(0x%02x) data=0x%s"), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, - (const char *)ngtcp2_encode_hex(buf, fr->data, sizeof(fr->data))); -} - -static void log_fr_crypto(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_crypto *fr, const char *dir) { - size_t datalen = 0; - size_t i; - - for (i = 0; i < fr->datacnt; ++i) { - datalen += fr->data[i].len; - } - - log->log_printf( - log->user_data, - (NGTCP2_LOG_PKT " CRYPTO(0x%02x) offset=%" PRIu64 " len=%" PRIu64), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->offset, datalen); -} - -static void log_fr_new_token(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_new_token *fr, const char *dir) { - /* Show at most first 64 bytes of token. If token is longer than 64 - bytes, log first 64 bytes and then append "*" */ - uint8_t buf[128 + 1 + 1]; - uint8_t *p; - - if (fr->token.len > 64) { - p = ngtcp2_encode_hex(buf, fr->token.base, 64); - p[128] = '*'; - p[129] = '\0'; - } else { - p = ngtcp2_encode_hex(buf, fr->token.base, fr->token.len); - } - log->log_printf( - log->user_data, (NGTCP2_LOG_PKT " NEW_TOKEN(0x%02x) token=0x%s len=%zu"), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, (const char *)p, fr->token.len); -} - -static void log_fr_retire_connection_id(ngtcp2_log *log, - const ngtcp2_pkt_hd *hd, - const ngtcp2_retire_connection_id *fr, - const char *dir) { - log->log_printf(log->user_data, - (NGTCP2_LOG_PKT " RETIRE_CONNECTION_ID(0x%02x) seq=%" PRIu64), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type, fr->seq); -} - -static void log_fr_handshake_done(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_handshake_done *fr, - const char *dir) { - log->log_printf(log->user_data, (NGTCP2_LOG_PKT " HANDSHAKE_DONE(0x%02x)"), - NGTCP2_LOG_FRM_HD_FIELDS(dir), fr->type); -} - -static void log_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_frame *fr, const char *dir) { - switch (fr->type) { - case NGTCP2_FRAME_STREAM: - log_fr_stream(log, hd, &fr->stream, dir); - break; - case NGTCP2_FRAME_ACK: - case NGTCP2_FRAME_ACK_ECN: - log_fr_ack(log, hd, &fr->ack, dir); - break; - case NGTCP2_FRAME_PADDING: - log_fr_padding(log, hd, &fr->padding, dir); - break; - case NGTCP2_FRAME_RESET_STREAM: - log_fr_reset_stream(log, hd, &fr->reset_stream, dir); - break; - case NGTCP2_FRAME_CONNECTION_CLOSE: - case NGTCP2_FRAME_CONNECTION_CLOSE_APP: - log_fr_connection_close(log, hd, &fr->connection_close, dir); - break; - case NGTCP2_FRAME_MAX_DATA: - log_fr_max_data(log, hd, &fr->max_data, dir); - break; - case NGTCP2_FRAME_MAX_STREAM_DATA: - log_fr_max_stream_data(log, hd, &fr->max_stream_data, dir); - break; - case NGTCP2_FRAME_MAX_STREAMS_BIDI: - case NGTCP2_FRAME_MAX_STREAMS_UNI: - log_fr_max_streams(log, hd, &fr->max_streams, dir); - break; - case NGTCP2_FRAME_PING: - log_fr_ping(log, hd, &fr->ping, dir); - break; - case NGTCP2_FRAME_DATA_BLOCKED: - log_fr_data_blocked(log, hd, &fr->data_blocked, dir); - break; - case NGTCP2_FRAME_STREAM_DATA_BLOCKED: - log_fr_stream_data_blocked(log, hd, &fr->stream_data_blocked, dir); - break; - case NGTCP2_FRAME_STREAMS_BLOCKED_BIDI: - case NGTCP2_FRAME_STREAMS_BLOCKED_UNI: - log_fr_streams_blocked(log, hd, &fr->streams_blocked, dir); - break; - case NGTCP2_FRAME_NEW_CONNECTION_ID: - log_fr_new_connection_id(log, hd, &fr->new_connection_id, dir); - break; - case NGTCP2_FRAME_STOP_SENDING: - log_fr_stop_sending(log, hd, &fr->stop_sending, dir); - break; - case NGTCP2_FRAME_PATH_CHALLENGE: - log_fr_path_challenge(log, hd, &fr->path_challenge, dir); - break; - case NGTCP2_FRAME_PATH_RESPONSE: - log_fr_path_response(log, hd, &fr->path_response, dir); - break; - case NGTCP2_FRAME_CRYPTO: - log_fr_crypto(log, hd, &fr->crypto, dir); - break; - case NGTCP2_FRAME_NEW_TOKEN: - log_fr_new_token(log, hd, &fr->new_token, dir); - break; - case NGTCP2_FRAME_RETIRE_CONNECTION_ID: - log_fr_retire_connection_id(log, hd, &fr->retire_connection_id, dir); - break; - case NGTCP2_FRAME_HANDSHAKE_DONE: - log_fr_handshake_done(log, hd, &fr->handshake_done, dir); - break; - default: - assert(0); - } -} - -void ngtcp2_log_rx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_frame *fr) { - if (!log->log_printf) { - return; - } - - log_fr(log, hd, fr, "rx"); -} - -void ngtcp2_log_tx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_frame *fr) { - if (!log->log_printf) { - return; - } - - log_fr(log, hd, fr, "tx"); -} - -void ngtcp2_log_rx_vn(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const uint32_t *sv, size_t nsv) { - size_t i; - - if (!log->log_printf) { - return; - } - - for (i = 0; i < nsv; ++i) { - log->log_printf(log->user_data, (NGTCP2_LOG_PKT " v=0x%08x"), - NGTCP2_LOG_PKT_HD_FIELDS("rx"), sv[i]); - } -} - -void ngtcp2_log_rx_sr(ngtcp2_log *log, const ngtcp2_pkt_stateless_reset *sr) { - uint8_t buf[sizeof(sr->stateless_reset_token) * 2 + 1]; - ngtcp2_pkt_hd shd; - ngtcp2_pkt_hd *hd = &shd; - - if (!log->log_printf) { - return; - } - - memset(&shd, 0, sizeof(shd)); - - log->log_printf( - log->user_data, (NGTCP2_LOG_PKT " token=0x%s randlen=%zu"), - NGTCP2_LOG_PKT_HD_FIELDS("rx"), - (const char *)ngtcp2_encode_hex(buf, sr->stateless_reset_token, - sizeof(sr->stateless_reset_token)), - sr->randlen); -} - -void ngtcp2_log_remote_tp(ngtcp2_log *log, uint8_t exttype, - const ngtcp2_transport_params *params) { - uint8_t token[NGTCP2_STATELESS_RESET_TOKENLEN * 2 + 1]; - uint8_t addr[16 * 2 + 1]; - uint8_t cid[NGTCP2_MAX_CIDLEN * 2 + 1]; - - if (!log->log_printf) { - return; - } - - if (exttype == NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS) { - if (params->stateless_reset_token_present) { - log->log_printf(log->user_data, - (NGTCP2_LOG_TP " stateless_reset_token=0x%s"), - NGTCP2_LOG_TP_HD_FIELDS, - (const char *)ngtcp2_encode_hex( - token, params->stateless_reset_token, - sizeof(params->stateless_reset_token))); - } - - if (params->preferred_address_present) { - log->log_printf(log->user_data, - (NGTCP2_LOG_TP " preferred_address.ipv4_addr=0x%s"), - NGTCP2_LOG_TP_HD_FIELDS, - (const char *)ngtcp2_encode_hex( - addr, params->preferred_address.ipv4_addr, - sizeof(params->preferred_address.ipv4_addr))); - log->log_printf( - log->user_data, (NGTCP2_LOG_TP " preferred_address.ipv4_port=%u"), - NGTCP2_LOG_TP_HD_FIELDS, params->preferred_address.ipv4_port); - - log->log_printf(log->user_data, - (NGTCP2_LOG_TP " preferred_address.ipv6_addr=0x%s"), - NGTCP2_LOG_TP_HD_FIELDS, - (const char *)ngtcp2_encode_hex( - addr, params->preferred_address.ipv6_addr, - sizeof(params->preferred_address.ipv6_addr))); - log->log_printf( - log->user_data, (NGTCP2_LOG_TP " preferred_address.ipv6_port=%u"), - NGTCP2_LOG_TP_HD_FIELDS, params->preferred_address.ipv6_port); - - log->log_printf(log->user_data, - (NGTCP2_LOG_TP " preferred_address.cid=0x%s"), - NGTCP2_LOG_TP_HD_FIELDS, - (const char *)ngtcp2_encode_hex( - cid, params->preferred_address.cid.data, - params->preferred_address.cid.datalen)); - log->log_printf( - log->user_data, - (NGTCP2_LOG_TP " preferred_address.stateless_reset_token=0x%s"), - NGTCP2_LOG_TP_HD_FIELDS, - (const char *)ngtcp2_encode_hex( - token, params->preferred_address.stateless_reset_token, - sizeof(params->preferred_address.stateless_reset_token))); - } - - log->log_printf( - log->user_data, - (NGTCP2_LOG_TP " original_destination_connection_id=0x%s"), - NGTCP2_LOG_TP_HD_FIELDS, - (const char *)ngtcp2_encode_hex(cid, params->original_dcid.data, - params->original_dcid.datalen)); - - if (params->retry_scid_present) { - log->log_printf( - log->user_data, (NGTCP2_LOG_TP " retry_source_connection_id=0x%s"), - NGTCP2_LOG_TP_HD_FIELDS, - (const char *)ngtcp2_encode_hex(cid, params->retry_scid.data, - params->retry_scid.datalen)); - } - } - - log->log_printf( - log->user_data, (NGTCP2_LOG_TP " initial_source_connection_id=0x%s"), - NGTCP2_LOG_TP_HD_FIELDS, - (const char *)ngtcp2_encode_hex(cid, params->initial_scid.data, - params->initial_scid.datalen)); - - log->log_printf( - log->user_data, - (NGTCP2_LOG_TP " initial_max_stream_data_bidi_local=%" PRIu64), - NGTCP2_LOG_TP_HD_FIELDS, params->initial_max_stream_data_bidi_local); - log->log_printf( - log->user_data, - (NGTCP2_LOG_TP " initial_max_stream_data_bidi_remote=%" PRIu64), - NGTCP2_LOG_TP_HD_FIELDS, params->initial_max_stream_data_bidi_remote); - log->log_printf(log->user_data, - (NGTCP2_LOG_TP " initial_max_stream_data_uni=%" PRIu64), - NGTCP2_LOG_TP_HD_FIELDS, params->initial_max_stream_data_uni); - log->log_printf(log->user_data, (NGTCP2_LOG_TP " initial_max_data=%" PRIu64), - NGTCP2_LOG_TP_HD_FIELDS, params->initial_max_data); - log->log_printf(log->user_data, - (NGTCP2_LOG_TP " initial_max_bidi_streams=%" PRIu64), - NGTCP2_LOG_TP_HD_FIELDS, params->initial_max_streams_bidi); - log->log_printf(log->user_data, - (NGTCP2_LOG_TP " initial_max_uni_streams=%" PRIu64), - NGTCP2_LOG_TP_HD_FIELDS, params->initial_max_streams_uni); - log->log_printf(log->user_data, (NGTCP2_LOG_TP " max_idle_timeout=%" PRIu64), - NGTCP2_LOG_TP_HD_FIELDS, - params->max_idle_timeout / NGTCP2_MILLISECONDS); - log->log_printf(log->user_data, - (NGTCP2_LOG_TP " max_udp_payload_size=%" PRIu64), - NGTCP2_LOG_TP_HD_FIELDS, params->max_udp_payload_size); - log->log_printf(log->user_data, - (NGTCP2_LOG_TP " ack_delay_exponent=%" PRIu64), - NGTCP2_LOG_TP_HD_FIELDS, params->ack_delay_exponent); - log->log_printf(log->user_data, (NGTCP2_LOG_TP " max_ack_delay=%" PRIu64), - NGTCP2_LOG_TP_HD_FIELDS, - params->max_ack_delay / NGTCP2_MILLISECONDS); - log->log_printf(log->user_data, - (NGTCP2_LOG_TP " active_connection_id_limit=%" PRIu64), - NGTCP2_LOG_TP_HD_FIELDS, params->active_connection_id_limit); - log->log_printf(log->user_data, - (NGTCP2_LOG_TP " disable_active_migration=%d"), - NGTCP2_LOG_TP_HD_FIELDS, params->disable_active_migration); -} - -void ngtcp2_log_pkt_lost(ngtcp2_log *log, int64_t pkt_num, uint8_t type, - uint8_t flags, ngtcp2_tstamp sent_ts) { - if (!log->log_printf) { - return; - } - - ngtcp2_log_info( - log, NGTCP2_LOG_EVENT_RCV, - "pkn=%" PRId64 " lost type=%s(0x%02x) sent_ts=%" PRIu64, pkt_num, - (flags & NGTCP2_PKT_FLAG_LONG_FORM) ? strpkttype_long(type) : "Short", - type, sent_ts); -} - -static void log_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const char *dir) { - uint8_t dcid[sizeof(hd->dcid.data) * 2 + 1]; - uint8_t scid[sizeof(hd->scid.data) * 2 + 1]; - - if (!log->log_printf) { - return; - } - - ngtcp2_log_info( - log, NGTCP2_LOG_EVENT_PKT, - "%s pkn=%" PRId64 " dcid=0x%s scid=0x%s type=%s(0x%02x) len=%zu k=%d", - dir, hd->pkt_num, - (const char *)ngtcp2_encode_hex(dcid, hd->dcid.data, hd->dcid.datalen), - (const char *)ngtcp2_encode_hex(scid, hd->scid.data, hd->scid.datalen), - (hd->flags & NGTCP2_PKT_FLAG_LONG_FORM) ? strpkttype_long(hd->type) - : "Short", - hd->type, hd->len, (hd->flags & NGTCP2_PKT_FLAG_KEY_PHASE) != 0); -} - -void ngtcp2_log_rx_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd) { - log_pkt_hd(log, hd, "rx"); -} - -void ngtcp2_log_tx_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd) { - log_pkt_hd(log, hd, "tx"); -} - -void ngtcp2_log_info(ngtcp2_log *log, ngtcp2_log_event ev, const char *fmt, - ...) { - va_list ap; - int n; - char buf[NGTCP2_LOG_BUFLEN]; - - if (!log->log_printf) { - return; - } - - va_start(ap, fmt); - n = vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - - if (n < 0 || (size_t)n >= sizeof(buf)) { - return; - } - - log->log_printf(log->user_data, (NGTCP2_LOG_HD " %s"), - timestamp_cast(log->last_ts - log->ts), log->scid, - strevent(ev), buf); -} - -void ngtcp2_log_tx_cancel(ngtcp2_log *log, const ngtcp2_pkt_hd *hd) { - ngtcp2_log_info(log, NGTCP2_LOG_EVENT_PKT, - "cancel tx pkn=%" PRId64 " type=%s(0x%02x)", hd->pkt_num, - strpkttype(hd), hd->type); -} diff --git a/deps/ngtcp2/lib/ngtcp2_log.h b/deps/ngtcp2/lib/ngtcp2_log.h deleted file mode 100644 index 985aa84b2711f8..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_log.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_LOG_H -#define NGTCP2_LOG_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_pkt.h" - -struct ngtcp2_log { - /* log_printf is a sink to write log. NULL means no logging - output. */ - ngtcp2_printf log_printf; - /* ts is the time point used to write time delta in the log. */ - ngtcp2_tstamp ts; - /* last_ts is the most recent time point that this object is - told. */ - ngtcp2_tstamp last_ts; - /* user_data is user-defined opaque data which is passed to - log_pritnf. */ - void *user_data; - /* scid is SCID encoded as NULL-terminated hex string. */ - uint8_t scid[NGTCP2_MAX_CIDLEN * 2 + 1]; -}; - -typedef struct ngtcp2_log ngtcp2_log; - -void ngtcp2_log_init(ngtcp2_log *log, const ngtcp2_cid *scid, - ngtcp2_printf log_printf, ngtcp2_tstamp ts, - void *user_data); - -void ngtcp2_log_rx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_frame *fr); -void ngtcp2_log_tx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const ngtcp2_frame *fr); - -void ngtcp2_log_rx_vn(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, - const uint32_t *sv, size_t nsv); - -void ngtcp2_log_rx_sr(ngtcp2_log *log, const ngtcp2_pkt_stateless_reset *sr); - -void ngtcp2_log_remote_tp(ngtcp2_log *log, uint8_t exttype, - const ngtcp2_transport_params *params); - -void ngtcp2_log_pkt_lost(ngtcp2_log *log, int64_t pkt_num, uint8_t type, - uint8_t flags, ngtcp2_tstamp sent_ts); - -void ngtcp2_log_rx_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd); - -void ngtcp2_log_tx_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd); - -void ngtcp2_log_tx_cancel(ngtcp2_log *log, const ngtcp2_pkt_hd *hd); - -#endif /* NGTCP2_LOG_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_macro.h b/deps/ngtcp2/lib/ngtcp2_macro.h deleted file mode 100644 index e2603aae15dd04..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_macro.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_MACRO_H -#define NGTCP2_MACRO_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include - -#define ngtcp2_min(A, B) ((A) < (B) ? (A) : (B)) -#define ngtcp2_max(A, B) ((A) > (B) ? (A) : (B)) - -#define ngtcp2_struct_of(ptr, type, member) \ - ((type *)(void *)((char *)(ptr)-offsetof(type, member))) - -/* ngtcp2_list_insert inserts |T| before |*PD|. The contract is that - this is singly linked list, and the next element is pointed by next - field of the previous element. |PD| must be a pointer to the - pointer to the next field of the previous element of |*PD|: if C is - the previous element of |PD|, PD = &C->next. */ -#define ngtcp2_list_insert(T, PD) \ - do { \ - (T)->next = *(PD); \ - *(PD) = (T); \ - } while (0) - -#endif /* NGTCP2_MACRO_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_map.c b/deps/ngtcp2/lib/ngtcp2_map.c deleted file mode 100644 index 12a20283b4c8e0..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_map.c +++ /dev/null @@ -1,333 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2012 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_map.h" - -#include -#include - -#include "ngtcp2_conv.h" - -#define INITIAL_TABLE_LENGTH 256 - -int ngtcp2_map_init(ngtcp2_map *map, const ngtcp2_mem *mem) { - map->mem = mem; - map->tablelen = INITIAL_TABLE_LENGTH; - map->table = ngtcp2_mem_calloc(mem, map->tablelen, sizeof(ngtcp2_map_bucket)); - if (map->table == NULL) { - return NGTCP2_ERR_NOMEM; - } - - map->size = 0; - - return 0; -} - -void ngtcp2_map_free(ngtcp2_map *map) { - size_t i; - ngtcp2_map_bucket *bkt; - - if (!map) { - return; - } - - for (i = 0; i < map->tablelen; ++i) { - bkt = &map->table[i]; - if (bkt->ksl) { - ngtcp2_ksl_free(bkt->ksl); - ngtcp2_mem_free(map->mem, bkt->ksl); - } - } - - ngtcp2_mem_free(map->mem, map->table); -} - -void ngtcp2_map_each_free(ngtcp2_map *map, - int (*func)(ngtcp2_map_entry *entry, void *ptr), - void *ptr) { - uint32_t i; - ngtcp2_map_bucket *bkt; - ngtcp2_ksl_it it; - - for (i = 0; i < map->tablelen; ++i) { - bkt = &map->table[i]; - - if (bkt->ptr) { - func(bkt->ptr, ptr); - bkt->ptr = NULL; - assert(bkt->ksl == NULL || ngtcp2_ksl_len(bkt->ksl) == 0); - continue; - } - - if (bkt->ksl) { - for (it = ngtcp2_ksl_begin(bkt->ksl); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - func(ngtcp2_ksl_it_get(&it), ptr); - } - - ngtcp2_ksl_free(bkt->ksl); - ngtcp2_mem_free(map->mem, bkt->ksl); - bkt->ksl = NULL; - } - } -} - -int ngtcp2_map_each(ngtcp2_map *map, - int (*func)(ngtcp2_map_entry *entry, void *ptr), - void *ptr) { - int rv; - uint32_t i; - ngtcp2_map_bucket *bkt; - ngtcp2_ksl_it it; - - for (i = 0; i < map->tablelen; ++i) { - bkt = &map->table[i]; - - if (bkt->ptr) { - rv = func(bkt->ptr, ptr); - if (rv != 0) { - return rv; - } - assert(bkt->ksl == NULL || ngtcp2_ksl_len(bkt->ksl) == 0); - continue; - } - - if (bkt->ksl) { - for (it = ngtcp2_ksl_begin(bkt->ksl); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - rv = func(ngtcp2_ksl_it_get(&it), ptr); - if (rv != 0) { - return rv; - } - } - } - } - return 0; -} - -void ngtcp2_map_entry_init(ngtcp2_map_entry *entry, key_type key) { - entry->key = key; - entry->next = NULL; -} - -/* FNV1a hash */ -static uint32_t hash(key_type key, uint32_t mod) { - uint8_t *p, *end; - uint32_t h = 0x811C9DC5u; - - key = ngtcp2_htonl64(key); - p = (uint8_t *)&key; - end = p + sizeof(key_type); - - for (; p != end;) { - h ^= *p++; - h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24); - } - - return h & (mod - 1); -} - -static int less(const ngtcp2_ksl_key *lhs, const ngtcp2_ksl_key *rhs) { - return *(key_type *)lhs < *(key_type *)rhs; -} - -static int map_insert(ngtcp2_map *map, ngtcp2_map_bucket *table, - uint32_t tablelen, ngtcp2_map_entry *entry) { - uint32_t h = hash(entry->key, tablelen); - ngtcp2_map_bucket *bkt = &table[h]; - const ngtcp2_mem *mem = map->mem; - int rv; - - if (bkt->ptr == NULL && (bkt->ksl == NULL || ngtcp2_ksl_len(bkt->ksl) == 0)) { - bkt->ptr = entry; - return 0; - } - - if (!bkt->ksl) { - bkt->ksl = ngtcp2_mem_malloc(mem, sizeof(*bkt->ksl)); - if (bkt->ksl == NULL) { - return NGTCP2_ERR_NOMEM; - } - ngtcp2_ksl_init(bkt->ksl, less, sizeof(key_type), mem); - } - - if (bkt->ptr) { - rv = ngtcp2_ksl_insert(bkt->ksl, NULL, &bkt->ptr->key, bkt->ptr); - if (rv != 0) { - return rv; - } - - bkt->ptr = NULL; - } - - return ngtcp2_ksl_insert(bkt->ksl, NULL, &entry->key, entry); -} - -/* new_tablelen must be power of 2 */ -static int map_resize(ngtcp2_map *map, uint32_t new_tablelen) { - uint32_t i; - ngtcp2_map_bucket *new_table; - ngtcp2_map_bucket *bkt; - ngtcp2_ksl_it it; - int rv; - - new_table = - ngtcp2_mem_calloc(map->mem, new_tablelen, sizeof(ngtcp2_map_bucket)); - if (new_table == NULL) { - return NGTCP2_ERR_NOMEM; - } - - for (i = 0; i < map->tablelen; ++i) { - bkt = &map->table[i]; - - if (bkt->ptr) { - rv = map_insert(map, new_table, new_tablelen, bkt->ptr); - if (rv != 0) { - goto fail; - } - assert(bkt->ksl == NULL || ngtcp2_ksl_len(bkt->ksl) == 0); - continue; - } - - if (bkt->ksl) { - for (it = ngtcp2_ksl_begin(bkt->ksl); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - rv = map_insert(map, new_table, new_tablelen, ngtcp2_ksl_it_get(&it)); - if (rv != 0) { - goto fail; - } - } - } - } - - for (i = 0; i < map->tablelen; ++i) { - bkt = &map->table[i]; - if (bkt->ksl) { - ngtcp2_ksl_free(bkt->ksl); - ngtcp2_mem_free(map->mem, bkt->ksl); - } - } - - ngtcp2_mem_free(map->mem, map->table); - map->tablelen = new_tablelen; - map->table = new_table; - - return 0; - -fail: - for (i = 0; i < new_tablelen; ++i) { - bkt = &new_table[i]; - if (bkt->ksl) { - ngtcp2_ksl_free(bkt->ksl); - ngtcp2_mem_free(map->mem, bkt->ksl); - } - } - - return rv; -} - -int ngtcp2_map_insert(ngtcp2_map *map, ngtcp2_map_entry *new_entry) { - int rv; - - /* Load factor is 0.75 */ - if ((map->size + 1) * 4 > map->tablelen * 3) { - rv = map_resize(map, map->tablelen * 2); - if (rv != 0) { - return rv; - } - } - rv = map_insert(map, map->table, map->tablelen, new_entry); - if (rv != 0) { - return rv; - } - ++map->size; - return 0; -} - -ngtcp2_map_entry *ngtcp2_map_find(ngtcp2_map *map, key_type key) { - ngtcp2_map_bucket *bkt = &map->table[hash(key, map->tablelen)]; - ngtcp2_ksl_it it; - - if (bkt->ptr) { - if (bkt->ptr->key == key) { - return bkt->ptr; - } - return NULL; - } - - if (bkt->ksl) { - it = ngtcp2_ksl_lower_bound(bkt->ksl, &key); - if (ngtcp2_ksl_it_end(&it) || *(key_type *)ngtcp2_ksl_it_key(&it) != key) { - return NULL; - } - return ngtcp2_ksl_it_get(&it); - } - - return NULL; -} - -int ngtcp2_map_remove(ngtcp2_map *map, key_type key) { - ngtcp2_map_bucket *bkt = &map->table[hash(key, map->tablelen)]; - int rv; - - if (bkt->ptr) { - if (bkt->ptr->key == key) { - bkt->ptr = NULL; - --map->size; - return 0; - } - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - if (bkt->ksl) { - rv = ngtcp2_ksl_remove(bkt->ksl, NULL, &key); - if (rv != 0) { - return rv; - } - --map->size; - return 0; - } - - return NGTCP2_ERR_INVALID_ARGUMENT; -} - -void ngtcp2_map_clear(ngtcp2_map *map) { - uint32_t i; - ngtcp2_map_bucket *bkt; - - for (i = 0; i < map->tablelen; ++i) { - bkt = &map->table[i]; - bkt->ptr = NULL; - if (bkt->ksl) { - ngtcp2_ksl_free(bkt->ksl); - ngtcp2_mem_free(map->mem, bkt->ksl); - bkt->ksl = NULL; - } - } - - map->size = 0; -} - -size_t ngtcp2_map_size(ngtcp2_map *map) { return map->size; } diff --git a/deps/ngtcp2/lib/ngtcp2_map.h b/deps/ngtcp2/lib/ngtcp2_map.h deleted file mode 100644 index 20afce24e9adab..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_map.h +++ /dev/null @@ -1,151 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2012 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_MAP_H -#define NGTCP2_MAP_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_mem.h" -#include "ngtcp2_ksl.h" - -/* Implementation of unordered map */ - -typedef uint64_t key_type; - -typedef struct ngtcp2_map_entry { - struct ngtcp2_map_entry *next; - key_type key; -} ngtcp2_map_entry; - -typedef struct ngtcp2_map_bucket { - ngtcp2_map_entry *ptr; - ngtcp2_ksl *ksl; -} ngtcp2_map_bucket; - -typedef struct { - ngtcp2_map_bucket *table; - const ngtcp2_mem *mem; - size_t size; - uint32_t tablelen; -} ngtcp2_map; - -/* - * Initializes the map |map|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -int ngtcp2_map_init(ngtcp2_map *map, const ngtcp2_mem *mem); - -/* - * Deallocates any resources allocated for |map|. The stored entries - * are not freed by this function. Use ngtcp2_map_each_free() to free - * each entries. - */ -void ngtcp2_map_free(ngtcp2_map *map); - -/* - * Deallocates each entries using |func| function and any resources - * allocated for |map|. The |func| function is responsible for freeing - * given the |entry| object. The |ptr| will be passed to the |func| as - * send argument. The return value of the |func| will be ignored. - */ -void ngtcp2_map_each_free(ngtcp2_map *map, - int (*func)(ngtcp2_map_entry *entry, void *ptr), - void *ptr); - -/* - * Initializes the |entry| with the |key|. All entries to be inserted - * to the map must be initialized with this function. - */ -void ngtcp2_map_entry_init(ngtcp2_map_entry *entry, key_type key); - -/* - * Inserts the new |entry| with the key |entry->key| to the map |map|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_INVALID_ARGUMENT - * The item associated by |key| already exists. - * NGTCP2_ERR_NOMEM - * Out of memory - */ -int ngtcp2_map_insert(ngtcp2_map *map, ngtcp2_map_entry *entry); - -/* - * Returns the entry associated by the key |key|. If there is no such - * entry, this function returns NULL. - */ -ngtcp2_map_entry *ngtcp2_map_find(ngtcp2_map *map, key_type key); - -/* - * Removes the entry associated by the key |key| from the |map|. The - * removed entry is not freed by this function. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_INVALID_ARGUMENT - * The entry associated by |key| does not exist. - */ -int ngtcp2_map_remove(ngtcp2_map *map, key_type key); - -/* - * Removes all entries from |map|. - */ -void ngtcp2_map_clear(ngtcp2_map *map); - -/* - * Returns the number of items stored in the map |map|. - */ -size_t ngtcp2_map_size(ngtcp2_map *map); - -/* - * Applies the function |func| to each entry in the |map| with the - * optional user supplied pointer |ptr|. - * - * If the |func| returns 0, this function calls the |func| with the - * next entry. If the |func| returns nonzero, it will not call the - * |func| for further entries and return the return value of the - * |func| immediately. Thus, this function returns 0 if all the - * invocations of the |func| return 0, or nonzero value which the last - * invocation of |func| returns. - * - * Don't use this function to free each entry. Use - * ngtcp2_map_each_free() instead. - */ -int ngtcp2_map_each(ngtcp2_map *map, - int (*func)(ngtcp2_map_entry *entry, void *ptr), void *ptr); - -#endif /* NGTCP2_MAP_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_mem.c b/deps/ngtcp2/lib/ngtcp2_mem.c deleted file mode 100644 index 2c036ad1634b05..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_mem.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2014 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_mem.h" - -static void *default_malloc(size_t size, void *mem_user_data) { - (void)mem_user_data; - - return malloc(size); -} - -static void default_free(void *ptr, void *mem_user_data) { - (void)mem_user_data; - - free(ptr); -} - -static void *default_calloc(size_t nmemb, size_t size, void *mem_user_data) { - (void)mem_user_data; - - return calloc(nmemb, size); -} - -static void *default_realloc(void *ptr, size_t size, void *mem_user_data) { - (void)mem_user_data; - - return realloc(ptr, size); -} - -static const ngtcp2_mem mem_default = {NULL, default_malloc, default_free, - default_calloc, default_realloc}; - -const ngtcp2_mem *ngtcp2_mem_default(void) { return &mem_default; } - -void *ngtcp2_mem_malloc(const ngtcp2_mem *mem, size_t size) { - return mem->malloc(size, mem->mem_user_data); -} - -void ngtcp2_mem_free(const ngtcp2_mem *mem, void *ptr) { - mem->free(ptr, mem->mem_user_data); -} - -void ngtcp2_mem_free2(ngtcp2_free free_func, void *ptr, void *mem_user_data) { - free_func(ptr, mem_user_data); -} - -void *ngtcp2_mem_calloc(const ngtcp2_mem *mem, size_t nmemb, size_t size) { - return mem->calloc(nmemb, size, mem->mem_user_data); -} - -void *ngtcp2_mem_realloc(const ngtcp2_mem *mem, void *ptr, size_t size) { - return mem->realloc(ptr, size, mem->mem_user_data); -} diff --git a/deps/ngtcp2/lib/ngtcp2_mem.h b/deps/ngtcp2/lib/ngtcp2_mem.h deleted file mode 100644 index cdecf8763a5f36..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_mem.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2014 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_MEM_H -#define NGTCP2_MEM_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -/* Convenient wrapper functions to call allocator function in - |mem|. */ -void *ngtcp2_mem_malloc(const ngtcp2_mem *mem, size_t size); -void ngtcp2_mem_free(const ngtcp2_mem *mem, void *ptr); -void ngtcp2_mem_free2(ngtcp2_free free_func, void *ptr, void *mem_user_data); -void *ngtcp2_mem_calloc(const ngtcp2_mem *mem, size_t nmemb, size_t size); -void *ngtcp2_mem_realloc(const ngtcp2_mem *mem, void *ptr, size_t size); - -#endif /* NGTCP2_MEM_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_path.c b/deps/ngtcp2/lib/ngtcp2_path.c deleted file mode 100644 index 3f35f28ef6a394..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_path.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_path.h" - -#include - -#include "ngtcp2_addr.h" - -void ngtcp2_path_init(ngtcp2_path *path, const ngtcp2_addr *local, - const ngtcp2_addr *remote) { - path->local = *local; - path->remote = *remote; -} - -void ngtcp2_path_copy(ngtcp2_path *dest, const ngtcp2_path *src) { - ngtcp2_addr_copy(&dest->local, &src->local); - ngtcp2_addr_copy(&dest->remote, &src->remote); -} - -int ngtcp2_path_eq(const ngtcp2_path *a, const ngtcp2_path *b) { - return ngtcp2_addr_eq(&a->local, &b->local) && - ngtcp2_addr_eq(&a->remote, &b->remote); -} - -void ngtcp2_path_storage_init(ngtcp2_path_storage *ps, - const struct sockaddr *local_addr, - size_t local_addrlen, void *local_user_data, - const struct sockaddr *remote_addr, - size_t remote_addrlen, void *remote_user_data) { - ngtcp2_addr_init(&ps->path.local, (const struct sockaddr *)&ps->local_addrbuf, - 0, local_user_data); - ngtcp2_addr_init(&ps->path.remote, - (const struct sockaddr *)&ps->remote_addrbuf, 0, - remote_user_data); - - ngtcp2_addr_copy_byte(&ps->path.local, local_addr, local_addrlen); - ngtcp2_addr_copy_byte(&ps->path.remote, remote_addr, remote_addrlen); -} - -void ngtcp2_path_storage_init2(ngtcp2_path_storage *ps, - const ngtcp2_path *path) { - ngtcp2_path_storage_init(ps, path->local.addr, path->local.addrlen, - path->local.user_data, path->remote.addr, - path->remote.addrlen, path->remote.user_data); -} - -void ngtcp2_path_storage_zero(ngtcp2_path_storage *ps) { - ngtcp2_addr_init(&ps->path.local, (const struct sockaddr *)&ps->local_addrbuf, - 0, NULL); - ngtcp2_addr_init(&ps->path.remote, - (const struct sockaddr *)&ps->remote_addrbuf, 0, NULL); -} diff --git a/deps/ngtcp2/lib/ngtcp2_path.h b/deps/ngtcp2/lib/ngtcp2_path.h deleted file mode 100644 index 1b2e2f87c8c780..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_path.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_PATH_H -#define NGTCP2_PATH_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -/* - * ngtcp2_path_init initializes |path| with the given addresses. Note - * that the buffer pointed by local->addr and remote->addr are not - * copied. Their pointer values are assigned instead. - */ -void ngtcp2_path_init(ngtcp2_path *path, const ngtcp2_addr *local, - const ngtcp2_addr *remote); - -/* - * ngtcp2_path_copy copies |src| into |dest|. This function assumes - * that |dest| has enough buffer to store the deep copy of src->local - * and src->remote. - */ -void ngtcp2_path_copy(ngtcp2_path *dest, const ngtcp2_path *src); - -/* - * ngtcp2_path_eq returns nonzero if |a| equals |b| such that - * ngtcp2_addr_eq(&a->local, &b->local) && ngtcp2_addr_eq(&a->remote, - * &b->remote) is true. - */ -int ngtcp2_path_eq(const ngtcp2_path *a, const ngtcp2_path *b); - -/* - * ngtcp2_path_storage_init2 initializes |ps| using |path| as initial - * data. - */ -void ngtcp2_path_storage_init2(ngtcp2_path_storage *ps, - const ngtcp2_path *path); - -#endif /* NGTCP2_PATH_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_pkt.c b/deps/ngtcp2/lib/ngtcp2_pkt.c deleted file mode 100644 index 905af29a822602..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_pkt.c +++ /dev/null @@ -1,2271 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_pkt.h" - -#include -#include -#include - -#include "ngtcp2_conv.h" -#include "ngtcp2_str.h" -#include "ngtcp2_macro.h" -#include "ngtcp2_cid.h" -#include "ngtcp2_mem.h" - -int ngtcp2_pkt_chain_new(ngtcp2_pkt_chain **ppc, const ngtcp2_path *path, - const uint8_t *pkt, size_t pktlen, ngtcp2_tstamp ts, - const ngtcp2_mem *mem) { - *ppc = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_pkt_chain) + pktlen); - if (*ppc == NULL) { - return NGTCP2_ERR_NOMEM; - } - - ngtcp2_path_storage_init2(&(*ppc)->path, path); - (*ppc)->next = NULL; - (*ppc)->pkt = (uint8_t *)(*ppc) + sizeof(ngtcp2_pkt_chain); - (*ppc)->pktlen = pktlen; - (*ppc)->ts = ts; - - memcpy((*ppc)->pkt, pkt, pktlen); - - return 0; -} - -void ngtcp2_pkt_chain_del(ngtcp2_pkt_chain *pc, const ngtcp2_mem *mem) { - ngtcp2_mem_free(mem, pc); -} - -int ngtcp2_pkt_decode_version_cid(uint32_t *pversion, const uint8_t **pdcid, - size_t *pdcidlen, const uint8_t **pscid, - size_t *pscidlen, const uint8_t *data, - size_t datalen, size_t short_dcidlen) { - size_t len; - uint32_t version; - size_t dcidlen, scidlen; - - assert(datalen); - - if (data[0] & NGTCP2_HEADER_FORM_BIT) { - /* 1 byte (Header Form, Fixed Bit, Long Packet Type, Type-Specific bits) - * 4 bytes Version - * 1 byte DCID Length - * 1 byte SCID Length - */ - len = 1 + 4 + 1 + 1; - if (datalen < len) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - dcidlen = data[5]; - len += dcidlen; - if (datalen < len) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - scidlen = data[5 + 1 + dcidlen]; - len += scidlen; - if (datalen < len) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - version = ngtcp2_get_uint32(&data[1]); - - if ((version == 0 || version == NGTCP2_PROTO_VER) && - (dcidlen > NGTCP2_MAX_CIDLEN || scidlen > NGTCP2_MAX_CIDLEN)) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - *pversion = version; - *pdcid = &data[6]; - *pdcidlen = dcidlen; - *pscid = &data[6 + dcidlen + 1]; - *pscidlen = scidlen; - - if (version && version != NGTCP2_PROTO_VER) { - return 1; - } - return 0; - } - - assert(short_dcidlen <= NGTCP2_MAX_CIDLEN); - - len = 1 + short_dcidlen; - if (datalen < len) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - *pversion = NGTCP2_PROTO_VER; - *pdcid = &data[1]; - *pdcidlen = short_dcidlen; - *pscid = NULL; - *pscidlen = 0; - - return 0; -} - -void ngtcp2_pkt_hd_init(ngtcp2_pkt_hd *hd, uint8_t flags, uint8_t type, - const ngtcp2_cid *dcid, const ngtcp2_cid *scid, - int64_t pkt_num, size_t pkt_numlen, uint32_t version, - size_t len) { - hd->flags = flags; - hd->type = type; - if (dcid) { - hd->dcid = *dcid; - } else { - ngtcp2_cid_zero(&hd->dcid); - } - if (scid) { - hd->scid = *scid; - } else { - ngtcp2_cid_zero(&hd->scid); - } - hd->pkt_num = pkt_num; - hd->token.base = NULL; - hd->token.len = 0; - hd->pkt_numlen = pkt_numlen; - hd->version = version; - hd->len = len; -} - -static int has_mask(uint8_t b, uint8_t mask) { return (b & mask) == mask; } - -ngtcp2_ssize ngtcp2_pkt_decode_hd_long(ngtcp2_pkt_hd *dest, const uint8_t *pkt, - size_t pktlen) { - uint8_t type; - uint32_t version; - size_t dcil, scil; - const uint8_t *p; - size_t len = 0; - size_t n; - size_t ntokenlen = 0; - const uint8_t *token = NULL; - size_t tokenlen = 0; - uint64_t vi; - - if (pktlen < 5) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - if (!(pkt[0] & NGTCP2_HEADER_FORM_BIT)) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - version = ngtcp2_get_uint32(&pkt[1]); - - if (version == 0) { - type = NGTCP2_PKT_VERSION_NEGOTIATION; - /* This must be Version Negotiation packet which lacks packet - number and payload length fields. */ - len = 5 + 2; - } else { - if (!(pkt[0] & NGTCP2_FIXED_BIT_MASK)) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - type = ngtcp2_pkt_get_type_long(pkt[0]); - switch (type) { - case NGTCP2_PKT_INITIAL: - len = 1 /* Token Length */ + NGTCP2_MIN_LONG_HEADERLEN - - 1; /* Cut packet number field */ - break; - case NGTCP2_PKT_RETRY: - /* Retry packet does not have packet number and length fields */ - len = 5 + 2; - break; - case NGTCP2_PKT_HANDSHAKE: - case NGTCP2_PKT_0RTT: - len = NGTCP2_MIN_LONG_HEADERLEN - 1; /* Cut packet number field */ - break; - default: - /* Unreachable */ - assert(0); - } - } - - if (pktlen < len) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - p = &pkt[5]; - dcil = *p; - if (dcil > NGTCP2_MAX_CIDLEN) { - /* QUIC v1 implementation never expect to receive CID length more - than NGTCP2_MAX_CIDLEN. */ - return NGTCP2_ERR_INVALID_ARGUMENT; - } - len += dcil; - - if (pktlen < len) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - p += 1 + dcil; - scil = *p; - if (scil > NGTCP2_MAX_CIDLEN) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - len += scil; - - if (pktlen < len) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - p += 1 + scil; - - if (type == NGTCP2_PKT_INITIAL) { - /* Token Length */ - ntokenlen = ngtcp2_get_varint_len(p); - len += ntokenlen - 1; - - if (pktlen < len) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - vi = ngtcp2_get_varint(&ntokenlen, p); - if (pktlen - len < vi) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - tokenlen = (size_t)vi; - len += tokenlen; - - p += ntokenlen; - - if (tokenlen) { - token = p; - } - - p += tokenlen; - } - - switch (type) { - case NGTCP2_PKT_VERSION_NEGOTIATION: - case NGTCP2_PKT_RETRY: - break; - default: - /* Length */ - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (pktlen < len) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - } - - dest->flags = NGTCP2_PKT_FLAG_LONG_FORM; - dest->type = type; - dest->version = version; - dest->pkt_num = 0; - dest->pkt_numlen = 0; - - p = &pkt[6]; - ngtcp2_cid_init(&dest->dcid, p, dcil); - p += dcil + 1; - ngtcp2_cid_init(&dest->scid, p, scil); - p += scil; - - dest->token.base = (uint8_t *)token; - dest->token.len = tokenlen; - p += ntokenlen + tokenlen; - - switch (type) { - case NGTCP2_PKT_VERSION_NEGOTIATION: - case NGTCP2_PKT_RETRY: - dest->len = 0; - break; - default: - vi = ngtcp2_get_varint(&n, p); - if (vi > SIZE_MAX) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - dest->len = (size_t)vi; - p += n; - } - - assert((size_t)(p - pkt) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_hd_short(ngtcp2_pkt_hd *dest, const uint8_t *pkt, - size_t pktlen, size_t dcidlen) { - size_t len = 1 + dcidlen; - const uint8_t *p = pkt; - - assert(dcidlen <= NGTCP2_MAX_CIDLEN); - - if (pktlen < len) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - if ((pkt[0] & NGTCP2_HEADER_FORM_BIT) || - (pkt[0] & NGTCP2_FIXED_BIT_MASK) == 0) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - p = &pkt[1]; - - dest->type = NGTCP2_PKT_SHORT; - - ngtcp2_cid_init(&dest->dcid, p, dcidlen); - p += dcidlen; - - /* Set 0 to SCID so that we don't accidentally reference it and gets - garbage. */ - ngtcp2_cid_zero(&dest->scid); - - dest->flags = NGTCP2_PKT_FLAG_NONE; - dest->version = 0; - dest->len = 0; - dest->pkt_num = 0; - dest->pkt_numlen = 0; - - assert((size_t)(p - pkt) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_encode_hd_long(uint8_t *out, size_t outlen, - const ngtcp2_pkt_hd *hd) { - uint8_t *p; - size_t len = NGTCP2_MIN_LONG_HEADERLEN + hd->dcid.datalen + hd->scid.datalen - - 2; /* NGTCP2_MIN_LONG_HEADERLEN includes 1 byte for - len and 1 byte for packet number. */ - - if (hd->type != NGTCP2_PKT_RETRY) { - len += 2 /* Length */ + hd->pkt_numlen; - } - - if (hd->type == NGTCP2_PKT_INITIAL) { - len += ngtcp2_put_varint_len(hd->token.len) + hd->token.len; - } - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_HEADER_FORM_BIT | NGTCP2_FIXED_BIT_MASK | - (uint8_t)(hd->type << 4) | (uint8_t)(hd->pkt_numlen - 1); - p = ngtcp2_put_uint32be(p, hd->version); - *p++ = (uint8_t)hd->dcid.datalen; - if (hd->dcid.datalen) { - p = ngtcp2_cpymem(p, hd->dcid.data, hd->dcid.datalen); - } - *p++ = (uint8_t)hd->scid.datalen; - if (hd->scid.datalen) { - p = ngtcp2_cpymem(p, hd->scid.data, hd->scid.datalen); - } - - if (hd->type == NGTCP2_PKT_INITIAL) { - p = ngtcp2_put_varint(p, hd->token.len); - if (hd->token.len) { - p = ngtcp2_cpymem(p, hd->token.base, hd->token.len); - } - } - - if (hd->type != NGTCP2_PKT_RETRY) { - p = ngtcp2_put_varint14(p, (uint16_t)hd->len); - p = ngtcp2_put_pkt_num(p, hd->pkt_num, hd->pkt_numlen); - } - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_encode_hd_short(uint8_t *out, size_t outlen, - const ngtcp2_pkt_hd *hd) { - uint8_t *p; - size_t len = 1 + hd->dcid.datalen + hd->pkt_numlen; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p = NGTCP2_FIXED_BIT_MASK | (uint8_t)(hd->pkt_numlen - 1); - if (hd->flags & NGTCP2_PKT_FLAG_KEY_PHASE) { - *p |= NGTCP2_SHORT_KEY_PHASE_BIT; - } - - ++p; - - if (hd->dcid.datalen) { - p = ngtcp2_cpymem(p, hd->dcid.data, hd->dcid.datalen); - } - - p = ngtcp2_put_pkt_num(p, hd->pkt_num, hd->pkt_numlen); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_frame(ngtcp2_frame *dest, const uint8_t *payload, - size_t payloadlen) { - uint8_t type; - - if (payloadlen == 0) { - return 0; - } - - type = payload[0]; - - switch (type) { - case NGTCP2_FRAME_PADDING: - return (ngtcp2_ssize)ngtcp2_pkt_decode_padding_frame(&dest->padding, - payload, payloadlen); - case NGTCP2_FRAME_RESET_STREAM: - return ngtcp2_pkt_decode_reset_stream_frame(&dest->reset_stream, payload, - payloadlen); - case NGTCP2_FRAME_CONNECTION_CLOSE: - case NGTCP2_FRAME_CONNECTION_CLOSE_APP: - return ngtcp2_pkt_decode_connection_close_frame(&dest->connection_close, - payload, payloadlen); - case NGTCP2_FRAME_MAX_DATA: - return ngtcp2_pkt_decode_max_data_frame(&dest->max_data, payload, - payloadlen); - case NGTCP2_FRAME_MAX_STREAM_DATA: - return ngtcp2_pkt_decode_max_stream_data_frame(&dest->max_stream_data, - payload, payloadlen); - case NGTCP2_FRAME_MAX_STREAMS_BIDI: - case NGTCP2_FRAME_MAX_STREAMS_UNI: - return ngtcp2_pkt_decode_max_streams_frame(&dest->max_streams, payload, - payloadlen); - case NGTCP2_FRAME_PING: - return ngtcp2_pkt_decode_ping_frame(&dest->ping, payload, payloadlen); - case NGTCP2_FRAME_DATA_BLOCKED: - return ngtcp2_pkt_decode_data_blocked_frame(&dest->data_blocked, payload, - payloadlen); - case NGTCP2_FRAME_STREAM_DATA_BLOCKED: - return ngtcp2_pkt_decode_stream_data_blocked_frame( - &dest->stream_data_blocked, payload, payloadlen); - case NGTCP2_FRAME_STREAMS_BLOCKED_BIDI: - case NGTCP2_FRAME_STREAMS_BLOCKED_UNI: - return ngtcp2_pkt_decode_streams_blocked_frame(&dest->streams_blocked, - payload, payloadlen); - case NGTCP2_FRAME_NEW_CONNECTION_ID: - return ngtcp2_pkt_decode_new_connection_id_frame(&dest->new_connection_id, - payload, payloadlen); - case NGTCP2_FRAME_STOP_SENDING: - return ngtcp2_pkt_decode_stop_sending_frame(&dest->stop_sending, payload, - payloadlen); - case NGTCP2_FRAME_ACK: - case NGTCP2_FRAME_ACK_ECN: - return ngtcp2_pkt_decode_ack_frame(&dest->ack, payload, payloadlen); - case NGTCP2_FRAME_PATH_CHALLENGE: - return ngtcp2_pkt_decode_path_challenge_frame(&dest->path_challenge, - payload, payloadlen); - case NGTCP2_FRAME_PATH_RESPONSE: - return ngtcp2_pkt_decode_path_response_frame(&dest->path_response, payload, - payloadlen); - case NGTCP2_FRAME_CRYPTO: - return ngtcp2_pkt_decode_crypto_frame(&dest->crypto, payload, payloadlen); - case NGTCP2_FRAME_NEW_TOKEN: - return ngtcp2_pkt_decode_new_token_frame(&dest->new_token, payload, - payloadlen); - case NGTCP2_FRAME_RETIRE_CONNECTION_ID: - return ngtcp2_pkt_decode_retire_connection_id_frame( - &dest->retire_connection_id, payload, payloadlen); - case NGTCP2_FRAME_HANDSHAKE_DONE: - return ngtcp2_pkt_decode_handshake_done_frame(&dest->handshake_done, - payload, payloadlen); - default: - if (has_mask(type, NGTCP2_FRAME_STREAM)) { - return ngtcp2_pkt_decode_stream_frame(&dest->stream, payload, payloadlen); - } - return NGTCP2_ERR_FRAME_ENCODING; - } -} - -ngtcp2_ssize ngtcp2_pkt_decode_stream_frame(ngtcp2_stream *dest, - const uint8_t *payload, - size_t payloadlen) { - uint8_t type; - size_t len = 1 + 1; - const uint8_t *p; - size_t datalen; - size_t ndatalen = 0; - size_t n; - uint64_t vi; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - type = payload[0]; - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - - if (type & NGTCP2_STREAM_OFF_BIT) { - ++len; - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - } - - if (type & NGTCP2_STREAM_LEN_BIT) { - ++len; - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - ndatalen = ngtcp2_get_varint_len(p); - len += ndatalen - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - vi = ngtcp2_get_varint(&ndatalen, p); - if (payloadlen - len < vi) { - return NGTCP2_ERR_FRAME_ENCODING; - } - datalen = (size_t)vi; - len += datalen; - } else { - len = payloadlen; - } - - p = payload + 1; - - dest->type = NGTCP2_FRAME_STREAM; - dest->flags = (uint8_t)(type & ~NGTCP2_FRAME_STREAM); - dest->fin = (type & NGTCP2_STREAM_FIN_BIT) != 0; - dest->stream_id = (int64_t)ngtcp2_get_varint(&n, p); - p += n; - - if (type & NGTCP2_STREAM_OFF_BIT) { - dest->offset = ngtcp2_get_varint(&n, p); - p += n; - } else { - dest->offset = 0; - } - - if (type & NGTCP2_STREAM_LEN_BIT) { - p += ndatalen; - } else { - datalen = payloadlen - (size_t)(p - payload); - } - - if (datalen) { - dest->data[0].len = datalen; - dest->data[0].base = (uint8_t *)p; - dest->datacnt = 1; - p += datalen; - } else { - dest->datacnt = 0; - } - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_ack_frame(ngtcp2_ack *dest, - const uint8_t *payload, - size_t payloadlen) { - size_t num_blks, max_num_blks; - size_t nnum_blks; - size_t len = 1 + 1 + 1 + 1 + 1; - const uint8_t *p; - size_t i, j; - ngtcp2_ack_blk *blk; - size_t n; - uint8_t type; - uint64_t vi; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - type = payload[0]; - - p = payload + 1; - - /* Largest Acknowledged */ - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - - /* ACK Delay */ - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - - /* ACK Block Count */ - nnum_blks = ngtcp2_get_varint_len(p); - len += nnum_blks - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - vi = ngtcp2_get_varint(&nnum_blks, p); - if (vi > SIZE_MAX / (1 + 1) || payloadlen - len < vi * (1 + 1)) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - num_blks = (size_t)vi; - len += num_blks * (1 + 1); - - p += nnum_blks; - - /* First ACK Block */ - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - - for (i = 0; i < num_blks; ++i) { - /* Gap, and Additional ACK Block */ - for (j = 0; j < 2; ++j) { - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - } - } - - if (type == NGTCP2_FRAME_ACK_ECN) { - len += 3; - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - for (i = 0; i < 3; ++i) { - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - } - } - - /* TODO We might not decode all blocks. It could be very large. */ - max_num_blks = ngtcp2_min(NGTCP2_MAX_ACK_BLKS, num_blks); - - p = payload + 1; - - dest->type = type; - dest->largest_ack = (int64_t)ngtcp2_get_varint(&n, p); - p += n; - dest->ack_delay = ngtcp2_get_varint(&n, p); - /* This value will be assigned in the upper layer. */ - dest->ack_delay_unscaled = 0; - p += n; - dest->num_blks = max_num_blks; - p += nnum_blks; - dest->first_ack_blklen = ngtcp2_get_varint(&n, p); - p += n; - - for (i = 0; i < max_num_blks; ++i) { - blk = &dest->blks[i]; - blk->gap = ngtcp2_get_varint(&n, p); - p += n; - blk->blklen = ngtcp2_get_varint(&n, p); - p += n; - } - for (i = max_num_blks; i < num_blks; ++i) { - p += ngtcp2_get_varint_len(p); - p += ngtcp2_get_varint_len(p); - } - - if (type == NGTCP2_FRAME_ACK_ECN) { - /* Just parse ECN section for now */ - for (i = 0; i < 3; ++i) { - ngtcp2_get_varint(&n, p); - p += n; - } - } - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -size_t ngtcp2_pkt_decode_padding_frame(ngtcp2_padding *dest, - const uint8_t *payload, - size_t payloadlen) { - const uint8_t *p, *ep; - - assert(payloadlen > 0); - - p = payload + 1; - ep = payload + payloadlen; - - for (; p != ep && *p == NGTCP2_FRAME_PADDING; ++p) - ; - - dest->type = NGTCP2_FRAME_PADDING; - dest->len = (size_t)(p - payload); - - return dest->len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_reset_stream_frame(ngtcp2_reset_stream *dest, - const uint8_t *payload, - size_t payloadlen) { - size_t len = 1 + 1 + 1 + 1; - const uint8_t *p; - size_t n; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - p += n; - n = ngtcp2_get_varint_len(p); - len += n - 1; - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - p += n; - n = ngtcp2_get_varint_len(p); - len += n - 1; - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - dest->type = NGTCP2_FRAME_RESET_STREAM; - dest->stream_id = (int64_t)ngtcp2_get_varint(&n, p); - p += n; - dest->app_error_code = ngtcp2_get_varint(&n, p); - p += n; - dest->final_size = ngtcp2_get_varint(&n, p); - p += n; - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_connection_close_frame( - ngtcp2_connection_close *dest, const uint8_t *payload, size_t payloadlen) { - size_t len = 1 + 1 + 1; - const uint8_t *p; - size_t reasonlen; - size_t nreasonlen; - size_t n; - uint8_t type; - uint64_t vi; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - type = payload[0]; - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - - if (type == NGTCP2_FRAME_CONNECTION_CLOSE) { - ++len; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - } - - nreasonlen = ngtcp2_get_varint_len(p); - len += nreasonlen - 1; - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - vi = ngtcp2_get_varint(&nreasonlen, p); - if (payloadlen - len < vi) { - return NGTCP2_ERR_FRAME_ENCODING; - } - reasonlen = (size_t)vi; - len += reasonlen; - - p = payload + 1; - - dest->type = type; - dest->error_code = ngtcp2_get_varint(&n, p); - p += n; - if (type == NGTCP2_FRAME_CONNECTION_CLOSE) { - dest->frame_type = ngtcp2_get_varint(&n, p); - p += n; - } else { - dest->frame_type = 0; - } - dest->reasonlen = reasonlen; - p += nreasonlen; - if (reasonlen == 0) { - dest->reason = NULL; - } else { - dest->reason = (uint8_t *)p; - p += reasonlen; - } - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_max_data_frame(ngtcp2_max_data *dest, - const uint8_t *payload, - size_t payloadlen) { - size_t len = 1 + 1; - const uint8_t *p; - size_t n; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - dest->type = NGTCP2_FRAME_MAX_DATA; - dest->max_data = ngtcp2_get_varint(&n, p); - p += n; - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_max_stream_data_frame( - ngtcp2_max_stream_data *dest, const uint8_t *payload, size_t payloadlen) { - size_t len = 1 + 1 + 1; - const uint8_t *p; - size_t n; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - dest->type = NGTCP2_FRAME_MAX_STREAM_DATA; - dest->stream_id = (int64_t)ngtcp2_get_varint(&n, p); - p += n; - dest->max_stream_data = ngtcp2_get_varint(&n, p); - p += n; - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_max_streams_frame(ngtcp2_max_streams *dest, - const uint8_t *payload, - size_t payloadlen) { - size_t len = 1 + 1; - const uint8_t *p; - size_t n; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - dest->type = payload[0]; - dest->max_streams = ngtcp2_get_varint(&n, p); - p += n; - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_ping_frame(ngtcp2_ping *dest, - const uint8_t *payload, - size_t payloadlen) { - (void)payload; - (void)payloadlen; - - dest->type = NGTCP2_FRAME_PING; - return 1; -} - -ngtcp2_ssize ngtcp2_pkt_decode_data_blocked_frame(ngtcp2_data_blocked *dest, - const uint8_t *payload, - size_t payloadlen) { - size_t len = 1 + 1; - const uint8_t *p; - size_t n; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - dest->type = NGTCP2_FRAME_DATA_BLOCKED; - dest->offset = ngtcp2_get_varint(&n, p); - p += n; - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize -ngtcp2_pkt_decode_stream_data_blocked_frame(ngtcp2_stream_data_blocked *dest, - const uint8_t *payload, - size_t payloadlen) { - size_t len = 1 + 1 + 1; - const uint8_t *p; - size_t n; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - dest->type = NGTCP2_FRAME_STREAM_DATA_BLOCKED; - dest->stream_id = (int64_t)ngtcp2_get_varint(&n, p); - p += n; - dest->offset = ngtcp2_get_varint(&n, p); - p += n; - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_streams_blocked_frame( - ngtcp2_streams_blocked *dest, const uint8_t *payload, size_t payloadlen) { - size_t len = 1 + 1; - const uint8_t *p; - size_t n; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - dest->type = payload[0]; - dest->stream_limit = ngtcp2_get_varint(&n, p); - p += n; - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_new_connection_id_frame( - ngtcp2_new_connection_id *dest, const uint8_t *payload, size_t payloadlen) { - size_t len = 1 + 1 + 1 + 1 + 16; - const uint8_t *p; - size_t n; - size_t cil; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - - cil = *p; - if (cil < NGTCP2_MIN_CIDLEN || cil > NGTCP2_MAX_CIDLEN) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - len += cil; - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - dest->type = NGTCP2_FRAME_NEW_CONNECTION_ID; - dest->seq = ngtcp2_get_varint(&n, p); - p += n; - dest->retire_prior_to = ngtcp2_get_varint(&n, p); - p += n + 1; - ngtcp2_cid_init(&dest->cid, p, cil); - p += cil; - memcpy(dest->stateless_reset_token, p, NGTCP2_STATELESS_RESET_TOKENLEN); - p += NGTCP2_STATELESS_RESET_TOKENLEN; - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_stop_sending_frame(ngtcp2_stop_sending *dest, - const uint8_t *payload, - size_t payloadlen) { - size_t len = 1 + 1 + 1; - const uint8_t *p; - size_t n; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - p += n; - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - dest->type = NGTCP2_FRAME_STOP_SENDING; - dest->stream_id = (int64_t)ngtcp2_get_varint(&n, p); - p += n; - dest->app_error_code = ngtcp2_get_varint(&n, p); - p += n; - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_path_challenge_frame(ngtcp2_path_challenge *dest, - const uint8_t *payload, - size_t payloadlen) { - size_t len = 1 + 8; - const uint8_t *p; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - dest->type = NGTCP2_FRAME_PATH_CHALLENGE; - ngtcp2_cpymem(dest->data, p, sizeof(dest->data)); - p += sizeof(dest->data); - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_path_response_frame(ngtcp2_path_response *dest, - const uint8_t *payload, - size_t payloadlen) { - size_t len = 1 + 8; - const uint8_t *p; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - dest->type = NGTCP2_FRAME_PATH_RESPONSE; - ngtcp2_cpymem(dest->data, p, sizeof(dest->data)); - p += sizeof(dest->data); - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_crypto_frame(ngtcp2_crypto *dest, - const uint8_t *payload, - size_t payloadlen) { - size_t len = 1 + 1 + 1; - const uint8_t *p; - size_t datalen; - size_t ndatalen; - size_t n; - uint64_t vi; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p += n; - - ndatalen = ngtcp2_get_varint_len(p); - len += ndatalen - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - vi = ngtcp2_get_varint(&ndatalen, p); - if (payloadlen - len < vi) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - datalen = (size_t)vi; - len += datalen; - - p = payload + 1; - - dest->type = NGTCP2_FRAME_CRYPTO; - dest->offset = ngtcp2_get_varint(&n, p); - p += n; - dest->data[0].len = datalen; - p += ndatalen; - if (dest->data[0].len) { - dest->data[0].base = (uint8_t *)p; - p += dest->data[0].len; - dest->datacnt = 1; - } else { - dest->data[0].base = NULL; - dest->datacnt = 0; - } - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_new_token_frame(ngtcp2_new_token *dest, - const uint8_t *payload, - size_t payloadlen) { - size_t len = 1 + 1; - const uint8_t *p; - size_t n; - size_t datalen; - uint64_t vi; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - vi = ngtcp2_get_varint(&n, p); - if (payloadlen - len < vi) { - return NGTCP2_ERR_FRAME_ENCODING; - } - datalen = (size_t)vi; - len += datalen; - - dest->type = NGTCP2_FRAME_NEW_TOKEN; - dest->token.len = datalen; - p += n; - dest->token.base = (uint8_t *)p; - p += dest->token.len; - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize -ngtcp2_pkt_decode_retire_connection_id_frame(ngtcp2_retire_connection_id *dest, - const uint8_t *payload, - size_t payloadlen) { - size_t len = 1 + 1; - const uint8_t *p; - size_t n; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - p = payload + 1; - - n = ngtcp2_get_varint_len(p); - len += n - 1; - - if (payloadlen < len) { - return NGTCP2_ERR_FRAME_ENCODING; - } - - dest->type = NGTCP2_FRAME_RETIRE_CONNECTION_ID; - dest->seq = ngtcp2_get_varint(&n, p); - p += n; - - assert((size_t)(p - payload) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_decode_handshake_done_frame(ngtcp2_handshake_done *dest, - const uint8_t *payload, - size_t payloadlen) { - (void)payload; - (void)payloadlen; - - dest->type = NGTCP2_FRAME_HANDSHAKE_DONE; - return 1; -} - -ngtcp2_ssize ngtcp2_pkt_encode_frame(uint8_t *out, size_t outlen, - ngtcp2_frame *fr) { - switch (fr->type) { - case NGTCP2_FRAME_STREAM: - return ngtcp2_pkt_encode_stream_frame(out, outlen, &fr->stream); - case NGTCP2_FRAME_ACK: - return ngtcp2_pkt_encode_ack_frame(out, outlen, &fr->ack); - case NGTCP2_FRAME_PADDING: - return ngtcp2_pkt_encode_padding_frame(out, outlen, &fr->padding); - case NGTCP2_FRAME_RESET_STREAM: - return ngtcp2_pkt_encode_reset_stream_frame(out, outlen, &fr->reset_stream); - case NGTCP2_FRAME_CONNECTION_CLOSE: - case NGTCP2_FRAME_CONNECTION_CLOSE_APP: - return ngtcp2_pkt_encode_connection_close_frame(out, outlen, - &fr->connection_close); - case NGTCP2_FRAME_MAX_DATA: - return ngtcp2_pkt_encode_max_data_frame(out, outlen, &fr->max_data); - case NGTCP2_FRAME_MAX_STREAM_DATA: - return ngtcp2_pkt_encode_max_stream_data_frame(out, outlen, - &fr->max_stream_data); - case NGTCP2_FRAME_MAX_STREAMS_BIDI: - case NGTCP2_FRAME_MAX_STREAMS_UNI: - return ngtcp2_pkt_encode_max_streams_frame(out, outlen, &fr->max_streams); - case NGTCP2_FRAME_PING: - return ngtcp2_pkt_encode_ping_frame(out, outlen, &fr->ping); - case NGTCP2_FRAME_DATA_BLOCKED: - return ngtcp2_pkt_encode_data_blocked_frame(out, outlen, &fr->data_blocked); - case NGTCP2_FRAME_STREAM_DATA_BLOCKED: - return ngtcp2_pkt_encode_stream_data_blocked_frame( - out, outlen, &fr->stream_data_blocked); - case NGTCP2_FRAME_STREAMS_BLOCKED_BIDI: - case NGTCP2_FRAME_STREAMS_BLOCKED_UNI: - return ngtcp2_pkt_encode_streams_blocked_frame(out, outlen, - &fr->streams_blocked); - case NGTCP2_FRAME_NEW_CONNECTION_ID: - return ngtcp2_pkt_encode_new_connection_id_frame(out, outlen, - &fr->new_connection_id); - case NGTCP2_FRAME_STOP_SENDING: - return ngtcp2_pkt_encode_stop_sending_frame(out, outlen, &fr->stop_sending); - case NGTCP2_FRAME_PATH_CHALLENGE: - return ngtcp2_pkt_encode_path_challenge_frame(out, outlen, - &fr->path_challenge); - case NGTCP2_FRAME_PATH_RESPONSE: - return ngtcp2_pkt_encode_path_response_frame(out, outlen, - &fr->path_response); - case NGTCP2_FRAME_CRYPTO: - return ngtcp2_pkt_encode_crypto_frame(out, outlen, &fr->crypto); - case NGTCP2_FRAME_NEW_TOKEN: - return ngtcp2_pkt_encode_new_token_frame(out, outlen, &fr->new_token); - case NGTCP2_FRAME_RETIRE_CONNECTION_ID: - return ngtcp2_pkt_encode_retire_connection_id_frame( - out, outlen, &fr->retire_connection_id); - case NGTCP2_FRAME_HANDSHAKE_DONE: - return ngtcp2_pkt_encode_handshake_done_frame(out, outlen, - &fr->handshake_done); - default: - return NGTCP2_ERR_INVALID_ARGUMENT; - } -} - -ngtcp2_ssize ngtcp2_pkt_encode_stream_frame(uint8_t *out, size_t outlen, - ngtcp2_stream *fr) { - size_t len = 1; - uint8_t flags = NGTCP2_STREAM_LEN_BIT; - uint8_t *p; - size_t i; - size_t datalen = 0; - - if (fr->fin) { - flags |= NGTCP2_STREAM_FIN_BIT; - } - - if (fr->offset) { - flags |= NGTCP2_STREAM_OFF_BIT; - len += ngtcp2_put_varint_len(fr->offset); - } - - len += ngtcp2_put_varint_len((uint64_t)fr->stream_id); - - for (i = 0; i < fr->datacnt; ++i) { - datalen += fr->data[i].len; - } - - len += ngtcp2_put_varint_len(datalen); - len += datalen; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = flags | NGTCP2_FRAME_STREAM; - - fr->flags = flags; - - p = ngtcp2_put_varint(p, (uint64_t)fr->stream_id); - - if (fr->offset) { - p = ngtcp2_put_varint(p, fr->offset); - } - - p = ngtcp2_put_varint(p, datalen); - - for (i = 0; i < fr->datacnt; ++i) { - assert(fr->data[i].len); - assert(fr->data[i].base); - p = ngtcp2_cpymem(p, fr->data[i].base, fr->data[i].len); - } - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_encode_ack_frame(uint8_t *out, size_t outlen, - ngtcp2_ack *fr) { - size_t len = 1 + ngtcp2_put_varint_len((uint64_t)fr->largest_ack) + - ngtcp2_put_varint_len(fr->ack_delay) + - ngtcp2_put_varint_len(fr->num_blks) + - ngtcp2_put_varint_len(fr->first_ack_blklen); - uint8_t *p; - size_t i; - const ngtcp2_ack_blk *blk; - - for (i = 0; i < fr->num_blks; ++i) { - blk = &fr->blks[i]; - len += ngtcp2_put_varint_len(blk->gap); - len += ngtcp2_put_varint_len(blk->blklen); - } - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_FRAME_ACK; - p = ngtcp2_put_varint(p, (uint64_t)fr->largest_ack); - p = ngtcp2_put_varint(p, fr->ack_delay); - p = ngtcp2_put_varint(p, fr->num_blks); - p = ngtcp2_put_varint(p, fr->first_ack_blklen); - - for (i = 0; i < fr->num_blks; ++i) { - blk = &fr->blks[i]; - p = ngtcp2_put_varint(p, blk->gap); - p = ngtcp2_put_varint(p, blk->blklen); - } - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_encode_padding_frame(uint8_t *out, size_t outlen, - const ngtcp2_padding *fr) { - if (outlen < fr->len) { - return NGTCP2_ERR_NOBUF; - } - - memset(out, 0, fr->len); - - return (ngtcp2_ssize)fr->len; -} - -ngtcp2_ssize -ngtcp2_pkt_encode_reset_stream_frame(uint8_t *out, size_t outlen, - const ngtcp2_reset_stream *fr) { - size_t len = 1 + ngtcp2_put_varint_len((uint64_t)fr->stream_id) + - ngtcp2_put_varint_len(fr->app_error_code) + - ngtcp2_put_varint_len(fr->final_size); - uint8_t *p; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_FRAME_RESET_STREAM; - p = ngtcp2_put_varint(p, (uint64_t)fr->stream_id); - p = ngtcp2_put_varint(p, fr->app_error_code); - p = ngtcp2_put_varint(p, fr->final_size); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize -ngtcp2_pkt_encode_connection_close_frame(uint8_t *out, size_t outlen, - const ngtcp2_connection_close *fr) { - size_t len = 1 + ngtcp2_put_varint_len(fr->error_code) + - (fr->type == NGTCP2_FRAME_CONNECTION_CLOSE - ? ngtcp2_put_varint_len(fr->frame_type) - : 0) + - ngtcp2_put_varint_len(fr->reasonlen) + fr->reasonlen; - uint8_t *p; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = fr->type; - p = ngtcp2_put_varint(p, fr->error_code); - if (fr->type == NGTCP2_FRAME_CONNECTION_CLOSE) { - p = ngtcp2_put_varint(p, fr->frame_type); - } - p = ngtcp2_put_varint(p, fr->reasonlen); - if (fr->reasonlen) { - p = ngtcp2_cpymem(p, fr->reason, fr->reasonlen); - } - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_encode_max_data_frame(uint8_t *out, size_t outlen, - const ngtcp2_max_data *fr) { - size_t len = 1 + ngtcp2_put_varint_len(fr->max_data); - uint8_t *p; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_FRAME_MAX_DATA; - p = ngtcp2_put_varint(p, fr->max_data); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize -ngtcp2_pkt_encode_max_stream_data_frame(uint8_t *out, size_t outlen, - const ngtcp2_max_stream_data *fr) { - size_t len = 1 + ngtcp2_put_varint_len((uint64_t)fr->stream_id) + - ngtcp2_put_varint_len(fr->max_stream_data); - uint8_t *p; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_FRAME_MAX_STREAM_DATA; - p = ngtcp2_put_varint(p, (uint64_t)fr->stream_id); - p = ngtcp2_put_varint(p, fr->max_stream_data); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_encode_max_streams_frame(uint8_t *out, size_t outlen, - const ngtcp2_max_streams *fr) { - size_t len = 1 + ngtcp2_put_varint_len(fr->max_streams); - uint8_t *p; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = fr->type; - p = ngtcp2_put_varint(p, fr->max_streams); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_encode_ping_frame(uint8_t *out, size_t outlen, - const ngtcp2_ping *fr) { - (void)fr; - - if (outlen < 1) { - return NGTCP2_ERR_NOBUF; - } - - *out++ = NGTCP2_FRAME_PING; - - return 1; -} - -ngtcp2_ssize -ngtcp2_pkt_encode_data_blocked_frame(uint8_t *out, size_t outlen, - const ngtcp2_data_blocked *fr) { - size_t len = 1 + ngtcp2_put_varint_len(fr->offset); - uint8_t *p; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_FRAME_DATA_BLOCKED; - p = ngtcp2_put_varint(p, fr->offset); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_encode_stream_data_blocked_frame( - uint8_t *out, size_t outlen, const ngtcp2_stream_data_blocked *fr) { - size_t len = 1 + ngtcp2_put_varint_len((uint64_t)fr->stream_id) + - ngtcp2_put_varint_len(fr->offset); - uint8_t *p; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_FRAME_STREAM_DATA_BLOCKED; - p = ngtcp2_put_varint(p, (uint64_t)fr->stream_id); - p = ngtcp2_put_varint(p, fr->offset); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize -ngtcp2_pkt_encode_streams_blocked_frame(uint8_t *out, size_t outlen, - const ngtcp2_streams_blocked *fr) { - size_t len = 1 + ngtcp2_put_varint_len(fr->stream_limit); - uint8_t *p; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = fr->type; - p = ngtcp2_put_varint(p, fr->stream_limit); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize -ngtcp2_pkt_encode_new_connection_id_frame(uint8_t *out, size_t outlen, - const ngtcp2_new_connection_id *fr) { - size_t len = 1 + ngtcp2_put_varint_len(fr->seq) + - ngtcp2_put_varint_len(fr->retire_prior_to) + 1 + - fr->cid.datalen + NGTCP2_STATELESS_RESET_TOKENLEN; - uint8_t *p; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_FRAME_NEW_CONNECTION_ID; - p = ngtcp2_put_varint(p, fr->seq); - p = ngtcp2_put_varint(p, fr->retire_prior_to); - *p++ = (uint8_t)fr->cid.datalen; - p = ngtcp2_cpymem(p, fr->cid.data, fr->cid.datalen); - p = ngtcp2_cpymem(p, fr->stateless_reset_token, - NGTCP2_STATELESS_RESET_TOKENLEN); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize -ngtcp2_pkt_encode_stop_sending_frame(uint8_t *out, size_t outlen, - const ngtcp2_stop_sending *fr) { - size_t len = 1 + ngtcp2_put_varint_len((uint64_t)fr->stream_id) + - ngtcp2_put_varint_len(fr->app_error_code); - uint8_t *p; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_FRAME_STOP_SENDING; - p = ngtcp2_put_varint(p, (uint64_t)fr->stream_id); - p = ngtcp2_put_varint(p, fr->app_error_code); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize -ngtcp2_pkt_encode_path_challenge_frame(uint8_t *out, size_t outlen, - const ngtcp2_path_challenge *fr) { - size_t len = 1 + 8; - uint8_t *p; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_FRAME_PATH_CHALLENGE; - p = ngtcp2_cpymem(p, fr->data, sizeof(fr->data)); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize -ngtcp2_pkt_encode_path_response_frame(uint8_t *out, size_t outlen, - const ngtcp2_path_response *fr) { - size_t len = 1 + 8; - uint8_t *p; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_FRAME_PATH_RESPONSE; - p = ngtcp2_cpymem(p, fr->data, sizeof(fr->data)); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_encode_crypto_frame(uint8_t *out, size_t outlen, - const ngtcp2_crypto *fr) { - size_t len = 1; - uint8_t *p; - size_t i; - size_t datalen = 0; - - len += ngtcp2_put_varint_len(fr->offset); - - for (i = 0; i < fr->datacnt; ++i) { - datalen += fr->data[i].len; - } - - len += ngtcp2_put_varint_len(datalen); - len += datalen; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_FRAME_CRYPTO; - - p = ngtcp2_put_varint(p, fr->offset); - p = ngtcp2_put_varint(p, datalen); - - for (i = 0; i < fr->datacnt; ++i) { - assert(fr->data[i].base); - p = ngtcp2_cpymem(p, fr->data[i].base, fr->data[i].len); - } - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_encode_new_token_frame(uint8_t *out, size_t outlen, - const ngtcp2_new_token *fr) { - size_t len = 1 + ngtcp2_put_varint_len(fr->token.len) + fr->token.len; - uint8_t *p; - - assert(fr->token.len); - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_FRAME_NEW_TOKEN; - - p = ngtcp2_put_varint(p, fr->token.len); - p = ngtcp2_cpymem(p, fr->token.base, fr->token.len); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize ngtcp2_pkt_encode_retire_connection_id_frame( - uint8_t *out, size_t outlen, const ngtcp2_retire_connection_id *fr) { - size_t len = 1 + ngtcp2_put_varint_len(fr->seq); - uint8_t *p; - - if (outlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = out; - - *p++ = NGTCP2_FRAME_RETIRE_CONNECTION_ID; - - p = ngtcp2_put_varint(p, fr->seq); - - assert((size_t)(p - out) == len); - - return (ngtcp2_ssize)len; -} - -ngtcp2_ssize -ngtcp2_pkt_encode_handshake_done_frame(uint8_t *out, size_t outlen, - const ngtcp2_handshake_done *fr) { - (void)fr; - - if (outlen < 1) { - return NGTCP2_ERR_NOBUF; - } - - *out++ = NGTCP2_FRAME_HANDSHAKE_DONE; - - return 1; -} - -ngtcp2_ssize ngtcp2_pkt_write_version_negotiation( - uint8_t *dest, size_t destlen, uint8_t unused_random, const uint8_t *dcid, - size_t dcidlen, const uint8_t *scid, size_t scidlen, const uint32_t *sv, - size_t nsv) { - size_t len = 1 + 4 + 1 + dcidlen + 1 + scidlen + nsv * 4; - uint8_t *p; - size_t i; - - assert(dcidlen < 256); - assert(scidlen < 256); - - if (destlen < len) { - return NGTCP2_ERR_NOBUF; - } - - p = dest; - - *p++ = 0x80 | unused_random; - p = ngtcp2_put_uint32be(p, 0); - *p++ = (uint8_t)dcidlen; - if (dcidlen) { - p = ngtcp2_cpymem(p, dcid, dcidlen); - } - *p++ = (uint8_t)scidlen; - if (scidlen) { - p = ngtcp2_cpymem(p, scid, scidlen); - } - - for (i = 0; i < nsv; ++i) { - p = ngtcp2_put_uint32be(p, sv[i]); - } - - assert((size_t)(p - dest) == len); - - return (ngtcp2_ssize)len; -} - -size_t ngtcp2_pkt_decode_version_negotiation(uint32_t *dest, - const uint8_t *payload, - size_t payloadlen) { - const uint8_t *end = payload + payloadlen; - - assert((payloadlen % sizeof(uint32_t)) == 0); - - for (; payload != end; payload += sizeof(uint32_t)) { - *dest++ = ngtcp2_get_uint32(payload); - } - - return payloadlen / sizeof(uint32_t); -} - -int ngtcp2_pkt_decode_stateless_reset(ngtcp2_pkt_stateless_reset *sr, - const uint8_t *payload, - size_t payloadlen) { - const uint8_t *p = payload; - - if (payloadlen < - NGTCP2_MIN_STATELESS_RESET_RANDLEN + NGTCP2_STATELESS_RESET_TOKENLEN) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - sr->rand = p; - sr->randlen = payloadlen - NGTCP2_STATELESS_RESET_TOKENLEN; - p += sr->randlen; - memcpy(sr->stateless_reset_token, p, NGTCP2_STATELESS_RESET_TOKENLEN); - - return 0; -} - -int ngtcp2_pkt_decode_retry(ngtcp2_pkt_retry *dest, const uint8_t *payload, - size_t payloadlen) { - size_t len = /* token */ 1 + NGTCP2_RETRY_TAGLEN; - - if (payloadlen < len) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - dest->token.base = (uint8_t *)payload; - dest->token.len = (size_t)(payloadlen - NGTCP2_RETRY_TAGLEN); - ngtcp2_cpymem(dest->tag, payload + dest->token.len, NGTCP2_RETRY_TAGLEN); - - return 0; -} - -int64_t ngtcp2_pkt_adjust_pkt_num(int64_t max_pkt_num, int64_t pkt_num, - size_t n) { - int64_t expected = max_pkt_num + 1; - int64_t win = (int64_t)1 << n; - int64_t hwin = win / 2; - int64_t mask = win - 1; - int64_t cand = (expected & ~mask) | pkt_num; - - if (cand <= expected - hwin) { - assert(cand <= (int64_t)NGTCP2_MAX_VARINT - win); - return cand + win; - } - if (cand > expected + hwin && cand >= win) { - return cand - win; - } - return cand; -} - -int ngtcp2_pkt_validate_ack(ngtcp2_ack *fr) { - int64_t largest_ack = fr->largest_ack; - size_t i; - - if (largest_ack < (int64_t)fr->first_ack_blklen) { - return NGTCP2_ERR_ACK_FRAME; - } - - largest_ack -= (int64_t)fr->first_ack_blklen; - - for (i = 0; i < fr->num_blks; ++i) { - if (largest_ack < (int64_t)fr->blks[i].gap + 2) { - return NGTCP2_ERR_ACK_FRAME; - } - - largest_ack -= (int64_t)fr->blks[i].gap + 2; - - if (largest_ack < (int64_t)fr->blks[i].blklen) { - return NGTCP2_ERR_ACK_FRAME; - } - - largest_ack -= (int64_t)fr->blks[i].blklen; - } - - return 0; -} - -ngtcp2_ssize -ngtcp2_pkt_write_stateless_reset(uint8_t *dest, size_t destlen, - const uint8_t *stateless_reset_token, - const uint8_t *rand, size_t randlen) { - uint8_t *p; - - if (destlen < - NGTCP2_MIN_STATELESS_RESET_RANDLEN + NGTCP2_STATELESS_RESET_TOKENLEN) { - return NGTCP2_ERR_NOBUF; - } - - if (randlen < NGTCP2_MIN_STATELESS_RESET_RANDLEN) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - p = dest; - - randlen = ngtcp2_min(destlen - NGTCP2_STATELESS_RESET_TOKENLEN, randlen); - - p = ngtcp2_cpymem(p, rand, randlen); - p = ngtcp2_cpymem(p, stateless_reset_token, NGTCP2_STATELESS_RESET_TOKENLEN); - *dest = (uint8_t)((*dest & 0x7fu) | 0x40u); - - return p - dest; -} - -ngtcp2_ssize -ngtcp2_pkt_write_retry(uint8_t *dest, size_t destlen, const ngtcp2_cid *dcid, - const ngtcp2_cid *scid, const ngtcp2_cid *odcid, - const uint8_t *token, size_t tokenlen, - ngtcp2_encrypt encrypt, const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx) { - ngtcp2_pkt_hd hd; - uint8_t pseudo_retry[1500]; - ngtcp2_ssize pseudo_retrylen; - uint8_t tag[NGTCP2_RETRY_TAGLEN]; - int rv; - uint8_t *p; - size_t offset; - - assert(tokenlen > 0); - assert(!ngtcp2_cid_eq(scid, odcid)); - - /* Retry packet is sent at most once per one connection attempt. In - the first connection attempt, client has to send random DCID - which is at least 8 bytes long. */ - if (odcid->datalen < 8) { - return NGTCP2_ERR_INVALID_ARGUMENT; - } - - ngtcp2_pkt_hd_init(&hd, NGTCP2_PKT_FLAG_LONG_FORM, NGTCP2_PKT_RETRY, dcid, - scid, /* pkt_num = */ 0, /* pkt_numlen = */ 1, - NGTCP2_PROTO_VER, /* len = */ 0); - - pseudo_retrylen = - ngtcp2_pkt_encode_pseudo_retry(pseudo_retry, sizeof(pseudo_retry), &hd, - /* unused = */ 0, odcid, token, tokenlen); - if (pseudo_retrylen < 0) { - return pseudo_retrylen; - } - - /* OpenSSL does not like NULL plaintext. */ - rv = encrypt(tag, aead, aead_ctx, (const uint8_t *)"", 0, - (const uint8_t *)NGTCP2_RETRY_NONCE, - sizeof(NGTCP2_RETRY_NONCE) - 1, pseudo_retry, - (size_t)pseudo_retrylen); - if (rv != 0) { - return rv; - } - - offset = 1 + odcid->datalen; - if (destlen < (size_t)pseudo_retrylen + sizeof(tag) - offset) { - return NGTCP2_ERR_NOBUF; - } - - p = ngtcp2_cpymem(dest, pseudo_retry + offset, - (size_t)pseudo_retrylen - offset); - p = ngtcp2_cpymem(p, tag, sizeof(tag)); - - return p - dest; -} - -ngtcp2_ssize ngtcp2_pkt_encode_pseudo_retry( - uint8_t *dest, size_t destlen, const ngtcp2_pkt_hd *hd, uint8_t unused, - const ngtcp2_cid *odcid, const uint8_t *token, size_t tokenlen) { - uint8_t *p = dest; - ngtcp2_ssize nwrite; - - if (destlen < 1 + odcid->datalen) { - return NGTCP2_ERR_NOBUF; - } - - *p++ = (uint8_t)odcid->datalen; - p = ngtcp2_cpymem(p, odcid->data, odcid->datalen); - destlen -= (size_t)(p - dest); - - nwrite = ngtcp2_pkt_encode_hd_long(p, destlen, hd); - if (nwrite < 0) { - return nwrite; - } - - if (destlen < (size_t)nwrite + tokenlen) { - return NGTCP2_ERR_NOBUF; - } - - *p &= 0xf0; - *p |= unused; - - p += nwrite; - - p = ngtcp2_cpymem(p, token, tokenlen); - - return p - dest; -} - -int ngtcp2_pkt_verify_retry_tag(const ngtcp2_pkt_retry *retry, - const uint8_t *pkt, size_t pktlen, - ngtcp2_encrypt encrypt, - const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx) { - uint8_t pseudo_retry[1500]; - size_t pseudo_retrylen; - uint8_t *p = pseudo_retry; - int rv; - uint8_t tag[NGTCP2_RETRY_TAGLEN]; - - assert(pktlen >= sizeof(retry->tag)); - - if (sizeof(pseudo_retry) < - 1 + retry->odcid.datalen + pktlen - sizeof(retry->tag)) { - return NGTCP2_ERR_PROTO; - } - - *p++ = (uint8_t)retry->odcid.datalen; - p = ngtcp2_cpymem(p, retry->odcid.data, retry->odcid.datalen); - p = ngtcp2_cpymem(p, pkt, pktlen - sizeof(retry->tag)); - - pseudo_retrylen = (size_t)(p - pseudo_retry); - - /* OpenSSL does not like NULL plaintext. */ - rv = encrypt(tag, aead, aead_ctx, (const uint8_t *)"", 0, - (const uint8_t *)NGTCP2_RETRY_NONCE, - sizeof(NGTCP2_RETRY_NONCE) - 1, pseudo_retry, pseudo_retrylen); - if (rv != 0) { - return rv; - } - - if (0 != memcmp(retry->tag, tag, sizeof(retry->tag))) { - return NGTCP2_ERR_PROTO; - } - - return 0; -} - -size_t ngtcp2_pkt_stream_max_datalen(int64_t stream_id, uint64_t offset, - size_t len, size_t left) { - size_t n = 1 /* type */ + ngtcp2_put_varint_len((uint64_t)stream_id) + - (offset ? ngtcp2_put_varint_len(offset) : 0); - - if (left <= n) { - return (size_t)-1; - } - - left -= n; - - if (left > 8 + 1073741823 && len > 1073741823) { -#if SIZE_MAX > UINT32_MAX - len = ngtcp2_min(len, 4611686018427387903lu); -#endif /* SIZE_MAX > UINT32_MAX */ - return ngtcp2_min(len, left - 8); - } - - if (left > 4 + 16383 && len > 16383) { - len = ngtcp2_min(len, 1073741823); - return ngtcp2_min(len, left - 4); - } - - if (left > 2 + 63 && len > 63) { - len = ngtcp2_min(len, 16383); - return ngtcp2_min(len, left - 2); - } - - len = ngtcp2_min(len, 63); - return ngtcp2_min(len, left - 1); -} - -size_t ngtcp2_pkt_crypto_max_datalen(uint64_t offset, size_t len, size_t left) { - size_t n = 1 /* type */ + ngtcp2_put_varint_len(offset); - - /* CRYPTO frame must contain nonzero length data. Return -1 if - there is no space to write crypto data. */ - if (left <= n + 1) { - return (size_t)-1; - } - - left -= n; - - if (left > 8 + 1073741823 && len > 1073741823) { -#if SIZE_MAX > UINT32_MAX - len = ngtcp2_min(len, 4611686018427387903lu); -#endif /* SIZE_MAX > UINT32_MAX */ - return ngtcp2_min(len, left - 8); - } - - if (left > 4 + 16383 && len > 16383) { - len = ngtcp2_min(len, 1073741823); - return ngtcp2_min(len, left - 4); - } - - if (left > 2 + 63 && len > 63) { - len = ngtcp2_min(len, 16383); - return ngtcp2_min(len, left - 2); - } - - len = ngtcp2_min(len, 63); - return ngtcp2_min(len, left - 1); -} - -uint8_t ngtcp2_pkt_get_type_long(uint8_t c) { - return (uint8_t)((c & NGTCP2_LONG_TYPE_MASK) >> 4); -} - -int ngtcp2_pkt_verify_reserved_bits(uint8_t c) { - if (c & NGTCP2_HEADER_FORM_BIT) { - return (c & NGTCP2_LONG_RESERVED_BIT_MASK) == 0 ? 0 : NGTCP2_ERR_PROTO; - } - return (c & NGTCP2_SHORT_RESERVED_BIT_MASK) == 0 ? 0 : NGTCP2_ERR_PROTO; -} diff --git a/deps/ngtcp2/lib/ngtcp2_pkt.h b/deps/ngtcp2/lib/ngtcp2_pkt.h deleted file mode 100644 index 7348cb9a9d01d5..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_pkt.h +++ /dev/null @@ -1,1126 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_PKT_H -#define NGTCP2_PKT_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -/* QUIC header macros */ -#define NGTCP2_HEADER_FORM_BIT 0x80 -#define NGTCP2_FIXED_BIT_MASK 0x40 -#define NGTCP2_PKT_NUMLEN_MASK 0x03 - -/* Long header specific macros */ -#define NGTCP2_LONG_TYPE_MASK 0x30 -#define NGTCP2_LONG_RESERVED_BIT_MASK 0x0c - -/* Short header specific macros */ -#define NGTCP2_SHORT_SPIN_BIT_MASK 0x20 -#define NGTCP2_SHORT_RESERVED_BIT_MASK 0x18 -#define NGTCP2_SHORT_KEY_PHASE_BIT 0x04 - -/* NGTCP2_SR_TYPE is a Type field of Stateless Reset. */ -#define NGTCP2_SR_TYPE 0x1f - -/* NGTCP2_MIN_LONG_HEADERLEN is the minimum length of long header. - That is (1|1|TT|RR|PP)<1> + VERSION<4> + DCIL<1> + SCIL<1> + - LENGTH<1> + PKN<1> */ -#define NGTCP2_MIN_LONG_HEADERLEN (1 + 4 + 1 + 1 + 1 + 1) - -#define NGTCP2_STREAM_FIN_BIT 0x01 -#define NGTCP2_STREAM_LEN_BIT 0x02 -#define NGTCP2_STREAM_OFF_BIT 0x04 - -/* NGTCP2_STREAM_OVERHEAD is the maximum number of bytes required - other than payload for STREAM frame. That is from type field to - the beginning of the payload. */ -#define NGTCP2_STREAM_OVERHEAD (1 + 8 + 8 + 8) - -/* NGTCP2_CRYPTO_OVERHEAD is the maximum number of bytes required - other than payload for CRYPTO frame. That is from type field to - the beginning of the payload. */ -#define NGTCP2_CRYPTO_OVERHEAD (1 + 8 + 8) - -/* NGTCP2_MIN_FRAME_PAYLOADLEN is the minimum frame payload length. */ -#define NGTCP2_MIN_FRAME_PAYLOADLEN 16 - -/* NGTCP2_MAX_VARINT is the maximum value which can be encoded in - variable-length integer encoding */ -#define NGTCP2_MAX_VARINT ((1ULL << 62) - 1) - -/* NGTCP2_MAX_SERVER_STREAM_ID_BIDI is the maximum bidirectional - server stream ID. */ -#define NGTCP2_MAX_SERVER_STREAM_ID_BIDI ((int64_t)0x3ffffffffffffffdll) -/* NGTCP2_MAX_CLIENT_STREAM_ID_BIDI is the maximum bidirectional - client stream ID. */ -#define NGTCP2_MAX_CLIENT_STREAM_ID_BIDI ((int64_t)0x3ffffffffffffffcll) -/* NGTCP2_MAX_SERVER_STREAM_ID_UNI is the maximum unidirectional - server stream ID. */ -#define NGTCP2_MAX_SERVER_STREAM_ID_UNI ((int64_t)0x3fffffffffffffffll) -/* NGTCP2_MAX_CLIENT_STREAM_ID_UNI is the maximum unidirectional - client stream ID. */ -#define NGTCP2_MAX_CLIENT_STREAM_ID_UNI ((int64_t)0x3ffffffffffffffell) - -/* NGTCP2_MAX_NUM_ACK_BLK is the maximum number of Additional ACK - blocks which this library can create, or decode. */ -#define NGTCP2_MAX_ACK_BLKS 32 - -/* NGTCP2_MAX_PKT_NUM is the maximum packet number. */ -#define NGTCP2_MAX_PKT_NUM ((int64_t)((1ll << 62) - 1)) - -/* NGTCP2_MIN_PKT_EXPANDLEN is the minimum packet size expansion in - addition to the minimum DCID length to hide/trigger Stateless - Reset. */ -#define NGTCP2_MIN_PKT_EXPANDLEN 22 - -/* NGTCP2_RETRY_TAGLEN is the length of Retry packet integrity tag. */ -#define NGTCP2_RETRY_TAGLEN 16 - -typedef struct ngtcp2_pkt_retry { - ngtcp2_cid odcid; - ngtcp2_vec token; - uint8_t tag[NGTCP2_RETRY_TAGLEN]; -} ngtcp2_pkt_retry; - -typedef enum { - NGTCP2_FRAME_PADDING = 0x00, - NGTCP2_FRAME_PING = 0x01, - NGTCP2_FRAME_ACK = 0x02, - NGTCP2_FRAME_ACK_ECN = 0x03, - NGTCP2_FRAME_RESET_STREAM = 0x04, - NGTCP2_FRAME_STOP_SENDING = 0x05, - NGTCP2_FRAME_CRYPTO = 0x06, - NGTCP2_FRAME_NEW_TOKEN = 0x07, - NGTCP2_FRAME_STREAM = 0x08, - NGTCP2_FRAME_MAX_DATA = 0x10, - NGTCP2_FRAME_MAX_STREAM_DATA = 0x11, - NGTCP2_FRAME_MAX_STREAMS_BIDI = 0x12, - NGTCP2_FRAME_MAX_STREAMS_UNI = 0x13, - NGTCP2_FRAME_DATA_BLOCKED = 0x14, - NGTCP2_FRAME_STREAM_DATA_BLOCKED = 0x15, - NGTCP2_FRAME_STREAMS_BLOCKED_BIDI = 0x16, - NGTCP2_FRAME_STREAMS_BLOCKED_UNI = 0x17, - NGTCP2_FRAME_NEW_CONNECTION_ID = 0x18, - NGTCP2_FRAME_RETIRE_CONNECTION_ID = 0x19, - NGTCP2_FRAME_PATH_CHALLENGE = 0x1a, - NGTCP2_FRAME_PATH_RESPONSE = 0x1b, - NGTCP2_FRAME_CONNECTION_CLOSE = 0x1c, - NGTCP2_FRAME_CONNECTION_CLOSE_APP = 0x1d, - NGTCP2_FRAME_HANDSHAKE_DONE = 0x1e, -} ngtcp2_frame_type; - -typedef struct { - uint8_t type; - /** - * flags of decoded STREAM frame. This gets ignored when encoding - * STREAM frame. - */ - uint8_t flags; - uint8_t fin; - int64_t stream_id; - uint64_t offset; - /* datacnt is the number of elements that data contains. Although - the length of data is 1 in this definition, the library may - allocate extra bytes to hold more elements. */ - size_t datacnt; - /* data is the array of ngtcp2_vec which references data. */ - ngtcp2_vec data[1]; -} ngtcp2_stream; - -typedef struct { - uint64_t gap; - uint64_t blklen; -} ngtcp2_ack_blk; - -typedef struct { - uint8_t type; - int64_t largest_ack; - uint64_t ack_delay; - /** - * ack_delay_unscaled is an ack_delay multiplied by - * 2**ack_delay_component * NGTCP2_MICROSECONDS. - */ - ngtcp2_duration ack_delay_unscaled; - uint64_t first_ack_blklen; - size_t num_blks; - ngtcp2_ack_blk blks[1]; -} ngtcp2_ack; - -typedef struct { - uint8_t type; - /** - * The length of contiguous PADDING frames. - */ - size_t len; -} ngtcp2_padding; - -typedef struct { - uint8_t type; - int64_t stream_id; - uint64_t app_error_code; - uint64_t final_size; -} ngtcp2_reset_stream; - -typedef struct { - uint8_t type; - uint64_t error_code; - uint64_t frame_type; - size_t reasonlen; - uint8_t *reason; -} ngtcp2_connection_close; - -typedef struct { - uint8_t type; - /** - * max_data is Maximum Data. - */ - uint64_t max_data; -} ngtcp2_max_data; - -typedef struct { - uint8_t type; - int64_t stream_id; - uint64_t max_stream_data; -} ngtcp2_max_stream_data; - -typedef struct { - uint8_t type; - uint64_t max_streams; -} ngtcp2_max_streams; - -typedef struct { - uint8_t type; -} ngtcp2_ping; - -typedef struct { - uint8_t type; - uint64_t offset; -} ngtcp2_data_blocked; - -typedef struct { - uint8_t type; - int64_t stream_id; - uint64_t offset; -} ngtcp2_stream_data_blocked; - -typedef struct { - uint8_t type; - uint64_t stream_limit; -} ngtcp2_streams_blocked; - -typedef struct { - uint8_t type; - uint64_t seq; - uint64_t retire_prior_to; - ngtcp2_cid cid; - uint8_t stateless_reset_token[NGTCP2_STATELESS_RESET_TOKENLEN]; -} ngtcp2_new_connection_id; - -typedef struct { - uint8_t type; - int64_t stream_id; - uint64_t app_error_code; -} ngtcp2_stop_sending; - -typedef struct { - uint8_t type; - uint8_t data[8]; -} ngtcp2_path_challenge; - -typedef struct { - uint8_t type; - uint8_t data[8]; -} ngtcp2_path_response; - -typedef struct { - uint8_t type; - uint64_t offset; - /* datacnt is the number of elements that data contains. Although - the length of data is 1 in this definition, the library may - allocate extra bytes to hold more elements. */ - size_t datacnt; - /* data is the array of ngtcp2_vec which references data. */ - ngtcp2_vec data[1]; -} ngtcp2_crypto; - -typedef struct { - uint8_t type; - ngtcp2_vec token; -} ngtcp2_new_token; - -typedef struct { - uint8_t type; - uint64_t seq; -} ngtcp2_retire_connection_id; - -typedef struct { - uint8_t type; -} ngtcp2_handshake_done; - -typedef union { - uint8_t type; - ngtcp2_stream stream; - ngtcp2_ack ack; - ngtcp2_padding padding; - ngtcp2_reset_stream reset_stream; - ngtcp2_connection_close connection_close; - ngtcp2_max_data max_data; - ngtcp2_max_stream_data max_stream_data; - ngtcp2_max_streams max_streams; - ngtcp2_ping ping; - ngtcp2_data_blocked data_blocked; - ngtcp2_stream_data_blocked stream_data_blocked; - ngtcp2_streams_blocked streams_blocked; - ngtcp2_new_connection_id new_connection_id; - ngtcp2_stop_sending stop_sending; - ngtcp2_path_challenge path_challenge; - ngtcp2_path_response path_response; - ngtcp2_crypto crypto; - ngtcp2_new_token new_token; - ngtcp2_retire_connection_id retire_connection_id; - ngtcp2_handshake_done handshake_done; -} ngtcp2_frame; - -struct ngtcp2_pkt_chain; -typedef struct ngtcp2_pkt_chain ngtcp2_pkt_chain; - -/* - * ngtcp2_pkt_chain is the chain of incoming packets buffered. - */ -struct ngtcp2_pkt_chain { - ngtcp2_path_storage path; - ngtcp2_pkt_chain *next; - uint8_t *pkt; - size_t pktlen; - ngtcp2_tstamp ts; -}; - -/* - * ngtcp2_pkt_chain_new allocates ngtcp2_pkt_chain objects, and - * assigns its pointer to |*ppc|. The content of buffer pointed by - * |pkt| of length |pktlen| is copied into |*ppc|. The packet is - * obtained via the network |path|. The values of path->local and - * path->remote are copied into |*ppc|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_pkt_chain_new(ngtcp2_pkt_chain **ppc, const ngtcp2_path *path, - const uint8_t *pkt, size_t pktlen, ngtcp2_tstamp ts, - const ngtcp2_mem *mem); - -/* - * ngtcp2_pkt_chain_del deallocates |pc|. It also frees the memory - * pointed by |pc|. - */ -void ngtcp2_pkt_chain_del(ngtcp2_pkt_chain *pc, const ngtcp2_mem *mem); - -/* - * ngtcp2_pkt_hd_init initializes |hd| with the given values. If - * |dcid| and/or |scid| is NULL, DCID and SCID of |hd| is empty - * respectively. |pkt_numlen| is the number of bytes used to encode - * |pkt_num| and either 1, 2, or 4. |version| is QUIC version for - * long header. |len| is the length field of Initial, 0RTT, and - * Handshake packets. - */ -void ngtcp2_pkt_hd_init(ngtcp2_pkt_hd *hd, uint8_t flags, uint8_t type, - const ngtcp2_cid *dcid, const ngtcp2_cid *scid, - int64_t pkt_num, size_t pkt_numlen, uint32_t version, - size_t len); - -/* - * ngtcp2_pkt_encode_hd_long encodes |hd| as QUIC long header into - * |out| which has length |outlen|. It returns the number of bytes - * written into |outlen| if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer is too short - */ -ngtcp2_ssize ngtcp2_pkt_encode_hd_long(uint8_t *out, size_t outlen, - const ngtcp2_pkt_hd *hd); - -/* - * ngtcp2_pkt_encode_hd_short encodes |hd| as QUIC short header into - * |out| which has length |outlen|. It returns the number of bytes - * written into |outlen| if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer is too short - */ -ngtcp2_ssize ngtcp2_pkt_encode_hd_short(uint8_t *out, size_t outlen, - const ngtcp2_pkt_hd *hd); - -/** - * @function - * - * `ngtcp2_pkt_decode_frame` decodes a QUIC frame from the buffer - * pointed by |payload| whose length is |payloadlen|. - * - * This function returns the number of bytes read to decode a single - * frame if it succeeds, or one of the following negative error codes: - * - * :enum:`NGTCP2_ERR_FRAME_ENCODING` - * Frame is badly formatted; or frame type is unknown. - */ -ngtcp2_ssize ngtcp2_pkt_decode_frame(ngtcp2_frame *dest, const uint8_t *payload, - size_t payloadlen); - -/** - * @function - * - * `ngtcp2_pkt_encode_frame` encodes a frame |fm| into the buffer - * pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written to the buffer, or - * one of the following negative error codes: - * - * :enum:`NGTCP2_ERR_NOBUF` - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize ngtcp2_pkt_encode_frame(uint8_t *out, size_t outlen, - ngtcp2_frame *fr); - -/* - * ngtcp2_pkt_decode_version_negotiation decodes Version Negotiation - * packet payload |payload| of length |payloadlen|, and stores the - * result in |dest|. |dest| must have enough capacity to store the - * result. |payloadlen| also must be a multiple of sizeof(uint32_t). - * - * This function returns the number of versions written in |dest|. - */ -size_t ngtcp2_pkt_decode_version_negotiation(uint32_t *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_stateless_reset decodes Stateless Reset payload - * |payload| of length |payloadlen|. The |payload| must start with - * Stateless Reset Token. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_INVALID_ARGUMENT - * Payloadlen is too short. - */ -int ngtcp2_pkt_decode_stateless_reset(ngtcp2_pkt_stateless_reset *sr, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_retry decodes Retry packet payload |payload| of - * length |payloadlen|. The |payload| must start with Retry token - * field. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_INVALID_ARGUMENT - * Payloadlen is too short. - */ -int ngtcp2_pkt_decode_retry(ngtcp2_pkt_retry *dest, const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_stream_frame decodes STREAM frame from |payload| - * of length |payloadlen|. The result is stored in the object pointed - * by |dest|. STREAM frame must start at payload[0]. This function - * finishes when it decodes one STREAM frame, and returns the exact - * number of bytes read to decode a frame if it succeeds, or one of - * the following negative error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include STREAM frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_stream_frame(ngtcp2_stream *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_ack_frame decodes ACK frame from |payload| of - * length |payloadlen|. The result is stored in the object pointed by - * |dest|. ACK frame must start at payload[0]. This function - * finishes when it decodes one ACK frame, and returns the exact - * number of bytes read to decode a frame if it succeeds, or one of - * the following negative error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include ACK frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_ack_frame(ngtcp2_ack *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_padding_frame decodes contiguous PADDING frames - * from |payload| of length |payloadlen|. It continues to parse - * frames as long as the frame type is PADDING. This finishes when it - * encounters the frame type which is not PADDING, or all input data - * is read. The first byte (payload[0]) must be NGTCP2_FRAME_PADDING. - * This function returns the exact number of bytes read to decode - * PADDING frames. - */ -size_t ngtcp2_pkt_decode_padding_frame(ngtcp2_padding *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_reset_stream_frame decodes RESET_STREAM frame - * from |payload| of length |payloadlen|. The result is stored in the - * object pointed by |dest|. RESET_STREAM frame must start at - * payload[0]. This function finishes when it decodes one - * RESET_STREAM frame, and returns the exact number of bytes read to - * decode a frame if it succeeds, or one of the following negative - * error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include RESET_STREAM frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_reset_stream_frame(ngtcp2_reset_stream *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_connection_close_frame decodes CONNECTION_CLOSE - * frame from |payload| of length |payloadlen|. The result is stored - * in the object pointed by |dest|. CONNECTION_CLOSE frame must start - * at payload[0]. This function finishes it decodes one - * CONNECTION_CLOSE frame, and returns the exact number of bytes read - * to decode a frame if it succeeds, or one of the following negative - * error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include CONNECTION_CLOSE frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_connection_close_frame( - ngtcp2_connection_close *dest, const uint8_t *payload, size_t payloadlen); - -/* - * ngtcp2_pkt_decode_max_data_frame decodes MAX_DATA frame from - * |payload| of length |payloadlen|. The result is stored in the - * object pointed by |dest|. MAX_DATA frame must start at payload[0]. - * This function finishes when it decodes one MAX_DATA frame, and - * returns the exact number of bytes read to decode a frame if it - * succeeds, or one of the following negative error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include MAX_DATA frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_max_data_frame(ngtcp2_max_data *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_max_stream_data_frame decodes MAX_STREAM_DATA - * frame from |payload| of length |payloadlen|. The result is stored - * in the object pointed by |dest|. MAX_STREAM_DATA frame must start - * at payload[0]. This function finishes when it decodes one - * MAX_STREAM_DATA frame, and returns the exact number of bytes read - * to decode a frame if it succeeds, or one of the following negative - * error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include MAX_STREAM_DATA frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_max_stream_data_frame( - ngtcp2_max_stream_data *dest, const uint8_t *payload, size_t payloadlen); - -/* - * ngtcp2_pkt_decode_max_streams_frame decodes MAX_STREAMS frame from - * |payload| of length |payloadlen|. The result is stored in the - * object pointed by |dest|. MAX_STREAMS frame must start at - * payload[0]. This function finishes when it decodes one MAX_STREAMS - * frame, and returns the exact number of bytes read to decode a frame - * if it succeeds, or one of the following negative error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include MAX_STREAMS frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_max_streams_frame(ngtcp2_max_streams *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_ping_frame decodes PING frame from |payload| of - * length |payloadlen|. The result is stored in the object pointed by - * |dest|. PING frame must start at payload[0]. This function - * finishes when it decodes one PING frame, and returns the exact - * number of bytes read to decode a frame if it succeeds, or one of - * the following negative error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include PING frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_ping_frame(ngtcp2_ping *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_data_blocked_frame decodes DATA_BLOCKED frame - * from |payload| of length |payloadlen|. The result is stored in the - * object pointed by |dest|. DATA_BLOCKED frame must start at - * payload[0]. This function finishes when it decodes one - * DATA_BLOCKED frame, and returns the exact number of bytes read to - * decode a frame if it succeeds, or one of the following negative - * error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include DATA_BLOCKED frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_data_blocked_frame(ngtcp2_data_blocked *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_stream_data_blocked_frame decodes - * STREAM_DATA_BLOCKED frame from |payload| of length |payloadlen|. - * The result is stored in the object pointed by |dest|. - * STREAM_DATA_BLOCKED frame must start at payload[0]. This function - * finishes when it decodes one STREAM_DATA_BLOCKED frame, and returns - * the exact number of bytes read to decode a frame if it succeeds, or - * one of the following negative error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include STREAM_DATA_BLOCKED frame. - */ -ngtcp2_ssize -ngtcp2_pkt_decode_stream_data_blocked_frame(ngtcp2_stream_data_blocked *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_streams_blocked_frame decodes STREAMS_BLOCKED - * frame from |payload| of length |payloadlen|. The result is stored - * in the object pointed by |dest|. STREAMS_BLOCKED frame must start - * at payload[0]. This function finishes when it decodes one - * STREAMS_BLOCKED frame, and returns the exact number of bytes read - * to decode a frame if it succeeds, or one of the following negative - * error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include STREAMS_BLOCKED frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_streams_blocked_frame( - ngtcp2_streams_blocked *dest, const uint8_t *payload, size_t payloadlen); - -/* - * ngtcp2_pkt_decode_new_connection_id_frame decodes NEW_CONNECTION_ID - * frame from |payload| of length |payloadlen|. The result is stored - * in the object pointed by |dest|. NEW_CONNECTION_ID frame must - * start at payload[0]. This function finishes when it decodes one - * NEW_CONNECTION_ID frame, and returns the exact number of bytes read - * to decode a frame if it succeeds, or one of the following negative - * error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include NEW_CONNECTION_ID frame; or the - * length of CID is strictly less than NGTCP2_MIN_CIDLEN or - * greater than NGTCP2_MAX_CIDLEN. - */ -ngtcp2_ssize ngtcp2_pkt_decode_new_connection_id_frame( - ngtcp2_new_connection_id *dest, const uint8_t *payload, size_t payloadlen); - -/* - * ngtcp2_pkt_decode_stop_sending_frame decodes STOP_SENDING frame - * from |payload| of length |payloadlen|. The result is stored in the - * object pointed by |dest|. STOP_SENDING frame must start at - * payload[0]. This function finishes when it decodes one - * STOP_SENDING frame, and returns the exact number of bytes read to - * decode a frame if it succeeds, or one of the following negative - * error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include STOP_SENDING frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_stop_sending_frame(ngtcp2_stop_sending *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_path_challenge_frame decodes PATH_CHALLENGE frame - * from |payload| of length |payloadlen|. The result is stored in the - * object pointed by |dest|. PATH_CHALLENGE frame must start at - * payload[0]. This function finishes when it decodes one - * PATH_CHALLENGE frame, and returns the exact number of bytes read to - * decode a frame if it succeeds, or one of the following negative - * error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include PATH_CHALLENGE frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_path_challenge_frame(ngtcp2_path_challenge *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_path_response_frame decodes PATH_RESPONSE frame - * from |payload| of length |payloadlen|. The result is stored in the - * object pointed by |dest|. PATH_RESPONSE frame must start at - * payload[0]. This function finishes when it decodes one - * PATH_RESPONSE frame, and returns the exact number of bytes read to - * decode a frame if it succeeds, or one of the following negative - * error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include PATH_RESPONSE frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_path_response_frame(ngtcp2_path_response *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_crypto_frame decodes CRYPTO frame from |payload| - * of length |payloadlen|. The result is stored in the object pointed - * by |dest|. CRYPTO frame must start at payload[0]. This function - * finishes when it decodes one CRYPTO frame, and returns the exact - * number of bytes read to decode a frame if it succeeds, or one of - * the following negative error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include CRYPTO frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_crypto_frame(ngtcp2_crypto *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_new_token_frame decodes NEW_TOKEN frame from - * |payload| of length |payloadlen|. The result is stored in the - * object pointed by |dest|. NEW_TOKEN frame must start at - * payload[0]. This function finishes when it decodes one NEW_TOKEN - * frame, and returns the exact number of bytes read to decode a frame - * if it succeeds, or one of the following negative error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include NEW_TOKEN frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_new_token_frame(ngtcp2_new_token *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_retire_connection_id_frame decodes RETIRE_CONNECTION_ID - * frame from |payload| of length |payloadlen|. The result is stored in the - * object pointed by |dest|. RETIRE_CONNECTION_ID frame must start at - * payload[0]. This function finishes when it decodes one RETIRE_CONNECTION_ID - * frame, and returns the exact number of bytes read to decode a frame - * if it succeeds, or one of the following negative error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include RETIRE_CONNECTION_ID frame. - */ -ngtcp2_ssize -ngtcp2_pkt_decode_retire_connection_id_frame(ngtcp2_retire_connection_id *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_decode_handshake_done_frame decodes HANDSHAKE_DONE frame - * from |payload| of length |payloadlen|. The result is stored in the - * object pointed by |dest|. HANDSHAKE_DONE frame must start at - * payload[0]. This function finishes when it decodes one - * HANDSHAKE_DONE frame, and returns the exact number of bytes read to - * decode a frame if it succeeds, or one of the following negative - * error codes: - * - * NGTCP2_ERR_FRAME_ENCODING - * Payload is too short to include HANDSHAKE_DONE frame. - */ -ngtcp2_ssize ngtcp2_pkt_decode_handshake_done_frame(ngtcp2_handshake_done *dest, - const uint8_t *payload, - size_t payloadlen); - -/* - * ngtcp2_pkt_encode_stream_frame encodes STREAM frame |fr| into the - * buffer pointed by |out| of length |outlen|. - * - * This function assigns & - * ~NGTCP2_FRAME_STREAM to fr->flags. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize ngtcp2_pkt_encode_stream_frame(uint8_t *out, size_t outlen, - ngtcp2_stream *fr); - -/* - * ngtcp2_pkt_encode_ack_frame encodes ACK frame |fr| into the buffer - * pointed by |out| of length |outlen|. - * - * This function assigns & - * ~NGTCP2_FRAME_ACK to fr->flags. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize ngtcp2_pkt_encode_ack_frame(uint8_t *out, size_t outlen, - ngtcp2_ack *fr); - -/* - * ngtcp2_pkt_encode_padding_frame encodes PADDING frame |fr| into the - * buffer pointed by |out| of length |outlen|. - * - * This function encodes consecutive fr->len PADDING frames. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write frame(s). - */ -ngtcp2_ssize ngtcp2_pkt_encode_padding_frame(uint8_t *out, size_t outlen, - const ngtcp2_padding *fr); - -/* - * ngtcp2_pkt_encode_reset_stream_frame encodes RESET_STREAM frame - * |fr| into the buffer pointed by |out| of length |buflen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize -ngtcp2_pkt_encode_reset_stream_frame(uint8_t *out, size_t outlen, - const ngtcp2_reset_stream *fr); - -/* - * ngtcp2_pkt_encode_connection_close_frame encodes CONNECTION_CLOSE - * frame |fr| into the buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize -ngtcp2_pkt_encode_connection_close_frame(uint8_t *out, size_t outlen, - const ngtcp2_connection_close *fr); - -/* - * ngtcp2_pkt_encode_max_data_frame encodes MAX_DATA frame |fr| into - * the buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize ngtcp2_pkt_encode_max_data_frame(uint8_t *out, size_t outlen, - const ngtcp2_max_data *fr); - -/* - * ngtcp2_pkt_encode_max_stream_data_frame encodes MAX_STREAM_DATA - * frame |fr| into the buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize -ngtcp2_pkt_encode_max_stream_data_frame(uint8_t *out, size_t outlen, - const ngtcp2_max_stream_data *fr); - -/* - * ngtcp2_pkt_encode_max_streams_frame encodes MAX_STREAMS - * frame |fr| into the buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize ngtcp2_pkt_encode_max_streams_frame(uint8_t *out, size_t outlen, - const ngtcp2_max_streams *fr); - -/* - * ngtcp2_pkt_encode_ping_frame encodes PING frame |fr| into the - * buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize ngtcp2_pkt_encode_ping_frame(uint8_t *out, size_t outlen, - const ngtcp2_ping *fr); - -/* - * ngtcp2_pkt_encode_data_blocked_frame encodes DATA_BLOCKED frame - * |fr| into the buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize -ngtcp2_pkt_encode_data_blocked_frame(uint8_t *out, size_t outlen, - const ngtcp2_data_blocked *fr); - -/* - * ngtcp2_pkt_encode_stream_data_blocked_frame encodes - * STREAM_DATA_BLOCKED frame |fr| into the buffer pointed by |out| of - * length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize ngtcp2_pkt_encode_stream_data_blocked_frame( - uint8_t *out, size_t outlen, const ngtcp2_stream_data_blocked *fr); - -/* - * ngtcp2_pkt_encode_streams_blocked_frame encodes STREAMS_BLOCKED - * frame |fr| into the buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize -ngtcp2_pkt_encode_streams_blocked_frame(uint8_t *out, size_t outlen, - const ngtcp2_streams_blocked *fr); - -/* - * ngtcp2_pkt_encode_new_connection_id_frame encodes NEW_CONNECTION_ID - * frame |fr| into the buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize -ngtcp2_pkt_encode_new_connection_id_frame(uint8_t *out, size_t outlen, - const ngtcp2_new_connection_id *fr); - -/* - * ngtcp2_pkt_encode_stop_sending_frame encodes STOP_SENDING frame - * |fr| into the buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize -ngtcp2_pkt_encode_stop_sending_frame(uint8_t *out, size_t outlen, - const ngtcp2_stop_sending *fr); - -/* - * ngtcp2_pkt_encode_path_challenge_frame encodes PATH_CHALLENGE frame - * |fr| into the buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize -ngtcp2_pkt_encode_path_challenge_frame(uint8_t *out, size_t outlen, - const ngtcp2_path_challenge *fr); - -/* - * ngtcp2_pkt_encode_path_response_frame encodes PATH_RESPONSE frame - * |fr| into the buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize -ngtcp2_pkt_encode_path_response_frame(uint8_t *out, size_t outlen, - const ngtcp2_path_response *fr); - -/* - * ngtcp2_pkt_encode_crypto_frame encodes CRYPTO frame |fr| into the - * buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize ngtcp2_pkt_encode_crypto_frame(uint8_t *out, size_t outlen, - const ngtcp2_crypto *fr); - -/* - * ngtcp2_pkt_encode_new_token_frame encodes NEW_TOKEN frame |fr| into - * the buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize ngtcp2_pkt_encode_new_token_frame(uint8_t *out, size_t outlen, - const ngtcp2_new_token *fr); - -/* - * ngtcp2_pkt_encode_retire_connection_id_frame encodes RETIRE_CONNECTION_ID - * frame |fr| into the buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize ngtcp2_pkt_encode_retire_connection_id_frame( - uint8_t *out, size_t outlen, const ngtcp2_retire_connection_id *fr); - -/* - * ngtcp2_pkt_encode_handshake_done_frame encodes HANDSHAKE_DONE frame - * |fr| into the buffer pointed by |out| of length |outlen|. - * - * This function returns the number of bytes written if it succeeds, - * or one of the following negative error codes: - * - * NGTCP2_ERR_NOBUF - * Buffer does not have enough capacity to write a frame. - */ -ngtcp2_ssize -ngtcp2_pkt_encode_handshake_done_frame(uint8_t *out, size_t outlen, - const ngtcp2_handshake_done *fr); - -/* - * ngtcp2_pkt_adjust_pkt_num find the full 64 bits packet number for - * |pkt_num|, which is expected to be least significant |n| bits. The - * |max_pkt_num| is the highest successfully authenticated packet - * number. - */ -int64_t ngtcp2_pkt_adjust_pkt_num(int64_t max_pkt_num, int64_t pkt_num, - size_t n); - -/* - * ngtcp2_pkt_validate_ack checks that ack is malformed or not. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_ACK_FRAME - * ACK frame is malformed - */ -int ngtcp2_pkt_validate_ack(ngtcp2_ack *fr); - -/* - * ngtcp2_pkt_stream_max_datalen returns the maximum number of bytes - * which can be sent for stream denoted by |stream_id|. |offset| is - * an offset of within the stream. |len| is the estimated number of - * bytes to be sent. |left| is the size of buffer. If |left| is too - * small to write STREAM frame, this function returns (size_t)-1. - */ -size_t ngtcp2_pkt_stream_max_datalen(int64_t stream_id, uint64_t offset, - size_t len, size_t left); - -/* - * ngtcp2_pkt_crypto_max_datalen returns the maximum number of bytes - * which can be sent for crypto stream. |offset| is an offset of - * within the crypto stream. |len| is the estimated number of bytes - * to be sent. |left| is the size of buffer. If |left| is too small - * to write CRYPTO frame, this function returns (size_t)-1. - */ -size_t ngtcp2_pkt_crypto_max_datalen(uint64_t offset, size_t len, size_t left); - -/* - * ngtcp2_pkt_verify_reserved_bits verifies that the first byte |c| of - * the packet header has the correct reserved bits. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_PROTO - * Reserved bits has wrong value. - */ -int ngtcp2_pkt_verify_reserved_bits(uint8_t c); - -/* - * ngtcp2_pkt_encode_pseudo_retry encodes Retry pseudo-packet in the - * buffer pointed by |dest| of length |destlen|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_BUF - * Buffer is too short. - */ -ngtcp2_ssize ngtcp2_pkt_encode_pseudo_retry( - uint8_t *dest, size_t destlen, const ngtcp2_pkt_hd *hd, uint8_t unused, - const ngtcp2_cid *odcid, const uint8_t *token, size_t tokenlen); - -/* - * ngtcp2_pkt_verify_retry_tag verifies Retry packet. The buffer - * pointed by |pkt| of length |pktlen| must contain Retry packet - * including packet header. The odcid and tag fields of |retry| must - * be specified. |aead| must be AEAD_AES_128_GCM. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_PROTO - * Verification failed. - */ -int ngtcp2_pkt_verify_retry_tag(const ngtcp2_pkt_retry *retry, - const uint8_t *pkt, size_t pktlen, - ngtcp2_encrypt encrypt, - const ngtcp2_crypto_aead *aead, - const ngtcp2_crypto_aead_ctx *aead_ctx); - -#endif /* NGTCP2_PKT_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_ppe.c b/deps/ngtcp2/lib/ngtcp2_ppe.c deleted file mode 100644 index e2c47fd0c5fe05..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_ppe.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_ppe.h" - -#include -#include - -#include "ngtcp2_str.h" -#include "ngtcp2_conv.h" - -void ngtcp2_ppe_init(ngtcp2_ppe *ppe, uint8_t *out, size_t outlen, - ngtcp2_crypto_cc *cc) { - ngtcp2_buf_init(&ppe->buf, out, outlen); - - ppe->hdlen = 0; - ppe->len_offset = 0; - ppe->pkt_num_offset = 0; - ppe->pkt_numlen = 0; - ppe->pkt_num = 0; - ppe->sample_offset = 0; - ppe->cc = cc; -} - -int ngtcp2_ppe_encode_hd(ngtcp2_ppe *ppe, const ngtcp2_pkt_hd *hd) { - ngtcp2_ssize rv; - ngtcp2_buf *buf = &ppe->buf; - ngtcp2_crypto_cc *cc = ppe->cc; - - if (ngtcp2_buf_left(buf) < cc->aead_overhead) { - return NGTCP2_ERR_NOBUF; - } - - if (hd->flags & NGTCP2_PKT_FLAG_LONG_FORM) { - ppe->len_offset = 1 + 4 + 1 + hd->dcid.datalen + 1 + hd->scid.datalen; - if (hd->type == NGTCP2_PKT_INITIAL) { - ppe->len_offset += ngtcp2_put_varint_len(hd->token.len) + hd->token.len; - } - ppe->pkt_num_offset = ppe->len_offset + 2; - rv = ngtcp2_pkt_encode_hd_long( - buf->last, ngtcp2_buf_left(buf) - cc->aead_overhead, hd); - } else { - ppe->pkt_num_offset = 1 + hd->dcid.datalen; - rv = ngtcp2_pkt_encode_hd_short( - buf->last, ngtcp2_buf_left(buf) - cc->aead_overhead, hd); - } - if (rv < 0) { - return (int)rv; - } - - ppe->sample_offset = ppe->pkt_num_offset + 4; - - buf->last += rv; - - ppe->pkt_numlen = hd->pkt_numlen; - ppe->hdlen = (size_t)rv; - - ppe->pkt_num = hd->pkt_num; - - return 0; -} - -int ngtcp2_ppe_encode_frame(ngtcp2_ppe *ppe, ngtcp2_frame *fr) { - ngtcp2_ssize rv; - ngtcp2_buf *buf = &ppe->buf; - ngtcp2_crypto_cc *cc = ppe->cc; - - if (ngtcp2_buf_left(buf) < cc->aead_overhead) { - return NGTCP2_ERR_NOBUF; - } - - rv = ngtcp2_pkt_encode_frame(buf->last, - ngtcp2_buf_left(buf) - cc->aead_overhead, fr); - if (rv < 0) { - return (int)rv; - } - - buf->last += rv; - - return 0; -} - -ngtcp2_ssize ngtcp2_ppe_final(ngtcp2_ppe *ppe, const uint8_t **ppkt) { - ngtcp2_buf *buf = &ppe->buf; - ngtcp2_crypto_cc *cc = ppe->cc; - uint8_t *payload = buf->begin + ppe->hdlen; - size_t payloadlen = ngtcp2_buf_len(buf) - ppe->hdlen; - uint8_t mask[NGTCP2_HP_SAMPLELEN]; - uint8_t *p; - size_t i; - int rv; - - assert(cc->encrypt); - assert(cc->hp_mask); - - if (ppe->len_offset) { - ngtcp2_put_varint14( - buf->begin + ppe->len_offset, - (uint16_t)(payloadlen + ppe->pkt_numlen + cc->aead_overhead)); - } - - ngtcp2_crypto_create_nonce(ppe->nonce, cc->ckm->iv.base, cc->ckm->iv.len, - ppe->pkt_num); - - rv = cc->encrypt(payload, &cc->aead, &cc->ckm->aead_ctx, payload, payloadlen, - ppe->nonce, cc->ckm->iv.len, buf->begin, ppe->hdlen); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - buf->last = payload + payloadlen + cc->aead_overhead; - - /* TODO Check that we have enough space to get sample */ - assert(ppe->sample_offset + NGTCP2_HP_SAMPLELEN <= ngtcp2_buf_len(buf)); - - rv = cc->hp_mask(mask, &cc->hp, &cc->hp_ctx, buf->begin + ppe->sample_offset); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - - p = buf->begin; - if (*p & NGTCP2_HEADER_FORM_BIT) { - *p = (uint8_t)(*p ^ (mask[0] & 0x0f)); - } else { - *p = (uint8_t)(*p ^ (mask[0] & 0x1f)); - } - - p = buf->begin + ppe->pkt_num_offset; - for (i = 0; i < ppe->pkt_numlen; ++i) { - *(p + i) ^= mask[i + 1]; - } - - if (ppkt != NULL) { - *ppkt = buf->begin; - } - - return (ngtcp2_ssize)ngtcp2_buf_len(buf); -} - -size_t ngtcp2_ppe_left(ngtcp2_ppe *ppe) { - ngtcp2_crypto_cc *cc = ppe->cc; - - if (ngtcp2_buf_left(&ppe->buf) < cc->aead_overhead) { - return 0; - } - - return ngtcp2_buf_left(&ppe->buf) - cc->aead_overhead; -} - -size_t ngtcp2_ppe_pktlen(ngtcp2_ppe *ppe) { - ngtcp2_crypto_cc *cc = ppe->cc; - - return ngtcp2_buf_len(&ppe->buf) + cc->aead_overhead; -} - -size_t ngtcp2_ppe_padding(ngtcp2_ppe *ppe) { - ngtcp2_crypto_cc *cc = ppe->cc; - ngtcp2_buf *buf = &ppe->buf; - size_t len; - - assert(ngtcp2_buf_left(buf) >= cc->aead_overhead); - - len = ngtcp2_buf_left(buf) - cc->aead_overhead; - memset(buf->last, 0, len); - buf->last += len; - - return len; -} - -size_t ngtcp2_ppe_padding_hp_sample(ngtcp2_ppe *ppe) { - ngtcp2_crypto_cc *cc = ppe->cc; - ngtcp2_buf *buf = &ppe->buf; - size_t max_samplelen; - size_t len = 0; - - assert(cc->aead_overhead); - - max_samplelen = ngtcp2_buf_len(buf) + cc->aead_overhead - ppe->sample_offset; - if (max_samplelen < NGTCP2_HP_SAMPLELEN) { - len = NGTCP2_HP_SAMPLELEN - max_samplelen; - assert(ngtcp2_ppe_left(ppe) >= len); - memset(buf->last, 0, len); - buf->last += len; - } - - return len; -} - -size_t ngtcp2_ppe_padding_size(ngtcp2_ppe *ppe, size_t n) { - ngtcp2_crypto_cc *cc = ppe->cc; - ngtcp2_buf *buf = &ppe->buf; - size_t pktlen = ngtcp2_buf_len(buf) + cc->aead_overhead; - size_t len; - - if (pktlen >= n) { - return 0; - } - - len = n - pktlen; - buf->last = ngtcp2_setmem(buf->last, 0, len); - - return len; -} - -int ngtcp2_ppe_ensure_hp_sample(ngtcp2_ppe *ppe) { - ngtcp2_buf *buf = &ppe->buf; - return ngtcp2_buf_left(buf) >= (4 - ppe->pkt_numlen) + NGTCP2_HP_SAMPLELEN; -} diff --git a/deps/ngtcp2/lib/ngtcp2_ppe.h b/deps/ngtcp2/lib/ngtcp2_ppe.h deleted file mode 100644 index ca6b21dce0b41a..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_ppe.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_PPE_H -#define NGTCP2_PPE_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_pkt.h" -#include "ngtcp2_buf.h" -#include "ngtcp2_crypto.h" - -/* - * ngtcp2_ppe is the Protected Packet Encoder. - */ -typedef struct { - ngtcp2_buf buf; - ngtcp2_crypto_cc *cc; - /* hdlen is the number of bytes for packet header written in buf. */ - size_t hdlen; - /* len_offset is the offset to Length field. */ - size_t len_offset; - /* pkt_num_offset is the offset to packet number field. */ - size_t pkt_num_offset; - /* pkt_numlen is the number of bytes used to encode a packet - number */ - size_t pkt_numlen; - /* sample_offset is the offset to sample for packet number - encryption. */ - size_t sample_offset; - /* pkt_num is the packet number written in buf. */ - int64_t pkt_num; - /* nonce is the buffer to store nonce. It should be equal or longer - than then length of IV. */ - uint8_t nonce[32]; -} ngtcp2_ppe; - -/* - * ngtcp2_ppe_init initializes |ppe| with the given buffer. - */ -void ngtcp2_ppe_init(ngtcp2_ppe *ppe, uint8_t *out, size_t outlen, - ngtcp2_crypto_cc *cc); - -/* - * ngtcp2_ppe_encode_hd encodes |hd|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOBUF - * The buffer is too small. - */ -int ngtcp2_ppe_encode_hd(ngtcp2_ppe *ppe, const ngtcp2_pkt_hd *hd); - -/* - * ngtcp2_ppe_encode_frame encodes |fr|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOBUF - * The buffer is too small. - */ -int ngtcp2_ppe_encode_frame(ngtcp2_ppe *ppe, ngtcp2_frame *fr); - -/* - * ngtcp2_ppe_final encrypts QUIC packet payload. If |**ppkt| is not - * NULL, the pointer to the packet is assigned to it. - * - * This function returns the length of QUIC packet, including header, - * and payload if it succeeds, or one of the following negative error - * codes: - * - * NGTCP2_ERR_CALLBACK_FAILURE - * User-defined callback function failed. - */ -ngtcp2_ssize ngtcp2_ppe_final(ngtcp2_ppe *ppe, const uint8_t **ppkt); - -/* - * ngtcp2_ppe_left returns the number of bytes left to write - * additional frames. This does not count AEAD overhead. - */ -size_t ngtcp2_ppe_left(ngtcp2_ppe *ppe); - -/* - * ngtcp2_ppe_pktlen returns the provisional packet length. It - * includes AEAD overhead. - */ -size_t ngtcp2_ppe_pktlen(ngtcp2_ppe *ppe); - -/** - * @function - * - * `ngtcp2_ppe_padding` encodes PADDING frames to the end of the - * buffer. This function returns the number of bytes padded. - */ -size_t ngtcp2_ppe_padding(ngtcp2_ppe *ppe); - -/* - * ngtcp2_ppe_padding_hp_sample adds PADDING frame if the current - * payload does not have enough space for header protection sample. - * This function should be called just before calling - * ngtcp2_ppe_final(). - * - * This function returns the number of bytes added as padding. - */ -size_t ngtcp2_ppe_padding_hp_sample(ngtcp2_ppe *ppe); - -/* - * ngtcp2_ppe_padding_size adds PADDING frame so that the size of QUIC - * packet is at least |n| bytes long. If it is unable to add PADDING - * in that way, this function still adds PADDING frame as much as - * possible. This function should be called just before calling - * ngtcp2_ppe_final(). For Short packet, this function should be - * called instead of ngtcp2_ppe_padding_hp_sample. - * - * This function returns the number of bytes added as padding. - */ -size_t ngtcp2_ppe_padding_size(ngtcp2_ppe *ppe, size_t n); - -/* - * ngtcp2_ppe_ensure_hp_sample returns nonzero if the buffer has - * enough space for header protection sample. This should be called - * right after packet header is written. - */ -int ngtcp2_ppe_ensure_hp_sample(ngtcp2_ppe *ppe); - -#endif /* NGTCP2_PPE_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_pq.c b/deps/ngtcp2/lib/ngtcp2_pq.c deleted file mode 100644 index 5e1003d7942e53..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_pq.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2012 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_pq.h" - -#include - -#include "ngtcp2_macro.h" - -void ngtcp2_pq_init(ngtcp2_pq *pq, ngtcp2_less less, const ngtcp2_mem *mem) { - pq->mem = mem; - pq->capacity = 0; - pq->q = NULL; - pq->length = 0; - pq->less = less; -} - -void ngtcp2_pq_free(ngtcp2_pq *pq) { - ngtcp2_mem_free(pq->mem, pq->q); - pq->q = NULL; -} - -static void swap(ngtcp2_pq *pq, size_t i, size_t j) { - ngtcp2_pq_entry *a = pq->q[i]; - ngtcp2_pq_entry *b = pq->q[j]; - - pq->q[i] = b; - b->index = i; - pq->q[j] = a; - a->index = j; -} - -static void bubble_up(ngtcp2_pq *pq, size_t index) { - size_t parent; - while (index != 0) { - parent = (index - 1) / 2; - if (!pq->less(pq->q[index], pq->q[parent])) { - return; - } - swap(pq, parent, index); - index = parent; - } -} - -int ngtcp2_pq_push(ngtcp2_pq *pq, ngtcp2_pq_entry *item) { - if (pq->capacity <= pq->length) { - void *nq; - size_t ncapacity; - - ncapacity = ngtcp2_max(4, (pq->capacity * 2)); - - nq = ngtcp2_mem_realloc(pq->mem, pq->q, - ncapacity * sizeof(ngtcp2_pq_entry *)); - if (nq == NULL) { - return NGTCP2_ERR_NOMEM; - } - pq->capacity = ncapacity; - pq->q = nq; - } - pq->q[pq->length] = item; - item->index = pq->length; - ++pq->length; - bubble_up(pq, pq->length - 1); - return 0; -} - -ngtcp2_pq_entry *ngtcp2_pq_top(ngtcp2_pq *pq) { - assert(pq->length); - return pq->q[0]; -} - -static void bubble_down(ngtcp2_pq *pq, size_t index) { - size_t i, j, minindex; - for (;;) { - j = index * 2 + 1; - minindex = index; - for (i = 0; i < 2; ++i, ++j) { - if (j >= pq->length) { - break; - } - if (pq->less(pq->q[j], pq->q[minindex])) { - minindex = j; - } - } - if (minindex == index) { - return; - } - swap(pq, index, minindex); - index = minindex; - } -} - -void ngtcp2_pq_pop(ngtcp2_pq *pq) { - if (pq->length > 0) { - pq->q[0] = pq->q[pq->length - 1]; - pq->q[0]->index = 0; - --pq->length; - bubble_down(pq, 0); - } -} - -void ngtcp2_pq_remove(ngtcp2_pq *pq, ngtcp2_pq_entry *item) { - assert(pq->q[item->index] == item); - - if (item->index == 0) { - ngtcp2_pq_pop(pq); - return; - } - - if (item->index == pq->length - 1) { - --pq->length; - return; - } - - pq->q[item->index] = pq->q[pq->length - 1]; - pq->q[item->index]->index = item->index; - --pq->length; - - if (pq->less(item, pq->q[item->index])) { - bubble_down(pq, item->index); - } else { - bubble_up(pq, item->index); - } -} - -int ngtcp2_pq_empty(ngtcp2_pq *pq) { return pq->length == 0; } - -size_t ngtcp2_pq_size(ngtcp2_pq *pq) { return pq->length; } - -int ngtcp2_pq_each(ngtcp2_pq *pq, ngtcp2_pq_item_cb fun, void *arg) { - size_t i; - - if (pq->length == 0) { - return 0; - } - for (i = 0; i < pq->length; ++i) { - if ((*fun)(pq->q[i], arg)) { - return 1; - } - } - return 0; -} diff --git a/deps/ngtcp2/lib/ngtcp2_pq.h b/deps/ngtcp2/lib/ngtcp2_pq.h deleted file mode 100644 index b7e4a77ba5bb70..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_pq.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * Copyright (c) 2012 nghttp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_PQ_H -#define NGTCP2_PQ_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_mem.h" - -/* Implementation of priority queue */ - -/* NGTCP2_PQ_BAD_INDEX is the priority queue index which indicates - that an entry is not queued. Assigning this value to - ngtcp2_pq_entry.index can check that the entry is queued or not. */ -#define NGTCP2_PQ_BAD_INDEX SIZE_MAX - -typedef struct { - size_t index; -} ngtcp2_pq_entry; - -/* "less" function, return nonzero if |lhs| is less than |rhs|. */ -typedef int (*ngtcp2_less)(const ngtcp2_pq_entry *lhs, - const ngtcp2_pq_entry *rhs); - -typedef struct { - /* The pointer to the pointer to the item stored */ - ngtcp2_pq_entry **q; - /* Memory allocator */ - const ngtcp2_mem *mem; - /* The number of items stored */ - size_t length; - /* The maximum number of items this pq can store. This is - automatically extended when length is reached to this value. */ - size_t capacity; - /* The less function between items */ - ngtcp2_less less; -} ngtcp2_pq; - -/* - * Initializes priority queue |pq| with compare function |cmp|. - */ -void ngtcp2_pq_init(ngtcp2_pq *pq, ngtcp2_less less, const ngtcp2_mem *mem); - -/* - * Deallocates any resources allocated for |pq|. The stored items are - * not freed by this function. - */ -void ngtcp2_pq_free(ngtcp2_pq *pq); - -/* - * Adds |item| to the priority queue |pq|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_pq_push(ngtcp2_pq *pq, ngtcp2_pq_entry *item); - -/* - * Returns item at the top of the queue |pq|. It is undefined if the - * queue is empty. - */ -ngtcp2_pq_entry *ngtcp2_pq_top(ngtcp2_pq *pq); - -/* - * Pops item at the top of the queue |pq|. The popped item is not - * freed by this function. - */ -void ngtcp2_pq_pop(ngtcp2_pq *pq); - -/* - * Returns nonzero if the queue |pq| is empty. - */ -int ngtcp2_pq_empty(ngtcp2_pq *pq); - -/* - * Returns the number of items in the queue |pq|. - */ -size_t ngtcp2_pq_size(ngtcp2_pq *pq); - -typedef int (*ngtcp2_pq_item_cb)(ngtcp2_pq_entry *item, void *arg); - -/* - * Applys |fun| to each item in |pq|. The |arg| is passed as arg - * parameter to callback function. This function must not change the - * ordering key. If the return value from callback is nonzero, this - * function returns 1 immediately without iterating remaining items. - * Otherwise this function returns 0. - */ -int ngtcp2_pq_each(ngtcp2_pq *pq, ngtcp2_pq_item_cb fun, void *arg); - -/* - * Removes |item| from priority queue. - */ -void ngtcp2_pq_remove(ngtcp2_pq *pq, ngtcp2_pq_entry *item); - -#endif /* NGTCP2_PQ_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_pv.c b/deps/ngtcp2/lib/ngtcp2_pv.c deleted file mode 100644 index 171f02dc43dd29..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_pv.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_pv.h" - -#include - -#include "ngtcp2_mem.h" -#include "ngtcp2_log.h" -#include "ngtcp2_macro.h" -#include "ngtcp2_addr.h" - -void ngtcp2_pv_entry_init(ngtcp2_pv_entry *pvent, const uint8_t *data, - ngtcp2_tstamp expiry) { - memcpy(pvent->data, data, sizeof(pvent->data)); - pvent->expiry = expiry; -} - -int ngtcp2_pv_new(ngtcp2_pv **ppv, const ngtcp2_dcid *dcid, - ngtcp2_duration timeout, uint8_t flags, ngtcp2_log *log, - const ngtcp2_mem *mem) { - int rv; - - (*ppv) = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_pv)); - if (*ppv == NULL) { - return NGTCP2_ERR_NOMEM; - } - - rv = ngtcp2_ringbuf_init(&(*ppv)->ents, NGTCP2_PV_MAX_ENTRIES, - sizeof(ngtcp2_pv_entry), mem); - if (rv != 0) { - ngtcp2_mem_free(mem, *ppv); - return 0; - } - - ngtcp2_dcid_copy(&(*ppv)->dcid, dcid); - - (*ppv)->mem = mem; - (*ppv)->log = log; - (*ppv)->timeout = timeout; - (*ppv)->started_ts = 0; - (*ppv)->loss_count = 0; - (*ppv)->flags = flags; - - return 0; -} - -void ngtcp2_pv_del(ngtcp2_pv *pv) { - if (pv == NULL) { - return; - } - ngtcp2_ringbuf_free(&pv->ents); - ngtcp2_mem_free(pv->mem, pv); -} - -void ngtcp2_pv_ensure_start(ngtcp2_pv *pv, ngtcp2_tstamp ts) { - if (pv->started_ts) { - return; - } - pv->started_ts = ts; -} - -void ngtcp2_pv_add_entry(ngtcp2_pv *pv, const uint8_t *data, - ngtcp2_tstamp expiry) { - ngtcp2_pv_entry *ent = ngtcp2_ringbuf_push_back(&pv->ents); - ngtcp2_pv_entry_init(ent, data, expiry); -} - -int ngtcp2_pv_full(ngtcp2_pv *pv) { return ngtcp2_ringbuf_full(&pv->ents); } - -int ngtcp2_pv_validate(ngtcp2_pv *pv, const uint8_t *data) { - size_t len = ngtcp2_ringbuf_len(&pv->ents); - size_t i; - ngtcp2_pv_entry *ent; - - if (len == 0) { - return NGTCP2_ERR_INVALID_STATE; - } - - for (i = 0; i < len; ++i) { - ent = ngtcp2_ringbuf_get(&pv->ents, i); - if (memcmp(ent->data, data, sizeof(ent->data)) == 0) { - ngtcp2_log_info(pv->log, NGTCP2_LOG_EVENT_PTV, "path has been validated"); - return 0; - } - } - - return NGTCP2_ERR_INVALID_ARGUMENT; -} - -void ngtcp2_pv_handle_entry_expiry(ngtcp2_pv *pv, ngtcp2_tstamp ts) { - ngtcp2_pv_entry *ent; - - if (ngtcp2_ringbuf_len(&pv->ents) == 0) { - return; - } - - ent = ngtcp2_ringbuf_get(&pv->ents, 0); - if (ent->expiry <= ts) { - ++pv->loss_count; - - ngtcp2_ringbuf_pop_front(&pv->ents); - - for (; ngtcp2_ringbuf_len(&pv->ents);) { - ent = ngtcp2_ringbuf_get(&pv->ents, 0); - if (ent->expiry <= ts) { - ngtcp2_ringbuf_pop_front(&pv->ents); - continue; - } - break; - } - } -} - -int ngtcp2_pv_validation_timed_out(ngtcp2_pv *pv, ngtcp2_tstamp ts) { - return pv->started_ts + pv->timeout <= ts; -} - -ngtcp2_tstamp ngtcp2_pv_next_expiry(ngtcp2_pv *pv) { - ngtcp2_tstamp t = UINT64_MAX; - ngtcp2_pv_entry *ent; - - if (pv->started_ts) { - t = pv->started_ts + pv->timeout; - } - - if (ngtcp2_ringbuf_len(&pv->ents) == 0) { - return t; - } - - ent = ngtcp2_ringbuf_get(&pv->ents, 0); - - return ngtcp2_min(t, ent->expiry); -} diff --git a/deps/ngtcp2/lib/ngtcp2_pv.h b/deps/ngtcp2/lib/ngtcp2_pv.h deleted file mode 100644 index 0f1734ec3e1bf5..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_pv.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_PV_H -#define NGTCP2_PV_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_cid.h" -#include "ngtcp2_ringbuf.h" - -/* NGTCP2_PV_MAX_ENTRIES is the maximum number of entries that - ngtcp2_pv can contain. It must be power of 2. */ -#define NGTCP2_PV_MAX_ENTRIES 4 - -struct ngtcp2_log; -typedef struct ngtcp2_log ngtcp2_log; - -struct ngtcp2_frame_chain; -typedef struct ngtcp2_frame_chain ngtcp2_frame_chain; - -typedef struct { - /* expiry is the timestamp when this PATH_CHALLENGE expires. */ - ngtcp2_tstamp expiry; - /* data is a byte string included in PATH_CHALLENGE. */ - uint8_t data[8]; -} ngtcp2_pv_entry; - -void ngtcp2_pv_entry_init(ngtcp2_pv_entry *pvent, const uint8_t *data, - ngtcp2_tstamp expiry); - -typedef enum { - NGTCP2_PV_FLAG_NONE, - /* NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE indicates that fallback DCID - is available in ngtcp2_pv. If path validation fails, fallback to - the fallback DCID. If path validation succeeds, fallback DCID is - retired if it does not equal to the current DCID. */ - NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE = 0x04, -} ngtcp2_pv_flag; - -struct ngtcp2_pv; -typedef struct ngtcp2_pv ngtcp2_pv; - -/* - * ngtcp2_pv is the context of a single path validation. - */ -struct ngtcp2_pv { - const ngtcp2_mem *mem; - ngtcp2_log *log; - /* dcid is DCID and path this path validation uses. */ - ngtcp2_dcid dcid; - /* fallback_dcid is the usually validated DCID and used as a - fallback if this path validation fails. */ - ngtcp2_dcid fallback_dcid; - /* ents is the ring buffer of ngtcp2_pv_entry */ - ngtcp2_ringbuf ents; - /* timeout is the duration within which this path validation should - succeed. */ - ngtcp2_duration timeout; - /* started_ts is the timestamp this path validation starts. */ - ngtcp2_tstamp started_ts; - /* loss_count is the number of lost PATH_CHALLENGE */ - size_t loss_count; - /* flags is bitwise-OR of zero or more of ngtcp2_pv_flag. */ - uint8_t flags; -}; - -/* - * ngtcp2_pv_new creates new ngtcp2_pv object and assigns its pointer - * to |*ppv|. This function makes a copy of |dcid|. |timeout| is a - * duration within which this path validation must succeed. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -int ngtcp2_pv_new(ngtcp2_pv **ppv, const ngtcp2_dcid *dcid, - ngtcp2_duration timeout, uint8_t flags, ngtcp2_log *log, - const ngtcp2_mem *mem); - -/* - * ngtcp2_pv_del deallocates |pv|. This function frees memory |pv| - * points too. - */ -void ngtcp2_pv_del(ngtcp2_pv *pv); - -/* - * ngtcp2_pv_ensure_start sets started_ts field to |ts| if it is zero. - */ -void ngtcp2_pv_ensure_start(ngtcp2_pv *pv, ngtcp2_tstamp ts); - -/* - * ngtcp2_pv_add_entry adds new entry with |data|. |expiry| is the - * expiry time of the entry. - */ -void ngtcp2_pv_add_entry(ngtcp2_pv *pv, const uint8_t *data, - ngtcp2_tstamp expiry); - -/* - * ngtcp2_pv_full returns nonzero if |pv| is full of ngtcp2_pv_entry. - */ -int ngtcp2_pv_full(ngtcp2_pv *pv); - -/* - * ngtcp2_pv_validate validates that the received |data| matches the - * one of the existing entry. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_PATH_VALIDATION_FAILED - * path validation has failed and must be abandoned - * NGTCP2_ERR_INVALID_STATE - * |pv| includes no entry - * NGTCP2_ERR_INVALID_ARGUMENT - * |pv| does not have an entry which has |data| and |path| - */ -int ngtcp2_pv_validate(ngtcp2_pv *pv, const uint8_t *data); - -/* - * ngtcp2_pv_handle_entry_expiry checks expiry for each entry. - */ -void ngtcp2_pv_handle_entry_expiry(ngtcp2_pv *pv, ngtcp2_tstamp ts); - -/* - * ngtcp2_pv_validation_timed_out returns nonzero if the path - * validation fails because of timeout. - */ -int ngtcp2_pv_validation_timed_out(ngtcp2_pv *pv, ngtcp2_tstamp ts); - -/* - * ngtcp2_pv_next_expiry returns the earliest expiry. - */ -ngtcp2_tstamp ngtcp2_pv_next_expiry(ngtcp2_pv *pv); - -#endif /* NGTCP2_PV_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_qlog.c b/deps/ngtcp2/lib/ngtcp2_qlog.c deleted file mode 100644 index 580b6a6fe0fd27..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_qlog.c +++ /dev/null @@ -1,1225 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_qlog.h" - -#include - -#include "ngtcp2_str.h" -#include "ngtcp2_vec.h" - -void ngtcp2_qlog_init(ngtcp2_qlog *qlog, ngtcp2_qlog_write write, - ngtcp2_tstamp ts, void *user_data) { - qlog->write = write; - qlog->ts = qlog->last_ts = ts; - qlog->user_data = user_data; -} - -static uint8_t *write_string(uint8_t *p, const ngtcp2_vec *s) { - *p++ = '"'; - if (s->len) { - p = ngtcp2_cpymem(p, s->base, s->len); - } - *p++ = '"'; - return p; -} - -#define NGTCP2_LOWER_XDIGITS "0123456789abcdef" - -static uint8_t *write_hex(uint8_t *p, const ngtcp2_vec *s) { - const uint8_t *b = s->base, *end = s->base + s->len; - *p++ = '"'; - for (; b != end; ++b) { - *p++ = (uint8_t)NGTCP2_LOWER_XDIGITS[*b >> 4]; - *p++ = (uint8_t)NGTCP2_LOWER_XDIGITS[*b & 0xf]; - } - *p++ = '"'; - return p; -} - -static uint8_t *write_cid(uint8_t *p, const ngtcp2_cid *cid) { - ngtcp2_vec value; - return write_hex(p, ngtcp2_vec_init(&value, cid->data, cid->datalen)); -} - -static uint8_t *write_number(uint8_t *p, uint64_t n) { - size_t nlen = 0; - uint64_t t; - uint8_t *res; - - if (n == 0) { - *p++ = '0'; - return p; - } - for (t = n; t; t /= 10, ++nlen) - ; - p += nlen; - res = p; - for (; n; n /= 10) { - *--p = (uint8_t)((n % 10) + '0'); - } - return res; -} - -static uint8_t *write_numstr(uint8_t *p, uint64_t n) { - *p++ = '"'; - p = write_number(p, n); - *p++ = '"'; - return p; -} - -static uint8_t *write_tstamp(uint8_t *p, ngtcp2_tstamp ts) { - return write_number(p, ts / NGTCP2_MILLISECONDS); -} - -static uint8_t *write_duration(uint8_t *p, ngtcp2_duration duration) { - return write_number(p, duration / NGTCP2_MILLISECONDS); -} - -static uint8_t *write_bool(uint8_t *p, int b) { - if (b) { - return ngtcp2_cpymem(p, "true", sizeof("true") - 1); - } - return ngtcp2_cpymem(p, "false", sizeof("false") - 1); -} - -static uint8_t *write_pair(uint8_t *p, const ngtcp2_vec *name, - const ngtcp2_vec *value) { - p = write_string(p, name); - *p++ = ':'; - return write_string(p, value); -} - -static uint8_t *write_pair_hex(uint8_t *p, const ngtcp2_vec *name, - const ngtcp2_vec *value) { - p = write_string(p, name); - *p++ = ':'; - return write_hex(p, value); -} - -static uint8_t *write_pair_numstr(uint8_t *p, const ngtcp2_vec *name, - uint64_t value) { - p = write_string(p, name); - *p++ = ':'; - p = write_numstr(p, value); - return p; -} - -static uint8_t *write_pair_number(uint8_t *p, const ngtcp2_vec *name, - uint64_t value) { - p = write_string(p, name); - *p++ = ':'; - return write_number(p, value); -} - -static uint8_t *write_pair_duration(uint8_t *p, const ngtcp2_vec *name, - ngtcp2_tstamp duration) { - p = write_string(p, name); - *p++ = ':'; - return write_duration(p, duration); -} - -static uint8_t *write_pair_bool(uint8_t *p, const ngtcp2_vec *name, int b) { - p = write_string(p, name); - *p++ = ':'; - return write_bool(p, b); -} - -static uint8_t *write_pair_cid(uint8_t *p, const ngtcp2_vec *name, - const ngtcp2_cid *cid) { - p = write_string(p, name); - *p++ = ':'; - return write_cid(p, cid); -} - -static uint8_t *write_trace_start(uint8_t *p, int server) { -#define NGTCP2_M \ - "\"traces\":[{\"vantage_point\":{\"name\":\"ngtcp2\",\"type\":\"" - p = ngtcp2_cpymem(p, NGTCP2_M, sizeof(NGTCP2_M) - 1); -#undef NGTCP2_M - if (server) { - p = ngtcp2_cpymem(p, "server", sizeof("server") - 1); - } else { - p = ngtcp2_cpymem(p, "client", sizeof("client") - 1); - } - *p++ = '"'; - *p++ = '}'; - *p++ = ','; - return p; -} - -static uint8_t *write_common_fields(uint8_t *p, const ngtcp2_cid *odcid) { - ngtcp2_vec name; -#define NGTCP2_M \ - "\"common_fields\":{\"protocol_type\":\"QUIC_HTTP3\",\"reference_" \ - "time\":\"0\"," - p = ngtcp2_cpymem(p, NGTCP2_M, sizeof(NGTCP2_M) - 1); -#undef NGTCP2_M - p = write_pair_cid(p, ngtcp2_vec_lit(&name, "group_id"), odcid); - *p++ = ','; - p = write_pair_cid(p, ngtcp2_vec_lit(&name, "ODCID"), odcid); - *p++ = '}'; - *p++ = ','; - return p; -} - -static uint8_t *write_event_fields(uint8_t *p) { -#define NGTCP2_M \ - "\"event_fields\":[\"relative_time\",\"category\",\"event\",\"data\"]," - p = ngtcp2_cpymem(p, NGTCP2_M, sizeof(NGTCP2_M) - 1); -#undef NGTCP2_M - return p; -} - -static uint8_t *write_events_start(uint8_t *p) { -#define NGTCP2_M "\"events\":[" - p = ngtcp2_cpymem(p, NGTCP2_M, sizeof(NGTCP2_M) - 1); -#undef NGTCP2_M - return p; -} - -static uint8_t *write_events_end(uint8_t *p) { - *p++ = '['; - *p++ = ']'; - *p++ = ']'; - return p; -} - -static uint8_t *write_trace_end(uint8_t *p) { - *p++ = '}'; - *p++ = ']'; - return p; -} - -void ngtcp2_qlog_start(ngtcp2_qlog *qlog, const ngtcp2_cid *odcid, int server) { - uint8_t buf[1024]; - ngtcp2_vec name, value; - uint8_t *p = buf; - - if (!qlog->write) { - return; - } - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "qlog_version"), - ngtcp2_vec_lit(&value, "draft-01")); - *p++ = ','; - p = write_trace_start(p, server); - p = write_common_fields(p, odcid); - p = write_event_fields(p); - p = write_events_start(p); - - qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, buf, - (size_t)(p - buf)); -} - -void ngtcp2_qlog_end(ngtcp2_qlog *qlog) { - uint8_t buf[256]; - uint8_t *p = buf; - - if (!qlog->write) { - return; - } - - p = write_events_end(p); - p = write_trace_end(p); - *p++ = '}'; - - qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_FIN, buf, - (size_t)(p - buf)); -} - -static uint8_t *write_pkt_hd(uint8_t *p, const ngtcp2_pkt_hd *hd, - size_t pktlen) { - ngtcp2_vec value; - - /* - * {"packet_number":"0000000000000000000","packet_size":0000000000000000000} - */ -#define NGTCP2_QLOG_PKT_HD_OVERHEAD 73 - - *p++ = '{'; - p = write_pair_numstr(p, ngtcp2_vec_lit(&value, "packet_number"), - (uint64_t)hd->pkt_num); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&value, "packet_size"), pktlen); - /* TODO Write DCIL and DCID */ - /* TODO Write SCIL and SCID */ - *p++ = '}'; - return p; -} - -static ngtcp2_vec *qlog_pkt_type(ngtcp2_vec *dest, const ngtcp2_pkt_hd *hd) { - if (hd->flags & NGTCP2_PKT_FLAG_LONG_FORM) { - switch (hd->type) { - case NGTCP2_PKT_INITIAL: - return ngtcp2_vec_lit(dest, "initial"); - case NGTCP2_PKT_HANDSHAKE: - return ngtcp2_vec_lit(dest, "handshake"); - case NGTCP2_PKT_0RTT: - return ngtcp2_vec_lit(dest, "0RTT"); - default: - return ngtcp2_vec_lit(dest, "unknown"); - } - } - - return ngtcp2_vec_lit(dest, "1RTT"); -} - -static uint8_t *write_padding_frame(uint8_t *p, const ngtcp2_padding *fr) { - ngtcp2_vec name, value; - (void)fr; - - /* {"frame_type":"padding"} */ -#define NGTCP2_QLOG_PADDING_FRAME_OVERHEAD 24 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "padding")); - *p++ = '}'; - - return p; -} - -static uint8_t *write_ping_frame(uint8_t *p, const ngtcp2_ping *fr) { - ngtcp2_vec name, value; - (void)fr; - - /* {"frame_type":"ping"} */ -#define NGTCP2_QLOG_PING_FRAME_OVERHEAD 21 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "ping")); - *p++ = '}'; - - return p; -} - -static uint8_t *write_ack_frame(uint8_t *p, const ngtcp2_ack *fr) { - ngtcp2_vec name, value; - int64_t largest_ack, min_ack; - size_t i; - const ngtcp2_ack_blk *blk; - - /* - * {"frame_type":"ack","ack_delay":0000000000000000000,"acked_ranges":[]} - * - * each range: - * ["0000000000000000000","0000000000000000000"], - */ -#define NGTCP2_QLOG_ACK_FRAME_BASE_OVERHEAD 70 -#define NGTCP2_QLOG_ACK_FRAME_RANGE_OVERHEAD 46 - - *p++ = '{'; - /* TODO Handle ACK ECN */ - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "ack")); - *p++ = ','; - p = write_pair_duration(p, ngtcp2_vec_lit(&name, "ack_delay"), - fr->ack_delay_unscaled); - *p++ = ','; - p = write_string(p, ngtcp2_vec_lit(&name, "acked_ranges")); - *p++ = ':'; - *p++ = '['; - - largest_ack = fr->largest_ack; - min_ack = fr->largest_ack - (int64_t)fr->first_ack_blklen; - - *p++ = '['; - p = write_numstr(p, (uint64_t)min_ack); - if (largest_ack != min_ack) { - *p++ = ','; - p = write_numstr(p, (uint64_t)largest_ack); - } - *p++ = ']'; - - for (i = 0; i < fr->num_blks; ++i) { - blk = &fr->blks[i]; - largest_ack = min_ack - (int64_t)blk->gap - 2; - min_ack = largest_ack - (int64_t)blk->blklen; - *p++ = ','; - *p++ = '['; - p = write_numstr(p, (uint64_t)min_ack); - if (largest_ack != min_ack) { - *p++ = ','; - p = write_numstr(p, (uint64_t)largest_ack); - } - *p++ = ']'; - } - - *p++ = ']'; - *p++ = '}'; - - return p; -} - -static uint8_t *write_reset_stream_frame(uint8_t *p, - const ngtcp2_reset_stream *fr) { - ngtcp2_vec name, value; - - /* - * {"frame_type":"reset_stream","stream_id":"0000000000000000000","error_code":0000000000000000000,"final_size":"0000000000000000000"} - */ -#define NGTCP2_QLOG_RESET_STREAM_FRAME_OVERHEAD 131 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "reset_stream")); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "stream_id"), - (uint64_t)fr->stream_id); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "error_code"), - fr->app_error_code); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "final_size"), fr->final_size); - *p++ = '}'; - - return p; -} - -static uint8_t *write_stop_sending_frame(uint8_t *p, - const ngtcp2_stop_sending *fr) { - ngtcp2_vec name, value; - - /* - * {"frame_type":"stop_sending","stream_id":"0000000000000000000","error_code":0000000000000000000} - */ -#define NGTCP2_QLOG_STOP_SENDING_FRAME_OVERHEAD 96 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "stop_sending")); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "stream_id"), - (uint64_t)fr->stream_id); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "error_code"), - fr->app_error_code); - *p++ = '}'; - - return p; -} - -static uint8_t *write_crypto_frame(uint8_t *p, const ngtcp2_crypto *fr) { - ngtcp2_vec name, value; - - /* - * {"frame_type":"crypto","offset":"0000000000000000000","length":0000000000000000000} - */ -#define NGTCP2_QLOG_CRYPTO_FRAME_OVERHEAD 83 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "crypto")); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "offset"), fr->offset); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "length"), - ngtcp2_vec_len(fr->data, fr->datacnt)); - *p++ = '}'; - - return p; -} - -static uint8_t *write_new_token_frame(uint8_t *p, const ngtcp2_new_token *fr) { - ngtcp2_vec name, value; - (void)fr; - - /* - * {"frame_type":"new_token","length":0000000000000000000,"token":""} - */ -#define NGTCP2_QLOG_NEW_TOKEN_FRAME_OVERHEAD 66 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "new_token")); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "length"), fr->token.len); - *p++ = ','; - p = write_pair_hex(p, ngtcp2_vec_lit(&name, "token"), &fr->token); - *p++ = '}'; - - return p; -} - -static uint8_t *write_stream_frame(uint8_t *p, const ngtcp2_stream *fr) { - ngtcp2_vec name, value; - - /* - * {"frame_type":"stream","stream_id":"0000000000000000000","offset":"0000000000000000000","length":0000000000000000000,"fin":true} - */ -#define NGTCP2_QLOG_STREAM_FRAME_OVERHEAD 128 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "stream")); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "stream_id"), - (uint64_t)fr->stream_id); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "offset"), fr->offset); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "length"), - ngtcp2_vec_len(fr->data, fr->datacnt)); - if (fr->fin) { - *p++ = ','; - p = write_pair_bool(p, ngtcp2_vec_lit(&name, "fin"), 1); - } - *p++ = '}'; - - return p; -} - -static uint8_t *write_max_data_frame(uint8_t *p, const ngtcp2_max_data *fr) { - ngtcp2_vec name, value; - - /* - * {"frame_type":"max_data","maximum":"0000000000000000000"} - */ -#define NGTCP2_QLOG_MAX_DATA_FRAME_OVERHEAD 57 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "max_data")); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "maximum"), fr->max_data); - *p++ = '}'; - - return p; -} - -static uint8_t *write_max_stream_data_frame(uint8_t *p, - const ngtcp2_max_stream_data *fr) { - ngtcp2_vec name, value; - - /* - * {"frame_type":"max_stream_data","stream_id":"0000000000000000000","maximum":"0000000000000000000"} - */ -#define NGTCP2_QLOG_MAX_STREAM_DATA_FRAME_OVERHEAD 98 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "max_stream_data")); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "stream_id"), - (uint64_t)fr->stream_id); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "maximum"), - fr->max_stream_data); - *p++ = '}'; - - return p; -} - -static uint8_t *write_max_streams_frame(uint8_t *p, - const ngtcp2_max_streams *fr) { - ngtcp2_vec name, value; - - /* - * {"frame_type":"max_streams","stream_type":"unidirectional","maximum":"0000000000000000000"} - */ -#define NGTCP2_QLOG_MAX_STREAMS_FRAME_OVERHEAD 91 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "max_streams")); - *p++ = ','; - p = write_pair(p, ngtcp2_vec_lit(&name, "stream_type"), - fr->type == NGTCP2_FRAME_MAX_STREAMS_BIDI - ? ngtcp2_vec_lit(&value, "bidirectional") - : ngtcp2_vec_lit(&value, "unidirectional")); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "maximum"), fr->max_streams); - *p++ = '}'; - - return p; -} - -static uint8_t *write_data_blocked_frame(uint8_t *p, - const ngtcp2_data_blocked *fr) { - ngtcp2_vec name, value; - (void)fr; - - /* - * {"frame_type":"data_blocked"} - */ -#define NGTCP2_QLOG_DATA_BLOCKED_FRAME_OVERHEAD 29 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "data_blocked")); - *p++ = '}'; - - return p; -} - -static uint8_t * -write_stream_data_blocked_frame(uint8_t *p, - const ngtcp2_stream_data_blocked *fr) { - ngtcp2_vec name, value; - (void)fr; - - /* - * {"frame_type":"stream_data_blocked"} - */ -#define NGTCP2_QLOG_STREAM_DATA_BLOCKED_FRAME_OVERHEAD 36 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "stream_data_blocked")); - *p++ = '}'; - - return p; -} - -static uint8_t *write_streams_blocked_frame(uint8_t *p, - const ngtcp2_streams_blocked *fr) { - ngtcp2_vec name, value; - (void)fr; - - /* - * {"frame_type":"streams_blocked"} - */ -#define NGTCP2_QLOG_STREAMS_BLOCKED_FRAME_OVERHEAD 32 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "streams_blocked")); - *p++ = '}'; - - return p; -} - -static uint8_t * -write_new_connection_id_frame(uint8_t *p, const ngtcp2_new_connection_id *fr) { - ngtcp2_vec name, value; - - /* - * {"frame_type":"new_connection_id","sequence_number":"0000000000000000000","retire_prior_to":"0000000000000000000","length":0000000000000000000,"connection_id":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","reset_token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} - */ -#define NGTCP2_QLOG_NEW_CONNECTION_ID_FRAME_OVERHEAD 251 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "new_connection_id")); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "sequence_number"), fr->seq); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "retire_prior_to"), - fr->retire_prior_to); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "length"), fr->cid.datalen); - *p++ = ','; - p = write_pair_cid(p, ngtcp2_vec_lit(&name, "connection_id"), &fr->cid); - *p++ = ','; - p = write_pair_hex(p, ngtcp2_vec_lit(&name, "reset_token"), - ngtcp2_vec_init(&value, fr->stateless_reset_token, - sizeof(fr->stateless_reset_token))); - *p++ = '}'; - - return p; -} - -static uint8_t * -write_retire_connection_id_frame(uint8_t *p, - const ngtcp2_retire_connection_id *fr) { - ngtcp2_vec name, value; - - /* - * {"frame_type":"retire_connection_id","sequence_number":"0000000000000000000"} - */ -#define NGTCP2_QLOG_RETIRE_CONNECTION_ID_FRAME_OVERHEAD 77 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "retire_connection_id")); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "sequence_number"), fr->seq); - *p++ = '}'; - - return p; -} - -static uint8_t *write_path_challenge_frame(uint8_t *p, - const ngtcp2_path_challenge *fr) { - ngtcp2_vec name, value; - - /* - * {"frame_type":"path_challenge","data":"xxxxxxxxxxxxxxxx"} - */ -#define NGTCP2_QLOG_PATH_CHALLENGE_FRAME_OVERHEAD 57 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "path_challenge")); - *p++ = ','; - p = write_pair_hex(p, ngtcp2_vec_lit(&name, "data"), - ngtcp2_vec_init(&value, fr->data, sizeof(fr->data))); - *p++ = '}'; - - return p; -} - -static uint8_t *write_path_response_frame(uint8_t *p, - const ngtcp2_path_response *fr) { - ngtcp2_vec name, value; - - /* - * {"frame_type":"path_response","data":"xxxxxxxxxxxxxxxx"} - */ -#define NGTCP2_QLOG_PATH_RESPONSE_FRAME_OVERHEAD 56 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "path_response")); - *p++ = ','; - p = write_pair_hex(p, ngtcp2_vec_lit(&name, "data"), - ngtcp2_vec_init(&value, fr->data, sizeof(fr->data))); - *p++ = '}'; - - return p; -} - -static uint8_t * -write_connection_close_frame(uint8_t *p, const ngtcp2_connection_close *fr) { - ngtcp2_vec name, value; - - /* - * {"frame_type":"connection_close","error_space":"application","error_code":0000000000000000000,"raw_error_code":0000000000000000000,"reason":""} - */ -#define NGTCP2_QLOG_CONNECTION_CLOSE_FRAME_OVERHEAD 143 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "connection_close")); - *p++ = ','; - p = write_pair(p, ngtcp2_vec_lit(&name, "error_space"), - fr->type == NGTCP2_FRAME_CONNECTION_CLOSE - ? ngtcp2_vec_lit(&value, "transport") - : ngtcp2_vec_lit(&value, "application")); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "error_code"), fr->error_code); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "raw_error_code"), - fr->error_code); - *p++ = ','; - /* TODO Write reason by escaping non-printables */ - p = write_pair(p, ngtcp2_vec_lit(&name, "reason"), - ngtcp2_vec_lit(&value, "")); - /* TODO Write trigger_frame_type */ - *p++ = '}'; - - return p; -} - -static uint8_t *write_handshake_done_frame(uint8_t *p, - const ngtcp2_handshake_done *fr) { - ngtcp2_vec name, value; - (void)fr; - - /* - * {"frame_type":"handshake_done"} - */ -#define NGTCP2_QLOG_HANDSHAKE_DONE_FRAME_OVERHEAD 31 - - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "frame_type"), - ngtcp2_vec_lit(&value, "handshake_done")); - *p++ = '}'; - - return p; -} - -static void qlog_pkt_write_start(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd, - int sent) { - uint8_t *p; - ngtcp2_vec name, value; - - if (!qlog->write) { - return; - } - - ngtcp2_buf_reset(&qlog->buf); - p = qlog->buf.last; - - *p++ = '['; - p = write_tstamp(p, qlog->last_ts - qlog->ts); - *p++ = ','; - p = write_string(p, ngtcp2_vec_lit(&value, "transport")); - *p++ = ','; - p = write_string(p, sent ? ngtcp2_vec_lit(&value, "packet_sent") - : ngtcp2_vec_lit(&value, "packet_received")); - *p++ = ','; - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "packet_type"), - qlog_pkt_type(&value, hd)); - *p++ = ','; - p = write_string(p, ngtcp2_vec_lit(&value, "frames")); - *p++ = ':'; - *p++ = '['; - - qlog->buf.last = p; -} - -static void qlog_pkt_write_end(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd, - size_t pktlen) { - uint8_t *p = qlog->buf.last; - ngtcp2_vec value; - - if (!qlog->write) { - return; - } - - /* - * ],"header":}], - */ -#define NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD (14 + NGTCP2_QLOG_PKT_HD_OVERHEAD) - - assert(ngtcp2_buf_left(&qlog->buf) >= NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD); - assert(ngtcp2_buf_len(&qlog->buf)); - - /* Eat last ',' */ - if (*(p - 1) == ',') { - --p; - } - *p++ = ']'; - *p++ = ','; - p = write_string(p, ngtcp2_vec_lit(&value, "header")); - *p++ = ':'; - p = write_pkt_hd(p, hd, pktlen); - *p++ = '}'; - *p++ = ']'; - *p++ = ','; - - qlog->buf.last = p; - - qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, qlog->buf.pos, - ngtcp2_buf_len(&qlog->buf)); -} - -void ngtcp2_qlog_write_frame(ngtcp2_qlog *qlog, const ngtcp2_frame *fr) { - uint8_t *p = qlog->buf.last; - - if (!qlog->write) { - return; - } - - switch (fr->type) { - case NGTCP2_FRAME_PADDING: - if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_PADDING_FRAME_OVERHEAD + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_padding_frame(p, &fr->padding); - break; - case NGTCP2_FRAME_PING: - if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_PING_FRAME_OVERHEAD + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_ping_frame(p, &fr->ping); - break; - case NGTCP2_FRAME_ACK: - case NGTCP2_FRAME_ACK_ECN: - if (ngtcp2_buf_left(&qlog->buf) < - NGTCP2_QLOG_ACK_FRAME_BASE_OVERHEAD + - NGTCP2_QLOG_ACK_FRAME_RANGE_OVERHEAD * (1 + fr->ack.num_blks) + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_ack_frame(p, &fr->ack); - break; - case NGTCP2_FRAME_RESET_STREAM: - if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_RESET_STREAM_FRAME_OVERHEAD + - 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_reset_stream_frame(p, &fr->reset_stream); - break; - case NGTCP2_FRAME_STOP_SENDING: - if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_STOP_SENDING_FRAME_OVERHEAD + - 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_stop_sending_frame(p, &fr->stop_sending); - break; - case NGTCP2_FRAME_CRYPTO: - if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_CRYPTO_FRAME_OVERHEAD + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_crypto_frame(p, &fr->crypto); - break; - case NGTCP2_FRAME_NEW_TOKEN: - if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_NEW_TOKEN_FRAME_OVERHEAD + - fr->new_token.token.len * 2 + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_new_token_frame(p, &fr->new_token); - break; - case NGTCP2_FRAME_STREAM: - if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_STREAM_FRAME_OVERHEAD + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_stream_frame(p, &fr->stream); - break; - case NGTCP2_FRAME_MAX_DATA: - if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_MAX_DATA_FRAME_OVERHEAD + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_max_data_frame(p, &fr->max_data); - break; - case NGTCP2_FRAME_MAX_STREAM_DATA: - if (ngtcp2_buf_left(&qlog->buf) < - NGTCP2_QLOG_MAX_STREAM_DATA_FRAME_OVERHEAD + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_max_stream_data_frame(p, &fr->max_stream_data); - break; - case NGTCP2_FRAME_MAX_STREAMS_BIDI: - case NGTCP2_FRAME_MAX_STREAMS_UNI: - if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_MAX_STREAMS_FRAME_OVERHEAD + - 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_max_streams_frame(p, &fr->max_streams); - break; - case NGTCP2_FRAME_DATA_BLOCKED: - if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_DATA_BLOCKED_FRAME_OVERHEAD + - 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_data_blocked_frame(p, &fr->data_blocked); - break; - case NGTCP2_FRAME_STREAM_DATA_BLOCKED: - if (ngtcp2_buf_left(&qlog->buf) < - NGTCP2_QLOG_STREAM_DATA_BLOCKED_FRAME_OVERHEAD + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_stream_data_blocked_frame(p, &fr->stream_data_blocked); - break; - case NGTCP2_FRAME_STREAMS_BLOCKED_BIDI: - case NGTCP2_FRAME_STREAMS_BLOCKED_UNI: - if (ngtcp2_buf_left(&qlog->buf) < - NGTCP2_QLOG_STREAMS_BLOCKED_FRAME_OVERHEAD + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_streams_blocked_frame(p, &fr->streams_blocked); - break; - case NGTCP2_FRAME_NEW_CONNECTION_ID: - if (ngtcp2_buf_left(&qlog->buf) < - NGTCP2_QLOG_NEW_CONNECTION_ID_FRAME_OVERHEAD + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_new_connection_id_frame(p, &fr->new_connection_id); - break; - case NGTCP2_FRAME_RETIRE_CONNECTION_ID: - if (ngtcp2_buf_left(&qlog->buf) < - NGTCP2_QLOG_RETIRE_CONNECTION_ID_FRAME_OVERHEAD + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_retire_connection_id_frame(p, &fr->retire_connection_id); - break; - case NGTCP2_FRAME_PATH_CHALLENGE: - if (ngtcp2_buf_left(&qlog->buf) < - NGTCP2_QLOG_PATH_CHALLENGE_FRAME_OVERHEAD + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_path_challenge_frame(p, &fr->path_challenge); - break; - case NGTCP2_FRAME_PATH_RESPONSE: - if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_PATH_RESPONSE_FRAME_OVERHEAD + - 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_path_response_frame(p, &fr->path_response); - break; - case NGTCP2_FRAME_CONNECTION_CLOSE: - case NGTCP2_FRAME_CONNECTION_CLOSE_APP: - if (ngtcp2_buf_left(&qlog->buf) < - NGTCP2_QLOG_CONNECTION_CLOSE_FRAME_OVERHEAD + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_connection_close_frame(p, &fr->connection_close); - break; - case NGTCP2_FRAME_HANDSHAKE_DONE: - if (ngtcp2_buf_left(&qlog->buf) < - NGTCP2_QLOG_HANDSHAKE_DONE_FRAME_OVERHEAD + 1 + - NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD) { - return; - } - p = write_handshake_done_frame(p, &fr->handshake_done); - break; - default: - assert(0); - } - - *p++ = ','; - - qlog->buf.last = p; -} - -void ngtcp2_qlog_pkt_received_start(ngtcp2_qlog *qlog, - const ngtcp2_pkt_hd *hd) { - qlog_pkt_write_start(qlog, hd, /* sent = */ 0); -} - -void ngtcp2_qlog_pkt_received_end(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd, - size_t pktlen) { - qlog_pkt_write_end(qlog, hd, pktlen); -} - -void ngtcp2_qlog_pkt_sent_start(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd) { - qlog_pkt_write_start(qlog, hd, /* sent = */ 1); -} - -void ngtcp2_qlog_pkt_sent_end(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd, - size_t pktlen) { - qlog_pkt_write_end(qlog, hd, pktlen); -} - -void ngtcp2_qlog_parameters_set_transport_params( - ngtcp2_qlog *qlog, const ngtcp2_transport_params *params, int server, - ngtcp2_qlog_side side) { - uint8_t buf[1024]; - uint8_t *p = buf; - ngtcp2_vec name, value; - const ngtcp2_preferred_addr *paddr; - - if (!qlog->write) { - return; - } - - *p++ = '['; - p = write_tstamp(p, qlog->last_ts - qlog->ts); - *p++ = ','; - p = write_string(p, ngtcp2_vec_lit(&value, "transport")); - *p++ = ','; - p = write_string(p, ngtcp2_vec_lit(&value, "parameters_set")); - *p++ = ','; - *p++ = '{'; - p = write_pair(p, ngtcp2_vec_lit(&name, "owner"), - side == NGTCP2_QLOG_SIDE_LOCAL - ? ngtcp2_vec_lit(&value, "local") - : ngtcp2_vec_lit(&value, "remote")); - *p++ = ','; - p = write_pair_cid(p, ngtcp2_vec_lit(&name, "initial_source_connection_id"), - ¶ms->initial_scid); - *p++ = ','; - if (side == (server ? NGTCP2_QLOG_SIDE_LOCAL : NGTCP2_QLOG_SIDE_REMOTE)) { - p = write_pair_cid( - p, ngtcp2_vec_lit(&name, "original_destination_connection_id"), - ¶ms->original_dcid); - *p++ = ','; - } - if (params->retry_scid_present) { - p = write_pair_cid(p, ngtcp2_vec_lit(&name, "retry_source_connection_id"), - ¶ms->retry_scid); - *p++ = ','; - } - if (params->stateless_reset_token_present) { - p = write_pair_hex(p, ngtcp2_vec_lit(&name, "stateless_reset_token"), - ngtcp2_vec_init(&value, params->stateless_reset_token, - sizeof(params->stateless_reset_token))); - *p++ = ','; - } - p = write_pair_bool(p, ngtcp2_vec_lit(&name, "disable_active_migration"), - params->disable_active_migration); - *p++ = ','; - p = write_pair_duration(p, ngtcp2_vec_lit(&name, "max_idle_timeout"), - params->max_idle_timeout); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "max_udp_payload_size"), - params->max_udp_payload_size); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "ack_delay_exponent"), - params->ack_delay_exponent); - *p++ = ','; - p = write_pair_duration(p, ngtcp2_vec_lit(&name, "max_ack_delay"), - params->max_ack_delay); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "active_connection_id_limit"), - params->active_connection_id_limit); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "initial_max_data"), - params->initial_max_data); - *p++ = ','; - p = write_pair_numstr( - p, ngtcp2_vec_lit(&name, "initial_max_stream_data_bidi_local"), - params->initial_max_stream_data_bidi_local); - *p++ = ','; - p = write_pair_numstr( - p, ngtcp2_vec_lit(&name, "initial_max_stream_data_bidi_remote"), - params->initial_max_stream_data_bidi_remote); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "initial_max_stream_data_uni"), - params->initial_max_stream_data_uni); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "initial_max_streams_bidi"), - params->initial_max_streams_bidi); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "initial_max_streams_uni"), - params->initial_max_streams_uni); - if (params->preferred_address_present) { - *p++ = ','; - paddr = ¶ms->preferred_address; - p = write_string(p, ngtcp2_vec_lit(&name, "preferred_address")); - *p++ = ':'; - *p++ = '{'; - p = write_pair_hex( - p, ngtcp2_vec_lit(&name, "ip_v4"), - ngtcp2_vec_init(&value, paddr->ipv4_addr, sizeof(paddr->ipv4_addr))); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "port_v4"), - paddr->ipv4_port); - *p++ = ','; - p = write_pair_hex( - p, ngtcp2_vec_lit(&name, "ip_v6"), - ngtcp2_vec_init(&value, paddr->ipv6_addr, sizeof(paddr->ipv6_addr))); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "port_v6"), - paddr->ipv6_port); - *p++ = ','; - p = write_pair_cid(p, ngtcp2_vec_lit(&name, "connection_id"), &paddr->cid); - *p++ = ','; - p = write_pair_hex(p, ngtcp2_vec_lit(&name, "stateless_reset_token"), - ngtcp2_vec_init(&value, paddr->stateless_reset_token, - sizeof(paddr->stateless_reset_token))); - *p++ = '}'; - } - *p++ = '}'; - *p++ = ']'; - *p++ = ','; - - qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, buf, - (size_t)(p - buf)); -} - -void ngtcp2_qlog_metrics_updated(ngtcp2_qlog *qlog, - const ngtcp2_conn_stat *cstat) { - uint8_t buf[1024]; - uint8_t *p = buf; - ngtcp2_vec name, value; - - if (!qlog->write) { - return; - } - - *p++ = '['; - p = write_tstamp(p, qlog->last_ts - qlog->ts); - *p++ = ','; - p = write_string(p, ngtcp2_vec_lit(&value, "recovery")); - *p++ = ','; - p = write_string(p, ngtcp2_vec_lit(&value, "metrics_updated")); - *p++ = ','; - *p++ = '{'; - - if (cstat->min_rtt != UINT64_MAX) { - p = write_pair_duration(p, ngtcp2_vec_lit(&name, "min_rtt"), - cstat->min_rtt); - *p++ = ','; - } - p = write_pair_duration(p, ngtcp2_vec_lit(&name, "smoothed_rtt"), - cstat->smoothed_rtt); - *p++ = ','; - p = write_pair_duration(p, ngtcp2_vec_lit(&name, "latest_rtt"), - cstat->latest_rtt); - *p++ = ','; - p = write_pair_duration(p, ngtcp2_vec_lit(&name, "rtt_variance"), - cstat->rttvar); - *p++ = ','; - /* TODO max_ack_delay? */ - p = write_pair_number(p, ngtcp2_vec_lit(&name, "pto_count"), - cstat->pto_count); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "congestion_window"), - cstat->cwnd); - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "bytes_in_flight"), - cstat->bytes_in_flight); - if (cstat->ssthresh != UINT64_MAX) { - *p++ = ','; - p = write_pair_number(p, ngtcp2_vec_lit(&name, "ssthresh"), - cstat->ssthresh); - } - - *p++ = '}'; - *p++ = ']'; - *p++ = ','; - - qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, buf, - (size_t)(p - buf)); -} - -void ngtcp2_qlog_pkt_lost(ngtcp2_qlog *qlog, ngtcp2_rtb_entry *ent) { - uint8_t buf[256]; - uint8_t *p = buf; - ngtcp2_vec name, value; - ngtcp2_pkt_hd hd; - - if (!qlog->write) { - return; - } - - *p++ = '['; - p = write_tstamp(p, qlog->last_ts - qlog->ts); - *p++ = ','; - p = write_string(p, ngtcp2_vec_lit(&value, "recovery")); - *p++ = ','; - p = write_string(p, ngtcp2_vec_lit(&value, "packet_lost")); - *p++ = ','; - *p++ = '{'; - - hd.type = ent->hd.type; - hd.flags = ent->hd.flags; - - p = write_pair(p, ngtcp2_vec_lit(&name, "packet_type"), - qlog_pkt_type(&value, &hd)); - *p++ = ','; - p = write_pair_numstr(p, ngtcp2_vec_lit(&name, "packet_number"), - (uint64_t)ent->hd.pkt_num); - *p++ = '}'; - *p++ = ']'; - *p++ = ','; - - qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, buf, - (size_t)(p - buf)); -} diff --git a/deps/ngtcp2/lib/ngtcp2_qlog.h b/deps/ngtcp2/lib/ngtcp2_qlog.h deleted file mode 100644 index 0709f92a3648dc..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_qlog.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_QLOG_H -#define NGTCP2_QLOG_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_pkt.h" -#include "ngtcp2_cc.h" -#include "ngtcp2_buf.h" -#include "ngtcp2_rtb.h" - -/* NGTCP2_QLOG_BUFLEN is the length of heap allocated buffer for - qlog. */ -#define NGTCP2_QLOG_BUFLEN 4096 - -typedef enum ngtcp2_qlog_side { - NGTCP2_QLOG_SIDE_LOCAL, - NGTCP2_QLOG_SIDE_REMOTE, -} ngtcp2_qlog_side; - -typedef struct ngtcp2_qlog { - /* write is a callback function to write qlog. */ - ngtcp2_qlog_write write; - /* ts is the initial timestamp */ - ngtcp2_tstamp ts; - /* last_ts is the timestamp observed last time. */ - ngtcp2_tstamp last_ts; - /* buf is a heap allocated buffer to write exclusively - packet_received and packet_sent. */ - ngtcp2_buf buf; - /* user_data is an opaque pointer which is passed to write - callback. */ - void *user_data; -} ngtcp2_qlog; - -/* - * ngtcp2_qlog_init initializes |qlog|. - */ -void ngtcp2_qlog_init(ngtcp2_qlog *qlog, ngtcp2_qlog_write write, - ngtcp2_tstamp ts, void *user_data); - -/* - * ngtcp2_qlog_start writes qlog preamble. - */ -void ngtcp2_qlog_start(ngtcp2_qlog *qlog, const ngtcp2_cid *odcid, int server); - -/* - * ngtcp2_qlog_end writes closing part of qlog. - */ -void ngtcp2_qlog_end(ngtcp2_qlog *qlog); - -/* - * ngtcp2_qlog_write_frame writes |fr| to qlog->buf. - * ngtcp2_qlog_pkt_received_start or ngtcp2_qlog_pkt_sent_start must - * be called before calling this function. - */ -void ngtcp2_qlog_write_frame(ngtcp2_qlog *qlog, const ngtcp2_frame *fr); - -/* - * ngtcp2_qlog_pkt_received_start starts to write packet_received - * event. It initializes qlog->buf. It writes qlog to qlog->buf. - * ngtcp2_qlog_pkt_received_end will flush the content of qlog->buf to - * write callback. - */ -void ngtcp2_qlog_pkt_received_start(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd); - -/* - * ngtcp2_qlog_pkt_received_end ends packet_received event and sends - * the content of qlog->buf to qlog->write callback. - */ -void ngtcp2_qlog_pkt_received_end(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd, - size_t pktlen); - -/* - * ngtcp2_qlog_pkt_sent_start starts to write packet_sent event. It - * initializes qlog->buf. It writes qlog to qlog->buf. - * ngtcp2_qlog_pkt_sent_end will flush the content of qlog->buf to - * write callback. - */ -void ngtcp2_qlog_pkt_sent_start(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd); - -/* - * ngtcp2_qlog_pkt_sent_end ends packet_sent event and sends the - * content of qlog->buf to qlog->write callback. - */ -void ngtcp2_qlog_pkt_sent_end(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd, - size_t pktlen); - -/* - * ngtcp2_qlog_parameters_set_transport_params writes |params| to qlog - * as parameters_set event. |server| is nonzero if the local endpoint - * is server. If |local| is nonzero, it is "owner" field becomes - * "local", otherwise "remote". - */ -void ngtcp2_qlog_parameters_set_transport_params( - ngtcp2_qlog *qlog, const ngtcp2_transport_params *params, int server, - ngtcp2_qlog_side side); - -/* - * ngtcp2_qlog_metrics_updated writes metrics_updated event of - * recovery category. - */ -void ngtcp2_qlog_metrics_updated(ngtcp2_qlog *qlog, - const ngtcp2_conn_stat *cstat); - -/* - * ngtcp2_qlog_pkt_lost writes packet_lost event. - */ -void ngtcp2_qlog_pkt_lost(ngtcp2_qlog *qlog, ngtcp2_rtb_entry *ent); - -/* connection_id_updated */ - -#endif /* NGTCP2_QLOG_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_range.c b/deps/ngtcp2/lib/ngtcp2_range.c deleted file mode 100644 index 9379496b7d4b53..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_range.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_range.h" -#include "ngtcp2_macro.h" - -void ngtcp2_range_init(ngtcp2_range *r, uint64_t begin, uint64_t end) { - r->begin = begin; - r->end = end; -} - -ngtcp2_range ngtcp2_range_intersect(const ngtcp2_range *a, - const ngtcp2_range *b) { - ngtcp2_range r = {0, 0}; - uint64_t begin = ngtcp2_max(a->begin, b->begin); - uint64_t end = ngtcp2_min(a->end, b->end); - if (begin < end) { - ngtcp2_range_init(&r, begin, end); - } - return r; -} - -uint64_t ngtcp2_range_len(const ngtcp2_range *r) { return r->end - r->begin; } - -int ngtcp2_range_eq(const ngtcp2_range *a, const ngtcp2_range *b) { - return a->begin == b->begin && a->end == b->end; -} - -void ngtcp2_range_cut(ngtcp2_range *left, ngtcp2_range *right, - const ngtcp2_range *a, const ngtcp2_range *b) { - /* Assume that b is included in a */ - left->begin = a->begin; - left->end = b->begin; - right->begin = b->end; - right->end = a->end; -} - -int ngtcp2_range_not_after(const ngtcp2_range *a, const ngtcp2_range *b) { - return a->end <= b->end; -} diff --git a/deps/ngtcp2/lib/ngtcp2_range.h b/deps/ngtcp2/lib/ngtcp2_range.h deleted file mode 100644 index 96b9a54b28f2d6..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_range.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_RANGE_H -#define NGTCP2_RANGE_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -/* - * ngtcp2_range represents half-closed range [begin, end). - */ -typedef struct { - uint64_t begin; - uint64_t end; -} ngtcp2_range; - -/* - * ngtcp2_range_init initializes |r| with the range [|begin|, |end|). - */ -void ngtcp2_range_init(ngtcp2_range *r, uint64_t begin, uint64_t end); - -/* - * ngtcp2_range_intersect returns the intersection of |a| and |b|. If - * they do not overlap, it returns empty range. - */ -ngtcp2_range ngtcp2_range_intersect(const ngtcp2_range *a, - const ngtcp2_range *b); - -/* - * ngtcp2_range_len returns the length of |r|. - */ -uint64_t ngtcp2_range_len(const ngtcp2_range *r); - -/* - * ngtcp2_range_eq returns nonzero if |a| equals |b|, such that - * a->begin == b->begin, and a->end == b->end hold. - */ -int ngtcp2_range_eq(const ngtcp2_range *a, const ngtcp2_range *b); - -/* - * ngtcp2_range_cut returns the left and right range after removing - * |b| from |a|. This function assumes that |a| completely includes - * |b|. In other words, a->begin <= b->begin and b->end <= a->end - * hold. - */ -void ngtcp2_range_cut(ngtcp2_range *left, ngtcp2_range *right, - const ngtcp2_range *a, const ngtcp2_range *b); - -/* - * ngtcp2_range_not_after returns nonzero if the right edge of |a| - * does not go beyond of the right edge of |b|. - */ -int ngtcp2_range_not_after(const ngtcp2_range *a, const ngtcp2_range *b); - -#endif /* NGTCP2_RANGE_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_rcvry.h b/deps/ngtcp2/lib/ngtcp2_rcvry.h deleted file mode 100644 index e392c34ebfedb7..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_rcvry.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_RCVRY_H -#define NGTCP2_RCVRY_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -/* NGTCP2_PKT_THRESHOLD is kPacketThreshold described in - draft-ietf-quic-recovery-22. */ -#define NGTCP2_PKT_THRESHOLD 3 - -/* NGTCP2_GRANULARITY is kGranularity described in - draft-ietf-quic-recovery-17. */ -#define NGTCP2_GRANULARITY NGTCP2_MILLISECONDS - -#endif /* NGTCP2_RCVRY_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_ringbuf.c b/deps/ngtcp2/lib/ngtcp2_ringbuf.c deleted file mode 100644 index e4deab1ff76b83..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_ringbuf.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_ringbuf.h" - -#include -#ifdef WIN32 -# include -#endif - -#include "ngtcp2_macro.h" - -#if defined(_MSC_VER) && defined(_M_ARM64) -unsigned int __popcnt(unsigned int x) { - unsigned int c = 0; - for (; x; ++c) { - x &= x - 1; - } - return c; -} -#endif - -int ngtcp2_ringbuf_init(ngtcp2_ringbuf *rb, size_t nmemb, size_t size, - const ngtcp2_mem *mem) { -#ifdef WIN32 - assert(1 == __popcnt((unsigned int)nmemb)); -#else - assert(1 == __builtin_popcount((unsigned int)nmemb)); -#endif - - rb->buf = ngtcp2_mem_malloc(mem, nmemb * size); - if (rb->buf == NULL) { - return NGTCP2_ERR_NOMEM; - } - - rb->mem = mem; - rb->nmemb = nmemb; - rb->size = size; - rb->first = 0; - rb->len = 0; - - return 0; -} - -void ngtcp2_ringbuf_free(ngtcp2_ringbuf *rb) { - if (rb == NULL) { - return; - } - - ngtcp2_mem_free(rb->mem, rb->buf); -} - -void *ngtcp2_ringbuf_push_front(ngtcp2_ringbuf *rb) { - rb->first = (rb->first - 1) & (rb->nmemb - 1); - rb->len = ngtcp2_min(rb->nmemb, rb->len + 1); - - return (void *)&rb->buf[rb->first * rb->size]; -} - -void *ngtcp2_ringbuf_push_back(ngtcp2_ringbuf *rb) { - size_t offset = (rb->first + rb->len) & (rb->nmemb - 1); - - if (rb->len == rb->nmemb) { - rb->first = (rb->first + 1) & (rb->nmemb - 1); - } else { - ++rb->len; - } - - return (void *)&rb->buf[offset * rb->size]; -} - -void ngtcp2_ringbuf_pop_front(ngtcp2_ringbuf *rb) { - rb->first = (rb->first + 1) & (rb->nmemb - 1); - --rb->len; -} - -void ngtcp2_ringbuf_pop_back(ngtcp2_ringbuf *rb) { - assert(rb->len); - --rb->len; -} - -void ngtcp2_ringbuf_resize(ngtcp2_ringbuf *rb, size_t len) { - assert(len <= rb->nmemb); - rb->len = len; -} - -void *ngtcp2_ringbuf_get(ngtcp2_ringbuf *rb, size_t offset) { - assert(offset < rb->len); - offset = (rb->first + offset) & (rb->nmemb - 1); - return &rb->buf[offset * rb->size]; -} - -int ngtcp2_ringbuf_full(ngtcp2_ringbuf *rb) { return rb->len == rb->nmemb; } diff --git a/deps/ngtcp2/lib/ngtcp2_ringbuf.h b/deps/ngtcp2/lib/ngtcp2_ringbuf.h deleted file mode 100644 index 6d546495f2ac51..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_ringbuf.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_RINGBUF_H -#define NGTCP2_RINGBUF_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_mem.h" - -typedef struct { - /* buf points to the underlying buffer. */ - uint8_t *buf; - const ngtcp2_mem *mem; - /* nmemb is the number of elements that can be stored in this ring - buffer. */ - size_t nmemb; - /* size is the size of each element. */ - size_t size; - /* first is the offset to the first element. */ - size_t first; - /* len is the number of elements actually stored. */ - size_t len; -} ngtcp2_ringbuf; - -/* - * ngtcp2_ringbuf_init initializes |rb|. |nmemb| is the number of - * elements that can be stored in this buffer. |size| is the size of - * each element. |size| must be power of 2. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_ringbuf_init(ngtcp2_ringbuf *rb, size_t nmemb, size_t size, - const ngtcp2_mem *mem); - -/* - * ngtcp2_ringbuf_free frees resources allocated for |rb|. This - * function does not free the memory pointed by |rb|. - */ -void ngtcp2_ringbuf_free(ngtcp2_ringbuf *rb); - -/* ngtcp2_ringbuf_push_front moves the offset to the first element in - the buffer backward, and returns the pointer to the element. - Caller can store data to the buffer pointed by the returned - pointer. If this action exceeds the capacity of the ring buffer, - the last element is silently overwritten, and rb->len remains - unchanged. */ -void *ngtcp2_ringbuf_push_front(ngtcp2_ringbuf *rb); - -/* ngtcp2_ringbuf_push_back moves the offset to the last element in - the buffer forward, and returns the pointer to the element. Caller - can store data to the buffer pointed by the returned pointer. If - this action exceeds the capacity of the ring buffer, the first - element is silently overwritten, and rb->len remains unchanged. */ -void *ngtcp2_ringbuf_push_back(ngtcp2_ringbuf *rb); - -/* - * ngtcp2_ringbuf_pop_front removes first element in |rb|. - */ -void ngtcp2_ringbuf_pop_front(ngtcp2_ringbuf *rb); - -/* - * ngtcp2_ringbuf_pop_back removes the last element in |rb|. - */ -void ngtcp2_ringbuf_pop_back(ngtcp2_ringbuf *rb); - -/* ngtcp2_ringbuf_resize changes the number of elements stored. This - does not change the capacity of the underlying buffer. */ -void ngtcp2_ringbuf_resize(ngtcp2_ringbuf *rb, size_t len); - -/* ngtcp2_ringbuf_get returns the pointer to the element at - |offset|. */ -void *ngtcp2_ringbuf_get(ngtcp2_ringbuf *rb, size_t offset); - -/* ngtcp2_ringbuf_len returns the number of elements stored. */ -#define ngtcp2_ringbuf_len(RB) ((RB)->len) - -/* ngtcp2_ringbuf_full returns nonzero if |rb| is full. */ -int ngtcp2_ringbuf_full(ngtcp2_ringbuf *rb); - -#endif /* NGTCP2_RINGBUF_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_rob.c b/deps/ngtcp2/lib/ngtcp2_rob.c deleted file mode 100644 index 499c07ec6be247..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_rob.c +++ /dev/null @@ -1,327 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_rob.h" - -#include -#include - -#include "ngtcp2_macro.h" - -int ngtcp2_rob_gap_new(ngtcp2_rob_gap **pg, uint64_t begin, uint64_t end, - const ngtcp2_mem *mem) { - *pg = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_rob_gap)); - if (*pg == NULL) { - return NGTCP2_ERR_NOMEM; - } - - (*pg)->range.begin = begin; - (*pg)->range.end = end; - - return 0; -} - -void ngtcp2_rob_gap_del(ngtcp2_rob_gap *g, const ngtcp2_mem *mem) { - ngtcp2_mem_free(mem, g); -} - -int ngtcp2_rob_data_new(ngtcp2_rob_data **pd, uint64_t offset, size_t chunk, - const ngtcp2_mem *mem) { - *pd = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_rob_data) + chunk); - if (*pd == NULL) { - return NGTCP2_ERR_NOMEM; - } - - (*pd)->range.begin = offset; - (*pd)->range.end = offset + chunk; - (*pd)->begin = (uint8_t *)(*pd) + sizeof(ngtcp2_rob_data); - (*pd)->end = (*pd)->begin + chunk; - - return 0; -} - -void ngtcp2_rob_data_del(ngtcp2_rob_data *d, const ngtcp2_mem *mem) { - ngtcp2_mem_free(mem, d); -} - -int ngtcp2_rob_init(ngtcp2_rob *rob, size_t chunk, const ngtcp2_mem *mem) { - int rv; - ngtcp2_rob_gap *g; - - rv = ngtcp2_ksl_init(&rob->gapksl, ngtcp2_ksl_range_compar, - sizeof(ngtcp2_range), mem); - if (rv != 0) { - goto fail_gapksl_ksl_init; - } - - rv = ngtcp2_rob_gap_new(&g, 0, UINT64_MAX, mem); - if (rv != 0) { - goto fail_rob_gap_new; - } - - rv = ngtcp2_ksl_insert(&rob->gapksl, NULL, &g->range, g); - if (rv != 0) { - goto fail_gapksl_ksl_insert; - } - - rv = ngtcp2_ksl_init(&rob->dataksl, ngtcp2_ksl_range_compar, - sizeof(ngtcp2_range), mem); - if (rv != 0) { - goto fail_dataksl_ksl_init; - } - - rob->chunk = chunk; - rob->mem = mem; - - return 0; - -fail_dataksl_ksl_init: -fail_gapksl_ksl_insert: - ngtcp2_rob_gap_del(g, mem); -fail_rob_gap_new: - ngtcp2_ksl_free(&rob->gapksl); -fail_gapksl_ksl_init: - return rv; -} - -void ngtcp2_rob_free(ngtcp2_rob *rob) { - ngtcp2_ksl_it it; - - if (rob == NULL) { - return; - } - - for (it = ngtcp2_ksl_begin(&rob->dataksl); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - ngtcp2_rob_data_del(ngtcp2_ksl_it_get(&it), rob->mem); - } - - for (it = ngtcp2_ksl_begin(&rob->gapksl); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - ngtcp2_rob_gap_del(ngtcp2_ksl_it_get(&it), rob->mem); - } - - ngtcp2_ksl_free(&rob->dataksl); - ngtcp2_ksl_free(&rob->gapksl); -} - -static int rob_write_data(ngtcp2_rob *rob, uint64_t offset, const uint8_t *data, - size_t len) { - size_t n; - int rv; - ngtcp2_rob_data *d; - ngtcp2_range range = {offset, offset + len}; - ngtcp2_ksl_it it; - - for (it = ngtcp2_ksl_lower_bound_compar(&rob->dataksl, &range, - ngtcp2_ksl_range_exclusive_compar); - len; ngtcp2_ksl_it_next(&it)) { - if (ngtcp2_ksl_it_end(&it)) { - d = NULL; - } else { - d = ngtcp2_ksl_it_get(&it); - } - - if (d == NULL || offset < d->range.begin) { - rv = ngtcp2_rob_data_new(&d, (offset / rob->chunk) * rob->chunk, - rob->chunk, rob->mem); - if (rv != 0) { - return rv; - } - - rv = ngtcp2_ksl_insert(&rob->dataksl, &it, &d->range, d); - if (rv != 0) { - ngtcp2_rob_data_del(d, rob->mem); - return rv; - } - } - - n = (size_t)ngtcp2_min((uint64_t)len, d->range.begin + rob->chunk - offset); - memcpy(d->begin + (offset - d->range.begin), data, n); - offset += n; - data += n; - len -= n; - } - - return 0; -} - -int ngtcp2_rob_push(ngtcp2_rob *rob, uint64_t offset, const uint8_t *data, - size_t datalen) { - int rv; - ngtcp2_rob_gap *g; - ngtcp2_range m, l, r, q = {offset, offset + datalen}; - ngtcp2_ksl_it it; - - it = ngtcp2_ksl_lower_bound_compar(&rob->gapksl, &q, - ngtcp2_ksl_range_exclusive_compar); - - for (; !ngtcp2_ksl_it_end(&it);) { - g = ngtcp2_ksl_it_get(&it); - - m = ngtcp2_range_intersect(&q, &g->range); - if (!ngtcp2_range_len(&m)) { - break; - } - if (ngtcp2_range_eq(&g->range, &m)) { - ngtcp2_ksl_remove(&rob->gapksl, &it, &g->range); - ngtcp2_rob_gap_del(g, rob->mem); - rv = rob_write_data(rob, m.begin, data + (m.begin - offset), - (size_t)ngtcp2_range_len(&m)); - if (rv != 0) { - return rv; - } - - continue; - } - ngtcp2_range_cut(&l, &r, &g->range, &m); - if (ngtcp2_range_len(&l)) { - ngtcp2_ksl_update_key(&rob->gapksl, &g->range, &l); - g->range = l; - - if (ngtcp2_range_len(&r)) { - ngtcp2_rob_gap *ng; - rv = ngtcp2_rob_gap_new(&ng, r.begin, r.end, rob->mem); - if (rv != 0) { - return rv; - } - rv = ngtcp2_ksl_insert(&rob->gapksl, &it, &ng->range, ng); - if (rv != 0) { - ngtcp2_rob_gap_del(ng, rob->mem); - return rv; - } - } - } else if (ngtcp2_range_len(&r)) { - ngtcp2_ksl_update_key(&rob->gapksl, &g->range, &r); - g->range = r; - } - rv = rob_write_data(rob, m.begin, data + (m.begin - offset), - (size_t)ngtcp2_range_len(&m)); - if (rv != 0) { - return rv; - } - ngtcp2_ksl_it_next(&it); - } - return 0; -} - -int ngtcp2_rob_remove_prefix(ngtcp2_rob *rob, uint64_t offset) { - ngtcp2_rob_gap *g; - ngtcp2_rob_data *d; - ngtcp2_ksl_it it; - - it = ngtcp2_ksl_begin(&rob->gapksl); - - for (; !ngtcp2_ksl_it_end(&it);) { - g = ngtcp2_ksl_it_get(&it); - if (offset <= g->range.begin) { - break; - } - if (offset < g->range.end) { - ngtcp2_range r = {offset, g->range.end}; - ngtcp2_ksl_update_key(&rob->gapksl, &g->range, &r); - g->range.begin = offset; - break; - } - ngtcp2_ksl_remove(&rob->gapksl, &it, &g->range); - ngtcp2_rob_gap_del(g, rob->mem); - } - - it = ngtcp2_ksl_begin(&rob->dataksl); - - for (; !ngtcp2_ksl_it_end(&it);) { - d = ngtcp2_ksl_it_get(&it); - if (offset < d->range.begin + rob->chunk) { - return 0; - } - ngtcp2_ksl_remove(&rob->dataksl, &it, &d->range); - ngtcp2_rob_data_del(d, rob->mem); - } - - return 0; -} - -size_t ngtcp2_rob_data_at(ngtcp2_rob *rob, const uint8_t **pdest, - uint64_t offset) { - ngtcp2_rob_gap *g; - ngtcp2_rob_data *d; - ngtcp2_ksl_it it; - - it = ngtcp2_ksl_begin(&rob->gapksl); - if (ngtcp2_ksl_it_end(&it)) { - return 0; - } - - g = ngtcp2_ksl_it_get(&it); - - if (g->range.begin <= offset) { - return 0; - } - - it = ngtcp2_ksl_begin(&rob->dataksl); - d = ngtcp2_ksl_it_get(&it); - - assert(d); - assert(d->range.begin <= offset); - assert(offset < d->range.begin + rob->chunk); - - *pdest = d->begin + (offset - d->range.begin); - - return (size_t)(ngtcp2_min(g->range.begin, d->range.begin + rob->chunk) - - offset); -} - -void ngtcp2_rob_pop(ngtcp2_rob *rob, uint64_t offset, size_t len) { - ngtcp2_ksl_it it; - ngtcp2_rob_data *d; - - it = ngtcp2_ksl_begin(&rob->dataksl); - d = ngtcp2_ksl_it_get(&it); - - assert(d); - - if (offset + len < d->range.begin + rob->chunk) { - return; - } - - ngtcp2_ksl_remove(&rob->dataksl, NULL, &d->range); - ngtcp2_rob_data_del(d, rob->mem); -} - -uint64_t ngtcp2_rob_first_gap_offset(ngtcp2_rob *rob) { - ngtcp2_ksl_it it = ngtcp2_ksl_begin(&rob->gapksl); - ngtcp2_rob_gap *g; - - if (ngtcp2_ksl_it_end(&it)) { - return UINT64_MAX; - } - - g = ngtcp2_ksl_it_get(&it); - - return g->range.begin; -} - -int ngtcp2_rob_data_buffered(ngtcp2_rob *rob) { - return ngtcp2_ksl_len(&rob->dataksl) != 0; -} diff --git a/deps/ngtcp2/lib/ngtcp2_rob.h b/deps/ngtcp2/lib/ngtcp2_rob.h deleted file mode 100644 index c6a039ce408de6..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_rob.h +++ /dev/null @@ -1,203 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_ROB_H -#define NGTCP2_ROB_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_mem.h" -#include "ngtcp2_range.h" -#include "ngtcp2_ksl.h" - -struct ngtcp2_rob_gap; -typedef struct ngtcp2_rob_gap ngtcp2_rob_gap; - -/* - * ngtcp2_rob_gap represents the gap, which is the range of stream - * data that is not received yet. - */ -struct ngtcp2_rob_gap { - /* range is the range of this gap. */ - ngtcp2_range range; -}; - -/* - * ngtcp2_rob_gap_new allocates new ngtcp2_rob_gap object, and assigns - * its pointer to |*pg|. The caller should call ngtcp2_rob_gap_del to - * delete it when it is no longer used. The range of the gap is - * [begin, end). |mem| is custom memory allocator to allocate memory. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_rob_gap_new(ngtcp2_rob_gap **pg, uint64_t begin, uint64_t end, - const ngtcp2_mem *mem); - -/* - * ngtcp2_rob_gap_del deallocates |g|. It deallocates the memory - * pointed by |g| it self. |mem| is custom memory allocator to - * deallocate memory. - */ -void ngtcp2_rob_gap_del(ngtcp2_rob_gap *g, const ngtcp2_mem *mem); - -struct ngtcp2_rob_data; -typedef struct ngtcp2_rob_data ngtcp2_rob_data; - -/* - * ngtcp2_rob_data holds the buffered stream data. - */ -struct ngtcp2_rob_data { - /* range is the range of this gap. */ - ngtcp2_range range; - /* begin points to the buffer. */ - uint8_t *begin; - /* end points to the one beyond of the last byte of the buffer */ - uint8_t *end; -}; - -/* - * ngtcp2_rob_data_new allocates new ngtcp2_rob_data object, and - * assigns its pointer to |*pd|. The caller should call - * ngtcp2_rob_data_del to delete it when it is no longer used. - * |offset| is the stream offset of the first byte of this data. - * |chunk| is the size of the buffer. |offset| must be multiple of - * |chunk|. |mem| is custom memory allocator to allocate memory. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_rob_data_new(ngtcp2_rob_data **pd, uint64_t offset, size_t chunk, - const ngtcp2_mem *mem); - -/* - * ngtcp2_rob_data_del deallocates |d|. It deallocates the memory - * pointed by |d| itself. |mem| is custom memory allocator to - * deallocate memory. - */ -void ngtcp2_rob_data_del(ngtcp2_rob_data *d, const ngtcp2_mem *mem); - -/* - * ngtcp2_rob is the reorder buffer which reassembles stream data - * received in out of order. - */ -typedef struct { - /* gapksl maintains the range of offset which is not received - yet. Initially, its range is [0, UINT64_MAX). */ - ngtcp2_ksl gapksl; - /* dataksl maintains the list of buffers which store received data - ordered by stream offset. */ - ngtcp2_ksl dataksl; - /* mem is custom memory allocator */ - const ngtcp2_mem *mem; - /* chunk is the size of each buffer in data field */ - size_t chunk; -} ngtcp2_rob; - -/* - * ngtcp2_rob_init initializes |rob|. |chunk| is the size of buffer - * per chunk. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_rob_init(ngtcp2_rob *rob, size_t chunk, const ngtcp2_mem *mem); - -/* - * ngtcp2_rob_free frees resources allocated for |rob|. - */ -void ngtcp2_rob_free(ngtcp2_rob *rob); - -/* - * ngtcp2_rob_push adds new data of length |datalen| at the stream - * offset |offset|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -int ngtcp2_rob_push(ngtcp2_rob *rob, uint64_t offset, const uint8_t *data, - size_t datalen); - -/* - * ngtcp2_rob_remove_prefix removes gap up to |offset|, exclusive. It - * also removes data buffer if it is completely included in |offset|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -int ngtcp2_rob_remove_prefix(ngtcp2_rob *rob, uint64_t offset); - -/* - * ngtcp2_rob_data_at stores the pointer to the buffer of stream - * offset |offset| to |*pdest| if it is available, and returns the - * valid length of available data. If no data is available, it - * returns 0. - */ -size_t ngtcp2_rob_data_at(ngtcp2_rob *rob, const uint8_t **pdest, - uint64_t offset); - -/* - * ngtcp2_rob_pop clears data at stream offset |offset| of length - * |len|. - * - * |offset| must be the offset given in ngtcp2_rob_data_at. |len| - * must be the return value of ngtcp2_rob_data_at when |offset| is - * passed. - * - * Caller should call this function from offset 0 in non-decreasing - * order. - */ -void ngtcp2_rob_pop(ngtcp2_rob *rob, uint64_t offset, size_t len); - -/* - * ngtcp2_rob_first_gap_offset returns the offset to the first gap. - * If there is no gap, it returns UINT64_MAX. - */ -uint64_t ngtcp2_rob_first_gap_offset(ngtcp2_rob *rob); - -/* - * ngtcp2_rob_data_buffered returns nonzero if any data is buffered. - */ -int ngtcp2_rob_data_buffered(ngtcp2_rob *rob); - -#endif /* NGTCP2_ROB_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_rst.c b/deps/ngtcp2/lib/ngtcp2_rst.c deleted file mode 100644 index e546fdf85c623b..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_rst.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_rst.h" -#include "ngtcp2_rtb.h" -#include "ngtcp2_cc.h" -#include "ngtcp2_macro.h" - -void ngtcp2_rs_init(ngtcp2_rs *rs) { - rs->interval = UINT64_MAX; - rs->delivered = 0; - rs->prior_delivered = 0; - rs->prior_ts = 0; - rs->send_elapsed = 0; - rs->ack_elapsed = 0; - rs->is_app_limited = 0; -} - -void ngtcp2_rst_init(ngtcp2_rst *rst) { - ngtcp2_rs_init(&rst->rs); - rst->delivered = 0; - rst->delivered_ts = 0; - rst->first_sent_ts = 0; - rst->app_limited = 0; -} - -void ngtcp2_rst_on_pkt_sent(ngtcp2_rst *rst, ngtcp2_rtb_entry *ent, - const ngtcp2_conn_stat *cstat) { - if (cstat->bytes_in_flight == 0) { - rst->first_sent_ts = rst->delivered_ts = ent->ts; - } - ent->rst.first_sent_ts = rst->first_sent_ts; - ent->rst.delivered_ts = rst->delivered_ts; - ent->rst.delivered = rst->delivered; - ent->rst.is_app_limited = rst->app_limited != 0; -} - -int ngtcp2_rst_on_ack_recv(ngtcp2_rst *rst, ngtcp2_conn_stat *cstat) { - ngtcp2_rs *rs = &rst->rs; - - if (rst->app_limited && rst->delivered > rst->app_limited) { - rst->app_limited = 0; - } - - if (rs->prior_ts == 0) { - return 0; - } - - rs->interval = ngtcp2_max(rs->send_elapsed, rs->ack_elapsed); - - rs->delivered = rst->delivered - rs->prior_delivered; - - if (rs->interval < cstat->min_rtt) { - rs->interval = UINT64_MAX; - return 0; - } - - if (rs->interval) { - cstat->delivery_rate_sec = rs->delivered * NGTCP2_SECONDS / rs->interval; - } - - return 0; -} - -void ngtcp2_rst_update_rate_sample(ngtcp2_rst *rst, const ngtcp2_rtb_entry *ent, - ngtcp2_tstamp ts) { - ngtcp2_rs *rs = &rst->rs; - - rst->delivered += ent->pktlen; - rst->delivered_ts = ts; - - if (ent->rst.delivered > rs->prior_delivered) { - rs->prior_delivered = ent->rst.delivered; - rs->prior_ts = ent->rst.delivered_ts; - rs->is_app_limited = ent->rst.is_app_limited; - rs->send_elapsed = ent->ts - ent->rst.first_sent_ts; - rs->ack_elapsed = rst->delivered_ts - ent->rst.delivered_ts; - rst->first_sent_ts = ent->ts; - } -} - -void ngtcp2_rst_update_app_limited(ngtcp2_rst *rst, ngtcp2_conn_stat *cstat) { - (void)rst; - (void)cstat; - /* TODO Not implemented */ -} diff --git a/deps/ngtcp2/lib/ngtcp2_rst.h b/deps/ngtcp2/lib/ngtcp2_rst.h deleted file mode 100644 index f68a1f9b22d8b5..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_rst.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_RST_H -#define NGTCP2_RST_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -struct ngtcp2_rtb_entry; -typedef struct ngtcp2_rtb_entry ngtcp2_rtb_entry; - -/** - * @struct - * - * ngtcp2_rs contains connection state for delivery rate estimation. - */ -typedef struct ngtcp2_rs { - ngtcp2_duration interval; - uint64_t delivered; - uint64_t prior_delivered; - ngtcp2_tstamp prior_ts; - ngtcp2_duration send_elapsed; - ngtcp2_duration ack_elapsed; - int is_app_limited; -} ngtcp2_rs; - -void ngtcp2_rs_init(ngtcp2_rs *rs); - -/* - * ngtcp2_rst implements delivery rate estimation described in - * https://tools.ietf.org/html/draft-cheng-iccrg-delivery-rate-estimation-00 - */ -typedef struct ngtcp2_rst { - ngtcp2_rs rs; - uint64_t delivered; - ngtcp2_tstamp delivered_ts; - ngtcp2_tstamp first_sent_ts; - uint64_t app_limited; -} ngtcp2_rst; - -void ngtcp2_rst_init(ngtcp2_rst *rst); - -void ngtcp2_rst_on_pkt_sent(ngtcp2_rst *rst, ngtcp2_rtb_entry *ent, - const ngtcp2_conn_stat *cstat); -int ngtcp2_rst_on_ack_recv(ngtcp2_rst *rst, ngtcp2_conn_stat *cstat); -void ngtcp2_rst_update_rate_sample(ngtcp2_rst *rst, const ngtcp2_rtb_entry *ent, - ngtcp2_tstamp ts); -void ngtcp2_rst_update_app_limited(ngtcp2_rst *rst, ngtcp2_conn_stat *cstat); - -#endif /* NGTCP2_RST_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_rtb.c b/deps/ngtcp2/lib/ngtcp2_rtb.c deleted file mode 100644 index d58a6b2ea1adb7..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_rtb.c +++ /dev/null @@ -1,1172 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_rtb.h" - -#include -#include - -#include "ngtcp2_macro.h" -#include "ngtcp2_conn.h" -#include "ngtcp2_log.h" -#include "ngtcp2_vec.h" -#include "ngtcp2_cc.h" -#include "ngtcp2_rcvry.h" -#include "ngtcp2_rst.h" - -int ngtcp2_frame_chain_new(ngtcp2_frame_chain **pfrc, const ngtcp2_mem *mem) { - *pfrc = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_frame_chain)); - if (*pfrc == NULL) { - return NGTCP2_ERR_NOMEM; - } - - ngtcp2_frame_chain_init(*pfrc); - - return 0; -} - -int ngtcp2_frame_chain_extralen_new(ngtcp2_frame_chain **pfrc, size_t extralen, - const ngtcp2_mem *mem) { - *pfrc = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_frame_chain) + extralen); - if (*pfrc == NULL) { - return NGTCP2_ERR_NOMEM; - } - - ngtcp2_frame_chain_init(*pfrc); - - return 0; -} - -int ngtcp2_frame_chain_stream_datacnt_new(ngtcp2_frame_chain **pfrc, - size_t datacnt, - const ngtcp2_mem *mem) { - size_t need = sizeof(ngtcp2_vec) * (datacnt - 1); - size_t avail = sizeof(ngtcp2_frame) - sizeof(ngtcp2_stream); - - if (datacnt > 0 && need > avail) { - return ngtcp2_frame_chain_extralen_new(pfrc, need - avail, mem); - } - - return ngtcp2_frame_chain_new(pfrc, mem); -} - -int ngtcp2_frame_chain_crypto_datacnt_new(ngtcp2_frame_chain **pfrc, - size_t datacnt, - const ngtcp2_mem *mem) { - size_t need = sizeof(ngtcp2_vec) * (datacnt - 1); - size_t avail = sizeof(ngtcp2_frame) - sizeof(ngtcp2_crypto); - - if (datacnt > 0 && need > avail) { - return ngtcp2_frame_chain_extralen_new(pfrc, need - avail, mem); - } - - return ngtcp2_frame_chain_new(pfrc, mem); -} - -int ngtcp2_frame_chain_new_token_new(ngtcp2_frame_chain **pfrc, - const ngtcp2_vec *token, - const ngtcp2_mem *mem) { - size_t avail = sizeof(ngtcp2_frame) - sizeof(ngtcp2_new_token); - int rv; - uint8_t *p; - ngtcp2_frame *fr; - - if (token->len > avail) { - rv = ngtcp2_frame_chain_extralen_new(pfrc, token->len - avail, mem); - } else { - rv = ngtcp2_frame_chain_new(pfrc, mem); - } - if (rv != 0) { - return rv; - } - - fr = &(*pfrc)->fr; - fr->type = NGTCP2_FRAME_NEW_TOKEN; - - p = (uint8_t *)(*pfrc) + sizeof(ngtcp2_new_token); - memcpy(p, token->base, token->len); - - ngtcp2_vec_init(&fr->new_token.token, p, token->len); - - return 0; -} - -void ngtcp2_frame_chain_del(ngtcp2_frame_chain *frc, const ngtcp2_mem *mem) { - ngtcp2_frame_chain_binder *binder; - - if (frc == NULL) { - return; - } - - binder = frc->binder; - if (binder && --binder->refcount == 0) { - ngtcp2_mem_free(mem, binder); - } - - ngtcp2_mem_free(mem, frc); -} - -void ngtcp2_frame_chain_init(ngtcp2_frame_chain *frc) { - frc->next = NULL; - frc->binder = NULL; -} - -void ngtcp2_frame_chain_list_del(ngtcp2_frame_chain *frc, - const ngtcp2_mem *mem) { - ngtcp2_frame_chain *next; - - for (; frc;) { - next = frc->next; - ngtcp2_frame_chain_del(frc, mem); - frc = next; - } -} - -int ngtcp2_frame_chain_binder_new(ngtcp2_frame_chain_binder **pbinder, - const ngtcp2_mem *mem) { - *pbinder = ngtcp2_mem_calloc(mem, 1, sizeof(ngtcp2_frame_chain_binder)); - if (*pbinder == NULL) { - return NGTCP2_ERR_NOMEM; - } - - return 0; -} - -int ngtcp2_bind_frame_chains(ngtcp2_frame_chain *a, ngtcp2_frame_chain *b, - const ngtcp2_mem *mem) { - ngtcp2_frame_chain_binder *binder; - int rv; - - assert(b->binder == NULL); - - if (a->binder == NULL) { - rv = ngtcp2_frame_chain_binder_new(&binder, mem); - if (rv != 0) { - return rv; - } - - a->binder = binder; - ++a->binder->refcount; - } - - b->binder = a->binder; - ++b->binder->refcount; - - return 0; -} - -int ngtcp2_rtb_entry_new(ngtcp2_rtb_entry **pent, const ngtcp2_pkt_hd *hd, - ngtcp2_frame_chain *frc, ngtcp2_tstamp ts, - size_t pktlen, uint8_t flags, const ngtcp2_mem *mem) { - (*pent) = ngtcp2_mem_calloc(mem, 1, sizeof(ngtcp2_rtb_entry)); - if (*pent == NULL) { - return NGTCP2_ERR_NOMEM; - } - - (*pent)->hd.pkt_num = hd->pkt_num; - (*pent)->hd.type = hd->type; - (*pent)->hd.flags = hd->flags; - (*pent)->frc = frc; - (*pent)->ts = ts; - (*pent)->lost_ts = UINT64_MAX; - (*pent)->pktlen = pktlen; - (*pent)->flags = flags; - (*pent)->next = NULL; - - return 0; -} - -void ngtcp2_rtb_entry_del(ngtcp2_rtb_entry *ent, const ngtcp2_mem *mem) { - if (ent == NULL) { - return; - } - - ngtcp2_frame_chain_list_del(ent->frc, mem); - - ngtcp2_mem_free(mem, ent); -} - -static int greater(const ngtcp2_ksl_key *lhs, const ngtcp2_ksl_key *rhs) { - return *(int64_t *)lhs > *(int64_t *)rhs; -} - -void ngtcp2_rtb_init(ngtcp2_rtb *rtb, ngtcp2_pktns_id pktns_id, - ngtcp2_strm *crypto, ngtcp2_rst *rst, ngtcp2_cc *cc, - ngtcp2_log *log, ngtcp2_qlog *qlog, - const ngtcp2_mem *mem) { - ngtcp2_ksl_init(&rtb->ents, greater, sizeof(int64_t), mem); - rtb->crypto = crypto; - rtb->rst = rst; - rtb->cc = cc; - rtb->log = log; - rtb->qlog = qlog; - rtb->mem = mem; - rtb->largest_acked_tx_pkt_num = -1; - rtb->num_ack_eliciting = 0; - rtb->num_retransmittable = 0; - rtb->probe_pkt_left = 0; - rtb->pktns_id = pktns_id; - rtb->cc_pkt_num = 0; - rtb->cc_bytes_in_flight = 0; - rtb->persistent_congestion_start_ts = UINT64_MAX; - rtb->num_lost_pkts = 0; -} - -void ngtcp2_rtb_free(ngtcp2_rtb *rtb) { - ngtcp2_ksl_it it; - - if (rtb == NULL) { - return; - } - - it = ngtcp2_ksl_begin(&rtb->ents); - - for (; !ngtcp2_ksl_it_end(&it); ngtcp2_ksl_it_next(&it)) { - ngtcp2_rtb_entry_del(ngtcp2_ksl_it_get(&it), rtb->mem); - } - - ngtcp2_ksl_free(&rtb->ents); -} - -static void rtb_on_add(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent, - ngtcp2_conn_stat *cstat) { - ngtcp2_rst_on_pkt_sent(rtb->rst, ent, cstat); - - assert(rtb->cc_pkt_num <= ent->hd.pkt_num); - - cstat->bytes_in_flight += ent->pktlen; - rtb->cc_bytes_in_flight += ent->pktlen; - - ngtcp2_rst_update_app_limited(rtb->rst, cstat); - - if (ent->flags & NGTCP2_RTB_FLAG_ACK_ELICITING) { - ++rtb->num_ack_eliciting; - } - if (ent->flags & NGTCP2_RTB_FLAG_RETRANSMITTABLE) { - ++rtb->num_retransmittable; - } -} - -static void rtb_on_remove(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent, - ngtcp2_conn_stat *cstat) { - if (ent->flags & NGTCP2_RTB_FLAG_LOST_RETRANSMITTED) { - return; - } - - if (ent->flags & NGTCP2_RTB_FLAG_ACK_ELICITING) { - assert(rtb->num_ack_eliciting); - --rtb->num_ack_eliciting; - } - - if ((ent->flags & NGTCP2_RTB_FLAG_RETRANSMITTABLE) && - !(ent->flags & NGTCP2_RTB_FLAG_PTO_RECLAIMED)) { - assert(rtb->num_retransmittable); - --rtb->num_retransmittable; - } - - if (rtb->cc_pkt_num <= ent->hd.pkt_num) { - assert(cstat->bytes_in_flight >= ent->pktlen); - cstat->bytes_in_flight -= ent->pktlen; - - assert(rtb->cc_bytes_in_flight >= ent->pktlen); - rtb->cc_bytes_in_flight -= ent->pktlen; - } -} - -/* - * rtb_reclaim_frame queues unacknowledged frames included in |ent| - * for retransmission. The re-queued frames are not deleted from - * |ent|. It returns the number of frames queued. - */ -static ngtcp2_ssize rtb_reclaim_frame(ngtcp2_rtb *rtb, ngtcp2_conn *conn, - ngtcp2_pktns *pktns, - ngtcp2_rtb_entry *ent) { - ngtcp2_frame_chain *frc, *nfrc, **pfrc = &pktns->tx.frq; - ngtcp2_frame *fr; - ngtcp2_strm *strm; - ngtcp2_range gap, range; - size_t num_reclaimed = 0; - int rv; - - /* PADDING only (or PADDING + ACK ) packets will have NULL - ent->frc. */ - /* TODO Reconsider the order of pfrc */ - for (frc = ent->frc; frc; frc = frc->next) { - fr = &frc->fr; - /* Check that a late ACK acknowledged this frame. */ - if (frc->binder && - (frc->binder->flags & NGTCP2_FRAME_CHAIN_BINDER_FLAG_ACK)) { - continue; - } - switch (frc->fr.type) { - case NGTCP2_FRAME_STREAM: - strm = ngtcp2_conn_find_stream(conn, fr->stream.stream_id); - if (strm == NULL) { - continue; - } - - gap = ngtcp2_strm_get_unacked_range_after(strm, fr->stream.offset); - - range.begin = fr->stream.offset; - range.end = fr->stream.offset + - ngtcp2_vec_len(fr->stream.data, fr->stream.datacnt); - range = ngtcp2_range_intersect(&range, &gap); - if (ngtcp2_range_len(&range) == 0 && - (!fr->stream.fin || (strm->flags & NGTCP2_STRM_FLAG_FIN_ACKED))) { - continue; - } - - rv = ngtcp2_frame_chain_stream_datacnt_new(&nfrc, fr->stream.datacnt, - rtb->mem); - if (rv != 0) { - return rv; - } - - nfrc->fr = *fr; - ngtcp2_vec_copy(nfrc->fr.stream.data, fr->stream.data, - fr->stream.datacnt); - - rv = ngtcp2_strm_streamfrq_push(strm, nfrc); - if (rv != 0) { - ngtcp2_frame_chain_del(nfrc, conn->mem); - return rv; - } - if (!ngtcp2_strm_is_tx_queued(strm)) { - strm->cycle = ngtcp2_conn_tx_strmq_first_cycle(conn); - rv = ngtcp2_conn_tx_strmq_push(conn, strm); - if (rv != 0) { - return rv; - } - } - - ++num_reclaimed; - - continue; - case NGTCP2_FRAME_CRYPTO: - /* Don't resend CRYPTO frame if the whole region it contains has - been acknowledged */ - gap = ngtcp2_strm_get_unacked_range_after(rtb->crypto, fr->crypto.offset); - - range.begin = fr->crypto.offset; - range.end = fr->crypto.offset + - ngtcp2_vec_len(fr->crypto.data, fr->crypto.datacnt); - range = ngtcp2_range_intersect(&range, &gap); - if (ngtcp2_range_len(&range) == 0) { - continue; - } - - rv = ngtcp2_frame_chain_crypto_datacnt_new(&nfrc, fr->crypto.datacnt, - rtb->mem); - if (rv != 0) { - return rv; - } - - nfrc->fr = *fr; - ngtcp2_vec_copy(nfrc->fr.crypto.data, fr->crypto.data, - fr->crypto.datacnt); - - rv = ngtcp2_ksl_insert(&pktns->crypto.tx.frq, NULL, - &nfrc->fr.crypto.offset, nfrc); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(nfrc, conn->mem); - return rv; - } - - ++num_reclaimed; - - continue; - case NGTCP2_FRAME_NEW_TOKEN: - rv = ngtcp2_frame_chain_new_token_new(&nfrc, &fr->new_token.token, - rtb->mem); - if (rv != 0) { - return rv; - } - - rv = ngtcp2_bind_frame_chains(frc, nfrc, rtb->mem); - if (rv != 0) { - return rv; - } - - break; - default: - rv = ngtcp2_frame_chain_new(&nfrc, rtb->mem); - if (rv != 0) { - return rv; - } - - nfrc->fr = *fr; - - rv = ngtcp2_bind_frame_chains(frc, nfrc, rtb->mem); - if (rv != 0) { - return rv; - } - - break; - } - - ++num_reclaimed; - - nfrc->next = *pfrc; - *pfrc = nfrc; - pfrc = &nfrc->next; - } - - return (ngtcp2_ssize)num_reclaimed; -} - -static int rtb_on_pkt_lost(ngtcp2_rtb *rtb, ngtcp2_ksl_it *it, - ngtcp2_rtb_entry *ent, ngtcp2_conn *conn, - ngtcp2_pktns *pktns, ngtcp2_tstamp ts) { - int rv; - ngtcp2_ssize reclaimed; - - ngtcp2_log_pkt_lost(rtb->log, ent->hd.pkt_num, ent->hd.type, ent->hd.flags, - ent->ts); - - if (rtb->qlog) { - ngtcp2_qlog_pkt_lost(rtb->qlog, ent); - } - - if (!(ent->flags & NGTCP2_RTB_FLAG_PROBE)) { - if (ent->flags & NGTCP2_RTB_FLAG_PTO_RECLAIMED) { - ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV, - "pkn=%" PRId64 " has already been reclaimed on PTO", - ent->hd.pkt_num); - assert(!(ent->flags & NGTCP2_RTB_FLAG_LOST_RETRANSMITTED)); - assert(UINT64_MAX == ent->lost_ts); - - ent->flags |= NGTCP2_RTB_FLAG_LOST_RETRANSMITTED; - ent->lost_ts = ts; - - ++rtb->num_lost_pkts; - - ngtcp2_ksl_it_next(it); - - return 0; - } - - if (ent->frc) { - assert(!(ent->flags & NGTCP2_RTB_FLAG_LOST_RETRANSMITTED)); - assert(UINT64_MAX == ent->lost_ts); - - reclaimed = rtb_reclaim_frame(rtb, conn, pktns, ent); - if (reclaimed < 0) { - return (int)reclaimed; - } - - if (reclaimed) { - ent->flags |= NGTCP2_RTB_FLAG_LOST_RETRANSMITTED; - ent->lost_ts = ts; - - ++rtb->num_lost_pkts; - - ngtcp2_ksl_it_next(it); - - return 0; - } - } - } else { - ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV, - "pkn=%" PRId64 - " is a probe packet, no retransmission is necessary", - ent->hd.pkt_num); - } - - rv = ngtcp2_ksl_remove(&rtb->ents, it, &ent->hd.pkt_num); - assert(0 == rv); - - ngtcp2_rtb_entry_del(ent, rtb->mem); - - return 0; -} - -int ngtcp2_rtb_add(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent, - ngtcp2_conn_stat *cstat) { - int rv; - - rv = ngtcp2_ksl_insert(&rtb->ents, NULL, &ent->hd.pkt_num, ent); - if (rv != 0) { - return rv; - } - - rtb_on_add(rtb, ent, cstat); - - return 0; -} - -ngtcp2_ksl_it ngtcp2_rtb_head(ngtcp2_rtb *rtb) { - return ngtcp2_ksl_begin(&rtb->ents); -} - -static void rtb_remove(ngtcp2_rtb *rtb, ngtcp2_ksl_it *it, - ngtcp2_rtb_entry **pent, ngtcp2_rtb_entry *ent, - ngtcp2_conn_stat *cstat) { - int rv; - rv = ngtcp2_ksl_remove(&rtb->ents, it, &ent->hd.pkt_num); - assert(0 == rv); - rtb_on_remove(rtb, ent, cstat); - - assert(ent->next == NULL); - - ngtcp2_list_insert(ent, pent); -} - -static int rtb_process_acked_pkt(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent, - ngtcp2_conn *conn) { - ngtcp2_frame_chain *frc; - uint64_t prev_stream_offset, stream_offset; - ngtcp2_strm *strm; - int rv; - uint64_t datalen; - ngtcp2_strm *crypto = rtb->crypto; - ngtcp2_crypto_level crypto_level; - - for (frc = ent->frc; frc; frc = frc->next) { - if (frc->binder) { - frc->binder->flags |= NGTCP2_FRAME_CHAIN_BINDER_FLAG_ACK; - } - - switch (frc->fr.type) { - case NGTCP2_FRAME_STREAM: - strm = ngtcp2_conn_find_stream(conn, frc->fr.stream.stream_id); - if (strm == NULL) { - break; - } - - if (frc->fr.stream.fin) { - strm->flags |= NGTCP2_STRM_FLAG_FIN_ACKED; - } - - prev_stream_offset = ngtcp2_strm_get_acked_offset(strm); - rv = ngtcp2_strm_ack_data( - strm, frc->fr.stream.offset, - ngtcp2_vec_len(frc->fr.stream.data, frc->fr.stream.datacnt)); - if (rv != 0) { - return rv; - } - - if (conn->callbacks.acked_stream_data_offset) { - stream_offset = ngtcp2_strm_get_acked_offset(strm); - datalen = stream_offset - prev_stream_offset; - if (datalen == 0 && !frc->fr.stream.fin) { - break; - } - - rv = conn->callbacks.acked_stream_data_offset( - conn, strm->stream_id, prev_stream_offset, datalen, conn->user_data, - strm->stream_user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - } - - rv = ngtcp2_conn_close_stream_if_shut_rdwr(conn, strm, NGTCP2_NO_ERROR); - if (rv != 0) { - return rv; - } - break; - case NGTCP2_FRAME_CRYPTO: - prev_stream_offset = ngtcp2_strm_get_acked_offset(crypto); - rv = ngtcp2_strm_ack_data( - crypto, frc->fr.crypto.offset, - ngtcp2_vec_len(frc->fr.crypto.data, frc->fr.crypto.datacnt)); - if (rv != 0) { - return rv; - } - - if (conn->callbacks.acked_crypto_offset) { - stream_offset = ngtcp2_strm_get_acked_offset(crypto); - datalen = stream_offset - prev_stream_offset; - if (datalen == 0) { - break; - } - - switch (rtb->pktns_id) { - case NGTCP2_PKTNS_ID_INITIAL: - crypto_level = NGTCP2_CRYPTO_LEVEL_INITIAL; - break; - case NGTCP2_PKTNS_ID_HANDSHAKE: - crypto_level = NGTCP2_CRYPTO_LEVEL_HANDSHAKE; - break; - case NGTCP2_PKTNS_ID_APP: - crypto_level = NGTCP2_CRYPTO_LEVEL_APP; - break; - default: - assert(0); - } - - rv = conn->callbacks.acked_crypto_offset( - conn, crypto_level, prev_stream_offset, datalen, conn->user_data); - if (rv != 0) { - return NGTCP2_ERR_CALLBACK_FAILURE; - } - } - break; - case NGTCP2_FRAME_RESET_STREAM: - strm = ngtcp2_conn_find_stream(conn, frc->fr.reset_stream.stream_id); - if (strm == NULL) { - break; - } - strm->flags |= NGTCP2_STRM_FLAG_RST_ACKED; - rv = ngtcp2_conn_close_stream_if_shut_rdwr(conn, strm, NGTCP2_NO_ERROR); - if (rv != 0) { - return rv; - } - break; - case NGTCP2_FRAME_RETIRE_CONNECTION_ID: - assert(conn->dcid.num_retire_queued); - --conn->dcid.num_retire_queued; - break; - } - } - return 0; -} - -static void rtb_on_pkt_acked(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent, - ngtcp2_conn_stat *cstat, ngtcp2_tstamp ts) { - ngtcp2_cc *cc = rtb->cc; - ngtcp2_cc_pkt pkt; - - ngtcp2_rst_update_rate_sample(rtb->rst, ent, ts); - - cc->on_pkt_acked(cc, cstat, - ngtcp2_cc_pkt_init(&pkt, ent->hd.pkt_num, ent->pktlen, - rtb->pktns_id, ent->ts), - ts); - - if (!(ent->flags & NGTCP2_RTB_FLAG_PROBE) && - (ent->flags & NGTCP2_RTB_FLAG_ACK_ELICITING)) { - cstat->pto_count = 0; - } -} - -ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr, - ngtcp2_conn_stat *cstat, ngtcp2_conn *conn, - ngtcp2_tstamp pkt_ts, ngtcp2_tstamp ts) { - ngtcp2_rtb_entry *ent; - int64_t largest_ack = fr->largest_ack, min_ack; - size_t i; - int rv; - ngtcp2_ksl_it it; - ngtcp2_ssize num_acked = 0; - ngtcp2_tstamp largest_pkt_sent_ts = UINT64_MAX; - int64_t pkt_num; - ngtcp2_cc *cc = rtb->cc; - ngtcp2_rtb_entry *acked_ent = NULL; - int ack_eliciting_pkt_acked = 0; - - if (conn && (conn->flags & NGTCP2_CONN_FLAG_KEY_UPDATE_NOT_CONFIRMED) && - largest_ack >= conn->pktns.crypto.tx.ckm->pkt_num) { - conn->flags &= (uint16_t)~NGTCP2_CONN_FLAG_KEY_UPDATE_NOT_CONFIRMED; - conn->crypto.key_update.confirmed_ts = ts; - - ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_CRY, "key update confirmed"); - } - - rtb->largest_acked_tx_pkt_num = - ngtcp2_max(rtb->largest_acked_tx_pkt_num, largest_ack); - - /* Assume that ngtcp2_pkt_validate_ack(fr) returns 0 */ - it = ngtcp2_ksl_lower_bound(&rtb->ents, &largest_ack); - if (ngtcp2_ksl_it_end(&it)) { - return 0; - } - - min_ack = largest_ack - (int64_t)fr->first_ack_blklen; - - for (; !ngtcp2_ksl_it_end(&it);) { - pkt_num = *(int64_t *)ngtcp2_ksl_it_key(&it); - - assert(pkt_num <= largest_ack); - - if (pkt_num < min_ack) { - break; - } - - ent = ngtcp2_ksl_it_get(&it); - - if (largest_ack == pkt_num) { - largest_pkt_sent_ts = ent->ts; - } - - if (ent->flags & NGTCP2_RTB_FLAG_ACK_ELICITING) { - ack_eliciting_pkt_acked = 1; - } - - rtb_remove(rtb, &it, &acked_ent, ent, cstat); - ++num_acked; - } - - for (i = 0; i < fr->num_blks;) { - largest_ack = min_ack - (int64_t)fr->blks[i].gap - 2; - min_ack = largest_ack - (int64_t)fr->blks[i].blklen; - - it = ngtcp2_ksl_lower_bound(&rtb->ents, &largest_ack); - if (ngtcp2_ksl_it_end(&it)) { - break; - } - - for (; !ngtcp2_ksl_it_end(&it);) { - pkt_num = *(int64_t *)ngtcp2_ksl_it_key(&it); - if (pkt_num < min_ack) { - break; - } - ent = ngtcp2_ksl_it_get(&it); - - if (ent->flags & NGTCP2_RTB_FLAG_ACK_ELICITING) { - ack_eliciting_pkt_acked = 1; - } - - rtb_remove(rtb, &it, &acked_ent, ent, cstat); - ++num_acked; - } - - ++i; - } - - if (largest_pkt_sent_ts != UINT64_MAX && ack_eliciting_pkt_acked) { - ngtcp2_conn_update_rtt(conn, pkt_ts - largest_pkt_sent_ts, - fr->ack_delay_unscaled); - if (cc->new_rtt_sample) { - cc->new_rtt_sample(cc, cstat, ts); - } - } - - ngtcp2_rst_on_ack_recv(rtb->rst, cstat); - - if (conn) { - for (ent = acked_ent; ent; ent = acked_ent) { - rv = rtb_process_acked_pkt(rtb, ent, conn); - if (rv != 0) { - goto fail; - } - - rtb_on_pkt_acked(rtb, ent, cstat, ts); - acked_ent = ent->next; - ngtcp2_rtb_entry_del(ent, rtb->mem); - } - } else { - /* For unit tests */ - for (ent = acked_ent; ent; ent = acked_ent) { - rtb_on_pkt_acked(rtb, ent, cstat, ts); - acked_ent = ent->next; - ngtcp2_rtb_entry_del(ent, rtb->mem); - } - } - - cc->on_ack_recv(cc, cstat, ts); - - return num_acked; - -fail: - for (ent = acked_ent; ent; ent = acked_ent) { - acked_ent = ent->next; - ngtcp2_rtb_entry_del(ent, rtb->mem); - } - - return rv; -} - -static int rtb_pkt_lost(ngtcp2_rtb *rtb, ngtcp2_conn_stat *cstat, - const ngtcp2_rtb_entry *ent, uint64_t loss_delay, - ngtcp2_tstamp lost_send_time, uint64_t pkt_thres) { - ngtcp2_tstamp loss_time; - - if (ent->ts <= lost_send_time || - rtb->largest_acked_tx_pkt_num >= ent->hd.pkt_num + (int64_t)pkt_thres) { - return 1; - } - - loss_time = cstat->loss_time[rtb->pktns_id]; - - if (loss_time == UINT64_MAX) { - loss_time = ent->ts + loss_delay; - } else { - loss_time = ngtcp2_min(loss_time, ent->ts + loss_delay); - } - - cstat->loss_time[rtb->pktns_id] = loss_time; - - return 0; -} - -/* - * rtb_compute_pkt_loss_delay computes loss delay. - */ -static ngtcp2_duration compute_pkt_loss_delay(const ngtcp2_conn_stat *cstat) { - /* 9/8 is kTimeThreshold */ - ngtcp2_duration loss_delay = - ngtcp2_max(cstat->latest_rtt, cstat->smoothed_rtt) * 9 / 8; - return ngtcp2_max(loss_delay, NGTCP2_GRANULARITY); -} - -int ngtcp2_rtb_detect_lost_pkt(ngtcp2_rtb *rtb, ngtcp2_conn *conn, - ngtcp2_pktns *pktns, ngtcp2_conn_stat *cstat, - ngtcp2_duration pto, ngtcp2_tstamp ts) { - ngtcp2_rtb_entry *ent; - ngtcp2_duration loss_delay; - ngtcp2_tstamp lost_send_time; - ngtcp2_ksl_it it; - ngtcp2_tstamp latest_ts, oldest_ts; - int64_t last_lost_pkt_num; - ngtcp2_duration loss_window, congestion_period; - ngtcp2_cc *cc = rtb->cc; - int rv; - uint64_t pkt_thres = - rtb->cc_bytes_in_flight / cstat->max_udp_payload_size / 2; - - pkt_thres = ngtcp2_max(pkt_thres, NGTCP2_PKT_THRESHOLD); - cstat->loss_time[rtb->pktns_id] = UINT64_MAX; - loss_delay = compute_pkt_loss_delay(cstat); - lost_send_time = ts - loss_delay; - - it = ngtcp2_ksl_lower_bound(&rtb->ents, &rtb->largest_acked_tx_pkt_num); - for (; !ngtcp2_ksl_it_end(&it); ngtcp2_ksl_it_next(&it)) { - ent = ngtcp2_ksl_it_get(&it); - - if (ent->flags & NGTCP2_RTB_FLAG_LOST_RETRANSMITTED) { - break; - } - - if (rtb_pkt_lost(rtb, cstat, ent, loss_delay, lost_send_time, pkt_thres)) { - /* All entries from ent are considered to be lost. */ - latest_ts = oldest_ts = ent->ts; - last_lost_pkt_num = ent->hd.pkt_num; - - congestion_period = pto * NGTCP2_PERSISTENT_CONGESTION_THRESHOLD; - - for (; !ngtcp2_ksl_it_end(&it);) { - ent = ngtcp2_ksl_it_get(&it); - - if (last_lost_pkt_num == ent->hd.pkt_num + 1 && - ent->ts >= rtb->persistent_congestion_start_ts) { - last_lost_pkt_num = ent->hd.pkt_num; - oldest_ts = ent->ts; - } else { - last_lost_pkt_num = -1; - } - - if ((ent->flags & NGTCP2_RTB_FLAG_LOST_RETRANSMITTED)) { - if (rtb->pktns_id != NGTCP2_PKTNS_ID_APP || last_lost_pkt_num == -1 || - latest_ts - oldest_ts >= congestion_period) { - break; - } - ngtcp2_ksl_it_next(&it); - continue; - } - - rtb_on_remove(rtb, ent, cstat); - rv = rtb_on_pkt_lost(rtb, &it, ent, conn, pktns, ts); - if (rv != 0) { - return rv; - } - } - - cc->congestion_event(cc, cstat, latest_ts, ts); - - loss_window = latest_ts - oldest_ts; - /* Persistent congestion situation is only evaluated for app - * packet number space and for the packets sent after handshake - * is confirmed. During handshake, there is not much packets - * sent and also people seem to do lots of effort not to trigger - * persistent congestion there, then it is a lot easier to just - * not enable it during handshake. - */ - if (rtb->pktns_id == NGTCP2_PKTNS_ID_APP && loss_window > 0) { - if (loss_window >= congestion_period) { - ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV, - "persistent congestion loss_window=%" PRIu64 - " congestion_period=%" PRIu64, - loss_window, congestion_period); - - cc->on_persistent_congestion(cc, cstat, ts); - } - } - - break; - } - } - - ngtcp2_rtb_remove_excessive_lost_pkt(rtb, pkt_thres); - - return 0; -} - -void ngtcp2_rtb_remove_excessive_lost_pkt(ngtcp2_rtb *rtb, size_t n) { - ngtcp2_ksl_it it = ngtcp2_ksl_end(&rtb->ents); - ngtcp2_rtb_entry *ent; - int rv; - - for (; rtb->num_lost_pkts > n;) { - assert(ngtcp2_ksl_it_end(&it)); - ngtcp2_ksl_it_prev(&it); - ent = ngtcp2_ksl_it_get(&it); - - assert(ent->flags & NGTCP2_RTB_FLAG_LOST_RETRANSMITTED); - - ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV, - "removing stale lost pkn=%" PRId64, ent->hd.pkt_num); - - --rtb->num_lost_pkts; - rv = ngtcp2_ksl_remove(&rtb->ents, &it, &ent->hd.pkt_num); - assert(0 == rv); - ngtcp2_rtb_entry_del(ent, rtb->mem); - } -} - -void ngtcp2_rtb_remove_expired_lost_pkt(ngtcp2_rtb *rtb, ngtcp2_duration pto, - ngtcp2_tstamp ts) { - ngtcp2_ksl_it it; - ngtcp2_rtb_entry *ent; - int rv; - - if (ngtcp2_ksl_len(&rtb->ents) == 0) { - return; - } - - it = ngtcp2_ksl_end(&rtb->ents); - - for (;;) { - assert(ngtcp2_ksl_it_end(&it)); - - ngtcp2_ksl_it_prev(&it); - ent = ngtcp2_ksl_it_get(&it); - - if (!(ent->flags & NGTCP2_RTB_FLAG_LOST_RETRANSMITTED) || - ts - ent->lost_ts < pto) { - return; - } - - ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV, - "removing stale lost pkn=%" PRId64, ent->hd.pkt_num); - - --rtb->num_lost_pkts; - rv = ngtcp2_ksl_remove(&rtb->ents, &it, &ent->hd.pkt_num); - assert(0 == rv); - ngtcp2_rtb_entry_del(ent, rtb->mem); - - if (ngtcp2_ksl_len(&rtb->ents) == 0) { - return; - } - } -} - -ngtcp2_tstamp ngtcp2_rtb_lost_pkt_ts(ngtcp2_rtb *rtb) { - ngtcp2_ksl_it it; - ngtcp2_rtb_entry *ent; - - if (ngtcp2_ksl_len(&rtb->ents) == 0) { - return UINT64_MAX; - } - - it = ngtcp2_ksl_end(&rtb->ents); - ngtcp2_ksl_it_prev(&it); - ent = ngtcp2_ksl_it_get(&it); - - if (!(ent->flags & NGTCP2_RTB_FLAG_LOST_RETRANSMITTED)) { - return UINT64_MAX; - } - - return ent->lost_ts; -} - -static int rtb_on_pkt_lost_resched_move(ngtcp2_rtb *rtb, ngtcp2_conn *conn, - ngtcp2_pktns *pktns, - ngtcp2_rtb_entry *ent) { - ngtcp2_frame_chain **pfrc, *frc; - ngtcp2_stream *sfr; - ngtcp2_strm *strm; - int rv; - - ngtcp2_log_pkt_lost(rtb->log, ent->hd.pkt_num, ent->hd.type, ent->hd.flags, - ent->ts); - - if (rtb->qlog) { - ngtcp2_qlog_pkt_lost(rtb->qlog, ent); - } - - if (ent->flags & NGTCP2_RTB_FLAG_PROBE) { - ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV, - "pkn=%" PRId64 - " is a probe packet, no retransmission is necessary", - ent->hd.pkt_num); - return 0; - } - - if (!ent->frc) { - /* PADDING only (or PADDING + ACK ) packets will have NULL - ent->frc. */ - assert(!(ent->flags & NGTCP2_RTB_FLAG_LOST_RETRANSMITTED)); - assert(!(ent->flags & NGTCP2_RTB_FLAG_PTO_RECLAIMED)); - return 0; - } - - if (ent->flags & NGTCP2_RTB_FLAG_LOST_RETRANSMITTED) { - --rtb->num_lost_pkts; - } - - if (ent->flags & NGTCP2_RTB_FLAG_LOST_RETRANSMITTED) { - ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV, - "pkn=%" PRId64 - " was declared lost and has already been retransmitted", - ent->hd.pkt_num); - return 0; - } - - if (ent->flags & NGTCP2_RTB_FLAG_PTO_RECLAIMED) { - ngtcp2_log_info(rtb->log, NGTCP2_LOG_EVENT_RCV, - "pkn=%" PRId64 " has already been reclaimed on PTO", - ent->hd.pkt_num); - return 0; - } - - pfrc = &ent->frc; - - for (; *pfrc;) { - switch ((*pfrc)->fr.type) { - case NGTCP2_FRAME_STREAM: - frc = *pfrc; - - *pfrc = frc->next; - frc->next = NULL; - sfr = &frc->fr.stream; - - strm = ngtcp2_conn_find_stream(conn, sfr->stream_id); - if (!strm) { - ngtcp2_frame_chain_del(frc, conn->mem); - break; - } - rv = ngtcp2_strm_streamfrq_push(strm, frc); - if (rv != 0) { - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - if (!ngtcp2_strm_is_tx_queued(strm)) { - strm->cycle = ngtcp2_conn_tx_strmq_first_cycle(conn); - rv = ngtcp2_conn_tx_strmq_push(conn, strm); - if (rv != 0) { - return rv; - } - } - break; - case NGTCP2_FRAME_CRYPTO: - frc = *pfrc; - - *pfrc = frc->next; - frc->next = NULL; - - rv = ngtcp2_ksl_insert(&pktns->crypto.tx.frq, NULL, - &frc->fr.crypto.offset, frc); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(frc, conn->mem); - return rv; - } - break; - default: - pfrc = &(*pfrc)->next; - } - } - - *pfrc = pktns->tx.frq; - pktns->tx.frq = ent->frc; - ent->frc = NULL; - - return 0; -} - -int ngtcp2_rtb_remove_all(ngtcp2_rtb *rtb, ngtcp2_conn *conn, - ngtcp2_pktns *pktns, ngtcp2_conn_stat *cstat) { - ngtcp2_rtb_entry *ent; - ngtcp2_ksl_it it; - int rv; - - it = ngtcp2_ksl_begin(&rtb->ents); - - for (; !ngtcp2_ksl_it_end(&it);) { - ent = ngtcp2_ksl_it_get(&it); - - rtb_on_remove(rtb, ent, cstat); - rv = ngtcp2_ksl_remove(&rtb->ents, &it, &ent->hd.pkt_num); - assert(0 == rv); - - rv = rtb_on_pkt_lost_resched_move(rtb, conn, pktns, ent); - ngtcp2_rtb_entry_del(ent, rtb->mem); - if (rv != 0) { - return rv; - } - } - - return 0; -} - -int ngtcp2_rtb_empty(ngtcp2_rtb *rtb) { - return ngtcp2_ksl_len(&rtb->ents) == 0; -} - -void ngtcp2_rtb_reset_cc_state(ngtcp2_rtb *rtb, int64_t cc_pkt_num) { - rtb->cc_pkt_num = cc_pkt_num; - rtb->cc_bytes_in_flight = 0; -} - -ngtcp2_ssize ngtcp2_rtb_reclaim_on_pto(ngtcp2_rtb *rtb, ngtcp2_conn *conn, - ngtcp2_pktns *pktns, size_t num_pkts) { - ngtcp2_ksl_it it; - ngtcp2_rtb_entry *ent; - ngtcp2_ssize reclaimed; - size_t atmost = num_pkts; - - it = ngtcp2_ksl_end(&rtb->ents); - for (; !ngtcp2_ksl_it_begin(&it) && num_pkts >= 1;) { - ngtcp2_ksl_it_prev(&it); - ent = ngtcp2_ksl_it_get(&it); - - if ((ent->flags & (NGTCP2_RTB_FLAG_LOST_RETRANSMITTED | - NGTCP2_RTB_FLAG_PTO_RECLAIMED)) || - !(ent->flags & NGTCP2_RTB_FLAG_RETRANSMITTABLE)) { - continue; - } - - assert(ent->frc); - - reclaimed = rtb_reclaim_frame(rtb, conn, pktns, ent); - if (reclaimed < 0) { - return reclaimed; - } - - /* Mark reclaimed even if reclaimed == 0 so that we can skip it in - the next run. */ - ent->flags |= NGTCP2_RTB_FLAG_PTO_RECLAIMED; - - assert(rtb->num_retransmittable); - --rtb->num_retransmittable; - - if (reclaimed) { - --num_pkts; - } - } - - return (ngtcp2_ssize)(atmost - num_pkts); -} diff --git a/deps/ngtcp2/lib/ngtcp2_rtb.h b/deps/ngtcp2/lib/ngtcp2_rtb.h deleted file mode 100644 index 0d0b738f396a23..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_rtb.h +++ /dev/null @@ -1,408 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_RTB_H -#define NGTCP2_RTB_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_pkt.h" -#include "ngtcp2_ksl.h" -#include "ngtcp2_pq.h" - -struct ngtcp2_conn; -typedef struct ngtcp2_conn ngtcp2_conn; - -typedef struct ngtcp2_pktns ngtcp2_pktns; - -struct ngtcp2_frame_chain; -typedef struct ngtcp2_frame_chain ngtcp2_frame_chain; - -struct ngtcp2_log; -typedef struct ngtcp2_log ngtcp2_log; - -struct ngtcp2_qlog; -typedef struct ngtcp2_qlog ngtcp2_qlog; - -struct ngtcp2_strm; -typedef struct ngtcp2_strm ngtcp2_strm; - -struct ngtcp2_rst; -typedef struct ngtcp2_rst ngtcp2_rst; - -typedef enum ngtcp2_frame_chain_binder_flag { - NGTCP2_FRAME_CHAIN_BINDER_FLAG_NONE = 0x00, - /* NGTCP2_FRAME_CHAIN_BINDER_FLAG_ACK indicates that an information - which a frame carries has been acknowledged. */ - NGTCP2_FRAME_CHAIN_BINDER_FLAG_ACK = 0x01, -} ngtcp2_frame_chain_binder_flag; - -/* - * ngtcp2_frame_chain_binder binds 2 or more of ngtcp2_frame_chain to - * share the acknowledgement state. In general, all - * ngtcp2_frame_chains bound to the same binder must have the same - * information. - */ -typedef struct ngtcp2_frame_chain_binder { - size_t refcount; - uint32_t flags; -} ngtcp2_frame_chain_binder; - -int ngtcp2_frame_chain_binder_new(ngtcp2_frame_chain_binder **pbinder, - const ngtcp2_mem *mem); - -/* - * ngtcp2_bind_frame_chains binds two frame chains |a| and |b| using - * new or existing ngtcp2_frame_chain_binder. |a| might have non-NULL - * a->binder. |b| must not have non-NULL b->binder. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -int ngtcp2_bind_frame_chains(ngtcp2_frame_chain *a, ngtcp2_frame_chain *b, - const ngtcp2_mem *mem); - -/* - * ngtcp2_frame_chain chains frames in a single packet. - */ -struct ngtcp2_frame_chain { - ngtcp2_frame_chain *next; - ngtcp2_frame_chain_binder *binder; - ngtcp2_frame fr; -}; - -/* NGTCP2_MAX_STREAM_DATACNT is the maximum number of ngtcp2_vec that - a ngtcp2_stream can include. */ -#define NGTCP2_MAX_STREAM_DATACNT 256 - -/* NGTCP2_MAX_CRYPTO_DATACNT is the maximum number of ngtcp2_vec that - a ngtcp2_crypto can include. */ -#define NGTCP2_MAX_CRYPTO_DATACNT 8 - -/* - * ngtcp2_frame_chain_new allocates ngtcp2_frame_chain object and - * assigns its pointer to |*pfrc|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_frame_chain_new(ngtcp2_frame_chain **pfrc, const ngtcp2_mem *mem); - -/* - * ngtcp2_frame_chain_extralen_new works like ngtcp2_frame_chain_new, - * but it allocates extra memory |extralen| in order to extend - * ngtcp2_frame. - */ -int ngtcp2_frame_chain_extralen_new(ngtcp2_frame_chain **pfrc, size_t extralen, - const ngtcp2_mem *mem); - -/* - * ngtcp2_frame_chain_stream_datacnt_new works like - * ngtcp2_frame_chain_new, but it allocates enough data to store - * additional |datacnt| - 1 ngtcp2_vec object after ngtcp2_stream - * object. If |datacnt| equals to 1, ngtcp2_frame_chain_new is called - * internally. - */ -int ngtcp2_frame_chain_stream_datacnt_new(ngtcp2_frame_chain **pfrc, - size_t datacnt, - const ngtcp2_mem *mem); - -/* - * ngtcp2_frame_chain_crypto_datacnt_new works like - * ngtcp2_frame_chain_new, but it allocates enough data to store - * additional |datacnt| - 1 ngtcp2_vec object after ngtcp2_crypto - * object. If |datacnt| equals to 1, ngtcp2_frame_chain_new is called - * internally. - */ -int ngtcp2_frame_chain_crypto_datacnt_new(ngtcp2_frame_chain **pfrc, - size_t datacnt, - const ngtcp2_mem *mem); - -int ngtcp2_frame_chain_new_token_new(ngtcp2_frame_chain **pfrc, - const ngtcp2_vec *token, - const ngtcp2_mem *mem); - -/* - * ngtcp2_frame_chain_del deallocates |frc|. It also deallocates the - * memory pointed by |frc|. - */ -void ngtcp2_frame_chain_del(ngtcp2_frame_chain *frc, const ngtcp2_mem *mem); - -/* - * ngtcp2_frame_chain_init initializes |frc|. - */ -void ngtcp2_frame_chain_init(ngtcp2_frame_chain *frc); - -/* - * ngtcp2_frame_chain_list_del deletes |frc|, and all objects - * connected by next field. - */ -void ngtcp2_frame_chain_list_del(ngtcp2_frame_chain *frc, - const ngtcp2_mem *mem); - -typedef enum { - NGTCP2_RTB_FLAG_NONE = 0x00, - /* NGTCP2_RTB_FLAG_PROBE indicates that the entry includes a probe - packet. */ - NGTCP2_RTB_FLAG_PROBE = 0x01, - /* NGTCP2_RTB_FLAG_RETRANSMITTABLE indicates that the entry includes - a frame which must be retransmitted until it is acknowledged. In - most cases, this flag is used along with - NGTCP2_RTB_FLAG_ACK_ELICITING. We have these 2 flags because - NGTCP2_RTB_FLAG_RETRANSMITTABLE triggers PTO, but just - NGTCP2_RTB_FLAG_ACK_ELICITING does not. */ - NGTCP2_RTB_FLAG_RETRANSMITTABLE = 0x02, - /* NGTCP2_RTB_FLAG_ACK_ELICITING indicates that the entry elicits - acknowledgement. */ - NGTCP2_RTB_FLAG_ACK_ELICITING = 0x04, - /* NGTCP2_RTB_FLAG_PTO_RECLAIMED indicates that the packet has been - reclaimed on PTO. It is not marked lost yet and still consumes - congestion window. */ - NGTCP2_RTB_FLAG_PTO_RECLAIMED = 0x08, - /* NGTCP2_RTB_FLAG_LOST_RETRANSMITTED indicates that the entry has - been marked lost and scheduled to retransmit. */ - NGTCP2_RTB_FLAG_LOST_RETRANSMITTED = 0x10, -} ngtcp2_rtb_flag; - -struct ngtcp2_rtb_entry; -typedef struct ngtcp2_rtb_entry ngtcp2_rtb_entry; - -/* - * ngtcp2_rtb_entry is an object stored in ngtcp2_rtb. It corresponds - * to the one packet which is waiting for its ACK. - */ -struct ngtcp2_rtb_entry { - ngtcp2_rtb_entry *next; - - struct { - int64_t pkt_num; - uint8_t type; - uint8_t flags; - } hd; - ngtcp2_frame_chain *frc; - /* ts is the time point when a packet included in this entry is sent - to a peer. */ - ngtcp2_tstamp ts; - /* lost_ts is the time when this entry is marked lost. */ - ngtcp2_tstamp lost_ts; - /* pktlen is the length of QUIC packet */ - size_t pktlen; - struct { - uint64_t delivered; - ngtcp2_tstamp delivered_ts; - ngtcp2_tstamp first_sent_ts; - int is_app_limited; - } rst; - /* flags is bitwise-OR of zero or more of ngtcp2_rtb_flag. */ - uint8_t flags; -}; - -/* - * ngtcp2_rtb_entry_new allocates ngtcp2_rtb_entry object, and assigns - * its pointer to |*pent|. On success, |*pent| takes ownership of - * |frc|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory. - */ -int ngtcp2_rtb_entry_new(ngtcp2_rtb_entry **pent, const ngtcp2_pkt_hd *hd, - ngtcp2_frame_chain *frc, ngtcp2_tstamp ts, - size_t pktlen, uint8_t flags, const ngtcp2_mem *mem); - -/* - * ngtcp2_rtb_entry_del deallocates |ent|. It also frees memory - * pointed by |ent|. - */ -void ngtcp2_rtb_entry_del(ngtcp2_rtb_entry *ent, const ngtcp2_mem *mem); - -/* - * ngtcp2_rtb tracks sent packets, and its ACK timeout for - * retransmission. - */ -typedef struct { - /* ents includes ngtcp2_rtb_entry sorted by decreasing order of - packet number. */ - ngtcp2_ksl ents; - /* crypto is CRYPTO stream. */ - ngtcp2_strm *crypto; - ngtcp2_rst *rst; - ngtcp2_cc *cc; - ngtcp2_log *log; - ngtcp2_qlog *qlog; - const ngtcp2_mem *mem; - /* largest_acked_tx_pkt_num is the largest packet number - acknowledged by the peer. */ - int64_t largest_acked_tx_pkt_num; - /* num_ack_eliciting is the number of ACK eliciting entries. */ - size_t num_ack_eliciting; - /* num_retransmittable is the number of packets which contain frames - that must be retransmitted on loss. */ - size_t num_retransmittable; - /* probe_pkt_left is the number of probe packet to send */ - size_t probe_pkt_left; - /* pktns_id is the identifier of packet number space. */ - ngtcp2_pktns_id pktns_id; - /* cc_pkt_num is the smallest packet number that is contributed to - ngtcp2_conn_stat.bytes_in_flight. */ - int64_t cc_pkt_num; - /* cc_bytes_in_flight is the number of in-flight bytes that is - contributed to ngtcp2_conn_stat.bytes_in_flight. It only - includes the bytes after congestion state is reset. */ - uint64_t cc_bytes_in_flight; - /* persistent_congestion_start_ts is the time when persistent - congestion evaluation is started. It happens roughly after - handshake is confirmed. */ - ngtcp2_tstamp persistent_congestion_start_ts; - /* num_lost_pkts is the number entries in ents which has - NGTCP2_RTB_FLAG_LOST_RETRANSMITTED flag set. */ - size_t num_lost_pkts; -} ngtcp2_rtb; - -/* - * ngtcp2_rtb_init initializes |rtb|. - */ -void ngtcp2_rtb_init(ngtcp2_rtb *rtb, ngtcp2_pktns_id pktns_id, - ngtcp2_strm *crypto, ngtcp2_rst *rst, ngtcp2_cc *cc, - ngtcp2_log *log, ngtcp2_qlog *qlog, const ngtcp2_mem *mem); - -/* - * ngtcp2_rtb_free deallocates resources allocated for |rtb|. - */ -void ngtcp2_rtb_free(ngtcp2_rtb *rtb); - -/* - * ngtcp2_rtb_add adds |ent| to |rtb|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -int ngtcp2_rtb_add(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent, - ngtcp2_conn_stat *cstat); - -/* - * ngtcp2_rtb_head returns the iterator which points to the entry - * which has the largest packet number. If there is no entry, - * returned value satisfies ngtcp2_ksl_it_end(&it) != 0. - */ -ngtcp2_ksl_it ngtcp2_rtb_head(ngtcp2_rtb *rtb); - -/* - * ngtcp2_rtb_recv_ack removes acked ngtcp2_rtb_entry from |rtb|. - * |pkt_num| is a packet number which includes |fr|. |pkt_ts| is the - * timestamp when packet is received. |ts| should be the current - * time. Usually they are the same, but for buffered packets, - * |pkt_ts| would be earlier than |ts|. - * - * This function returns the number of newly acknowledged packets if - * it succeeds, or one of the following negative error codes: - * - * NGTCP2_ERR_CALLBACK_FAILURE - * User callback failed - * NGTCP2_ERR_NOMEM - * Out of memory - */ -ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr, - ngtcp2_conn_stat *cstat, ngtcp2_conn *conn, - ngtcp2_tstamp pkt_ts, ngtcp2_tstamp ts); - -/* - * ngtcp2_rtb_detect_lost_pkt detects lost packets and prepends the - * frames contained them to |*pfrc|. Even when this function fails, - * some frames might be prepended to |*pfrc| and the caller should - * handle them. |pto| is PTO. - */ -int ngtcp2_rtb_detect_lost_pkt(ngtcp2_rtb *rtb, ngtcp2_conn *conn, - ngtcp2_pktns *pktns, ngtcp2_conn_stat *cstat, - ngtcp2_duration pto, ngtcp2_tstamp ts); - -/* - * ngtcp2_rtb_remove_expired_lost_pkt removes expired lost packet. - */ -void ngtcp2_rtb_remove_expired_lost_pkt(ngtcp2_rtb *rtb, ngtcp2_duration pto, - ngtcp2_tstamp ts); - -/* - * ngtcp2_rtb_lost_pkt_ts returns the earliest time when the still - * retained packet was lost. It returns UINT64_MAX if no such packet - * exists. - */ -ngtcp2_tstamp ngtcp2_rtb_lost_pkt_ts(ngtcp2_rtb *rtb); - -/* - * ngtcp2_rtb_remove_all removes all packets from |rtb| and prepends - * all frames to |*pfrc|. Even when this function fails, some frames - * might be prepended to |*pfrc| and the caller should handle them. - */ -int ngtcp2_rtb_remove_all(ngtcp2_rtb *rtb, ngtcp2_conn *conn, - ngtcp2_pktns *pktns, ngtcp2_conn_stat *cstat); - -/* - * ngtcp2_rtb_empty returns nonzero if |rtb| have no entry. - */ -int ngtcp2_rtb_empty(ngtcp2_rtb *rtb); - -/* - * ngtcp2_rtb_reset_cc_state resets congestion state in |rtb|. - * |cc_pkt_num| is the next outbound packet number which is sent under - * new congestion state. - */ -void ngtcp2_rtb_reset_cc_state(ngtcp2_rtb *rtb, int64_t cc_pkt_num); - -/* - * ngtcp2_rtb_remove_expired_lost_pkt ensures that the number of lost - * packets at most |n|. - */ -void ngtcp2_rtb_remove_excessive_lost_pkt(ngtcp2_rtb *rtb, size_t n); - -/* - * ngtcp2_rtb_reclaim_on_pto reclaims up to |num_pkts| packets which - * are in-flight and not marked lost to send them in PTO probe. The - * reclaimed frames are chained to |*pfrc|. - * - * This function returns the number of packets reclaimed if it - * succeeds, or one of the following negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -ngtcp2_ssize ngtcp2_rtb_reclaim_on_pto(ngtcp2_rtb *rtb, ngtcp2_conn *conn, - ngtcp2_pktns *pktns, size_t num_pkts); - -#endif /* NGTCP2_RTB_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_str.c b/deps/ngtcp2/lib/ngtcp2_str.c deleted file mode 100644 index b7502e3bd0a5af..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_str.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_str.h" - -#include - -void *ngtcp2_cpymem(void *dest, const void *src, size_t n) { - memcpy(dest, src, n); - return (uint8_t *)dest + n; -} - -uint8_t *ngtcp2_setmem(uint8_t *dest, uint8_t b, size_t n) { - memset(dest, b, n); - return dest + n; -} - -#define LOWER_XDIGITS "0123456789abcdef" - -uint8_t *ngtcp2_encode_hex(uint8_t *dest, const uint8_t *data, size_t len) { - size_t i; - uint8_t *p = dest; - - for (i = 0; i < len; ++i) { - *p++ = (uint8_t)LOWER_XDIGITS[data[i] >> 4]; - *p++ = (uint8_t)LOWER_XDIGITS[data[i] & 0xf]; - } - - *p = '\0'; - - return dest; -} - -char *ngtcp2_encode_printable_ascii(char *dest, const uint8_t *data, - size_t len) { - size_t i; - char *p = dest; - uint8_t c; - - for (i = 0; i < len; ++i) { - c = data[i]; - if (0x20 <= c && c <= 0x7e) { - *p++ = (char)c; - } else { - *p++ = '.'; - } - } - - *p = '\0'; - - return dest; -} - -int ngtcp2_verify_stateless_reset_token(const uint8_t *want, - const uint8_t *got) { - return !ngtcp2_check_invalid_stateless_reset_token(got) && - ngtcp2_cmemeq(want, got, NGTCP2_STATELESS_RESET_TOKENLEN) - ? 0 - : NGTCP2_ERR_INVALID_ARGUMENT; -} - -int ngtcp2_check_invalid_stateless_reset_token(const uint8_t *token) { - static uint8_t invalid_token[NGTCP2_STATELESS_RESET_TOKENLEN] = {0}; - - return 0 == memcmp(invalid_token, token, NGTCP2_STATELESS_RESET_TOKENLEN); -} - -int ngtcp2_cmemeq(const uint8_t *a, const uint8_t *b, size_t n) { - size_t i; - int rv = 0; - - for (i = 0; i < n; ++i) { - rv |= a[i] ^ b[i]; - } - - return rv == 0; -} diff --git a/deps/ngtcp2/lib/ngtcp2_str.h b/deps/ngtcp2/lib/ngtcp2_str.h deleted file mode 100644 index 104b1f1a03873b..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_str.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_STR_H -#define NGTCP2_STR_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -void *ngtcp2_cpymem(void *dest, const void *src, size_t n); - -/* - * ngtcp2_setmem writes a string of length |n| consisting only |b| to - * the buffer pointed by |dest|. It returns dest + n; - */ -uint8_t *ngtcp2_setmem(uint8_t *dest, uint8_t b, size_t n); -/* - * ngtcp2_encode_hex encodes |data| of length |len| in hex string. It - * writes additional NULL bytes at the end of the buffer. The buffer - * pointed by |dest| must have at least |len| * 2 + 1 bytes space. - * This function returns |dest|. - */ -uint8_t *ngtcp2_encode_hex(uint8_t *dest, const uint8_t *data, size_t len); - -/* - * ngtcp2_encode_printable_ascii encodes |data| of length |len| in - * |dest| in the following manner: printable ascii characters are - * copied as is. The other characters are converted to ".". It - * writes additional NULL bytes at the end of the buffer. |dest| must - * have at least |len| + 1 bytes. This function returns |dest|. - */ -char *ngtcp2_encode_printable_ascii(char *dest, const uint8_t *data, - size_t len); - -/* - * ngtcp2_verify_stateless_reset_token verifies stateless reset token - * |want| and |got|. This function returns 0 if |want| equals |got| - * and |got| is not all zero, or one of the following negative error - * codes: - * - * NGTCP2_ERR_INVALID_ARGUMENT - * Token does not match; or token is all zero. - */ -int ngtcp2_verify_stateless_reset_token(const uint8_t *want, - const uint8_t *got); - -/* - * ngtcp2_check_invalid_stateless_reset_token returns nonzero if - * |token| is invalid stateless reset token. Currently, token which - * consists of all zeros is considered invalid. - */ -int ngtcp2_check_invalid_stateless_reset_token(const uint8_t *token); - -/* - * ngtcp2_cmemeq returns nonzero if the first |n| bytes of the buffers - * pointed by |a| and |b| are equal. The comparison is done in a - * constant time manner. - */ -int ngtcp2_cmemeq(const uint8_t *a, const uint8_t *b, size_t n); - -#endif /* NGTCP2_STR_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_strm.c b/deps/ngtcp2/lib/ngtcp2_strm.c deleted file mode 100644 index 6fb73dc0727b5f..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_strm.c +++ /dev/null @@ -1,664 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_strm.h" - -#include -#include - -#include "ngtcp2_rtb.h" -#include "ngtcp2_pkt.h" -#include "ngtcp2_vec.h" - -static int offset_less(const ngtcp2_ksl_key *lhs, const ngtcp2_ksl_key *rhs) { - return *(int64_t *)lhs < *(int64_t *)rhs; -} - -int ngtcp2_strm_init(ngtcp2_strm *strm, int64_t stream_id, uint32_t flags, - uint64_t max_rx_offset, uint64_t max_tx_offset, - void *stream_user_data, const ngtcp2_mem *mem) { - strm->cycle = 0; - strm->tx.acked_offset = NULL; - strm->tx.cont_acked_offset = 0; - strm->tx.streamfrq = NULL; - strm->tx.offset = 0; - strm->tx.max_offset = max_tx_offset; - strm->rx.rob = NULL; - strm->rx.cont_offset = 0; - strm->rx.last_offset = 0; - strm->stream_id = stream_id; - strm->flags = flags; - strm->stream_user_data = stream_user_data; - strm->rx.max_offset = strm->rx.unsent_max_offset = max_rx_offset; - strm->me.key = (uint64_t)stream_id; - strm->me.next = NULL; - strm->pe.index = NGTCP2_PQ_BAD_INDEX; - strm->mem = mem; - strm->app_error_code = 0; - - return 0; -} - -void ngtcp2_strm_free(ngtcp2_strm *strm) { - ngtcp2_ksl_it it; - - if (strm == NULL) { - return; - } - - if (strm->tx.streamfrq) { - for (it = ngtcp2_ksl_begin(strm->tx.streamfrq); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - ngtcp2_frame_chain_del(ngtcp2_ksl_it_get(&it), strm->mem); - } - - ngtcp2_ksl_free(strm->tx.streamfrq); - ngtcp2_mem_free(strm->mem, strm->tx.streamfrq); - } - - ngtcp2_rob_free(strm->rx.rob); - ngtcp2_mem_free(strm->mem, strm->rx.rob); - ngtcp2_gaptr_free(strm->tx.acked_offset); - ngtcp2_mem_free(strm->mem, strm->tx.acked_offset); -} - -static int strm_rob_init(ngtcp2_strm *strm) { - int rv; - ngtcp2_rob *rob = ngtcp2_mem_malloc(strm->mem, sizeof(*rob)); - - if (rob == NULL) { - return NGTCP2_ERR_NOMEM; - } - - rv = ngtcp2_rob_init(rob, 8 * 1024, strm->mem); - if (rv != 0) { - ngtcp2_mem_free(strm->mem, rob); - return rv; - } - - strm->rx.rob = rob; - - return 0; -} - -uint64_t ngtcp2_strm_rx_offset(ngtcp2_strm *strm) { - if (strm->rx.rob == NULL) { - return strm->rx.cont_offset; - } - return ngtcp2_rob_first_gap_offset(strm->rx.rob); -} - -int ngtcp2_strm_recv_reordering(ngtcp2_strm *strm, const uint8_t *data, - size_t datalen, uint64_t offset) { - int rv; - - if (strm->rx.rob == NULL) { - rv = strm_rob_init(strm); - if (rv != 0) { - return rv; - } - - if (strm->rx.cont_offset) { - rv = ngtcp2_rob_remove_prefix(strm->rx.rob, strm->rx.cont_offset); - if (rv != 0) { - return rv; - } - } - } - - return ngtcp2_rob_push(strm->rx.rob, offset, data, datalen); -} - -int ngtcp2_strm_update_rx_offset(ngtcp2_strm *strm, uint64_t offset) { - if (strm->rx.rob == NULL) { - strm->rx.cont_offset = offset; - return 0; - } - - return ngtcp2_rob_remove_prefix(strm->rx.rob, offset); -} - -void ngtcp2_strm_shutdown(ngtcp2_strm *strm, uint32_t flags) { - strm->flags |= flags & NGTCP2_STRM_FLAG_SHUT_RDWR; -} - -static int strm_streamfrq_init(ngtcp2_strm *strm) { - int rv; - ngtcp2_ksl *streamfrq = ngtcp2_mem_malloc(strm->mem, sizeof(*streamfrq)); - if (streamfrq == NULL) { - return NGTCP2_ERR_NOMEM; - } - - rv = ngtcp2_ksl_init(streamfrq, offset_less, sizeof(uint64_t), strm->mem); - if (rv != 0) { - ngtcp2_mem_free(strm->mem, streamfrq); - return rv; - } - - strm->tx.streamfrq = streamfrq; - - return 0; -} - -int ngtcp2_strm_streamfrq_push(ngtcp2_strm *strm, ngtcp2_frame_chain *frc) { - int rv; - - assert(frc->fr.type == NGTCP2_FRAME_STREAM); - assert(frc->next == NULL); - - if (strm->tx.streamfrq == NULL) { - rv = strm_streamfrq_init(strm); - if (rv != 0) { - return rv; - } - } - - return ngtcp2_ksl_insert(strm->tx.streamfrq, NULL, &frc->fr.stream.offset, - frc); -} - -static int strm_streamfrq_unacked_pop(ngtcp2_strm *strm, - ngtcp2_frame_chain **pfrc) { - ngtcp2_frame_chain *frc, *nfrc; - ngtcp2_stream *fr, *nfr; - uint64_t offset, end_offset; - size_t idx, end_idx; - uint64_t base_offset, end_base_offset; - ngtcp2_range gap; - ngtcp2_vec *v; - int rv; - ngtcp2_ksl_it it; - - *pfrc = NULL; - - assert(strm->tx.streamfrq); - assert(ngtcp2_ksl_len(strm->tx.streamfrq)); - - for (it = ngtcp2_ksl_begin(strm->tx.streamfrq); !ngtcp2_ksl_it_end(&it);) { - frc = ngtcp2_ksl_it_get(&it); - fr = &frc->fr.stream; - - ngtcp2_ksl_remove(strm->tx.streamfrq, &it, &fr->offset); - - idx = 0; - offset = fr->offset; - base_offset = 0; - - gap = ngtcp2_strm_get_unacked_range_after(strm, offset); - if (gap.begin < offset) { - gap.begin = offset; - } - - for (; idx < fr->datacnt && offset < gap.begin; ++idx) { - v = &fr->data[idx]; - if (offset + v->len > gap.begin) { - base_offset = gap.begin - offset; - break; - } - - offset += v->len; - } - - if (idx == fr->datacnt) { - if (fr->fin) { - if (strm->flags & NGTCP2_STRM_FLAG_FIN_ACKED) { - ngtcp2_frame_chain_del(frc, strm->mem); - assert(ngtcp2_ksl_len(strm->tx.streamfrq) == 0); - return 0; - } - - fr->offset = fr->offset + ngtcp2_vec_len(fr->data, fr->datacnt); - fr->datacnt = 0; - - *pfrc = frc; - - return 0; - } - ngtcp2_frame_chain_del(frc, strm->mem); - continue; - } - - assert(gap.begin == offset + base_offset); - - end_idx = idx; - end_offset = offset; - end_base_offset = 0; - - for (; end_idx < fr->datacnt; ++end_idx) { - v = &fr->data[end_idx]; - if (end_offset + v->len > gap.end) { - end_base_offset = gap.end - end_offset; - break; - } - - end_offset += v->len; - } - - if (fr->offset == offset && base_offset == 0 && fr->datacnt == end_idx) { - *pfrc = frc; - return 0; - } - - if (fr->datacnt == end_idx) { - memmove(fr->data, fr->data + idx, sizeof(fr->data[0]) * (end_idx - idx)); - - assert(fr->data[0].len > base_offset); - - fr->offset = offset + base_offset; - fr->datacnt = end_idx - idx; - fr->data[0].base += base_offset; - fr->data[0].len -= (size_t)base_offset; - - *pfrc = frc; - return 0; - } - - rv = ngtcp2_frame_chain_stream_datacnt_new(&nfrc, fr->datacnt - end_idx, - strm->mem); - if (rv != 0) { - ngtcp2_frame_chain_del(frc, strm->mem); - return rv; - } - - nfr = &nfrc->fr.stream; - memcpy(nfr->data, fr->data + end_idx, - sizeof(nfr->data[0]) * (fr->datacnt - end_idx)); - - assert(nfr->data[0].len > end_base_offset); - - nfr->type = NGTCP2_FRAME_STREAM; - nfr->flags = 0; - nfr->fin = fr->fin; - nfr->stream_id = fr->stream_id; - nfr->offset = end_offset + end_base_offset; - nfr->datacnt = fr->datacnt - end_idx; - nfr->data[0].base += end_base_offset; - nfr->data[0].len -= (size_t)end_base_offset; - - rv = ngtcp2_ksl_insert(strm->tx.streamfrq, NULL, &nfr->offset, nfrc); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(nfrc, strm->mem); - ngtcp2_frame_chain_del(frc, strm->mem); - return rv; - } - - if (end_base_offset) { - ++end_idx; - } - - memmove(fr->data, fr->data + idx, sizeof(fr->data[0]) * (end_idx - idx)); - - assert(fr->data[0].len > base_offset); - - fr->fin = 0; - fr->offset = offset + base_offset; - fr->datacnt = end_idx - idx; - if (end_base_offset) { - assert(fr->data[fr->datacnt - 1].len > end_base_offset); - fr->data[fr->datacnt - 1].len = (size_t)end_base_offset; - } - fr->data[0].base += base_offset; - fr->data[0].len -= (size_t)base_offset; - - *pfrc = frc; - return 0; - } - - return 0; -} - -int ngtcp2_strm_streamfrq_pop(ngtcp2_strm *strm, ngtcp2_frame_chain **pfrc, - size_t left) { - ngtcp2_stream *fr, *nfr; - ngtcp2_frame_chain *frc, *nfrc; - int rv; - size_t nmerged; - size_t datalen; - ngtcp2_vec a[NGTCP2_MAX_STREAM_DATACNT]; - ngtcp2_vec b[NGTCP2_MAX_STREAM_DATACNT]; - size_t acnt, bcnt; - uint64_t unacked_offset; - - if (strm->tx.streamfrq == NULL || ngtcp2_ksl_len(strm->tx.streamfrq) == 0) { - *pfrc = NULL; - return 0; - } - - rv = strm_streamfrq_unacked_pop(strm, &frc); - if (rv != 0) { - return rv; - } - if (frc == NULL) { - *pfrc = NULL; - return 0; - } - - fr = &frc->fr.stream; - datalen = ngtcp2_vec_len(fr->data, fr->datacnt); - - if (left == 0) { - /* datalen could be zero if 0 length STREAM has been sent */ - if (datalen || ngtcp2_ksl_len(strm->tx.streamfrq) > 1) { - rv = ngtcp2_ksl_insert(strm->tx.streamfrq, NULL, &fr->offset, frc); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(frc, strm->mem); - return rv; - } - *pfrc = NULL; - return 0; - } - } - - if (datalen > left) { - ngtcp2_vec_copy(a, fr->data, fr->datacnt); - acnt = fr->datacnt; - - bcnt = 0; - ngtcp2_vec_split(a, &acnt, b, &bcnt, left, NGTCP2_MAX_STREAM_DATACNT); - - assert(acnt > 0); - assert(bcnt > 0); - - rv = ngtcp2_frame_chain_stream_datacnt_new(&nfrc, bcnt, strm->mem); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(frc, strm->mem); - return rv; - } - - nfr = &nfrc->fr.stream; - nfr->type = NGTCP2_FRAME_STREAM; - nfr->flags = 0; - nfr->fin = fr->fin; - nfr->stream_id = fr->stream_id; - nfr->offset = fr->offset + left; - nfr->datacnt = bcnt; - ngtcp2_vec_copy(nfr->data, b, bcnt); - - rv = ngtcp2_ksl_insert(strm->tx.streamfrq, NULL, &nfr->offset, nfrc); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(nfrc, strm->mem); - ngtcp2_frame_chain_del(frc, strm->mem); - return rv; - } - - rv = ngtcp2_frame_chain_stream_datacnt_new(&nfrc, acnt, strm->mem); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(frc, strm->mem); - return rv; - } - - nfr = &nfrc->fr.stream; - *nfr = *fr; - nfr->fin = 0; - nfr->datacnt = acnt; - ngtcp2_vec_copy(nfr->data, a, acnt); - - ngtcp2_frame_chain_del(frc, strm->mem); - - *pfrc = nfrc; - - return 0; - } - - left -= datalen; - - ngtcp2_vec_copy(a, fr->data, fr->datacnt); - acnt = fr->datacnt; - - for (; left && ngtcp2_ksl_len(strm->tx.streamfrq);) { - unacked_offset = ngtcp2_strm_streamfrq_unacked_offset(strm); - if (unacked_offset != fr->offset + datalen) { - assert(fr->offset + datalen < unacked_offset); - break; - } - - rv = strm_streamfrq_unacked_pop(strm, &nfrc); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(frc, strm->mem); - return rv; - } - if (nfrc == NULL) { - break; - } - - nfr = &nfrc->fr.stream; - - if (nfr->fin && nfr->datacnt == 0) { - fr->fin = 1; - ngtcp2_frame_chain_del(nfrc, strm->mem); - break; - } - - nmerged = ngtcp2_vec_merge(a, &acnt, nfr->data, &nfr->datacnt, left, - NGTCP2_MAX_STREAM_DATACNT); - if (nmerged == 0) { - rv = ngtcp2_ksl_insert(strm->tx.streamfrq, NULL, &nfr->offset, nfrc); - if (rv != 0) { - assert(ngtcp2_err_is_fatal(rv)); - ngtcp2_frame_chain_del(nfrc, strm->mem); - ngtcp2_frame_chain_del(frc, strm->mem); - return rv; - } - break; - } - - datalen += nmerged; - left -= nmerged; - - if (nfr->datacnt == 0) { - fr->fin = nfr->fin; - ngtcp2_frame_chain_del(nfrc, strm->mem); - continue; - } - - nfr->offset += nmerged; - - rv = ngtcp2_ksl_insert(strm->tx.streamfrq, NULL, &nfr->offset, nfrc); - if (rv != 0) { - ngtcp2_frame_chain_del(nfrc, strm->mem); - ngtcp2_frame_chain_del(frc, strm->mem); - return rv; - } - - break; - } - - if (acnt == fr->datacnt) { - if (acnt > 0) { - fr->data[acnt - 1] = a[acnt - 1]; - } - - *pfrc = frc; - return 0; - } - - assert(acnt > fr->datacnt); - - rv = ngtcp2_frame_chain_stream_datacnt_new(&nfrc, acnt, strm->mem); - if (rv != 0) { - ngtcp2_frame_chain_del(frc, strm->mem); - return rv; - } - - nfr = &nfrc->fr.stream; - *nfr = *fr; - nfr->datacnt = acnt; - ngtcp2_vec_copy(nfr->data, a, acnt); - - ngtcp2_frame_chain_del(frc, strm->mem); - - *pfrc = nfrc; - - return 0; -} - -uint64_t ngtcp2_strm_streamfrq_unacked_offset(ngtcp2_strm *strm) { - ngtcp2_frame_chain *frc; - ngtcp2_stream *fr; - ngtcp2_range gap; - ngtcp2_ksl_it it; - size_t datalen; - - assert(strm->tx.streamfrq); - assert(ngtcp2_ksl_len(strm->tx.streamfrq)); - - for (it = ngtcp2_ksl_begin(strm->tx.streamfrq); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - frc = ngtcp2_ksl_it_get(&it); - fr = &frc->fr.stream; - - gap = ngtcp2_strm_get_unacked_range_after(strm, fr->offset); - - datalen = ngtcp2_vec_len(fr->data, fr->datacnt); - - if (gap.begin <= fr->offset) { - return fr->offset; - } - if (gap.begin < fr->offset + datalen) { - return gap.begin; - } - if (fr->offset + datalen == gap.begin && fr->fin && - !(strm->flags & NGTCP2_STRM_FLAG_FIN_ACKED)) { - return fr->offset + datalen; - } - } - - return (uint64_t)-1; -} - -ngtcp2_frame_chain *ngtcp2_strm_streamfrq_top(ngtcp2_strm *strm) { - ngtcp2_ksl_it it; - - assert(strm->tx.streamfrq); - assert(ngtcp2_ksl_len(strm->tx.streamfrq)); - - it = ngtcp2_ksl_begin(strm->tx.streamfrq); - return ngtcp2_ksl_it_get(&it); -} - -int ngtcp2_strm_streamfrq_empty(ngtcp2_strm *strm) { - return strm->tx.streamfrq == NULL || ngtcp2_ksl_len(strm->tx.streamfrq) == 0; -} - -void ngtcp2_strm_streamfrq_clear(ngtcp2_strm *strm) { - ngtcp2_frame_chain *frc; - ngtcp2_ksl_it it; - - if (strm->tx.streamfrq == NULL) { - return; - } - - for (it = ngtcp2_ksl_begin(strm->tx.streamfrq); !ngtcp2_ksl_it_end(&it); - ngtcp2_ksl_it_next(&it)) { - frc = ngtcp2_ksl_it_get(&it); - ngtcp2_frame_chain_del(frc, strm->mem); - } - ngtcp2_ksl_clear(strm->tx.streamfrq); -} - -int ngtcp2_strm_is_tx_queued(ngtcp2_strm *strm) { - return strm->pe.index != NGTCP2_PQ_BAD_INDEX; -} - -int ngtcp2_strm_is_all_tx_data_acked(ngtcp2_strm *strm) { - if (strm->tx.acked_offset == NULL) { - return strm->tx.cont_acked_offset == strm->tx.offset; - } - - return ngtcp2_gaptr_first_gap_offset(strm->tx.acked_offset) == - strm->tx.offset; -} - -ngtcp2_range ngtcp2_strm_get_unacked_range_after(ngtcp2_strm *strm, - uint64_t offset) { - ngtcp2_ksl_it gapit; - ngtcp2_range gap; - - if (strm->tx.acked_offset == NULL) { - gap.begin = strm->tx.cont_acked_offset; - gap.end = UINT64_MAX; - return gap; - } - - gapit = ngtcp2_gaptr_get_first_gap_after(strm->tx.acked_offset, offset); - return *(ngtcp2_range *)ngtcp2_ksl_it_key(&gapit); -} - -uint64_t ngtcp2_strm_get_acked_offset(ngtcp2_strm *strm) { - if (strm->tx.acked_offset == NULL) { - return strm->tx.cont_acked_offset; - } - - return ngtcp2_gaptr_first_gap_offset(strm->tx.acked_offset); -} - -static int strm_acked_offset_init(ngtcp2_strm *strm) { - int rv; - ngtcp2_gaptr *acked_offset = - ngtcp2_mem_malloc(strm->mem, sizeof(*acked_offset)); - - if (acked_offset == NULL) { - return NGTCP2_ERR_NOMEM; - } - - rv = ngtcp2_gaptr_init(acked_offset, strm->mem); - if (rv != 0) { - ngtcp2_mem_free(strm->mem, acked_offset); - return rv; - } - - strm->tx.acked_offset = acked_offset; - - return 0; -} - -int ngtcp2_strm_ack_data(ngtcp2_strm *strm, uint64_t offset, uint64_t len) { - int rv; - - if (strm->tx.acked_offset == NULL) { - if (strm->tx.cont_acked_offset == offset) { - strm->tx.cont_acked_offset += len; - return 0; - } - - rv = strm_acked_offset_init(strm); - if (rv != 0) { - return rv; - } - - rv = - ngtcp2_gaptr_push(strm->tx.acked_offset, 0, strm->tx.cont_acked_offset); - if (rv != 0) { - return rv; - } - } - - return ngtcp2_gaptr_push(strm->tx.acked_offset, offset, len); -} diff --git a/deps/ngtcp2/lib/ngtcp2_strm.h b/deps/ngtcp2/lib/ngtcp2_strm.h deleted file mode 100644 index 7da8437e6681f7..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_strm.h +++ /dev/null @@ -1,266 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2017 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_STRM_H -#define NGTCP2_STRM_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_rob.h" -#include "ngtcp2_map.h" -#include "ngtcp2_gaptr.h" -#include "ngtcp2_ksl.h" -#include "ngtcp2_pq.h" - -struct ngtcp2_frame_chain; -typedef struct ngtcp2_frame_chain ngtcp2_frame_chain; - -typedef enum { - NGTCP2_STRM_FLAG_NONE = 0, - /* NGTCP2_STRM_FLAG_SHUT_RD indicates that further reception of - stream data is not allowed. */ - NGTCP2_STRM_FLAG_SHUT_RD = 0x01, - /* NGTCP2_STRM_FLAG_SHUT_WR indicates that further transmission of - stream data is not allowed. */ - NGTCP2_STRM_FLAG_SHUT_WR = 0x02, - NGTCP2_STRM_FLAG_SHUT_RDWR = - NGTCP2_STRM_FLAG_SHUT_RD | NGTCP2_STRM_FLAG_SHUT_WR, - /* NGTCP2_STRM_FLAG_SENT_RST indicates that RST_STREAM is sent from - the local endpoint. In this case, NGTCP2_STRM_FLAG_SHUT_WR is - also set. */ - NGTCP2_STRM_FLAG_SENT_RST = 0x04, - /* NGTCP2_STRM_FLAG_SENT_RST indicates that RST_STREAM is received - from the remote endpoint. In this case, NGTCP2_STRM_FLAG_SHUT_RD - is also set. */ - NGTCP2_STRM_FLAG_RECV_RST = 0x08, - /* NGTCP2_STRM_FLAG_STOP_SENDING indicates that STOP_SENDING is sent - from the local endpoint. */ - NGTCP2_STRM_FLAG_STOP_SENDING = 0x10, - /* NGTCP2_STRM_FLAG_RST_ACKED indicates that the outgoing RST_STREAM - is acknowledged by peer. */ - NGTCP2_STRM_FLAG_RST_ACKED = 0x20, - /* NGTCP2_STRM_FLAG_FIN_ACKED indicates that a STREAM with FIN bit - set is acknowledged by a remote endpoint. */ - NGTCP2_STRM_FLAG_FIN_ACKED = 0x40, -} ngtcp2_strm_flags; - -struct ngtcp2_strm; -typedef struct ngtcp2_strm ngtcp2_strm; - -struct ngtcp2_strm { - ngtcp2_map_entry me; - ngtcp2_pq_entry pe; - uint64_t cycle; - - struct { - /* acked_offset tracks acknowledged outgoing data. */ - ngtcp2_gaptr *acked_offset; - /* cont_acked_offset is the offset that all data up to this offset - is acknowledged by a remote endpoint. It is used until the - remote endpoint acknowledges data in out-of-order. After that, - acked_offset is used instead. */ - uint64_t cont_acked_offset; - /* streamfrq contains STREAM frame for retransmission. The flow - control credits have been paid when they are transmitted first - time. There are no restriction regarding flow control for - retransmission. */ - ngtcp2_ksl *streamfrq; - /* offset is the next offset of outgoing data. In other words, it - is the number of bytes sent in this stream without - duplication. */ - uint64_t offset; - /* max_tx_offset is the maximum offset that local endpoint can - send for this stream. */ - uint64_t max_offset; - } tx; - - struct { - /* rob is the reorder buffer for incoming stream data. The data - received in out of order is buffered and sorted by its offset - in this object. */ - ngtcp2_rob *rob; - /* cont_offset is the largest offset of consecutive data. It is - used until the endpoint receives out-of-order data. After - that, rob is used to track the offset and data. */ - uint64_t cont_offset; - /* last_offset is the largest offset of stream data received for - this stream. */ - uint64_t last_offset; - /* max_offset is the maximum offset that remote endpoint can send - to this stream. */ - uint64_t max_offset; - /* unsent_max_offset is the maximum offset that remote endpoint - can send to this stream, and it is not notified to the remote - endpoint. unsent_max_offset >= max_offset must be hold. */ - uint64_t unsent_max_offset; - } rx; - - const ngtcp2_mem *mem; - int64_t stream_id; - void *stream_user_data; - /* flags is bit-wise OR of zero or more of ngtcp2_strm_flags. */ - uint32_t flags; - /* app_error_code is an error code the local endpoint sent in - RST_STREAM or STOP_SENDING. */ - uint64_t app_error_code; -}; - -/* - * ngtcp2_strm_init initializes |strm|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -int ngtcp2_strm_init(ngtcp2_strm *strm, int64_t stream_id, uint32_t flags, - uint64_t max_rx_offset, uint64_t max_tx_offset, - void *stream_user_data, const ngtcp2_mem *mem); - -/* - * ngtcp2_strm_free deallocates memory allocated for |strm|. This - * function does not free the memory pointed by |strm| itself. - */ -void ngtcp2_strm_free(ngtcp2_strm *strm); - -/* - * ngtcp2_strm_rx_offset returns the minimum offset of stream data - * which is not received yet. - */ -uint64_t ngtcp2_strm_rx_offset(ngtcp2_strm *strm); - -/* - * ngtcp2_strm_recv_reordering handles reordered data. - * - * It returns 0 if it succeeds, or one of the following negative error - * codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -int ngtcp2_strm_recv_reordering(ngtcp2_strm *strm, const uint8_t *data, - size_t datalen, uint64_t offset); - -/* - * ngtcp2_strm_update_rx_offset tells that data up to offset bytes are - * received in order. - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -int ngtcp2_strm_update_rx_offset(ngtcp2_strm *strm, uint64_t offset); - -/* - * ngtcp2_strm_shutdown shutdowns |strm|. |flags| should be - * NGTCP2_STRM_FLAG_SHUT_RD, and/or NGTCP2_STRM_FLAG_SHUT_WR. - */ -void ngtcp2_strm_shutdown(ngtcp2_strm *strm, uint32_t flags); - -/* - * ngtcp2_strm_streamfrq_push pushes |frc| to streamfrq for - * retransmission. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -int ngtcp2_strm_streamfrq_push(ngtcp2_strm *strm, ngtcp2_frame_chain *frc); - -/* - * ngtcp2_strm_streamfrq_pop pops the first ngtcp2_frame_chain and - * assigns it to |*pfrc|. This function splits into or merges several - * ngtcp2_frame_chain objects so that the returned ngtcp2_frame_chain - * has at most |left| data length. If there is no frames to send, - * this function returns 0 and |*pfrc| is NULL. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGTCP2_ERR_NOMEM - * Out of memory - */ -int ngtcp2_strm_streamfrq_pop(ngtcp2_strm *strm, ngtcp2_frame_chain **pfrc, - size_t left); - -/* - * ngtcp2_strm_streamfrq_unacked_offset returns the smallest offset of - * unacknowledged stream data held in strm->tx.streamfrq. - */ -uint64_t ngtcp2_strm_streamfrq_unacked_offset(ngtcp2_strm *strm); - -/* - * ngtcp2_strm_streamfrq_top returns the first ngtcp2_frame_chain. - * The queue must not be empty. - */ -ngtcp2_frame_chain *ngtcp2_strm_streamfrq_top(ngtcp2_strm *strm); - -/* - * ngtcp2_strm_streamfrq_empty returns nonzero if streamfrq is empty. - */ -int ngtcp2_strm_streamfrq_empty(ngtcp2_strm *strm); - -/* - * ngtcp2_strm_streamfrq_clear removes all frames from streamfrq. - */ -void ngtcp2_strm_streamfrq_clear(ngtcp2_strm *strm); - -/* - * ngtcp2_strm_is_tx_queued returns nonzero if |strm| is queued. - */ -int ngtcp2_strm_is_tx_queued(ngtcp2_strm *strm); - -/* - * ngtcp2_strm_is_all_tx_data_acked returns nonzero if all outgoing - * data for |strm| which have sent so far have been acknowledged. - */ -int ngtcp2_strm_is_all_tx_data_acked(ngtcp2_strm *strm); - -/* - * ngtcp2_strm_get_unacked_range_after returns the range that is not - * acknowledged yet and intersects or comes after |offset|. - */ -ngtcp2_range ngtcp2_strm_get_unacked_range_after(ngtcp2_strm *strm, - uint64_t offset); - -/* - * ngtcp2_strm_get_acked_offset returns offset, that is the data up to - * this offset have been acknowledged by a remote endpoint. It - * returns 0 if no data is acknowledged. - */ -uint64_t ngtcp2_strm_get_acked_offset(ngtcp2_strm *strm); - -/* - * ngtcp2_strm_ack_data tells |strm| that the data [offset, - * offset+len) is acknowledged by a remote endpoint. - */ -int ngtcp2_strm_ack_data(ngtcp2_strm *strm, uint64_t offset, uint64_t len); - -#endif /* NGTCP2_STRM_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_vec.c b/deps/ngtcp2/lib/ngtcp2_vec.c deleted file mode 100644 index 7a6f8afa051f20..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_vec.c +++ /dev/null @@ -1,232 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "ngtcp2_vec.h" - -#include -#include - -#include "ngtcp2_str.h" - -ngtcp2_vec *ngtcp2_vec_init(ngtcp2_vec *vec, const uint8_t *base, size_t len) { - vec->base = (uint8_t *)base; - vec->len = len; - return vec; -} - -int ngtcp2_vec_new(ngtcp2_vec **pvec, const uint8_t *data, size_t datalen, - const ngtcp2_mem *mem) { - size_t len; - uint8_t *p; - - len = sizeof(ngtcp2_vec) + datalen; - - *pvec = ngtcp2_mem_malloc(mem, len); - if (*pvec == NULL) { - return NGTCP2_ERR_NOMEM; - } - - p = (uint8_t *)(*pvec) + sizeof(ngtcp2_vec); - (*pvec)->base = p; - (*pvec)->len = datalen; - if (datalen) { - /* p = */ ngtcp2_cpymem(p, data, datalen); - } - - return 0; -} - -void ngtcp2_vec_del(ngtcp2_vec *vec, const ngtcp2_mem *mem) { - ngtcp2_mem_free(mem, vec); -} - -size_t ngtcp2_vec_len(const ngtcp2_vec *vec, size_t n) { - size_t i; - size_t res = 0; - - for (i = 0; i < n; ++i) { - res += vec[i].len; - } - - return res; -} - -ngtcp2_ssize ngtcp2_vec_split(ngtcp2_vec *src, size_t *psrccnt, ngtcp2_vec *dst, - size_t *pdstcnt, size_t left, size_t maxcnt) { - size_t i; - size_t srccnt = *psrccnt; - size_t nmove; - size_t extra = 0; - - for (i = 0; i < srccnt; ++i) { - if (left >= src[i].len) { - left -= src[i].len; - continue; - } - - if (*pdstcnt && src[srccnt - 1].base + src[srccnt - 1].len == dst[0].base) { - if (*pdstcnt + srccnt - i - 1 > maxcnt) { - return -1; - } - - dst[0].len += src[srccnt - 1].len; - dst[0].base = src[srccnt - 1].base; - extra = src[srccnt - 1].len; - --srccnt; - } else if (*pdstcnt + srccnt - i > maxcnt) { - return -1; - } - - if (left == 0) { - *psrccnt = i; - } else { - *psrccnt = i + 1; - } - - nmove = srccnt - i; - if (nmove) { - memmove(dst + nmove, dst, sizeof(ngtcp2_vec) * (*pdstcnt)); - *pdstcnt += nmove; - memcpy(dst, src + i, sizeof(ngtcp2_vec) * nmove); - } - - dst[0].len -= left; - dst[0].base += left; - src[i].len = left; - - if (nmove == 0) { - extra -= left; - } - - return (ngtcp2_ssize)(ngtcp2_vec_len(dst, nmove) + extra); - } - - return 0; -} - -size_t ngtcp2_vec_merge(ngtcp2_vec *dst, size_t *pdstcnt, ngtcp2_vec *src, - size_t *psrccnt, size_t left, size_t maxcnt) { - size_t orig_left = left; - size_t i; - ngtcp2_vec *a, *b; - - assert(maxcnt); - - if (*pdstcnt == 0) { - if (*psrccnt == 0) { - return 0; - } - - a = &dst[0]; - b = &src[0]; - - if (left >= b->len) { - *a = *b; - ++*pdstcnt; - left -= b->len; - i = 1; - } else { - a->len = left; - a->base = b->base; - - b->len -= left; - b->base += left; - - return left; - } - } else { - i = 0; - } - - for (; left && i < *psrccnt; ++i) { - a = &dst[*pdstcnt - 1]; - b = &src[i]; - - if (left >= b->len) { - if (a->base + a->len == b->base) { - a->len += b->len; - } else if (*pdstcnt == maxcnt) { - break; - } else { - dst[(*pdstcnt)++] = *b; - } - left -= b->len; - continue; - } - - if (a->base + a->len == b->base) { - a->len += left; - } else if (*pdstcnt == maxcnt) { - break; - } else { - dst[*pdstcnt].len = left; - dst[*pdstcnt].base = b->base; - ++*pdstcnt; - } - - b->len -= left; - b->base += left; - left = 0; - - break; - } - - memmove(src, src + i, sizeof(ngtcp2_vec) * (*psrccnt - i)); - *psrccnt -= i; - - return orig_left - left; -} - -size_t ngtcp2_vec_copy_at_most(ngtcp2_vec *dst, size_t *pnwritten, - size_t dstcnt, const ngtcp2_vec *src, - size_t srccnt, size_t left) { - size_t i, j; - size_t len = left; - - *pnwritten = 0; - - for (i = 0, j = 0; left > 0 && i < srccnt && j < dstcnt;) { - if (src[i].len == 0) { - ++i; - continue; - } - dst[j] = src[i]; - if (dst[j].len > left) { - dst[j].len = left; - *pnwritten = len; - return j + 1; - } - left -= dst[j].len; - ++i; - ++j; - } - - *pnwritten = len - left; - - return j; -} - -void ngtcp2_vec_copy(ngtcp2_vec *dst, const ngtcp2_vec *src, size_t cnt) { - memcpy(dst, src, sizeof(ngtcp2_vec) * cnt); -} diff --git a/deps/ngtcp2/lib/ngtcp2_vec.h b/deps/ngtcp2/lib/ngtcp2_vec.h deleted file mode 100644 index 077820a9efed23..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_vec.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2018 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef NGTCP2_VEC_H -#define NGTCP2_VEC_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "ngtcp2_mem.h" - -/* - * ngtcp2_vec_lit is a convenient macro to fill the object pointed by - * |DEST| with the literal string |LIT|. - */ -#define ngtcp2_vec_lit(DEST, LIT) \ - ((DEST)->base = (uint8_t *)(LIT), (DEST)->len = sizeof(LIT) - 1, (DEST)) - -/* - * ngtcp2_vec_init initializes |vec| with the given parameters. It - * returns |vec|. - */ -ngtcp2_vec *ngtcp2_vec_init(ngtcp2_vec *vec, const uint8_t *base, size_t len); - -/* - * ngtcp2_vec_new allocates and initializes |*pvec| with given |data| - * of length |datalen|. This function allocates memory for |*pvec| - * and the given data with a single allocation, and the contents - * pointed by |data| is copied into the allocated memory space. To - * free the allocated memory, call ngtcp2_vec_del. - */ -int ngtcp2_vec_new(ngtcp2_vec **pvec, const uint8_t *data, size_t datalen, - const ngtcp2_mem *mem); - -/* - * ngtcp2_vec_del frees the memory allocated by |vec| which is - * allocated and initialized by ngtcp2_vec_new. - */ -void ngtcp2_vec_del(ngtcp2_vec *vec, const ngtcp2_mem *mem); - -/* - * ngtcp2_vec_len returns the sum of length in |vec| of |n| elements. - */ -size_t ngtcp2_vec_len(const ngtcp2_vec *vec, size_t n); - -/* - * ngtcp2_vec_split splits |src| to |dst| so that the sum of the - * length in |src| does not exceed |left| bytes. The |maxcnt| is the - * maximum number of elements which |dst| array can contain. The - * caller must set |*psrccnt| to the number of elements of |src|. - * Similarly, the caller must set |*pdstcnt| to the number of elements - * of |dst|. The split does not necessarily occur at the boundary of - * ngtcp2_vec object. After split has done, this function updates - * |*psrccnt| and |*pdstcnt|. This function returns the number of - * bytes moved from |src| to |dst|. If split cannot be made because - * doing so exceeds |maxcnt|, this function returns -1. - */ -ngtcp2_ssize ngtcp2_vec_split(ngtcp2_vec *src, size_t *psrccnt, ngtcp2_vec *dst, - size_t *pdstcnt, size_t left, size_t maxcnt); - -/* - * ngtcp2_vec_merge merges |src| into |dst| by moving at most |left| - * bytes from |src|. The |maxcnt| is the maximum number of elements - * which |dst| array can contain. The caller must set |*pdstcnt| to - * the number of elements of |dst|. Similarly, the caller must set - * |*psrccnt| to the number of elements of |src|. After merge has - * done, this function updates |*psrccnt| and |*pdstcnt|. This - * function returns the number of bytes moved from |src| to |dst|. - */ -size_t ngtcp2_vec_merge(ngtcp2_vec *dst, size_t *pdstcnt, ngtcp2_vec *src, - size_t *psrccnt, size_t left, size_t maxcnt); - -/* - * ngtcp2_vec_copy_at_most copies |src| of length |srccnt| to |dst| of - * length |dstcnt|. The total number of bytes which the copied - * ngtcp2_vec refers to is at most |left| and is assigned to - * |*pnwritten|. The empty elements in |src| are ignored. This - * function returns the number of elements copied. - */ -size_t ngtcp2_vec_copy_at_most(ngtcp2_vec *dst, size_t *pnwritten, - size_t dstcnt, const ngtcp2_vec *src, - size_t srccnt, size_t left); - -/* - * ngtcp2_vec_copy copies |src| of length |cnt| to |dst|. |dst| must - * have sufficient capacity. - */ -void ngtcp2_vec_copy(ngtcp2_vec *dst, const ngtcp2_vec *src, size_t cnt); - -#endif /* NGTCP2_VEC_H */ diff --git a/deps/ngtcp2/lib/ngtcp2_version.c b/deps/ngtcp2/lib/ngtcp2_version.c deleted file mode 100644 index 40f3ae3f9eade4..00000000000000 --- a/deps/ngtcp2/lib/ngtcp2_version.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * ngtcp2 - * - * Copyright (c) 2019 ngtcp2 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -static ngtcp2_info version = {NGTCP2_VERSION_AGE, NGTCP2_VERSION_NUM, - NGTCP2_VERSION}; - -ngtcp2_info *ngtcp2_version(int least_version) { - if (least_version > NGTCP2_VERSION_NUM) { - return NULL; - } - return &version; -} diff --git a/deps/ngtcp2/ngtcp2.gyp b/deps/ngtcp2/ngtcp2.gyp deleted file mode 100644 index fbdd556895537d..00000000000000 --- a/deps/ngtcp2/ngtcp2.gyp +++ /dev/null @@ -1,118 +0,0 @@ -{ - 'target_defaults': { - 'defines': [ - '_U_=' - ] - }, - 'targets': [ - { - 'target_name': 'ngtcp2', - 'type': 'static_library', - 'include_dirs': [ - 'lib/includes', - 'lib', - 'crypto/includes', - 'crypto' - ], - 'defines': [ - 'BUILDING_NGTCP2', - 'NGTCP2_STATICLIB', - ], - 'dependencies': [ - '../openssl/openssl.gyp:openssl' - ], - 'conditions': [ - ['OS=="win"', { - 'defines': [ - 'WIN32', - '_WINDOWS', - 'HAVE_CONFIG_H', - ], - 'msvs_settings': { - 'VCCLCompilerTool': { - 'CompileAs': '1' - }, - }, - }], - ['OS=="linux"', { - 'defines': [ - 'HAVE_ARPA_INET_H', - 'HAVE_NETINET_IN_H', - ], - }], - ], - 'direct_dependent_settings': { - 'defines': [ 'NGTCP2_STATICLIB' ], - 'include_dirs': [ - 'lib/includes', - 'crypto/includes', - ] - }, - 'sources': [ - 'lib/ngtcp2_acktr.c', - 'lib/ngtcp2_acktr.h', - 'lib/ngtcp2_addr.c', - 'lib/ngtcp2_addr.h', - 'lib/ngtcp2_buf.c', - 'lib/ngtcp2_buf.h', - 'lib/ngtcp2_cc.c', - 'lib/ngtcp2_cc.h', - 'lib/ngtcp2_cid.c', - 'lib/ngtcp2_cid.h', - 'lib/ngtcp2_conn.c', - 'lib/ngtcp2_conn.h', - 'lib/ngtcp2_conv.c', - 'lib/ngtcp2_conv.h', - 'lib/ngtcp2_crypto.c', - 'lib/ngtcp2_crypto.h', - 'lib/ngtcp2_err.c', - 'lib/ngtcp2_err.h', - 'lib/ngtcp2_gaptr.c', - 'lib/ngtcp2_gaptr.h', - 'lib/ngtcp2_idtr.c', - 'lib/ngtcp2_idtr.h', - 'lib/ngtcp2_ksl.c', - 'lib/ngtcp2_ksl.h', - 'lib/ngtcp2_log.c', - 'lib/ngtcp2_log.h', - 'lib/ngtcp2_macro.h', - 'lib/ngtcp2_map.c', - 'lib/ngtcp2_map.h', - 'lib/ngtcp2_mem.c', - 'lib/ngtcp2_mem.h', - 'lib/ngtcp2_path.c', - 'lib/ngtcp2_path.h', - 'lib/ngtcp2_pkt.c', - 'lib/ngtcp2_pkt.h', - 'lib/ngtcp2_ppe.c', - 'lib/ngtcp2_ppe.h', - 'lib/ngtcp2_pq.c', - 'lib/ngtcp2_pq.h', - 'lib/ngtcp2_pv.c', - 'lib/ngtcp2_pv.h', - 'lib/ngtcp2_qlog.c', - 'lib/ngtcp2_qlog.h', - 'lib/ngtcp2_range.c', - 'lib/ngtcp2_range.h', - 'lib/ngtcp2_ringbuf.c', - 'lib/ngtcp2_ringbuf.h', - 'lib/ngtcp2_rob.c', - 'lib/ngtcp2_rob.h', - 'lib/ngtcp2_rtb.c', - 'lib/ngtcp2_rtb.h', - 'lib/ngtcp2_rst.c', - 'lib/ngtcp2_rst.h', - 'lib/ngtcp2_str.c', - 'lib/ngtcp2_str.h', - 'lib/ngtcp2_strm.c', - 'lib/ngtcp2_strm.h', - 'lib/ngtcp2_vec.c', - 'lib/ngtcp2_vec.h', - 'lib/ngtcp2_version.c', - 'crypto/shared.c', - 'crypto/shared.h', - 'crypto/openssl/openssl.c' - ] - } - ] -} diff --git a/deps/npm/AUTHORS b/deps/npm/AUTHORS index 0a9c02f8b7d2b7..d731ad8ca64f03 100644 --- a/deps/npm/AUTHORS +++ b/deps/npm/AUTHORS @@ -747,3 +747,6 @@ marsonya <16393876+marsonya@users.noreply.github.com> Jeff Griffiths Michael Garvin Gar +dr-js +Pavan Bellamkonda <31280326+pavanbellamkonda@users.noreply.github.com> +Alexander Riccio diff --git a/deps/npm/CHANGELOG.md b/deps/npm/CHANGELOG.md index df3e2ba22f31ad..c3b826517edba8 100644 --- a/deps/npm/CHANGELOG.md +++ b/deps/npm/CHANGELOG.md @@ -1,3 +1,102 @@ +## v7.5.1 (2021-02-01 + +### BUG FIXES + +* [`0ea134e41`](https://github.com/npm/cli/commit/0ea134e4190f322138299c51672eab5387ec41bb) + [#2587](https://github.com/npm/cli/issues/2587) + pass all settings through to pacote.packument, fixes #2060 + ([@nlf](https://github.com/nlf)) +* [`8c5ca2f51`](https://github.com/npm/cli/commit/8c5ca2f516f5ac87f3bbd7f1fd95c0b283a21f14) + Add test for npm-usage.js, and fix 'npm --long' output + ([@isaacs](https://github.com/isaacs)) + +### DEPENDENCIES + +* [`7e4e88e93`](https://github.com/npm/cli/commit/7e4e88e938323e34a2a41176472d8e43e84bd4dd) + `@npmcli/arborist@2.1.1`, `pacote@11.2.4` + * Properly raise ERESOLVE errors on root dev dependencies + * Ignore ERESOLVE errors when performing git dep 'prepare' scripts + * Always reinstall packages that are explicitly requested + * fix global update all so it actually updates things + * Install bins properly when global root is a link + ([@isaacs](https://github.com/isaacs)) + +### DOCUMENTATION + +* [`23dac2fef`](https://github.com/npm/cli/commit/23dac2feff1d02193791c7e39d9e93bc9bf8e624) + [#2557](https://github.com/npm/cli/issues/2557) + npm team revamp + ([@ruyadorno](https://github.com/ruyadorno)) +* [`dd05ba0c0`](https://github.com/npm/cli/commit/dd05ba0c0b2f4c70eb8558c0ecc54889efbe98f5) + [#2572](https://github.com/npm/cli/issues/2572) + add note about `--force` overriding peer dependencies + ([@isaacs](https://github.com/isaacs)) +* [`e27639780`](https://github.com/npm/cli/commit/e276397809aceb01cc468e02a83bc6f2265376d9) + [#2584](https://github.com/npm/cli/issues/2584) + Fixed the spelling of contributor as it was written as conributor + ([@pavanbellamkonda](https://github.com/pavanbellamkonda)) +* [`13a5e3178`](https://github.com/npm/cli/commit/13a5e31781cdaa37d3f007e1c8583c7cb591c62a) + [#2502](https://github.com/npm/cli/issues/2502) + elaborate that npm help uses browser + ([@ariccio](https://github.com/ariccio)) + +## v7.5.0 (2021-01-28) + +### FEATURES + +* [`d011266b7`](https://github.com/npm/cli/commit/d011266b733367aad283ccbfb9d2b19442c3405f) + [#1319](https://github.com/npm/cli/issues/1319) + add npm diff command + ([@ruyadorno](https://github.com/ruyadorno)) + +### BUG FIXES + +* [`d2f8af2da`](https://github.com/npm/cli/commit/d2f8af2da64d510d3d363aec10531bebf840d84e) + [#2445](https://github.com/npm/cli/issues/2445) + publish: don't complain about missing auth until after registry is chosen + ([@dr-js](https://github.com/dr-js)) + +### DOCUMENTATION + +* [`8d3fd63aa`](https://github.com/npm/cli/commit/8d3fd63aaa6a5c9b3d2281dd0bd9e1c270b35941) + [#2559](https://github.com/npm/cli/issues/2559) + updates to readme, removal, contributing and several other docs + ([@darcyclarke](https://github.com/darcyclarke)) +* [`7772d9f9f`](https://github.com/npm/cli/commit/7772d9f9f9f853573a7ff8e7fb60c5e46566f596) + [#2542](https://github.com/npm/cli/issues/2542) + fix grammar on caching docs for search, exec and init + ([@wraithgar](https://github.com/wraithgar)) +* [`52e8a1aef`](https://github.com/npm/cli/commit/52e8a1aef4aab3f378c20276a9109bb3f00eccd5) + [#2558](https://github.com/npm/cli/issues/2558) + refreshed npm updated docs + ([@ruyadorno](https://github.com/ruyadorno)) +* [`abae00ca0`](https://github.com/npm/cli/commit/abae00ca05925e521696dd12480853509aab6c0a) + [#2565](https://github.com/npm/cli/issues/2565) + update npm command docs + ([@wraithgar](https://github.com/wraithgar)) +* [`9351cbf9a`](https://github.com/npm/cli/commit/9351cbf9afd2310c56b9953c005505ea5126a5d4) + [#2566](https://github.com/npm/cli/issues/2566) + refresh npm run-script docs + ([@ruyadorno](https://github.com/ruyadorno)) + +### DEPENDENCIES + +* [`56c08863e`](https://github.com/npm/cli/commit/56c08863e15cb9cf8662b99ddc627cfcdff0348d) + `hosted-git-info@3.0.8` +* [`18a93f06b`](https://github.com/npm/cli/commit/18a93f06b632be051b9455e32a85e4e75066f52c) + `ssri@8.0.1` +* [`cb768f671`](https://github.com/npm/cli/commit/cb768f671c4d8d5a09d9a6c5a74227d300e81104) + `@npmcli/move-file@1.1.1` +* [`32cc0a4be`](https://github.com/npm/cli/commit/32cc0a4be76465093e3d0f314215a0ec46dc03c6) + `minipass-fetch@1.3.3` + * fixes ssl settings passthrough +* [`530997968`](https://github.com/npm/cli/commit/530997968fbbd9e8bf016689b1d192daa812b4de) + `@npmcli/arborist@2.1.0` + * added signal handler to rollback when possible + * prevent ERESOLVEs caused by loose root dep specs + * detect conflicts among nested peerOptional deps + * properly buildIdealTree when root is a symlink + ## v7.4.3 (2021-01-21) ### DOCUMENTATION diff --git a/deps/npm/CONTRIBUTING.md b/deps/npm/CONTRIBUTING.md index 3e3512ffeaec05..5198918f010dfa 100644 --- a/deps/npm/CONTRIBUTING.md +++ b/deps/npm/CONTRIBUTING.md @@ -1,191 +1,56 @@ -# npm CLI Contributor Roles and Responsibilities +# Contributing -## Table of Contents +## Code of Conduct -* [Introduction](#introduction) -* [Code Structure](#code-structure) -* [Running Tests](#running-tests) -* [Debugging](#debugging) -* [Coverage](#coverage) -* [Benchmarking](#benchmarking) -* [Types of Contributions](#types-of-contributions) - * [Contributing an Issue?](#contributing-an-issue) - * [Contributing a Question?](#contributing-a-question) - * [Contributing a Bug Fix?](#contributing-a-bug-fix) - * [Contributing a Feature?](#contributing-a-bug-feature) -* [Development Dependencies](#development-dependencies) -* [Dependencies](#dependencies) +All interactions in the **npm** organization on GitHub are considered to be covered by our standard [Code of Conduct](https://www.npmjs.com/policies/conduct). -## Introduction +## Development -Welcome to the npm CLI Contributor Guide! This document outlines the npm CLI repository's process for community interaction and contribution. This includes the issue tracker, pull requests, wiki pages, and, to a certain extent, outside communication in the context of the npm CLI. This is an entry point for anyone wishing to contribute their time and effort to making npm a better tool for the JavaScript community! +**1. Clone this repository...** -All interactions in the npm repository are covered by the [npm Code of Conduct](https://www.npmjs.com/policies/conduct) +```bash +$ git clone git@github.com:npm/cli.git +``` +**2. Navigate into project & install development-specific dependencies...** -## Code Structure -``` -/ -├── bin/ -│ │ # Directory for executable files. It's very rare that you -│ │ # will need to update a file in this directory. -│ │ -│ ├── npm # npm-cli entrypoint for bourne shell -│ ├── npm-cli.js # npm-cli entrypoint for node -│ ├── npm.cmd # npm-cli entrypoint for windows -│ ├── npx # npx entrypoint for bourne shell -│ ├── npx-cli.js # npx entrypoint for node -│ └── npx.cmd # npx entrypoint for windows -│ -├── docs/ 📖 -│ │ # Directory that contains the documentation website for -│ │ # the npm-cli. You can run this website locally, and have -│ │ # offline docs! 🔥📖🤓 -│ │ -│ ├── content/ # Markdown files for site content -│ ├── src/ # Source files for the website; gatsby related -│ └── package.json # Site manifest; scripts and dependencies -│ -├── lib/ 📦 -│ # All the Good Bits(tm) of the CLI project live here -│ -├── node_modules/ 🔋 -│ # Vendored dependencies for the CLI project (See the -│ # dependencies section below for more details). -│ -├── scripts/ 📜 -│ # We've created some helper scripts for working with the -│ # CLI project, specifically around managing our vendored -│ # dependencies, merging in pull-requests, and publishing -│ # releases. -│ -├── test/ 🧪 -│ # All the tests for the CLI live in this folder. We've -│ # got a lot of tests 🤓🧪🩺 -│ -├── CONTRIBUTING.md # This file! 🎉 -└── package.json # The projects main manifest file 📃 +```bash +$ cd ./npm && npm install ``` -## Running Tests +**3. Write some code &/or add some tests...** +```bash +... ``` -# Make sure you install the dependencies first before running tests. -$ npm install -# Run tests for the CLI (it could take a while). -$ npm run test +**4. Run tests & ensure they pass...** ``` - -## Debugging - -It can be tricky to track down issues in the CLI. It's a large code base that has been evolving for over a decade. There is a handy `make` command that will connect the **cloned repository** you have on your machine with the global command, so you can add `console.log` statements or debug any other way you feel most comfortable with. - +$ npm run test ``` -# Clone the repository to start with -$ git clone git@github.com:npm/cli.git -# Change working directories into the repository -$ cd cli +**5. Open a [Pull Request](https://github.com/npm/cli/pulls) for your work & become the newest contributor to `npm`! 🎉** -# Make sure you have the latest code (if that's what you're trying to debug) -$ git fetch origin latest +## Test Coverage -# Connect repository to the global namespace -$ make link +We expect that every new feature or bug fix comes with corresponding tests that validate the solutions. We strive to have as close to, if not exactly, 100% code coverage. -################# -# ALTERNATIVELY -################# -# If you're working on a feature or bug, you can run the same command on your -# working branch and link that code. +**You can find out what the current test coverage percentage is by running...** -# Create new branch to work from (there are many ways) -$ git checkout -b feature/awesome-feature - -# Connect repository to global namespace -$ make link -``` - -## Coverage - -We try and make sure that each new feature or bug fix has tests to go along with them in order to keep code coverages consistent and increasing. We are actively striving for 100% code coverage! - -``` -# You can run the following command to find out coverage +```bash $ npm run test-coverage ``` -## Benchmarking - -We often want to know if the bug we've fixed for the feature we've added has any sort of performance impact. We've created a [benchmark suite](https://github.com/npm/benchmarks) to run against the CLI project from pull-requests. If you would like to know if there are any performance impacts to the work you're contributing, simply do the following: +## Performance & Benchmarks -1. Make a pull-request against this repository -2. Add the following comment to the pull-request: "`test this please ✅`" +We've set up an automated [benchmark](https://github.com/npm/benchmarks) integration that will run against all Pull Requests; Posting back a comment with the results of the run. -This will trigger the [benchmark suite](https://github.com/npm/benchmarks) to run against your pull-request, and when it's finished running it will post a comment on your pull-request just like below. You'll be able to see the results from the suite inline in your pull-request. - -> You'll notice that the bot-user will also add a 🚀 reaction to your comment to -let you know that it's sent the request to start the benchmark suite. +**Example:** ![image](https://user-images.githubusercontent.com/2818462/72312698-e2e57f80-3656-11ea-9fcf-4a8f6b97b0d1.png) -If you've updated your pull-request and you'd like to run the the benchmark suite again, simple update your original comment, by adding `test this please ✅` again, or simply just adding another emoji to the **end**. _(The trigger is the phrase "test this please ✅" at the beginning of a comment. Updates will trigger as well, so long as the phrase stays at the beginning.)_. - -![image](https://user-images.githubusercontent.com/2818462/72313006-ec231c00-3657-11ea-9bd9-227634d67362.png) - -## Types of Contributions - -### Contributing an Issue? - -Great!! Is your [new issue](https://github.com/npm/cli/issues/new/choose) a [bug](https://github.com/npm/cli/issues/new?template=bug.md&title=%5BBUG%5D+%3Ctitle%3E), a [feature](https://github.com/npm/cli/issues/new?template=feature.md&title=%5BFEATURE%5D+%3Ctitle%3E), or a [question](https://github.com/npm/cli/issues/new?template=question.md&title=%5BQUESTION%5D+%3Ctitle%3E)? - -### Contributing a Question? - -Huh? 🤔 Got a situation you're not sure about?! Perfect! We've got some resources you can use. - -* Our [documentation site](https://docs.npmjs.com/) -* The local docs that come with the CLI project - - > **Example**: `npm help install --viewer browser` - -* The man pages that are built and shipped with the CLI - - > **Example**: `man npm-install` (only on linux/macOS) - -* Search of the [current issues](https://github.com/npm/cli/issues) - -### Contributing a Bug Fix? - -We'd be happy to triage and help! Head over to the issues and [create a new one](https://github.com/npm/cli/issues/new?template=bug.md&title=%5BBUG%5D+%3Ctitle%3E)! - -> We'll need a little bit of information about what happened, rather than "it broke". Such as: -* When did/does this bug happen? -* Can you reproduce it? _(Can you make it happen more than once.)_ -* What version of `node`/`npm` are you running on your computer? -* What did you expect it to do? -* What did it _actually do? -* etc... - -### Contributing a Feature? - -Snazzy, we're always up for fancy new things! If the feature is fairly minor, the team can triage it and prioritize it into our backlog. However, if the feature is a little more complex, then it's best to create an [RFC](https://en.wikipedia.org/wiki/Request_for_Comments) in our [RFC repository](https://github.com/npm/rfcs). Exactly how to do that is outlined in that repository. If you're not sure _exactly_ how to implement your idea, or don't want to make a document about your idea, then please create an issue on that repository. We consider these RRFC's, or a "Requesting Request For Comment". - -## Development Dependencies - -You'll need a few things installed in order to update and test the CLI project during development: - -* [node](https://nodejs.org/) v8 or greater - -> We recommend that you have a [node version manager](https://github.com/nvm-sh/nvm) installed if you plan on fixing bugs that might be present in a specific version of node. With a version manager you can easily switch versions of node and test if your changes to the CLI project are working. - -* [git](https://git-scm.com/) v2.11+ - - -## Dependencies - -> Package vendoring is commonly referred to as the case where dependent packages are stored in the same place as your project. That usually means you dependencies are checked into your source management system, such as Git. +You can learn more about this tool, including how to run & configure it manually, [here](https://github.com/npm/benchmarks) -The CLI project vendors its dependencies in the `node_modules/` folder. Meaning all the dependencies that the CLI project uses are contained within the project itself. This is represented by the `bundledDependencies` section in the root level `package.json` file. The main reason for this is because the `npm` CLI project is distributed with the NodeJS runtime and needs to work out of the box, which means all dependencies need to be available after the runtime is installed. +## Reporting Bugs -There are a couple scripts created to help manage this process in the `scripts/` folder. +When submitting a new bug report, please first [search](https://github.com/npm/cli/issues) for an existing or similar report & then use one of our existing [issue templates](https://github.com/npm/cli/issues/new/choose) if you believe you've come across a unique problem. Duplicate issues, or issues that don't use one of our templates may get closed without a response. diff --git a/deps/npm/README.md b/deps/npm/README.md index 794a24b6b15207..9350087f62cd13 100644 --- a/deps/npm/README.md +++ b/deps/npm/README.md @@ -1,163 +1,53 @@ -npm(1) -- a JavaScript package manager -============================== +[![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/npm/cli/Node%20CI/latest)](https://github.com/npm/cli/actions?query=workflow%3A%22Node+CI%22+branch%3Alatest) [![Coveralls github branch](https://img.shields.io/coveralls/github/npm/cli/latest)](https://coveralls.io/github/npm/cli?branch=latest) -[![Build Status](https://img.shields.io/travis/npm/cli/latest.svg)](https://travis-ci.org/npm/cli) +# npm - a JavaScript package manager -## SYNOPSIS +### Requirements -This is just enough info to get you up and running. +* [**Node.js** `v10`](https://nodejs.org/en/download/) or higher must be installed to run this program -Much more info will be available via `npm help` once it's installed. +### Installation -## IMPORTANT +**`npm`** comes bundled with [**`node`**](https://nodejs.org/), & most third-party distributions, by default. Officially supported downloads/distributions can be found at: [nodejs.org/en/download](https://nodejs.org/en/download) -**You need node v6 or higher to run this program.** +#### Direct Download -To install an old **and unsupported** version of npm that works on node v5 -and prior, clone the git repo and dig through the old tags and branches. +You can download & install **`npm`** directly from [**npmjs**.com](https://npmjs.com/) using our custom `install.sh` script: -**npm is configured to use npm, Inc.'s public registry at - by default.** Use of the npm public registry -is subject to terms of use available at . - -You can configure npm to use any compatible registry you -like, and even run your own registry. Check out the [doc on -registries](https://docs.npmjs.com/misc/registry). - -## Super Easy Install - -npm is bundled with [node](https://nodejs.org/en/download/). - -### Windows Computers - -[Get the MSI](https://nodejs.org/en/download/). npm is in it. - -### Apple Macintosh Computers - -[Get the pkg](https://nodejs.org/en/download/). npm is in it. - -### Other Sorts of Unices - -Run `make install`. npm will be installed with node. - -If you want a more fancy pants install (a different version, customized -paths, etc.) then read on. - -## Fancy Install (Unix) - -There's a pretty robust install script at -. You can download that and run it. - -Here's an example using curl: - -```sh +```bash curl -L https://www.npmjs.com/install.sh | sh ``` -### Slightly Fancier +#### Node Version Managers -You can set any npm configuration params with that script: +If you're looking to manage multiple versions of **`node`** &/or **`npm`**, consider using a "Node Version Manager" such as: -```sh -npm_config_prefix=/some/path sh install.sh -``` +* [**`nvm`**](https://github.com/nvm-sh/nvm) +* [**`nvs`**](https://github.com/jasongin/nvs) +* [**`nave`**](https://github.com/isaacs/nave) +* [**`n`**](https://github.com/tj/n) +* [**`volta`**](https://github.com/volta-cli/volta) -Or, you can run it in uber-debuggery mode: +### Usage -```sh -npm_debug=1 sh install.sh +```bash +npm ``` -### Even Fancier - -Get the code with git. Use `make` to build the docs and do other stuff. -If you plan on hacking on npm, `make link` is your friend. - -If you've got the npm source code, you can also semi-permanently set -arbitrary config keys using the `./configure --key=val ...`, and then -run npm commands by doing `node bin/npm-cli.js `. (This is helpful -for testing, or running stuff without actually installing npm itself.) - -## Windows Install or Upgrade - -Many improvements for Windows users have been made in npm 3 - you will have a better -experience if you run a recent version of npm. To upgrade, either use [Microsoft's -upgrade tool](https://github.com/felixrieseberg/npm-windows-upgrade), -[download a new version of Node](https://nodejs.org/en/download/), -or follow the Windows upgrade instructions in the -[Installing/upgrading npm](https://npm.community/t/installing-upgrading-npm/251/2) post. - -If that's not fancy enough for you, then you can fetch the code with -git, and mess with it directly. - -## Installing on Cygwin - -No. - -## Uninstalling - -So sad to see you go. - -```sh -sudo npm uninstall npm -g -``` -Or, if that fails, - -```sh -sudo make uninstall -``` - -## More Severe Uninstalling - -Usually, the above instructions are sufficient. That will remove -npm, but leave behind anything you've installed. - -If you would like to remove all the packages that you have installed, -then you can use the `npm ls` command to find them, and then `npm rm` to -remove them. - -To remove cruft left behind by npm 0.x, you can use the included -`clean-old.sh` script file. You can run it conveniently like this: - -```sh -npm explore npm -g -- sh scripts/clean-old.sh -``` - -npm uses two configuration files, one for per-user configs, and another -for global (every-user) configs. You can view them by doing: - -```sh -npm config get userconfig # defaults to ~/.npmrc -npm config get globalconfig # defaults to /usr/local/etc/npmrc -``` - -Uninstalling npm does not remove configuration files by default. You -must remove them yourself manually if you want them gone. Note that -this means that future npm installs will not remember the settings that -you have chosen. - -## More Docs - -Check out the [docs](https://docs.npmjs.com/). - -You can use the `npm help` command to read any of them. - -If you're a developer, and you want to use npm to publish your program, -you should [read this](https://docs.npmjs.com/misc/developers). - -## BUGS - -When you find issues, please report them: - -* web: - -* archived web: - +### Links & Resources -Be sure to include *all* of the output from the npm command that didn't work -as expected. The `npm-debug.log` file is also helpful to provide. +* [**Documentation**](https://docs.npmjs.com/) - Official docs & how-tos for all things **npm** + * Note: you can also search docs locally with `npm help-search ` +* [**Bug Tracker**](https://github.com/npm/cli/issues) - Search or submit bugs against the CLI +* [**Roadmap**](https://github.com/npm/roadmap) - Track & follow along with our public roadmap +* [**Feedback**](https://github.com/npm/feedback) - Contribute ideas & discussion around the npm registry, website & CLI +* [**RFCs**](https://github.com/npm/rfcs) - Contribute ideas & specifications for the API/design of the npm CLI +* [**Service Status**](https://status.npmjs.org/) - Monitor the current status & see incident reports for the website & registry +* [**Project Status**](https://npm.github.io/statusboard/) - See the health of all our maintained OSS projects in one view +* [**Events Calendar**](https://calendar.google.com/calendar/u/0/embed?src=npmjs.com_oonluqt8oftrt0vmgrfbg6q6go@group.calendar.google.com) - Keep track of our Open RFC calls, releases, meetups, conferences & more +* [**Support**](https://www.npmjs.com/support) - Experiencing problems with the **npm** [website](https://npmjs.com) or [registry](https://registry.npmjs.org)? File a ticket [here](https://www.npmjs.com/support) -## SEE ALSO +### Acknowledgments -* npm(1) -* npm-help(1) +* `npm` is configured to use the **npm Public Registry** at [https://registry.npmjs.org](https://registry.npmjs.org) by default; Usage of this registry is subject to **Terms of Use** available at [https://npmjs.com/policies/terms](https://npmjs.com/policies/terms) +* You can configure `npm` to use any other compatible registry you prefer. You can read more about configuring third-party registries [here](https://docs.npmjs.com/cli/v7/using-npm/registry) \ No newline at end of file diff --git a/deps/npm/docs/content/commands/npm-diff.md b/deps/npm/docs/content/commands/npm-diff.md new file mode 100644 index 00000000000000..0ce5e8dc8baee6 --- /dev/null +++ b/deps/npm/docs/content/commands/npm-diff.md @@ -0,0 +1,237 @@ +--- +title: npm-diff +section: 1 +description: The registry diff command +--- + +### Synopsis + +```bash +npm diff [...] +npm diff --diff= [...] +npm diff --diff= [--diff=] [...] +npm diff --diff= [--diff=] [...] +npm diff [--diff-ignore-all-space] [--diff-name-only] [...] +``` + +### Description + +Similar to its `git diff` counterpart, this command will print diff patches +of files for packages published to the npm registry. + +* `npm diff --diff= --diff=` + + Compares two package versions using their registry specifiers, e.g: + `npm diff --diff=pkg@1.0.0 --diff=pkg@^2.0.0`. It's also possible to + compare across forks of any package, + e.g: `npm diff --diff=pkg@1.0.0 --diff=pkg-fork@1.0.0`. + + Any valid spec can be used, so that it's also possible to compare + directories or git repositories, + e.g: `npm diff --diff=pkg@latest --diff=./packages/pkg` + + Here's an example comparing two different versions of a package named + `abbrev` from the registry: + + ```bash + npm diff --diff=abbrev@1.1.0 --diff=abbrev@1.1.1 + ``` + + On success, output looks like: + + ```bash + diff --git a/package.json b/package.json + index v1.1.0..v1.1.1 100644 + --- a/package.json + +++ b/package.json + @@ -1,6 +1,6 @@ + { + "name": "abbrev", + - "version": "1.1.0", + + "version": "1.1.1", + "description": "Like ruby's abbrev module, but in js", + "author": "Isaac Z. Schlueter ", + "main": "abbrev.js", + ``` + + Given the flexible nature of npm specs, you can also target local + directories or git repos just like when using `npm install`: + + ```bash + npm diff --diff=https://github.com/npm/libnpmdiff --diff=./local-path + ``` + + In the example above we can compare the contents from the package installed + from the git repo at `github.com/npm/libnpmdiff` with the contents of the + `./local-path` that contains a valid package, such as a modified copy of + the original. + +* `npm diff` (in a package directory, no arguments): + + If the package is published to the registry, `npm diff` will fetch the + tarball version tagged as `latest` (this value can be configured using the + `tag` option) and proceed to compare the contents of files present in that + tarball, with the current files in your local file system. + + This workflow provides a handy way for package authors to see what + package-tracked files have been changed in comparison with the latest + published version of that package. + +* `npm diff --diff=` (in a package directory): + + When using a single package name (with no version or tag specifier) as an + argument, `npm diff` will work in a similar way to + [`npm-outdated`](npm-outdated) and reach for the registry to figure out + what current published version of the package named will satisfy + its dependent declared semver-range. Once that specific version is known + `npm diff` will print diff patches comparing the current version of + found in the local file system with that specific version + returned by the registry. + + Given a package named `abbrev` that is currently installed: + + ```bash + npm diff --diff=abbrev + ``` + + That will request from the registry its most up to date version and + will print a diff output comparing the currently installed version to this + newer one if the version numbers are not the same. + +* `npm diff --diff=` (in a package directory): + + Similar to using only a single package name, it's also possible to declare + a full registry specifier version if you wish to compare the local version + of an installed package with the specific version/tag/semver-range provided + in ``. + + An example: assuming `pkg@1.0.0` is installed in the current `node_modules` + folder, running: + + ```bash + npm diff --diff=pkg@2.0.0 + ``` + + It will effectively be an alias to + `npm diff --diff=pkg@1.0.0 --diff=pkg@2.0.0`. + +* `npm diff --diff= [--diff=]` (in a package directory): + + Using `npm diff` along with semver-valid version numbers is a shorthand + to compare different versions of the current package. + + It needs to be run from a package directory, such that for a package named + `pkg` running `npm diff --diff=1.0.0 --diff=1.0.1` is the same as running + `npm diff --diff=pkg@1.0.0 --diff=pkg@1.0.1`. + + If only a single argument `` is provided, then the current local + file system is going to be compared against that version. + + Here's an example comparing two specific versions (published to the + configured registry) of the current project directory: + + ```bash + npm diff --diff=1.0.0 --diff=1.1.0 + ``` + +Note that tag names are not valid `--diff` argument values, if you wish to +compare to a published tag, you must use the `pkg@tagname` syntax. + +#### Filtering files + +It's possible to also specify positional arguments using file names or globs +pattern matching in order to limit the result of diff patches to only a subset +of files for a given package, e.g: + + ```bash + npm diff --diff=pkg@2 ./lib/ CHANGELOG.md + ``` + +In the example above the diff output is only going to print contents of files +located within the folder `./lib/` and changed lines of code within the +`CHANGELOG.md` file. + +### Configuration + +#### diff + +* Type: Array +* Default: null + +Defines npm package specifiers to compare using the `npm diff` command. + +This can be specified up to 2 times. + +#### diff-name-only + +* Type: Boolean +* Default: false + +When set to `true` running `npm diff` only returns the names of the files that +have any difference. + +#### diff-unified + +* Type: Number +* Default: `3` + +The number of lines of context to print in the unified diff format output. + +#### diff-ignore-all-space + +* Type: Boolean +* Default: false + +Ignore whitespace when comparing lines. This ignores differences even if one +line has whitespace where the other line has none. + +#### diff-no-prefix + +* Type: Boolean +* Default: false + +Do not show any source or destination prefix. + +#### diff-src-prefix + +* Type: String +* Default: `"a/"` + +Show the given source prefix in diff patches headers instead of using "a/". + +#### diff-dst-prefix + +* Type: String +* Default: `"b/"` + +Show the given source prefix in diff patches headers instead of using "b/". + +#### diff-text + +* Type: Boolean +* Default: false + +Treat all files as text. + +#### global + +* Default: false +* Type: Boolean + +Uses packages from the global space as a source for comparison. + +#### tag + +* Type: String +* Default: `"latest"` + +The tag used to fetch the tarball that will be compared with the local file +system files when running npm diff with no arguments. + + +## See Also + +* [npm outdated](/commands/npm-outdated) +* [npm install](/commands/npm-install) +* [npm config](/commands/npm-config) +* [npm registry](/using-npm/registry) diff --git a/deps/npm/docs/content/commands/npm-exec.md b/deps/npm/docs/content/commands/npm-exec.md index 3ae30fa0cba9a7..cb3e51c8255d4b 100644 --- a/deps/npm/docs/content/commands/npm-exec.md +++ b/deps/npm/docs/content/commands/npm-exec.md @@ -173,6 +173,28 @@ This resulted in some shifts in its functionality: - The `--shell` option is replaced with `--script-shell`, but maintained in the `npx` executable for backwards compatibility. +### A note on caching + +The npm cli utilizes its internal package cache when using the package +name specified. You can use the following to change how and when the +cli uses this cache. See [`npm cache`](/commands/npm-cache) for more on +how the cache works. + +#### prefer-online + +Forces staleness checks for packages, making the cli look for updates +immediately even if the package is already in the cache. + +#### prefer-offline + +Bypasses staleness checks for packages. Missing data will still be +requested from the server. To force full offline mode, use `offline`. + +#### offline + +Forces full offline mode. Any packages not locally cached will result in +an error. + ### See Also * [npm run-script](/commands/npm-run-script) diff --git a/deps/npm/docs/content/commands/npm-init.md b/deps/npm/docs/content/commands/npm-init.md index 3eac923175b5a1..8a40d90e8354d5 100644 --- a/deps/npm/docs/content/commands/npm-init.md +++ b/deps/npm/docs/content/commands/npm-init.md @@ -71,9 +71,32 @@ Generate it without having it ask any questions: $ npm init -y ``` +### A note on caching + +The npm cli utilizes its internal package cache when using the package +name specified. You can use the following to change how and when the +cli uses this cache. See [`npm cache`](/commands/npm-cache) for more on +how the cache works. + +#### prefer-online + +Forces staleness checks for packages, making the cli look for updates +immediately even if the package is already in the cache. + +#### prefer-offline + +Bypasses staleness checks for packages. Missing data will still be +requested from the server. To force full offline mode, use `offline`. + +#### offline + +Forces full offline mode. Any packages not locally cached will result in +an error. + ### See Also * [init-package-json module](http://npm.im/init-package-json) * [package.json](/configuring-npm/package-json) * [npm version](/commands/npm-version) * [npm scope](/using-npm/scope) +* [npm exec](/commands/npm-exec) diff --git a/deps/npm/docs/content/commands/npm-owner.md b/deps/npm/docs/content/commands/npm-owner.md index 6479f3bdd11f42..69eba56afd97d5 100644 --- a/deps/npm/docs/content/commands/npm-owner.md +++ b/deps/npm/docs/content/commands/npm-owner.md @@ -39,4 +39,3 @@ on the command line when changing ownership with `--otp`. * [npm publish](/commands/npm-publish) * [npm registry](/using-npm/registry) * [npm adduser](/commands/npm-adduser) -* [npm disputes](/using-npm/disputes) diff --git a/deps/npm/docs/content/commands/npm-run-script.md b/deps/npm/docs/content/commands/npm-run-script.md index b7ab20a73af473..8b89435e1a97be 100644 --- a/deps/npm/docs/content/commands/npm-run-script.md +++ b/deps/npm/docs/content/commands/npm-run-script.md @@ -32,7 +32,7 @@ npm run test -- --grep="pattern" ``` The arguments will only be passed to the script specified after ```npm run``` -and not to any pre or post script. +and not to any `pre` or `post` script. The `env` script is a special built-in command that can be used to list environment variables that will be available to the script at runtime. If an @@ -56,7 +56,8 @@ instead of ``` The actual shell your script is run within is platform dependent. By default, -on Unix-like systems it is the `/bin/sh` command, on Windows it is the `cmd.exe`. +on Unix-like systems it is the `/bin/sh` command, on Windows it is +`cmd.exe`. The actual shell referred to by `/bin/sh` also depends on the system. You can customize the shell with the `script-shell` configuration. @@ -73,15 +74,43 @@ If `--scripts-prepend-node-path=auto` is passed (which has been the default in `npm` v3), this is only performed when that `node` executable is not found in the `PATH`. -If you try to run a script without having a `node_modules` directory and it fails, -you will be given a warning to run `npm install`, just in case you've forgotten. +If you try to run a script without having a `node_modules` directory and it +fails, you will be given a warning to run `npm install`, just in case you've +forgotten. -You can use the `--silent` flag to prevent showing `npm ERR!` output on error. +### Configuration + +#### if-present + +* Type: Boolean +* Default: false You can use the `--if-present` flag to avoid exiting with a non-zero exit code when the script is undefined. This lets you run potentially undefined scripts without breaking the execution chain. +#### ignore-scripts + +* Type: Boolean +* Default: false + +Skips running `pre` and `post` scripts. + +#### script-shell + +* Type: String +* Default: `null` + +Optional custom script to use to execute the command. If not defined defaults +to `/bin/sh` on Unix, defaults to `env.comspec` or `cmd.exe` on Windows. + +#### silent + +* Type: Boolean +* Default: false + +You can use the `--silent` flag to prevent showing `npm ERR!` output on error. + ### See Also * [npm scripts](/using-npm/scripts) diff --git a/deps/npm/docs/content/commands/npm-search.md b/deps/npm/docs/content/commands/npm-search.md index 33864d472d4a20..35178bcb0a580a 100644 --- a/deps/npm/docs/content/commands/npm-search.md +++ b/deps/npm/docs/content/commands/npm-search.md @@ -110,13 +110,13 @@ on how the cache works. #### prefer-online -Forced staleness checks for cached searches, making the cli look for +Forces staleness checks for cached searches, making the cli look for updates immediately even for fresh search results. #### prefer-offline -Bypasses staleness checks for cached. Missing data will still be -requested from the server. To force full offline mode, use `offline`. +Bypasses staleness checks for cached searches. Missing data will still +be requested from the server. To force full offline mode, use `offline`. #### offline diff --git a/deps/npm/docs/content/commands/npm-team.md b/deps/npm/docs/content/commands/npm-team.md index 4901ae1680a54a..96aacd8ae95f22 100644 --- a/deps/npm/docs/content/commands/npm-team.md +++ b/deps/npm/docs/content/commands/npm-team.md @@ -14,8 +14,6 @@ npm team add npm team rm npm team ls | - -npm team edit ``` ### Description @@ -24,31 +22,76 @@ Used to manage teams in organizations, and change team memberships. Does not handle permissions for packages. Teams must always be fully qualified with the organization/scope they belong to -when operating on them, separated by a colon (`:`). That is, if you have a `wombats` team in a `wisdom` organization, you must always refer to that team as `wisdom:wombats` in these commands. +when operating on them, separated by a colon (`:`). That is, if you have a +`newteam` team in an `org` organization, you must always refer to that team +as `@org:newteam` in these commands. -If you have two-factor authentication enabled in `auth-and-writes` mode, then you can provide a code from your authenticator with `[--otp ]`. If you don't include this then you will be prompted. +If you have two-factor authentication enabled in `auth-and-writes` mode, then +you can provide a code from your authenticator with `[--otp ]`. +If you don't include this then you will be prompted. * create / destroy: - Create a new team, or destroy an existing one. Note: You cannot remove the `developers` team, learn more. -* add / rm: - Add a user to an existing team, or remove a user from a team they belong to. + Create a new team, or destroy an existing one. Note: You cannot remove the + `developers` team, learn more. + + Here's how to create a new team `newteam` under the `org` org: + + ```bash + npm team create @org:newteam + ``` + + You should see a confirming message such as: `+@org:newteam` once the new + team has been created. + +* add: + Add a user to an existing team. + + Adding a new user `username` to a team named `newteam` under the `org` org: + + ```bash + npm team add @org:newteam username + ``` + + On success, you should see a message: `username added to @org:newteam` + +* rm: + Using `npm team rm` you can also remove users from a team they belong to. + + Here's an example removing user `username` from `newteam` team + in `org` organization: + + ```bash + npm team rm @org:newteam username + ``` + + Once the user is removed a confirmation message is displayed: + `username removed from @org:newteam` * ls: If performed on an organization name, will return a list of existing teams under that organization. If performed on a team, it will instead return a list of all users belonging to that particular team. -* edit: - Edit a current team. + Here's an example of how to list all teams from an org named `org`: + + ```bash + npm team ls @org + ``` + + Example listing all members of a team named `newteam`: + + ```bash + npm team ls @org:newteam + ``` ### Details `npm team` always operates directly on the current registry, configurable from the command line using `--registry=`. -In order to create teams and manage team membership, you must be a *team admin* -under the given organization. Listing teams and team memberships may be done by -any member of the organizations. +You must be a *team admin* to create teams and manage team membership, under +the given organization. Listing teams and team memberships may be done by +any member of the organization. Organization creation and management of team admins and *organization* members is done through the website, not the npm CLI. @@ -59,4 +102,5 @@ use the `npm access` command to grant or revoke the appropriate permissions. ### See Also * [npm access](/commands/npm-access) +* [npm config](/commands/npm-config) * [npm registry](/using-npm/registry) diff --git a/deps/npm/docs/content/commands/npm-update.md b/deps/npm/docs/content/commands/npm-update.md index 424d686189dca6..012c8472c93fec 100644 --- a/deps/npm/docs/content/commands/npm-update.md +++ b/deps/npm/docs/content/commands/npm-update.md @@ -1,7 +1,7 @@ --- title: npm-update section: 1 -description: Update a package +description: Update packages --- ### Synopsis @@ -27,22 +27,11 @@ packages. If no package name is specified, all packages in the specified location (global or local) will be updated. -As of `npm@2.6.1`, the `npm update` will only inspect top-level packages. -Prior versions of `npm` would also recursively inspect all dependencies. -To get the old behavior, use `npm --depth 9999 update`. - -As of `npm@5.0.0`, the `npm update` will change `package.json` to save the -new version as the minimum required dependency. To get the old behavior, -use `npm update --no-save`. - ### Example -IMPORTANT VERSION NOTE: these examples assume `npm@2.6.1` or later. For -older versions of `npm`, you must specify `--depth 0` to get the behavior -described below. - For the examples below, assume that the current package is `app` and it depends -on dependencies, `dep1` (`dep2`, .. etc.). The published versions of `dep1` are: +on dependencies, `dep1` (`dep2`, .. etc.). The published versions of `dep1` +are: ```json { @@ -84,10 +73,10 @@ However, if `app`'s `package.json` contains: } ``` -In this case, running `npm update` will install `dep1@1.1.2`. Even though the `latest` -tag points to `1.2.2`, this version does not satisfy `~1.1.1`, which is equivalent -to `>=1.1.1 <1.2.0`. So the highest-sorting version that satisfies `~1.1.1` is used, -which is `1.1.2`. +In this case, running `npm update` will install `dep1@1.1.2`. Even though the +`latest` tag points to `1.2.2`, this version do not satisfy `~1.1.1`, which is +equivalent to `>=1.1.1 <1.2.0`. So the highest-sorting version that satisfies +`~1.1.1` is used, which is `1.1.2`. #### Caret Dependencies below 1.0.0 @@ -120,7 +109,9 @@ version that satisfies `^0.4.0` (`>= 0.4.0 <0.5.0`) package that is `outdated` -- that is, has a version that is different from `wanted`. -Note: Globally installed packages are treated as if they are installed with a caret semver range specified. So if you require to update to `latest` you may need to run `npm install -g [...]` +Note: Globally installed packages are treated as if they are installed with a +caret semver range specified. So if you require to update to `latest` you may +need to run `npm install -g [...]` NOTE: If a package has been upgraded to a version newer than `latest`, it will be _downgraded_. diff --git a/deps/npm/docs/content/commands/npm-version.md b/deps/npm/docs/content/commands/npm-version.md index 5f93ef44ae5dd1..0eb814b9899b0f 100644 --- a/deps/npm/docs/content/commands/npm-version.md +++ b/deps/npm/docs/content/commands/npm-version.md @@ -83,37 +83,37 @@ Take the following example: } ``` -This runs all your tests, and proceeds only if they pass. Then runs your `build` script, and +This runs all your tests and proceeds only if they pass. Then runs your `build` script, and adds everything in the `dist` directory to the commit. After the commit, it pushes the new commit and tag up to the server, and deletes the `build/temp` directory. ### Configuration -#### allow-same-version +#### `allow-same-version` -* Default: false +* Default: `false` * Type: Boolean -Prevents throwing an error when `npm version` is used to set the new version +Prevents throwing an error when `npm version` is used to set the new version to the same value as the current version. -#### git-tag-version +#### `git-tag-version` -* Default: true +* Default: `true` * Type: Boolean Commit and tag the version change. -#### commit-hooks +#### `commit-hooks` -* Default: true +* Default: `true` * Type: Boolean Run git commit hooks when committing the version change. -#### sign-git-tag +#### `sign-git-tag` -* Default: false +* Default: `false` * Type: Boolean Pass the `-s` flag to git to sign the tag. @@ -126,5 +126,4 @@ Note that you must have a default GPG key set up in your git config for this to * [npm run-script](/commands/npm-run-script) * [npm scripts](/using-npm/scripts) * [package.json](/configuring-npm/package-json) -* [semver](/using-npm/semver) * [config](/using-npm/config) diff --git a/deps/npm/docs/content/commands/npm-view.md b/deps/npm/docs/content/commands/npm-view.md index 3404c0314335b7..bf09c2ba4f3616 100644 --- a/deps/npm/docs/content/commands/npm-view.md +++ b/deps/npm/docs/content/commands/npm-view.md @@ -17,50 +17,48 @@ aliases: info, show, v This command shows data about a package and prints it to the stream referenced by the `outfd` config, which defaults to stdout. -To show the package registry entry for the `connect` package, you can do -this: +As an example, to view information about the `connect` package from the registry, you would run: ```bash npm view connect ``` -The default version is "latest" if unspecified. +The default version is `"latest"` if unspecified. Field names can be specified after the package descriptor. For example, to show the dependencies of the `ronn` package at version -0.3.5, you could do the following: +`0.3.5`, you could do the following: ```bash npm view ronn@0.3.5 dependencies ``` You can view child fields by separating them with a period. -To view the git repository URL for the latest version of npm, you could -do this: +To view the git repository URL for the latest version of `npm`, you would run the following command: ```bash npm view npm repository.url ``` This makes it easy to view information about a dependency with a bit of -shell scripting. For example, to view all the data about the version of -opts that ronn depends on, you can do this: +shell scripting. For example, to view all the data about the version of +`opts` that `ronn` depends on, you could write the following: ```bash npm view opts@$(npm view ronn dependencies.opts) ``` For fields that are arrays, requesting a non-numeric field will return -all of the values from the objects in the list. For example, to get all -the contributor names for the "express" project, you can do this: +all of the values from the objects in the list. For example, to get all +the contributor names for the `express` package, you would run: ```bash npm view express contributors.email ``` You may also use numeric indices in square braces to specifically select -an item in an array field. To just get the email address of the first -contributor in the list, you can do this: +an item in an array field. To just get the email address of the first +contributor in the list, you can run: ```bash npm view express contributors[0].email @@ -75,7 +73,7 @@ npm view express contributors.name contributors.email ``` "Person" fields are shown as a string if they would be shown as an -object. So, for example, this will show the list of npm contributors in +object. So, for example, this will show the list of `npm` contributors in the shortened string format. (See [`package.json`](/configuring-npm/package.json) for more on this.) ```bash @@ -83,12 +81,12 @@ npm view npm contributors ``` If a version range is provided, then data will be printed for every -matching version of the package. This will show which version of jsdom -was required by each matching version of yui3: +matching version of the package. This will show which version of `jsdom` +was required by each matching version of `yui3`: ```bash npm view yui3@'>0.5.4' dependencies.jsdom -``` +``` To show the `connect` package version history, you can do this: @@ -100,15 +98,15 @@ npm view connect versions ### Output If only a single string field for a single version is output, then it -will not be colorized or quoted, so as to enable piping the output to +will not be colorized or quoted, to enable piping the output to another command. If the field is an object, it will be output as a JavaScript object literal. -If the --json flag is given, the outputted fields will be JSON. +If the `--json` flag is given, the outputted fields will be JSON. -If the version range matches multiple versions, than each printed value +If the version range matches multiple versions then each printed value will be prefixed with the version it applies to. -If multiple fields are requested, than each of them are prefixed with +If multiple fields are requested, then each of them is prefixed with the field name. ### See Also diff --git a/deps/npm/docs/content/commands/npm.md b/deps/npm/docs/content/commands/npm.md index dd7da2f18aa33e..d01146d37041ca 100644 --- a/deps/npm/docs/content/commands/npm.md +++ b/deps/npm/docs/content/commands/npm.md @@ -20,36 +20,42 @@ npm is the package manager for the Node JavaScript platform. It puts modules in place so that node can find them, and manages dependency conflicts intelligently. -It is extremely configurable to support a wide variety of use cases. -Most commonly, it is used to publish, discover, install, and develop node +It is extremely configurable to support a variety of use cases. Most +commonly, you use it to publish, discover, install, and develop node programs. Run `npm help` to get a list of available commands. ### Important -npm is configured to use npm, Inc.'s public registry at +npm comes preconfigured to use npm's public registry at https://registry.npmjs.org by default. Use of the npm public registry is -subject to terms of use available at https://www.npmjs.com/policies/terms. +subject to terms of use available at +https://www.npmjs.com/policies/terms. -You can configure npm to use any compatible registry you like, and even run -your own registry. Use of someone else's registry may be governed by their -terms of use. +You can configure npm to use any compatible registry you like, and even +run your own registry. Use of someone else's registry is governed by +their terms of use. ### Introduction You probably got npm because you want to install stuff. -Use `npm install blerg` to install the latest version of "blerg". Check out -[`npm install`](/commands/npm-install) for more info. It can do a lot of stuff. +The very first thing you will most likely want to run in any node +program is `npm install` to install its dependencies. -Use the `npm search` command to show everything that's available. -Use `npm ls` to show everything you've installed. +You can also run `npm install blerg` to install the latest version of +"blerg". Check out [`npm install`](/commands/npm-install) for more +info. It can do a lot of stuff. + +Use the `npm search` command to show everything that's available in the +public registry. Use `npm ls` to show everything you've installed. ### Dependencies -If a package references to another package with a git URL, npm depends -on a preinstalled git. +If a package lists a dependency using a git URL, npm will install that +dependency using the [`git`](https://github.com/git-guides/install-git) +command and will generate an error if it is not installed. If one of the packages npm tries to install is a native node module and requires compiling of C++ Code, npm will use @@ -64,20 +70,22 @@ the [node-gyp Wiki](https://github.com/nodejs/node-gyp/wiki). ### Directories -See [`folders`](/configuring-npm/folders) to learn about where npm puts stuff. +See [`folders`](/configuring-npm/folders) to learn about where npm puts +stuff. In particular, npm has two modes of operation: -* global mode: - npm installs packages into the install prefix at - `prefix/lib/node_modules` and bins are installed in `prefix/bin`. * local mode: npm installs packages into the current project directory, which - defaults to the current working directory. Packages are installed to - `./node_modules`, and bins are installed to `./node_modules/.bin`. + defaults to the current working directory. Packages install to + `./node_modules`, and bins to `./node_modules/.bin`. +* global mode: + npm installs packages into the install prefix at + `$npm_config_prefix/lib/node_modules` and bins to + `$npm_config_prefix/bin`. Local mode is the default. Use `-g` or `--global` on any command to -operate in global mode instead. +run in global mode instead. ### Developer Usage @@ -85,20 +93,22 @@ If you're using npm to develop and publish your code, check out the following help topics: * json: - Make a package.json file. See [`package.json`](/configuring-npm/package-json). + Make a package.json file. See + [`package.json`](/configuring-npm/package-json). * link: - For linking your current working code into Node's path, so that you - don't have to reinstall every time you make a change. Use - `npm link` to do this. + Links your current working code into Node's path, so that you don't + have to reinstall every time you make a change. Use [`npm + link`](/commands/npm-link) to do this. * install: - It's a good idea to install things if you don't need the symbolic link. - Especially, installing other peoples code from the registry is done via - `npm install` + It's a good idea to install things if you don't need the symbolic + link. Especially, installing other peoples code from the registry is + done via [`npm install`](/commands/npm-install) * adduser: - Create an account or log in. Credentials are stored in the - user config file. + Create an account or log in. When you do this, npm will store + credentials in the user config file config file. * publish: - Use the `npm publish` command to upload your code to the registry. + Use the [`npm publish`](/commands/npm-publish`) command to upload your + code to the registry. #### Configuration @@ -108,20 +118,20 @@ npm is extremely configurable. It reads its configuration options from * Command line switches: Set a config with `--key val`. All keys take a value, even if they are booleans (the config parser doesn't know what the options are at - the time of parsing). If no value is provided, then the option is set - to boolean `true`. + the time of parsing). If you do not provide a value (`--key`) then + the option is set to boolean `true`. * Environment Variables: Set any config by prefixing the name in an environment variable with `npm_config_`. For example, `export npm_config_key=val`. * User Configs: - The file at $HOME/.npmrc is an ini-formatted list of configs. If + The file at `$HOME/.npmrc` is an ini-formatted list of configs. If present, it is parsed. If the `userconfig` option is set in the cli - or env, then that will be used instead. + or env, that file will be used instead. * Global Configs: - The file found at ../etc/npmrc (from the node executable, by default - this resolves to /usr/local/etc/npmrc) will be parsed if it is found. - If the `globalconfig` option is set in the cli, env, or user config, - then that file is parsed instead. + The file found at `./etc/npmrc` (relative to the global prefix will be + parsed if it is found. See [`npm prefix`](/commands/npm-prefix) for + more info on the global prefix. If the `globalconfig` option is set + in the cli, env, or user config, then that file is parsed instead. * Defaults: npm's default configuration options are defined in lib/utils/config-defs.js. These must not be changed. @@ -132,15 +142,17 @@ See [`config`](/using-npm/config) for much much more information. Patches welcome! -If you would like to contribute, but don't know what to work on, read -the [contributing guidelines](https://github.com/npm/cli/blob/latest/CONTRIBUTING.md) -and check the issues list. +If you would like to help, but don't know what to work on, read the +[contributing +guidelines](https://github.com/npm/cli/blob/latest/CONTRIBUTING.md) and +check the issues list. ### Bugs -When you find issues, please report them: +When you find issues, please report them: + -Be sure to follow the template and bug reporting guidelines. +Please be sure to follow the template and bug reporting guidelines. ### Feature Requests @@ -153,8 +165,11 @@ Or suggest formal RFC proposals: * ### See Also + * [npm help](/commands/npm-help) * [package.json](/configuring-npm/package-json) -* [npm install](/commands/npm-install) -* [npm config](/commands/npm-config) * [npmrc](/configuring-npm/npmrc) +* [npm config](/commands/npm-config) +* [npm install](/commands/npm-install) +* [npm prefix](/commands/npm-prefix) +* [npm publish](/commands/npm-publish) diff --git a/deps/npm/docs/content/configuring-npm/package-json.md b/deps/npm/docs/content/configuring-npm/package-json.md index caa1e16a32678a..4b3fd2ba934591 100644 --- a/deps/npm/docs/content/configuring-npm/package-json.md +++ b/deps/npm/docs/content/configuring-npm/package-json.md @@ -63,8 +63,6 @@ Version must be parseable by [node-semver](https://github.com/npm/node-semver), which is bundled with npm as a dependency. (`npm install semver` to use it yourself.) -More on version numbers and ranges at [semver](/using-npm/semver). - ### description Put a description in it. It's a string. This helps people discover your @@ -564,8 +562,8 @@ tarball or git URL. **Please do not put test harnesses or transpilers or other "development" time tools in your `dependencies` object.** See `devDependencies`, below. -See [semver](/using-npm/semver) for more details about specifying version -ranges. +See [semver]([/using-npm/semver](https://github.com/npm/node-semver#versions)) +for more details about specifying version ranges. * `version` Must match `version` exactly * `>version` Must be greater than `version` @@ -573,8 +571,8 @@ ranges. * `` -2. Email the author, CC -3. After a few weeks, if there's no resolution, we'll sort it out. - -Don't squat on package names. Publish code or move out of the way. - -### Description - -There sometimes arise cases where a user publishes a module, and then later, -some other user wants to use that name. Here are some common ways that happens -(each of these is based on actual events.) - -1. Alice writes a JavaScript module `foo`, which is not node-specific. Alice - doesn't use node at all. Yusuf wants to use `foo` in node, so he wraps it in - an npm module. Some time later, Alice starts using node, and wants to take - over management of her program. -2. Yusuf writes an npm module `foo`, and publishes it. Perhaps much later, Alice - finds a bug in `foo`, and fixes it. She sends a pull request to Yusuf, but - Yusuf doesn't have the time to deal with it, because he has a new job and a - new baby and is focused on his new Erlang project, and kind of not involved - with node any more. Alice would like to publish a new `foo`, but can't, - because the name is taken. -3. Yusuf writes a 10-line flow-control library, and calls it `foo`, and - publishes it to the npm registry. Being a simple little thing, it never - really has to be updated. Alice works for Foo Inc, the makers of the - critically acclaimed and widely-marketed `foo` JavaScript toolkit framework. - They publish it to npm as `foojs`, but people are routinely confused when - `npm install foo` is some different thing. -4. Yusuf writes a parser for the widely-known `foo` file format, because he - needs it for work. Then, he gets a new job, and never updates the prototype. - Later on, Alice writes a much more complete `foo` parser, but can't publish, - because Yusuf's `foo` is in the way. - -1. `npm owner ls foo`. This will tell Alice the email address of the owner - (Yusuf). -2. Alice emails Yusuf, explaining the situation **as respectfully as possible**, - and what she would like to do with the module name. She adds the npm support - staff to the CC list of the email. Mention in the email - that Yusuf can run npm owner `add alice foo` to add Alice as an owner of the - foo package. -3. After a reasonable amount of time, if Yusuf has not responded, or if Yusuf - and Alice can't come to any sort of resolution, email support - and we'll sort it out. ("Reasonable" is usually at least - 4 weeks.) - -### Reasoning - -In almost every case so far, the parties involved have been able to reach an -amicable resolution without any major intervention. Most people really do want -to be reasonable, and are probably not even aware that they're in your way. - -Module ecosystems are most vibrant and powerful when they are as self-directed -as possible. If an admin one day deletes something you had worked on, then that -is going to make most people quite upset, regardless of the justification. When -humans solve their problems by talking to other humans with respect, everyone -has the chance to end up feeling good about the interaction. - -### Exceptions - -Some things are not allowed, and will be removed without discussion if they are -brought to the attention of the npm registry admins, including but not limited -to: - -1. Malware (that is, a package designed to exploit or harm the machine on which - it is installed). -2. Violations of copyright or licenses (for example, cloning an MIT-licensed - program, and then removing or changing the copyright and license statement). -3. Illegal content. -4. "Squatting" on a package name that you plan to use, but aren't actually - using. Sorry, I don't care how great the name is, or how perfect a fit it is - for the thing that someday might happen. If someone wants to use it today, - and you're just taking up space with an empty tarball, you're going to be - evicted. -5. Putting empty packages in the registry. Packages must have SOME - functionality. It can be silly, but it can't be nothing. (See also: - squatting.) -6. Doing weird things with the registry, like using it as your own personal - application database or otherwise putting non-packagey things into it. -7. Other things forbidden by the npm - [Code of Conduct](https://www.npmjs.com/policies/conduct) such as hateful - language, pornographic content, or harassment. - -If you see bad behavior like this, please report it to right -away. **You are never expected to resolve abusive behavior on your own. We are -here to help.** - -### Trademarks - -If you think another npm publisher is infringing your trademark, such as by -using a confusingly similar package name, email with a link to -the package or user account on [https://www.npmjs.com/](https://www.npmjs.com/). -Attach a copy of your trademark registration certificate. - -If we see that the package's publisher is intentionally misleading others by -misusing your registered mark without permission, we will transfer the package -name to you. Otherwise, we will contact the package publisher and ask them to -clear up any confusion with changes to their package's `README` file or -metadata. - -### Changes - -This is a living document and may be updated from time to time. Please refer to -the [git history for this document](https://github.com/npm/cli/commits/latest/doc/misc/npm-disputes.md) -to view the changes. - -### License - -Copyright (C) npm, Inc., All rights reserved - -This document may be reused under a Creative Commons Attribution-ShareAlike -License. - -### See also - -* [npm registry](/using-npm/registry) -* [npm owner](/commands/npm-owner) diff --git a/deps/npm/docs/content/using-npm/registry.md b/deps/npm/docs/content/using-npm/registry.md index b7a18712f8be8e..c07fa7a48e888f 100644 --- a/deps/npm/docs/content/using-npm/registry.md +++ b/deps/npm/docs/content/using-npm/registry.md @@ -10,7 +10,7 @@ To resolve packages by name and version, npm talks to a registry website that implements the CommonJS Package Registry specification for reading package info. -npm is configured to use npm, Inc.'s public registry at +npm is configured to use the **npm public registry** at by default. Use of the npm public registry is subject to terms of use available at . @@ -23,9 +23,7 @@ write APIs as well, to allow for publishing packages and managing user account information. The npm public registry is powered by a CouchDB database, -of which there is a public mirror at -. The code for the couchapp is -available at . +of which there is a public mirror at . The registry URL used is determined by the scope of the package (see [`scope`](/using-npm/scope). If no scope is specified, the default registry is used, which is @@ -55,44 +53,18 @@ about your environment: The npm registry does not try to correlate the information in these headers with any authenticated accounts that may be used in the same requests. -### Can I run my own private registry? +### How can I prevent my package from being published in the official registry? -Yes! - -The easiest way is to replicate the couch database, and use the same (or -similar) design doc to implement the APIs. - -If you set up continuous replication from the official CouchDB, and then -set your internal CouchDB as the registry config, then you'll be able -to read any published packages, in addition to your private ones, and by -default will only publish internally. - -If you then want to publish a package for the whole world to see, you can -simply override the `--registry` option for that `publish` command. - -### I don't want my package published in the official registry. It's private. - -Set `"private": true` in your package.json to prevent it from being +Set `"private": true` in your `package.json` to prevent it from being published at all, or `"publishConfig":{"registry":"http://my-internal-registry.local"}` -to force it to be published only to your internal registry. +to force it to be published only to your internal/private registry. See [`package.json`](/configuring-npm/package-json) for more info on what goes in the package.json file. -### Will you replicate from my registry into the public one? - -No. If you want things to be public, then publish them into the public -registry using npm. What little security there is would be for nought -otherwise. - -### Do I have to use couchdb to build a registry that npm can talk to? - -No, but it's way easier. Basically, yes, you do, or you have to -effectively implement the entire CouchDB API anyway. - -### Is there a website or something to see package docs and such? +### Where can I find my own, & other's, published packages? -Yes, head over to + ### See also @@ -100,4 +72,3 @@ Yes, head over to * [config](/using-npm/config) * [npmrc](/configuring-npm/npmrc) * [npm developers](/using-npm/developers) -* [npm disputes](/using-npm/disputes) diff --git a/deps/npm/docs/content/using-npm/removal.md b/deps/npm/docs/content/using-npm/removal.md index 7b35460b595e83..c5e13b6741b6de 100644 --- a/deps/npm/docs/content/using-npm/removal.md +++ b/deps/npm/docs/content/using-npm/removal.md @@ -58,8 +58,6 @@ modules. To track those down, you can do the following: find /usr/local/{lib/node,bin} -exec grep -l npm \{\} \; ; ``` -(This is also in the README file.) - ### See also * [npm uninstall](/commands/npm-uninstall) diff --git a/deps/npm/docs/content/using-npm/semver.md b/deps/npm/docs/content/using-npm/semver.md deleted file mode 100644 index 55141ed537c586..00000000000000 --- a/deps/npm/docs/content/using-npm/semver.md +++ /dev/null @@ -1,415 +0,0 @@ ---- -title: semver -section: 7 -description: The semantic versioner for npm ---- - -## Install - -```bash -npm install --save semver -```` - -## Usage - -As a node module: - -```js -const semver = require('semver') - -semver.valid('1.2.3') // '1.2.3' -semver.valid('a.b.c') // null -semver.clean(' =v1.2.3 ') // '1.2.3' -semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true -semver.gt('1.2.3', '9.8.7') // false -semver.lt('1.2.3', '9.8.7') // true -semver.minVersion('>=1.0.0') // '1.0.0' -semver.valid(semver.coerce('v2')) // '2.0.0' -semver.valid(semver.coerce('42.6.7.9.3-alpha')) // '42.6.7' -``` - -As a command-line utility: - -``` -$ semver -h - -A JavaScript implementation of the https://semver.org/ specification -Copyright Isaac Z. Schlueter - -Usage: semver [options] [ [...]] -Prints valid versions sorted by SemVer precedence - -Options: --r --range - Print versions that match the specified range. - --i --increment [] - Increment a version by the specified level. Level can - be one of: major, minor, patch, premajor, preminor, - prepatch, or prerelease. Default level is 'patch'. - Only one version may be specified. - ---preid - Identifier to be used to prefix premajor, preminor, - prepatch or prerelease version increments. - --l --loose - Interpret versions and ranges loosely - --p --include-prerelease - Always include prerelease versions in range matching - --c --coerce - Coerce a string into SemVer if possible - (does not imply --loose) - -Program exits successfully if any valid version satisfies -all supplied ranges, and prints all satisfying versions. - -If no satisfying versions are found, then exits failure. - -Versions are printed in ascending order, so supplying -multiple versions to the utility will just sort them. -``` - -## Versions - -A "version" is described by the `v2.0.0` specification found at -. - -A leading `"="` or `"v"` character is stripped off and ignored. - -## Ranges - -A `version range` is a set of `comparators` which specify versions -that satisfy the range. - -A `comparator` is composed of an `operator` and a `version`. The set -of primitive `operators` is: - -* `<` Less than -* `<=` Less than or equal to -* `>` Greater than -* `>=` Greater than or equal to -* `=` Equal. If no operator is specified, then equality is assumed, - so this operator is optional, but MAY be included. - -For example, the comparator `>=1.2.7` would match the versions -`1.2.7`, `1.2.8`, `2.5.3`, and `1.3.9`, but not the versions `1.2.6` -or `1.1.0`. - -Comparators can be joined by whitespace to form a `comparator set`, -which is satisfied by the **intersection** of all of the comparators -it includes. - -A range is composed of one or more comparator sets, joined by `||`. A -version matches a range if and only if every comparator in at least -one of the `||`-separated comparator sets is satisfied by the version. - -For example, the range `>=1.2.7 <1.3.0` would match the versions -`1.2.7`, `1.2.8`, and `1.2.99`, but not the versions `1.2.6`, `1.3.0`, -or `1.1.0`. - -The range `1.2.7 || >=1.2.9 <2.0.0` would match the versions `1.2.7`, -`1.2.9`, and `1.4.6`, but not the versions `1.2.8` or `2.0.0`. - -### Prerelease Tags - -If a version has a prerelease tag (for example, `1.2.3-alpha.3`) then -it will only be allowed to satisfy comparator sets if at least one -comparator with the same `[major, minor, patch]` tuple also has a -prerelease tag. - -For example, the range `>1.2.3-alpha.3` would be allowed to match the -version `1.2.3-alpha.7`, but it would *not* be satisfied by -`3.4.5-alpha.9`, even though `3.4.5-alpha.9` is technically "greater -than" `1.2.3-alpha.3` according to the SemVer sort rules. The version -range only accepts prerelease tags on the `1.2.3` version. The -version `3.4.5` *would* satisfy the range, because it does not have a -prerelease flag, and `3.4.5` is greater than `1.2.3-alpha.7`. - -The purpose for this behavior is twofold. First, prerelease versions -frequently are updated very quickly, and contain many breaking changes -that are (by the author's design) not yet fit for public consumption. -Therefore, by default, they are excluded from range matching -semantics. - -Second, a user who has opted into using a prerelease version has -clearly indicated the intent to use *that specific* set of -alpha/beta/rc versions. By including a prerelease tag in the range, -the user is indicating that they are aware of the risk. However, it -is still not appropriate to assume that they have opted into taking a -similar risk on the *next* set of prerelease versions. - -Note that this behavior can be suppressed (treating all prerelease -versions as if they were normal versions, for the purpose of range -matching) by setting the `includePrerelease` flag on the options -object to any -[functions](https://github.com/npm/node-semver#functions) that do -range matching. - -#### Prerelease Identifiers - -The method `.inc` takes an additional `identifier` string argument that -will append the value of the string as a prerelease identifier: - -```javascript -semver.inc('1.2.3', 'prerelease', 'beta') -// '1.2.4-beta.0' -``` - -command-line example: - -```bash -$ semver 1.2.3 -i prerelease --preid beta -1.2.4-beta.0 -``` - -Which then can be used to increment further: - -```bash -$ semver 1.2.4-beta.0 -i prerelease -1.2.4-beta.1 -``` - -### Advanced Range Syntax - -Advanced range syntax desugars to primitive comparators in -deterministic ways. - -Advanced ranges may be combined in the same way as primitive -comparators using white space or `||`. - -#### Hyphen Ranges `X.Y.Z - A.B.C` - -Specifies an inclusive set. - -* `1.2.3 - 2.3.4` := `>=1.2.3 <=2.3.4` - -If a partial version is provided as the first version in the inclusive -range, then the missing pieces are replaced with zeroes. - -* `1.2 - 2.3.4` := `>=1.2.0 <=2.3.4` - -If a partial version is provided as the second version in the -inclusive range, then all versions that start with the supplied parts -of the tuple are accepted, but nothing that would be greater than the -provided tuple parts. - -* `1.2.3 - 2.3` := `>=1.2.3 <2.4.0` -* `1.2.3 - 2` := `>=1.2.3 <3.0.0` - -#### X-Ranges `1.2.x` `1.X` `1.2.*` `*` - -Any of `X`, `x`, or `*` may be used to "stand in" for one of the -numeric values in the `[major, minor, patch]` tuple. - -* `*` := `>=0.0.0` (Any version satisfies) -* `1.x` := `>=1.0.0 <2.0.0` (Matching major version) -* `1.2.x` := `>=1.2.0 <1.3.0` (Matching major and minor versions) - -A partial version range is treated as an X-Range, so the special -character is in fact optional. - -* `""` (empty string) := `*` := `>=0.0.0` -* `1` := `1.x.x` := `>=1.0.0 <2.0.0` -* `1.2` := `1.2.x` := `>=1.2.0 <1.3.0` - -#### Tilde Ranges `~1.2.3` `~1.2` `~1` - -Allows patch-level changes if a minor version is specified on the -comparator. Allows minor-level changes if not. - -* `~1.2.3` := `>=1.2.3 <1.(2+1).0` := `>=1.2.3 <1.3.0` -* `~1.2` := `>=1.2.0 <1.(2+1).0` := `>=1.2.0 <1.3.0` (Same as `1.2.x`) -* `~1` := `>=1.0.0 <(1+1).0.0` := `>=1.0.0 <2.0.0` (Same as `1.x`) -* `~0.2.3` := `>=0.2.3 <0.(2+1).0` := `>=0.2.3 <0.3.0` -* `~0.2` := `>=0.2.0 <0.(2+1).0` := `>=0.2.0 <0.3.0` (Same as `0.2.x`) -* `~0` := `>=0.0.0 <(0+1).0.0` := `>=0.0.0 <1.0.0` (Same as `0.x`) -* `~1.2.3-beta.2` := `>=1.2.3-beta.2 <1.3.0` Note that prereleases in - the `1.2.3` version will be allowed, if they are greater than or - equal to `beta.2`. So, `1.2.3-beta.4` would be allowed, but - `1.2.4-beta.2` would not, because it is a prerelease of a - different `[major, minor, patch]` tuple. - -#### Caret Ranges `^1.2.3` `^0.2.5` `^0.0.4` - -Allows changes that do not modify the left-most non-zero digit in the -`[major, minor, patch]` tuple. In other words, this allows patch and -minor updates for versions `1.0.0` and above, patch updates for -versions `0.X >=0.1.0`, and *no* updates for versions `0.0.X`. - -Many authors treat a `0.x` version as if the `x` were the major -"breaking-change" indicator. - -Caret ranges are ideal when an author may make breaking changes -between `0.2.4` and `0.3.0` releases, which is a common practice. -However, it presumes that there will *not* be breaking changes between -`0.2.4` and `0.2.5`. It allows for changes that are presumed to be -additive (but non-breaking), according to commonly observed practices. - -* `^1.2.3` := `>=1.2.3 <2.0.0` -* `^0.2.3` := `>=0.2.3 <0.3.0` -* `^0.0.3` := `>=0.0.3 <0.0.4` -* `^1.2.3-beta.2` := `>=1.2.3-beta.2 <2.0.0` Note that prereleases in - the `1.2.3` version will be allowed, if they are greater than or - equal to `beta.2`. So, `1.2.3-beta.4` would be allowed, but - `1.2.4-beta.2` would not, because it is a prerelease of a - different `[major, minor, patch]` tuple. -* `^0.0.3-beta` := `>=0.0.3-beta <0.0.4` Note that prereleases in the - `0.0.3` version *only* will be allowed, if they are greater than or - equal to `beta`. So, `0.0.3-pr.2` would be allowed. - -When parsing caret ranges, a missing `patch` value desugars to the -number `0`, but will allow flexibility within that value, even if the -major and minor versions are both `0`. - -* `^1.2.x` := `>=1.2.0 <2.0.0` -* `^0.0.x` := `>=0.0.0 <0.1.0` -* `^0.0` := `>=0.0.0 <0.1.0` - -A missing `minor` and `patch` values will desugar to zero, but also -allow flexibility within those values, even if the major version is -zero. - -* `^1.x` := `>=1.0.0 <2.0.0` -* `^0.x` := `>=0.0.0 <1.0.0` - -### Range Grammar - -Putting all this together, here is a Backus-Naur grammar for ranges, -for the benefit of parser authors: - -```bnf -range-set ::= range ( logical-or range ) * -logical-or ::= ( ' ' ) * '||' ( ' ' ) * -range ::= hyphen | simple ( ' ' simple ) * | '' -hyphen ::= partial ' - ' partial -simple ::= primitive | partial | tilde | caret -primitive ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial -partial ::= xr ( '.' xr ( '.' xr qualifier ? )? )? -xr ::= 'x' | 'X' | '*' | nr -nr ::= '0' | ['1'-'9'] ( ['0'-'9'] ) * -tilde ::= '~' partial -caret ::= '^' partial -qualifier ::= ( '-' pre )? ( '+' build )? -pre ::= parts -build ::= parts -parts ::= part ( '.' part ) * -part ::= nr | [-0-9A-Za-z]+ -``` - -## Functions - -All methods and classes take a final `options` object argument. All -options in this object are `false` by default. The options supported -are: - -- `loose` Be more forgiving about not-quite-valid semver strings. - (Any resulting output will always be 100% strict compliant, of - course.) For backwards compatibility reasons, if the `options` - argument is a boolean value instead of an object, it is interpreted - to be the `loose` param. -- `includePrerelease` Set to suppress the [default - behavior](https://github.com/npm/node-semver#prerelease-tags) of - excluding prerelease tagged versions from ranges unless they are - explicitly opted into. - -Strict-mode Comparators and Ranges will be strict about the SemVer -strings that they parse. - -* `valid(v)`: Return the parsed version, or null if it's not valid. -* `inc(v, release)`: Return the version incremented by the release - type (`major`, `premajor`, `minor`, `preminor`, `patch`, - `prepatch`, or `prerelease`), or null if it's not valid - * `premajor` in one call will bump the version up to the next major - version and down to a prerelease of that major version. - `preminor`, and `prepatch` work the same way. - * If called from a non-prerelease version, the `prerelease` will work the - same as `prepatch`. It increments the patch version, then makes a - prerelease. If the input version is already a prerelease it simply - increments it. -* `prerelease(v)`: Returns an array of prerelease components, or null - if none exist. Example: `prerelease('1.2.3-alpha.1') -> ['alpha', 1]` -* `major(v)`: Return the major version number. -* `minor(v)`: Return the minor version number. -* `patch(v)`: Return the patch version number. -* `intersects(r1, r2, loose)`: Return true if the two supplied ranges - or comparators intersect. -* `parse(v)`: Attempt to parse a string as a semantic version, returning either - a `SemVer` object or `null`. - -### Comparison - -* `gt(v1, v2)`: `v1 > v2` -* `gte(v1, v2)`: `v1 >= v2` -* `lt(v1, v2)`: `v1 < v2` -* `lte(v1, v2)`: `v1 <= v2` -* `eq(v1, v2)`: `v1 == v2` This is true if they're logically equivalent, - even if they're not the exact same string. You already know how to - compare strings. -* `neq(v1, v2)`: `v1 != v2` The opposite of `eq`. -* `cmp(v1, comparator, v2)`: Pass in a comparison string, and it'll call - the corresponding function above. `"==="` and `"!=="` do simple - string comparison, but are included for completeness. Throws if an - invalid comparison string is provided. -* `compare(v1, v2)`: Return `0` if `v1 == v2`, or `1` if `v1` is greater, or `-1` if - `v2` is greater. Sorts in ascending order if passed to `Array.sort()`. -* `rcompare(v1, v2)`: The reverse of compare. Sorts an array of versions - in descending order when passed to `Array.sort()`. -* `diff(v1, v2)`: Returns difference between two versions by the release type - (`major`, `premajor`, `minor`, `preminor`, `patch`, `prepatch`, or `prerelease`), - or null if the versions are the same. - -### Comparators - -* `intersects(comparator)`: Return true if the comparators intersect - -### Ranges - -* `validRange(range)`: Return the valid range or null if it's not valid -* `satisfies(version, range)`: Return true if the version satisfies the - range. -* `maxSatisfying(versions, range)`: Return the highest version in the list - that satisfies the range, or `null` if none of them do. -* `minSatisfying(versions, range)`: Return the lowest version in the list - that satisfies the range, or `null` if none of them do. -* `minVersion(range)`: Return the lowest version that can possibly match - the given range. -* `gtr(version, range)`: Return `true` if version is greater than all the - versions possible in the range. -* `ltr(version, range)`: Return `true` if version is less than all the - versions possible in the range. -* `outside(version, range, hilo)`: Return true if the version is outside - the bounds of the range in either the high or low direction. The - `hilo` argument must be either the string `'>'` or `'<'`. (This is - the function called by `gtr` and `ltr`.) -* `intersects(range)`: Return true if any of the ranges comparators intersect - -Note that, since ranges may be non-contiguous, a version might not be -greater than a range, less than a range, *or* satisfy a range! For -example, the range `1.2 <1.2.9 || >2.0.0` would have a hole from `1.2.9` -until `2.0.0`, so the version `1.2.10` would not be greater than the -range (because `2.0.1` satisfies, which is higher), nor less than the -range (since `1.2.8` satisfies, which is lower), and it also does not -satisfy the range. - -If you want to know if a version satisfies or does not satisfy a -range, use the `satisfies(version, range)` function. - -### Coercion - -* `coerce(version)`: Coerces a string to semver if possible - -This aims to provide a very forgiving translation of a non-semver string to -semver. It looks for the first digit in a string, and consumes all -remaining characters which satisfy at least a partial semver (e.g., `1`, -`1.2`, `1.2.3`) up to the max permitted length (256 characters). Longer -versions are simply truncated (`4.6.3.9.2-alpha2` becomes `4.6.3`). All -surrounding text is simply ignored (`v3.4 replaces v3.3.1` becomes -`3.4.0`). Only text which lacks digits will fail coercion (`version one` -is not valid). The maximum length for any semver component considered for -coercion is 16 characters; longer components will be ignored -(`10000000000000000.4.7.4` becomes `4.7.4`). The maximum value for any -semver component is `Number.MAX_SAFE_INTEGER || (2**53 - 1)`; higher value -components are invalid (`9999999999999999.4.7.4` is likely invalid). diff --git a/deps/npm/docs/output/commands/npm-diff.html b/deps/npm/docs/output/commands/npm-diff.html new file mode 100644 index 00000000000000..43840ea9a2984a --- /dev/null +++ b/deps/npm/docs/output/commands/npm-diff.html @@ -0,0 +1,346 @@ + +npm-diff + + + + + +
+
+

npm-diff

+The registry diff command +
+ +
+

Table of contents

+ +
+ +

Synopsis

+
npm diff [...<paths>]
+npm diff --diff=<pkg-name> [...<paths>]
+npm diff --diff=<version-a> [--diff=<version-b>] [...<paths>]
+npm diff --diff=<spec-a> [--diff=<spec-b>] [...<paths>]
+npm diff [--diff-ignore-all-space] [--diff-name-only] [...<paths>]
+
+

Description

+

Similar to its git diff counterpart, this command will print diff patches +of files for packages published to the npm registry.

+
    +
  • +

    npm diff --diff=<spec-a> --diff=<spec-b>

    +

    Compares two package versions using their registry specifiers, e.g: +npm diff --diff=pkg@1.0.0 --diff=pkg@^2.0.0. It’s also possible to +compare across forks of any package, +e.g: npm diff --diff=pkg@1.0.0 --diff=pkg-fork@1.0.0.

    +

    Any valid spec can be used, so that it’s also possible to compare +directories or git repositories, +e.g: npm diff --diff=pkg@latest --diff=./packages/pkg

    +

    Here’s an example comparing two different versions of a package named +abbrev from the registry:

    +
    npm diff --diff=abbrev@1.1.0 --diff=abbrev@1.1.1
    +
    +

    On success, output looks like:

    +
    diff --git a/package.json b/package.json
    +index v1.1.0..v1.1.1 100644
    +--- a/package.json
    ++++ b/package.json
    +@@ -1,6 +1,6 @@
    + {
    +   "name": "abbrev",
    +-  "version": "1.1.0",
    ++  "version": "1.1.1",
    +   "description": "Like ruby's abbrev module, but in js",
    +   "author": "Isaac Z. Schlueter <i@izs.me>",
    +   "main": "abbrev.js",
    +
    +

    Given the flexible nature of npm specs, you can also target local +directories or git repos just like when using npm install:

    +
    npm diff --diff=https://github.com/npm/libnpmdiff --diff=./local-path
    +
    +

    In the example above we can compare the contents from the package installed +from the git repo at github.com/npm/libnpmdiff with the contents of the +./local-path that contains a valid package, such as a modified copy of +the original.

    +
  • +
  • +

    npm diff (in a package directory, no arguments):

    +

    If the package is published to the registry, npm diff will fetch the +tarball version tagged as latest (this value can be configured using the +tag option) and proceed to compare the contents of files present in that +tarball, with the current files in your local file system.

    +

    This workflow provides a handy way for package authors to see what +package-tracked files have been changed in comparison with the latest +published version of that package.

    +
  • +
  • +

    npm diff --diff=<pkg-name> (in a package directory):

    +

    When using a single package name (with no version or tag specifier) as an +argument, npm diff will work in a similar way to +npm-outdated and reach for the registry to figure out +what current published version of the package named will satisfy +its dependent declared semver-range. Once that specific version is known +npm diff will print diff patches comparing the current version of + found in the local file system with that specific version +returned by the registry.

    +

    Given a package named abbrev that is currently installed:

    +
    npm diff --diff=abbrev
    +
    +

    That will request from the registry its most up to date version and +will print a diff output comparing the currently installed version to this +newer one if the version numbers are not the same.

    +
  • +
  • +

    npm diff --diff=<spec-a> (in a package directory):

    +

    Similar to using only a single package name, it’s also possible to declare +a full registry specifier version if you wish to compare the local version +of an installed package with the specific version/tag/semver-range provided +in <spec-a>.

    +

    An example: assuming pkg@1.0.0 is installed in the current node_modules +folder, running:

    +
    npm diff --diff=pkg@2.0.0
    +
    +

    It will effectively be an alias to +npm diff --diff=pkg@1.0.0 --diff=pkg@2.0.0.

    +
  • +
  • +

    npm diff --diff=<semver-a> [--diff=<semver-b>] (in a package directory):

    +

    Using npm diff along with semver-valid version numbers is a shorthand +to compare different versions of the current package.

    +

    It needs to be run from a package directory, such that for a package named +pkg running npm diff --diff=1.0.0 --diff=1.0.1 is the same as running +npm diff --diff=pkg@1.0.0 --diff=pkg@1.0.1.

    +

    If only a single argument <version-a> is provided, then the current local +file system is going to be compared against that version.

    +

    Here’s an example comparing two specific versions (published to the +configured registry) of the current project directory:

    +
    npm diff --diff=1.0.0 --diff=1.1.0
    +
    +
  • +
+

Note that tag names are not valid --diff argument values, if you wish to +compare to a published tag, you must use the pkg@tagname syntax.

+

Filtering files

+

It’s possible to also specify positional arguments using file names or globs +pattern matching in order to limit the result of diff patches to only a subset +of files for a given package, e.g:

+
npm diff --diff=pkg@2 ./lib/ CHANGELOG.md
+
+

In the example above the diff output is only going to print contents of files +located within the folder ./lib/ and changed lines of code within the +CHANGELOG.md file.

+

Configuration

+

diff

+
    +
  • Type: Array
  • +
  • Default: null
  • +
+

Defines npm package specifiers to compare using the npm diff command.

+

This can be specified up to 2 times.

+

diff-name-only

+
    +
  • Type: Boolean
  • +
  • Default: false
  • +
+

When set to true running npm diff only returns the names of the files that +have any difference.

+

diff-unified

+
    +
  • Type: Number
  • +
  • Default: 3
  • +
+

The number of lines of context to print in the unified diff format output.

+

diff-ignore-all-space

+
    +
  • Type: Boolean
  • +
  • Default: false
  • +
+

Ignore whitespace when comparing lines. This ignores differences even if one +line has whitespace where the other line has none.

+

diff-no-prefix

+
    +
  • Type: Boolean
  • +
  • Default: false
  • +
+

Do not show any source or destination prefix.

+

diff-src-prefix

+
    +
  • Type: String
  • +
  • Default: "a/"
  • +
+

Show the given source prefix in diff patches headers instead of using “a/”.

+

diff-dst-prefix

+
    +
  • Type: String
  • +
  • Default: "b/"
  • +
+

Show the given source prefix in diff patches headers instead of using “b/”.

+

diff-text

+
    +
  • Type: Boolean
  • +
  • Default: false
  • +
+

Treat all files as text.

+

global

+
    +
  • Default: false
  • +
  • Type: Boolean
  • +
+

Uses packages from the global space as a source for comparison.

+

tag

+
    +
  • Type: String
  • +
  • Default: "latest"
  • +
+

The tag used to fetch the tarball that will be compared with the local file +system files when running npm diff with no arguments.

+

See Also

+ +
+ + +
+ + + + \ No newline at end of file diff --git a/deps/npm/docs/output/commands/npm-exec.html b/deps/npm/docs/output/commands/npm-exec.html index ecee5f014341af..03059c52052a50 100644 --- a/deps/npm/docs/output/commands/npm-exec.html +++ b/deps/npm/docs/output/commands/npm-exec.html @@ -141,7 +141,7 @@

npm-exec

Table of contents

- +

Synopsis

@@ -273,6 +273,20 @@

Compatibility with Older npx Vers
  • The --shell option is replaced with --script-shell, but maintained in the npx executable for backwards compatibility.
  • +

    A note on caching

    +

    The npm cli utilizes its internal package cache when using the package +name specified. You can use the following to change how and when the +cli uses this cache. See npm cache for more on +how the cache works.

    +

    prefer-online

    +

    Forces staleness checks for packages, making the cli look for updates +immediately even if the package is already in the cache.

    +

    prefer-offline

    +

    Bypasses staleness checks for packages. Missing data will still be +requested from the server. To force full offline mode, use offline.

    +

    offline

    +

    Forces full offline mode. Any packages not locally cached will result in +an error.

    See Also

    • npm run-script
    • diff --git a/deps/npm/docs/output/commands/npm-init.html b/deps/npm/docs/output/commands/npm-init.html index 0284b365398dd5..3abf8e967b4649 100644 --- a/deps/npm/docs/output/commands/npm-init.html +++ b/deps/npm/docs/output/commands/npm-init.html @@ -141,7 +141,7 @@

      npm-init

      Table of contents

      - +

      Synopsis

      @@ -189,12 +189,27 @@

      Examples

      Generate it without having it ask any questions:

      $ npm init -y
       
      +

      A note on caching

      +

      The npm cli utilizes its internal package cache when using the package +name specified. You can use the following to change how and when the +cli uses this cache. See npm cache for more on +how the cache works.

      +

      prefer-online

      +

      Forces staleness checks for packages, making the cli look for updates +immediately even if the package is already in the cache.

      +

      prefer-offline

      +

      Bypasses staleness checks for packages. Missing data will still be +requested from the server. To force full offline mode, use offline.

      +

      offline

      +

      Forces full offline mode. Any packages not locally cached will result in +an error.

      See Also

      diff --git a/deps/npm/docs/output/commands/npm-ls.html b/deps/npm/docs/output/commands/npm-ls.html index 15d1bbc99f4784..ba62a72741de83 100644 --- a/deps/npm/docs/output/commands/npm-ls.html +++ b/deps/npm/docs/output/commands/npm-ls.html @@ -159,7 +159,7 @@

      Description

      the results to only the paths to the packages named. Note that nested packages will also show the paths to the specified packages. For example, running npm ls promzard in npm’s source tree will show:

      -
      npm@7.4.3 /path/to/npm
      +
      npm@7.5.1 /path/to/npm
       └─┬ init-package-json@0.0.4
         └── promzard@0.1.5
       
      diff --git a/deps/npm/docs/output/commands/npm-owner.html b/deps/npm/docs/output/commands/npm-owner.html index 625d3be234be80..77f072da40b2ee 100644 --- a/deps/npm/docs/output/commands/npm-owner.html +++ b/deps/npm/docs/output/commands/npm-owner.html @@ -173,7 +173,6 @@

      See Also

    • npm publish
    • npm registry
    • npm adduser
    • -
    • npm disputes
    diff --git a/deps/npm/docs/output/commands/npm-run-script.html b/deps/npm/docs/output/commands/npm-run-script.html index 57f6e6e2b658d8..a78a434760bc05 100644 --- a/deps/npm/docs/output/commands/npm-run-script.html +++ b/deps/npm/docs/output/commands/npm-run-script.html @@ -141,7 +141,7 @@

    npm-run-script

    Table of contents

    - +

    Synopsis

    @@ -162,7 +162,7 @@

    Description

    npm run test -- --grep="pattern"
     

    The arguments will only be passed to the script specified after npm run -and not to any pre or post script.

    +and not to any pre or post script.

    The env script is a special built-in command that can be used to list environment variables that will be available to the script at runtime. If an “env” command is defined in your package, it will take precedence over the @@ -178,7 +178,8 @@

    Description

    "scripts": {"test": "node_modules/.bin/tap test/*.js"}
     

    The actual shell your script is run within is platform dependent. By default, -on Unix-like systems it is the /bin/sh command, on Windows it is the cmd.exe. +on Unix-like systems it is the /bin/sh command, on Windows it is +cmd.exe. The actual shell referred to by /bin/sh also depends on the system. You can customize the shell with the script-shell configuration.

    Scripts are run from the root of the package folder, regardless of what the @@ -192,12 +193,37 @@

    Description

    If --scripts-prepend-node-path=auto is passed (which has been the default in npm v3), this is only performed when that node executable is not found in the PATH.

    -

    If you try to run a script without having a node_modules directory and it fails, -you will be given a warning to run npm install, just in case you’ve forgotten.

    -

    You can use the --silent flag to prevent showing npm ERR! output on error.

    +

    If you try to run a script without having a node_modules directory and it +fails, you will be given a warning to run npm install, just in case you’ve +forgotten.

    +

    Configuration

    +

    if-present

    +
      +
    • Type: Boolean
    • +
    • Default: false
    • +

    You can use the --if-present flag to avoid exiting with a non-zero exit code when the script is undefined. This lets you run potentially undefined scripts without breaking the execution chain.

    +

    ignore-scripts

    +
      +
    • Type: Boolean
    • +
    • Default: false
    • +
    +

    Skips running pre and post scripts.

    +

    script-shell

    +
      +
    • Type: String
    • +
    • Default: null
    • +
    +

    Optional custom script to use to execute the command. If not defined defaults +to /bin/sh on Unix, defaults to env.comspec or cmd.exe on Windows.

    +

    silent

    +
      +
    • Type: Boolean
    • +
    • Default: false
    • +
    +

    You can use the --silent flag to prevent showing npm ERR! output on error.

    See Also

    • npm scripts
    • diff --git a/deps/npm/docs/output/commands/npm-search.html b/deps/npm/docs/output/commands/npm-search.html index bad81ffa002be5..bd1522305035ec 100644 --- a/deps/npm/docs/output/commands/npm-search.html +++ b/deps/npm/docs/output/commands/npm-search.html @@ -230,11 +230,11 @@

      A note on caching

      the cli uses this cache. See npm cache for more on how the cache works.

      prefer-online

      -

      Forced staleness checks for cached searches, making the cli look for +

      Forces staleness checks for cached searches, making the cli look for updates immediately even for fresh search results.

      prefer-offline

      -

      Bypasses staleness checks for cached. Missing data will still be -requested from the server. To force full offline mode, use offline.

      +

      Bypasses staleness checks for cached searches. Missing data will still +be requested from the server. To force full offline mode, use offline.

      offline

      Forces full offline mode. Any searches not locally cached will result in an error.

      diff --git a/deps/npm/docs/output/commands/npm-team.html b/deps/npm/docs/output/commands/npm-team.html index 502f1e747c8469..bf29f4a5eaf633 100644 --- a/deps/npm/docs/output/commands/npm-team.html +++ b/deps/npm/docs/output/commands/npm-team.html @@ -152,41 +152,65 @@

      Table of contents

      npm team rm <scope:team> <user> npm team ls <scope>|<scope:team> - -npm team edit <scope:team>

      Description

      Used to manage teams in organizations, and change team memberships. Does not handle permissions for packages.

      Teams must always be fully qualified with the organization/scope they belong to -when operating on them, separated by a colon (:). That is, if you have a wombats team in a wisdom organization, you must always refer to that team as wisdom:wombats in these commands.

      -

      If you have two-factor authentication enabled in auth-and-writes mode, then you can provide a code from your authenticator with [--otp <otpcode>]. If you don’t include this then you will be prompted.

      +when operating on them, separated by a colon (:). That is, if you have a +newteam team in an org organization, you must always refer to that team +as @org:newteam in these commands.

      +

      If you have two-factor authentication enabled in auth-and-writes mode, then +you can provide a code from your authenticator with [--otp <otpcode>]. +If you don’t include this then you will be prompted.

      • create / destroy: -Create a new team, or destroy an existing one. Note: You cannot remove the developers team, learn more.

        +Create a new team, or destroy an existing one. Note: You cannot remove the +developers team, learn more.

        +

        Here’s how to create a new team newteam under the org org:

        +
        npm team create @org:newteam
        +
        +

        You should see a confirming message such as: +@org:newteam once the new +team has been created.

        +
      • +
      • +

        add: +Add a user to an existing team.

        +

        Adding a new user username to a team named newteam under the org org:

        +
        npm team add @org:newteam username
        +
        +

        On success, you should see a message: username added to @org:newteam

      • -

        add / rm: -Add a user to an existing team, or remove a user from a team they belong to.

        +

        rm: +Using npm team rm you can also remove users from a team they belong to.

        +

        Here’s an example removing user username from newteam team +in org organization:

        +
        npm team rm @org:newteam username
        +
        +

        Once the user is removed a confirmation message is displayed: +username removed from @org:newteam

      • ls: If performed on an organization name, will return a list of existing teams under that organization. If performed on a team, it will instead return a list of all users belonging to that particular team.

        -
      • -
      • -

        edit: -Edit a current team.

        +

        Here’s an example of how to list all teams from an org named org:

        +
        npm team ls @org
        +
        +

        Example listing all members of a team named newteam:

        +
        npm team ls @org:newteam
        +

      Details

      npm team always operates directly on the current registry, configurable from the command line using --registry=<registry url>.

      -

      In order to create teams and manage team membership, you must be a team admin -under the given organization. Listing teams and team memberships may be done by -any member of the organizations.

      +

      You must be a team admin to create teams and manage team membership, under +the given organization. Listing teams and team memberships may be done by +any member of the organization.

      Organization creation and management of team admins and organization members is done through the website, not the npm CLI.

      To use teams to manage permissions on packages belonging to your organization, @@ -194,6 +218,7 @@

      Details

      See Also

    diff --git a/deps/npm/docs/output/commands/npm-update.html b/deps/npm/docs/output/commands/npm-update.html index 7533721fa3e09f..1c5d53e5d24e3a 100644 --- a/deps/npm/docs/output/commands/npm-update.html +++ b/deps/npm/docs/output/commands/npm-update.html @@ -136,7 +136,7 @@

    npm-update

    -Update a package +Update packages
    @@ -159,18 +159,10 @@

    Description

    packages.

    If no package name is specified, all packages in the specified location (global or local) will be updated.

    -

    As of npm@2.6.1, the npm update will only inspect top-level packages. -Prior versions of npm would also recursively inspect all dependencies. -To get the old behavior, use npm --depth 9999 update.

    -

    As of npm@5.0.0, the npm update will change package.json to save the -new version as the minimum required dependency. To get the old behavior, -use npm update --no-save.

    Example

    -

    IMPORTANT VERSION NOTE: these examples assume npm@2.6.1 or later. For -older versions of npm, you must specify --depth 0 to get the behavior -described below.

    For the examples below, assume that the current package is app and it depends -on dependencies, dep1 (dep2, .. etc.). The published versions of dep1 are:

    +on dependencies, dep1 (dep2, .. etc.). The published versions of dep1 +are:

    {
       "dist-tags": { "latest": "1.2.2" },
       "versions": [
    @@ -200,10 +192,10 @@ 

    Tilde Dependencies

    "dep1": "~1.1.1" }
    -

    In this case, running npm update will install dep1@1.1.2. Even though the latest -tag points to 1.2.2, this version does not satisfy ~1.1.1, which is equivalent -to >=1.1.1 <1.2.0. So the highest-sorting version that satisfies ~1.1.1 is used, -which is 1.1.2.

    +

    In this case, running npm update will install dep1@1.1.2. Even though the +latest tag points to 1.2.2, this version do not satisfy ~1.1.1, which is +equivalent to >=1.1.1 <1.2.0. So the highest-sorting version that satisfies +~1.1.1 is used, which is 1.1.2.

    Caret Dependencies below 1.0.0

    Suppose app has a caret dependency on a version below 1.0.0, for example:

    "dependencies": {
    @@ -223,7 +215,9 @@ 

    Updating Globally-Installed Packag

    npm update -g will apply the update action to each globally installed package that is outdated – that is, has a version that is different from wanted.

    -

    Note: Globally installed packages are treated as if they are installed with a caret semver range specified. So if you require to update to latest you may need to run npm install -g [<pkg>...]

    +

    Note: Globally installed packages are treated as if they are installed with a +caret semver range specified. So if you require to update to latest you may +need to run npm install -g [<pkg>...]

    NOTE: If a package has been upgraded to a version newer than latest, it will be downgraded.

    See Also

    diff --git a/deps/npm/docs/output/commands/npm-version.html b/deps/npm/docs/output/commands/npm-version.html index e11de2179b5af5..f5832a2d2fdc2b 100644 --- a/deps/npm/docs/output/commands/npm-version.html +++ b/deps/npm/docs/output/commands/npm-version.html @@ -141,7 +141,7 @@

    npm-version

    Table of contents

    - +

    Synopsis

    @@ -207,32 +207,32 @@

    Description

    "postversion": "git push && git push --tags && rm -rf build/temp" }
    -

    This runs all your tests, and proceeds only if they pass. Then runs your build script, and +

    This runs all your tests and proceeds only if they pass. Then runs your build script, and adds everything in the dist directory to the commit. After the commit, it pushes the new commit and tag up to the server, and deletes the build/temp directory.

    Configuration

    -

    allow-same-version

    +

    allow-same-version

      -
    • Default: false
    • +
    • Default: false
    • Type: Boolean

    Prevents throwing an error when npm version is used to set the new version to the same value as the current version.

    -

    git-tag-version

    +

    git-tag-version

      -
    • Default: true
    • +
    • Default: true
    • Type: Boolean

    Commit and tag the version change.

    -

    commit-hooks

    +

    commit-hooks

      -
    • Default: true
    • +
    • Default: true
    • Type: Boolean

    Run git commit hooks when committing the version change.

    -

    sign-git-tag

    +

    sign-git-tag

      -
    • Default: false
    • +
    • Default: false
    • Type: Boolean

    Pass the -s flag to git to sign the tag.

    @@ -243,7 +243,6 @@

    See Also

  • npm run-script
  • npm scripts
  • package.json
  • -
  • semver
  • config
  • diff --git a/deps/npm/docs/output/commands/npm-view.html b/deps/npm/docs/output/commands/npm-view.html index 9865e5a8886490..d7790e2fa7af12 100644 --- a/deps/npm/docs/output/commands/npm-view.html +++ b/deps/npm/docs/output/commands/npm-view.html @@ -152,34 +152,32 @@

    Table of contents

    Description

    This command shows data about a package and prints it to the stream referenced by the outfd config, which defaults to stdout.

    -

    To show the package registry entry for the connect package, you can do -this:

    +

    As an example, to view information about the connect package from the registry, you would run:

    npm view connect
     
    -

    The default version is “latest” if unspecified.

    +

    The default version is "latest" if unspecified.

    Field names can be specified after the package descriptor. For example, to show the dependencies of the ronn package at version -0.3.5, you could do the following:

    +0.3.5, you could do the following:

    npm view ronn@0.3.5 dependencies
     

    You can view child fields by separating them with a period. -To view the git repository URL for the latest version of npm, you could -do this:

    +To view the git repository URL for the latest version of npm, you would run the following command:

    npm view npm repository.url
     

    This makes it easy to view information about a dependency with a bit of -shell scripting. For example, to view all the data about the version of -opts that ronn depends on, you can do this:

    +shell scripting. For example, to view all the data about the version of +opts that ronn depends on, you could write the following:

    npm view opts@$(npm view ronn dependencies.opts)
     

    For fields that are arrays, requesting a non-numeric field will return -all of the values from the objects in the list. For example, to get all -the contributor names for the “express” project, you can do this:

    +all of the values from the objects in the list. For example, to get all +the contributor names for the express package, you would run:

    npm view express contributors.email
     

    You may also use numeric indices in square braces to specifically select -an item in an array field. To just get the email address of the first -contributor in the list, you can do this:

    +an item in an array field. To just get the email address of the first +contributor in the list, you can run:

    npm view express contributors[0].email
     

    Multiple fields may be specified, and will be printed one after another. @@ -188,13 +186,13 @@

    Description

    npm view express contributors.name contributors.email
     

    “Person” fields are shown as a string if they would be shown as an -object. So, for example, this will show the list of npm contributors in +object. So, for example, this will show the list of npm contributors in the shortened string format. (See package.json for more on this.)

    npm view npm contributors
     

    If a version range is provided, then data will be printed for every -matching version of the package. This will show which version of jsdom -was required by each matching version of yui3:

    +matching version of the package. This will show which version of jsdom +was required by each matching version of yui3:

    npm view yui3@'>0.5.4' dependencies.jsdom
     

    To show the connect package version history, you can do @@ -203,12 +201,12 @@

    Description

    Output

    If only a single string field for a single version is output, then it -will not be colorized or quoted, so as to enable piping the output to +will not be colorized or quoted, to enable piping the output to another command. If the field is an object, it will be output as a JavaScript object literal.

    -

    If the –json flag is given, the outputted fields will be JSON.

    -

    If the version range matches multiple versions, than each printed value +

    If the --json flag is given, the outputted fields will be JSON.

    +

    If the version range matches multiple versions then each printed value will be prefixed with the version it applies to.

    -

    If multiple fields are requested, than each of them are prefixed with +

    If multiple fields are requested, then each of them is prefixed with the field name.

    See Also

      diff --git a/deps/npm/docs/output/commands/npm.html b/deps/npm/docs/output/commands/npm.html index 03d4c92821011c..727120c1b747aa 100644 --- a/deps/npm/docs/output/commands/npm.html +++ b/deps/npm/docs/output/commands/npm.html @@ -148,31 +148,36 @@

      Table of contents

      npm <command> [args]
       

      Version

      -

      7.4.3

      +

      7.5.1

      Description

      npm is the package manager for the Node JavaScript platform. It puts modules in place so that node can find them, and manages dependency conflicts intelligently.

      -

      It is extremely configurable to support a wide variety of use cases. -Most commonly, it is used to publish, discover, install, and develop node +

      It is extremely configurable to support a variety of use cases. Most +commonly, you use it to publish, discover, install, and develop node programs.

      Run npm help to get a list of available commands.

      Important

      -

      npm is configured to use npm, Inc.’s public registry at +

      npm comes preconfigured to use npm’s public registry at https://registry.npmjs.org by default. Use of the npm public registry is -subject to terms of use available at https://www.npmjs.com/policies/terms.

      -

      You can configure npm to use any compatible registry you like, and even run -your own registry. Use of someone else’s registry may be governed by their -terms of use.

      +subject to terms of use available at +https://www.npmjs.com/policies/terms.

      +

      You can configure npm to use any compatible registry you like, and even +run your own registry. Use of someone else’s registry is governed by +their terms of use.

      Introduction

      You probably got npm because you want to install stuff.

      -

      Use npm install blerg to install the latest version of “blerg”. Check out -npm install for more info. It can do a lot of stuff.

      -

      Use the npm search command to show everything that’s available. -Use npm ls to show everything you’ve installed.

      +

      The very first thing you will most likely want to run in any node +program is npm install to install its dependencies.

      +

      You can also run npm install blerg to install the latest version of +“blerg”. Check out npm install for more +info. It can do a lot of stuff.

      +

      Use the npm search command to show everything that’s available in the +public registry. Use npm ls to show everything you’ve installed.

      Dependencies

      -

      If a package references to another package with a git URL, npm depends -on a preinstalled git.

      +

      If a package lists a dependency using a git URL, npm will install that +dependency using the git +command and will generate an error if it is not installed.

      If one of the packages npm tries to install is a native node module and requires compiling of C++ Code, npm will use node-gyp for that task. @@ -184,38 +189,41 @@

      Dependencies

      the node-gyp repository and the node-gyp Wiki.

      Directories

      -

      See folders to learn about where npm puts stuff.

      +

      See folders to learn about where npm puts +stuff.

      In particular, npm has two modes of operation:

        -
      • global mode: -npm installs packages into the install prefix at -prefix/lib/node_modules and bins are installed in prefix/bin.
      • local mode: npm installs packages into the current project directory, which -defaults to the current working directory. Packages are installed to -./node_modules, and bins are installed to ./node_modules/.bin.
      • +defaults to the current working directory. Packages install to +./node_modules, and bins to ./node_modules/.bin. +
      • global mode: +npm installs packages into the install prefix at +$npm_config_prefix/lib/node_modules and bins to +$npm_config_prefix/bin.

      Local mode is the default. Use -g or --global on any command to -operate in global mode instead.

      +run in global mode instead.

      Developer Usage

      If you’re using npm to develop and publish your code, check out the following help topics:

      • json: -Make a package.json file. See package.json.
      • +Make a package.json file. See +package.json.
      • link: -For linking your current working code into Node’s path, so that you -don’t have to reinstall every time you make a change. Use -npm link to do this.
      • +Links your current working code into Node’s path, so that you don’t +have to reinstall every time you make a change. Use npm link to do this.
      • install: -It’s a good idea to install things if you don’t need the symbolic link. -Especially, installing other peoples code from the registry is done via -npm install
      • +It’s a good idea to install things if you don’t need the symbolic +link. Especially, installing other peoples code from the registry is +done via npm install
      • adduser: -Create an account or log in. Credentials are stored in the -user config file.
      • +Create an account or log in. When you do this, npm will store +credentials in the user config file config file.
      • publish: -Use the npm publish command to upload your code to the registry.
      • +Use the npm publish command to upload your +code to the registry.

      Configuration

      npm is extremely configurable. It reads its configuration options from @@ -224,20 +232,20 @@

      Configuration

    • Command line switches: Set a config with --key val. All keys take a value, even if they are booleans (the config parser doesn’t know what the options are at -the time of parsing). If no value is provided, then the option is set -to boolean true.
    • +the time of parsing). If you do not provide a value (--key) then +the option is set to boolean true.
    • Environment Variables: Set any config by prefixing the name in an environment variable with npm_config_. For example, export npm_config_key=val.
    • User Configs: -The file at $HOME/.npmrc is an ini-formatted list of configs. If +The file at $HOME/.npmrc is an ini-formatted list of configs. If present, it is parsed. If the userconfig option is set in the cli -or env, then that will be used instead.
    • +or env, that file will be used instead.
    • Global Configs: -The file found at ../etc/npmrc (from the node executable, by default -this resolves to /usr/local/etc/npmrc) will be parsed if it is found. -If the globalconfig option is set in the cli, env, or user config, -then that file is parsed instead.
    • +The file found at ./etc/npmrc (relative to the global prefix will be +parsed if it is found. See npm prefix for +more info on the global prefix. If the globalconfig option is set +in the cli, env, or user config, then that file is parsed instead.
    • Defaults: npm’s default configuration options are defined in lib/utils/config-defs.js. These must not be changed.
    • @@ -245,12 +253,14 @@

      Configuration

      See config for much much more information.

      Contributions

      Patches welcome!

      -

      If you would like to contribute, but don’t know what to work on, read -the contributing guidelines -and check the issues list.

      +

      If you would like to help, but don’t know what to work on, read the +contributing +guidelines and +check the issues list.

      Bugs

      -

      When you find issues, please report them: https://github.com/npm/cli/issues

      -

      Be sure to follow the template and bug reporting guidelines.

      +

      When you find issues, please report them: +https://github.com/npm/cli/issues

      +

      Please be sure to follow the template and bug reporting guidelines.

      Feature Requests

      Discuss new feature ideas on our discussion forum:

        @@ -264,9 +274,11 @@

        See Also

        diff --git a/deps/npm/docs/output/configuring-npm/package-json.html b/deps/npm/docs/output/configuring-npm/package-json.html index 2b01733ab86643..114c18d61ebb25 100644 --- a/deps/npm/docs/output/configuring-npm/package-json.html +++ b/deps/npm/docs/output/configuring-npm/package-json.html @@ -193,7 +193,6 @@

        version

        Version must be parseable by node-semver, which is bundled with npm as a dependency. (npm install semver to use it yourself.)

        -

        More on version numbers and ranges at semver.

        description

        Put a description in it. It’s a string. This helps people discover your package, as it’s listed in npm search.

        @@ -566,8 +565,8 @@

        dependencies

        tarball or git URL.

        Please do not put test harnesses or transpilers or other “development” time tools in your dependencies object. See devDependencies, below.

        -

        See semver for more details about specifying version -ranges.

        +

        See semver +for more details about specifying version ranges.

        • version Must match version exactly
        • >version Must be greater than version
        • @@ -575,8 +574,8 @@

          dependencies

        • <version
        • <=version
        • ~version “Approximately equivalent to version” See -semver
        • -
        • ^version “Compatible with version” See semver
        • +semver +
        • ^version “Compatible with version” See semver
        • 1.2.x 1.2.0, 1.2.1, etc., but not 1.3.0
        • http://... See ‘URLs as Dependencies’ below
        • * Matches any version
        • @@ -917,7 +916,7 @@

          DEFAULT VALUES

        SEE ALSO

        The npm registry does not try to correlate the information in these headers with any authenticated accounts that may be used in the same requests.

        -

        Can I run my own private registry?

        -

        Yes!

        -

        The easiest way is to replicate the couch database, and use the same (or -similar) design doc to implement the APIs.

        -

        If you set up continuous replication from the official CouchDB, and then -set your internal CouchDB as the registry config, then you’ll be able -to read any published packages, in addition to your private ones, and by -default will only publish internally.

        -

        If you then want to publish a package for the whole world to see, you can -simply override the --registry option for that publish command.

        -

        I don’t want my package published in the official registry. It’s private.

        -

        Set "private": true in your package.json to prevent it from being +

        How can I prevent my package from being published in the official registry?

        +

        Set "private": true in your package.json to prevent it from being published at all, or "publishConfig":{"registry":"http://my-internal-registry.local"} -to force it to be published only to your internal registry.

        +to force it to be published only to your internal/private registry.

        See package.json for more info on what goes in the package.json file.

        -

        Will you replicate from my registry into the public one?

        -

        No. If you want things to be public, then publish them into the public -registry using npm. What little security there is would be for nought -otherwise.

        -

        Do I have to use couchdb to build a registry that npm can talk to?

        -

        No, but it’s way easier. Basically, yes, you do, or you have to -effectively implement the entire CouchDB API anyway.

        -

        Is there a website or something to see package docs and such?

        -

        Yes, head over to https://www.npmjs.com/

        +

        Where can I find my own, & other’s, published packages?

        +

        https://www.npmjs.com/

        See also

        diff --git a/deps/npm/docs/output/using-npm/removal.html b/deps/npm/docs/output/using-npm/removal.html index 0007b712dbb7dd..2130e3efbea63b 100644 --- a/deps/npm/docs/output/using-npm/removal.html +++ b/deps/npm/docs/output/using-npm/removal.html @@ -177,7 +177,6 @@

        More Severe Uninstalling

        modules. To track those down, you can do the following:

        find /usr/local/{lib/node,bin} -exec grep -l npm \{\} \; ;
         
        -

        (This is also in the README file.)

        See also

        • npm uninstall
        • diff --git a/deps/npm/docs/output/using-npm/semver.html b/deps/npm/docs/output/using-npm/semver.html deleted file mode 100644 index d01d5022d40e77..00000000000000 --- a/deps/npm/docs/output/using-npm/semver.html +++ /dev/null @@ -1,521 +0,0 @@ - -semver - - - - - -
          -
          -

          semver

          -The semantic versioner for npm -
          - -
          -

          Table of contents

          - -
          - -

          Install

          -
          npm install --save semver
          -
          -

          Usage

          -

          As a node module:

          -
          const semver = require('semver')
          -
          -semver.valid('1.2.3') // '1.2.3'
          -semver.valid('a.b.c') // null
          -semver.clean('  =v1.2.3   ') // '1.2.3'
          -semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true
          -semver.gt('1.2.3', '9.8.7') // false
          -semver.lt('1.2.3', '9.8.7') // true
          -semver.minVersion('>=1.0.0') // '1.0.0'
          -semver.valid(semver.coerce('v2')) // '2.0.0'
          -semver.valid(semver.coerce('42.6.7.9.3-alpha')) // '42.6.7'
          -
          -

          As a command-line utility:

          -
          $ semver -h
          -
          -A JavaScript implementation of the https://semver.org/ specification
          -Copyright Isaac Z. Schlueter
          -
          -Usage: semver [options] <version> [<version> [...]]
          -Prints valid versions sorted by SemVer precedence
          -
          -Options:
          --r --range <range>
          -        Print versions that match the specified range.
          -
          --i --increment [<level>]
          -        Increment a version by the specified level.  Level can
          -        be one of: major, minor, patch, premajor, preminor,
          -        prepatch, or prerelease.  Default level is 'patch'.
          -        Only one version may be specified.
          -
          ---preid <identifier>
          -        Identifier to be used to prefix premajor, preminor,
          -        prepatch or prerelease version increments.
          -
          --l --loose
          -        Interpret versions and ranges loosely
          -
          --p --include-prerelease
          -        Always include prerelease versions in range matching
          -
          --c --coerce
          -        Coerce a string into SemVer if possible
          -        (does not imply --loose)
          -
          -Program exits successfully if any valid version satisfies
          -all supplied ranges, and prints all satisfying versions.
          -
          -If no satisfying versions are found, then exits failure.
          -
          -Versions are printed in ascending order, so supplying
          -multiple versions to the utility will just sort them.
          -
          -

          Versions

          -

          A “version” is described by the v2.0.0 specification found at -https://semver.org/.

          -

          A leading "=" or "v" character is stripped off and ignored.

          -

          Ranges

          -

          A version range is a set of comparators which specify versions -that satisfy the range.

          -

          A comparator is composed of an operator and a version. The set -of primitive operators is:

          -
            -
          • < Less than
          • -
          • <= Less than or equal to
          • -
          • > Greater than
          • -
          • >= Greater than or equal to
          • -
          • = Equal. If no operator is specified, then equality is assumed, -so this operator is optional, but MAY be included.
          • -
          -

          For example, the comparator >=1.2.7 would match the versions -1.2.7, 1.2.8, 2.5.3, and 1.3.9, but not the versions 1.2.6 -or 1.1.0.

          -

          Comparators can be joined by whitespace to form a comparator set, -which is satisfied by the intersection of all of the comparators -it includes.

          -

          A range is composed of one or more comparator sets, joined by ||. A -version matches a range if and only if every comparator in at least -one of the ||-separated comparator sets is satisfied by the version.

          -

          For example, the range >=1.2.7 <1.3.0 would match the versions -1.2.7, 1.2.8, and 1.2.99, but not the versions 1.2.6, 1.3.0, -or 1.1.0.

          -

          The range 1.2.7 || >=1.2.9 <2.0.0 would match the versions 1.2.7, -1.2.9, and 1.4.6, but not the versions 1.2.8 or 2.0.0.

          -

          Prerelease Tags

          -

          If a version has a prerelease tag (for example, 1.2.3-alpha.3) then -it will only be allowed to satisfy comparator sets if at least one -comparator with the same [major, minor, patch] tuple also has a -prerelease tag.

          -

          For example, the range >1.2.3-alpha.3 would be allowed to match the -version 1.2.3-alpha.7, but it would not be satisfied by -3.4.5-alpha.9, even though 3.4.5-alpha.9 is technically “greater -than” 1.2.3-alpha.3 according to the SemVer sort rules. The version -range only accepts prerelease tags on the 1.2.3 version. The -version 3.4.5 would satisfy the range, because it does not have a -prerelease flag, and 3.4.5 is greater than 1.2.3-alpha.7.

          -

          The purpose for this behavior is twofold. First, prerelease versions -frequently are updated very quickly, and contain many breaking changes -that are (by the author’s design) not yet fit for public consumption. -Therefore, by default, they are excluded from range matching -semantics.

          -

          Second, a user who has opted into using a prerelease version has -clearly indicated the intent to use that specific set of -alpha/beta/rc versions. By including a prerelease tag in the range, -the user is indicating that they are aware of the risk. However, it -is still not appropriate to assume that they have opted into taking a -similar risk on the next set of prerelease versions.

          -

          Note that this behavior can be suppressed (treating all prerelease -versions as if they were normal versions, for the purpose of range -matching) by setting the includePrerelease flag on the options -object to any -functions that do -range matching.

          -

          Prerelease Identifiers

          -

          The method .inc takes an additional identifier string argument that -will append the value of the string as a prerelease identifier:

          -
          semver.inc('1.2.3', 'prerelease', 'beta')
          -// '1.2.4-beta.0'
          -
          -

          command-line example:

          -
          $ semver 1.2.3 -i prerelease --preid beta
          -1.2.4-beta.0
          -
          -

          Which then can be used to increment further:

          -
          $ semver 1.2.4-beta.0 -i prerelease
          -1.2.4-beta.1
          -
          -

          Advanced Range Syntax

          -

          Advanced range syntax desugars to primitive comparators in -deterministic ways.

          -

          Advanced ranges may be combined in the same way as primitive -comparators using white space or ||.

          -

          Hyphen Ranges X.Y.Z - A.B.C

          -

          Specifies an inclusive set.

          -
            -
          • 1.2.3 - 2.3.4 := >=1.2.3 <=2.3.4
          • -
          -

          If a partial version is provided as the first version in the inclusive -range, then the missing pieces are replaced with zeroes.

          -
            -
          • 1.2 - 2.3.4 := >=1.2.0 <=2.3.4
          • -
          -

          If a partial version is provided as the second version in the -inclusive range, then all versions that start with the supplied parts -of the tuple are accepted, but nothing that would be greater than the -provided tuple parts.

          -
            -
          • 1.2.3 - 2.3 := >=1.2.3 <2.4.0
          • -
          • 1.2.3 - 2 := >=1.2.3 <3.0.0
          • -
          -

          X-Ranges 1.2.x 1.X 1.2.* *

          -

          Any of X, x, or * may be used to “stand in” for one of the -numeric values in the [major, minor, patch] tuple.

          -
            -
          • * := >=0.0.0 (Any version satisfies)
          • -
          • 1.x := >=1.0.0 <2.0.0 (Matching major version)
          • -
          • 1.2.x := >=1.2.0 <1.3.0 (Matching major and minor versions)
          • -
          -

          A partial version range is treated as an X-Range, so the special -character is in fact optional.

          -
            -
          • "" (empty string) := * := >=0.0.0
          • -
          • 1 := 1.x.x := >=1.0.0 <2.0.0
          • -
          • 1.2 := 1.2.x := >=1.2.0 <1.3.0
          • -
          -

          Tilde Ranges ~1.2.3 ~1.2 ~1

          -

          Allows patch-level changes if a minor version is specified on the -comparator. Allows minor-level changes if not.

          -
            -
          • ~1.2.3 := >=1.2.3 <1.(2+1).0 := >=1.2.3 <1.3.0
          • -
          • ~1.2 := >=1.2.0 <1.(2+1).0 := >=1.2.0 <1.3.0 (Same as 1.2.x)
          • -
          • ~1 := >=1.0.0 <(1+1).0.0 := >=1.0.0 <2.0.0 (Same as 1.x)
          • -
          • ~0.2.3 := >=0.2.3 <0.(2+1).0 := >=0.2.3 <0.3.0
          • -
          • ~0.2 := >=0.2.0 <0.(2+1).0 := >=0.2.0 <0.3.0 (Same as 0.2.x)
          • -
          • ~0 := >=0.0.0 <(0+1).0.0 := >=0.0.0 <1.0.0 (Same as 0.x)
          • -
          • ~1.2.3-beta.2 := >=1.2.3-beta.2 <1.3.0 Note that prereleases in -the 1.2.3 version will be allowed, if they are greater than or -equal to beta.2. So, 1.2.3-beta.4 would be allowed, but -1.2.4-beta.2 would not, because it is a prerelease of a -different [major, minor, patch] tuple.
          • -
          -

          Caret Ranges ^1.2.3 ^0.2.5 ^0.0.4

          -

          Allows changes that do not modify the left-most non-zero digit in the -[major, minor, patch] tuple. In other words, this allows patch and -minor updates for versions 1.0.0 and above, patch updates for -versions 0.X >=0.1.0, and no updates for versions 0.0.X.

          -

          Many authors treat a 0.x version as if the x were the major -“breaking-change” indicator.

          -

          Caret ranges are ideal when an author may make breaking changes -between 0.2.4 and 0.3.0 releases, which is a common practice. -However, it presumes that there will not be breaking changes between -0.2.4 and 0.2.5. It allows for changes that are presumed to be -additive (but non-breaking), according to commonly observed practices.

          -
            -
          • ^1.2.3 := >=1.2.3 <2.0.0
          • -
          • ^0.2.3 := >=0.2.3 <0.3.0
          • -
          • ^0.0.3 := >=0.0.3 <0.0.4
          • -
          • ^1.2.3-beta.2 := >=1.2.3-beta.2 <2.0.0 Note that prereleases in -the 1.2.3 version will be allowed, if they are greater than or -equal to beta.2. So, 1.2.3-beta.4 would be allowed, but -1.2.4-beta.2 would not, because it is a prerelease of a -different [major, minor, patch] tuple.
          • -
          • ^0.0.3-beta := >=0.0.3-beta <0.0.4 Note that prereleases in the -0.0.3 version only will be allowed, if they are greater than or -equal to beta. So, 0.0.3-pr.2 would be allowed.
          • -
          -

          When parsing caret ranges, a missing patch value desugars to the -number 0, but will allow flexibility within that value, even if the -major and minor versions are both 0.

          -
            -
          • ^1.2.x := >=1.2.0 <2.0.0
          • -
          • ^0.0.x := >=0.0.0 <0.1.0
          • -
          • ^0.0 := >=0.0.0 <0.1.0
          • -
          -

          A missing minor and patch values will desugar to zero, but also -allow flexibility within those values, even if the major version is -zero.

          -
            -
          • ^1.x := >=1.0.0 <2.0.0
          • -
          • ^0.x := >=0.0.0 <1.0.0
          • -
          -

          Range Grammar

          -

          Putting all this together, here is a Backus-Naur grammar for ranges, -for the benefit of parser authors:

          -
          range-set  ::= range ( logical-or range ) *
          -logical-or ::= ( ' ' ) * '||' ( ' ' ) *
          -range      ::= hyphen | simple ( ' ' simple ) * | ''
          -hyphen     ::= partial ' - ' partial
          -simple     ::= primitive | partial | tilde | caret
          -primitive  ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial
          -partial    ::= xr ( '.' xr ( '.' xr qualifier ? )? )?
          -xr         ::= 'x' | 'X' | '*' | nr
          -nr         ::= '0' | ['1'-'9'] ( ['0'-'9'] ) *
          -tilde      ::= '~' partial
          -caret      ::= '^' partial
          -qualifier  ::= ( '-' pre )? ( '+' build )?
          -pre        ::= parts
          -build      ::= parts
          -parts      ::= part ( '.' part ) *
          -part       ::= nr | [-0-9A-Za-z]+
          -
          -

          Functions

          -

          All methods and classes take a final options object argument. All -options in this object are false by default. The options supported -are:

          -
            -
          • loose Be more forgiving about not-quite-valid semver strings. -(Any resulting output will always be 100% strict compliant, of -course.) For backwards compatibility reasons, if the options -argument is a boolean value instead of an object, it is interpreted -to be the loose param.
          • -
          • includePrerelease Set to suppress the default -behavior of -excluding prerelease tagged versions from ranges unless they are -explicitly opted into.
          • -
          -

          Strict-mode Comparators and Ranges will be strict about the SemVer -strings that they parse.

          -
            -
          • valid(v): Return the parsed version, or null if it’s not valid.
          • -
          • inc(v, release): Return the version incremented by the release -type (major, premajor, minor, preminor, patch, -prepatch, or prerelease), or null if it’s not valid -
              -
            • premajor in one call will bump the version up to the next major -version and down to a prerelease of that major version. -preminor, and prepatch work the same way.
            • -
            • If called from a non-prerelease version, the prerelease will work the -same as prepatch. It increments the patch version, then makes a -prerelease. If the input version is already a prerelease it simply -increments it.
            • -
            -
          • -
          • prerelease(v): Returns an array of prerelease components, or null -if none exist. Example: prerelease('1.2.3-alpha.1') -> ['alpha', 1]
          • -
          • major(v): Return the major version number.
          • -
          • minor(v): Return the minor version number.
          • -
          • patch(v): Return the patch version number.
          • -
          • intersects(r1, r2, loose): Return true if the two supplied ranges -or comparators intersect.
          • -
          • parse(v): Attempt to parse a string as a semantic version, returning either -a SemVer object or null.
          • -
          -

          Comparison

          -
            -
          • gt(v1, v2): v1 > v2
          • -
          • gte(v1, v2): v1 >= v2
          • -
          • lt(v1, v2): v1 < v2
          • -
          • lte(v1, v2): v1 <= v2
          • -
          • eq(v1, v2): v1 == v2 This is true if they’re logically equivalent, -even if they’re not the exact same string. You already know how to -compare strings.
          • -
          • neq(v1, v2): v1 != v2 The opposite of eq.
          • -
          • cmp(v1, comparator, v2): Pass in a comparison string, and it’ll call -the corresponding function above. "===" and "!==" do simple -string comparison, but are included for completeness. Throws if an -invalid comparison string is provided.
          • -
          • compare(v1, v2): Return 0 if v1 == v2, or 1 if v1 is greater, or -1 if -v2 is greater. Sorts in ascending order if passed to Array.sort().
          • -
          • rcompare(v1, v2): The reverse of compare. Sorts an array of versions -in descending order when passed to Array.sort().
          • -
          • diff(v1, v2): Returns difference between two versions by the release type -(major, premajor, minor, preminor, patch, prepatch, or prerelease), -or null if the versions are the same.
          • -
          -

          Comparators

          -
            -
          • intersects(comparator): Return true if the comparators intersect
          • -
          -

          Ranges

          -
            -
          • validRange(range): Return the valid range or null if it’s not valid
          • -
          • satisfies(version, range): Return true if the version satisfies the -range.
          • -
          • maxSatisfying(versions, range): Return the highest version in the list -that satisfies the range, or null if none of them do.
          • -
          • minSatisfying(versions, range): Return the lowest version in the list -that satisfies the range, or null if none of them do.
          • -
          • minVersion(range): Return the lowest version that can possibly match -the given range.
          • -
          • gtr(version, range): Return true if version is greater than all the -versions possible in the range.
          • -
          • ltr(version, range): Return true if version is less than all the -versions possible in the range.
          • -
          • outside(version, range, hilo): Return true if the version is outside -the bounds of the range in either the high or low direction. The -hilo argument must be either the string '>' or '<'. (This is -the function called by gtr and ltr.)
          • -
          • intersects(range): Return true if any of the ranges comparators intersect
          • -
          -

          Note that, since ranges may be non-contiguous, a version might not be -greater than a range, less than a range, or satisfy a range! For -example, the range 1.2 <1.2.9 || >2.0.0 would have a hole from 1.2.9 -until 2.0.0, so the version 1.2.10 would not be greater than the -range (because 2.0.1 satisfies, which is higher), nor less than the -range (since 1.2.8 satisfies, which is lower), and it also does not -satisfy the range.

          -

          If you want to know if a version satisfies or does not satisfy a -range, use the satisfies(version, range) function.

          -

          Coercion

          -
            -
          • coerce(version): Coerces a string to semver if possible
          • -
          -

          This aims to provide a very forgiving translation of a non-semver string to -semver. It looks for the first digit in a string, and consumes all -remaining characters which satisfy at least a partial semver (e.g., 1, -1.2, 1.2.3) up to the max permitted length (256 characters). Longer -versions are simply truncated (4.6.3.9.2-alpha2 becomes 4.6.3). All -surrounding text is simply ignored (v3.4 replaces v3.3.1 becomes -3.4.0). Only text which lacks digits will fail coercion (version one -is not valid). The maximum length for any semver component considered for -coercion is 16 characters; longer components will be ignored -(10000000000000000.4.7.4 becomes 4.7.4). The maximum value for any -semver component is Number.MAX_SAFE_INTEGER || (2**53 - 1); higher value -components are invalid (9999999999999999.4.7.4 is likely invalid).

          -
          - - -
          - - - - \ No newline at end of file diff --git a/deps/npm/lib/access.js b/deps/npm/lib/access.js index 68c6e628d01870..8a372d90cb55cd 100644 --- a/deps/npm/lib/access.js +++ b/deps/npm/lib/access.js @@ -8,7 +8,6 @@ const output = require('./utils/output.js') const otplease = require('./utils/otplease.js') const usageUtil = require('./utils/usage.js') const getIdentity = require('./utils/get-identity.js') -const { prefix } = npm const usage = usageUtil( 'npm access', @@ -165,7 +164,7 @@ const getPackage = async (name, requireScope) => { return name.trim() else { try { - const pkg = await readPackageJson(path.resolve(prefix, 'package.json')) + const pkg = await readPackageJson(path.resolve(npm.prefix, 'package.json')) name = pkg.name } catch (err) { if (err.code === 'ENOENT') { diff --git a/deps/npm/lib/ci.js b/deps/npm/lib/ci.js index 89c6b8f4207428..36410616fb9bfb 100644 --- a/deps/npm/lib/ci.js +++ b/deps/npm/lib/ci.js @@ -3,6 +3,8 @@ const Arborist = require('@npmcli/arborist') const rimraf = util.promisify(require('rimraf')) const reifyFinish = require('./utils/reify-finish.js') const runScript = require('@npmcli/run-script') +const fs = require('fs') +const readdir = util.promisify(fs.readdir) const log = require('npmlog') const npm = require('./npm.js') @@ -13,6 +15,16 @@ const completion = require('./utils/completion/none.js') const cmd = (args, cb) => ci().then(() => cb()).catch(cb) +const removeNodeModules = async where => { + const rimrafOpts = { glob: false } + process.emit('time', 'npm-ci:rm') + const path = `${where}/node_modules` + // get the list of entries so we can skip the glob for performance + const entries = await readdir(path, null).catch(er => []) + await Promise.all(entries.map(f => rimraf(`${path}/${f}`, rimrafOpts))) + process.emit('timeEnd', 'npm-ci:rm') +} + const ci = async () => { if (npm.flatOptions.global) { const err = new Error('`npm ci` does not work for global packages') @@ -33,7 +45,7 @@ const ci = async () => { 'later to generate a package-lock.json file, then try again.' throw new Error(msg) }), - rimraf(`${where}/node_modules/*`, { glob: { dot: true, nosort: true, silent: true } }), + removeNodeModules(where), ]) // npm ci should never modify the lockfile or package.json await arb.reify({ ...npm.flatOptions, save: false }) diff --git a/deps/npm/lib/diff.js b/deps/npm/lib/diff.js new file mode 100644 index 00000000000000..af6760106e0065 --- /dev/null +++ b/deps/npm/lib/diff.js @@ -0,0 +1,266 @@ +const { resolve } = require('path') + +const semver = require('semver') +const libdiff = require('libnpmdiff') +const npa = require('npm-package-arg') +const Arborist = require('@npmcli/arborist') +const npmlog = require('npmlog') +const pacote = require('pacote') +const pickManifest = require('npm-pick-manifest') + +const npm = require('./npm.js') +const usageUtil = require('./utils/usage.js') +const output = require('./utils/output.js') +const completion = require('./utils/completion/none.js') +const readLocalPkg = require('./utils/read-local-package.js') + +const usage = usageUtil( + 'diff', + 'npm diff [...]' + + '\nnpm diff --diff= [...]' + + '\nnpm diff --diff= [--diff=] [...]' + + '\nnpm diff --diff= [--diff=] [...]' + + '\nnpm diff [--diff-ignore-all-space] [--diff-name-only] [...] [...]' +) + +const cmd = (args, cb) => diff(args).then(() => cb()).catch(cb) + +const where = () => { + const globalTop = resolve(npm.globalDir, '..') + const { global } = npm.flatOptions + return global ? globalTop : npm.prefix +} + +const diff = async (args) => { + const specs = npm.flatOptions.diff.filter(d => d) + if (specs.length > 2) { + throw new TypeError( + 'Can\'t use more than two --diff arguments.\n\n' + + `Usage:\n${usage}` + ) + } + + const [a, b] = await retrieveSpecs(specs) + npmlog.info('diff', { src: a, dst: b }) + + const res = await libdiff([a, b], { ...npm.flatOptions, diffFiles: args }) + return output(res) +} + +const retrieveSpecs = ([a, b]) => { + // no arguments, defaults to comparing cwd + // to its latest published registry version + if (!a) + return defaultSpec() + + // single argument, used to compare wanted versions of an + // installed dependency or to compare the cwd to a published version + if (!b) + return transformSingleSpec(a) + + return convertVersionsToSpecs([a, b]) + .then(findVersionsByPackageName) +} + +const defaultSpec = async () => { + let noPackageJson + let pkgName + try { + pkgName = await readLocalPkg() + } catch (e) { + npmlog.verbose('diff', 'could not read project dir package.json') + noPackageJson = true + } + + if (!pkgName || noPackageJson) { + throw new Error( + 'Needs multiple arguments to compare or run from a project dir.\n\n' + + `Usage:\n${usage}` + ) + } + + return [ + `${pkgName}@${npm.flatOptions.defaultTag}`, + `file:${npm.prefix}`, + ] +} + +const transformSingleSpec = async (a) => { + let noPackageJson + let pkgName + try { + pkgName = await readLocalPkg() + } catch (e) { + npmlog.verbose('diff', 'could not read project dir package.json') + noPackageJson = true + } + const missingPackageJson = new Error( + 'Needs multiple arguments to compare or run from a project dir.\n\n' + + `Usage:\n${usage}` + ) + + const specSelf = () => { + if (noPackageJson) + throw missingPackageJson + + return `file:${npm.prefix}` + } + + // using a valid semver range, that means it should just diff + // the cwd against a published version to the registry using the + // same project name and the provided semver range + if (semver.validRange(a)) { + if (!pkgName) + throw missingPackageJson + + return [ + `${pkgName}@${a}`, + specSelf(), + ] + } + + // when using a single package name as arg and it's part of the current + // install tree, then retrieve the current installed version and compare + // it against the same value `npm outdated` would suggest you to update to + const spec = npa(a) + if (spec.registry) { + let actualTree + let node + try { + const opts = { + ...npm.flatOptions, + path: where(), + } + const arb = new Arborist(opts) + actualTree = await arb.loadActual(opts) + node = actualTree && + actualTree.inventory.query('name', spec.name) + .values().next().value + } catch (e) { + npmlog.verbose('diff', 'failed to load actual install tree') + } + + if (!node || !node.name || !node.package || !node.package.version) { + return [ + `${spec.name}@${spec.fetchSpec}`, + specSelf(), + ] + } + + const tryRootNodeSpec = () => + (actualTree && actualTree.edgesOut.get(spec.name) || {}).spec + + const tryAnySpec = () => { + for (const edge of node.edgesIn) + return edge.spec + } + + const aSpec = `file:${node.realpath}` + + // finds what version of the package to compare against, if a exact + // version or tag was passed than it should use that, otherwise + // work from the top of the arborist tree to find the original semver + // range declared in the package that depends on the package. + let bSpec + if (spec.rawSpec) + bSpec = spec.rawSpec + else { + const bTargetVersion = + tryRootNodeSpec() + || tryAnySpec() + + // figure out what to compare against, + // follows same logic to npm outdated "Wanted" results + const packument = await pacote.packument(spec, { + ...npm.flatOptions, + preferOnline: true, + }) + bSpec = pickManifest( + packument, + bTargetVersion, + { ...npm.flatOptions } + ).version + } + + return [ + `${spec.name}@${aSpec}`, + `${spec.name}@${bSpec}`, + ] + } else if (spec.type === 'directory') { + return [ + `file:${spec.fetchSpec}`, + specSelf(), + ] + } else { + throw new Error( + 'Spec type not supported.\n\n' + + `Usage:\n${usage}` + ) + } +} + +const convertVersionsToSpecs = async ([a, b]) => { + const semverA = semver.validRange(a) + const semverB = semver.validRange(b) + + // both specs are semver versions, assume current project dir name + if (semverA && semverB) { + let pkgName + try { + pkgName = await readLocalPkg() + } catch (e) { + npmlog.verbose('diff', 'could not read project dir package.json') + } + + if (!pkgName) { + throw new Error( + 'Needs to be run from a project dir in order to diff two versions.\n\n' + + `Usage:\n${usage}` + ) + } + return [`${pkgName}@${a}`, `${pkgName}@${b}`] + } + + // otherwise uses the name from the other arg to + // figure out the spec.name of what to compare + if (!semverA && semverB) + return [a, `${npa(a).name}@${b}`] + + if (semverA && !semverB) + return [`${npa(b).name}@${a}`, b] + + // no valid semver ranges used + return [a, b] +} + +const findVersionsByPackageName = async (specs) => { + let actualTree + try { + const opts = { + ...npm.flatOptions, + path: where(), + } + const arb = new Arborist(opts) + actualTree = await arb.loadActual(opts) + } catch (e) { + npmlog.verbose('diff', 'failed to load actual install tree') + } + + return specs.map(i => { + const spec = npa(i) + if (spec.rawSpec) + return i + + const node = actualTree + && actualTree.inventory.query('name', spec.name) + .values().next().value + + const res = !node || !node.package || !node.package.version + ? spec.fetchSpec + : `file:${node.realpath}` + + return `${spec.name}@${res}` + }) +} + +module.exports = Object.assign(cmd, { completion, usage }) diff --git a/deps/npm/lib/help-search.js b/deps/npm/lib/help-search.js index c1814b4e53fc3e..d2a1818060b21b 100644 --- a/deps/npm/lib/help-search.js +++ b/deps/npm/lib/help-search.js @@ -132,7 +132,10 @@ const searchFiles = async (args, data, files) => { // sort results by number of results found, then by number of hits // then by number of matching lines - return results.sort((a, b) => + + // coverage is ignored here because the contents of results are + // nondeterministic due to either glob or readFiles or Object.entries + return results.sort(/* istanbul ignore next */ (a, b) => a.found.length > b.found.length ? -1 : a.found.length < b.found.length ? 1 : a.totalHits > b.totalHits ? -1 diff --git a/deps/npm/lib/outdated.js b/deps/npm/lib/outdated.js index b5f0f3b5b29287..f9a3fed8c10d48 100644 --- a/deps/npm/lib/outdated.js +++ b/deps/npm/lib/outdated.js @@ -108,6 +108,7 @@ async function outdated_ (tree, deps, opts) { async function getPackument (spec) { const packument = await pacote.packument(spec, { + ...npm.flatOptions, fullMetadata: npm.flatOptions.long, preferOnline: true, }) diff --git a/deps/npm/lib/publish.js b/deps/npm/lib/publish.js index 8ef7eff4c8a64d..49b2088070e7a5 100644 --- a/deps/npm/lib/publish.js +++ b/deps/npm/lib/publish.js @@ -35,22 +35,7 @@ const publish = async args => { log.verbose('publish', args) const opts = { ...npm.flatOptions } - const { json, defaultTag, registry } = opts - - if (!registry) { - throw Object.assign(new Error('No registry specified.'), { - code: 'ENOREGISTRY', - }) - } - - if (!opts.dryRun) { - const creds = npm.config.getCredentialsByURI(registry) - if (!creds.token && !creds.username) { - throw Object.assign(new Error('This command requires you to be logged in.'), { - code: 'ENEEDAUTH', - }) - } - } + const { json, defaultTag } = opts if (semver.validRange(defaultTag)) throw new Error('Tag name must not be a valid SemVer range: ' + defaultTag.trim()) @@ -91,6 +76,22 @@ const publish_ = async (arg, opts) => { if (manifest.publishConfig) Object.assign(opts, publishConfigToOpts(manifest.publishConfig)) + const { registry } = opts + if (!registry) { + throw Object.assign(new Error('No registry specified.'), { + code: 'ENOREGISTRY', + }) + } + + if (!dryRun) { + const creds = npm.config.getCredentialsByURI(registry) + if (!creds.token && !creds.username) { + throw Object.assign(new Error('This command requires you to be logged in.'), { + code: 'ENEEDAUTH', + }) + } + } + // only run scripts for directory type publishes if (spec.type === 'directory') { await runScript({ diff --git a/deps/npm/lib/utils/ansi-trim.js b/deps/npm/lib/utils/ansi-trim.js index 7f9a6c30ec9b1a..e35a1baf633352 100644 --- a/deps/npm/lib/utils/ansi-trim.js +++ b/deps/npm/lib/utils/ansi-trim.js @@ -1,7 +1,3 @@ -function ansiTrim (str) { - var r = new RegExp('\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|' + - '\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)', 'g') - return str.replace(r, '') -} - -module.exports = ansiTrim +const r = new RegExp('\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|' + + '\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)', 'g') +module.exports = str => str.replace(r, '') diff --git a/deps/npm/lib/utils/cmd-list.js b/deps/npm/lib/utils/cmd-list.js index 8c092e719c05c1..4e088c12d43f64 100644 --- a/deps/npm/lib/utils/cmd-list.js +++ b/deps/npm/lib/utils/cmd-list.js @@ -119,6 +119,7 @@ const cmdList = [ 'prefix', 'bin', 'whoami', + 'diff', 'dist-tag', 'ping', diff --git a/deps/npm/lib/utils/config.js b/deps/npm/lib/utils/config.js index 511215769893e3..3ca9766132f02f 100644 --- a/deps/npm/lib/utils/config.js +++ b/deps/npm/lib/utils/config.js @@ -74,6 +74,14 @@ const defaults = { depth: null, description: true, dev: false, + diff: [], + 'diff-unified': null, + 'diff-ignore-all-space': false, + 'diff-name-only': false, + 'diff-no-prefix': false, + 'diff-src-prefix': '', + 'diff-dst-prefix': '', + 'diff-text': false, 'dry-run': false, editor, 'engine-strict': false, @@ -216,6 +224,14 @@ const types = { depth: [null, Number], description: Boolean, dev: Boolean, + diff: [String, Array], + 'diff-unified': [null, Number], + 'diff-ignore-all-space': Boolean, + 'diff-name-only': Boolean, + 'diff-no-prefix': Boolean, + 'diff-src-prefix': String, + 'diff-dst-prefix': String, + 'diff-text': Boolean, 'dry-run': Boolean, editor: String, 'engine-strict': Boolean, diff --git a/deps/npm/lib/utils/flat-options.js b/deps/npm/lib/utils/flat-options.js index a161ff2e6a70fa..c082e4137ab217 100644 --- a/deps/npm/lib/utils/flat-options.js +++ b/deps/npm/lib/utils/flat-options.js @@ -102,6 +102,15 @@ const flatten = obj => ({ staleness: obj.searchstaleness, }, + diff: obj.diff, + diffUnified: obj['diff-unified'], + diffIgnoreAllSpace: obj['diff-ignore-all-space'], + diffNameOnly: obj['diff-name-only'], + diffNoPrefix: obj['diff-no-prefix'], + diffSrcPrefix: obj['diff-src-prefix'], + diffDstPrefix: obj['diff-dst-prefix'], + diffText: obj['diff-text'], + dryRun: obj['dry-run'], engineStrict: obj['engine-strict'], diff --git a/deps/npm/lib/utils/npm-usage.js b/deps/npm/lib/utils/npm-usage.js index 720aab3de088f1..d4261f79dcb715 100644 --- a/deps/npm/lib/utils/npm-usage.js +++ b/deps/npm/lib/utils/npm-usage.js @@ -6,6 +6,8 @@ const { cmdList } = require('./cmd-list') module.exports = (valid = true) => { npm.config.set('loglevel', 'silent') + const usesBrowser = npm.config.get('viewer') === 'browser' + ? ' (in a browser)' : '' npm.log.level = 'silent' output(` Usage: npm @@ -16,8 +18,8 @@ npm test run this project's tests npm run run the script named npm -h quick help on npm -l display usage info for all commands -npm help search for help on -npm help npm more involved overview +npm help search for help on ${usesBrowser} +npm help npm more involved overview${usesBrowser} All commands: ${npm.config.get('long') ? usages() : ('\n ' + wrap(cmdList))} @@ -40,44 +42,34 @@ npm@${npm.version} ${dirname(dirname(__dirname))} } const wrap = (arr) => { - var out = [''] - var l = 0 - var line + const out = [''] - line = process.stdout.columns - if (!line) - line = 60 - else - line = Math.min(60, Math.max(line - 16, 24)) + const line = !process.stdout.columns ? 60 + : Math.min(60, Math.max(process.stdout.columns - 16, 24)) - arr.sort(function (a, b) { - return a < b ? -1 : 1 - }) - .forEach(function (c) { - if (out[l].length + c.length + 2 < line) - out[l] += ', ' + c - else { - out[l++] += ',' - out[l] = c - } - }) + let l = 0 + for (const c of arr.sort((a, b) => a < b ? -1 : 1)) { + if (out[l].length + c.length + 2 < line) + out[l] += ', ' + c + else { + out[l++] += ',' + out[l] = c + } + } return out.join('\n ').substr(2) } const usages = () => { // return a string of : - var maxLen = 0 - return cmdList.reduce(function (set, c) { - set.push([c, require(`./${npm.deref(c)}.js`).usage || '']) + let maxLen = 0 + return cmdList.reduce((set, c) => { + set.push([c, require(`../${npm.deref(c)}.js`).usage || + /* istanbul ignore next - all commands should have usage */ '']) maxLen = Math.max(maxLen, c.length) return set - }, []).sort((a, b) => { - return a[0].localeCompare(b[0]) - }).map(function (item) { - var c = item[0] - var usage = item[1] - return '\n ' + - c + (new Array(maxLen - c.length + 2).join(' ')) + - (usage.split('\n').join('\n' + (new Array(maxLen + 6).join(' ')))) - }).join('\n') + }, []) + .sort((a, b) => a[0].localeCompare(b[0])) + .map(([c, usage]) => `\n ${c}${' '.repeat(maxLen - c.length + 1)}${ + (usage.split('\n').join('\n' + ' '.repeat(maxLen + 5)))}`) + .join('\n') } diff --git a/deps/npm/lib/utils/pulse-till-done.js b/deps/npm/lib/utils/pulse-till-done.js index 9d145eee976e16..13147bae166137 100644 --- a/deps/npm/lib/utils/pulse-till-done.js +++ b/deps/npm/lib/utils/pulse-till-done.js @@ -1,4 +1,3 @@ -const validate = require('aproba') const log = require('npmlog') let pulsers = 0 @@ -18,7 +17,6 @@ function pulseStop () { } module.exports = function (prefix, cb) { - validate('SF', [prefix, cb]) if (!prefix) prefix = 'network' pulseStart(prefix) diff --git a/deps/npm/man/man1/npm-access.1 b/deps/npm/man/man1/npm-access.1 index 173e6b1cfd1001..4a876707d65bd4 100644 --- a/deps/npm/man/man1/npm-access.1 +++ b/deps/npm/man/man1/npm-access.1 @@ -1,4 +1,4 @@ -.TH "NPM\-ACCESS" "1" "January 2021" "" "" +.TH "NPM\-ACCESS" "1" "February 2021" "" "" .SH "NAME" \fBnpm-access\fR \- Set access level on published packages .SS Synopsis diff --git a/deps/npm/man/man1/npm-adduser.1 b/deps/npm/man/man1/npm-adduser.1 index dd8fb918e1b3c7..a8fd9fdcb87464 100644 --- a/deps/npm/man/man1/npm-adduser.1 +++ b/deps/npm/man/man1/npm-adduser.1 @@ -1,4 +1,4 @@ -.TH "NPM\-ADDUSER" "1" "January 2021" "" "" +.TH "NPM\-ADDUSER" "1" "February 2021" "" "" .SH "NAME" \fBnpm-adduser\fR \- Add a registry user account .SS Synopsis diff --git a/deps/npm/man/man1/npm-audit.1 b/deps/npm/man/man1/npm-audit.1 index 1c7268e135bb26..d18e94ebb39015 100644 --- a/deps/npm/man/man1/npm-audit.1 +++ b/deps/npm/man/man1/npm-audit.1 @@ -1,4 +1,4 @@ -.TH "NPM\-AUDIT" "1" "January 2021" "" "" +.TH "NPM\-AUDIT" "1" "February 2021" "" "" .SH "NAME" \fBnpm-audit\fR \- Run a security audit .SS Synopsis diff --git a/deps/npm/man/man1/npm-bin.1 b/deps/npm/man/man1/npm-bin.1 index 771197e4b14fcc..bf6283b35a436c 100644 --- a/deps/npm/man/man1/npm-bin.1 +++ b/deps/npm/man/man1/npm-bin.1 @@ -1,4 +1,4 @@ -.TH "NPM\-BIN" "1" "January 2021" "" "" +.TH "NPM\-BIN" "1" "February 2021" "" "" .SH "NAME" \fBnpm-bin\fR \- Display npm bin folder .SS Synopsis diff --git a/deps/npm/man/man1/npm-bugs.1 b/deps/npm/man/man1/npm-bugs.1 index 3318f3a4bf7532..325fd855cd6f7b 100644 --- a/deps/npm/man/man1/npm-bugs.1 +++ b/deps/npm/man/man1/npm-bugs.1 @@ -1,4 +1,4 @@ -.TH "NPM\-BUGS" "1" "January 2021" "" "" +.TH "NPM\-BUGS" "1" "February 2021" "" "" .SH "NAME" \fBnpm-bugs\fR \- Report bugs for a package in a web browser .SS Synopsis diff --git a/deps/npm/man/man1/npm-cache.1 b/deps/npm/man/man1/npm-cache.1 index eb65d7c37290ec..4e70325055039e 100644 --- a/deps/npm/man/man1/npm-cache.1 +++ b/deps/npm/man/man1/npm-cache.1 @@ -1,4 +1,4 @@ -.TH "NPM\-CACHE" "1" "January 2021" "" "" +.TH "NPM\-CACHE" "1" "February 2021" "" "" .SH "NAME" \fBnpm-cache\fR \- Manipulates packages cache .SS Synopsis diff --git a/deps/npm/man/man1/npm-ci.1 b/deps/npm/man/man1/npm-ci.1 index b74c14dc7730bf..ac46f95ac701c6 100644 --- a/deps/npm/man/man1/npm-ci.1 +++ b/deps/npm/man/man1/npm-ci.1 @@ -1,4 +1,4 @@ -.TH "NPM\-CI" "1" "January 2021" "" "" +.TH "NPM\-CI" "1" "February 2021" "" "" .SH "NAME" \fBnpm-ci\fR \- Install a project with a clean slate .SS Synopsis diff --git a/deps/npm/man/man1/npm-completion.1 b/deps/npm/man/man1/npm-completion.1 index 6842e6aa08188c..997188c52b14c7 100644 --- a/deps/npm/man/man1/npm-completion.1 +++ b/deps/npm/man/man1/npm-completion.1 @@ -1,4 +1,4 @@ -.TH "NPM\-COMPLETION" "1" "January 2021" "" "" +.TH "NPM\-COMPLETION" "1" "February 2021" "" "" .SH "NAME" \fBnpm-completion\fR \- Tab Completion for npm .SS Synopsis diff --git a/deps/npm/man/man1/npm-config.1 b/deps/npm/man/man1/npm-config.1 index cf6114cd93e495..cba7846b8ee530 100644 --- a/deps/npm/man/man1/npm-config.1 +++ b/deps/npm/man/man1/npm-config.1 @@ -1,4 +1,4 @@ -.TH "NPM\-CONFIG" "1" "January 2021" "" "" +.TH "NPM\-CONFIG" "1" "February 2021" "" "" .SH "NAME" \fBnpm-config\fR \- Manage the npm configuration files .SS Synopsis diff --git a/deps/npm/man/man1/npm-dedupe.1 b/deps/npm/man/man1/npm-dedupe.1 index fe5ed775b45c53..be1b3e9b77b85f 100644 --- a/deps/npm/man/man1/npm-dedupe.1 +++ b/deps/npm/man/man1/npm-dedupe.1 @@ -1,4 +1,4 @@ -.TH "NPM\-DEDUPE" "1" "January 2021" "" "" +.TH "NPM\-DEDUPE" "1" "February 2021" "" "" .SH "NAME" \fBnpm-dedupe\fR \- Reduce duplication .SS Synopsis diff --git a/deps/npm/man/man1/npm-deprecate.1 b/deps/npm/man/man1/npm-deprecate.1 index 81e16e669350e0..00060ceea1f358 100644 --- a/deps/npm/man/man1/npm-deprecate.1 +++ b/deps/npm/man/man1/npm-deprecate.1 @@ -1,4 +1,4 @@ -.TH "NPM\-DEPRECATE" "1" "January 2021" "" "" +.TH "NPM\-DEPRECATE" "1" "February 2021" "" "" .SH "NAME" \fBnpm-deprecate\fR \- Deprecate a version of a package .SS Synopsis diff --git a/deps/npm/man/man1/npm-diff.1 b/deps/npm/man/man1/npm-diff.1 new file mode 100644 index 00000000000000..16c5c82863bfce --- /dev/null +++ b/deps/npm/man/man1/npm-diff.1 @@ -0,0 +1,266 @@ +.TH "NPM\-DIFF" "1" "February 2021" "" "" +.SH "NAME" +\fBnpm-diff\fR \- The registry diff command +.SS Synopsis +.P +.RS 2 +.nf +npm diff [\.\.\.] +npm diff \-\-diff= [\.\.\.] +npm diff \-\-diff= [\-\-diff=] [\.\.\.] +npm diff \-\-diff= [\-\-diff=] [\.\.\.] +npm diff [\-\-diff\-ignore\-all\-space] [\-\-diff\-name\-only] [\.\.\.] +.fi +.RE +.SS Description +.P +Similar to its \fBgit diff\fP counterpart, this command will print diff patches +of files for packages published to the npm registry\. +.RS 0 +.IP \(bu 2 +\fBnpm diff \-\-diff= \-\-diff=\fP + Compares two package versions using their registry specifiers, e\.g: + \fBnpm diff \-\-diff=pkg@1\.0\.0 \-\-diff=pkg@^2\.0\.0\fP\|\. It's also possible to + compare across forks of any package, + e\.g: \fBnpm diff \-\-diff=pkg@1\.0\.0 \-\-diff=pkg\-fork@1\.0\.0\fP\|\. + Any valid spec can be used, so that it's also possible to compare + directories or git repositories, + e\.g: \fBnpm diff \-\-diff=pkg@latest \-\-diff=\./packages/pkg\fP + Here's an example comparing two different versions of a package named + \fBabbrev\fP from the registry: +.P +.RS 2 +.nf + npm diff \-\-diff=abbrev@1\.1\.0 \-\-diff=abbrev@1\.1\.1 +.fi +.RE + On success, output looks like: +.P +.RS 2 +.nf + diff \-\-git a/package\.json b/package\.json + index v1\.1\.0\.\.v1\.1\.1 100644 + \-\-\- a/package\.json + +++ b/package\.json + @@ \-1,6 +1,6 @@ + { + "name": "abbrev", + \- "version": "1\.1\.0", + + "version": "1\.1\.1", + "description": "Like ruby's abbrev module, but in js", + "author": "Isaac Z\. Schlueter ", + "main": "abbrev\.js", +.fi +.RE + Given the flexible nature of npm specs, you can also target local + directories or git repos just like when using \fBnpm install\fP: +.P +.RS 2 +.nf + npm diff \-\-diff=https://github\.com/npm/libnpmdiff \-\-diff=\./local\-path +.fi +.RE + In the example above we can compare the contents from the package installed + from the git repo at \fBgithub\.com/npm/libnpmdiff\fP with the contents of the + \fB\|\./local\-path\fP that contains a valid package, such as a modified copy of + the original\. +.IP \(bu 2 +\fBnpm diff\fP (in a package directory, no arguments): + If the package is published to the registry, \fBnpm diff\fP will fetch the + tarball version tagged as \fBlatest\fP (this value can be configured using the + \fBtag\fP option) and proceed to compare the contents of files present in that + tarball, with the current files in your local file system\. + This workflow provides a handy way for package authors to see what + package\-tracked files have been changed in comparison with the latest + published version of that package\. +.IP \(bu 2 +\fBnpm diff \-\-diff=\fP (in a package directory): + When using a single package name (with no version or tag specifier) as an + argument, \fBnpm diff\fP will work in a similar way to + \fBnpm\-outdated\fP \fInpm\-outdated\fR and reach for the registry to figure out + what current published version of the package named will satisfy + its dependent declared semver\-range\. Once that specific version is known + \fBnpm diff\fP will print diff patches comparing the current version of + found in the local file system with that specific version + returned by the registry\. + Given a package named \fBabbrev\fP that is currently installed: +.P +.RS 2 +.nf + npm diff \-\-diff=abbrev +.fi +.RE + That will request from the registry its most up to date version and + will print a diff output comparing the currently installed version to this + newer one if the version numbers are not the same\. +.IP \(bu 2 +\fBnpm diff \-\-diff=\fP (in a package directory): + Similar to using only a single package name, it's also possible to declare + a full registry specifier version if you wish to compare the local version + of an installed package with the specific version/tag/semver\-range provided + in \fB\fP\|\. + An example: assuming \fBpkg@1\.0\.0\fP is installed in the current \fBnode_modules\fP + folder, running: +.P +.RS 2 +.nf + npm diff \-\-diff=pkg@2\.0\.0 +.fi +.RE + It will effectively be an alias to + \fBnpm diff \-\-diff=pkg@1\.0\.0 \-\-diff=pkg@2\.0\.0\fP\|\. +.IP \(bu 2 +\fBnpm diff \-\-diff= [\-\-diff=]\fP (in a package directory): + Using \fBnpm diff\fP along with semver\-valid version numbers is a shorthand + to compare different versions of the current package\. + It needs to be run from a package directory, such that for a package named + \fBpkg\fP running \fBnpm diff \-\-diff=1\.0\.0 \-\-diff=1\.0\.1\fP is the same as running + \fBnpm diff \-\-diff=pkg@1\.0\.0 \-\-diff=pkg@1\.0\.1\fP\|\. + If only a single argument \fB\fP is provided, then the current local + file system is going to be compared against that version\. + Here's an example comparing two specific versions (published to the + configured registry) of the current project directory: +.P +.RS 2 +.nf + npm diff \-\-diff=1\.0\.0 \-\-diff=1\.1\.0 +.fi +.RE + +.RE +.P +Note that tag names are not valid \fB\-\-diff\fP argument values, if you wish to +compare to a published tag, you must use the \fBpkg@tagname\fP syntax\. +.SS Filtering files +.P +It's possible to also specify positional arguments using file names or globs +pattern matching in order to limit the result of diff patches to only a subset +of files for a given package, e\.g: +.P +.RS 2 +.nf + npm diff \-\-diff=pkg@2 \./lib/ CHANGELOG\.md +.fi +.RE +.P +In the example above the diff output is only going to print contents of files +located within the folder \fB\|\./lib/\fP and changed lines of code within the +\fBCHANGELOG\.md\fP file\. +.SS Configuration +.SS diff +.RS 0 +.IP \(bu 2 +Type: Array +.IP \(bu 2 +Default: null + +.RE +.P +Defines npm package specifiers to compare using the \fBnpm diff\fP command\. +.P +This can be specified up to 2 times\. +.SS diff\-name\-only +.RS 0 +.IP \(bu 2 +Type: Boolean +.IP \(bu 2 +Default: false + +.RE +.P +When set to \fBtrue\fP running \fBnpm diff\fP only returns the names of the files that +have any difference\. +.SS diff\-unified +.RS 0 +.IP \(bu 2 +Type: Number +.IP \(bu 2 +Default: \fB3\fP + +.RE +.P +The number of lines of context to print in the unified diff format output\. +.SS diff\-ignore\-all\-space +.RS 0 +.IP \(bu 2 +Type: Boolean +.IP \(bu 2 +Default: false + +.RE +.P +Ignore whitespace when comparing lines\. This ignores differences even if one +line has whitespace where the other line has none\. +.SS diff\-no\-prefix +.RS 0 +.IP \(bu 2 +Type: Boolean +.IP \(bu 2 +Default: false + +.RE +.P +Do not show any source or destination prefix\. +.SS diff\-src\-prefix +.RS 0 +.IP \(bu 2 +Type: String +.IP \(bu 2 +Default: \fB"a/"\fP + +.RE +.P +Show the given source prefix in diff patches headers instead of using "a/"\. +.SS diff\-dst\-prefix +.RS 0 +.IP \(bu 2 +Type: String +.IP \(bu 2 +Default: \fB"b/"\fP + +.RE +.P +Show the given source prefix in diff patches headers instead of using "b/"\. +.SS diff\-text +.RS 0 +.IP \(bu 2 +Type: Boolean +.IP \(bu 2 +Default: false + +.RE +.P +Treat all files as text\. +.SS global +.RS 0 +.IP \(bu 2 +Default: false +.IP \(bu 2 +Type: Boolean + +.RE +.P +Uses packages from the global space as a source for comparison\. +.SS tag +.RS 0 +.IP \(bu 2 +Type: String +.IP \(bu 2 +Default: \fB"latest"\fP + +.RE +.P +The tag used to fetch the tarball that will be compared with the local file +system files when running npm diff with no arguments\. +.SH See Also +.RS 0 +.IP \(bu 2 +npm help outdated +.IP \(bu 2 +npm help install +.IP \(bu 2 +npm help config +.IP \(bu 2 +npm help registry + +.RE diff --git a/deps/npm/man/man1/npm-dist-tag.1 b/deps/npm/man/man1/npm-dist-tag.1 index 4729a069d0a057..779fd6b48e5a7d 100644 --- a/deps/npm/man/man1/npm-dist-tag.1 +++ b/deps/npm/man/man1/npm-dist-tag.1 @@ -1,4 +1,4 @@ -.TH "NPM\-DIST\-TAG" "1" "January 2021" "" "" +.TH "NPM\-DIST\-TAG" "1" "February 2021" "" "" .SH "NAME" \fBnpm-dist-tag\fR \- Modify package distribution tags .SS Synopsis diff --git a/deps/npm/man/man1/npm-docs.1 b/deps/npm/man/man1/npm-docs.1 index 5bedabb0aecc90..3bb3258b997d6d 100644 --- a/deps/npm/man/man1/npm-docs.1 +++ b/deps/npm/man/man1/npm-docs.1 @@ -1,4 +1,4 @@ -.TH "NPM\-DOCS" "1" "January 2021" "" "" +.TH "NPM\-DOCS" "1" "February 2021" "" "" .SH "NAME" \fBnpm-docs\fR \- Open documentation for a package in a web browser .SS Synopsis diff --git a/deps/npm/man/man1/npm-doctor.1 b/deps/npm/man/man1/npm-doctor.1 index dda1886ebeb757..9f6006eb3dd175 100644 --- a/deps/npm/man/man1/npm-doctor.1 +++ b/deps/npm/man/man1/npm-doctor.1 @@ -1,4 +1,4 @@ -.TH "NPM\-DOCTOR" "1" "January 2021" "" "" +.TH "NPM\-DOCTOR" "1" "February 2021" "" "" .SH "NAME" \fBnpm-doctor\fR \- Check your npm environment .SS Synopsis diff --git a/deps/npm/man/man1/npm-edit.1 b/deps/npm/man/man1/npm-edit.1 index 844e2ee7d0302f..248150e2ff2018 100644 --- a/deps/npm/man/man1/npm-edit.1 +++ b/deps/npm/man/man1/npm-edit.1 @@ -1,4 +1,4 @@ -.TH "NPM\-EDIT" "1" "January 2021" "" "" +.TH "NPM\-EDIT" "1" "February 2021" "" "" .SH "NAME" \fBnpm-edit\fR \- Edit an installed package .SS Synopsis diff --git a/deps/npm/man/man1/npm-exec.1 b/deps/npm/man/man1/npm-exec.1 index a4c45df72e8b27..22d04207b9e1b9 100644 --- a/deps/npm/man/man1/npm-exec.1 +++ b/deps/npm/man/man1/npm-exec.1 @@ -1,4 +1,4 @@ -.TH "NPM\-EXEC" "1" "January 2021" "" "" +.TH "NPM\-EXEC" "1" "February 2021" "" "" .SH "NAME" \fBnpm-exec\fR \- Run a command from a local or remote npm package .SS Synopsis @@ -200,6 +200,24 @@ The \fB\-\-shell\fP option is replaced with \fB\-\-script\-shell\fP, but maintai in the \fBnpx\fP executable for backwards compatibility\. .RE +.SS A note on caching +.P +The npm cli utilizes its internal package cache when using the package +name specified\. You can use the following to change how and when the +cli uses this cache\. See npm help \fBcache\fP for more on +how the cache works\. +.SS prefer\-online +.P +Forces staleness checks for packages, making the cli look for updates +immediately even if the package is already in the cache\. +.SS prefer\-offline +.P +Bypasses staleness checks for packages\. Missing data will still be +requested from the server\. To force full offline mode, use \fBoffline\fP\|\. +.SS offline +.P +Forces full offline mode\. Any packages not locally cached will result in +an error\. .SS See Also .RS 0 .IP \(bu 2 diff --git a/deps/npm/man/man1/npm-explain.1 b/deps/npm/man/man1/npm-explain.1 index 05def6f9953406..13b252d8a69f11 100644 --- a/deps/npm/man/man1/npm-explain.1 +++ b/deps/npm/man/man1/npm-explain.1 @@ -1,4 +1,4 @@ -.TH "NPM\-EXPLAIN" "1" "January 2021" "" "" +.TH "NPM\-EXPLAIN" "1" "February 2021" "" "" .SH "NAME" \fBnpm-explain\fR \- Explain installed packages .SS Synopsis diff --git a/deps/npm/man/man1/npm-explore.1 b/deps/npm/man/man1/npm-explore.1 index 75e19e0ccfb79b..adcc074e532612 100644 --- a/deps/npm/man/man1/npm-explore.1 +++ b/deps/npm/man/man1/npm-explore.1 @@ -1,4 +1,4 @@ -.TH "NPM\-EXPLORE" "1" "January 2021" "" "" +.TH "NPM\-EXPLORE" "1" "February 2021" "" "" .SH "NAME" \fBnpm-explore\fR \- Browse an installed package .SS Synopsis diff --git a/deps/npm/man/man1/npm-fund.1 b/deps/npm/man/man1/npm-fund.1 index 5ecc397d5d3129..278e39d4f970a0 100644 --- a/deps/npm/man/man1/npm-fund.1 +++ b/deps/npm/man/man1/npm-fund.1 @@ -1,4 +1,4 @@ -.TH "NPM\-FUND" "1" "January 2021" "" "" +.TH "NPM\-FUND" "1" "February 2021" "" "" .SH "NAME" \fBnpm-fund\fR \- Retrieve funding information .SS Synopsis diff --git a/deps/npm/man/man1/npm-help-search.1 b/deps/npm/man/man1/npm-help-search.1 index 0fb25c5afeb018..60a3ac4d593999 100644 --- a/deps/npm/man/man1/npm-help-search.1 +++ b/deps/npm/man/man1/npm-help-search.1 @@ -1,4 +1,4 @@ -.TH "NPM\-HELP\-SEARCH" "1" "January 2021" "" "" +.TH "NPM\-HELP\-SEARCH" "1" "February 2021" "" "" .SH "NAME" \fBnpm-help-search\fR \- Search npm help documentation .SS Synopsis diff --git a/deps/npm/man/man1/npm-help.1 b/deps/npm/man/man1/npm-help.1 index 01151c5d9ca768..0ace5ec6bb5f74 100644 --- a/deps/npm/man/man1/npm-help.1 +++ b/deps/npm/man/man1/npm-help.1 @@ -1,4 +1,4 @@ -.TH "NPM\-HELP" "1" "January 2021" "" "" +.TH "NPM\-HELP" "1" "February 2021" "" "" .SH "NAME" \fBnpm-help\fR \- Get help on npm .SS Synopsis diff --git a/deps/npm/man/man1/npm-hook.1 b/deps/npm/man/man1/npm-hook.1 index d7715658890357..950b7f85142071 100644 --- a/deps/npm/man/man1/npm-hook.1 +++ b/deps/npm/man/man1/npm-hook.1 @@ -1,4 +1,4 @@ -.TH "NPM\-HOOK" "1" "January 2021" "" "" +.TH "NPM\-HOOK" "1" "February 2021" "" "" .SH "NAME" \fBnpm-hook\fR \- Manage registry hooks .SS Synopsis diff --git a/deps/npm/man/man1/npm-init.1 b/deps/npm/man/man1/npm-init.1 index 05dbd6d80a6110..d759efc5244d7c 100644 --- a/deps/npm/man/man1/npm-init.1 +++ b/deps/npm/man/man1/npm-init.1 @@ -1,4 +1,4 @@ -.TH "NPM\-INIT" "1" "January 2021" "" "" +.TH "NPM\-INIT" "1" "February 2021" "" "" .SH "NAME" \fBnpm-init\fR \- create a package\.json file .SS Synopsis @@ -80,6 +80,24 @@ Generate it without having it ask any questions: $ npm init \-y .fi .RE +.SS A note on caching +.P +The npm cli utilizes its internal package cache when using the package +name specified\. You can use the following to change how and when the +cli uses this cache\. See npm help \fBcache\fP for more on +how the cache works\. +.SS prefer\-online +.P +Forces staleness checks for packages, making the cli look for updates +immediately even if the package is already in the cache\. +.SS prefer\-offline +.P +Bypasses staleness checks for packages\. Missing data will still be +requested from the server\. To force full offline mode, use \fBoffline\fP\|\. +.SS offline +.P +Forces full offline mode\. Any packages not locally cached will result in +an error\. .SS See Also .RS 0 .IP \(bu 2 @@ -90,5 +108,7 @@ npm help package\.json npm help version .IP \(bu 2 npm help scope +.IP \(bu 2 +npm help exec .RE diff --git a/deps/npm/man/man1/npm-install-ci-test.1 b/deps/npm/man/man1/npm-install-ci-test.1 index bc0ec6ef2fd0c6..a4f69dd04ebed1 100644 --- a/deps/npm/man/man1/npm-install-ci-test.1 +++ b/deps/npm/man/man1/npm-install-ci-test.1 @@ -1,4 +1,4 @@ -.TH "NPM\-INSTALL\-CI\-TEST" "1" "January 2021" "" "" +.TH "NPM\-INSTALL\-CI\-TEST" "1" "February 2021" "" "" .SH "NAME" \fBnpm-install-ci-test\fR \- Install a project with a clean slate and run tests .SS Synopsis diff --git a/deps/npm/man/man1/npm-install-test.1 b/deps/npm/man/man1/npm-install-test.1 index 73fccaf4154e38..def347d19d78c8 100644 --- a/deps/npm/man/man1/npm-install-test.1 +++ b/deps/npm/man/man1/npm-install-test.1 @@ -1,4 +1,4 @@ -.TH "NPM\-INSTALL\-TEST" "1" "January 2021" "" "" +.TH "NPM\-INSTALL\-TEST" "1" "February 2021" "" "" .SH "NAME" \fBnpm-install-test\fR \- Install package(s) and run tests .SS Synopsis diff --git a/deps/npm/man/man1/npm-install.1 b/deps/npm/man/man1/npm-install.1 index b0f567e254a19b..0522d8b6588c05 100644 --- a/deps/npm/man/man1/npm-install.1 +++ b/deps/npm/man/man1/npm-install.1 @@ -1,4 +1,4 @@ -.TH "NPM\-INSTALL" "1" "January 2021" "" "" +.TH "NPM\-INSTALL" "1" "February 2021" "" "" .SH "NAME" \fBnpm-install\fR \- Install a package .SS Synopsis diff --git a/deps/npm/man/man1/npm-link.1 b/deps/npm/man/man1/npm-link.1 index 881ee1f87fb089..7f978f281f0ea0 100644 --- a/deps/npm/man/man1/npm-link.1 +++ b/deps/npm/man/man1/npm-link.1 @@ -1,4 +1,4 @@ -.TH "NPM\-LINK" "1" "January 2021" "" "" +.TH "NPM\-LINK" "1" "February 2021" "" "" .SH "NAME" \fBnpm-link\fR \- Symlink a package folder .SS Synopsis diff --git a/deps/npm/man/man1/npm-logout.1 b/deps/npm/man/man1/npm-logout.1 index c0bbf0e803b1a3..032a0bbd76e9e1 100644 --- a/deps/npm/man/man1/npm-logout.1 +++ b/deps/npm/man/man1/npm-logout.1 @@ -1,4 +1,4 @@ -.TH "NPM\-LOGOUT" "1" "January 2021" "" "" +.TH "NPM\-LOGOUT" "1" "February 2021" "" "" .SH "NAME" \fBnpm-logout\fR \- Log out of the registry .SS Synopsis diff --git a/deps/npm/man/man1/npm-ls.1 b/deps/npm/man/man1/npm-ls.1 index 0a90b749529343..450f21d7b757a1 100644 --- a/deps/npm/man/man1/npm-ls.1 +++ b/deps/npm/man/man1/npm-ls.1 @@ -1,4 +1,4 @@ -.TH "NPM\-LS" "1" "January 2021" "" "" +.TH "NPM\-LS" "1" "February 2021" "" "" .SH "NAME" \fBnpm-ls\fR \- List installed packages .SS Synopsis @@ -26,7 +26,7 @@ example, running \fBnpm ls promzard\fP in npm's source tree will show: .P .RS 2 .nf -npm@7\.4\.3 /path/to/npm +npm@7\.5\.1 /path/to/npm └─┬ init\-package\-json@0\.0\.4 └── promzard@0\.1\.5 .fi diff --git a/deps/npm/man/man1/npm-org.1 b/deps/npm/man/man1/npm-org.1 index a25119964ae99f..8749ca79d73128 100644 --- a/deps/npm/man/man1/npm-org.1 +++ b/deps/npm/man/man1/npm-org.1 @@ -1,4 +1,4 @@ -.TH "NPM\-ORG" "1" "January 2021" "" "" +.TH "NPM\-ORG" "1" "February 2021" "" "" .SH "NAME" \fBnpm-org\fR \- Manage orgs .SS Synopsis diff --git a/deps/npm/man/man1/npm-outdated.1 b/deps/npm/man/man1/npm-outdated.1 index a9e59718c243e6..6fe63984c19541 100644 --- a/deps/npm/man/man1/npm-outdated.1 +++ b/deps/npm/man/man1/npm-outdated.1 @@ -1,4 +1,4 @@ -.TH "NPM\-OUTDATED" "1" "January 2021" "" "" +.TH "NPM\-OUTDATED" "1" "February 2021" "" "" .SH "NAME" \fBnpm-outdated\fR \- Check for outdated packages .SS Synopsis diff --git a/deps/npm/man/man1/npm-owner.1 b/deps/npm/man/man1/npm-owner.1 index f7709d7c27ba48..ca853fd0d233cb 100644 --- a/deps/npm/man/man1/npm-owner.1 +++ b/deps/npm/man/man1/npm-owner.1 @@ -1,4 +1,4 @@ -.TH "NPM\-OWNER" "1" "January 2021" "" "" +.TH "NPM\-OWNER" "1" "February 2021" "" "" .SH "NAME" \fBnpm-owner\fR \- Manage package owners .SS Synopsis @@ -45,7 +45,5 @@ npm help publish npm help registry .IP \(bu 2 npm help adduser -.IP \(bu 2 -npm help disputes .RE diff --git a/deps/npm/man/man1/npm-pack.1 b/deps/npm/man/man1/npm-pack.1 index 08445b378405b5..60434874a80726 100644 --- a/deps/npm/man/man1/npm-pack.1 +++ b/deps/npm/man/man1/npm-pack.1 @@ -1,4 +1,4 @@ -.TH "NPM\-PACK" "1" "January 2021" "" "" +.TH "NPM\-PACK" "1" "February 2021" "" "" .SH "NAME" \fBnpm-pack\fR \- Create a tarball from a package .SS Synopsis diff --git a/deps/npm/man/man1/npm-ping.1 b/deps/npm/man/man1/npm-ping.1 index e0277ea3f1bfae..0633da299d0195 100644 --- a/deps/npm/man/man1/npm-ping.1 +++ b/deps/npm/man/man1/npm-ping.1 @@ -1,4 +1,4 @@ -.TH "NPM\-PING" "1" "January 2021" "" "" +.TH "NPM\-PING" "1" "February 2021" "" "" .SH "NAME" \fBnpm-ping\fR \- Ping npm registry .SS Synopsis diff --git a/deps/npm/man/man1/npm-prefix.1 b/deps/npm/man/man1/npm-prefix.1 index ce1426703aa0e1..93c5035e7f64d3 100644 --- a/deps/npm/man/man1/npm-prefix.1 +++ b/deps/npm/man/man1/npm-prefix.1 @@ -1,4 +1,4 @@ -.TH "NPM\-PREFIX" "1" "January 2021" "" "" +.TH "NPM\-PREFIX" "1" "February 2021" "" "" .SH "NAME" \fBnpm-prefix\fR \- Display prefix .SS Synopsis diff --git a/deps/npm/man/man1/npm-profile.1 b/deps/npm/man/man1/npm-profile.1 index 0b6116664d98ca..ee153aedf4262f 100644 --- a/deps/npm/man/man1/npm-profile.1 +++ b/deps/npm/man/man1/npm-profile.1 @@ -1,4 +1,4 @@ -.TH "NPM\-PROFILE" "1" "January 2021" "" "" +.TH "NPM\-PROFILE" "1" "February 2021" "" "" .SH "NAME" \fBnpm-profile\fR \- Change settings on your registry profile .SS Synopsis diff --git a/deps/npm/man/man1/npm-prune.1 b/deps/npm/man/man1/npm-prune.1 index 20b229b52ac7a5..20e3346c409416 100644 --- a/deps/npm/man/man1/npm-prune.1 +++ b/deps/npm/man/man1/npm-prune.1 @@ -1,4 +1,4 @@ -.TH "NPM\-PRUNE" "1" "January 2021" "" "" +.TH "NPM\-PRUNE" "1" "February 2021" "" "" .SH "NAME" \fBnpm-prune\fR \- Remove extraneous packages .SS Synopsis diff --git a/deps/npm/man/man1/npm-publish.1 b/deps/npm/man/man1/npm-publish.1 index c6fafeca620642..fdcdbd0c044cc6 100644 --- a/deps/npm/man/man1/npm-publish.1 +++ b/deps/npm/man/man1/npm-publish.1 @@ -1,4 +1,4 @@ -.TH "NPM\-PUBLISH" "1" "January 2021" "" "" +.TH "NPM\-PUBLISH" "1" "February 2021" "" "" .SH "NAME" \fBnpm-publish\fR \- Publish a package .SS Synopsis diff --git a/deps/npm/man/man1/npm-rebuild.1 b/deps/npm/man/man1/npm-rebuild.1 index 75a132f16a1674..ae451948b5554c 100644 --- a/deps/npm/man/man1/npm-rebuild.1 +++ b/deps/npm/man/man1/npm-rebuild.1 @@ -1,4 +1,4 @@ -.TH "NPM\-REBUILD" "1" "January 2021" "" "" +.TH "NPM\-REBUILD" "1" "February 2021" "" "" .SH "NAME" \fBnpm-rebuild\fR \- Rebuild a package .SS Synopsis diff --git a/deps/npm/man/man1/npm-repo.1 b/deps/npm/man/man1/npm-repo.1 index 5f95ca52ee3200..9d56e9c39e1dee 100644 --- a/deps/npm/man/man1/npm-repo.1 +++ b/deps/npm/man/man1/npm-repo.1 @@ -1,4 +1,4 @@ -.TH "NPM\-REPO" "1" "January 2021" "" "" +.TH "NPM\-REPO" "1" "February 2021" "" "" .SH "NAME" \fBnpm-repo\fR \- Open package repository page in the browser .SS Synopsis diff --git a/deps/npm/man/man1/npm-restart.1 b/deps/npm/man/man1/npm-restart.1 index 2663343dc1eb8e..5c421e6b8caf54 100644 --- a/deps/npm/man/man1/npm-restart.1 +++ b/deps/npm/man/man1/npm-restart.1 @@ -1,4 +1,4 @@ -.TH "NPM\-RESTART" "1" "January 2021" "" "" +.TH "NPM\-RESTART" "1" "February 2021" "" "" .SH "NAME" \fBnpm-restart\fR \- Restart a package .SS Synopsis diff --git a/deps/npm/man/man1/npm-root.1 b/deps/npm/man/man1/npm-root.1 index dc36c04e495c29..be6042217c8b01 100644 --- a/deps/npm/man/man1/npm-root.1 +++ b/deps/npm/man/man1/npm-root.1 @@ -1,4 +1,4 @@ -.TH "NPM\-ROOT" "1" "January 2021" "" "" +.TH "NPM\-ROOT" "1" "February 2021" "" "" .SH "NAME" \fBnpm-root\fR \- Display npm root .SS Synopsis diff --git a/deps/npm/man/man1/npm-run-script.1 b/deps/npm/man/man1/npm-run-script.1 index 12d53610de0fbd..0d7f8ae994c04e 100644 --- a/deps/npm/man/man1/npm-run-script.1 +++ b/deps/npm/man/man1/npm-run-script.1 @@ -1,4 +1,4 @@ -.TH "NPM\-RUN\-SCRIPT" "1" "January 2021" "" "" +.TH "NPM\-RUN\-SCRIPT" "1" "February 2021" "" "" .SH "NAME" \fBnpm-run-script\fR \- Run arbitrary package scripts .SS Synopsis @@ -32,7 +32,7 @@ npm run test \-\- \-\-grep="pattern" .RE .P The arguments will only be passed to the script specified after \fBnpm run\fP -and not to any pre or post script\. +and not to any \fBpre\fP or \fBpost\fP script\. .P The \fBenv\fP script is a special built\-in command that can be used to list environment variables that will be available to the script at runtime\. If an @@ -60,7 +60,8 @@ instead of .RE .P The actual shell your script is run within is platform dependent\. By default, -on Unix\-like systems it is the \fB/bin/sh\fP command, on Windows it is the \fBcmd\.exe\fP\|\. +on Unix\-like systems it is the \fB/bin/sh\fP command, on Windows it is +\fBcmd\.exe\fP\|\. The actual shell referred to by \fB/bin/sh\fP also depends on the system\. You can customize the shell with the \fBscript\-shell\fP configuration\. .P @@ -77,14 +78,53 @@ If \fB\-\-scripts\-prepend\-node\-path=auto\fP is passed (which has been the def in \fBnpm\fP v3), this is only performed when that \fBnode\fP executable is not found in the \fBPATH\fP\|\. .P -If you try to run a script without having a \fBnode_modules\fP directory and it fails, -you will be given a warning to run \fBnpm install\fP, just in case you've forgotten\. -.P -You can use the \fB\-\-silent\fP flag to prevent showing \fBnpm ERR!\fP output on error\. +If you try to run a script without having a \fBnode_modules\fP directory and it +fails, you will be given a warning to run \fBnpm install\fP, just in case you've +forgotten\. +.SS Configuration +.SS if\-present +.RS 0 +.IP \(bu 2 +Type: Boolean +.IP \(bu 2 +Default: false + +.RE .P You can use the \fB\-\-if\-present\fP flag to avoid exiting with a non\-zero exit code when the script is undefined\. This lets you run potentially undefined scripts without breaking the execution chain\. +.SS ignore\-scripts +.RS 0 +.IP \(bu 2 +Type: Boolean +.IP \(bu 2 +Default: false + +.RE +.P +Skips running \fBpre\fP and \fBpost\fP scripts\. +.SS script\-shell +.RS 0 +.IP \(bu 2 +Type: String +.IP \(bu 2 +Default: \fBnull\fP + +.RE +.P +Optional custom script to use to execute the command\. If not defined defaults +to \fB/bin/sh\fP on Unix, defaults to \fBenv\.comspec\fP or \fBcmd\.exe\fP on Windows\. +.SS silent +.RS 0 +.IP \(bu 2 +Type: Boolean +.IP \(bu 2 +Default: false + +.RE +.P +You can use the \fB\-\-silent\fP flag to prevent showing \fBnpm ERR!\fP output on error\. .SS See Also .RS 0 .IP \(bu 2 diff --git a/deps/npm/man/man1/npm-search.1 b/deps/npm/man/man1/npm-search.1 index ab71c948f48bf8..c34eb58a8d6f82 100644 --- a/deps/npm/man/man1/npm-search.1 +++ b/deps/npm/man/man1/npm-search.1 @@ -1,4 +1,4 @@ -.TH "NPM\-SEARCH" "1" "January 2021" "" "" +.TH "NPM\-SEARCH" "1" "February 2021" "" "" .SH "NAME" \fBnpm-search\fR \- Search for packages .SS Synopsis @@ -129,12 +129,12 @@ the cli uses this cache\. See npm help \fBcache\fP for more on how the cache works\. .SS prefer\-online .P -Forced staleness checks for cached searches, making the cli look for +Forces staleness checks for cached searches, making the cli look for updates immediately even for fresh search results\. .SS prefer\-offline .P -Bypasses staleness checks for cached\. Missing data will still be -requested from the server\. To force full offline mode, use \fBoffline\fP\|\. +Bypasses staleness checks for cached searches\. Missing data will still +be requested from the server\. To force full offline mode, use \fBoffline\fP\|\. .SS offline .P Forces full offline mode\. Any searches not locally cached will result in diff --git a/deps/npm/man/man1/npm-set-script.1 b/deps/npm/man/man1/npm-set-script.1 index cbadcbe53100ec..e5cbdc067df42c 100644 --- a/deps/npm/man/man1/npm-set-script.1 +++ b/deps/npm/man/man1/npm-set-script.1 @@ -1,4 +1,4 @@ -.TH "NPM\-SET\-SCRIPT" "1" "January 2021" "" "" +.TH "NPM\-SET\-SCRIPT" "1" "February 2021" "" "" .SH "NAME" \fBnpm-set-script\fR \- Set tasks in the scripts section of package\.json .SS Synopsis diff --git a/deps/npm/man/man1/npm-shrinkwrap.1 b/deps/npm/man/man1/npm-shrinkwrap.1 index c5151ab9abe2b2..31ad8d96acf1c6 100644 --- a/deps/npm/man/man1/npm-shrinkwrap.1 +++ b/deps/npm/man/man1/npm-shrinkwrap.1 @@ -1,4 +1,4 @@ -.TH "NPM\-SHRINKWRAP" "1" "January 2021" "" "" +.TH "NPM\-SHRINKWRAP" "1" "February 2021" "" "" .SH "NAME" \fBnpm-shrinkwrap\fR \- Lock down dependency versions for publication .SS Synopsis diff --git a/deps/npm/man/man1/npm-star.1 b/deps/npm/man/man1/npm-star.1 index 914b98c81a9de4..476e0298d7476e 100644 --- a/deps/npm/man/man1/npm-star.1 +++ b/deps/npm/man/man1/npm-star.1 @@ -1,4 +1,4 @@ -.TH "NPM\-STAR" "1" "January 2021" "" "" +.TH "NPM\-STAR" "1" "February 2021" "" "" .SH "NAME" \fBnpm-star\fR \- Mark your favorite packages .SS Synopsis diff --git a/deps/npm/man/man1/npm-stars.1 b/deps/npm/man/man1/npm-stars.1 index 48f404639c7b23..09a1cecc3b724e 100644 --- a/deps/npm/man/man1/npm-stars.1 +++ b/deps/npm/man/man1/npm-stars.1 @@ -1,4 +1,4 @@ -.TH "NPM\-STARS" "1" "January 2021" "" "" +.TH "NPM\-STARS" "1" "February 2021" "" "" .SH "NAME" \fBnpm-stars\fR \- View packages marked as favorites .SS Synopsis diff --git a/deps/npm/man/man1/npm-start.1 b/deps/npm/man/man1/npm-start.1 index a3d343d84f4bbd..2f9507cae43f6c 100644 --- a/deps/npm/man/man1/npm-start.1 +++ b/deps/npm/man/man1/npm-start.1 @@ -1,4 +1,4 @@ -.TH "NPM\-START" "1" "January 2021" "" "" +.TH "NPM\-START" "1" "February 2021" "" "" .SH "NAME" \fBnpm-start\fR \- Start a package .SS Synopsis diff --git a/deps/npm/man/man1/npm-stop.1 b/deps/npm/man/man1/npm-stop.1 index 2d811be0b48f92..ebbde966f435df 100644 --- a/deps/npm/man/man1/npm-stop.1 +++ b/deps/npm/man/man1/npm-stop.1 @@ -1,4 +1,4 @@ -.TH "NPM\-STOP" "1" "January 2021" "" "" +.TH "NPM\-STOP" "1" "February 2021" "" "" .SH "NAME" \fBnpm-stop\fR \- Stop a package .SS Synopsis diff --git a/deps/npm/man/man1/npm-team.1 b/deps/npm/man/man1/npm-team.1 index bb3bc1d5d006ca..79a9dc3b0c17fc 100644 --- a/deps/npm/man/man1/npm-team.1 +++ b/deps/npm/man/man1/npm-team.1 @@ -1,4 +1,4 @@ -.TH "NPM\-TEAM" "1" "January 2021" "" "" +.TH "NPM\-TEAM" "1" "February 2021" "" "" .SH "NAME" \fBnpm-team\fR \- Manage organization teams and team memberships .SS Synopsis @@ -12,8 +12,6 @@ npm team add npm team rm npm team ls | - -npm team edit .fi .RE .SS Description @@ -22,24 +20,70 @@ Used to manage teams in organizations, and change team memberships\. Does not handle permissions for packages\. .P Teams must always be fully qualified with the organization/scope they belong to -when operating on them, separated by a colon (\fB:\fP)\. That is, if you have a \fBwombats\fP team in a \fBwisdom\fP organization, you must always refer to that team as \fBwisdom:wombats\fP in these commands\. +when operating on them, separated by a colon (\fB:\fP)\. That is, if you have a +\fBnewteam\fP team in an \fBorg\fP organization, you must always refer to that team +as \fB@org:newteam\fP in these commands\. .P -If you have two\-factor authentication enabled in \fBauth\-and\-writes\fP mode, then you can provide a code from your authenticator with \fB[\-\-otp ]\fP\|\. If you don't include this then you will be prompted\. +If you have two\-factor authentication enabled in \fBauth\-and\-writes\fP mode, then +you can provide a code from your authenticator with \fB[\-\-otp ]\fP\|\. +If you don't include this then you will be prompted\. .RS 0 .IP \(bu 2 create / destroy: -Create a new team, or destroy an existing one\. Note: You cannot remove the \fBdevelopers\fP team, learn more\. +Create a new team, or destroy an existing one\. Note: You cannot remove the +\fBdevelopers\fP team, learn more\. +Here's how to create a new team \fBnewteam\fP under the \fBorg\fP org: +.P +.RS 2 +.nf +npm team create @org:newteam +.fi +.RE +You should see a confirming message such as: \fB+@org:newteam\fP once the new +team has been created\. .IP \(bu 2 -add / rm: -Add a user to an existing team, or remove a user from a team they belong to\. +add: +Add a user to an existing team\. +Adding a new user \fBusername\fP to a team named \fBnewteam\fP under the \fBorg\fP org: +.P +.RS 2 +.nf +npm team add @org:newteam username +.fi +.RE +On success, you should see a message: \fBusername added to @org:newteam\fP +.IP \(bu 2 +rm: +Using \fBnpm team rm\fP you can also remove users from a team they belong to\. +Here's an example removing user \fBusername\fP from \fBnewteam\fP team +in \fBorg\fP organization: +.P +.RS 2 +.nf +npm team rm @org:newteam username +.fi +.RE +Once the user is removed a confirmation message is displayed: +\fBusername removed from @org:newteam\fP .IP \(bu 2 ls: If performed on an organization name, will return a list of existing teams under that organization\. If performed on a team, it will instead return a list of all users belonging to that particular team\. -.IP \(bu 2 -edit: -Edit a current team\. +Here's an example of how to list all teams from an org named \fBorg\fP: +.P +.RS 2 +.nf +npm team ls @org +.fi +.RE +Example listing all members of a team named \fBnewteam\fP: +.P +.RS 2 +.nf +npm team ls @org:newteam +.fi +.RE .RE .SS Details @@ -47,9 +91,9 @@ Edit a current team\. \fBnpm team\fP always operates directly on the current registry, configurable from the command line using \fB\-\-registry=\fP\|\. .P -In order to create teams and manage team membership, you must be a \fIteam admin\fR -under the given organization\. Listing teams and team memberships may be done by -any member of the organizations\. +You must be a \fIteam admin\fR to create teams and manage team membership, under +the given organization\. Listing teams and team memberships may be done by +any member of the organization\. .P Organization creation and management of team admins and \fIorganization\fR members is done through the website, not the npm CLI\. @@ -61,6 +105,8 @@ use the \fBnpm access\fP command to grant or revoke the appropriate permissions\ .IP \(bu 2 npm help access .IP \(bu 2 +npm help config +.IP \(bu 2 npm help registry .RE diff --git a/deps/npm/man/man1/npm-test.1 b/deps/npm/man/man1/npm-test.1 index 877e25c8157f5c..33b1570a3391a9 100644 --- a/deps/npm/man/man1/npm-test.1 +++ b/deps/npm/man/man1/npm-test.1 @@ -1,4 +1,4 @@ -.TH "NPM\-TEST" "1" "January 2021" "" "" +.TH "NPM\-TEST" "1" "February 2021" "" "" .SH "NAME" \fBnpm-test\fR \- Test a package .SS Synopsis diff --git a/deps/npm/man/man1/npm-token.1 b/deps/npm/man/man1/npm-token.1 index 5edb1cee42eda1..4437653cd365ed 100644 --- a/deps/npm/man/man1/npm-token.1 +++ b/deps/npm/man/man1/npm-token.1 @@ -1,4 +1,4 @@ -.TH "NPM\-TOKEN" "1" "January 2021" "" "" +.TH "NPM\-TOKEN" "1" "February 2021" "" "" .SH "NAME" \fBnpm-token\fR \- Manage your authentication tokens .SS Synopsis diff --git a/deps/npm/man/man1/npm-uninstall.1 b/deps/npm/man/man1/npm-uninstall.1 index fb5016b3903935..4e996411db6719 100644 --- a/deps/npm/man/man1/npm-uninstall.1 +++ b/deps/npm/man/man1/npm-uninstall.1 @@ -1,4 +1,4 @@ -.TH "NPM\-UNINSTALL" "1" "January 2021" "" "" +.TH "NPM\-UNINSTALL" "1" "February 2021" "" "" .SH "NAME" \fBnpm-uninstall\fR \- Remove a package .SS Synopsis diff --git a/deps/npm/man/man1/npm-unpublish.1 b/deps/npm/man/man1/npm-unpublish.1 index 6542ec54643f38..b938c99d574c0d 100644 --- a/deps/npm/man/man1/npm-unpublish.1 +++ b/deps/npm/man/man1/npm-unpublish.1 @@ -1,4 +1,4 @@ -.TH "NPM\-UNPUBLISH" "1" "January 2021" "" "" +.TH "NPM\-UNPUBLISH" "1" "February 2021" "" "" .SH "NAME" \fBnpm-unpublish\fR \- Remove a package from the registry .SS Synopsis diff --git a/deps/npm/man/man1/npm-unstar.1 b/deps/npm/man/man1/npm-unstar.1 index 70df2998f8825b..f45999e93979af 100644 --- a/deps/npm/man/man1/npm-unstar.1 +++ b/deps/npm/man/man1/npm-unstar.1 @@ -1,4 +1,4 @@ -.TH "NPM\-UNSTAR" "1" "January 2021" "" "" +.TH "NPM\-UNSTAR" "1" "February 2021" "" "" .SH "NAME" \fBnpm-unstar\fR \- Remove an item from your favorite packages .SS Synopsis diff --git a/deps/npm/man/man1/npm-update.1 b/deps/npm/man/man1/npm-update.1 index 7eee932e92c5b0..59f0177187e796 100644 --- a/deps/npm/man/man1/npm-update.1 +++ b/deps/npm/man/man1/npm-update.1 @@ -1,6 +1,6 @@ -.TH "NPM\-UPDATE" "1" "January 2021" "" "" +.TH "NPM\-UPDATE" "1" "February 2021" "" "" .SH "NAME" -\fBnpm-update\fR \- Update a package +\fBnpm-update\fR \- Update packages .SS Synopsis .P .RS 2 @@ -24,22 +24,11 @@ packages\. .P If no package name is specified, all packages in the specified location (global or local) will be updated\. -.P -As of \fBnpm@2\.6\.1\fP, the \fBnpm update\fP will only inspect top\-level packages\. -Prior versions of \fBnpm\fP would also recursively inspect all dependencies\. -To get the old behavior, use \fBnpm \-\-depth 9999 update\fP\|\. -.P -As of \fBnpm@5\.0\.0\fP, the \fBnpm update\fP will change \fBpackage\.json\fP to save the -new version as the minimum required dependency\. To get the old behavior, -use \fBnpm update \-\-no\-save\fP\|\. .SS Example .P -IMPORTANT VERSION NOTE: these examples assume \fBnpm@2\.6\.1\fP or later\. For -older versions of \fBnpm\fP, you must specify \fB\-\-depth 0\fP to get the behavior -described below\. -.P For the examples below, assume that the current package is \fBapp\fP and it depends -on dependencies, \fBdep1\fP (\fBdep2\fP, \.\. etc\.)\. The published versions of \fBdep1\fP are: +on dependencies, \fBdep1\fP (\fBdep2\fP, \.\. etc\.)\. The published versions of \fBdep1\fP +are: .P .RS 2 .nf @@ -85,10 +74,10 @@ However, if \fBapp\fP\|'s \fBpackage\.json\fP contains: .fi .RE .P -In this case, running \fBnpm update\fP will install \fBdep1@1\.1\.2\fP\|\. Even though the \fBlatest\fP -tag points to \fB1\.2\.2\fP, this version does not satisfy \fB~1\.1\.1\fP, which is equivalent -to \fB>=1\.1\.1 <1\.2\.0\fP\|\. So the highest\-sorting version that satisfies \fB~1\.1\.1\fP is used, -which is \fB1\.1\.2\fP\|\. +In this case, running \fBnpm update\fP will install \fBdep1@1\.1\.2\fP\|\. Even though the +\fBlatest\fP tag points to \fB1\.2\.2\fP, this version do not satisfy \fB~1\.1\.1\fP, which is +equivalent to \fB>=1\.1\.1 <1\.2\.0\fP\|\. So the highest\-sorting version that satisfies +\fB~1\.1\.1\fP is used, which is \fB1\.1\.2\fP\|\. .SS Caret Dependencies below 1\.0\.0 .P Suppose \fBapp\fP has a caret dependency on a version below \fB1\.0\.0\fP, for example: @@ -122,7 +111,9 @@ version that satisfies \fB^0\.4\.0\fP (\fB>= 0\.4\.0 <0\.5\.0\fP) package that is \fBoutdated\fP \-\- that is, has a version that is different from \fBwanted\fP\|\. .P -Note: Globally installed packages are treated as if they are installed with a caret semver range specified\. So if you require to update to \fBlatest\fP you may need to run \fBnpm install \-g [\.\.\.]\fP +Note: Globally installed packages are treated as if they are installed with a +caret semver range specified\. So if you require to update to \fBlatest\fP you may +need to run \fBnpm install \-g [\.\.\.]\fP .P NOTE: If a package has been upgraded to a version newer than \fBlatest\fP, it will be \fIdowngraded\fR\|\. diff --git a/deps/npm/man/man1/npm-version.1 b/deps/npm/man/man1/npm-version.1 index aa3a5f1c1ba320..aa47748610c982 100644 --- a/deps/npm/man/man1/npm-version.1 +++ b/deps/npm/man/man1/npm-version.1 @@ -1,4 +1,4 @@ -.TH "NPM\-VERSION" "1" "January 2021" "" "" +.TH "NPM\-VERSION" "1" "February 2021" "" "" .SH "NAME" \fBnpm-version\fR \- Bump a package version .SS Synopsis @@ -96,45 +96,45 @@ Take the following example: .fi .RE .P -This runs all your tests, and proceeds only if they pass\. Then runs your \fBbuild\fP script, and +This runs all your tests and proceeds only if they pass\. Then runs your \fBbuild\fP script, and adds everything in the \fBdist\fP directory to the commit\. After the commit, it pushes the new commit and tag up to the server, and deletes the \fBbuild/temp\fP directory\. .SS Configuration -.SS allow\-same\-version +.SS \fBallow\-same\-version\fP .RS 0 .IP \(bu 2 -Default: false +Default: \fBfalse\fP .IP \(bu 2 Type: Boolean .RE .P -Prevents throwing an error when \fBnpm version\fP is used to set the new version +Prevents throwing an error when \fBnpm version\fP is used to set the new version to the same value as the current version\. -.SS git\-tag\-version +.SS \fBgit\-tag\-version\fP .RS 0 .IP \(bu 2 -Default: true +Default: \fBtrue\fP .IP \(bu 2 Type: Boolean .RE .P Commit and tag the version change\. -.SS commit\-hooks +.SS \fBcommit\-hooks\fP .RS 0 .IP \(bu 2 -Default: true +Default: \fBtrue\fP .IP \(bu 2 Type: Boolean .RE .P Run git commit hooks when committing the version change\. -.SS sign\-git\-tag +.SS \fBsign\-git\-tag\fP .RS 0 .IP \(bu 2 -Default: false +Default: \fBfalse\fP .IP \(bu 2 Type: Boolean @@ -154,8 +154,6 @@ npm help scripts .IP \(bu 2 npm help package\.json .IP \(bu 2 -npm help semver -.IP \(bu 2 npm help config .RE diff --git a/deps/npm/man/man1/npm-view.1 b/deps/npm/man/man1/npm-view.1 index ea6c1ec5db4f6b..b503ea1536656b 100644 --- a/deps/npm/man/man1/npm-view.1 +++ b/deps/npm/man/man1/npm-view.1 @@ -1,4 +1,4 @@ -.TH "NPM\-VIEW" "1" "January 2021" "" "" +.TH "NPM\-VIEW" "1" "February 2021" "" "" .SH "NAME" \fBnpm-view\fR \- View registry info .SS Synopsis @@ -15,8 +15,7 @@ aliases: info, show, v This command shows data about a package and prints it to the stream referenced by the \fBoutfd\fP config, which defaults to stdout\. .P -To show the package registry entry for the \fBconnect\fP package, you can do -this: +As an example, to view information about the \fBconnect\fP package from the registry, you would run: .P .RS 2 .nf @@ -24,11 +23,11 @@ npm view connect .fi .RE .P -The default version is "latest" if unspecified\. +The default version is \fB"latest"\fP if unspecified\. .P Field names can be specified after the package descriptor\. For example, to show the dependencies of the \fBronn\fP package at version -0\.3\.5, you could do the following: +\fB0\.3\.5\fP, you could do the following: .P .RS 2 .nf @@ -37,8 +36,7 @@ npm view ronn@0\.3\.5 dependencies .RE .P You can view child fields by separating them with a period\. -To view the git repository URL for the latest version of npm, you could -do this: +To view the git repository URL for the latest version of \fBnpm\fP, you would run the following command: .P .RS 2 .nf @@ -47,8 +45,8 @@ npm view npm repository\.url .RE .P This makes it easy to view information about a dependency with a bit of -shell scripting\. For example, to view all the data about the version of -opts that ronn depends on, you can do this: +shell scripting\. For example, to view all the data about the version of +\fBopts\fP that \fBronn\fP depends on, you could write the following: .P .RS 2 .nf @@ -57,8 +55,8 @@ npm view opts@$(npm view ronn dependencies\.opts) .RE .P For fields that are arrays, requesting a non\-numeric field will return -all of the values from the objects in the list\. For example, to get all -the contributor names for the "express" project, you can do this: +all of the values from the objects in the list\. For example, to get all +the contributor names for the \fBexpress\fP package, you would run: .P .RS 2 .nf @@ -67,8 +65,8 @@ npm view express contributors\.email .RE .P You may also use numeric indices in square braces to specifically select -an item in an array field\. To just get the email address of the first -contributor in the list, you can do this: +an item in an array field\. To just get the email address of the first +contributor in the list, you can run: .P .RS 2 .nf @@ -87,7 +85,7 @@ npm view express contributors\.name contributors\.email .RE .P "Person" fields are shown as a string if they would be shown as an -object\. So, for example, this will show the list of npm contributors in +object\. So, for example, this will show the list of \fBnpm\fP contributors in the shortened string format\. (See npm help \fBpackage\.json\fP for more on this\.) .P .RS 2 @@ -97,8 +95,8 @@ npm view npm contributors .RE .P If a version range is provided, then data will be printed for every -matching version of the package\. This will show which version of jsdom -was required by each matching version of yui3: +matching version of the package\. This will show which version of \fBjsdom\fP +was required by each matching version of \fByui3\fP: .P .RS 2 .nf @@ -117,15 +115,15 @@ npm view connect versions .SS Output .P If only a single string field for a single version is output, then it -will not be colorized or quoted, so as to enable piping the output to +will not be colorized or quoted, to enable piping the output to another command\. If the field is an object, it will be output as a JavaScript object literal\. .P -If the \-\-json flag is given, the outputted fields will be JSON\. +If the \fB\-\-json\fP flag is given, the outputted fields will be JSON\. .P -If the version range matches multiple versions, than each printed value +If the version range matches multiple versions then each printed value will be prefixed with the version it applies to\. .P -If multiple fields are requested, than each of them are prefixed with +If multiple fields are requested, then each of them is prefixed with the field name\. .SS See Also .RS 0 diff --git a/deps/npm/man/man1/npm-whoami.1 b/deps/npm/man/man1/npm-whoami.1 index dc944670c188e0..0d623e7f1f1e43 100644 --- a/deps/npm/man/man1/npm-whoami.1 +++ b/deps/npm/man/man1/npm-whoami.1 @@ -1,4 +1,4 @@ -.TH "NPM\-WHOAMI" "1" "January 2021" "" "" +.TH "NPM\-WHOAMI" "1" "February 2021" "" "" .SH "NAME" \fBnpm-whoami\fR \- Display npm username .SS Synopsis diff --git a/deps/npm/man/man1/npm.1 b/deps/npm/man/man1/npm.1 index a75dc70db92309..fc76aef29eb231 100644 --- a/deps/npm/man/man1/npm.1 +++ b/deps/npm/man/man1/npm.1 @@ -1,4 +1,4 @@ -.TH "NPM" "1" "January 2021" "" "" +.TH "NPM" "1" "February 2021" "" "" .SH "NAME" \fBnpm\fR \- javascript package manager .SS Synopsis @@ -10,40 +10,46 @@ npm [args] .RE .SS Version .P -7\.4\.3 +7\.5\.1 .SS Description .P npm is the package manager for the Node JavaScript platform\. It puts modules in place so that node can find them, and manages dependency conflicts intelligently\. .P -It is extremely configurable to support a wide variety of use cases\. -Most commonly, it is used to publish, discover, install, and develop node +It is extremely configurable to support a variety of use cases\. Most +commonly, you use it to publish, discover, install, and develop node programs\. .P Run \fBnpm help\fP to get a list of available commands\. .SS Important .P -npm is configured to use npm, Inc\.'s public registry at +npm comes preconfigured to use npm's public registry at https://registry\.npmjs\.org by default\. Use of the npm public registry is -subject to terms of use available at https://www\.npmjs\.com/policies/terms\. +subject to terms of use available at +https://www\.npmjs\.com/policies/terms\. .P -You can configure npm to use any compatible registry you like, and even run -your own registry\. Use of someone else's registry may be governed by their -terms of use\. +You can configure npm to use any compatible registry you like, and even +run your own registry\. Use of someone else's registry is governed by +their terms of use\. .SS Introduction .P You probably got npm because you want to install stuff\. .P -Use \fBnpm install blerg\fP to install the latest version of "blerg"\. Check out -npm help \fBinstall\fP for more info\. It can do a lot of stuff\. +The very first thing you will most likely want to run in any node +program is \fBnpm install\fP to install its dependencies\. .P -Use the \fBnpm search\fP command to show everything that's available\. -Use \fBnpm ls\fP to show everything you've installed\. +You can also run \fBnpm install blerg\fP to install the latest version of +"blerg"\. Check out npm help \fBinstall\fP for more +info\. It can do a lot of stuff\. +.P +Use the \fBnpm search\fP command to show everything that's available in the +public registry\. Use \fBnpm ls\fP to show everything you've installed\. .SS Dependencies .P -If a package references to another package with a git URL, npm depends -on a preinstalled git\. +If a package lists a dependency using a git URL, npm will install that +dependency using the \fBgit\fP \fIhttps://github\.com/git\-guides/install\-git\fR +command and will generate an error if it is not installed\. .P If one of the packages npm tries to install is a native node module and requires compiling of C++ Code, npm will use @@ -57,24 +63,26 @@ the node\-gyp repository \fIhttps://github\.com/nodejs/node\-gyp\fR and the node\-gyp Wiki \fIhttps://github\.com/nodejs/node\-gyp/wiki\fR\|\. .SS Directories .P -See npm help \fBfolders\fP to learn about where npm puts stuff\. +See npm help \fBfolders\fP to learn about where npm puts +stuff\. .P In particular, npm has two modes of operation: .RS 0 .IP \(bu 2 -global mode: -npm installs packages into the install prefix at -\fBprefix/lib/node_modules\fP and bins are installed in \fBprefix/bin\fP\|\. -.IP \(bu 2 local mode: npm installs packages into the current project directory, which -defaults to the current working directory\. Packages are installed to -\fB\|\./node_modules\fP, and bins are installed to \fB\|\./node_modules/\.bin\fP\|\. +defaults to the current working directory\. Packages install to +\fB\|\./node_modules\fP, and bins to \fB\|\./node_modules/\.bin\fP\|\. +.IP \(bu 2 +global mode: +npm installs packages into the install prefix at +\fB$npm_config_prefix/lib/node_modules\fP and bins to +\fB$npm_config_prefix/bin\fP\|\. .RE .P Local mode is the default\. Use \fB\-g\fP or \fB\-\-global\fP on any command to -operate in global mode instead\. +run in global mode instead\. .SS Developer Usage .P If you're using npm to develop and publish your code, check out the @@ -82,24 +90,26 @@ following help topics: .RS 0 .IP \(bu 2 json: -Make a package\.json file\. See npm help \fBpackage\.json\fP\|\. +Make a package\.json file\. See +npm help \fBpackage\.json\fP\|\. .IP \(bu 2 link: -For linking your current working code into Node's path, so that you -don't have to reinstall every time you make a change\. Use -\fBnpm link\fP to do this\. +Links your current working code into Node's path, so that you don't +have to reinstall every time you make a change\. Use npm help \fBnpm +link\fP to do this\. .IP \(bu 2 install: -It's a good idea to install things if you don't need the symbolic link\. -Especially, installing other peoples code from the registry is done via -\fBnpm install\fP +It's a good idea to install things if you don't need the symbolic +link\. Especially, installing other peoples code from the registry is +done via npm help \fBinstall\fP .IP \(bu 2 adduser: -Create an account or log in\. Credentials are stored in the -user config file\. +Create an account or log in\. When you do this, npm will store +credentials in the user config file config file\. .IP \(bu 2 publish: -Use the \fBnpm publish\fP command to upload your code to the registry\. +Use the npm help \fBpublish\fP command to upload your +code to the registry\. .RE .SS Configuration @@ -111,23 +121,23 @@ npm is extremely configurable\. It reads its configuration options from Command line switches: Set a config with \fB\-\-key val\fP\|\. All keys take a value, even if they are booleans (the config parser doesn't know what the options are at -the time of parsing)\. If no value is provided, then the option is set -to boolean \fBtrue\fP\|\. +the time of parsing)\. If you do not provide a value (\fB\-\-key\fP) then +the option is set to boolean \fBtrue\fP\|\. .IP \(bu 2 Environment Variables: Set any config by prefixing the name in an environment variable with \fBnpm_config_\fP\|\. For example, \fBexport npm_config_key=val\fP\|\. .IP \(bu 2 User Configs: -The file at $HOME/\.npmrc is an ini\-formatted list of configs\. If +The file at \fB$HOME/\.npmrc\fP is an ini\-formatted list of configs\. If present, it is parsed\. If the \fBuserconfig\fP option is set in the cli -or env, then that will be used instead\. +or env, that file will be used instead\. .IP \(bu 2 Global Configs: -The file found at \.\./etc/npmrc (from the node executable, by default -this resolves to /usr/local/etc/npmrc) will be parsed if it is found\. -If the \fBglobalconfig\fP option is set in the cli, env, or user config, -then that file is parsed instead\. +The file found at \fB\|\./etc/npmrc\fP (relative to the global prefix will be +parsed if it is found\. See npm help \fBprefix\fP for +more info on the global prefix\. If the \fBglobalconfig\fP option is set +in the cli, env, or user config, then that file is parsed instead\. .IP \(bu 2 Defaults: npm's default configuration options are defined in @@ -140,14 +150,16 @@ See npm help \fBconfig\fP for much much more information\. .P Patches welcome! .P -If you would like to contribute, but don't know what to work on, read -the contributing guidelines \fIhttps://github\.com/npm/cli/blob/latest/CONTRIBUTING\.md\fR -and check the issues list\. +If you would like to help, but don't know what to work on, read the +contributing +guidelines \fIhttps://github\.com/npm/cli/blob/latest/CONTRIBUTING\.md\fR and +check the issues list\. .SS Bugs .P -When you find issues, please report them: https://github\.com/npm/cli/issues +When you find issues, please report them: +https://github\.com/npm/cli/issues .P -Be sure to follow the template and bug reporting guidelines\. +Please be sure to follow the template and bug reporting guidelines\. .SS Feature Requests .P Discuss new feature ideas on our discussion forum: @@ -170,10 +182,14 @@ npm help help .IP \(bu 2 npm help package\.json .IP \(bu 2 -npm help install +npm help npmrc .IP \(bu 2 npm help config .IP \(bu 2 -npm help npmrc +npm help install +.IP \(bu 2 +npm help prefix +.IP \(bu 2 +npm help publish .RE diff --git a/deps/npm/man/man1/npx.1 b/deps/npm/man/man1/npx.1 index a6535f3e54680a..4de1c3ddf6b5c0 100644 --- a/deps/npm/man/man1/npx.1 +++ b/deps/npm/man/man1/npx.1 @@ -1,4 +1,4 @@ -.TH "NPX" "1" "January 2021" "" "" +.TH "NPX" "1" "February 2021" "" "" .SH "NAME" \fBnpx\fR \- Run a command from a local or remote npm package .SS Synopsis diff --git a/deps/npm/man/man5/folders.5 b/deps/npm/man/man5/folders.5 index 8ba0a19d9d33a0..89df00b19d48a1 100644 --- a/deps/npm/man/man5/folders.5 +++ b/deps/npm/man/man5/folders.5 @@ -1,4 +1,4 @@ -.TH "FOLDERS" "5" "January 2021" "" "" +.TH "FOLDERS" "5" "February 2021" "" "" .SH "NAME" \fBfolders\fR \- Folder Structures Used by npm .SS Description diff --git a/deps/npm/man/man5/install.5 b/deps/npm/man/man5/install.5 index d01600aa8d769a..106ca58a2fe800 100644 --- a/deps/npm/man/man5/install.5 +++ b/deps/npm/man/man5/install.5 @@ -1,4 +1,4 @@ -.TH "INSTALL" "5" "January 2021" "" "" +.TH "INSTALL" "5" "February 2021" "" "" .SH "NAME" \fBinstall\fR \- Download and install node and npm .SS Description diff --git a/deps/npm/man/man5/npm-shrinkwrap-json.5 b/deps/npm/man/man5/npm-shrinkwrap-json.5 index 7f8012e847099f..12c366e6eef89f 100644 --- a/deps/npm/man/man5/npm-shrinkwrap-json.5 +++ b/deps/npm/man/man5/npm-shrinkwrap-json.5 @@ -1,4 +1,4 @@ -.TH "NPM\-SHRINKWRAP\.JSON" "5" "January 2021" "" "" +.TH "NPM\-SHRINKWRAP\.JSON" "5" "February 2021" "" "" .SH "NAME" \fBnpm-shrinkwrap.json\fR \- A publishable lockfile .SS Description diff --git a/deps/npm/man/man5/npmrc.5 b/deps/npm/man/man5/npmrc.5 index baf2fe3e5d9078..410f4e4ea89799 100644 --- a/deps/npm/man/man5/npmrc.5 +++ b/deps/npm/man/man5/npmrc.5 @@ -1,4 +1,4 @@ -.TH "NPMRC" "5" "January 2021" "" "" +.TH "NPMRC" "5" "February 2021" "" "" .SH "NAME" \fBnpmrc\fR \- The npm config files .SS Description diff --git a/deps/npm/man/man5/package-json.5 b/deps/npm/man/man5/package-json.5 index 79ebabc5eec228..cfe8eb3c6d7f56 100644 --- a/deps/npm/man/man5/package-json.5 +++ b/deps/npm/man/man5/package-json.5 @@ -1,4 +1,4 @@ -.TH "PACKAGE\.JSON" "5" "January 2021" "" "" +.TH "PACKAGE\.JSON" "5" "February 2021" "" "" .SH "NAME" \fBpackage.json\fR \- Specifics of npm's package\.json handling .SS Description @@ -69,8 +69,6 @@ version fields are optional\. Version must be parseable by node\-semver \fIhttps://github\.com/npm/node\-semver\fR, which is bundled with npm as a dependency\. (\fBnpm install semver\fP to use it yourself\.) -.P -More on version numbers and ranges at npm help semver\. .SS description .P Put a description in it\. It's a string\. This helps people discover your @@ -622,8 +620,8 @@ tarball or git URL\. \fBPlease do not put test harnesses or transpilers or other "development" time tools in your \fBdependencies\fP object\.\fR See \fBdevDependencies\fP, below\. .P -See npm help semver for more details about specifying version -ranges\. +See semver \fI[/using\-npm/semver](https://github\.com/npm/node\-semver#versions)\fR +for more details about specifying version ranges\. .RS 0 .IP \(bu 2 \fBversion\fP Must match \fBversion\fP exactly @@ -637,9 +635,9 @@ ranges\. \fB<=version\fP .IP \(bu 2 \fB~version\fP "Approximately equivalent to version" See -npm help semver +semver \fIhttps://github\.com/npm/node\-semver#versions\fR .IP \(bu 2 -\fB^version\fP "Compatible with version" See npm help semver +\fB^version\fP "Compatible with version" See semver \fIhttps://github\.com/npm/node\-semver#versions\fR .IP \(bu 2 \fB1\.2\.x\fP 1\.2\.0, 1\.2\.1, etc\., but not 1\.3\.0 .IP \(bu 2 @@ -1126,7 +1124,7 @@ optional\. Lines which start with a \fB#\fP or are blank, will be ignored\. .SS SEE ALSO .RS 0 .IP \(bu 2 -npm help semver +semver \fIhttps://github\.com/npm/node\-semver#versions\fR .IP \(bu 2 npm help workspaces .IP \(bu 2 diff --git a/deps/npm/man/man5/package-lock-json.5 b/deps/npm/man/man5/package-lock-json.5 index 453c0105cb0bad..f1e82de0a89457 100644 --- a/deps/npm/man/man5/package-lock-json.5 +++ b/deps/npm/man/man5/package-lock-json.5 @@ -1,4 +1,4 @@ -.TH "PACKAGE\-LOCK\.JSON" "5" "January 2021" "" "" +.TH "PACKAGE\-LOCK\.JSON" "5" "February 2021" "" "" .SH "NAME" \fBpackage-lock.json\fR \- A manifestation of the manifest .SS Description diff --git a/deps/npm/man/man7/config.7 b/deps/npm/man/man7/config.7 index c6235e825d08bc..c2cb63e08976d0 100644 --- a/deps/npm/man/man7/config.7 +++ b/deps/npm/man/man7/config.7 @@ -1,4 +1,4 @@ -.TH "CONFIG" "7" "January 2021" "" "" +.TH "CONFIG" "7" "February 2021" "" "" .SH "NAME" \fBconfig\fR \- More than you probably want to know about npm configuration .SS Description @@ -498,6 +498,88 @@ only report what it would have done\. This can be passed into any of the commands that modify your local installation, eg, \fBinstall\fP, \fBupdate\fP, \fBdedupe\fP, \fBuninstall\fP\|\. This is NOT currently honored by some network related commands, eg \fBdist\-tags\fP, \fBowner\fP, etc\. +.SS diff +.RS 0 +.IP \(bu 2 +Default: null +.IP \(bu 2 +Type: String, Array, null + +.RE +.P +Define arguments to compare in \fBnpm diff\fP\|\. +.SS diff\-name\-only +.RS 0 +.IP \(bu 2 +Default: false +.IP \(bu 2 +Type: Boolean + +.RE +.P +Prints only filenames when using \fBnpm diff\fP\|\. +.SS diff\-unified +.RS 0 +.IP \(bu 2 +Type: number +.IP \(bu 2 +Default: \fB3\fP + +.RE +.P +The number of lines of context to print in \fBnpm diff\fP\|\. +.SS diff\-ignore\-all\-space +.RS 0 +.IP \(bu 2 +Type: Boolean +.IP \(bu 2 +Default: false + +.RE +.P +Ignore whitespace when comparing lines in `npm diff\. +.SS diff\-no\-prefix +.RS 0 +.IP \(bu 2 +Type: Boolean +.IP \(bu 2 +Default: false + +.RE +.P +Do not show any source or destination prefix in \fBnpm diff\fP output\. +.SS diff\-src\-prefix +.RS 0 +.IP \(bu 2 +Type: String +.IP \(bu 2 +Default: \fB"a/"\fP + +.RE +.P +Source prefix to be used in \fBnpm diff\fP output\. +.SS diff\-dst\-prefix +.RS 0 +.IP \(bu 2 +Type: String +.IP \(bu 2 +Default: \fB"b/"\fP + +.RE +.P +Destination prefix to be used in \fBnpm diff\fP output\. +.SS diff\-text +.RS 0 +.IP \(bu 2 +Alias: \fB\-a\fP +.IP \(bu 2 +Type: Boolean +.IP \(bu 2 +Default: false + +.RE +.P +Treat all files as text in \fBnpm diff\fP\|\. .SS editor .RS 0 .IP \(bu 2 @@ -552,6 +634,8 @@ range (including SemVer\-major changes)\. Allow a module to be installed as a direct dependency of itself\. .IP \(bu 2 Allow unpublishing all versions of a published package\. +.IP \(bu 2 +Allow conflicting peerDependencies to be installed in the root project\. .RE .P diff --git a/deps/npm/man/man7/developers.7 b/deps/npm/man/man7/developers.7 index fbe0a455020d74..e371508a0dc239 100644 --- a/deps/npm/man/man7/developers.7 +++ b/deps/npm/man/man7/developers.7 @@ -1,4 +1,4 @@ -.TH "DEVELOPERS" "7" "January 2021" "" "" +.TH "DEVELOPERS" "7" "February 2021" "" "" .SH "NAME" \fBdevelopers\fR \- Developer Guide .SS Description diff --git a/deps/npm/man/man7/disputes.7 b/deps/npm/man/man7/disputes.7 deleted file mode 100644 index 8ef02443c9c9bd..00000000000000 --- a/deps/npm/man/man7/disputes.7 +++ /dev/null @@ -1,149 +0,0 @@ -.TH "DISPUTES" "7" "January 2021" "" "" -.SH "NAME" -\fBdisputes\fR \- Handling Module Name Disputes -.P -This document describes the steps that you should take to resolve module name -disputes with other npm publishers\. It also describes special steps you should -take about names you think infringe your trademarks\. -.P -This document is a clarification of the acceptable behavior outlined in the -npm Code of Conduct \fIhttps://www\.npmjs\.com/policies/conduct\fR, and nothing in -this document should be interpreted to contradict any aspect of the npm Code of -Conduct\. -.SS TL;DR -.RS 0 -.IP 1. 3 -Get the author email with \fBnpm owner ls \fP -.IP 2. 3 -Email the author, CC support@npmjs\.com -.IP 3. 3 -After a few weeks, if there's no resolution, we'll sort it out\. - -.RE -.P -Don't squat on package names\. Publish code or move out of the way\. -.SS Description -.P -There sometimes arise cases where a user publishes a module, and then later, -some other user wants to use that name\. Here are some common ways that happens -(each of these is based on actual events\.) -.RS 0 -.IP 1. 3 -Alice writes a JavaScript module \fBfoo\fP, which is not node\-specific\. Alice -doesn't use node at all\. Yusuf wants to use \fBfoo\fP in node, so he wraps it in -an npm module\. Some time later, Alice starts using node, and wants to take -over management of her program\. -.IP 2. 3 -Yusuf writes an npm module \fBfoo\fP, and publishes it\. Perhaps much later, Alice -finds a bug in \fBfoo\fP, and fixes it\. She sends a pull request to Yusuf, but -Yusuf doesn't have the time to deal with it, because he has a new job and a -new baby and is focused on his new Erlang project, and kind of not involved -with node any more\. Alice would like to publish a new \fBfoo\fP, but can't, -because the name is taken\. -.IP 3. 3 -Yusuf writes a 10\-line flow\-control library, and calls it \fBfoo\fP, and -publishes it to the npm registry\. Being a simple little thing, it never -really has to be updated\. Alice works for Foo Inc, the makers of the -critically acclaimed and widely\-marketed \fBfoo\fP JavaScript toolkit framework\. -They publish it to npm as \fBfoojs\fP, but people are routinely confused when -\fBnpm install foo\fP is some different thing\. -.IP 4. 3 -Yusuf writes a parser for the widely\-known \fBfoo\fP file format, because he -needs it for work\. Then, he gets a new job, and never updates the prototype\. -Later on, Alice writes a much more complete \fBfoo\fP parser, but can't publish, -because Yusuf's \fBfoo\fP is in the way\. -.IP 5. 3 -\fBnpm owner ls foo\fP\|\. This will tell Alice the email address of the owner -(Yusuf)\. -.IP 6. 3 -Alice emails Yusuf, explaining the situation \fBas respectfully as possible\fR, -and what she would like to do with the module name\. She adds the npm support -staff support@npmjs\.com to the CC list of the email\. Mention in the email -that Yusuf can run npm owner \fBadd alice foo\fP to add Alice as an owner of the -foo package\. -.IP 7. 3 -After a reasonable amount of time, if Yusuf has not responded, or if Yusuf -and Alice can't come to any sort of resolution, email support -support@npmjs\.com and we'll sort it out\. ("Reasonable" is usually at least -4 weeks\.) - -.RE -.SS Reasoning -.P -In almost every case so far, the parties involved have been able to reach an -amicable resolution without any major intervention\. Most people really do want -to be reasonable, and are probably not even aware that they're in your way\. -.P -Module ecosystems are most vibrant and powerful when they are as self\-directed -as possible\. If an admin one day deletes something you had worked on, then that -is going to make most people quite upset, regardless of the justification\. When -humans solve their problems by talking to other humans with respect, everyone -has the chance to end up feeling good about the interaction\. -.SS Exceptions -.P -Some things are not allowed, and will be removed without discussion if they are -brought to the attention of the npm registry admins, including but not limited -to: -.RS 0 -.IP 1. 3 -Malware (that is, a package designed to exploit or harm the machine on which -it is installed)\. -.IP 2. 3 -Violations of copyright or licenses (for example, cloning an MIT\-licensed -program, and then removing or changing the copyright and license statement)\. -.IP 3. 3 -Illegal content\. -.IP 4. 3 -"Squatting" on a package name that you plan to use, but aren't actually -using\. Sorry, I don't care how great the name is, or how perfect a fit it is -for the thing that someday might happen\. If someone wants to use it today, -and you're just taking up space with an empty tarball, you're going to be -evicted\. -.IP 5. 3 -Putting empty packages in the registry\. Packages must have SOME -functionality\. It can be silly, but it can't be nothing\. (See also: -squatting\.) -.IP 6. 3 -Doing weird things with the registry, like using it as your own personal -application database or otherwise putting non\-packagey things into it\. -.IP 7. 3 -Other things forbidden by the npm -Code of Conduct \fIhttps://www\.npmjs\.com/policies/conduct\fR such as hateful -language, pornographic content, or harassment\. - -.RE -.P -If you see bad behavior like this, please report it to abuse@npmjs\.com right -away\. \fBYou are never expected to resolve abusive behavior on your own\. We are -here to help\.\fR -.SS Trademarks -.P -If you think another npm publisher is infringing your trademark, such as by -using a confusingly similar package name, email abuse@npmjs\.com with a link to -the package or user account on https://www\.npmjs\.com/ \fIhttps://www\.npmjs\.com/\fR\|\. -Attach a copy of your trademark registration certificate\. -.P -If we see that the package's publisher is intentionally misleading others by -misusing your registered mark without permission, we will transfer the package -name to you\. Otherwise, we will contact the package publisher and ask them to -clear up any confusion with changes to their package's \fBREADME\fP file or -metadata\. -.SS Changes -.P -This is a living document and may be updated from time to time\. Please refer to -the git history for this document \fIhttps://github\.com/npm/cli/commits/latest/doc/misc/npm\-disputes\.md\fR -to view the changes\. -.SS License -.P -Copyright (C) npm, Inc\., All rights reserved -.P -This document may be reused under a Creative Commons Attribution\-ShareAlike -License\. -.SS See also -.RS 0 -.IP \(bu 2 -npm help registry -.IP \(bu 2 -npm help owner - -.RE diff --git a/deps/npm/man/man7/orgs.7 b/deps/npm/man/man7/orgs.7 index b2be9c387f6dc2..f8bcbf808ad3be 100644 --- a/deps/npm/man/man7/orgs.7 +++ b/deps/npm/man/man7/orgs.7 @@ -1,4 +1,4 @@ -.TH "ORGS" "7" "January 2021" "" "" +.TH "ORGS" "7" "February 2021" "" "" .SH "NAME" \fBorgs\fR \- Working with Teams & Orgs .SS Description diff --git a/deps/npm/man/man7/registry.7 b/deps/npm/man/man7/registry.7 index c72c1168ff4ff9..68c6f7b0e4b2fc 100644 --- a/deps/npm/man/man7/registry.7 +++ b/deps/npm/man/man7/registry.7 @@ -1,4 +1,4 @@ -.TH "REGISTRY" "7" "January 2021" "" "" +.TH "REGISTRY" "7" "February 2021" "" "" .SH "NAME" \fBregistry\fR \- The JavaScript Package Registry .SS Description @@ -7,7 +7,7 @@ To resolve packages by name and version, npm talks to a registry website that implements the CommonJS Package Registry specification for reading package info\. .P -npm is configured to use npm, Inc\.'s public registry at +npm is configured to use the \fBnpm public registry\fR at https://registry\.npmjs\.org by default\. Use of the npm public registry is subject to terms of use available at https://www\.npmjs\.com/policies/terms\|\. .P @@ -20,9 +20,7 @@ write APIs as well, to allow for publishing packages and managing user account information\. .P The npm public registry is powered by a CouchDB database, -of which there is a public mirror at -https://skimdb\.npmjs\.com/registry\|\. The code for the couchapp is -available at https://github\.com/npm/npm\-registry\-couchapp\|\. +of which there is a public mirror at https://skimdb\.npmjs\.com/registry\|\. .P The registry URL used is determined by the scope of the package (see npm help \fBscope\fP\|\. If no scope is specified, the default registry is used, which is @@ -54,40 +52,17 @@ build farms\. .P The npm registry does not try to correlate the information in these headers with any authenticated accounts that may be used in the same requests\. -.SS Can I run my own private registry? +.SS How can I prevent my package from being published in the official registry? .P -Yes! -.P -The easiest way is to replicate the couch database, and use the same (or -similar) design doc to implement the APIs\. -.P -If you set up continuous replication from the official CouchDB, and then -set your internal CouchDB as the registry config, then you'll be able -to read any published packages, in addition to your private ones, and by -default will only publish internally\. -.P -If you then want to publish a package for the whole world to see, you can -simply override the \fB\-\-registry\fP option for that \fBpublish\fP command\. -.SS I don't want my package published in the official registry\. It's private\. -.P -Set \fB"private": true\fP in your package\.json to prevent it from being +Set \fB"private": true\fP in your \fBpackage\.json\fP to prevent it from being published at all, or \fB"publishConfig":{"registry":"http://my\-internal\-registry\.local"}\fP -to force it to be published only to your internal registry\. +to force it to be published only to your internal/private registry\. .P See npm help \fBpackage\.json\fP for more info on what goes in the package\.json file\. -.SS Will you replicate from my registry into the public one? +.SS Where can I find my own, & other's, published packages? .P -No\. If you want things to be public, then publish them into the public -registry using npm\. What little security there is would be for nought -otherwise\. -.SS Do I have to use couchdb to build a registry that npm can talk to? -.P -No, but it's way easier\. Basically, yes, you do, or you have to -effectively implement the entire CouchDB API anyway\. -.SS Is there a website or something to see package docs and such? -.P -Yes, head over to https://www\.npmjs\.com/ +https://www\.npmjs\.com/ .SS See also .RS 0 .IP \(bu 2 @@ -98,7 +73,5 @@ npm help config npm help npmrc .IP \(bu 2 npm help developers -.IP \(bu 2 -npm help disputes .RE diff --git a/deps/npm/man/man7/removal.7 b/deps/npm/man/man7/removal.7 index 3f6d0187c87459..e0c1cd68facac4 100644 --- a/deps/npm/man/man7/removal.7 +++ b/deps/npm/man/man7/removal.7 @@ -1,4 +1,4 @@ -.TH "REMOVAL" "7" "January 2021" "" "" +.TH "REMOVAL" "7" "February 2021" "" "" .SH "NAME" \fBremoval\fR \- Cleaning the Slate .SS Synopsis @@ -63,8 +63,6 @@ modules\. To track those down, you can do the following: find /usr/local/{lib/node,bin} \-exec grep \-l npm \\{\\} \\; ; .fi .RE -.P -(This is also in the README file\.) .SS See also .RS 0 .IP \(bu 2 diff --git a/deps/npm/man/man7/scope.7 b/deps/npm/man/man7/scope.7 index fcbff4d89247c3..c7e3b9d93a701c 100644 --- a/deps/npm/man/man7/scope.7 +++ b/deps/npm/man/man7/scope.7 @@ -1,4 +1,4 @@ -.TH "SCOPE" "7" "January 2021" "" "" +.TH "SCOPE" "7" "February 2021" "" "" .SH "NAME" \fBscope\fR \- Scoped packages .SS Description diff --git a/deps/npm/man/man7/scripts.7 b/deps/npm/man/man7/scripts.7 index b00c208140b07f..1e027539873511 100644 --- a/deps/npm/man/man7/scripts.7 +++ b/deps/npm/man/man7/scripts.7 @@ -1,4 +1,4 @@ -.TH "SCRIPTS" "7" "January 2021" "" "" +.TH "SCRIPTS" "7" "February 2021" "" "" .SH "NAME" \fBscripts\fR \- How npm handles the "scripts" field .SS Description diff --git a/deps/npm/man/man7/semver.7 b/deps/npm/man/man7/semver.7 deleted file mode 100644 index 1a271545d1e18a..00000000000000 --- a/deps/npm/man/man7/semver.7 +++ /dev/null @@ -1,510 +0,0 @@ -.TH "SEMVER" "7" "January 2021" "" "" -.SH "NAME" -\fBsemver\fR \- The semantic versioner for npm -.SH Install -.P -.RS 2 -.nf -npm install \-\-save semver -.fi -.RE -.SH Usage -.P -As a node module: -.P -.RS 2 -.nf -const semver = require('semver') - -semver\.valid('1\.2\.3') // '1\.2\.3' -semver\.valid('a\.b\.c') // null -semver\.clean(' =v1\.2\.3 ') // '1\.2\.3' -semver\.satisfies('1\.2\.3', '1\.x || >=2\.5\.0 || 5\.0\.0 \- 7\.2\.3') // true -semver\.gt('1\.2\.3', '9\.8\.7') // false -semver\.lt('1\.2\.3', '9\.8\.7') // true -semver\.minVersion('>=1\.0\.0') // '1\.0\.0' -semver\.valid(semver\.coerce('v2')) // '2\.0\.0' -semver\.valid(semver\.coerce('42\.6\.7\.9\.3\-alpha')) // '42\.6\.7' -.fi -.RE -.P -As a command\-line utility: -.P -.RS 2 -.nf -$ semver \-h - -A JavaScript implementation of the https://semver\.org/ specification -Copyright Isaac Z\. Schlueter - -Usage: semver [options] [ [\.\.\.]] -Prints valid versions sorted by SemVer precedence - -Options: -\-r \-\-range - Print versions that match the specified range\. - -\-i \-\-increment [] - Increment a version by the specified level\. Level can - be one of: major, minor, patch, premajor, preminor, - prepatch, or prerelease\. Default level is 'patch'\. - Only one version may be specified\. - -\-\-preid - Identifier to be used to prefix premajor, preminor, - prepatch or prerelease version increments\. - -\-l \-\-loose - Interpret versions and ranges loosely - -\-p \-\-include\-prerelease - Always include prerelease versions in range matching - -\-c \-\-coerce - Coerce a string into SemVer if possible - (does not imply \-\-loose) - -Program exits successfully if any valid version satisfies -all supplied ranges, and prints all satisfying versions\. - -If no satisfying versions are found, then exits failure\. - -Versions are printed in ascending order, so supplying -multiple versions to the utility will just sort them\. -.fi -.RE -.SH Versions -.P -A "version" is described by the \fBv2\.0\.0\fP specification found at -https://semver\.org/\|\. -.P -A leading \fB"="\fP or \fB"v"\fP character is stripped off and ignored\. -.SH Ranges -.P -A \fBversion range\fP is a set of \fBcomparators\fP which specify versions -that satisfy the range\. -.P -A \fBcomparator\fP is composed of an \fBoperator\fP and a \fBversion\fP\|\. The set -of primitive \fBoperators\fP is: -.RS 0 -.IP \(bu 2 -\fB<\fP Less than -.IP \(bu 2 -\fB<=\fP Less than or equal to -.IP \(bu 2 -\fB>\fP Greater than -.IP \(bu 2 -\fB>=\fP Greater than or equal to -.IP \(bu 2 -\fB=\fP Equal\. If no operator is specified, then equality is assumed, -so this operator is optional, but MAY be included\. - -.RE -.P -For example, the comparator \fB>=1\.2\.7\fP would match the versions -\fB1\.2\.7\fP, \fB1\.2\.8\fP, \fB2\.5\.3\fP, and \fB1\.3\.9\fP, but not the versions \fB1\.2\.6\fP -or \fB1\.1\.0\fP\|\. -.P -Comparators can be joined by whitespace to form a \fBcomparator set\fP, -which is satisfied by the \fBintersection\fR of all of the comparators -it includes\. -.P -A range is composed of one or more comparator sets, joined by \fB||\fP\|\. A -version matches a range if and only if every comparator in at least -one of the \fB||\fP\-separated comparator sets is satisfied by the version\. -.P -For example, the range \fB>=1\.2\.7 <1\.3\.0\fP would match the versions -\fB1\.2\.7\fP, \fB1\.2\.8\fP, and \fB1\.2\.99\fP, but not the versions \fB1\.2\.6\fP, \fB1\.3\.0\fP, -or \fB1\.1\.0\fP\|\. -.P -The range \fB1\.2\.7 || >=1\.2\.9 <2\.0\.0\fP would match the versions \fB1\.2\.7\fP, -\fB1\.2\.9\fP, and \fB1\.4\.6\fP, but not the versions \fB1\.2\.8\fP or \fB2\.0\.0\fP\|\. -.SS Prerelease Tags -.P -If a version has a prerelease tag (for example, \fB1\.2\.3\-alpha\.3\fP) then -it will only be allowed to satisfy comparator sets if at least one -comparator with the same \fB[major, minor, patch]\fP tuple also has a -prerelease tag\. -.P -For example, the range \fB>1\.2\.3\-alpha\.3\fP would be allowed to match the -version \fB1\.2\.3\-alpha\.7\fP, but it would \fInot\fR be satisfied by -\fB3\.4\.5\-alpha\.9\fP, even though \fB3\.4\.5\-alpha\.9\fP is technically "greater -than" \fB1\.2\.3\-alpha\.3\fP according to the SemVer sort rules\. The version -range only accepts prerelease tags on the \fB1\.2\.3\fP version\. The -version \fB3\.4\.5\fP \fIwould\fR satisfy the range, because it does not have a -prerelease flag, and \fB3\.4\.5\fP is greater than \fB1\.2\.3\-alpha\.7\fP\|\. -.P -The purpose for this behavior is twofold\. First, prerelease versions -frequently are updated very quickly, and contain many breaking changes -that are (by the author's design) not yet fit for public consumption\. -Therefore, by default, they are excluded from range matching -semantics\. -.P -Second, a user who has opted into using a prerelease version has -clearly indicated the intent to use \fIthat specific\fR set of -alpha/beta/rc versions\. By including a prerelease tag in the range, -the user is indicating that they are aware of the risk\. However, it -is still not appropriate to assume that they have opted into taking a -similar risk on the \fInext\fR set of prerelease versions\. -.P -Note that this behavior can be suppressed (treating all prerelease -versions as if they were normal versions, for the purpose of range -matching) by setting the \fBincludePrerelease\fP flag on the options -object to any -functions \fIhttps://github\.com/npm/node\-semver#functions\fR that do -range matching\. -.SS Prerelease Identifiers -.P -The method \fB\|\.inc\fP takes an additional \fBidentifier\fP string argument that -will append the value of the string as a prerelease identifier: -.P -.RS 2 -.nf -semver\.inc('1\.2\.3', 'prerelease', 'beta') -// '1\.2\.4\-beta\.0' -.fi -.RE -.P -command\-line example: -.P -.RS 2 -.nf -$ semver 1\.2\.3 \-i prerelease \-\-preid beta -1\.2\.4\-beta\.0 -.fi -.RE -.P -Which then can be used to increment further: -.P -.RS 2 -.nf -$ semver 1\.2\.4\-beta\.0 \-i prerelease -1\.2\.4\-beta\.1 -.fi -.RE -.SS Advanced Range Syntax -.P -Advanced range syntax desugars to primitive comparators in -deterministic ways\. -.P -Advanced ranges may be combined in the same way as primitive -comparators using white space or \fB||\fP\|\. -.SS Hyphen Ranges \fBX\.Y\.Z \- A\.B\.C\fP -.P -Specifies an inclusive set\. -.RS 0 -.IP \(bu 2 -\fB1\.2\.3 \- 2\.3\.4\fP := \fB>=1\.2\.3 <=2\.3\.4\fP - -.RE -.P -If a partial version is provided as the first version in the inclusive -range, then the missing pieces are replaced with zeroes\. -.RS 0 -.IP \(bu 2 -\fB1\.2 \- 2\.3\.4\fP := \fB>=1\.2\.0 <=2\.3\.4\fP - -.RE -.P -If a partial version is provided as the second version in the -inclusive range, then all versions that start with the supplied parts -of the tuple are accepted, but nothing that would be greater than the -provided tuple parts\. -.RS 0 -.IP \(bu 2 -\fB1\.2\.3 \- 2\.3\fP := \fB>=1\.2\.3 <2\.4\.0\fP -.IP \(bu 2 -\fB1\.2\.3 \- 2\fP := \fB>=1\.2\.3 <3\.0\.0\fP - -.RE -.SS X\-Ranges \fB1\.2\.x\fP \fB1\.X\fP \fB1\.2\.*\fP \fB*\fP -.P -Any of \fBX\fP, \fBx\fP, or \fB*\fP may be used to "stand in" for one of the -numeric values in the \fB[major, minor, patch]\fP tuple\. -.RS 0 -.IP \(bu 2 -\fB*\fP := \fB>=0\.0\.0\fP (Any version satisfies) -.IP \(bu 2 -\fB1\.x\fP := \fB>=1\.0\.0 <2\.0\.0\fP (Matching major version) -.IP \(bu 2 -\fB1\.2\.x\fP := \fB>=1\.2\.0 <1\.3\.0\fP (Matching major and minor versions) - -.RE -.P -A partial version range is treated as an X\-Range, so the special -character is in fact optional\. -.RS 0 -.IP \(bu 2 -\fB""\fP (empty string) := \fB*\fP := \fB>=0\.0\.0\fP -.IP \(bu 2 -\fB1\fP := \fB1\.x\.x\fP := \fB>=1\.0\.0 <2\.0\.0\fP -.IP \(bu 2 -\fB1\.2\fP := \fB1\.2\.x\fP := \fB>=1\.2\.0 <1\.3\.0\fP - -.RE -.SS Tilde Ranges \fB~1\.2\.3\fP \fB~1\.2\fP \fB~1\fP -.P -Allows patch\-level changes if a minor version is specified on the -comparator\. Allows minor\-level changes if not\. -.RS 0 -.IP \(bu 2 -\fB~1\.2\.3\fP := \fB>=1\.2\.3 <1\.(2+1)\.0\fP := \fB>=1\.2\.3 <1\.3\.0\fP -.IP \(bu 2 -\fB~1\.2\fP := \fB>=1\.2\.0 <1\.(2+1)\.0\fP := \fB>=1\.2\.0 <1\.3\.0\fP (Same as \fB1\.2\.x\fP) -.IP \(bu 2 -\fB~1\fP := \fB>=1\.0\.0 <(1+1)\.0\.0\fP := \fB>=1\.0\.0 <2\.0\.0\fP (Same as \fB1\.x\fP) -.IP \(bu 2 -\fB~0\.2\.3\fP := \fB>=0\.2\.3 <0\.(2+1)\.0\fP := \fB>=0\.2\.3 <0\.3\.0\fP -.IP \(bu 2 -\fB~0\.2\fP := \fB>=0\.2\.0 <0\.(2+1)\.0\fP := \fB>=0\.2\.0 <0\.3\.0\fP (Same as \fB0\.2\.x\fP) -.IP \(bu 2 -\fB~0\fP := \fB>=0\.0\.0 <(0+1)\.0\.0\fP := \fB>=0\.0\.0 <1\.0\.0\fP (Same as \fB0\.x\fP) -.IP \(bu 2 -\fB~1\.2\.3\-beta\.2\fP := \fB>=1\.2\.3\-beta\.2 <1\.3\.0\fP Note that prereleases in -the \fB1\.2\.3\fP version will be allowed, if they are greater than or -equal to \fBbeta\.2\fP\|\. So, \fB1\.2\.3\-beta\.4\fP would be allowed, but -\fB1\.2\.4\-beta\.2\fP would not, because it is a prerelease of a -different \fB[major, minor, patch]\fP tuple\. - -.RE -.SS Caret Ranges \fB^1\.2\.3\fP \fB^0\.2\.5\fP \fB^0\.0\.4\fP -.P -Allows changes that do not modify the left\-most non\-zero digit in the -\fB[major, minor, patch]\fP tuple\. In other words, this allows patch and -minor updates for versions \fB1\.0\.0\fP and above, patch updates for -versions \fB0\.X >=0\.1\.0\fP, and \fIno\fR updates for versions \fB0\.0\.X\fP\|\. -.P -Many authors treat a \fB0\.x\fP version as if the \fBx\fP were the major -"breaking\-change" indicator\. -.P -Caret ranges are ideal when an author may make breaking changes -between \fB0\.2\.4\fP and \fB0\.3\.0\fP releases, which is a common practice\. -However, it presumes that there will \fInot\fR be breaking changes between -\fB0\.2\.4\fP and \fB0\.2\.5\fP\|\. It allows for changes that are presumed to be -additive (but non\-breaking), according to commonly observed practices\. -.RS 0 -.IP \(bu 2 -\fB^1\.2\.3\fP := \fB>=1\.2\.3 <2\.0\.0\fP -.IP \(bu 2 -\fB^0\.2\.3\fP := \fB>=0\.2\.3 <0\.3\.0\fP -.IP \(bu 2 -\fB^0\.0\.3\fP := \fB>=0\.0\.3 <0\.0\.4\fP -.IP \(bu 2 -\fB^1\.2\.3\-beta\.2\fP := \fB>=1\.2\.3\-beta\.2 <2\.0\.0\fP Note that prereleases in -the \fB1\.2\.3\fP version will be allowed, if they are greater than or -equal to \fBbeta\.2\fP\|\. So, \fB1\.2\.3\-beta\.4\fP would be allowed, but -\fB1\.2\.4\-beta\.2\fP would not, because it is a prerelease of a -different \fB[major, minor, patch]\fP tuple\. -.IP \(bu 2 -\fB^0\.0\.3\-beta\fP := \fB>=0\.0\.3\-beta <0\.0\.4\fP Note that prereleases in the -\fB0\.0\.3\fP version \fIonly\fR will be allowed, if they are greater than or -equal to \fBbeta\fP\|\. So, \fB0\.0\.3\-pr\.2\fP would be allowed\. - -.RE -.P -When parsing caret ranges, a missing \fBpatch\fP value desugars to the -number \fB0\fP, but will allow flexibility within that value, even if the -major and minor versions are both \fB0\fP\|\. -.RS 0 -.IP \(bu 2 -\fB^1\.2\.x\fP := \fB>=1\.2\.0 <2\.0\.0\fP -.IP \(bu 2 -\fB^0\.0\.x\fP := \fB>=0\.0\.0 <0\.1\.0\fP -.IP \(bu 2 -\fB^0\.0\fP := \fB>=0\.0\.0 <0\.1\.0\fP - -.RE -.P -A missing \fBminor\fP and \fBpatch\fP values will desugar to zero, but also -allow flexibility within those values, even if the major version is -zero\. -.RS 0 -.IP \(bu 2 -\fB^1\.x\fP := \fB>=1\.0\.0 <2\.0\.0\fP -.IP \(bu 2 -\fB^0\.x\fP := \fB>=0\.0\.0 <1\.0\.0\fP - -.RE -.SS Range Grammar -.P -Putting all this together, here is a Backus\-Naur grammar for ranges, -for the benefit of parser authors: -.P -.RS 2 -.nf -range\-set ::= range ( logical\-or range ) * -logical\-or ::= ( ' ' ) * '||' ( ' ' ) * -range ::= hyphen | simple ( ' ' simple ) * | '' -hyphen ::= partial ' \- ' partial -simple ::= primitive | partial | tilde | caret -primitive ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial -partial ::= xr ( '\.' xr ( '\.' xr qualifier ? )? )? -xr ::= 'x' | 'X' | '*' | nr -nr ::= '0' | ['1'\-'9'] ( ['0'\-'9'] ) * -tilde ::= '~' partial -caret ::= '^' partial -qualifier ::= ( '\-' pre )? ( '+' build )? -pre ::= parts -build ::= parts -parts ::= part ( '\.' part ) * -part ::= nr | [\-0\-9A\-Za\-z]+ -.fi -.RE -.SH Functions -.P -All methods and classes take a final \fBoptions\fP object argument\. All -options in this object are \fBfalse\fP by default\. The options supported -are: -.RS 0 -.IP \(bu 2 -\fBloose\fP Be more forgiving about not\-quite\-valid semver strings\. -(Any resulting output will always be 100% strict compliant, of -course\.) For backwards compatibility reasons, if the \fBoptions\fP -argument is a boolean value instead of an object, it is interpreted -to be the \fBloose\fP param\. -.IP \(bu 2 -\fBincludePrerelease\fP Set to suppress the default -behavior \fIhttps://github\.com/npm/node\-semver#prerelease\-tags\fR of -excluding prerelease tagged versions from ranges unless they are -explicitly opted into\. - -.RE -.P -Strict\-mode Comparators and Ranges will be strict about the SemVer -strings that they parse\. -.RS 0 -.IP \(bu 2 -\fBvalid(v)\fP: Return the parsed version, or null if it's not valid\. -.IP \(bu 2 -\fBinc(v, release)\fP: Return the version incremented by the release -type (\fBmajor\fP, \fBpremajor\fP, \fBminor\fP, \fBpreminor\fP, \fBpatch\fP, -\fBprepatch\fP, or \fBprerelease\fP), or null if it's not valid -.RS -.IP \(bu 2 -\fBpremajor\fP in one call will bump the version up to the next major -version and down to a prerelease of that major version\. -\fBpreminor\fP, and \fBprepatch\fP work the same way\. -.IP \(bu 2 -If called from a non\-prerelease version, the \fBprerelease\fP will work the -same as \fBprepatch\fP\|\. It increments the patch version, then makes a -prerelease\. If the input version is already a prerelease it simply -increments it\. - -.RE -.IP \(bu 2 -\fBprerelease(v)\fP: Returns an array of prerelease components, or null -if none exist\. Example: \fBprerelease('1\.2\.3\-alpha\.1') \-> ['alpha', 1]\fP -.IP \(bu 2 -\fBmajor(v)\fP: Return the major version number\. -.IP \(bu 2 -\fBminor(v)\fP: Return the minor version number\. -.IP \(bu 2 -\fBpatch(v)\fP: Return the patch version number\. -.IP \(bu 2 -\fBintersects(r1, r2, loose)\fP: Return true if the two supplied ranges -or comparators intersect\. -.IP \(bu 2 -\fBparse(v)\fP: Attempt to parse a string as a semantic version, returning either -a \fBSemVer\fP object or \fBnull\fP\|\. - -.RE -.SS Comparison -.RS 0 -.IP \(bu 2 -\fBgt(v1, v2)\fP: \fBv1 > v2\fP -.IP \(bu 2 -\fBgte(v1, v2)\fP: \fBv1 >= v2\fP -.IP \(bu 2 -\fBlt(v1, v2)\fP: \fBv1 < v2\fP -.IP \(bu 2 -\fBlte(v1, v2)\fP: \fBv1 <= v2\fP -.IP \(bu 2 -\fBeq(v1, v2)\fP: \fBv1 == v2\fP This is true if they're logically equivalent, -even if they're not the exact same string\. You already know how to -compare strings\. -.IP \(bu 2 -\fBneq(v1, v2)\fP: \fBv1 != v2\fP The opposite of \fBeq\fP\|\. -.IP \(bu 2 -\fBcmp(v1, comparator, v2)\fP: Pass in a comparison string, and it'll call -the corresponding function above\. \fB"==="\fP and \fB"!=="\fP do simple -string comparison, but are included for completeness\. Throws if an -invalid comparison string is provided\. -.IP \(bu 2 -\fBcompare(v1, v2)\fP: Return \fB0\fP if \fBv1 == v2\fP, or \fB1\fP if \fBv1\fP is greater, or \fB\-1\fP if -\fBv2\fP is greater\. Sorts in ascending order if passed to \fBArray\.sort()\fP\|\. -.IP \(bu 2 -\fBrcompare(v1, v2)\fP: The reverse of compare\. Sorts an array of versions -in descending order when passed to \fBArray\.sort()\fP\|\. -.IP \(bu 2 -\fBdiff(v1, v2)\fP: Returns difference between two versions by the release type -(\fBmajor\fP, \fBpremajor\fP, \fBminor\fP, \fBpreminor\fP, \fBpatch\fP, \fBprepatch\fP, or \fBprerelease\fP), -or null if the versions are the same\. - -.RE -.SS Comparators -.RS 0 -.IP \(bu 2 -\fBintersects(comparator)\fP: Return true if the comparators intersect - -.RE -.SS Ranges -.RS 0 -.IP \(bu 2 -\fBvalidRange(range)\fP: Return the valid range or null if it's not valid -.IP \(bu 2 -\fBsatisfies(version, range)\fP: Return true if the version satisfies the -range\. -.IP \(bu 2 -\fBmaxSatisfying(versions, range)\fP: Return the highest version in the list -that satisfies the range, or \fBnull\fP if none of them do\. -.IP \(bu 2 -\fBminSatisfying(versions, range)\fP: Return the lowest version in the list -that satisfies the range, or \fBnull\fP if none of them do\. -.IP \(bu 2 -\fBminVersion(range)\fP: Return the lowest version that can possibly match -the given range\. -.IP \(bu 2 -\fBgtr(version, range)\fP: Return \fBtrue\fP if version is greater than all the -versions possible in the range\. -.IP \(bu 2 -\fBltr(version, range)\fP: Return \fBtrue\fP if version is less than all the -versions possible in the range\. -.IP \(bu 2 -\fBoutside(version, range, hilo)\fP: Return true if the version is outside -the bounds of the range in either the high or low direction\. The -\fBhilo\fP argument must be either the string \fB\|'>'\fP or \fB\|'<'\fP\|\. (This is -the function called by \fBgtr\fP and \fBltr\fP\|\.) -.IP \(bu 2 -\fBintersects(range)\fP: Return true if any of the ranges comparators intersect - -.RE -.P -Note that, since ranges may be non\-contiguous, a version might not be -greater than a range, less than a range, \fIor\fR satisfy a range! For -example, the range \fB1\.2 <1\.2\.9 || >2\.0\.0\fP would have a hole from \fB1\.2\.9\fP -until \fB2\.0\.0\fP, so the version \fB1\.2\.10\fP would not be greater than the -range (because \fB2\.0\.1\fP satisfies, which is higher), nor less than the -range (since \fB1\.2\.8\fP satisfies, which is lower), and it also does not -satisfy the range\. -.P -If you want to know if a version satisfies or does not satisfy a -range, use the \fBsatisfies(version, range)\fP function\. -.SS Coercion -.RS 0 -.IP \(bu 2 -\fBcoerce(version)\fP: Coerces a string to semver if possible - -.RE -.P -This aims to provide a very forgiving translation of a non\-semver string to -semver\. It looks for the first digit in a string, and consumes all -remaining characters which satisfy at least a partial semver (e\.g\., \fB1\fP, -\fB1\.2\fP, \fB1\.2\.3\fP) up to the max permitted length (256 characters)\. Longer -versions are simply truncated (\fB4\.6\.3\.9\.2\-alpha2\fP becomes \fB4\.6\.3\fP)\. All -surrounding text is simply ignored (\fBv3\.4 replaces v3\.3\.1\fP becomes -\fB3\.4\.0\fP)\. Only text which lacks digits will fail coercion (\fBversion one\fP -is not valid)\. The maximum length for any semver component considered for -coercion is 16 characters; longer components will be ignored -(\fB10000000000000000\.4\.7\.4\fP becomes \fB4\.7\.4\fP)\. The maximum value for any -semver component is \fBNumber\.MAX_SAFE_INTEGER || (2**53 \- 1)\fP; higher value -components are invalid (\fB9999999999999999\.4\.7\.4\fP is likely invalid)\. diff --git a/deps/npm/man/man7/workspaces.7 b/deps/npm/man/man7/workspaces.7 index c2b3e30e539c35..350a80637831bc 100644 --- a/deps/npm/man/man7/workspaces.7 +++ b/deps/npm/man/man7/workspaces.7 @@ -1,4 +1,4 @@ -.TH "WORKSPACES" "7" "January 2021" "" "" +.TH "WORKSPACES" "7" "February 2021" "" "" .SH "NAME" \fBworkspaces\fR \- Working with workspaces .SS Description diff --git a/deps/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js b/deps/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js index c1f18af7e43dc7..ae92b74cefd188 100644 --- a/deps/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js +++ b/deps/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js @@ -314,10 +314,11 @@ module.exports = cls => class IdealTreeBuilder extends cls { .then(async root => { if (!this[_updateAll] && !this[_global] && !root.meta.loadedFromDisk) { await new this.constructor(this.options).loadActual({ root }) + const tree = root.target || root // even though we didn't load it from a package-lock.json FILE, // we still loaded it "from disk", meaning we have to reset // dep flags before assuming that any mutations were reflected. - if (root.children.size) + if (tree.children.size) root.meta.loadedFromDisk = true } return root @@ -332,20 +333,28 @@ module.exports = cls => class IdealTreeBuilder extends cls { }) } - [_globalRootNode] () { - const root = this[_rootNodeFromPackage]({ dependencies: {} }) + async [_globalRootNode] () { + const root = await this[_rootNodeFromPackage]({ dependencies: {} }) // this is a gross kludge to handle the fact that we don't save // metadata on the root node in global installs, because the "root" // node is something like /usr/local/lib. const meta = new Shrinkwrap({ path: this.path }) meta.reset() root.meta = meta - return Promise.resolve(root) + return root } - [_rootNodeFromPackage] (pkg) { - return new Node({ + async [_rootNodeFromPackage] (pkg) { + // if the path doesn't exist, then we explode at this point. Note that + // this is not a problem for reify(), since it creates the root path + // before ever loading trees. + // TODO: make buildIdealTree() and loadActual handle a missing root path, + // or a symlink to a missing target, and let reify() create it as needed. + const real = await realpath(this.path, this[_rpcache], this[_stcache]) + const Cls = real === this.path ? Node : Link + const root = new Cls({ path: this.path, + realpath: real, pkg, extraneous: false, dev: false, @@ -355,12 +364,29 @@ module.exports = cls => class IdealTreeBuilder extends cls { global: this[_global], legacyPeerDeps: this.legacyPeerDeps, }) + if (root.isLink) { + root.target = new Node({ + path: real, + realpath: real, + pkg, + extraneous: false, + dev: false, + devOptional: false, + peer: false, + optional: false, + global: this[_global], + legacyPeerDeps: this.legacyPeerDeps, + root, + }) + } + return root } // process the add/rm requests by modifying the root node, and the // update.names request by queueing nodes dependent on those named. async [_applyUserRequests] (options) { process.emit('time', 'idealTree:userRequests') + const tree = this.idealTree.target || this.idealTree // If we have a list of package names to update, and we know it's // going to update them wherever they are, add any paths into those // named nodes to the buildIdealTree queue. @@ -373,7 +399,7 @@ module.exports = cls => class IdealTreeBuilder extends cls { const nm = resolve(this.path, 'node_modules') for (const name of await readdir(nm)) { if (this[_updateAll] || this[_updateNames].includes(name)) - this.idealTree.package.dependencies[name] = '*' + tree.package.dependencies[name] = '*' } } @@ -381,7 +407,7 @@ module.exports = cls => class IdealTreeBuilder extends cls { this[_queueVulnDependents](options) if (options.rm && options.rm.length) { - addRmPkgDeps.rm(this.idealTree.package, options.rm) + addRmPkgDeps.rm(tree.package, options.rm) for (const name of options.rm) this[_explicitRequests].add(name) } @@ -390,8 +416,8 @@ module.exports = cls => class IdealTreeBuilder extends cls { await this[_add](options) // triggers a refresh of all edgesOut - if (options.add && options.add.length || options.rm && options.rm.length) - this.idealTree.package = this.idealTree.package + if (options.add && options.add.length || options.rm && options.rm.length || this[_global]) + tree.package = tree.package process.emit('timeEnd', 'idealTree:userRequests') } @@ -410,8 +436,9 @@ module.exports = cls => class IdealTreeBuilder extends cls { this[_resolvedAdd] = add // now add is a list of spec objects with names. // find a home for each of them! + const tree = this.idealTree.target || this.idealTree addRmPkgDeps.add({ - pkg: this.idealTree.package, + pkg: tree.package, add, saveBundle, saveType, @@ -514,7 +541,7 @@ module.exports = cls => class IdealTreeBuilder extends cls { fixAvailable, } = topVuln for (const node of topNodes) { - if (node !== this.idealTree) { + if (node !== this.idealTree && node !== this.idealTree.target) { // not something we're going to fix, sorry. have to cd into // that directory and fix it yourself. this.log.warn('audit', 'Manual fix required in linked project ' + @@ -606,7 +633,7 @@ This is a one-time fix-up, please be patient... this.addTracker('idealTree:inflate') const queue = [] for (const node of inventory.values()) { - if (node.isRoot) + if (node.isProjectRoot) continue queue.push(async () => { @@ -646,11 +673,12 @@ This is a one-time fix-up, please be patient... // at this point we have a virtual tree with the actual root node's // package deps, which may be partly or entirely incomplete, invalid // or extraneous. - [_buildDeps] (node) { + [_buildDeps] () { process.emit('time', 'idealTree:buildDeps') - this[_depsQueue].push(this.idealTree) + const tree = this.idealTree.target || this.idealTree + this[_depsQueue].push(tree) this.log.silly('idealTree', 'buildDeps') - this.addTracker('idealTree', this.idealTree.name, '') + this.addTracker('idealTree', tree.name, '') return this[_buildDepStep]() .then(() => process.emit('timeEnd', 'idealTree:buildDeps')) } @@ -835,7 +863,7 @@ This is a one-time fix-up, please be patient... // loads a node from an edge, and then loads its peer deps (and their // peer deps, on down the line) into a virtual root parent. - [_nodeFromEdge] (edge, parent_) { + async [_nodeFromEdge] (edge, parent_, secondEdge = null) { // create a virtual root node with the same deps as the node that // is requesting this one, so that we can get all the peer deps in // a context where they're likely to be resolvable. @@ -843,22 +871,43 @@ This is a one-time fix-up, please be patient... const realParent = edge.peer ? edge.from.resolveParent : edge.from const spec = npa.resolve(edge.name, edge.spec, edge.from.path) - return this[_nodeFromSpec](edge.name, spec, parent, edge) - .then(node => { - // handle otherwise unresolvable dependency nesting loops by - // creating a symbolic link - // a1 -> b1 -> a2 -> b2 -> a1 -> ... - // instead of nesting forever, when the loop occurs, create - // a symbolic link to the earlier instance - for (let p = edge.from.resolveParent; p; p = p.resolveParent) { - if (p.matches(node) && !p.isRoot) - return new Link({ parent: realParent, target: p }) - } - // keep track of the thing that caused this node to be included. - const src = parent.sourceReference - this[_peerSetSource].set(node, src) - return this[_loadPeerSet](node) - }) + const first = await this[_nodeFromSpec](edge.name, spec, parent, edge) + + // we might have a case where the parent has a peer dependency on + // `foo@*` which resolves to v2, but another dep in the set has a + // peerDependency on `foo@1`. In that case, if we force it to be v2, + // we're unnecessarily triggering an ERESOLVE. + // If we have a second edge to worry about, and it's not satisfied + // by the first node, try a second and see if that satisfies the + // original edge here. + const spec2 = secondEdge && npa.resolve( + edge.name, + secondEdge.spec, + secondEdge.from.path + ) + const second = secondEdge && !secondEdge.valid + ? await this[_nodeFromSpec](edge.name, spec2, parent, secondEdge) + : null + + // pick the second one if they're both happy with that, otherwise first + const node = second && edge.valid ? second : first + // ensure the one we want is the one that's placed + node.parent = parent + + // handle otherwise unresolvable dependency nesting loops by + // creating a symbolic link + // a1 -> b1 -> a2 -> b2 -> a1 -> ... + // instead of nesting forever, when the loop occurs, create + // a symbolic link to the earlier instance + for (let p = edge.from.resolveParent; p; p = p.resolveParent) { + if (p.matches(node) && !p.isTop) + return new Link({ parent: realParent, target: p }) + } + + // keep track of the thing that caused this node to be included. + const src = parent.sourceReference + this[_peerSetSource].set(node, src) + return this[_loadPeerSet](node) } [_virtualRoot] (node, reuse = false) { @@ -886,7 +935,7 @@ This is a one-time fix-up, please be patient... // also skip over any nodes in the tree that failed to load, since those // will crash the install later on anyway. - const bd = node.isRoot ? null : node.package.bundleDependencies + const bd = node.isProjectRoot ? null : node.package.bundleDependencies const bundled = new Set(bd || []) return [...node.edgesOut.values()] @@ -923,7 +972,7 @@ This is a one-time fix-up, please be patient... return true // If the user has explicitly asked to install this package, it's a problem. - if (node.isRoot && this[_explicitRequests].has(edge.name)) + if (node.isProjectRoot && this[_explicitRequests].has(edge.name)) return true // No problems! @@ -1005,30 +1054,34 @@ This is a one-time fix-up, please be patient... // deps to override, but throw if no preference can be determined. async [_loadPeerSet] (node) { const peerEdges = [...node.edgesOut.values()] - // we only care about peers here, and don't install peerOptionals - .filter(e => e.peer && !e.valid && !e.optional) + // we typically only install non-optional peers, but we have to + // factor them into the peerSet so that we can avoid conflicts + .filter(e => e.peer && !(e.valid && e.to)) .sort(({name: a}, {name: b}) => a.localeCompare(b)) for (const edge of peerEdges) { // already placed this one, and we're happy with it. - if (edge.valid) + if (edge.valid && edge.to) continue const parentEdge = node.parent.edgesOut.get(edge.name) - const {isRoot, isWorkspace} = node.parent.sourceReference - const isMine = isRoot || isWorkspace - if (edge.missing) { + const {isProjectRoot, isWorkspace} = node.parent.sourceReference + const isMine = isProjectRoot || isWorkspace + if (!edge.to) { if (!parentEdge) { // easy, just put the thing there await this[_nodeFromEdge](edge, node.parent) continue } else { - // try to put the parent's preference, and make sure that satisfies. - // if so, we're good. - // if it does not, then we have a problem in strict mode, no problem + // if the parent's edge is very broad like >=1, and the edge in + // question is something like 1.x, then we want to get a 1.x, not + // a 2.x. pass along the child edge as an advisory guideline. + // if the parent edge doesn't satisfy the child edge, and the + // child edge doesn't satisfy the parent edge, then we have + // a conflict. this is always a problem in strict mode, never // in force mode, and a problem in non-strict mode if this isn't - // on behalf of the root node. In all such cases, we warn at least. - await this[_nodeFromEdge](parentEdge, node.parent) + // on behalf of our project. in all such cases, we warn at least. + await this[_nodeFromEdge](parentEdge, node.parent, edge) // hooray! that worked! if (edge.valid) @@ -1037,8 +1090,9 @@ This is a one-time fix-up, please be patient... // allow it if (this[_force] || !isMine && !this[_strictPeerDeps]) continue - else - this[_failPeerConflict](edge) + + // problem + this[_failPeerConflict](edge) } } @@ -1094,6 +1148,7 @@ This is a one-time fix-up, please be patient... [_placeDep] (dep, node, edge, peerEntryEdge = null, peerPath = []) { if (edge.to && !edge.error && + !this[_explicitRequests].has(edge.name) && !this[_updateNames].includes(edge.name) && !this[_isVulnerable](edge.to)) return [] @@ -1101,7 +1156,7 @@ This is a one-time fix-up, please be patient... // top nodes should still get peer deps from their fsParent if possible, // and only install locally if there's no other option, eg for a link // outside of the project root, or for a conflicted dep. - const start = edge.peer && !node.isRoot ? node.resolveParent || node + const start = edge.peer && !node.isProjectRoot ? node.resolveParent || node : node let target @@ -1137,7 +1192,8 @@ This is a one-time fix-up, please be patient... // when installing globally, or just in global style, we never place // deps above the first level. - if (this[_globalStyle] && check.resolveParent === this.idealTree) + const tree = this.idealTree && this.idealTree.target || this.idealTree + if (this[_globalStyle] && check.resolveParent === tree) break } @@ -1350,8 +1406,8 @@ This is a one-time fix-up, please be patient... // depends on a, and it has a conflict, it's our problem. So, the root // (or whatever is bringing in a) becomes the "effective source" for // the purposes of this calculation. - const { isRoot, isWorkspace } = isSource ? target : source || {} - const isMine = isRoot || isWorkspace + const { isProjectRoot, isWorkspace } = isSource ? target : source || {} + const isMine = isProjectRoot || isWorkspace // Useful testing thingie right here. // peerEntryEdge should *always* be a non-peer dependency, or a peer diff --git a/deps/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js b/deps/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js index d916b49c22c018..6cc129a7cc0572 100644 --- a/deps/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js +++ b/deps/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js @@ -1,5 +1,6 @@ // mixin implementing the reify method +const onExit = require('../signal-handling.js') const pacote = require('pacote') const rpj = require('read-package-json-fast') const { updateDepSpec } = require('../dep-spec.js') @@ -27,8 +28,9 @@ const updateRootPackageJson = require('../update-root-package-json.js') const _retiredPaths = Symbol('retiredPaths') const _retiredUnchanged = Symbol('retiredUnchanged') const _sparseTreeDirs = Symbol('sparseTreeDirs') +const _sparseTreeRoots = Symbol('sparseTreeRoots') const _savePrefix = Symbol('savePrefix') -const _retireShallowNodes = Symbol('retireShallowNodes') +const _retireShallowNodes = Symbol.for('retireShallowNodes') const _getBundlesByDepth = Symbol('getBundlesByDepth') const _registryResolved = Symbol('registryResolved') const _addNodeToTrashList = Symbol('addNodeToTrashList') @@ -54,7 +56,7 @@ const _awaitQuickAudit = Symbol('awaitQuickAudit') const _unpackNewModules = Symbol.for('unpackNewModules') const _moveContents = Symbol.for('moveContents') const _moveBackRetiredUnchanged = Symbol.for('moveBackRetiredUnchanged') -const _build = Symbol('build') +const _build = Symbol.for('build') const _removeTrash = Symbol.for('removeTrash') const _renamePath = Symbol.for('renamePath') const _rollbackRetireShallowNodes = Symbol.for('rollbackRetireShallowNodes') @@ -102,6 +104,7 @@ module.exports = cls => class Reifier extends cls { this[_retiredPaths] = {} this[_retiredUnchanged] = {} this[_sparseTreeDirs] = new Set() + this[_sparseTreeRoots] = new Set() this[_trashList] = new Set() } @@ -153,16 +156,63 @@ module.exports = cls => class Reifier extends cls { return this[_submitQuickAudit]() } - await this[_retireShallowNodes]() - await this[_createSparseTree]() - await this[_addOmitsToTrashList]() - await this[_loadShrinkwrapsAndUpdateTrees]() - await this[_loadBundlesAndUpdateTrees]() - await this[_submitQuickAudit]() - await this[_unpackNewModules]() - await this[_moveBackRetiredUnchanged]() - await this[_build]() + // ok, we're about to start touching the fs. need to roll back + // if we get an early termination. + let reifyTerminated = null + const removeHandler = onExit(({signal}) => { + // only call once. if signal hits twice, we just terminate + removeHandler() + reifyTerminated = Object.assign(new Error('process terminated'), { + signal, + }) + return false + }) + + // [rollbackfn, [...actions]] + // after each step, if the process was terminated, execute the rollback + // note that each rollback *also* calls the previous one when it's + // finished, and then the first one throws the error, so we only need + // a new rollback step when we have a new thing that must be done to + // revert the install. + const steps = [ + [_rollbackRetireShallowNodes, [ + _retireShallowNodes, + ]], + [_rollbackCreateSparseTree, [ + _createSparseTree, + _addOmitsToTrashList, + _loadShrinkwrapsAndUpdateTrees, + _loadBundlesAndUpdateTrees, + _submitQuickAudit, + _unpackNewModules, + ]], + [_rollbackMoveBackRetiredUnchanged, [ + _moveBackRetiredUnchanged, + _build, + ]], + ] + for (const [rollback, actions] of steps) { + for (const action of actions) { + try { + await this[action]() + if (reifyTerminated) + throw reifyTerminated + } catch (er) { + await this[rollback](er) + /* istanbul ignore next - rollback throws, should never hit this */ + throw er + } + } + } + + // no rollback for this one, just exit with the error, since the + // install completed and can't be safely recovered at this point. await this[_removeTrash]() + if (reifyTerminated) + throw reifyTerminated + + // done modifying the file system, no need to keep listening for sigs + removeHandler() } // when doing a local install, we load everything and figure it all out. @@ -183,8 +233,9 @@ module.exports = cls => class Reifier extends cls { const actualOpt = this[_global] ? { ignoreMissing: true, global: true, - filter: (node, kid) => !node.isRoot ? true - : (node.edgesOut.has(kid) || this[_explicitRequests].has(kid)), + filter: (node, kid) => this[_explicitRequests].size === 0 || !node.isProjectRoot + ? true + : (node.edgesOut.has(kid) || this[_explicitRequests].has(kid)), } : { ignoreMissing: true } if (!this[_global]) { @@ -260,7 +311,6 @@ module.exports = cls => class Reifier extends cls { const movePromises = Object.entries(moves) .map(([from, to]) => this[_renamePath](from, to)) return promiseAllRejectLate(movePromises) - .catch(er => this[_rollbackRetireShallowNodes](er)) .then(() => process.emit('timeEnd', 'reify:retireShallow')) } @@ -326,18 +376,22 @@ module.exports = cls => class Reifier extends cls { .map(diff => diff.ideal.path) return promiseAllRejectLate(dirs.map(d => mkdirp(d))) - .then(() => dirs.forEach(dir => this[_sparseTreeDirs].add(dir))) + .then(made => { + made.forEach(made => this[_sparseTreeRoots].add(made)) + dirs.forEach(dir => this[_sparseTreeDirs].add(dir)) + }) .then(() => process.emit('timeEnd', 'reify:createSparse')) - .catch(er => this[_rollbackCreateSparseTree](er)) } [_rollbackCreateSparseTree] (er) { process.emit('time', 'reify:rollback:createSparse') - // cut the roots of the sparse tree, not the leaves - const moves = this[_retiredPaths] + // cut the roots of the sparse tree that were created, not the leaves + const roots = this[_sparseTreeRoots] + // also delete the moves that we retired, so that we can move them back const failures = [] - const unlinks = Object.entries(moves) - .map(([from, to]) => rimraf(from).catch(er => failures.push([from, er]))) + const targets = [...roots, ...Object.keys(this[_retiredPaths])] + const unlinks = targets + .map(path => rimraf(path).catch(er => failures.push([path, er]))) return promiseAllRejectLate(unlinks) .then(() => { if (failures.length) @@ -375,7 +429,6 @@ module.exports = cls => class Reifier extends cls { .then(() => this[_diffTrees]()) .then(() => this[_createSparseTree]()) .then(() => process.emit('timeEnd', 'reify:loadShrinkwraps')) - .catch(er => this[_rollbackCreateSparseTree](er)) } // create a symlink for Links, extract for Nodes @@ -543,7 +596,6 @@ module.exports = cls => class Reifier extends cls { })))) // move onto the next level of bundled items .then(() => this[_loadBundlesAndUpdateTrees](depth + 1, bundlesByDepth)) - .catch(er => this[_rollbackCreateSparseTree](er)) } [_getBundlesByDepth] () { @@ -553,7 +605,7 @@ module.exports = cls => class Reifier extends cls { tree: this.diff, visit: diff => { const node = diff.ideal - if (node && !node.isRoot && node.package.bundleDependencies && + if (node && !node.isProjectRoot && node.package.bundleDependencies && node.package.bundleDependencies.length) { maxBundleDepth = Math.max(maxBundleDepth, node.depth) if (!bundlesByDepth.has(node.depth)) @@ -677,7 +729,6 @@ module.exports = cls => class Reifier extends cls { }) return promiseAllRejectLate(unpacks) .then(() => process.emit('timeEnd', 'reify:unpack')) - .catch(er => this[_rollbackCreateSparseTree](er)) } // This is the part where we move back the unchanging nodes that were @@ -720,7 +771,6 @@ module.exports = cls => class Reifier extends cls { })) })) .then(() => process.emit('timeEnd', 'reify:unretire')) - .catch(er => this[_rollbackMoveBackRetiredUnchanged](er)) } // move the contents from the fromPath to the node.path @@ -761,7 +811,7 @@ module.exports = cls => class Reifier extends cls { dfwalk({ tree: this.diff, leave: diff => { - if (!diff.ideal.isRoot) + if (!diff.ideal.isProjectRoot) nodes.push(diff.ideal) }, // process adds before changes, ignore removals @@ -771,7 +821,6 @@ module.exports = cls => class Reifier extends cls { return this.rebuild({ nodes, handleOptionalFailure: true }) .then(() => process.emit('timeEnd', 'reify:build')) - .catch(er => this[_rollbackMoveBackRetiredUnchanged](er)) } // the tree is pretty much built now, so it's cleanup time. diff --git a/deps/npm/node_modules/@npmcli/arborist/lib/node.js b/deps/npm/node_modules/@npmcli/arborist/lib/node.js index 396bcb58a2de96..9a6b86e4021b8f 100644 --- a/deps/npm/node_modules/@npmcli/arborist/lib/node.js +++ b/deps/npm/node_modules/@npmcli/arborist/lib/node.js @@ -64,70 +64,7 @@ const _meta = Symbol('_meta') const relpath = require('./relpath.js') const consistentResolve = require('./consistent-resolve.js') -// helper function to output a clearer visualization -// of the current node and its descendents -class ArboristNode {} - -const printableTree = (tree, path = []) => - (path.includes(tree) ? { location: tree.location } : (path.push(tree), Object.assign(new ArboristNode(), { - name: tree.name, - ...(tree.package && tree.package.version - ? { version: tree.package.version } - : {}), - location: tree.location, - path: tree.path, - realpath: tree.realpath, - ...(tree.isLink ? { target: printableTree(tree.target, path) } : {}), - ...(tree.resolved != null ? { resolved: tree.resolved } : {}), - ...(tree.extraneous ? { extraneous: true } : { - ...(tree.dev ? { dev: true } : {}), - ...(tree.optional ? { optional: true } : {}), - ...(tree.devOptional && !tree.dev && !tree.optional - ? { devOptional: true } : {}), - ...(tree.peer ? { peer: true } : {}), - }), - ...(tree.inBundle ? { bundled: true } : {}), - // handle top-level tree error - ...(tree.error - ? { - error: { - code: tree.error.code, - ...(tree.error.path - ? { path: tree.error.path } - : {}), - }, - } : {}), - // handle errors for each node - ...(tree.errors && tree.errors.length - ? { - errors: tree.errors.map(error => ({ - code: error.code, - ...(error.path - ? { path: error.path } - : {}), - })), - } : {}), - ...(tree.edgesIn && tree.edgesIn.size ? { - edgesIn: new Set([...tree.edgesIn] - .sort((a, b) => a.from.location.localeCompare(b.from.location))), - } : {}), - ...(tree.edgesOut && tree.edgesOut.size ? { - edgesOut: new Map([...tree.edgesOut.entries()] - .sort((a, b) => a[0].localeCompare(b[0]))), - } : {}), - ...(tree.fsChildren && tree.fsChildren.size ? { - fsChildren: new Set([...tree.fsChildren] - .sort((a, b) => a.path.localeCompare(b.path)) - .map(tree => printableTree(tree, path))), - } : {}), - ...(tree.target || !tree.children || !tree.children.size - ? {} - : { - children: new Map([...tree.children.entries()] - .sort((a, b) => a[0].localeCompare(b[0])) - .map(([name, tree]) => [name, printableTree(tree, path)])), - }), - }))) +const printableTree = require('./printable.js') class Node { constructor (options) { @@ -310,7 +247,7 @@ class Node { // true for packages installed directly in the global node_modules folder get globalTop () { - return this.global && this.parent.isRoot + return this.global && this.parent.isProjectRoot } get workspaces () { @@ -357,8 +294,11 @@ class Node { const { name = '', version = '' } = this.package // root package will prefer package name over folder name, // and never be called an alias. - const myname = this.isRoot ? name || this.name : this.name - const alias = !this.isRoot && name && myname !== name ? `npm:${name}@` : '' + const { isProjectRoot } = this + const myname = isProjectRoot ? name || this.name + : this.name + const alias = !isProjectRoot && name && myname !== name ? `npm:${name}@` + : '' return `${myname}@${alias}${version}` } @@ -402,14 +342,14 @@ class Node { } [_explain] (edge, seen) { - if (this.isRoot && !this.sourceReference) { + if (this.isProjectRoot && !this.sourceReference) { return { location: this.path, } } const why = { - name: this.isRoot ? this.package.name : this.name, + name: this.isProjectRoot ? this.package.name : this.name, version: this.package.version, } if (this.errors.length || !this.package.name || !this.package.version) { @@ -447,7 +387,7 @@ class Node { // and are not keeping it held in this spot anyway. const edges = [] for (const edge of this.edgesIn) { - if (!edge.valid && !edge.from.isRoot) + if (!edge.valid && !edge.from.isProjectRoot) continue edges.push(edge) @@ -516,7 +456,7 @@ class Node { } get isWorkspace () { - if (this.isRoot) + if (this.isProjectRoot) return false const { root } = this const { type, to } = root.edgesOut.get(this.package.name) || {} @@ -527,6 +467,10 @@ class Node { return this === this.root } + get isProjectRoot () { + return this === this.root || this === this.root.target + } + set root (root) { // setting to null means this is the new root // should only ever be one step @@ -792,7 +736,9 @@ class Node { // Linked targets that are disconnected from the tree are tops, // but don't have a 'path' field, only a 'realpath', because we // don't know their canonical location. We don't need their devDeps. - if (this.isTop && this.path && !this.sourceReference) + const { isTop, path, sourceReference } = this + const { isTop: srcTop, path: srcPath } = sourceReference || {} + if (isTop && path && (!sourceReference || srcTop && srcPath)) this[_loadDepType](this.package.devDependencies, 'dev') const pd = this.package.peerDependencies @@ -961,8 +907,8 @@ class Node { if (this.isLink) return node.isLink && this.target.matches(node.target) - // if they're two root nodes, they're different if the paths differ - if (this.isRoot && node.isRoot) + // if they're two project root nodes, they're different if the paths differ + if (this.isProjectRoot && node.isProjectRoot) return this.path === node.path // if the integrity matches, then they're the same. diff --git a/deps/npm/node_modules/@npmcli/arborist/lib/printable.js b/deps/npm/node_modules/@npmcli/arborist/lib/printable.js new file mode 100644 index 00000000000000..fb73c7c2bc4349 --- /dev/null +++ b/deps/npm/node_modules/@npmcli/arborist/lib/printable.js @@ -0,0 +1,129 @@ +// helper function to output a clearer visualization +// of the current node and its descendents + +const util = require('util') + +class ArboristNode { + constructor (tree, path) { + this.name = tree.name + if (tree.package.name && tree.package.name !== this.name) + this.packageName = tree.package.name + if (tree.version) + this.version = tree.version + this.location = tree.location + this.path = tree.path + if (tree.realpath !== this.path) + this.realpath = tree.realpath + if (tree.resolved !== null) + this.resolved = tree.resolved + if (tree.extraneous) + this.extraneous = true + if (tree.dev) + this.dev = true + if (tree.optional) + this.optional = true + if (tree.devOptional && !tree.dev && !tree.optional) + this.devOptional = true + if (tree.peer) + this.peer = true + if (tree.inBundle) + this.bundled = true + if (tree.error) + this.error = treeError(tree.error) + if (tree.errors && tree.errors.length) + this.errors = tree.errors.map(treeError) + + // edgesOut sorted by name + if (tree.edgesOut.size) { + this.edgesOut = new Map([...tree.edgesOut.entries()] + .sort(([a], [b]) => a.localeCompare(b)) + .map(([name, edge]) => [name, new EdgeOut(edge)])) + } + + // edgesIn sorted by location + if (tree.edgesIn.size) { + this.edgesIn = new Set([...tree.edgesIn] + .sort((a, b) => a.from.location.localeCompare(b.from.location)) + .map(edge => new EdgeIn(edge))) + } + + // fsChildren sorted by path + if (tree.fsChildren.size) { + this.fsChildren = new Set([...tree.fsChildren] + .sort(({path: a}, {path: b}) => a.localeCompare(b)) + .map(tree => printableTree(tree, path))) + } + + // children sorted by name + if (tree.children.size) { + this.children = new Map([...tree.children.entries()] + .sort(([a], [b]) => a.localeCompare(b)) + .map(([name, tree]) => [name, printableTree(tree, path)])) + } + } +} + +class ArboristLink extends ArboristNode { + constructor (tree, path) { + super(tree, path) + this.target = printableTree(tree.target, path) + } +} + +const treeError = ({code, path}) => ({ + code, + ...(path ? { path } : {}), +}) + +// print out edges without dumping the full node all over again +// this base class will toJSON as a plain old object, but the +// util.inspect() output will be a bit cleaner +class Edge { + constructor (edge) { + this.type = edge.type + this.name = edge.name + this.spec = edge.spec || '*' + if (edge.error) + this.error = edge.error + } +} + +// don't care about 'from' for edges out +class EdgeOut extends Edge { + constructor (edge) { + super(edge) + this.to = edge.to && edge.to.location + } + + [util.inspect.custom] () { + return `{ ${this.type} ${this.name}@${this.spec}${ + this.to ? ' -> ' + this.to : '' + }${ + this.error ? ' ' + this.error : '' + } }` + } +} + +// don't care about 'to' for edges in +class EdgeIn extends Edge { + constructor (edge) { + super(edge) + this.from = edge.from && edge.from.location + } + + [util.inspect.custom] () { + return `{ ${this.from || '""'} ${this.type} ${this.name}@${this.spec}${ + this.error ? ' ' + this.error : '' + } }` + } +} + +const printableTree = (tree, path = []) => { + if (path.includes(tree)) + return { location: tree.location } + path.push(tree) + const Cls = tree.isLink ? ArboristLink : ArboristNode + return new Cls(tree, path) +} + +module.exports = printableTree diff --git a/deps/npm/node_modules/@npmcli/arborist/lib/signal-handling.js b/deps/npm/node_modules/@npmcli/arborist/lib/signal-handling.js new file mode 100644 index 00000000000000..1051cd593970a3 --- /dev/null +++ b/deps/npm/node_modules/@npmcli/arborist/lib/signal-handling.js @@ -0,0 +1,67 @@ +const signals = require('./signals.js') + +// for testing, expose the process being used +module.exports = Object.assign(fn => setup(fn), { process }) + +// do all of this in a setup function so that we can call it +// multiple times for multiple reifies that might be going on. +// Otherwise, Arborist.reify() is a global action, which is a +// new constraint we'd be adding with this behavior. +const setup = fn => { + const { process } = module.exports + + const sigListeners = { loaded: false } + + const unload = () => { + if (!sigListeners.loaded) + return + for (const sig of signals) { + try { + process.removeListener(sig, sigListeners[sig]) + } catch (er) {} + } + process.removeListener('beforeExit', onBeforeExit) + sigListeners.loaded = false + } + + const onBeforeExit = () => { + // this trick ensures that we exit with the same signal we caught + // Ie, if you press ^C and npm gets a SIGINT, we'll do the rollback + // and then exit with a SIGINT signal once we've removed the handler. + // The timeout is there because signals are asynchronous, so we need + // the process to NOT exit on its own, which means we have to have + // something keeping the event loop looping. Hence this hack. + unload() + process.kill(process.pid, signalReceived) + setTimeout(() => {}, 500) + } + + let signalReceived = null + const listener = (sig, fn) => () => { + signalReceived = sig + + // if we exit normally, but caught a signal which would have been fatal, + // then re-send it once we're done with whatever cleanup we have to do. + unload() + if (process.listeners(sig).length < 1) + process.once('beforeExit', onBeforeExit) + + fn({ signal: sig }) + } + + // do the actual loading here + for (const sig of signals) { + sigListeners[sig] = listener(sig, fn) + const max = process.getMaxListeners() + try { + // if we call this a bunch of times, avoid triggering the warning + const { length } = process.listeners(sig) + if (length >= max) + process.setMaxListeners(length + 1) + process.on(sig, sigListeners[sig]) + } catch (er) {} + } + sigListeners.loaded = true + + return unload +} diff --git a/deps/npm/node_modules/@npmcli/arborist/lib/signals.js b/deps/npm/node_modules/@npmcli/arborist/lib/signals.js new file mode 100644 index 00000000000000..8dcd585c4c0657 --- /dev/null +++ b/deps/npm/node_modules/@npmcli/arborist/lib/signals.js @@ -0,0 +1,58 @@ +// copied from signal-exit + +// This is not the set of all possible signals. +// +// It IS, however, the set of all signals that trigger +// an exit on either Linux or BSD systems. Linux is a +// superset of the signal names supported on BSD, and +// the unknown signals just fail to register, so we can +// catch that easily enough. +// +// Don't bother with SIGKILL. It's uncatchable, which +// means that we can't fire any callbacks anyway. +// +// If a user does happen to register a handler on a non- +// fatal signal like SIGWINCH or something, and then +// exit, it'll end up firing `process.emit('exit')`, so +// the handler will be fired anyway. +// +// SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised +// artificially, inherently leave the process in a +// state from which it is not safe to try and enter JS +// listeners. + +const platform = global.__ARBORIST_FAKE_PLATFORM__ || process.platform + +module.exports = [ + 'SIGABRT', + 'SIGALRM', + 'SIGHUP', + 'SIGINT', + 'SIGTERM', +] + +if (platform !== 'win32') { + module.exports.push( + 'SIGVTALRM', + 'SIGXCPU', + 'SIGXFSZ', + 'SIGUSR2', + 'SIGTRAP', + 'SIGSYS', + 'SIGQUIT', + 'SIGIOT' + // should detect profiler and enable/disable accordingly. + // see #21 + // 'SIGPROF' + ) +} + +if (platform === 'linux') { + module.exports.push( + 'SIGIO', + 'SIGPOLL', + 'SIGPWR', + 'SIGSTKFLT', + 'SIGUNUSED' + ) +} diff --git a/deps/npm/node_modules/@npmcli/arborist/package.json b/deps/npm/node_modules/@npmcli/arborist/package.json index fafd1fb0f865f2..2107652c6754d3 100644 --- a/deps/npm/node_modules/@npmcli/arborist/package.json +++ b/deps/npm/node_modules/@npmcli/arborist/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/arborist", - "version": "2.0.6", + "version": "2.1.1", "description": "Manage node_modules trees", "dependencies": { "@npmcli/installed-package-contents": "^1.0.5", @@ -20,7 +20,7 @@ "npm-package-arg": "^8.1.0", "npm-pick-manifest": "^6.1.0", "npm-registry-fetch": "^9.0.0", - "pacote": "^11.2.3", + "pacote": "^11.2.4", "parse-conflict-json": "^1.1.1", "promise-all-reject-late": "^1.0.0", "promise-call-limit": "^1.0.1", @@ -55,7 +55,7 @@ "postversion": "npm publish", "prepublishOnly": "git push origin --follow-tags", "eslint": "eslint", - "lint": "npm run eslint -- \"lib/**/*.js\"", + "lint": "npm run eslint -- \"lib/**/*.js\" \"test/arborist/*.js\" \"test/*.js\"", "lintfix": "npm run lint -- --fix", "benchmark": "node scripts/benchmark.js", "benchclean": "rm -rf scripts/benchmark/*/" diff --git a/deps/npm/node_modules/@npmcli/disparity-colors/CHANGELOG.md b/deps/npm/node_modules/@npmcli/disparity-colors/CHANGELOG.md new file mode 100644 index 00000000000000..c6dc19711a96dc --- /dev/null +++ b/deps/npm/node_modules/@npmcli/disparity-colors/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## 1.0.0 + +- Initial release diff --git a/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/LICENSE b/deps/npm/node_modules/@npmcli/disparity-colors/LICENSE similarity index 93% rename from deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/LICENSE rename to deps/npm/node_modules/@npmcli/disparity-colors/LICENSE index 19129e315fe593..dedcd7d2f9daec 100644 --- a/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/LICENSE +++ b/deps/npm/node_modules/@npmcli/disparity-colors/LICENSE @@ -1,6 +1,6 @@ The ISC License -Copyright (c) Isaac Z. Schlueter and Contributors +Copyright (c) npm Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/deps/npm/node_modules/@npmcli/disparity-colors/README.md b/deps/npm/node_modules/@npmcli/disparity-colors/README.md new file mode 100644 index 00000000000000..31d2b9c10d3ec6 --- /dev/null +++ b/deps/npm/node_modules/@npmcli/disparity-colors/README.md @@ -0,0 +1,48 @@ +# @npmcli/disparity-colors + +[![NPM version](https://img.shields.io/npm/v/@npmcli/disparity-colors)](https://www.npmjs.com/package/@npmcli/disparity-colors) +[![Build Status](https://img.shields.io/github/workflow/status/npm/disparity-colors/node-ci)](https://github.com/npm/disparity-colors) +[![License](https://img.shields.io/github/license/npm/disparity-colors)](https://github.com/npm/disparity-colors/blob/master/LICENSE) + +Spiritual sucessor to [disparity](https://www.npmjs.com/package/disparity). Colorizes [Diff Unified format](https://en.wikipedia.org/wiki/Diff#Unified_format) output using [ansi-styles](https://www.npmjs.com/package/ansi-styles). + +## Install + +`npm install @npmcli/disparity-colors` + +## Usage: + +```js +const colorize = require('@npmcli/disparity-colors') +mapWorkspaces(`--- a/src/index.js ++++ b/src/index.js +@@ -1,4 +1,5 @@ + "use strict"; ++"use foo"; + + const os = require("os"); +`) +// --- a/src/index.js +// +++ b/src/index.js +// @@ -1,4 +1,5 @@ +// "use strict"; +// +"use foo"; +// +// const os = require("os"); +``` + +## API: + +### `colorize(str, opts = {}) -> String` + +- `str`: A [Diff Unified format](https://en.wikipedia.org/wiki/Diff#Unified_format) string +- `opts`: + - `headerLength`: A **Number** defining how many lines should be colorized as header + +#### Returns + +A **String** including the appropriate [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) + +## LICENSE + +[ISC](./LICENSE) diff --git a/deps/npm/node_modules/@npmcli/disparity-colors/index.js b/deps/npm/node_modules/@npmcli/disparity-colors/index.js new file mode 100644 index 00000000000000..a02b8f884d8ac4 --- /dev/null +++ b/deps/npm/node_modules/@npmcli/disparity-colors/index.js @@ -0,0 +1,34 @@ +const ansi = require('ansi-styles') + +const colors = { + removed: ansi.red, + added: ansi.green, + header: ansi.yellow, + section: ansi.magenta +} + +function colorize (str, opts) { + let headerLength = (opts || {}).headerLength + if (typeof headerLength !== 'number' || Number.isNaN(headerLength)) { + headerLength = 2 + } + + const color = (str, colorId) => { + const { open, close } = colors[colorId] + // avoid highlighting the "\n" (would highlight till the end of the line) + return str.replace(/[^\n\r]+/g, open + '$&' + close) + } + + // this RegExp will include all the `\n` chars into the lines, easier to join + const lines = ((typeof str === 'string' && str) || '').split(/^/m) + + const start = color(lines.slice(0, headerLength).join(''), 'header') + const end = lines.slice(headerLength).join('') + .replace(/^-.*/gm, color('$&', 'removed')) + .replace(/^\+.*/gm, color('$&', 'added')) + .replace(/^@@.+@@/gm, color('$&', 'section')) + + return start + end +} + +module.exports = colorize diff --git a/deps/npm/node_modules/@npmcli/disparity-colors/package.json b/deps/npm/node_modules/@npmcli/disparity-colors/package.json new file mode 100644 index 00000000000000..3f389a42c9f99b --- /dev/null +++ b/deps/npm/node_modules/@npmcli/disparity-colors/package.json @@ -0,0 +1,60 @@ +{ + "name": "@npmcli/disparity-colors", + "version": "1.0.1", + "files": [ + "index.js" + ], + "engines": { + "node": ">=10" + }, + "description": "Colorizes unified diff output", + "repository": "https://github.com/npm/disparity-colors", + "keywords": [ + "disparity", + "npm", + "npmcli", + "diff", + "char", + "unified", + "multiline", + "string", + "color", + "ansi", + "terminal", + "cli", + "tty" + ], + "author": "npm Inc. ", + "contributors": [ + { + "name": "Ruy Adorno", + "url": "https://ruyadorno.com", + "twitter": "ruyadorno" + } + ], + "license": "ISC", + "scripts": { + "lint": "standard index.js", + "pretest": "npm run lint", + "test": "tap", + "snap": "tap", + "preversion": "npm test", + "postversion": "npm publish", + "prepublishOnly": "git push origin --follow-tags" + }, + "tap": { + "check-coverage": true + }, + "standard": { + "ignore": [ + "/tap-snapshots/" + ] + }, + "devDependencies": { + "standard": "^16.0.3", + "tap": "^14.11.0" + }, + "dependencies": { + "ansi-styles": "^4.3.0" + } +} diff --git a/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/README.md b/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/README.md deleted file mode 100644 index 423b8cf854ad3e..00000000000000 --- a/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/README.md +++ /dev/null @@ -1,101 +0,0 @@ -[![Build Status](https://travis-ci.org/isaacs/rimraf.svg?branch=master)](https://travis-ci.org/isaacs/rimraf) [![Dependency Status](https://david-dm.org/isaacs/rimraf.svg)](https://david-dm.org/isaacs/rimraf) [![devDependency Status](https://david-dm.org/isaacs/rimraf/dev-status.svg)](https://david-dm.org/isaacs/rimraf#info=devDependencies) - -The [UNIX command](http://en.wikipedia.org/wiki/Rm_(Unix)) `rm -rf` for node. - -Install with `npm install rimraf`, or just drop rimraf.js somewhere. - -## API - -`rimraf(f, [opts], callback)` - -The first parameter will be interpreted as a globbing pattern for files. If you -want to disable globbing you can do so with `opts.disableGlob` (defaults to -`false`). This might be handy, for instance, if you have filenames that contain -globbing wildcard characters. - -The callback will be called with an error if there is one. Certain -errors are handled for you: - -* Windows: `EBUSY` and `ENOTEMPTY` - rimraf will back off a maximum of - `opts.maxBusyTries` times before giving up, adding 100ms of wait - between each attempt. The default `maxBusyTries` is 3. -* `ENOENT` - If the file doesn't exist, rimraf will return - successfully, since your desired outcome is already the case. -* `EMFILE` - Since `readdir` requires opening a file descriptor, it's - possible to hit `EMFILE` if too many file descriptors are in use. - In the sync case, there's nothing to be done for this. But in the - async case, rimraf will gradually back off with timeouts up to - `opts.emfileWait` ms, which defaults to 1000. - -## options - -* unlink, chmod, stat, lstat, rmdir, readdir, - unlinkSync, chmodSync, statSync, lstatSync, rmdirSync, readdirSync - - In order to use a custom file system library, you can override - specific fs functions on the options object. - - If any of these functions are present on the options object, then - the supplied function will be used instead of the default fs - method. - - Sync methods are only relevant for `rimraf.sync()`, of course. - - For example: - - ```javascript - var myCustomFS = require('some-custom-fs') - - rimraf('some-thing', myCustomFS, callback) - ``` - -* maxBusyTries - - If an `EBUSY`, `ENOTEMPTY`, or `EPERM` error code is encountered - on Windows systems, then rimraf will retry with a linear backoff - wait of 100ms longer on each try. The default maxBusyTries is 3. - - Only relevant for async usage. - -* emfileWait - - If an `EMFILE` error is encountered, then rimraf will retry - repeatedly with a linear backoff of 1ms longer on each try, until - the timeout counter hits this max. The default limit is 1000. - - If you repeatedly encounter `EMFILE` errors, then consider using - [graceful-fs](http://npm.im/graceful-fs) in your program. - - Only relevant for async usage. - -* glob - - Set to `false` to disable [glob](http://npm.im/glob) pattern - matching. - - Set to an object to pass options to the glob module. The default - glob options are `{ nosort: true, silent: true }`. - - Glob version 6 is used in this module. - - Relevant for both sync and async usage. - -* disableGlob - - Set to any non-falsey value to disable globbing entirely. - (Equivalent to setting `glob: false`.) - -## rimraf.sync - -It can remove stuff synchronously, too. But that's not so good. Use -the async API. It's better. - -## CLI - -If installed with `npm install rimraf -g` it can be used as a global -command `rimraf [ ...]` which is useful for cross platform support. - -## mkdirp - -If you need to create a directory recursively, check out -[mkdirp](https://github.com/substack/node-mkdirp). diff --git a/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/bin.js b/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/bin.js deleted file mode 100755 index 0d1e17be701ec3..00000000000000 --- a/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/bin.js +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env node - -var rimraf = require('./') - -var help = false -var dashdash = false -var noglob = false -var args = process.argv.slice(2).filter(function(arg) { - if (dashdash) - return !!arg - else if (arg === '--') - dashdash = true - else if (arg === '--no-glob' || arg === '-G') - noglob = true - else if (arg === '--glob' || arg === '-g') - noglob = false - else if (arg.match(/^(-+|\/)(h(elp)?|\?)$/)) - help = true - else - return !!arg -}) - -if (help || args.length === 0) { - // If they didn't ask for help, then this is not a "success" - var log = help ? console.log : console.error - log('Usage: rimraf [ ...]') - log('') - log(' Deletes all files and folders at "path" recursively.') - log('') - log('Options:') - log('') - log(' -h, --help Display this usage info') - log(' -G, --no-glob Do not expand glob patterns in arguments') - log(' -g, --glob Expand glob patterns in arguments (default)') - process.exit(help ? 0 : 1) -} else - go(0) - -function go (n) { - if (n >= args.length) - return - var options = {} - if (noglob) - options = { glob: false } - rimraf(args[n], options, function (er) { - if (er) - throw er - go(n+1) - }) -} diff --git a/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/package.json b/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/package.json deleted file mode 100644 index 26e05d85ea2fdf..00000000000000 --- a/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "rimraf", - "version": "2.7.1", - "main": "rimraf.js", - "description": "A deep deletion module for node (like `rm -rf`)", - "author": "Isaac Z. Schlueter (http://blog.izs.me/)", - "license": "ISC", - "repository": "git://github.com/isaacs/rimraf.git", - "scripts": { - "preversion": "npm test", - "postversion": "npm publish", - "postpublish": "git push origin --all; git push origin --tags", - "test": "tap test/*.js" - }, - "bin": "./bin.js", - "dependencies": { - "glob": "^7.1.3" - }, - "files": [ - "LICENSE", - "README.md", - "bin.js", - "rimraf.js" - ], - "devDependencies": { - "mkdirp": "^0.5.1", - "tap": "^12.1.1" - } -} diff --git a/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/rimraf.js b/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/rimraf.js deleted file mode 100644 index a90ad029f3ece1..00000000000000 --- a/deps/npm/node_modules/@npmcli/move-file/node_modules/rimraf/rimraf.js +++ /dev/null @@ -1,372 +0,0 @@ -module.exports = rimraf -rimraf.sync = rimrafSync - -var assert = require("assert") -var path = require("path") -var fs = require("fs") -var glob = undefined -try { - glob = require("glob") -} catch (_err) { - // treat glob as optional. -} -var _0666 = parseInt('666', 8) - -var defaultGlobOpts = { - nosort: true, - silent: true -} - -// for EMFILE handling -var timeout = 0 - -var isWindows = (process.platform === "win32") - -function defaults (options) { - var methods = [ - 'unlink', - 'chmod', - 'stat', - 'lstat', - 'rmdir', - 'readdir' - ] - methods.forEach(function(m) { - options[m] = options[m] || fs[m] - m = m + 'Sync' - options[m] = options[m] || fs[m] - }) - - options.maxBusyTries = options.maxBusyTries || 3 - options.emfileWait = options.emfileWait || 1000 - if (options.glob === false) { - options.disableGlob = true - } - if (options.disableGlob !== true && glob === undefined) { - throw Error('glob dependency not found, set `options.disableGlob = true` if intentional') - } - options.disableGlob = options.disableGlob || false - options.glob = options.glob || defaultGlobOpts -} - -function rimraf (p, options, cb) { - if (typeof options === 'function') { - cb = options - options = {} - } - - assert(p, 'rimraf: missing path') - assert.equal(typeof p, 'string', 'rimraf: path should be a string') - assert.equal(typeof cb, 'function', 'rimraf: callback function required') - assert(options, 'rimraf: invalid options argument provided') - assert.equal(typeof options, 'object', 'rimraf: options should be object') - - defaults(options) - - var busyTries = 0 - var errState = null - var n = 0 - - if (options.disableGlob || !glob.hasMagic(p)) - return afterGlob(null, [p]) - - options.lstat(p, function (er, stat) { - if (!er) - return afterGlob(null, [p]) - - glob(p, options.glob, afterGlob) - }) - - function next (er) { - errState = errState || er - if (--n === 0) - cb(errState) - } - - function afterGlob (er, results) { - if (er) - return cb(er) - - n = results.length - if (n === 0) - return cb() - - results.forEach(function (p) { - rimraf_(p, options, function CB (er) { - if (er) { - if ((er.code === "EBUSY" || er.code === "ENOTEMPTY" || er.code === "EPERM") && - busyTries < options.maxBusyTries) { - busyTries ++ - var time = busyTries * 100 - // try again, with the same exact callback as this one. - return setTimeout(function () { - rimraf_(p, options, CB) - }, time) - } - - // this one won't happen if graceful-fs is used. - if (er.code === "EMFILE" && timeout < options.emfileWait) { - return setTimeout(function () { - rimraf_(p, options, CB) - }, timeout ++) - } - - // already gone - if (er.code === "ENOENT") er = null - } - - timeout = 0 - next(er) - }) - }) - } -} - -// Two possible strategies. -// 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR -// 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR -// -// Both result in an extra syscall when you guess wrong. However, there -// are likely far more normal files in the world than directories. This -// is based on the assumption that a the average number of files per -// directory is >= 1. -// -// If anyone ever complains about this, then I guess the strategy could -// be made configurable somehow. But until then, YAGNI. -function rimraf_ (p, options, cb) { - assert(p) - assert(options) - assert(typeof cb === 'function') - - // sunos lets the root user unlink directories, which is... weird. - // so we have to lstat here and make sure it's not a dir. - options.lstat(p, function (er, st) { - if (er && er.code === "ENOENT") - return cb(null) - - // Windows can EPERM on stat. Life is suffering. - if (er && er.code === "EPERM" && isWindows) - fixWinEPERM(p, options, er, cb) - - if (st && st.isDirectory()) - return rmdir(p, options, er, cb) - - options.unlink(p, function (er) { - if (er) { - if (er.code === "ENOENT") - return cb(null) - if (er.code === "EPERM") - return (isWindows) - ? fixWinEPERM(p, options, er, cb) - : rmdir(p, options, er, cb) - if (er.code === "EISDIR") - return rmdir(p, options, er, cb) - } - return cb(er) - }) - }) -} - -function fixWinEPERM (p, options, er, cb) { - assert(p) - assert(options) - assert(typeof cb === 'function') - if (er) - assert(er instanceof Error) - - options.chmod(p, _0666, function (er2) { - if (er2) - cb(er2.code === "ENOENT" ? null : er) - else - options.stat(p, function(er3, stats) { - if (er3) - cb(er3.code === "ENOENT" ? null : er) - else if (stats.isDirectory()) - rmdir(p, options, er, cb) - else - options.unlink(p, cb) - }) - }) -} - -function fixWinEPERMSync (p, options, er) { - assert(p) - assert(options) - if (er) - assert(er instanceof Error) - - try { - options.chmodSync(p, _0666) - } catch (er2) { - if (er2.code === "ENOENT") - return - else - throw er - } - - try { - var stats = options.statSync(p) - } catch (er3) { - if (er3.code === "ENOENT") - return - else - throw er - } - - if (stats.isDirectory()) - rmdirSync(p, options, er) - else - options.unlinkSync(p) -} - -function rmdir (p, options, originalEr, cb) { - assert(p) - assert(options) - if (originalEr) - assert(originalEr instanceof Error) - assert(typeof cb === 'function') - - // try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS) - // if we guessed wrong, and it's not a directory, then - // raise the original error. - options.rmdir(p, function (er) { - if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM")) - rmkids(p, options, cb) - else if (er && er.code === "ENOTDIR") - cb(originalEr) - else - cb(er) - }) -} - -function rmkids(p, options, cb) { - assert(p) - assert(options) - assert(typeof cb === 'function') - - options.readdir(p, function (er, files) { - if (er) - return cb(er) - var n = files.length - if (n === 0) - return options.rmdir(p, cb) - var errState - files.forEach(function (f) { - rimraf(path.join(p, f), options, function (er) { - if (errState) - return - if (er) - return cb(errState = er) - if (--n === 0) - options.rmdir(p, cb) - }) - }) - }) -} - -// this looks simpler, and is strictly *faster*, but will -// tie up the JavaScript thread and fail on excessively -// deep directory trees. -function rimrafSync (p, options) { - options = options || {} - defaults(options) - - assert(p, 'rimraf: missing path') - assert.equal(typeof p, 'string', 'rimraf: path should be a string') - assert(options, 'rimraf: missing options') - assert.equal(typeof options, 'object', 'rimraf: options should be object') - - var results - - if (options.disableGlob || !glob.hasMagic(p)) { - results = [p] - } else { - try { - options.lstatSync(p) - results = [p] - } catch (er) { - results = glob.sync(p, options.glob) - } - } - - if (!results.length) - return - - for (var i = 0; i < results.length; i++) { - var p = results[i] - - try { - var st = options.lstatSync(p) - } catch (er) { - if (er.code === "ENOENT") - return - - // Windows can EPERM on stat. Life is suffering. - if (er.code === "EPERM" && isWindows) - fixWinEPERMSync(p, options, er) - } - - try { - // sunos lets the root user unlink directories, which is... weird. - if (st && st.isDirectory()) - rmdirSync(p, options, null) - else - options.unlinkSync(p) - } catch (er) { - if (er.code === "ENOENT") - return - if (er.code === "EPERM") - return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er) - if (er.code !== "EISDIR") - throw er - - rmdirSync(p, options, er) - } - } -} - -function rmdirSync (p, options, originalEr) { - assert(p) - assert(options) - if (originalEr) - assert(originalEr instanceof Error) - - try { - options.rmdirSync(p) - } catch (er) { - if (er.code === "ENOENT") - return - if (er.code === "ENOTDIR") - throw originalEr - if (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM") - rmkidsSync(p, options) - } -} - -function rmkidsSync (p, options) { - assert(p) - assert(options) - options.readdirSync(p).forEach(function (f) { - rimrafSync(path.join(p, f), options) - }) - - // We only end up here once we got ENOTEMPTY at least once, and - // at this point, we are guaranteed to have removed all the kids. - // So, we know that it won't be ENOENT or ENOTDIR or anything else. - // try really hard to delete stuff on windows, because it has a - // PROFOUNDLY annoying habit of not closing handles promptly when - // files are deleted, resulting in spurious ENOTEMPTY errors. - var retries = isWindows ? 100 : 1 - var i = 0 - do { - var threw = true - try { - var ret = options.rmdirSync(p, options) - threw = false - return ret - } finally { - if (++i < retries && threw) - continue - } - } while (true) -} diff --git a/deps/npm/node_modules/@npmcli/move-file/package.json b/deps/npm/node_modules/@npmcli/move-file/package.json index 46b42c9e9aa2b8..28161645d936a2 100644 --- a/deps/npm/node_modules/@npmcli/move-file/package.json +++ b/deps/npm/node_modules/@npmcli/move-file/package.json @@ -1,13 +1,13 @@ { "name": "@npmcli/move-file", - "version": "1.1.0", + "version": "1.1.1", "files": [ "index.js" ], "description": "move a file (fork of move-file)", "dependencies": { "mkdirp": "^1.0.4", - "rimraf": "^2.7.1" + "rimraf": "^3.0.2" }, "devDependencies": { "require-inject": "^1.4.4", diff --git a/deps/npm/node_modules/binary-extensions/binary-extensions.json b/deps/npm/node_modules/binary-extensions/binary-extensions.json new file mode 100644 index 00000000000000..4aab3837893a2c --- /dev/null +++ b/deps/npm/node_modules/binary-extensions/binary-extensions.json @@ -0,0 +1,260 @@ +[ + "3dm", + "3ds", + "3g2", + "3gp", + "7z", + "a", + "aac", + "adp", + "ai", + "aif", + "aiff", + "alz", + "ape", + "apk", + "appimage", + "ar", + "arj", + "asf", + "au", + "avi", + "bak", + "baml", + "bh", + "bin", + "bk", + "bmp", + "btif", + "bz2", + "bzip2", + "cab", + "caf", + "cgm", + "class", + "cmx", + "cpio", + "cr2", + "cur", + "dat", + "dcm", + "deb", + "dex", + "djvu", + "dll", + "dmg", + "dng", + "doc", + "docm", + "docx", + "dot", + "dotm", + "dra", + "DS_Store", + "dsk", + "dts", + "dtshd", + "dvb", + "dwg", + "dxf", + "ecelp4800", + "ecelp7470", + "ecelp9600", + "egg", + "eol", + "eot", + "epub", + "exe", + "f4v", + "fbs", + "fh", + "fla", + "flac", + "flatpak", + "fli", + "flv", + "fpx", + "fst", + "fvt", + "g3", + "gh", + "gif", + "graffle", + "gz", + "gzip", + "h261", + "h263", + "h264", + "icns", + "ico", + "ief", + "img", + "ipa", + "iso", + "jar", + "jpeg", + "jpg", + "jpgv", + "jpm", + "jxr", + "key", + "ktx", + "lha", + "lib", + "lvp", + "lz", + "lzh", + "lzma", + "lzo", + "m3u", + "m4a", + "m4v", + "mar", + "mdi", + "mht", + "mid", + "midi", + "mj2", + "mka", + "mkv", + "mmr", + "mng", + "mobi", + "mov", + "movie", + "mp3", + "mp4", + "mp4a", + "mpeg", + "mpg", + "mpga", + "mxu", + "nef", + "npx", + "numbers", + "nupkg", + "o", + "odp", + "ods", + "odt", + "oga", + "ogg", + "ogv", + "otf", + "ott", + "pages", + "pbm", + "pcx", + "pdb", + "pdf", + "pea", + "pgm", + "pic", + "png", + "pnm", + "pot", + "potm", + "potx", + "ppa", + "ppam", + "ppm", + "pps", + "ppsm", + "ppsx", + "ppt", + "pptm", + "pptx", + "psd", + "pya", + "pyc", + "pyo", + "pyv", + "qt", + "rar", + "ras", + "raw", + "resources", + "rgb", + "rip", + "rlc", + "rmf", + "rmvb", + "rpm", + "rtf", + "rz", + "s3m", + "s7z", + "scpt", + "sgi", + "shar", + "snap", + "sil", + "sketch", + "slk", + "smv", + "snk", + "so", + "stl", + "suo", + "sub", + "swf", + "tar", + "tbz", + "tbz2", + "tga", + "tgz", + "thmx", + "tif", + "tiff", + "tlz", + "ttc", + "ttf", + "txz", + "udf", + "uvh", + "uvi", + "uvm", + "uvp", + "uvs", + "uvu", + "viv", + "vob", + "war", + "wav", + "wax", + "wbmp", + "wdp", + "weba", + "webm", + "webp", + "whl", + "wim", + "wm", + "wma", + "wmv", + "wmx", + "woff", + "woff2", + "wrm", + "wvx", + "xbm", + "xif", + "xla", + "xlam", + "xls", + "xlsb", + "xlsm", + "xlsx", + "xlt", + "xltm", + "xltx", + "xm", + "xmind", + "xpi", + "xpm", + "xwd", + "xz", + "z", + "zip", + "zipx" +] diff --git a/deps/npm/node_modules/binary-extensions/binary-extensions.json.d.ts b/deps/npm/node_modules/binary-extensions/binary-extensions.json.d.ts new file mode 100644 index 00000000000000..94a248c2bcff7d --- /dev/null +++ b/deps/npm/node_modules/binary-extensions/binary-extensions.json.d.ts @@ -0,0 +1,3 @@ +declare const binaryExtensionsJson: readonly string[]; + +export = binaryExtensionsJson; diff --git a/deps/npm/node_modules/binary-extensions/index.d.ts b/deps/npm/node_modules/binary-extensions/index.d.ts new file mode 100644 index 00000000000000..f469ac5fb0fe5f --- /dev/null +++ b/deps/npm/node_modules/binary-extensions/index.d.ts @@ -0,0 +1,14 @@ +/** +List of binary file extensions. + +@example +``` +import binaryExtensions = require('binary-extensions'); + +console.log(binaryExtensions); +//=> ['3ds', '3g2', …] +``` +*/ +declare const binaryExtensions: readonly string[]; + +export = binaryExtensions; diff --git a/deps/npm/node_modules/binary-extensions/index.js b/deps/npm/node_modules/binary-extensions/index.js new file mode 100644 index 00000000000000..d46e4688671141 --- /dev/null +++ b/deps/npm/node_modules/binary-extensions/index.js @@ -0,0 +1 @@ +module.exports = require('./binary-extensions.json'); diff --git a/deps/npm/node_modules/binary-extensions/license b/deps/npm/node_modules/binary-extensions/license new file mode 100644 index 00000000000000..401b1c731bcd3e --- /dev/null +++ b/deps/npm/node_modules/binary-extensions/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2019 Sindre Sorhus (https://sindresorhus.com), Paul Miller (https://paulmillr.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/deps/npm/node_modules/binary-extensions/package.json b/deps/npm/node_modules/binary-extensions/package.json new file mode 100644 index 00000000000000..c4d3641735b91b --- /dev/null +++ b/deps/npm/node_modules/binary-extensions/package.json @@ -0,0 +1,38 @@ +{ + "name": "binary-extensions", + "version": "2.2.0", + "description": "List of binary file extensions", + "license": "MIT", + "repository": "sindresorhus/binary-extensions", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=8" + }, + "scripts": { + "test": "xo && ava && tsd" + }, + "files": [ + "index.js", + "index.d.ts", + "binary-extensions.json", + "binary-extensions.json.d.ts" + ], + "keywords": [ + "binary", + "extensions", + "extension", + "file", + "json", + "list", + "array" + ], + "devDependencies": { + "ava": "^1.4.1", + "tsd": "^0.7.2", + "xo": "^0.24.0" + } +} diff --git a/deps/npm/node_modules/binary-extensions/readme.md b/deps/npm/node_modules/binary-extensions/readme.md new file mode 100644 index 00000000000000..3e25dd835e08b6 --- /dev/null +++ b/deps/npm/node_modules/binary-extensions/readme.md @@ -0,0 +1,41 @@ +# binary-extensions + +> List of binary file extensions + +The list is just a [JSON file](binary-extensions.json) and can be used anywhere. + + +## Install + +``` +$ npm install binary-extensions +``` + + +## Usage + +```js +const binaryExtensions = require('binary-extensions'); + +console.log(binaryExtensions); +//=> ['3ds', '3g2', …] +``` + + +## Related + +- [is-binary-path](https://github.com/sindresorhus/is-binary-path) - Check if a filepath is a binary file +- [text-extensions](https://github.com/sindresorhus/text-extensions) - List of text file extensions + + +--- + +
          + + Get professional support for this package with a Tidelift subscription + +
          + + Tidelift helps make open source sustainable for maintainers while giving companies
          assurances about security, maintenance, and licensing for their dependencies. +
          +
          diff --git a/deps/npm/node_modules/hosted-git-info/CHANGELOG.md b/deps/npm/node_modules/hosted-git-info/CHANGELOG.md index 08f3529de7db2f..3ffcacacc575c0 100644 --- a/deps/npm/node_modules/hosted-git-info/CHANGELOG.md +++ b/deps/npm/node_modules/hosted-git-info/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +## [3.0.8](https://github.com/npm/hosted-git-info/compare/v3.0.7...v3.0.8) (2021-01-28) + + +### Bug Fixes + +* simplify the regular expression for shortcut matching ([bede0dc](https://github.com/npm/hosted-git-info/commit/bede0dc)), closes [#76](https://github.com/npm/hosted-git-info/issues/76) + + + ## [3.0.7](https://github.com/npm/hosted-git-info/compare/v3.0.6...v3.0.7) (2020-10-15) diff --git a/deps/npm/node_modules/hosted-git-info/index.js b/deps/npm/node_modules/hosted-git-info/index.js index 0b08be1553cae1..8b3eaba3da7fb9 100644 --- a/deps/npm/node_modules/hosted-git-info/index.js +++ b/deps/npm/node_modules/hosted-git-info/index.js @@ -41,7 +41,7 @@ function fromUrl (giturl, opts) { isGitHubShorthand(giturl) ? 'github:' + giturl : giturl ) var parsed = parseGitUrl(url) - var shortcutMatch = url.match(new RegExp('^([^:]+):(?:(?:[^@:]+(?:[^@]+)?@)?([^/]*))[/](.+?)(?:[.]git)?($|#)')) + var shortcutMatch = url.match(/^([^:]+):(?:[^@]+@)?(?:([^/]*)\/)?([^#]+)/) var matches = Object.keys(gitHosts).map(function (gitHostName) { try { var gitHostInfo = gitHosts[gitHostName] @@ -55,7 +55,7 @@ function fromUrl (giturl, opts) { var defaultRepresentation = null if (shortcutMatch && shortcutMatch[1] === gitHostName) { user = shortcutMatch[2] && decodeURIComponent(shortcutMatch[2]) - project = decodeURIComponent(shortcutMatch[3]) + project = decodeURIComponent(shortcutMatch[3].replace(/\.git$/, '')) defaultRepresentation = 'shortcut' } else { if (parsed.host && parsed.host !== gitHostInfo.domain && parsed.host.replace(/^www[.]/, '') !== gitHostInfo.domain) return diff --git a/deps/npm/node_modules/hosted-git-info/package.json b/deps/npm/node_modules/hosted-git-info/package.json index 2a0062c8d253c9..32712269f04278 100644 --- a/deps/npm/node_modules/hosted-git-info/package.json +++ b/deps/npm/node_modules/hosted-git-info/package.json @@ -1,6 +1,6 @@ { "name": "hosted-git-info", - "version": "3.0.7", + "version": "3.0.8", "description": "Provides metadata and conversions from repository urls for Github, Bitbucket and Gitlab", "main": "index.js", "repository": { diff --git a/deps/npm/node_modules/libnpmdiff/CHANGELOG.md b/deps/npm/node_modules/libnpmdiff/CHANGELOG.md new file mode 100644 index 00000000000000..a4c3396e117d8a --- /dev/null +++ b/deps/npm/node_modules/libnpmdiff/CHANGELOG.md @@ -0,0 +1,29 @@ +# Changelog + +## 2.0.3 + +- fix name of options sent by the npm cli + +## 2.0.2 + +- fix matching basename file filter + +## 2.0.1 + +- fix for tarballs not listing folder names + +## 2.0.0 + +- API rewrite: + - normalized all options + - specs to compare are now an array +- fix context=0 +- added support to filtering by folder names + +## 1.0.1 + +- fixed nameOnly option + +## 1.0.0 + +- Initial release diff --git a/deps/npm/node_modules/libnpmdiff/LICENSE b/deps/npm/node_modules/libnpmdiff/LICENSE new file mode 100644 index 00000000000000..d3a1cdfd217b64 --- /dev/null +++ b/deps/npm/node_modules/libnpmdiff/LICENSE @@ -0,0 +1,15 @@ +The ISC License + +Copyright (c) GitHub Inc. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/deps/npm/node_modules/libnpmdiff/README.md b/deps/npm/node_modules/libnpmdiff/README.md new file mode 100644 index 00000000000000..41c33d0d110485 --- /dev/null +++ b/deps/npm/node_modules/libnpmdiff/README.md @@ -0,0 +1,97 @@ +# libnpmdiff + +[![npm version](https://img.shields.io/npm/v/libnpmdiff.svg)](https://npm.im/libnpmdiff) +[![license](https://img.shields.io/npm/l/libnpmdiff.svg)](https://npm.im/libnpmdiff) +[![GitHub Actions](https://github.com/npm/libnpmdiff/workflows/node-ci/badge.svg)](https://github.com/npm/libnpmdiff/actions?query=workflow%3Anode-ci) +[![Coverage Status](https://coveralls.io/repos/github/npm/libnpmdiff/badge.svg?branch=main)](https://coveralls.io/github/npm/libnpmdiff?branch=main) + +The registry diff lib. + +## Table of Contents + +* [Example](#example) +* [Install](#install) +* [Contributing](#contributing) +* [API](#api) +* [LICENSE](#license) + +## Example + +```js +const libdiff = require('libnpmdiff') + +const patch = await libdiff([ + 'abbrev@1.1.0', + 'abbrev@1.1.1' +]) +console.log( + patch +) +``` + +Returns: + +```patch +diff --git a/package.json b/package.json +index v1.1.0..v1.1.1 100644 +--- a/package.json ++++ b/package.json +@@ -1,6 +1,6 @@ + { + "name": "abbrev", +- "version": "1.1.0", ++ "version": "1.1.1", + "description": "Like ruby's abbrev module, but in js", + "author": "Isaac Z. Schlueter ", + "main": "abbrev.js", + +``` + +## Install + +`$ npm install libnpmdiff` + +### Contributing + +The npm team enthusiastically welcomes contributions and project participation! +There's a bunch of things you can do if you want to contribute! The +[Contributor Guide](https://github.com/npm/cli/blob/latest/CONTRIBUTING.md) +outlines the process for community interaction and contribution. Please don't +hesitate to jump in if you'd like to, or even ask us questions if something +isn't clear. + +All participants and maintainers in this project are expected to follow the +[npm Code of Conduct](https://www.npmjs.com/policies/conduct), and just +generally be excellent to each other. + +Please refer to the [Changelog](CHANGELOG.md) for project history details, too. + +Happy hacking! + +### API + +#### `> libnpmdif([ a, b ], [opts]) -> Promise` + +Fetches the registry tarballs and compare files between a spec `a` and spec `b`. **npm** spec types are usually described in `@` form but multiple other types are alsos supported, for more info on valid specs take a look at [`npm-package-arg`](https://github.com/npm/npm-package-arg). + +**Options**: + +- `color `: Should add ANSI colors to string output? Defaults to `false`. +- `tagVersionPrefix `: What prefix should be used to define version numbers. Defaults to `v` +- `diffUnified `: How many lines of code to print before/after each diff. Defaults to `3`. +- `diffFiles >`: If set only prints patches for the files listed in this array (also accepts globs). Defaults to `undefined`. +- `diffIgnoreAllSpace `: Whether or not should ignore changes in whitespace (very useful to avoid indentation changes extra diff lines). Defaults to `false`. +- `diffNameOnly `: Prints only file names and no patch diffs. Defaults to `false`. +- `diffNoPrefix `: If true then skips printing any prefixes in filenames. Defaults to `false`. +- `diffSrcPrefix `: Prefix to be used in the filenames from `a`. Defaults to `a/`. +- `diffDstPrefix `: Prefix to be used in the filenames from `b`. Defaults to `b/`. +- `diffText `: Should treat all files as text and try to print diff for binary files. Defaults to `false`. +- ...`cache`, `registry` and other common options accepted by [pacote](https://github.com/npm/pacote#options) + +Returns a `Promise` that fullfils with a `String` containing the resulting patch diffs. + +Throws an error if either `a` or `b` are missing or if trying to diff more than two specs. + +## LICENSE + +[ISC](./LICENSE) diff --git a/deps/npm/node_modules/libnpmdiff/index.js b/deps/npm/node_modules/libnpmdiff/index.js new file mode 100644 index 00000000000000..0bfc8734ef6397 --- /dev/null +++ b/deps/npm/node_modules/libnpmdiff/index.js @@ -0,0 +1,56 @@ +const pacote = require('pacote') + +const formatDiff = require('./lib/format-diff.js') +const untar = require('./lib/untar.js') + +const argsError = () => + Object.assign( + new TypeError('libnpmdiff needs two arguments to compare'), + { code: 'EDIFFARGS' } + ) +const diff = async (specs, opts = {}) => { + if (specs.length !== 2) + throw argsError() + + const [ + aManifest, + bManifest, + ] = + await Promise.all(specs.map(spec => pacote.manifest(spec, opts))) + + const versions = { + a: aManifest.version, + b: bManifest.version, + } + + // fetches tarball using pacote + const [a, b] = await Promise.all([ + pacote.tarball(aManifest._resolved, opts), + pacote.tarball(bManifest._resolved, opts), + ]) + + // read all files + // populates `files` and `refs` + const { + files, + refs, + } = await untar([ + { + prefix: 'a/', + item: a, + }, + { + prefix: 'b/', + item: b, + }, + ], opts) + + return formatDiff({ + files, + opts, + refs, + versions, + }) +} + +module.exports = diff diff --git a/deps/npm/node_modules/libnpmdiff/lib/format-diff.js b/deps/npm/node_modules/libnpmdiff/lib/format-diff.js new file mode 100644 index 00000000000000..979ce8873c54f2 --- /dev/null +++ b/deps/npm/node_modules/libnpmdiff/lib/format-diff.js @@ -0,0 +1,94 @@ +const EOL = '\n' + +const colorizeDiff = require('@npmcli/disparity-colors') +const jsDiff = require('diff') + +const shouldPrintPatch = require('./should-print-patch.js') + +const formatDiff = ({ files, opts = {}, refs, versions }) => { + let res = '' + const srcPrefix = opts.diffNoPrefix ? '' : opts.diffSrcPrefix || 'a/' + const dstPrefix = opts.diffNoPrefix ? '' : opts.diffDstPrefix || 'b/' + + for (const filename of files.values()) { + const names = { + a: `${srcPrefix}${filename}`, + b: `${dstPrefix}${filename}`, + } + + let fileMode = '' + const filenames = { + a: refs.get(`a/${filename}`), + b: refs.get(`b/${filename}`), + } + const contents = { + a: filenames.a && filenames.a.content, + b: filenames.b && filenames.b.content, + } + const modes = { + a: filenames.a && filenames.a.mode, + b: filenames.b && filenames.b.mode, + } + + if (contents.a === contents.b && modes.a === modes.b) + continue + + if (opts.diffNameOnly) { + res += `${filename}${EOL}` + continue + } + + let patch = '' + let headerLength = 0 + const header = str => { + headerLength++ + patch += `${str}${EOL}` + } + + // manually build a git diff-compatible header + header(`diff --git ${names.a} ${names.b}`) + if (modes.a === modes.b) + fileMode = filenames.a.mode + else { + if (modes.a && !modes.b) + header(`deleted file mode ${modes.a}`) + else if (!modes.a && modes.b) + header(`new file mode ${modes.b}`) + else { + header(`old mode ${modes.a}`) + header(`new mode ${modes.b}`) + } + } + header(`index ${opts.tagVersionPrefix || 'v'}${versions.a}..${opts.tagVersionPrefix || 'v'}${versions.b} ${fileMode}`) + + if (shouldPrintPatch(filename)) { + patch += jsDiff.createTwoFilesPatch( + names.a, + names.b, + contents.a || '', + contents.b || '', + '', + '', + { + context: opts.diffUnified === 0 ? 0 : opts.diffUnified || 3, + ignoreWhitespace: opts.diffIgnoreAllSpace, + } + ).replace( + '===================================================================\n', + '' + ).replace(/\t\n/g, '\n') // strip trailing tabs + headerLength += 2 + } else { + header(`--- ${names.a}`) + header(`+++ ${names.b}`) + } + + res += (opts.color + ? colorizeDiff(patch, { headerLength }) + : patch) + } + + return res.trim() +} + +module.exports = formatDiff diff --git a/deps/npm/node_modules/libnpmdiff/lib/should-print-patch.js b/deps/npm/node_modules/libnpmdiff/lib/should-print-patch.js new file mode 100644 index 00000000000000..aeb015c1a04b33 --- /dev/null +++ b/deps/npm/node_modules/libnpmdiff/lib/should-print-patch.js @@ -0,0 +1,21 @@ +const { basename, extname } = require('path') + +const binaryExtensions = require('binary-extensions') + +// we should try to print patches as long as the +// extension is not identified as binary files +const shouldPrintPatch = (path, opts = {}) => { + if (opts.diffText) + return true + + const filename = basename(path) + const extension = ( + filename.startsWith('.') + ? filename + : extname(filename) + ).substr(1) + + return !binaryExtensions.includes(extension) +} + +module.exports = shouldPrintPatch diff --git a/deps/npm/node_modules/libnpmdiff/lib/untar.js b/deps/npm/node_modules/libnpmdiff/lib/untar.js new file mode 100644 index 00000000000000..16b69ab8fdd010 --- /dev/null +++ b/deps/npm/node_modules/libnpmdiff/lib/untar.js @@ -0,0 +1,96 @@ +const tar = require('tar') +const minimatch = require('minimatch') + +const normalizeMatch = str => str + .replace(/\\+/g, '/') + .replace(/^\.\/|^\./, '') + +// files and refs are mutating params +// filterFiles, item, prefix and opts are read-only options +const untar = ({ files, refs }, { filterFiles, item, prefix }) => { + tar.list({ + filter: (path, entry) => { + const fileMatch = () => + (!filterFiles.length || + filterFiles.some(f => { + const pattern = normalizeMatch(f) + return minimatch( + normalizeMatch(path), + `{package/,}${pattern}`, + { matchBase: pattern.startsWith('*') } + ) + })) + + // expands usage of simple path filters, e.g: lib or src/ + const folderMatch = () => + filterFiles.some(f => + normalizeMatch(path).startsWith(normalizeMatch(f)) || + normalizeMatch(path).startsWith(`package/${normalizeMatch(f)}`)) + + if ( + entry.type === 'File' && + (fileMatch() || folderMatch()) + ) { + const key = path.replace(/^[^/]+\/?/, '') + files.add(key) + + // should skip reading file when using --name-only option + let content + try { + entry.setEncoding('utf8') + content = entry.concat() + } catch (e) { + /* istanbul ignore next */ + throw Object.assign( + new Error('failed to read files'), + { code: 'EDIFFUNTAR' } + ) + } + + refs.set(`${prefix}${key}`, { + content, + mode: `100${entry.mode.toString(8)}`, + }) + return true + } + }, + }) + .on('error', /* istanbul ignore next */ e => { + throw e + }) + .end(item) +} + +const readTarballs = async (tarballs, opts = {}) => { + const files = new Set() + const refs = new Map() + const arr = [].concat(tarballs) + + const filterFiles = opts.diffFiles || [] + + for (const i of arr) { + untar({ + files, + refs, + }, { + item: i.item, + prefix: i.prefix, + filterFiles, + }) + } + + // await to read all content from included files + const allRefs = [...refs.values()] + const contents = await Promise.all(allRefs.map(async ref => ref.content)) + + contents.forEach((content, index) => { + allRefs[index].content = content + }) + + return { + files, + refs, + } +} + +module.exports = readTarballs diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/CONTRIBUTING.md b/deps/npm/node_modules/libnpmdiff/node_modules/diff/CONTRIBUTING.md new file mode 100644 index 00000000000000..c8c4fe6cc225cc --- /dev/null +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/CONTRIBUTING.md @@ -0,0 +1,39 @@ +# How to Contribute + +## Pull Requests + +We also accept [pull requests][pull-request]! + +Generally we like to see pull requests that + +- Maintain the existing code style +- Are focused on a single change (i.e. avoid large refactoring or style adjustments in untouched code if not the primary goal of the pull request) +- Have [good commit messages](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) +- Have tests +- Don't decrease the current code coverage (see coverage/lcov-report/index.html) + +## Building + +``` +npm install +npm test +``` + +The `npm test -- dev` implements watching for tests within Node and `karma start` may be used for manual testing in browsers. + +If you notice any problems, please report them to the GitHub issue tracker at +[http://github.com/kpdecker/jsdiff/issues](http://github.com/kpdecker/jsdiff/issues). + +## Releasing + +JsDiff utilizes the [release yeoman generator][generator-release] to perform most release tasks. + +A full release may be completed with the following: + +``` +yo release +npm publish +``` + +[generator-release]: https://github.com/walmartlabs/generator-release +[pull-request]: https://github.com/kpdecker/jsdiff/pull/new/master diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/LICENSE b/deps/npm/node_modules/libnpmdiff/node_modules/diff/LICENSE new file mode 100644 index 00000000000000..4e7146ed78a2f2 --- /dev/null +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/LICENSE @@ -0,0 +1,31 @@ +Software License Agreement (BSD License) + +Copyright (c) 2009-2015, Kevin Decker + +All rights reserved. + +Redistribution and use of this software in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of Kevin Decker nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/README.md b/deps/npm/node_modules/libnpmdiff/node_modules/diff/README.md new file mode 100644 index 00000000000000..d7fb897311d74f --- /dev/null +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/README.md @@ -0,0 +1,208 @@ +# jsdiff + +[![Build Status](https://secure.travis-ci.org/kpdecker/jsdiff.svg)](http://travis-ci.org/kpdecker/jsdiff) +[![Sauce Test Status](https://saucelabs.com/buildstatus/jsdiff)](https://saucelabs.com/u/jsdiff) + +A javascript text differencing implementation. + +Based on the algorithm proposed in +["An O(ND) Difference Algorithm and its Variations" (Myers, 1986)](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927). + +## Installation +```bash +npm install diff --save +``` + +## API + +* `Diff.diffChars(oldStr, newStr[, options])` - diffs two blocks of text, comparing character by character. + + Returns a list of change objects (See below). + + Options + * `ignoreCase`: `true` to ignore casing difference. Defaults to `false`. + +* `Diff.diffWords(oldStr, newStr[, options])` - diffs two blocks of text, comparing word by word, ignoring whitespace. + + Returns a list of change objects (See below). + + Options + * `ignoreCase`: Same as in `diffChars`. + +* `Diff.diffWordsWithSpace(oldStr, newStr[, options])` - diffs two blocks of text, comparing word by word, treating whitespace as significant. + + Returns a list of change objects (See below). + +* `Diff.diffLines(oldStr, newStr[, options])` - diffs two blocks of text, comparing line by line. + + Options + * `ignoreWhitespace`: `true` to ignore leading and trailing whitespace. This is the same as `diffTrimmedLines` + * `newlineIsToken`: `true` to treat newline characters as separate tokens. This allows for changes to the newline structure to occur independently of the line content and to be treated as such. In general this is the more human friendly form of `diffLines` and `diffLines` is better suited for patches and other computer friendly output. + + Returns a list of change objects (See below). + +* `Diff.diffTrimmedLines(oldStr, newStr[, options])` - diffs two blocks of text, comparing line by line, ignoring leading and trailing whitespace. + + Returns a list of change objects (See below). + +* `Diff.diffSentences(oldStr, newStr[, options])` - diffs two blocks of text, comparing sentence by sentence. + + Returns a list of change objects (See below). + +* `Diff.diffCss(oldStr, newStr[, options])` - diffs two blocks of text, comparing CSS tokens. + + Returns a list of change objects (See below). + +* `Diff.diffJson(oldObj, newObj[, options])` - diffs two JSON objects, comparing the fields defined on each. The order of fields, etc does not matter in this comparison. + + Returns a list of change objects (See below). + +* `Diff.diffArrays(oldArr, newArr[, options])` - diffs two arrays, comparing each item for strict equality (===). + + Options + * `comparator`: `function(left, right)` for custom equality checks + + Returns a list of change objects (See below). + +* `Diff.createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader)` - creates a unified diff patch. + + Parameters: + * `oldFileName` : String to be output in the filename section of the patch for the removals + * `newFileName` : String to be output in the filename section of the patch for the additions + * `oldStr` : Original string value + * `newStr` : New string value + * `oldHeader` : Additional information to include in the old file header + * `newHeader` : Additional information to include in the new file header + * `options` : An object with options. Currently, only `context` is supported and describes how many lines of context should be included. + +* `Diff.createPatch(fileName, oldStr, newStr, oldHeader, newHeader)` - creates a unified diff patch. + + Just like Diff.createTwoFilesPatch, but with oldFileName being equal to newFileName. + + +* `Diff.structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options)` - returns an object with an array of hunk objects. + + This method is similar to createTwoFilesPatch, but returns a data structure + suitable for further processing. Parameters are the same as createTwoFilesPatch. The data structure returned may look like this: + + ```js + { + oldFileName: 'oldfile', newFileName: 'newfile', + oldHeader: 'header1', newHeader: 'header2', + hunks: [{ + oldStart: 1, oldLines: 3, newStart: 1, newLines: 3, + lines: [' line2', ' line3', '-line4', '+line5', '\\ No newline at end of file'], + }] + } + ``` + +* `Diff.applyPatch(source, patch[, options])` - applies a unified diff patch. + + Return a string containing new version of provided data. `patch` may be a string diff or the output from the `parsePatch` or `structuredPatch` methods. + + The optional `options` object may have the following keys: + + - `fuzzFactor`: Number of lines that are allowed to differ before rejecting a patch. Defaults to 0. + - `compareLine(lineNumber, line, operation, patchContent)`: Callback used to compare to given lines to determine if they should be considered equal when patching. Defaults to strict equality but may be overridden to provide fuzzier comparison. Should return false if the lines should be rejected. + +* `Diff.applyPatches(patch, options)` - applies one or more patches. + + This method will iterate over the contents of the patch and apply to data provided through callbacks. The general flow for each patch index is: + + - `options.loadFile(index, callback)` is called. The caller should then load the contents of the file and then pass that to the `callback(err, data)` callback. Passing an `err` will terminate further patch execution. + - `options.patched(index, content, callback)` is called once the patch has been applied. `content` will be the return value from `applyPatch`. When it's ready, the caller should call `callback(err)` callback. Passing an `err` will terminate further patch execution. + + Once all patches have been applied or an error occurs, the `options.complete(err)` callback is made. + +* `Diff.parsePatch(diffStr)` - Parses a patch into structured data + + Return a JSON object representation of the a patch, suitable for use with the `applyPatch` method. This parses to the same structure returned by `Diff.structuredPatch`. + +* `convertChangesToXML(changes)` - converts a list of changes to a serialized XML format + + +All methods above which accept the optional `callback` method will run in sync mode when that parameter is omitted and in async mode when supplied. This allows for larger diffs without blocking the event loop. This may be passed either directly as the final parameter or as the `callback` field in the `options` object. + +### Change Objects +Many of the methods above return change objects. These objects consist of the following fields: + +* `value`: Text content +* `added`: True if the value was inserted into the new string +* `removed`: True if the value was removed from the old string + +Note that some cases may omit a particular flag field. Comparison on the flag fields should always be done in a truthy or falsy manner. + +## Examples + +Basic example in Node + +```js +require('colors'); +const Diff = require('diff'); + +const one = 'beep boop'; +const other = 'beep boob blah'; + +const diff = Diff.diffChars(one, other); + +diff.forEach((part) => { + // green for additions, red for deletions + // grey for common parts + const color = part.added ? 'green' : + part.removed ? 'red' : 'grey'; + process.stderr.write(part.value[color]); +}); + +console.log(); +``` +Running the above program should yield + +Node Example + +Basic example in a web page + +```html +
          
          +
          +
          +```
          +
          +Open the above .html file in a browser and you should see
          +
          +Node Example
          +
          +**[Full online demo](http://kpdecker.github.com/jsdiff)**
          +
          +## Compatibility
          +
          +[![Sauce Test Status](https://saucelabs.com/browser-matrix/jsdiff.svg)](https://saucelabs.com/u/jsdiff)
          +
          +jsdiff supports all ES3 environments with some known issues on IE8 and below. Under these browsers some diff algorithms such as word diff and others may fail due to lack of support for capturing groups in the `split` operation.
          +
          +## License
          +
          +See [LICENSE](https://github.com/kpdecker/jsdiff/blob/master/LICENSE).
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/dist/diff.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/dist/diff.js
          new file mode 100644
          index 00000000000000..bba91954f4b23b
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/dist/diff.js
          @@ -0,0 +1,1582 @@
          +(function (global, factory) {
          +  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
          +  typeof define === 'function' && define.amd ? define(['exports'], factory) :
          +  (global = global || self, factory(global.Diff = {}));
          +}(this, (function (exports) { 'use strict';
          +
          +  function Diff() {}
          +  Diff.prototype = {
          +    diff: function diff(oldString, newString) {
          +      var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
          +      var callback = options.callback;
          +
          +      if (typeof options === 'function') {
          +        callback = options;
          +        options = {};
          +      }
          +
          +      this.options = options;
          +      var self = this;
          +
          +      function done(value) {
          +        if (callback) {
          +          setTimeout(function () {
          +            callback(undefined, value);
          +          }, 0);
          +          return true;
          +        } else {
          +          return value;
          +        }
          +      } // Allow subclasses to massage the input prior to running
          +
          +
          +      oldString = this.castInput(oldString);
          +      newString = this.castInput(newString);
          +      oldString = this.removeEmpty(this.tokenize(oldString));
          +      newString = this.removeEmpty(this.tokenize(newString));
          +      var newLen = newString.length,
          +          oldLen = oldString.length;
          +      var editLength = 1;
          +      var maxEditLength = newLen + oldLen;
          +      var bestPath = [{
          +        newPos: -1,
          +        components: []
          +      }]; // Seed editLength = 0, i.e. the content starts with the same values
          +
          +      var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
          +
          +      if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
          +        // Identity per the equality and tokenizer
          +        return done([{
          +          value: this.join(newString),
          +          count: newString.length
          +        }]);
          +      } // Main worker method. checks all permutations of a given edit length for acceptance.
          +
          +
          +      function execEditLength() {
          +        for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
          +          var basePath = void 0;
          +
          +          var addPath = bestPath[diagonalPath - 1],
          +              removePath = bestPath[diagonalPath + 1],
          +              _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
          +
          +          if (addPath) {
          +            // No one else is going to attempt to use this value, clear it
          +            bestPath[diagonalPath - 1] = undefined;
          +          }
          +
          +          var canAdd = addPath && addPath.newPos + 1 < newLen,
          +              canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
          +
          +          if (!canAdd && !canRemove) {
          +            // If this path is a terminal then prune
          +            bestPath[diagonalPath] = undefined;
          +            continue;
          +          } // Select the diagonal that we want to branch from. We select the prior
          +          // path whose position in the new string is the farthest from the origin
          +          // and does not pass the bounds of the diff graph
          +
          +
          +          if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
          +            basePath = clonePath(removePath);
          +            self.pushComponent(basePath.components, undefined, true);
          +          } else {
          +            basePath = addPath; // No need to clone, we've pulled it from the list
          +
          +            basePath.newPos++;
          +            self.pushComponent(basePath.components, true, undefined);
          +          }
          +
          +          _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
          +
          +          if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
          +            return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
          +          } else {
          +            // Otherwise track this path as a potential candidate and continue.
          +            bestPath[diagonalPath] = basePath;
          +          }
          +        }
          +
          +        editLength++;
          +      } // Performs the length of edit iteration. Is a bit fugly as this has to support the
          +      // sync and async mode which is never fun. Loops over execEditLength until a value
          +      // is produced.
          +
          +
          +      if (callback) {
          +        (function exec() {
          +          setTimeout(function () {
          +            // This should not happen, but we want to be safe.
          +
          +            /* istanbul ignore next */
          +            if (editLength > maxEditLength) {
          +              return callback();
          +            }
          +
          +            if (!execEditLength()) {
          +              exec();
          +            }
          +          }, 0);
          +        })();
          +      } else {
          +        while (editLength <= maxEditLength) {
          +          var ret = execEditLength();
          +
          +          if (ret) {
          +            return ret;
          +          }
          +        }
          +      }
          +    },
          +    pushComponent: function pushComponent(components, added, removed) {
          +      var last = components[components.length - 1];
          +
          +      if (last && last.added === added && last.removed === removed) {
          +        // We need to clone here as the component clone operation is just
          +        // as shallow array clone
          +        components[components.length - 1] = {
          +          count: last.count + 1,
          +          added: added,
          +          removed: removed
          +        };
          +      } else {
          +        components.push({
          +          count: 1,
          +          added: added,
          +          removed: removed
          +        });
          +      }
          +    },
          +    extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
          +      var newLen = newString.length,
          +          oldLen = oldString.length,
          +          newPos = basePath.newPos,
          +          oldPos = newPos - diagonalPath,
          +          commonCount = 0;
          +
          +      while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
          +        newPos++;
          +        oldPos++;
          +        commonCount++;
          +      }
          +
          +      if (commonCount) {
          +        basePath.components.push({
          +          count: commonCount
          +        });
          +      }
          +
          +      basePath.newPos = newPos;
          +      return oldPos;
          +    },
          +    equals: function equals(left, right) {
          +      if (this.options.comparator) {
          +        return this.options.comparator(left, right);
          +      } else {
          +        return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
          +      }
          +    },
          +    removeEmpty: function removeEmpty(array) {
          +      var ret = [];
          +
          +      for (var i = 0; i < array.length; i++) {
          +        if (array[i]) {
          +          ret.push(array[i]);
          +        }
          +      }
          +
          +      return ret;
          +    },
          +    castInput: function castInput(value) {
          +      return value;
          +    },
          +    tokenize: function tokenize(value) {
          +      return value.split('');
          +    },
          +    join: function join(chars) {
          +      return chars.join('');
          +    }
          +  };
          +
          +  function buildValues(diff, components, newString, oldString, useLongestToken) {
          +    var componentPos = 0,
          +        componentLen = components.length,
          +        newPos = 0,
          +        oldPos = 0;
          +
          +    for (; componentPos < componentLen; componentPos++) {
          +      var component = components[componentPos];
          +
          +      if (!component.removed) {
          +        if (!component.added && useLongestToken) {
          +          var value = newString.slice(newPos, newPos + component.count);
          +          value = value.map(function (value, i) {
          +            var oldValue = oldString[oldPos + i];
          +            return oldValue.length > value.length ? oldValue : value;
          +          });
          +          component.value = diff.join(value);
          +        } else {
          +          component.value = diff.join(newString.slice(newPos, newPos + component.count));
          +        }
          +
          +        newPos += component.count; // Common case
          +
          +        if (!component.added) {
          +          oldPos += component.count;
          +        }
          +      } else {
          +        component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
          +        oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
          +        // The diffing algorithm is tied to add then remove output and this is the simplest
          +        // route to get the desired output with minimal overhead.
          +
          +        if (componentPos && components[componentPos - 1].added) {
          +          var tmp = components[componentPos - 1];
          +          components[componentPos - 1] = components[componentPos];
          +          components[componentPos] = tmp;
          +        }
          +      }
          +    } // Special case handle for when one terminal is ignored (i.e. whitespace).
          +    // For this case we merge the terminal into the prior string and drop the change.
          +    // This is only available for string mode.
          +
          +
          +    var lastComponent = components[componentLen - 1];
          +
          +    if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
          +      components[componentLen - 2].value += lastComponent.value;
          +      components.pop();
          +    }
          +
          +    return components;
          +  }
          +
          +  function clonePath(path) {
          +    return {
          +      newPos: path.newPos,
          +      components: path.components.slice(0)
          +    };
          +  }
          +
          +  var characterDiff = new Diff();
          +  function diffChars(oldStr, newStr, options) {
          +    return characterDiff.diff(oldStr, newStr, options);
          +  }
          +
          +  function generateOptions(options, defaults) {
          +    if (typeof options === 'function') {
          +      defaults.callback = options;
          +    } else if (options) {
          +      for (var name in options) {
          +        /* istanbul ignore else */
          +        if (options.hasOwnProperty(name)) {
          +          defaults[name] = options[name];
          +        }
          +      }
          +    }
          +
          +    return defaults;
          +  }
          +
          +  //
          +  // Ranges and exceptions:
          +  // Latin-1 Supplement, 0080–00FF
          +  //  - U+00D7  × Multiplication sign
          +  //  - U+00F7  ÷ Division sign
          +  // Latin Extended-A, 0100–017F
          +  // Latin Extended-B, 0180–024F
          +  // IPA Extensions, 0250–02AF
          +  // Spacing Modifier Letters, 02B0–02FF
          +  //  - U+02C7  ˇ ˇ  Caron
          +  //  - U+02D8  ˘ ˘  Breve
          +  //  - U+02D9  ˙ ˙  Dot Above
          +  //  - U+02DA  ˚ ˚  Ring Above
          +  //  - U+02DB  ˛ ˛  Ogonek
          +  //  - U+02DC  ˜ ˜  Small Tilde
          +  //  - U+02DD  ˝ ˝  Double Acute Accent
          +  // Latin Extended Additional, 1E00–1EFF
          +
          +  var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
          +  var reWhitespace = /\S/;
          +  var wordDiff = new Diff();
          +
          +  wordDiff.equals = function (left, right) {
          +    if (this.options.ignoreCase) {
          +      left = left.toLowerCase();
          +      right = right.toLowerCase();
          +    }
          +
          +    return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
          +  };
          +
          +  wordDiff.tokenize = function (value) {
          +    // All whitespace symbols except newline group into one token, each newline - in separate token
          +    var tokens = value.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/); // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
          +
          +    for (var i = 0; i < tokens.length - 1; i++) {
          +      // If we have an empty string in the next field and we have only word chars before and after, merge
          +      if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
          +        tokens[i] += tokens[i + 2];
          +        tokens.splice(i + 1, 2);
          +        i--;
          +      }
          +    }
          +
          +    return tokens;
          +  };
          +
          +  function diffWords(oldStr, newStr, options) {
          +    options = generateOptions(options, {
          +      ignoreWhitespace: true
          +    });
          +    return wordDiff.diff(oldStr, newStr, options);
          +  }
          +  function diffWordsWithSpace(oldStr, newStr, options) {
          +    return wordDiff.diff(oldStr, newStr, options);
          +  }
          +
          +  var lineDiff = new Diff();
          +
          +  lineDiff.tokenize = function (value) {
          +    var retLines = [],
          +        linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
          +
          +    if (!linesAndNewlines[linesAndNewlines.length - 1]) {
          +      linesAndNewlines.pop();
          +    } // Merge the content and line separators into single tokens
          +
          +
          +    for (var i = 0; i < linesAndNewlines.length; i++) {
          +      var line = linesAndNewlines[i];
          +
          +      if (i % 2 && !this.options.newlineIsToken) {
          +        retLines[retLines.length - 1] += line;
          +      } else {
          +        if (this.options.ignoreWhitespace) {
          +          line = line.trim();
          +        }
          +
          +        retLines.push(line);
          +      }
          +    }
          +
          +    return retLines;
          +  };
          +
          +  function diffLines(oldStr, newStr, callback) {
          +    return lineDiff.diff(oldStr, newStr, callback);
          +  }
          +  function diffTrimmedLines(oldStr, newStr, callback) {
          +    var options = generateOptions(callback, {
          +      ignoreWhitespace: true
          +    });
          +    return lineDiff.diff(oldStr, newStr, options);
          +  }
          +
          +  var sentenceDiff = new Diff();
          +
          +  sentenceDiff.tokenize = function (value) {
          +    return value.split(/(\S.+?[.!?])(?=\s+|$)/);
          +  };
          +
          +  function diffSentences(oldStr, newStr, callback) {
          +    return sentenceDiff.diff(oldStr, newStr, callback);
          +  }
          +
          +  var cssDiff = new Diff();
          +
          +  cssDiff.tokenize = function (value) {
          +    return value.split(/([{}:;,]|\s+)/);
          +  };
          +
          +  function diffCss(oldStr, newStr, callback) {
          +    return cssDiff.diff(oldStr, newStr, callback);
          +  }
          +
          +  function _typeof(obj) {
          +    "@babel/helpers - typeof";
          +
          +    if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
          +      _typeof = function (obj) {
          +        return typeof obj;
          +      };
          +    } else {
          +      _typeof = function (obj) {
          +        return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
          +      };
          +    }
          +
          +    return _typeof(obj);
          +  }
          +
          +  function _toConsumableArray(arr) {
          +    return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
          +  }
          +
          +  function _arrayWithoutHoles(arr) {
          +    if (Array.isArray(arr)) return _arrayLikeToArray(arr);
          +  }
          +
          +  function _iterableToArray(iter) {
          +    if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
          +  }
          +
          +  function _unsupportedIterableToArray(o, minLen) {
          +    if (!o) return;
          +    if (typeof o === "string") return _arrayLikeToArray(o, minLen);
          +    var n = Object.prototype.toString.call(o).slice(8, -1);
          +    if (n === "Object" && o.constructor) n = o.constructor.name;
          +    if (n === "Map" || n === "Set") return Array.from(o);
          +    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
          +  }
          +
          +  function _arrayLikeToArray(arr, len) {
          +    if (len == null || len > arr.length) len = arr.length;
          +
          +    for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
          +
          +    return arr2;
          +  }
          +
          +  function _nonIterableSpread() {
          +    throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
          +  }
          +
          +  var objectPrototypeToString = Object.prototype.toString;
          +  var jsonDiff = new Diff(); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
          +  // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
          +
          +  jsonDiff.useLongestToken = true;
          +  jsonDiff.tokenize = lineDiff.tokenize;
          +
          +  jsonDiff.castInput = function (value) {
          +    var _this$options = this.options,
          +        undefinedReplacement = _this$options.undefinedReplacement,
          +        _this$options$stringi = _this$options.stringifyReplacer,
          +        stringifyReplacer = _this$options$stringi === void 0 ? function (k, v) {
          +      return typeof v === 'undefined' ? undefinedReplacement : v;
          +    } : _this$options$stringi;
          +    return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, '  ');
          +  };
          +
          +  jsonDiff.equals = function (left, right) {
          +    return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
          +  };
          +
          +  function diffJson(oldObj, newObj, options) {
          +    return jsonDiff.diff(oldObj, newObj, options);
          +  } // This function handles the presence of circular references by bailing out when encountering an
          +  // object that is already on the "stack" of items being processed. Accepts an optional replacer
          +
          +  function canonicalize(obj, stack, replacementStack, replacer, key) {
          +    stack = stack || [];
          +    replacementStack = replacementStack || [];
          +
          +    if (replacer) {
          +      obj = replacer(key, obj);
          +    }
          +
          +    var i;
          +
          +    for (i = 0; i < stack.length; i += 1) {
          +      if (stack[i] === obj) {
          +        return replacementStack[i];
          +      }
          +    }
          +
          +    var canonicalizedObj;
          +
          +    if ('[object Array]' === objectPrototypeToString.call(obj)) {
          +      stack.push(obj);
          +      canonicalizedObj = new Array(obj.length);
          +      replacementStack.push(canonicalizedObj);
          +
          +      for (i = 0; i < obj.length; i += 1) {
          +        canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
          +      }
          +
          +      stack.pop();
          +      replacementStack.pop();
          +      return canonicalizedObj;
          +    }
          +
          +    if (obj && obj.toJSON) {
          +      obj = obj.toJSON();
          +    }
          +
          +    if (_typeof(obj) === 'object' && obj !== null) {
          +      stack.push(obj);
          +      canonicalizedObj = {};
          +      replacementStack.push(canonicalizedObj);
          +
          +      var sortedKeys = [],
          +          _key;
          +
          +      for (_key in obj) {
          +        /* istanbul ignore else */
          +        if (obj.hasOwnProperty(_key)) {
          +          sortedKeys.push(_key);
          +        }
          +      }
          +
          +      sortedKeys.sort();
          +
          +      for (i = 0; i < sortedKeys.length; i += 1) {
          +        _key = sortedKeys[i];
          +        canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
          +      }
          +
          +      stack.pop();
          +      replacementStack.pop();
          +    } else {
          +      canonicalizedObj = obj;
          +    }
          +
          +    return canonicalizedObj;
          +  }
          +
          +  var arrayDiff = new Diff();
          +
          +  arrayDiff.tokenize = function (value) {
          +    return value.slice();
          +  };
          +
          +  arrayDiff.join = arrayDiff.removeEmpty = function (value) {
          +    return value;
          +  };
          +
          +  function diffArrays(oldArr, newArr, callback) {
          +    return arrayDiff.diff(oldArr, newArr, callback);
          +  }
          +
          +  function parsePatch(uniDiff) {
          +    var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
          +    var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
          +        delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
          +        list = [],
          +        i = 0;
          +
          +    function parseIndex() {
          +      var index = {};
          +      list.push(index); // Parse diff metadata
          +
          +      while (i < diffstr.length) {
          +        var line = diffstr[i]; // File header found, end parsing diff metadata
          +
          +        if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
          +          break;
          +        } // Diff index
          +
          +
          +        var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
          +
          +        if (header) {
          +          index.index = header[1];
          +        }
          +
          +        i++;
          +      } // Parse file headers if they are defined. Unified diff requires them, but
          +      // there's no technical issues to have an isolated hunk without file header
          +
          +
          +      parseFileHeader(index);
          +      parseFileHeader(index); // Parse hunks
          +
          +      index.hunks = [];
          +
          +      while (i < diffstr.length) {
          +        var _line = diffstr[i];
          +
          +        if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
          +          break;
          +        } else if (/^@@/.test(_line)) {
          +          index.hunks.push(parseHunk());
          +        } else if (_line && options.strict) {
          +          // Ignore unexpected content unless in strict mode
          +          throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
          +        } else {
          +          i++;
          +        }
          +      }
          +    } // Parses the --- and +++ headers, if none are found, no lines
          +    // are consumed.
          +
          +
          +    function parseFileHeader(index) {
          +      var fileHeader = /^(---|\+\+\+)\s+(.*)$/.exec(diffstr[i]);
          +
          +      if (fileHeader) {
          +        var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
          +        var data = fileHeader[2].split('\t', 2);
          +        var fileName = data[0].replace(/\\\\/g, '\\');
          +
          +        if (/^".*"$/.test(fileName)) {
          +          fileName = fileName.substr(1, fileName.length - 2);
          +        }
          +
          +        index[keyPrefix + 'FileName'] = fileName;
          +        index[keyPrefix + 'Header'] = (data[1] || '').trim();
          +        i++;
          +      }
          +    } // Parses a hunk
          +    // This assumes that we are at the start of a hunk.
          +
          +
          +    function parseHunk() {
          +      var chunkHeaderIndex = i,
          +          chunkHeaderLine = diffstr[i++],
          +          chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
          +      var hunk = {
          +        oldStart: +chunkHeader[1],
          +        oldLines: typeof chunkHeader[2] === 'undefined' ? 1 : +chunkHeader[2],
          +        newStart: +chunkHeader[3],
          +        newLines: typeof chunkHeader[4] === 'undefined' ? 1 : +chunkHeader[4],
          +        lines: [],
          +        linedelimiters: []
          +      }; // Unified Diff Format quirk: If the chunk size is 0,
          +      // the first number is one lower than one would expect.
          +      // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
          +
          +      if (hunk.oldLines === 0) {
          +        hunk.oldStart += 1;
          +      }
          +
          +      if (hunk.newLines === 0) {
          +        hunk.newStart += 1;
          +      }
          +
          +      var addCount = 0,
          +          removeCount = 0;
          +
          +      for (; i < diffstr.length; i++) {
          +        // Lines starting with '---' could be mistaken for the "remove line" operation
          +        // But they could be the header for the next file. Therefore prune such cases out.
          +        if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
          +          break;
          +        }
          +
          +        var operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? ' ' : diffstr[i][0];
          +
          +        if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
          +          hunk.lines.push(diffstr[i]);
          +          hunk.linedelimiters.push(delimiters[i] || '\n');
          +
          +          if (operation === '+') {
          +            addCount++;
          +          } else if (operation === '-') {
          +            removeCount++;
          +          } else if (operation === ' ') {
          +            addCount++;
          +            removeCount++;
          +          }
          +        } else {
          +          break;
          +        }
          +      } // Handle the empty block count case
          +
          +
          +      if (!addCount && hunk.newLines === 1) {
          +        hunk.newLines = 0;
          +      }
          +
          +      if (!removeCount && hunk.oldLines === 1) {
          +        hunk.oldLines = 0;
          +      } // Perform optional sanity checking
          +
          +
          +      if (options.strict) {
          +        if (addCount !== hunk.newLines) {
          +          throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
          +        }
          +
          +        if (removeCount !== hunk.oldLines) {
          +          throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
          +        }
          +      }
          +
          +      return hunk;
          +    }
          +
          +    while (i < diffstr.length) {
          +      parseIndex();
          +    }
          +
          +    return list;
          +  }
          +
          +  // Iterator that traverses in the range of [min, max], stepping
          +  // by distance from a given start position. I.e. for [0, 4], with
          +  // start of 2, this will iterate 2, 3, 1, 4, 0.
          +  function distanceIterator (start, minLine, maxLine) {
          +    var wantForward = true,
          +        backwardExhausted = false,
          +        forwardExhausted = false,
          +        localOffset = 1;
          +    return function iterator() {
          +      if (wantForward && !forwardExhausted) {
          +        if (backwardExhausted) {
          +          localOffset++;
          +        } else {
          +          wantForward = false;
          +        } // Check if trying to fit beyond text length, and if not, check it fits
          +        // after offset location (or desired location on first iteration)
          +
          +
          +        if (start + localOffset <= maxLine) {
          +          return localOffset;
          +        }
          +
          +        forwardExhausted = true;
          +      }
          +
          +      if (!backwardExhausted) {
          +        if (!forwardExhausted) {
          +          wantForward = true;
          +        } // Check if trying to fit before text beginning, and if not, check it fits
          +        // before offset location
          +
          +
          +        if (minLine <= start - localOffset) {
          +          return -localOffset++;
          +        }
          +
          +        backwardExhausted = true;
          +        return iterator();
          +      } // We tried to fit hunk before text beginning and beyond text length, then
          +      // hunk can't fit on the text. Return undefined
          +
          +    };
          +  }
          +
          +  function applyPatch(source, uniDiff) {
          +    var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
          +
          +    if (typeof uniDiff === 'string') {
          +      uniDiff = parsePatch(uniDiff);
          +    }
          +
          +    if (Array.isArray(uniDiff)) {
          +      if (uniDiff.length > 1) {
          +        throw new Error('applyPatch only works with a single input.');
          +      }
          +
          +      uniDiff = uniDiff[0];
          +    } // Apply the diff to the input
          +
          +
          +    var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
          +        delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
          +        hunks = uniDiff.hunks,
          +        compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) {
          +      return line === patchContent;
          +    },
          +        errorCount = 0,
          +        fuzzFactor = options.fuzzFactor || 0,
          +        minLine = 0,
          +        offset = 0,
          +        removeEOFNL,
          +        addEOFNL;
          +    /**
          +     * Checks if the hunk exactly fits on the provided location
          +     */
          +
          +
          +    function hunkFits(hunk, toPos) {
          +      for (var j = 0; j < hunk.lines.length; j++) {
          +        var line = hunk.lines[j],
          +            operation = line.length > 0 ? line[0] : ' ',
          +            content = line.length > 0 ? line.substr(1) : line;
          +
          +        if (operation === ' ' || operation === '-') {
          +          // Context sanity check
          +          if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
          +            errorCount++;
          +
          +            if (errorCount > fuzzFactor) {
          +              return false;
          +            }
          +          }
          +
          +          toPos++;
          +        }
          +      }
          +
          +      return true;
          +    } // Search best fit offsets for each hunk based on the previous ones
          +
          +
          +    for (var i = 0; i < hunks.length; i++) {
          +      var hunk = hunks[i],
          +          maxLine = lines.length - hunk.oldLines,
          +          localOffset = 0,
          +          toPos = offset + hunk.oldStart - 1;
          +      var iterator = distanceIterator(toPos, minLine, maxLine);
          +
          +      for (; localOffset !== undefined; localOffset = iterator()) {
          +        if (hunkFits(hunk, toPos + localOffset)) {
          +          hunk.offset = offset += localOffset;
          +          break;
          +        }
          +      }
          +
          +      if (localOffset === undefined) {
          +        return false;
          +      } // Set lower text limit to end of the current hunk, so next ones don't try
          +      // to fit over already patched text
          +
          +
          +      minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
          +    } // Apply patch hunks
          +
          +
          +    var diffOffset = 0;
          +
          +    for (var _i = 0; _i < hunks.length; _i++) {
          +      var _hunk = hunks[_i],
          +          _toPos = _hunk.oldStart + _hunk.offset + diffOffset - 1;
          +
          +      diffOffset += _hunk.newLines - _hunk.oldLines;
          +
          +      for (var j = 0; j < _hunk.lines.length; j++) {
          +        var line = _hunk.lines[j],
          +            operation = line.length > 0 ? line[0] : ' ',
          +            content = line.length > 0 ? line.substr(1) : line,
          +            delimiter = _hunk.linedelimiters[j];
          +
          +        if (operation === ' ') {
          +          _toPos++;
          +        } else if (operation === '-') {
          +          lines.splice(_toPos, 1);
          +          delimiters.splice(_toPos, 1);
          +          /* istanbul ignore else */
          +        } else if (operation === '+') {
          +          lines.splice(_toPos, 0, content);
          +          delimiters.splice(_toPos, 0, delimiter);
          +          _toPos++;
          +        } else if (operation === '\\') {
          +          var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
          +
          +          if (previousOperation === '+') {
          +            removeEOFNL = true;
          +          } else if (previousOperation === '-') {
          +            addEOFNL = true;
          +          }
          +        }
          +      }
          +    } // Handle EOFNL insertion/removal
          +
          +
          +    if (removeEOFNL) {
          +      while (!lines[lines.length - 1]) {
          +        lines.pop();
          +        delimiters.pop();
          +      }
          +    } else if (addEOFNL) {
          +      lines.push('');
          +      delimiters.push('\n');
          +    }
          +
          +    for (var _k = 0; _k < lines.length - 1; _k++) {
          +      lines[_k] = lines[_k] + delimiters[_k];
          +    }
          +
          +    return lines.join('');
          +  } // Wrapper that supports multiple file patches via callbacks.
          +
          +  function applyPatches(uniDiff, options) {
          +    if (typeof uniDiff === 'string') {
          +      uniDiff = parsePatch(uniDiff);
          +    }
          +
          +    var currentIndex = 0;
          +
          +    function processIndex() {
          +      var index = uniDiff[currentIndex++];
          +
          +      if (!index) {
          +        return options.complete();
          +      }
          +
          +      options.loadFile(index, function (err, data) {
          +        if (err) {
          +          return options.complete(err);
          +        }
          +
          +        var updatedContent = applyPatch(data, index, options);
          +        options.patched(index, updatedContent, function (err) {
          +          if (err) {
          +            return options.complete(err);
          +          }
          +
          +          processIndex();
          +        });
          +      });
          +    }
          +
          +    processIndex();
          +  }
          +
          +  function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
          +    if (!options) {
          +      options = {};
          +    }
          +
          +    if (typeof options.context === 'undefined') {
          +      options.context = 4;
          +    }
          +
          +    var diff = diffLines(oldStr, newStr, options);
          +    diff.push({
          +      value: '',
          +      lines: []
          +    }); // Append an empty value to make cleanup easier
          +
          +    function contextLines(lines) {
          +      return lines.map(function (entry) {
          +        return ' ' + entry;
          +      });
          +    }
          +
          +    var hunks = [];
          +    var oldRangeStart = 0,
          +        newRangeStart = 0,
          +        curRange = [],
          +        oldLine = 1,
          +        newLine = 1;
          +
          +    var _loop = function _loop(i) {
          +      var current = diff[i],
          +          lines = current.lines || current.value.replace(/\n$/, '').split('\n');
          +      current.lines = lines;
          +
          +      if (current.added || current.removed) {
          +        var _curRange;
          +
          +        // If we have previous context, start with that
          +        if (!oldRangeStart) {
          +          var prev = diff[i - 1];
          +          oldRangeStart = oldLine;
          +          newRangeStart = newLine;
          +
          +          if (prev) {
          +            curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
          +            oldRangeStart -= curRange.length;
          +            newRangeStart -= curRange.length;
          +          }
          +        } // Output our changes
          +
          +
          +        (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
          +          return (current.added ? '+' : '-') + entry;
          +        }))); // Track the updated file position
          +
          +
          +        if (current.added) {
          +          newLine += lines.length;
          +        } else {
          +          oldLine += lines.length;
          +        }
          +      } else {
          +        // Identical context lines. Track line changes
          +        if (oldRangeStart) {
          +          // Close out any changes that have been output (or join overlapping)
          +          if (lines.length <= options.context * 2 && i < diff.length - 2) {
          +            var _curRange2;
          +
          +            // Overlapping
          +            (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
          +          } else {
          +            var _curRange3;
          +
          +            // end the range and output
          +            var contextSize = Math.min(lines.length, options.context);
          +
          +            (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
          +
          +            var hunk = {
          +              oldStart: oldRangeStart,
          +              oldLines: oldLine - oldRangeStart + contextSize,
          +              newStart: newRangeStart,
          +              newLines: newLine - newRangeStart + contextSize,
          +              lines: curRange
          +            };
          +
          +            if (i >= diff.length - 2 && lines.length <= options.context) {
          +              // EOF is inside this hunk
          +              var oldEOFNewline = /\n$/.test(oldStr);
          +              var newEOFNewline = /\n$/.test(newStr);
          +              var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
          +
          +              if (!oldEOFNewline && noNlBeforeAdds && oldStr.length > 0) {
          +                // special case: old has no eol and no trailing context; no-nl can end up before adds
          +                // however, if the old file is empty, do not output the no-nl line
          +                curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
          +              }
          +
          +              if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
          +                curRange.push('\\ No newline at end of file');
          +              }
          +            }
          +
          +            hunks.push(hunk);
          +            oldRangeStart = 0;
          +            newRangeStart = 0;
          +            curRange = [];
          +          }
          +        }
          +
          +        oldLine += lines.length;
          +        newLine += lines.length;
          +      }
          +    };
          +
          +    for (var i = 0; i < diff.length; i++) {
          +      _loop(i);
          +    }
          +
          +    return {
          +      oldFileName: oldFileName,
          +      newFileName: newFileName,
          +      oldHeader: oldHeader,
          +      newHeader: newHeader,
          +      hunks: hunks
          +    };
          +  }
          +  function formatPatch(diff) {
          +    var ret = [];
          +
          +    if (diff.oldFileName == diff.newFileName) {
          +      ret.push('Index: ' + diff.oldFileName);
          +    }
          +
          +    ret.push('===================================================================');
          +    ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
          +    ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
          +
          +    for (var i = 0; i < diff.hunks.length; i++) {
          +      var hunk = diff.hunks[i]; // Unified Diff Format quirk: If the chunk size is 0,
          +      // the first number is one lower than one would expect.
          +      // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
          +
          +      if (hunk.oldLines === 0) {
          +        hunk.oldStart -= 1;
          +      }
          +
          +      if (hunk.newLines === 0) {
          +        hunk.newStart -= 1;
          +      }
          +
          +      ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
          +      ret.push.apply(ret, hunk.lines);
          +    }
          +
          +    return ret.join('\n') + '\n';
          +  }
          +  function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
          +    return formatPatch(structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options));
          +  }
          +  function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
          +    return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
          +  }
          +
          +  function arrayEqual(a, b) {
          +    if (a.length !== b.length) {
          +      return false;
          +    }
          +
          +    return arrayStartsWith(a, b);
          +  }
          +  function arrayStartsWith(array, start) {
          +    if (start.length > array.length) {
          +      return false;
          +    }
          +
          +    for (var i = 0; i < start.length; i++) {
          +      if (start[i] !== array[i]) {
          +        return false;
          +      }
          +    }
          +
          +    return true;
          +  }
          +
          +  function calcLineCount(hunk) {
          +    var _calcOldNewLineCount = calcOldNewLineCount(hunk.lines),
          +        oldLines = _calcOldNewLineCount.oldLines,
          +        newLines = _calcOldNewLineCount.newLines;
          +
          +    if (oldLines !== undefined) {
          +      hunk.oldLines = oldLines;
          +    } else {
          +      delete hunk.oldLines;
          +    }
          +
          +    if (newLines !== undefined) {
          +      hunk.newLines = newLines;
          +    } else {
          +      delete hunk.newLines;
          +    }
          +  }
          +  function merge(mine, theirs, base) {
          +    mine = loadPatch(mine, base);
          +    theirs = loadPatch(theirs, base);
          +    var ret = {}; // For index we just let it pass through as it doesn't have any necessary meaning.
          +    // Leaving sanity checks on this to the API consumer that may know more about the
          +    // meaning in their own context.
          +
          +    if (mine.index || theirs.index) {
          +      ret.index = mine.index || theirs.index;
          +    }
          +
          +    if (mine.newFileName || theirs.newFileName) {
          +      if (!fileNameChanged(mine)) {
          +        // No header or no change in ours, use theirs (and ours if theirs does not exist)
          +        ret.oldFileName = theirs.oldFileName || mine.oldFileName;
          +        ret.newFileName = theirs.newFileName || mine.newFileName;
          +        ret.oldHeader = theirs.oldHeader || mine.oldHeader;
          +        ret.newHeader = theirs.newHeader || mine.newHeader;
          +      } else if (!fileNameChanged(theirs)) {
          +        // No header or no change in theirs, use ours
          +        ret.oldFileName = mine.oldFileName;
          +        ret.newFileName = mine.newFileName;
          +        ret.oldHeader = mine.oldHeader;
          +        ret.newHeader = mine.newHeader;
          +      } else {
          +        // Both changed... figure it out
          +        ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
          +        ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
          +        ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
          +        ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
          +      }
          +    }
          +
          +    ret.hunks = [];
          +    var mineIndex = 0,
          +        theirsIndex = 0,
          +        mineOffset = 0,
          +        theirsOffset = 0;
          +
          +    while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
          +      var mineCurrent = mine.hunks[mineIndex] || {
          +        oldStart: Infinity
          +      },
          +          theirsCurrent = theirs.hunks[theirsIndex] || {
          +        oldStart: Infinity
          +      };
          +
          +      if (hunkBefore(mineCurrent, theirsCurrent)) {
          +        // This patch does not overlap with any of the others, yay.
          +        ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
          +        mineIndex++;
          +        theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
          +      } else if (hunkBefore(theirsCurrent, mineCurrent)) {
          +        // This patch does not overlap with any of the others, yay.
          +        ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
          +        theirsIndex++;
          +        mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
          +      } else {
          +        // Overlap, merge as best we can
          +        var mergedHunk = {
          +          oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
          +          oldLines: 0,
          +          newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
          +          newLines: 0,
          +          lines: []
          +        };
          +        mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
          +        theirsIndex++;
          +        mineIndex++;
          +        ret.hunks.push(mergedHunk);
          +      }
          +    }
          +
          +    return ret;
          +  }
          +
          +  function loadPatch(param, base) {
          +    if (typeof param === 'string') {
          +      if (/^@@/m.test(param) || /^Index:/m.test(param)) {
          +        return parsePatch(param)[0];
          +      }
          +
          +      if (!base) {
          +        throw new Error('Must provide a base reference or pass in a patch');
          +      }
          +
          +      return structuredPatch(undefined, undefined, base, param);
          +    }
          +
          +    return param;
          +  }
          +
          +  function fileNameChanged(patch) {
          +    return patch.newFileName && patch.newFileName !== patch.oldFileName;
          +  }
          +
          +  function selectField(index, mine, theirs) {
          +    if (mine === theirs) {
          +      return mine;
          +    } else {
          +      index.conflict = true;
          +      return {
          +        mine: mine,
          +        theirs: theirs
          +      };
          +    }
          +  }
          +
          +  function hunkBefore(test, check) {
          +    return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
          +  }
          +
          +  function cloneHunk(hunk, offset) {
          +    return {
          +      oldStart: hunk.oldStart,
          +      oldLines: hunk.oldLines,
          +      newStart: hunk.newStart + offset,
          +      newLines: hunk.newLines,
          +      lines: hunk.lines
          +    };
          +  }
          +
          +  function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
          +    // This will generally result in a conflicted hunk, but there are cases where the context
          +    // is the only overlap where we can successfully merge the content here.
          +    var mine = {
          +      offset: mineOffset,
          +      lines: mineLines,
          +      index: 0
          +    },
          +        their = {
          +      offset: theirOffset,
          +      lines: theirLines,
          +      index: 0
          +    }; // Handle any leading content
          +
          +    insertLeading(hunk, mine, their);
          +    insertLeading(hunk, their, mine); // Now in the overlap content. Scan through and select the best changes from each.
          +
          +    while (mine.index < mine.lines.length && their.index < their.lines.length) {
          +      var mineCurrent = mine.lines[mine.index],
          +          theirCurrent = their.lines[their.index];
          +
          +      if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
          +        // Both modified ...
          +        mutualChange(hunk, mine, their);
          +      } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
          +        var _hunk$lines;
          +
          +        // Mine inserted
          +        (_hunk$lines = hunk.lines).push.apply(_hunk$lines, _toConsumableArray(collectChange(mine)));
          +      } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
          +        var _hunk$lines2;
          +
          +        // Theirs inserted
          +        (_hunk$lines2 = hunk.lines).push.apply(_hunk$lines2, _toConsumableArray(collectChange(their)));
          +      } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
          +        // Mine removed or edited
          +        removal(hunk, mine, their);
          +      } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
          +        // Their removed or edited
          +        removal(hunk, their, mine, true);
          +      } else if (mineCurrent === theirCurrent) {
          +        // Context identity
          +        hunk.lines.push(mineCurrent);
          +        mine.index++;
          +        their.index++;
          +      } else {
          +        // Context mismatch
          +        conflict(hunk, collectChange(mine), collectChange(their));
          +      }
          +    } // Now push anything that may be remaining
          +
          +
          +    insertTrailing(hunk, mine);
          +    insertTrailing(hunk, their);
          +    calcLineCount(hunk);
          +  }
          +
          +  function mutualChange(hunk, mine, their) {
          +    var myChanges = collectChange(mine),
          +        theirChanges = collectChange(their);
          +
          +    if (allRemoves(myChanges) && allRemoves(theirChanges)) {
          +      // Special case for remove changes that are supersets of one another
          +      if (arrayStartsWith(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
          +        var _hunk$lines3;
          +
          +        (_hunk$lines3 = hunk.lines).push.apply(_hunk$lines3, _toConsumableArray(myChanges));
          +
          +        return;
          +      } else if (arrayStartsWith(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
          +        var _hunk$lines4;
          +
          +        (_hunk$lines4 = hunk.lines).push.apply(_hunk$lines4, _toConsumableArray(theirChanges));
          +
          +        return;
          +      }
          +    } else if (arrayEqual(myChanges, theirChanges)) {
          +      var _hunk$lines5;
          +
          +      (_hunk$lines5 = hunk.lines).push.apply(_hunk$lines5, _toConsumableArray(myChanges));
          +
          +      return;
          +    }
          +
          +    conflict(hunk, myChanges, theirChanges);
          +  }
          +
          +  function removal(hunk, mine, their, swap) {
          +    var myChanges = collectChange(mine),
          +        theirChanges = collectContext(their, myChanges);
          +
          +    if (theirChanges.merged) {
          +      var _hunk$lines6;
          +
          +      (_hunk$lines6 = hunk.lines).push.apply(_hunk$lines6, _toConsumableArray(theirChanges.merged));
          +    } else {
          +      conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
          +    }
          +  }
          +
          +  function conflict(hunk, mine, their) {
          +    hunk.conflict = true;
          +    hunk.lines.push({
          +      conflict: true,
          +      mine: mine,
          +      theirs: their
          +    });
          +  }
          +
          +  function insertLeading(hunk, insert, their) {
          +    while (insert.offset < their.offset && insert.index < insert.lines.length) {
          +      var line = insert.lines[insert.index++];
          +      hunk.lines.push(line);
          +      insert.offset++;
          +    }
          +  }
          +
          +  function insertTrailing(hunk, insert) {
          +    while (insert.index < insert.lines.length) {
          +      var line = insert.lines[insert.index++];
          +      hunk.lines.push(line);
          +    }
          +  }
          +
          +  function collectChange(state) {
          +    var ret = [],
          +        operation = state.lines[state.index][0];
          +
          +    while (state.index < state.lines.length) {
          +      var line = state.lines[state.index]; // Group additions that are immediately after subtractions and treat them as one "atomic" modify change.
          +
          +      if (operation === '-' && line[0] === '+') {
          +        operation = '+';
          +      }
          +
          +      if (operation === line[0]) {
          +        ret.push(line);
          +        state.index++;
          +      } else {
          +        break;
          +      }
          +    }
          +
          +    return ret;
          +  }
          +
          +  function collectContext(state, matchChanges) {
          +    var changes = [],
          +        merged = [],
          +        matchIndex = 0,
          +        contextChanges = false,
          +        conflicted = false;
          +
          +    while (matchIndex < matchChanges.length && state.index < state.lines.length) {
          +      var change = state.lines[state.index],
          +          match = matchChanges[matchIndex]; // Once we've hit our add, then we are done
          +
          +      if (match[0] === '+') {
          +        break;
          +      }
          +
          +      contextChanges = contextChanges || change[0] !== ' ';
          +      merged.push(match);
          +      matchIndex++; // Consume any additions in the other block as a conflict to attempt
          +      // to pull in the remaining context after this
          +
          +      if (change[0] === '+') {
          +        conflicted = true;
          +
          +        while (change[0] === '+') {
          +          changes.push(change);
          +          change = state.lines[++state.index];
          +        }
          +      }
          +
          +      if (match.substr(1) === change.substr(1)) {
          +        changes.push(change);
          +        state.index++;
          +      } else {
          +        conflicted = true;
          +      }
          +    }
          +
          +    if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
          +      conflicted = true;
          +    }
          +
          +    if (conflicted) {
          +      return changes;
          +    }
          +
          +    while (matchIndex < matchChanges.length) {
          +      merged.push(matchChanges[matchIndex++]);
          +    }
          +
          +    return {
          +      merged: merged,
          +      changes: changes
          +    };
          +  }
          +
          +  function allRemoves(changes) {
          +    return changes.reduce(function (prev, change) {
          +      return prev && change[0] === '-';
          +    }, true);
          +  }
          +
          +  function skipRemoveSuperset(state, removeChanges, delta) {
          +    for (var i = 0; i < delta; i++) {
          +      var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
          +
          +      if (state.lines[state.index + i] !== ' ' + changeContent) {
          +        return false;
          +      }
          +    }
          +
          +    state.index += delta;
          +    return true;
          +  }
          +
          +  function calcOldNewLineCount(lines) {
          +    var oldLines = 0;
          +    var newLines = 0;
          +    lines.forEach(function (line) {
          +      if (typeof line !== 'string') {
          +        var myCount = calcOldNewLineCount(line.mine);
          +        var theirCount = calcOldNewLineCount(line.theirs);
          +
          +        if (oldLines !== undefined) {
          +          if (myCount.oldLines === theirCount.oldLines) {
          +            oldLines += myCount.oldLines;
          +          } else {
          +            oldLines = undefined;
          +          }
          +        }
          +
          +        if (newLines !== undefined) {
          +          if (myCount.newLines === theirCount.newLines) {
          +            newLines += myCount.newLines;
          +          } else {
          +            newLines = undefined;
          +          }
          +        }
          +      } else {
          +        if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) {
          +          newLines++;
          +        }
          +
          +        if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) {
          +          oldLines++;
          +        }
          +      }
          +    });
          +    return {
          +      oldLines: oldLines,
          +      newLines: newLines
          +    };
          +  }
          +
          +  // See: http://code.google.com/p/google-diff-match-patch/wiki/API
          +  function convertChangesToDMP(changes) {
          +    var ret = [],
          +        change,
          +        operation;
          +
          +    for (var i = 0; i < changes.length; i++) {
          +      change = changes[i];
          +
          +      if (change.added) {
          +        operation = 1;
          +      } else if (change.removed) {
          +        operation = -1;
          +      } else {
          +        operation = 0;
          +      }
          +
          +      ret.push([operation, change.value]);
          +    }
          +
          +    return ret;
          +  }
          +
          +  function convertChangesToXML(changes) {
          +    var ret = [];
          +
          +    for (var i = 0; i < changes.length; i++) {
          +      var change = changes[i];
          +
          +      if (change.added) {
          +        ret.push('');
          +      } else if (change.removed) {
          +        ret.push('');
          +      }
          +
          +      ret.push(escapeHTML(change.value));
          +
          +      if (change.added) {
          +        ret.push('');
          +      } else if (change.removed) {
          +        ret.push('');
          +      }
          +    }
          +
          +    return ret.join('');
          +  }
          +
          +  function escapeHTML(s) {
          +    var n = s;
          +    n = n.replace(/&/g, '&');
          +    n = n.replace(//g, '>');
          +    n = n.replace(/"/g, '"');
          +    return n;
          +  }
          +
          +  exports.Diff = Diff;
          +  exports.applyPatch = applyPatch;
          +  exports.applyPatches = applyPatches;
          +  exports.canonicalize = canonicalize;
          +  exports.convertChangesToDMP = convertChangesToDMP;
          +  exports.convertChangesToXML = convertChangesToXML;
          +  exports.createPatch = createPatch;
          +  exports.createTwoFilesPatch = createTwoFilesPatch;
          +  exports.diffArrays = diffArrays;
          +  exports.diffChars = diffChars;
          +  exports.diffCss = diffCss;
          +  exports.diffJson = diffJson;
          +  exports.diffLines = diffLines;
          +  exports.diffSentences = diffSentences;
          +  exports.diffTrimmedLines = diffTrimmedLines;
          +  exports.diffWords = diffWords;
          +  exports.diffWordsWithSpace = diffWordsWithSpace;
          +  exports.merge = merge;
          +  exports.parsePatch = parsePatch;
          +  exports.structuredPatch = structuredPatch;
          +
          +  Object.defineProperty(exports, '__esModule', { value: true });
          +
          +})));
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/convert/dmp.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/convert/dmp.js
          new file mode 100644
          index 00000000000000..91ff40a9120f7d
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/convert/dmp.js
          @@ -0,0 +1,32 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.convertChangesToDMP = convertChangesToDMP;
          +
          +/*istanbul ignore end*/
          +// See: http://code.google.com/p/google-diff-match-patch/wiki/API
          +function convertChangesToDMP(changes) {
          +  var ret = [],
          +      change,
          +      operation;
          +
          +  for (var i = 0; i < changes.length; i++) {
          +    change = changes[i];
          +
          +    if (change.added) {
          +      operation = 1;
          +    } else if (change.removed) {
          +      operation = -1;
          +    } else {
          +      operation = 0;
          +    }
          +
          +    ret.push([operation, change.value]);
          +  }
          +
          +  return ret;
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb252ZXJ0L2RtcC5qcyJdLCJuYW1lcyI6WyJjb252ZXJ0Q2hhbmdlc1RvRE1QIiwiY2hhbmdlcyIsInJldCIsImNoYW5nZSIsIm9wZXJhdGlvbiIsImkiLCJsZW5ndGgiLCJhZGRlZCIsInJlbW92ZWQiLCJwdXNoIiwidmFsdWUiXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBO0FBQ08sU0FBU0EsbUJBQVQsQ0FBNkJDLE9BQTdCLEVBQXNDO0FBQzNDLE1BQUlDLEdBQUcsR0FBRyxFQUFWO0FBQUEsTUFDSUMsTUFESjtBQUFBLE1BRUlDLFNBRko7O0FBR0EsT0FBSyxJQUFJQyxDQUFDLEdBQUcsQ0FBYixFQUFnQkEsQ0FBQyxHQUFHSixPQUFPLENBQUNLLE1BQTVCLEVBQW9DRCxDQUFDLEVBQXJDLEVBQXlDO0FBQ3ZDRixJQUFBQSxNQUFNLEdBQUdGLE9BQU8sQ0FBQ0ksQ0FBRCxDQUFoQjs7QUFDQSxRQUFJRixNQUFNLENBQUNJLEtBQVgsRUFBa0I7QUFDaEJILE1BQUFBLFNBQVMsR0FBRyxDQUFaO0FBQ0QsS0FGRCxNQUVPLElBQUlELE1BQU0sQ0FBQ0ssT0FBWCxFQUFvQjtBQUN6QkosTUFBQUEsU0FBUyxHQUFHLENBQUMsQ0FBYjtBQUNELEtBRk0sTUFFQTtBQUNMQSxNQUFBQSxTQUFTLEdBQUcsQ0FBWjtBQUNEOztBQUVERixJQUFBQSxHQUFHLENBQUNPLElBQUosQ0FBUyxDQUFDTCxTQUFELEVBQVlELE1BQU0sQ0FBQ08sS0FBbkIsQ0FBVDtBQUNEOztBQUNELFNBQU9SLEdBQVA7QUFDRCIsInNvdXJjZXNDb250ZW50IjpbIi8vIFNlZTogaHR0cDovL2NvZGUuZ29vZ2xlLmNvbS9wL2dvb2dsZS1kaWZmLW1hdGNoLXBhdGNoL3dpa2kvQVBJXG5leHBvcnQgZnVuY3Rpb24gY29udmVydENoYW5nZXNUb0RNUChjaGFuZ2VzKSB7XG4gIGxldCByZXQgPSBbXSxcbiAgICAgIGNoYW5nZSxcbiAgICAgIG9wZXJhdGlvbjtcbiAgZm9yIChsZXQgaSA9IDA7IGkgPCBjaGFuZ2VzLmxlbmd0aDsgaSsrKSB7XG4gICAgY2hhbmdlID0gY2hhbmdlc1tpXTtcbiAgICBpZiAoY2hhbmdlLmFkZGVkKSB7XG4gICAgICBvcGVyYXRpb24gPSAxO1xuICAgIH0gZWxzZSBpZiAoY2hhbmdlLnJlbW92ZWQpIHtcbiAgICAgIG9wZXJhdGlvbiA9IC0xO1xuICAgIH0gZWxzZSB7XG4gICAgICBvcGVyYXRpb24gPSAwO1xuICAgIH1cblxuICAgIHJldC5wdXNoKFtvcGVyYXRpb24sIGNoYW5nZS52YWx1ZV0pO1xuICB9XG4gIHJldHVybiByZXQ7XG59XG4iXX0=
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/convert/xml.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/convert/xml.js
          new file mode 100644
          index 00000000000000..69ec60c66c81d0
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/convert/xml.js
          @@ -0,0 +1,42 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.convertChangesToXML = convertChangesToXML;
          +
          +/*istanbul ignore end*/
          +function convertChangesToXML(changes) {
          +  var ret = [];
          +
          +  for (var i = 0; i < changes.length; i++) {
          +    var change = changes[i];
          +
          +    if (change.added) {
          +      ret.push('');
          +    } else if (change.removed) {
          +      ret.push('');
          +    }
          +
          +    ret.push(escapeHTML(change.value));
          +
          +    if (change.added) {
          +      ret.push('');
          +    } else if (change.removed) {
          +      ret.push('');
          +    }
          +  }
          +
          +  return ret.join('');
          +}
          +
          +function escapeHTML(s) {
          +  var n = s;
          +  n = n.replace(/&/g, '&');
          +  n = n.replace(//g, '>');
          +  n = n.replace(/"/g, '"');
          +  return n;
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb252ZXJ0L3htbC5qcyJdLCJuYW1lcyI6WyJjb252ZXJ0Q2hhbmdlc1RvWE1MIiwiY2hhbmdlcyIsInJldCIsImkiLCJsZW5ndGgiLCJjaGFuZ2UiLCJhZGRlZCIsInB1c2giLCJyZW1vdmVkIiwiZXNjYXBlSFRNTCIsInZhbHVlIiwiam9pbiIsInMiLCJuIiwicmVwbGFjZSJdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQU8sU0FBU0EsbUJBQVQsQ0FBNkJDLE9BQTdCLEVBQXNDO0FBQzNDLE1BQUlDLEdBQUcsR0FBRyxFQUFWOztBQUNBLE9BQUssSUFBSUMsQ0FBQyxHQUFHLENBQWIsRUFBZ0JBLENBQUMsR0FBR0YsT0FBTyxDQUFDRyxNQUE1QixFQUFvQ0QsQ0FBQyxFQUFyQyxFQUF5QztBQUN2QyxRQUFJRSxNQUFNLEdBQUdKLE9BQU8sQ0FBQ0UsQ0FBRCxDQUFwQjs7QUFDQSxRQUFJRSxNQUFNLENBQUNDLEtBQVgsRUFBa0I7QUFDaEJKLE1BQUFBLEdBQUcsQ0FBQ0ssSUFBSixDQUFTLE9BQVQ7QUFDRCxLQUZELE1BRU8sSUFBSUYsTUFBTSxDQUFDRyxPQUFYLEVBQW9CO0FBQ3pCTixNQUFBQSxHQUFHLENBQUNLLElBQUosQ0FBUyxPQUFUO0FBQ0Q7O0FBRURMLElBQUFBLEdBQUcsQ0FBQ0ssSUFBSixDQUFTRSxVQUFVLENBQUNKLE1BQU0sQ0FBQ0ssS0FBUixDQUFuQjs7QUFFQSxRQUFJTCxNQUFNLENBQUNDLEtBQVgsRUFBa0I7QUFDaEJKLE1BQUFBLEdBQUcsQ0FBQ0ssSUFBSixDQUFTLFFBQVQ7QUFDRCxLQUZELE1BRU8sSUFBSUYsTUFBTSxDQUFDRyxPQUFYLEVBQW9CO0FBQ3pCTixNQUFBQSxHQUFHLENBQUNLLElBQUosQ0FBUyxRQUFUO0FBQ0Q7QUFDRjs7QUFDRCxTQUFPTCxHQUFHLENBQUNTLElBQUosQ0FBUyxFQUFULENBQVA7QUFDRDs7QUFFRCxTQUFTRixVQUFULENBQW9CRyxDQUFwQixFQUF1QjtBQUNyQixNQUFJQyxDQUFDLEdBQUdELENBQVI7QUFDQUMsRUFBQUEsQ0FBQyxHQUFHQSxDQUFDLENBQUNDLE9BQUYsQ0FBVSxJQUFWLEVBQWdCLE9BQWhCLENBQUo7QUFDQUQsRUFBQUEsQ0FBQyxHQUFHQSxDQUFDLENBQUNDLE9BQUYsQ0FBVSxJQUFWLEVBQWdCLE1BQWhCLENBQUo7QUFDQUQsRUFBQUEsQ0FBQyxHQUFHQSxDQUFDLENBQUNDLE9BQUYsQ0FBVSxJQUFWLEVBQWdCLE1BQWhCLENBQUo7QUFDQUQsRUFBQUEsQ0FBQyxHQUFHQSxDQUFDLENBQUNDLE9BQUYsQ0FBVSxJQUFWLEVBQWdCLFFBQWhCLENBQUo7QUFFQSxTQUFPRCxDQUFQO0FBQ0QiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZnVuY3Rpb24gY29udmVydENoYW5nZXNUb1hNTChjaGFuZ2VzKSB7XG4gIGxldCByZXQgPSBbXTtcbiAgZm9yIChsZXQgaSA9IDA7IGkgPCBjaGFuZ2VzLmxlbmd0aDsgaSsrKSB7XG4gICAgbGV0IGNoYW5nZSA9IGNoYW5nZXNbaV07XG4gICAgaWYgKGNoYW5nZS5hZGRlZCkge1xuICAgICAgcmV0LnB1c2goJzxpbnM+Jyk7XG4gICAgfSBlbHNlIGlmIChjaGFuZ2UucmVtb3ZlZCkge1xuICAgICAgcmV0LnB1c2goJzxkZWw+Jyk7XG4gICAgfVxuXG4gICAgcmV0LnB1c2goZXNjYXBlSFRNTChjaGFuZ2UudmFsdWUpKTtcblxuICAgIGlmIChjaGFuZ2UuYWRkZWQpIHtcbiAgICAgIHJldC5wdXNoKCc8L2lucz4nKTtcbiAgICB9IGVsc2UgaWYgKGNoYW5nZS5yZW1vdmVkKSB7XG4gICAgICByZXQucHVzaCgnPC9kZWw+Jyk7XG4gICAgfVxuICB9XG4gIHJldHVybiByZXQuam9pbignJyk7XG59XG5cbmZ1bmN0aW9uIGVzY2FwZUhUTUwocykge1xuICBsZXQgbiA9IHM7XG4gIG4gPSBuLnJlcGxhY2UoLyYvZywgJyZhbXA7Jyk7XG4gIG4gPSBuLnJlcGxhY2UoLzwvZywgJyZsdDsnKTtcbiAgbiA9IG4ucmVwbGFjZSgvPi9nLCAnJmd0OycpO1xuICBuID0gbi5yZXBsYWNlKC9cIi9nLCAnJnF1b3Q7Jyk7XG5cbiAgcmV0dXJuIG47XG59XG4iXX0=
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/array.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/array.js
          new file mode 100644
          index 00000000000000..19e36809893c1d
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/array.js
          @@ -0,0 +1,45 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.diffArrays = diffArrays;
          +exports.arrayDiff = void 0;
          +
          +/*istanbul ignore end*/
          +var
          +/*istanbul ignore start*/
          +_base = _interopRequireDefault(require("./base"))
          +/*istanbul ignore end*/
          +;
          +
          +/*istanbul ignore start*/ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
          +
          +/*istanbul ignore end*/
          +var arrayDiff = new
          +/*istanbul ignore start*/
          +_base
          +/*istanbul ignore end*/
          +[
          +/*istanbul ignore start*/
          +"default"
          +/*istanbul ignore end*/
          +]();
          +
          +/*istanbul ignore start*/
          +exports.arrayDiff = arrayDiff;
          +
          +/*istanbul ignore end*/
          +arrayDiff.tokenize = function (value) {
          +  return value.slice();
          +};
          +
          +arrayDiff.join = arrayDiff.removeEmpty = function (value) {
          +  return value;
          +};
          +
          +function diffArrays(oldArr, newArr, callback) {
          +  return arrayDiff.diff(oldArr, newArr, callback);
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL2FycmF5LmpzIl0sIm5hbWVzIjpbImFycmF5RGlmZiIsIkRpZmYiLCJ0b2tlbml6ZSIsInZhbHVlIiwic2xpY2UiLCJqb2luIiwicmVtb3ZlRW1wdHkiLCJkaWZmQXJyYXlzIiwib2xkQXJyIiwibmV3QXJyIiwiY2FsbGJhY2siLCJkaWZmIl0sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTs7Ozs7QUFFTyxJQUFNQSxTQUFTLEdBQUc7QUFBSUM7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUEsQ0FBSixFQUFsQjs7Ozs7O0FBQ1BELFNBQVMsQ0FBQ0UsUUFBVixHQUFxQixVQUFTQyxLQUFULEVBQWdCO0FBQ25DLFNBQU9BLEtBQUssQ0FBQ0MsS0FBTixFQUFQO0FBQ0QsQ0FGRDs7QUFHQUosU0FBUyxDQUFDSyxJQUFWLEdBQWlCTCxTQUFTLENBQUNNLFdBQVYsR0FBd0IsVUFBU0gsS0FBVCxFQUFnQjtBQUN2RCxTQUFPQSxLQUFQO0FBQ0QsQ0FGRDs7QUFJTyxTQUFTSSxVQUFULENBQW9CQyxNQUFwQixFQUE0QkMsTUFBNUIsRUFBb0NDLFFBQXBDLEVBQThDO0FBQUUsU0FBT1YsU0FBUyxDQUFDVyxJQUFWLENBQWVILE1BQWYsRUFBdUJDLE1BQXZCLEVBQStCQyxRQUEvQixDQUFQO0FBQWtEIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IERpZmYgZnJvbSAnLi9iYXNlJztcblxuZXhwb3J0IGNvbnN0IGFycmF5RGlmZiA9IG5ldyBEaWZmKCk7XG5hcnJheURpZmYudG9rZW5pemUgPSBmdW5jdGlvbih2YWx1ZSkge1xuICByZXR1cm4gdmFsdWUuc2xpY2UoKTtcbn07XG5hcnJheURpZmYuam9pbiA9IGFycmF5RGlmZi5yZW1vdmVFbXB0eSA9IGZ1bmN0aW9uKHZhbHVlKSB7XG4gIHJldHVybiB2YWx1ZTtcbn07XG5cbmV4cG9ydCBmdW5jdGlvbiBkaWZmQXJyYXlzKG9sZEFyciwgbmV3QXJyLCBjYWxsYmFjaykgeyByZXR1cm4gYXJyYXlEaWZmLmRpZmYob2xkQXJyLCBuZXdBcnIsIGNhbGxiYWNrKTsgfVxuIl19
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/base.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/base.js
          new file mode 100644
          index 00000000000000..48bbe234c74c48
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/base.js
          @@ -0,0 +1,304 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports["default"] = Diff;
          +
          +/*istanbul ignore end*/
          +function Diff() {}
          +
          +Diff.prototype = {
          +  /*istanbul ignore start*/
          +
          +  /*istanbul ignore end*/
          +  diff: function diff(oldString, newString) {
          +    /*istanbul ignore start*/
          +    var
          +    /*istanbul ignore end*/
          +    options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
          +    var callback = options.callback;
          +
          +    if (typeof options === 'function') {
          +      callback = options;
          +      options = {};
          +    }
          +
          +    this.options = options;
          +    var self = this;
          +
          +    function done(value) {
          +      if (callback) {
          +        setTimeout(function () {
          +          callback(undefined, value);
          +        }, 0);
          +        return true;
          +      } else {
          +        return value;
          +      }
          +    } // Allow subclasses to massage the input prior to running
          +
          +
          +    oldString = this.castInput(oldString);
          +    newString = this.castInput(newString);
          +    oldString = this.removeEmpty(this.tokenize(oldString));
          +    newString = this.removeEmpty(this.tokenize(newString));
          +    var newLen = newString.length,
          +        oldLen = oldString.length;
          +    var editLength = 1;
          +    var maxEditLength = newLen + oldLen;
          +    var bestPath = [{
          +      newPos: -1,
          +      components: []
          +    }]; // Seed editLength = 0, i.e. the content starts with the same values
          +
          +    var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
          +
          +    if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
          +      // Identity per the equality and tokenizer
          +      return done([{
          +        value: this.join(newString),
          +        count: newString.length
          +      }]);
          +    } // Main worker method. checks all permutations of a given edit length for acceptance.
          +
          +
          +    function execEditLength() {
          +      for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
          +        var basePath =
          +        /*istanbul ignore start*/
          +        void 0
          +        /*istanbul ignore end*/
          +        ;
          +
          +        var addPath = bestPath[diagonalPath - 1],
          +            removePath = bestPath[diagonalPath + 1],
          +            _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
          +
          +        if (addPath) {
          +          // No one else is going to attempt to use this value, clear it
          +          bestPath[diagonalPath - 1] = undefined;
          +        }
          +
          +        var canAdd = addPath && addPath.newPos + 1 < newLen,
          +            canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
          +
          +        if (!canAdd && !canRemove) {
          +          // If this path is a terminal then prune
          +          bestPath[diagonalPath] = undefined;
          +          continue;
          +        } // Select the diagonal that we want to branch from. We select the prior
          +        // path whose position in the new string is the farthest from the origin
          +        // and does not pass the bounds of the diff graph
          +
          +
          +        if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
          +          basePath = clonePath(removePath);
          +          self.pushComponent(basePath.components, undefined, true);
          +        } else {
          +          basePath = addPath; // No need to clone, we've pulled it from the list
          +
          +          basePath.newPos++;
          +          self.pushComponent(basePath.components, true, undefined);
          +        }
          +
          +        _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
          +
          +        if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
          +          return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
          +        } else {
          +          // Otherwise track this path as a potential candidate and continue.
          +          bestPath[diagonalPath] = basePath;
          +        }
          +      }
          +
          +      editLength++;
          +    } // Performs the length of edit iteration. Is a bit fugly as this has to support the
          +    // sync and async mode which is never fun. Loops over execEditLength until a value
          +    // is produced.
          +
          +
          +    if (callback) {
          +      (function exec() {
          +        setTimeout(function () {
          +          // This should not happen, but we want to be safe.
          +
          +          /* istanbul ignore next */
          +          if (editLength > maxEditLength) {
          +            return callback();
          +          }
          +
          +          if (!execEditLength()) {
          +            exec();
          +          }
          +        }, 0);
          +      })();
          +    } else {
          +      while (editLength <= maxEditLength) {
          +        var ret = execEditLength();
          +
          +        if (ret) {
          +          return ret;
          +        }
          +      }
          +    }
          +  },
          +
          +  /*istanbul ignore start*/
          +
          +  /*istanbul ignore end*/
          +  pushComponent: function pushComponent(components, added, removed) {
          +    var last = components[components.length - 1];
          +
          +    if (last && last.added === added && last.removed === removed) {
          +      // We need to clone here as the component clone operation is just
          +      // as shallow array clone
          +      components[components.length - 1] = {
          +        count: last.count + 1,
          +        added: added,
          +        removed: removed
          +      };
          +    } else {
          +      components.push({
          +        count: 1,
          +        added: added,
          +        removed: removed
          +      });
          +    }
          +  },
          +
          +  /*istanbul ignore start*/
          +
          +  /*istanbul ignore end*/
          +  extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
          +    var newLen = newString.length,
          +        oldLen = oldString.length,
          +        newPos = basePath.newPos,
          +        oldPos = newPos - diagonalPath,
          +        commonCount = 0;
          +
          +    while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
          +      newPos++;
          +      oldPos++;
          +      commonCount++;
          +    }
          +
          +    if (commonCount) {
          +      basePath.components.push({
          +        count: commonCount
          +      });
          +    }
          +
          +    basePath.newPos = newPos;
          +    return oldPos;
          +  },
          +
          +  /*istanbul ignore start*/
          +
          +  /*istanbul ignore end*/
          +  equals: function equals(left, right) {
          +    if (this.options.comparator) {
          +      return this.options.comparator(left, right);
          +    } else {
          +      return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
          +    }
          +  },
          +
          +  /*istanbul ignore start*/
          +
          +  /*istanbul ignore end*/
          +  removeEmpty: function removeEmpty(array) {
          +    var ret = [];
          +
          +    for (var i = 0; i < array.length; i++) {
          +      if (array[i]) {
          +        ret.push(array[i]);
          +      }
          +    }
          +
          +    return ret;
          +  },
          +
          +  /*istanbul ignore start*/
          +
          +  /*istanbul ignore end*/
          +  castInput: function castInput(value) {
          +    return value;
          +  },
          +
          +  /*istanbul ignore start*/
          +
          +  /*istanbul ignore end*/
          +  tokenize: function tokenize(value) {
          +    return value.split('');
          +  },
          +
          +  /*istanbul ignore start*/
          +
          +  /*istanbul ignore end*/
          +  join: function join(chars) {
          +    return chars.join('');
          +  }
          +};
          +
          +function buildValues(diff, components, newString, oldString, useLongestToken) {
          +  var componentPos = 0,
          +      componentLen = components.length,
          +      newPos = 0,
          +      oldPos = 0;
          +
          +  for (; componentPos < componentLen; componentPos++) {
          +    var component = components[componentPos];
          +
          +    if (!component.removed) {
          +      if (!component.added && useLongestToken) {
          +        var value = newString.slice(newPos, newPos + component.count);
          +        value = value.map(function (value, i) {
          +          var oldValue = oldString[oldPos + i];
          +          return oldValue.length > value.length ? oldValue : value;
          +        });
          +        component.value = diff.join(value);
          +      } else {
          +        component.value = diff.join(newString.slice(newPos, newPos + component.count));
          +      }
          +
          +      newPos += component.count; // Common case
          +
          +      if (!component.added) {
          +        oldPos += component.count;
          +      }
          +    } else {
          +      component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
          +      oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
          +      // The diffing algorithm is tied to add then remove output and this is the simplest
          +      // route to get the desired output with minimal overhead.
          +
          +      if (componentPos && components[componentPos - 1].added) {
          +        var tmp = components[componentPos - 1];
          +        components[componentPos - 1] = components[componentPos];
          +        components[componentPos] = tmp;
          +      }
          +    }
          +  } // Special case handle for when one terminal is ignored (i.e. whitespace).
          +  // For this case we merge the terminal into the prior string and drop the change.
          +  // This is only available for string mode.
          +
          +
          +  var lastComponent = components[componentLen - 1];
          +
          +  if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
          +    components[componentLen - 2].value += lastComponent.value;
          +    components.pop();
          +  }
          +
          +  return components;
          +}
          +
          +function clonePath(path) {
          +  return {
          +    newPos: path.newPos,
          +    components: path.components.slice(0)
          +  };
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL2Jhc2UuanMiXSwibmFtZXMiOlsiRGlmZiIsInByb3RvdHlwZSIsImRpZmYiLCJvbGRTdHJpbmciLCJuZXdTdHJpbmciLCJvcHRpb25zIiwiY2FsbGJhY2siLCJzZWxmIiwiZG9uZSIsInZhbHVlIiwic2V0VGltZW91dCIsInVuZGVmaW5lZCIsImNhc3RJbnB1dCIsInJlbW92ZUVtcHR5IiwidG9rZW5pemUiLCJuZXdMZW4iLCJsZW5ndGgiLCJvbGRMZW4iLCJlZGl0TGVuZ3RoIiwibWF4RWRpdExlbmd0aCIsImJlc3RQYXRoIiwibmV3UG9zIiwiY29tcG9uZW50cyIsIm9sZFBvcyIsImV4dHJhY3RDb21tb24iLCJqb2luIiwiY291bnQiLCJleGVjRWRpdExlbmd0aCIsImRpYWdvbmFsUGF0aCIsImJhc2VQYXRoIiwiYWRkUGF0aCIsInJlbW92ZVBhdGgiLCJjYW5BZGQiLCJjYW5SZW1vdmUiLCJjbG9uZVBhdGgiLCJwdXNoQ29tcG9uZW50IiwiYnVpbGRWYWx1ZXMiLCJ1c2VMb25nZXN0VG9rZW4iLCJleGVjIiwicmV0IiwiYWRkZWQiLCJyZW1vdmVkIiwibGFzdCIsInB1c2giLCJjb21tb25Db3VudCIsImVxdWFscyIsImxlZnQiLCJyaWdodCIsImNvbXBhcmF0b3IiLCJpZ25vcmVDYXNlIiwidG9Mb3dlckNhc2UiLCJhcnJheSIsImkiLCJzcGxpdCIsImNoYXJzIiwiY29tcG9uZW50UG9zIiwiY29tcG9uZW50TGVuIiwiY29tcG9uZW50Iiwic2xpY2UiLCJtYXAiLCJvbGRWYWx1ZSIsInRtcCIsImxhc3RDb21wb25lbnQiLCJwb3AiLCJwYXRoIl0sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBZSxTQUFTQSxJQUFULEdBQWdCLENBQUU7O0FBRWpDQSxJQUFJLENBQUNDLFNBQUwsR0FBaUI7QUFBQTs7QUFBQTtBQUNmQyxFQUFBQSxJQURlLGdCQUNWQyxTQURVLEVBQ0NDLFNBREQsRUFDMEI7QUFBQTtBQUFBO0FBQUE7QUFBZEMsSUFBQUEsT0FBYyx1RUFBSixFQUFJO0FBQ3ZDLFFBQUlDLFFBQVEsR0FBR0QsT0FBTyxDQUFDQyxRQUF2Qjs7QUFDQSxRQUFJLE9BQU9ELE9BQVAsS0FBbUIsVUFBdkIsRUFBbUM7QUFDakNDLE1BQUFBLFFBQVEsR0FBR0QsT0FBWDtBQUNBQSxNQUFBQSxPQUFPLEdBQUcsRUFBVjtBQUNEOztBQUNELFNBQUtBLE9BQUwsR0FBZUEsT0FBZjtBQUVBLFFBQUlFLElBQUksR0FBRyxJQUFYOztBQUVBLGFBQVNDLElBQVQsQ0FBY0MsS0FBZCxFQUFxQjtBQUNuQixVQUFJSCxRQUFKLEVBQWM7QUFDWkksUUFBQUEsVUFBVSxDQUFDLFlBQVc7QUFBRUosVUFBQUEsUUFBUSxDQUFDSyxTQUFELEVBQVlGLEtBQVosQ0FBUjtBQUE2QixTQUEzQyxFQUE2QyxDQUE3QyxDQUFWO0FBQ0EsZUFBTyxJQUFQO0FBQ0QsT0FIRCxNQUdPO0FBQ0wsZUFBT0EsS0FBUDtBQUNEO0FBQ0YsS0FqQnNDLENBbUJ2Qzs7O0FBQ0FOLElBQUFBLFNBQVMsR0FBRyxLQUFLUyxTQUFMLENBQWVULFNBQWYsQ0FBWjtBQUNBQyxJQUFBQSxTQUFTLEdBQUcsS0FBS1EsU0FBTCxDQUFlUixTQUFmLENBQVo7QUFFQUQsSUFBQUEsU0FBUyxHQUFHLEtBQUtVLFdBQUwsQ0FBaUIsS0FBS0MsUUFBTCxDQUFjWCxTQUFkLENBQWpCLENBQVo7QUFDQUMsSUFBQUEsU0FBUyxHQUFHLEtBQUtTLFdBQUwsQ0FBaUIsS0FBS0MsUUFBTCxDQUFjVixTQUFkLENBQWpCLENBQVo7QUFFQSxRQUFJVyxNQUFNLEdBQUdYLFNBQVMsQ0FBQ1ksTUFBdkI7QUFBQSxRQUErQkMsTUFBTSxHQUFHZCxTQUFTLENBQUNhLE1BQWxEO0FBQ0EsUUFBSUUsVUFBVSxHQUFHLENBQWpCO0FBQ0EsUUFBSUMsYUFBYSxHQUFHSixNQUFNLEdBQUdFLE1BQTdCO0FBQ0EsUUFBSUcsUUFBUSxHQUFHLENBQUM7QUFBRUMsTUFBQUEsTUFBTSxFQUFFLENBQUMsQ0FBWDtBQUFjQyxNQUFBQSxVQUFVLEVBQUU7QUFBMUIsS0FBRCxDQUFmLENBN0J1QyxDQStCdkM7O0FBQ0EsUUFBSUMsTUFBTSxHQUFHLEtBQUtDLGFBQUwsQ0FBbUJKLFFBQVEsQ0FBQyxDQUFELENBQTNCLEVBQWdDaEIsU0FBaEMsRUFBMkNELFNBQTNDLEVBQXNELENBQXRELENBQWI7O0FBQ0EsUUFBSWlCLFFBQVEsQ0FBQyxDQUFELENBQVIsQ0FBWUMsTUFBWixHQUFxQixDQUFyQixJQUEwQk4sTUFBMUIsSUFBb0NRLE1BQU0sR0FBRyxDQUFULElBQWNOLE1BQXRELEVBQThEO0FBQzVEO0FBQ0EsYUFBT1QsSUFBSSxDQUFDLENBQUM7QUFBQ0MsUUFBQUEsS0FBSyxFQUFFLEtBQUtnQixJQUFMLENBQVVyQixTQUFWLENBQVI7QUFBOEJzQixRQUFBQSxLQUFLLEVBQUV0QixTQUFTLENBQUNZO0FBQS9DLE9BQUQsQ0FBRCxDQUFYO0FBQ0QsS0FwQ3NDLENBc0N2Qzs7O0FBQ0EsYUFBU1csY0FBVCxHQUEwQjtBQUN4QixXQUFLLElBQUlDLFlBQVksR0FBRyxDQUFDLENBQUQsR0FBS1YsVUFBN0IsRUFBeUNVLFlBQVksSUFBSVYsVUFBekQsRUFBcUVVLFlBQVksSUFBSSxDQUFyRixFQUF3RjtBQUN0RixZQUFJQyxRQUFRO0FBQUE7QUFBQTtBQUFaO0FBQUE7O0FBQ0EsWUFBSUMsT0FBTyxHQUFHVixRQUFRLENBQUNRLFlBQVksR0FBRyxDQUFoQixDQUF0QjtBQUFBLFlBQ0lHLFVBQVUsR0FBR1gsUUFBUSxDQUFDUSxZQUFZLEdBQUcsQ0FBaEIsQ0FEekI7QUFBQSxZQUVJTCxPQUFNLEdBQUcsQ0FBQ1EsVUFBVSxHQUFHQSxVQUFVLENBQUNWLE1BQWQsR0FBdUIsQ0FBbEMsSUFBdUNPLFlBRnBEOztBQUdBLFlBQUlFLE9BQUosRUFBYTtBQUNYO0FBQ0FWLFVBQUFBLFFBQVEsQ0FBQ1EsWUFBWSxHQUFHLENBQWhCLENBQVIsR0FBNkJqQixTQUE3QjtBQUNEOztBQUVELFlBQUlxQixNQUFNLEdBQUdGLE9BQU8sSUFBSUEsT0FBTyxDQUFDVCxNQUFSLEdBQWlCLENBQWpCLEdBQXFCTixNQUE3QztBQUFBLFlBQ0lrQixTQUFTLEdBQUdGLFVBQVUsSUFBSSxLQUFLUixPQUFuQixJQUE2QkEsT0FBTSxHQUFHTixNQUR0RDs7QUFFQSxZQUFJLENBQUNlLE1BQUQsSUFBVyxDQUFDQyxTQUFoQixFQUEyQjtBQUN6QjtBQUNBYixVQUFBQSxRQUFRLENBQUNRLFlBQUQsQ0FBUixHQUF5QmpCLFNBQXpCO0FBQ0E7QUFDRCxTQWhCcUYsQ0FrQnRGO0FBQ0E7QUFDQTs7O0FBQ0EsWUFBSSxDQUFDcUIsTUFBRCxJQUFZQyxTQUFTLElBQUlILE9BQU8sQ0FBQ1QsTUFBUixHQUFpQlUsVUFBVSxDQUFDVixNQUF6RCxFQUFrRTtBQUNoRVEsVUFBQUEsUUFBUSxHQUFHSyxTQUFTLENBQUNILFVBQUQsQ0FBcEI7QUFDQXhCLFVBQUFBLElBQUksQ0FBQzRCLGFBQUwsQ0FBbUJOLFFBQVEsQ0FBQ1AsVUFBNUIsRUFBd0NYLFNBQXhDLEVBQW1ELElBQW5EO0FBQ0QsU0FIRCxNQUdPO0FBQ0xrQixVQUFBQSxRQUFRLEdBQUdDLE9BQVgsQ0FESyxDQUNlOztBQUNwQkQsVUFBQUEsUUFBUSxDQUFDUixNQUFUO0FBQ0FkLFVBQUFBLElBQUksQ0FBQzRCLGFBQUwsQ0FBbUJOLFFBQVEsQ0FBQ1AsVUFBNUIsRUFBd0MsSUFBeEMsRUFBOENYLFNBQTlDO0FBQ0Q7O0FBRURZLFFBQUFBLE9BQU0sR0FBR2hCLElBQUksQ0FBQ2lCLGFBQUwsQ0FBbUJLLFFBQW5CLEVBQTZCekIsU0FBN0IsRUFBd0NELFNBQXhDLEVBQW1EeUIsWUFBbkQsQ0FBVCxDQTlCc0YsQ0FnQ3RGOztBQUNBLFlBQUlDLFFBQVEsQ0FBQ1IsTUFBVCxHQUFrQixDQUFsQixJQUF1Qk4sTUFBdkIsSUFBaUNRLE9BQU0sR0FBRyxDQUFULElBQWNOLE1BQW5ELEVBQTJEO0FBQ3pELGlCQUFPVCxJQUFJLENBQUM0QixXQUFXLENBQUM3QixJQUFELEVBQU9zQixRQUFRLENBQUNQLFVBQWhCLEVBQTRCbEIsU0FBNUIsRUFBdUNELFNBQXZDLEVBQWtESSxJQUFJLENBQUM4QixlQUF2RCxDQUFaLENBQVg7QUFDRCxTQUZELE1BRU87QUFDTDtBQUNBakIsVUFBQUEsUUFBUSxDQUFDUSxZQUFELENBQVIsR0FBeUJDLFFBQXpCO0FBQ0Q7QUFDRjs7QUFFRFgsTUFBQUEsVUFBVTtBQUNYLEtBbEZzQyxDQW9GdkM7QUFDQTtBQUNBOzs7QUFDQSxRQUFJWixRQUFKLEVBQWM7QUFDWCxnQkFBU2dDLElBQVQsR0FBZ0I7QUFDZjVCLFFBQUFBLFVBQVUsQ0FBQyxZQUFXO0FBQ3BCOztBQUNBO0FBQ0EsY0FBSVEsVUFBVSxHQUFHQyxhQUFqQixFQUFnQztBQUM5QixtQkFBT2IsUUFBUSxFQUFmO0FBQ0Q7O0FBRUQsY0FBSSxDQUFDcUIsY0FBYyxFQUFuQixFQUF1QjtBQUNyQlcsWUFBQUEsSUFBSTtBQUNMO0FBQ0YsU0FWUyxFQVVQLENBVk8sQ0FBVjtBQVdELE9BWkEsR0FBRDtBQWFELEtBZEQsTUFjTztBQUNMLGFBQU9wQixVQUFVLElBQUlDLGFBQXJCLEVBQW9DO0FBQ2xDLFlBQUlvQixHQUFHLEdBQUdaLGNBQWMsRUFBeEI7O0FBQ0EsWUFBSVksR0FBSixFQUFTO0FBQ1AsaUJBQU9BLEdBQVA7QUFDRDtBQUNGO0FBQ0Y7QUFDRixHQTlHYzs7QUFBQTs7QUFBQTtBQWdIZkosRUFBQUEsYUFoSGUseUJBZ0hEYixVQWhIQyxFQWdIV2tCLEtBaEhYLEVBZ0hrQkMsT0FoSGxCLEVBZ0gyQjtBQUN4QyxRQUFJQyxJQUFJLEdBQUdwQixVQUFVLENBQUNBLFVBQVUsQ0FBQ04sTUFBWCxHQUFvQixDQUFyQixDQUFyQjs7QUFDQSxRQUFJMEIsSUFBSSxJQUFJQSxJQUFJLENBQUNGLEtBQUwsS0FBZUEsS0FBdkIsSUFBZ0NFLElBQUksQ0FBQ0QsT0FBTCxLQUFpQkEsT0FBckQsRUFBOEQ7QUFDNUQ7QUFDQTtBQUNBbkIsTUFBQUEsVUFBVSxDQUFDQSxVQUFVLENBQUNOLE1BQVgsR0FBb0IsQ0FBckIsQ0FBVixHQUFvQztBQUFDVSxRQUFBQSxLQUFLLEVBQUVnQixJQUFJLENBQUNoQixLQUFMLEdBQWEsQ0FBckI7QUFBd0JjLFFBQUFBLEtBQUssRUFBRUEsS0FBL0I7QUFBc0NDLFFBQUFBLE9BQU8sRUFBRUE7QUFBL0MsT0FBcEM7QUFDRCxLQUpELE1BSU87QUFDTG5CLE1BQUFBLFVBQVUsQ0FBQ3FCLElBQVgsQ0FBZ0I7QUFBQ2pCLFFBQUFBLEtBQUssRUFBRSxDQUFSO0FBQVdjLFFBQUFBLEtBQUssRUFBRUEsS0FBbEI7QUFBeUJDLFFBQUFBLE9BQU8sRUFBRUE7QUFBbEMsT0FBaEI7QUFDRDtBQUNGLEdBekhjOztBQUFBOztBQUFBO0FBMEhmakIsRUFBQUEsYUExSGUseUJBMEhESyxRQTFIQyxFQTBIU3pCLFNBMUhULEVBMEhvQkQsU0ExSHBCLEVBMEgrQnlCLFlBMUgvQixFQTBINkM7QUFDMUQsUUFBSWIsTUFBTSxHQUFHWCxTQUFTLENBQUNZLE1BQXZCO0FBQUEsUUFDSUMsTUFBTSxHQUFHZCxTQUFTLENBQUNhLE1BRHZCO0FBQUEsUUFFSUssTUFBTSxHQUFHUSxRQUFRLENBQUNSLE1BRnRCO0FBQUEsUUFHSUUsTUFBTSxHQUFHRixNQUFNLEdBQUdPLFlBSHRCO0FBQUEsUUFLSWdCLFdBQVcsR0FBRyxDQUxsQjs7QUFNQSxXQUFPdkIsTUFBTSxHQUFHLENBQVQsR0FBYU4sTUFBYixJQUF1QlEsTUFBTSxHQUFHLENBQVQsR0FBYU4sTUFBcEMsSUFBOEMsS0FBSzRCLE1BQUwsQ0FBWXpDLFNBQVMsQ0FBQ2lCLE1BQU0sR0FBRyxDQUFWLENBQXJCLEVBQW1DbEIsU0FBUyxDQUFDb0IsTUFBTSxHQUFHLENBQVYsQ0FBNUMsQ0FBckQsRUFBZ0g7QUFDOUdGLE1BQUFBLE1BQU07QUFDTkUsTUFBQUEsTUFBTTtBQUNOcUIsTUFBQUEsV0FBVztBQUNaOztBQUVELFFBQUlBLFdBQUosRUFBaUI7QUFDZmYsTUFBQUEsUUFBUSxDQUFDUCxVQUFULENBQW9CcUIsSUFBcEIsQ0FBeUI7QUFBQ2pCLFFBQUFBLEtBQUssRUFBRWtCO0FBQVIsT0FBekI7QUFDRDs7QUFFRGYsSUFBQUEsUUFBUSxDQUFDUixNQUFULEdBQWtCQSxNQUFsQjtBQUNBLFdBQU9FLE1BQVA7QUFDRCxHQTdJYzs7QUFBQTs7QUFBQTtBQStJZnNCLEVBQUFBLE1BL0llLGtCQStJUkMsSUEvSVEsRUErSUZDLEtBL0lFLEVBK0lLO0FBQ2xCLFFBQUksS0FBSzFDLE9BQUwsQ0FBYTJDLFVBQWpCLEVBQTZCO0FBQzNCLGFBQU8sS0FBSzNDLE9BQUwsQ0FBYTJDLFVBQWIsQ0FBd0JGLElBQXhCLEVBQThCQyxLQUE5QixDQUFQO0FBQ0QsS0FGRCxNQUVPO0FBQ0wsYUFBT0QsSUFBSSxLQUFLQyxLQUFULElBQ0QsS0FBSzFDLE9BQUwsQ0FBYTRDLFVBQWIsSUFBMkJILElBQUksQ0FBQ0ksV0FBTCxPQUF1QkgsS0FBSyxDQUFDRyxXQUFOLEVBRHhEO0FBRUQ7QUFDRixHQXRKYzs7QUFBQTs7QUFBQTtBQXVKZnJDLEVBQUFBLFdBdkplLHVCQXVKSHNDLEtBdkpHLEVBdUpJO0FBQ2pCLFFBQUlaLEdBQUcsR0FBRyxFQUFWOztBQUNBLFNBQUssSUFBSWEsQ0FBQyxHQUFHLENBQWIsRUFBZ0JBLENBQUMsR0FBR0QsS0FBSyxDQUFDbkMsTUFBMUIsRUFBa0NvQyxDQUFDLEVBQW5DLEVBQXVDO0FBQ3JDLFVBQUlELEtBQUssQ0FBQ0MsQ0FBRCxDQUFULEVBQWM7QUFDWmIsUUFBQUEsR0FBRyxDQUFDSSxJQUFKLENBQVNRLEtBQUssQ0FBQ0MsQ0FBRCxDQUFkO0FBQ0Q7QUFDRjs7QUFDRCxXQUFPYixHQUFQO0FBQ0QsR0EvSmM7O0FBQUE7O0FBQUE7QUFnS2YzQixFQUFBQSxTQWhLZSxxQkFnS0xILEtBaEtLLEVBZ0tFO0FBQ2YsV0FBT0EsS0FBUDtBQUNELEdBbEtjOztBQUFBOztBQUFBO0FBbUtmSyxFQUFBQSxRQW5LZSxvQkFtS05MLEtBbktNLEVBbUtDO0FBQ2QsV0FBT0EsS0FBSyxDQUFDNEMsS0FBTixDQUFZLEVBQVosQ0FBUDtBQUNELEdBcktjOztBQUFBOztBQUFBO0FBc0tmNUIsRUFBQUEsSUF0S2UsZ0JBc0tWNkIsS0F0S1UsRUFzS0g7QUFDVixXQUFPQSxLQUFLLENBQUM3QixJQUFOLENBQVcsRUFBWCxDQUFQO0FBQ0Q7QUF4S2MsQ0FBakI7O0FBMktBLFNBQVNXLFdBQVQsQ0FBcUJsQyxJQUFyQixFQUEyQm9CLFVBQTNCLEVBQXVDbEIsU0FBdkMsRUFBa0RELFNBQWxELEVBQTZEa0MsZUFBN0QsRUFBOEU7QUFDNUUsTUFBSWtCLFlBQVksR0FBRyxDQUFuQjtBQUFBLE1BQ0lDLFlBQVksR0FBR2xDLFVBQVUsQ0FBQ04sTUFEOUI7QUFBQSxNQUVJSyxNQUFNLEdBQUcsQ0FGYjtBQUFBLE1BR0lFLE1BQU0sR0FBRyxDQUhiOztBQUtBLFNBQU9nQyxZQUFZLEdBQUdDLFlBQXRCLEVBQW9DRCxZQUFZLEVBQWhELEVBQW9EO0FBQ2xELFFBQUlFLFNBQVMsR0FBR25DLFVBQVUsQ0FBQ2lDLFlBQUQsQ0FBMUI7O0FBQ0EsUUFBSSxDQUFDRSxTQUFTLENBQUNoQixPQUFmLEVBQXdCO0FBQ3RCLFVBQUksQ0FBQ2dCLFNBQVMsQ0FBQ2pCLEtBQVgsSUFBb0JILGVBQXhCLEVBQXlDO0FBQ3ZDLFlBQUk1QixLQUFLLEdBQUdMLFNBQVMsQ0FBQ3NELEtBQVYsQ0FBZ0JyQyxNQUFoQixFQUF3QkEsTUFBTSxHQUFHb0MsU0FBUyxDQUFDL0IsS0FBM0MsQ0FBWjtBQUNBakIsUUFBQUEsS0FBSyxHQUFHQSxLQUFLLENBQUNrRCxHQUFOLENBQVUsVUFBU2xELEtBQVQsRUFBZ0IyQyxDQUFoQixFQUFtQjtBQUNuQyxjQUFJUSxRQUFRLEdBQUd6RCxTQUFTLENBQUNvQixNQUFNLEdBQUc2QixDQUFWLENBQXhCO0FBQ0EsaUJBQU9RLFFBQVEsQ0FBQzVDLE1BQVQsR0FBa0JQLEtBQUssQ0FBQ08sTUFBeEIsR0FBaUM0QyxRQUFqQyxHQUE0Q25ELEtBQW5EO0FBQ0QsU0FITyxDQUFSO0FBS0FnRCxRQUFBQSxTQUFTLENBQUNoRCxLQUFWLEdBQWtCUCxJQUFJLENBQUN1QixJQUFMLENBQVVoQixLQUFWLENBQWxCO0FBQ0QsT0FSRCxNQVFPO0FBQ0xnRCxRQUFBQSxTQUFTLENBQUNoRCxLQUFWLEdBQWtCUCxJQUFJLENBQUN1QixJQUFMLENBQVVyQixTQUFTLENBQUNzRCxLQUFWLENBQWdCckMsTUFBaEIsRUFBd0JBLE1BQU0sR0FBR29DLFNBQVMsQ0FBQy9CLEtBQTNDLENBQVYsQ0FBbEI7QUFDRDs7QUFDREwsTUFBQUEsTUFBTSxJQUFJb0MsU0FBUyxDQUFDL0IsS0FBcEIsQ0Fac0IsQ0FjdEI7O0FBQ0EsVUFBSSxDQUFDK0IsU0FBUyxDQUFDakIsS0FBZixFQUFzQjtBQUNwQmpCLFFBQUFBLE1BQU0sSUFBSWtDLFNBQVMsQ0FBQy9CLEtBQXBCO0FBQ0Q7QUFDRixLQWxCRCxNQWtCTztBQUNMK0IsTUFBQUEsU0FBUyxDQUFDaEQsS0FBVixHQUFrQlAsSUFBSSxDQUFDdUIsSUFBTCxDQUFVdEIsU0FBUyxDQUFDdUQsS0FBVixDQUFnQm5DLE1BQWhCLEVBQXdCQSxNQUFNLEdBQUdrQyxTQUFTLENBQUMvQixLQUEzQyxDQUFWLENBQWxCO0FBQ0FILE1BQUFBLE1BQU0sSUFBSWtDLFNBQVMsQ0FBQy9CLEtBQXBCLENBRkssQ0FJTDtBQUNBO0FBQ0E7O0FBQ0EsVUFBSTZCLFlBQVksSUFBSWpDLFVBQVUsQ0FBQ2lDLFlBQVksR0FBRyxDQUFoQixDQUFWLENBQTZCZixLQUFqRCxFQUF3RDtBQUN0RCxZQUFJcUIsR0FBRyxHQUFHdkMsVUFBVSxDQUFDaUMsWUFBWSxHQUFHLENBQWhCLENBQXBCO0FBQ0FqQyxRQUFBQSxVQUFVLENBQUNpQyxZQUFZLEdBQUcsQ0FBaEIsQ0FBVixHQUErQmpDLFVBQVUsQ0FBQ2lDLFlBQUQsQ0FBekM7QUFDQWpDLFFBQUFBLFVBQVUsQ0FBQ2lDLFlBQUQsQ0FBVixHQUEyQk0sR0FBM0I7QUFDRDtBQUNGO0FBQ0YsR0F2QzJFLENBeUM1RTtBQUNBO0FBQ0E7OztBQUNBLE1BQUlDLGFBQWEsR0FBR3hDLFVBQVUsQ0FBQ2tDLFlBQVksR0FBRyxDQUFoQixDQUE5Qjs7QUFDQSxNQUFJQSxZQUFZLEdBQUcsQ0FBZixJQUNHLE9BQU9NLGFBQWEsQ0FBQ3JELEtBQXJCLEtBQStCLFFBRGxDLEtBRUlxRCxhQUFhLENBQUN0QixLQUFkLElBQXVCc0IsYUFBYSxDQUFDckIsT0FGekMsS0FHR3ZDLElBQUksQ0FBQzJDLE1BQUwsQ0FBWSxFQUFaLEVBQWdCaUIsYUFBYSxDQUFDckQsS0FBOUIsQ0FIUCxFQUc2QztBQUMzQ2EsSUFBQUEsVUFBVSxDQUFDa0MsWUFBWSxHQUFHLENBQWhCLENBQVYsQ0FBNkIvQyxLQUE3QixJQUFzQ3FELGFBQWEsQ0FBQ3JELEtBQXBEO0FBQ0FhLElBQUFBLFVBQVUsQ0FBQ3lDLEdBQVg7QUFDRDs7QUFFRCxTQUFPekMsVUFBUDtBQUNEOztBQUVELFNBQVNZLFNBQVQsQ0FBbUI4QixJQUFuQixFQUF5QjtBQUN2QixTQUFPO0FBQUUzQyxJQUFBQSxNQUFNLEVBQUUyQyxJQUFJLENBQUMzQyxNQUFmO0FBQXVCQyxJQUFBQSxVQUFVLEVBQUUwQyxJQUFJLENBQUMxQyxVQUFMLENBQWdCb0MsS0FBaEIsQ0FBc0IsQ0FBdEI7QUFBbkMsR0FBUDtBQUNEIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24gRGlmZigpIHt9XG5cbkRpZmYucHJvdG90eXBlID0ge1xuICBkaWZmKG9sZFN0cmluZywgbmV3U3RyaW5nLCBvcHRpb25zID0ge30pIHtcbiAgICBsZXQgY2FsbGJhY2sgPSBvcHRpb25zLmNhbGxiYWNrO1xuICAgIGlmICh0eXBlb2Ygb3B0aW9ucyA9PT0gJ2Z1bmN0aW9uJykge1xuICAgICAgY2FsbGJhY2sgPSBvcHRpb25zO1xuICAgICAgb3B0aW9ucyA9IHt9O1xuICAgIH1cbiAgICB0aGlzLm9wdGlvbnMgPSBvcHRpb25zO1xuXG4gICAgbGV0IHNlbGYgPSB0aGlzO1xuXG4gICAgZnVuY3Rpb24gZG9uZSh2YWx1ZSkge1xuICAgICAgaWYgKGNhbGxiYWNrKSB7XG4gICAgICAgIHNldFRpbWVvdXQoZnVuY3Rpb24oKSB7IGNhbGxiYWNrKHVuZGVmaW5lZCwgdmFsdWUpOyB9LCAwKTtcbiAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gdmFsdWU7XG4gICAgICB9XG4gICAgfVxuXG4gICAgLy8gQWxsb3cgc3ViY2xhc3NlcyB0byBtYXNzYWdlIHRoZSBpbnB1dCBwcmlvciB0byBydW5uaW5nXG4gICAgb2xkU3RyaW5nID0gdGhpcy5jYXN0SW5wdXQob2xkU3RyaW5nKTtcbiAgICBuZXdTdHJpbmcgPSB0aGlzLmNhc3RJbnB1dChuZXdTdHJpbmcpO1xuXG4gICAgb2xkU3RyaW5nID0gdGhpcy5yZW1vdmVFbXB0eSh0aGlzLnRva2VuaXplKG9sZFN0cmluZykpO1xuICAgIG5ld1N0cmluZyA9IHRoaXMucmVtb3ZlRW1wdHkodGhpcy50b2tlbml6ZShuZXdTdHJpbmcpKTtcblxuICAgIGxldCBuZXdMZW4gPSBuZXdTdHJpbmcubGVuZ3RoLCBvbGRMZW4gPSBvbGRTdHJpbmcubGVuZ3RoO1xuICAgIGxldCBlZGl0TGVuZ3RoID0gMTtcbiAgICBsZXQgbWF4RWRpdExlbmd0aCA9IG5ld0xlbiArIG9sZExlbjtcbiAgICBsZXQgYmVzdFBhdGggPSBbeyBuZXdQb3M6IC0xLCBjb21wb25lbnRzOiBbXSB9XTtcblxuICAgIC8vIFNlZWQgZWRpdExlbmd0aCA9IDAsIGkuZS4gdGhlIGNvbnRlbnQgc3RhcnRzIHdpdGggdGhlIHNhbWUgdmFsdWVzXG4gICAgbGV0IG9sZFBvcyA9IHRoaXMuZXh0cmFjdENvbW1vbihiZXN0UGF0aFswXSwgbmV3U3RyaW5nLCBvbGRTdHJpbmcsIDApO1xuICAgIGlmIChiZXN0UGF0aFswXS5uZXdQb3MgKyAxID49IG5ld0xlbiAmJiBvbGRQb3MgKyAxID49IG9sZExlbikge1xuICAgICAgLy8gSWRlbnRpdHkgcGVyIHRoZSBlcXVhbGl0eSBhbmQgdG9rZW5pemVyXG4gICAgICByZXR1cm4gZG9uZShbe3ZhbHVlOiB0aGlzLmpvaW4obmV3U3RyaW5nKSwgY291bnQ6IG5ld1N0cmluZy5sZW5ndGh9XSk7XG4gICAgfVxuXG4gICAgLy8gTWFpbiB3b3JrZXIgbWV0aG9kLiBjaGVja3MgYWxsIHBlcm11dGF0aW9ucyBvZiBhIGdpdmVuIGVkaXQgbGVuZ3RoIGZvciBhY2NlcHRhbmNlLlxuICAgIGZ1bmN0aW9uIGV4ZWNFZGl0TGVuZ3RoKCkge1xuICAgICAgZm9yIChsZXQgZGlhZ29uYWxQYXRoID0gLTEgKiBlZGl0TGVuZ3RoOyBkaWFnb25hbFBhdGggPD0gZWRpdExlbmd0aDsgZGlhZ29uYWxQYXRoICs9IDIpIHtcbiAgICAgICAgbGV0IGJhc2VQYXRoO1xuICAgICAgICBsZXQgYWRkUGF0aCA9IGJlc3RQYXRoW2RpYWdvbmFsUGF0aCAtIDFdLFxuICAgICAgICAgICAgcmVtb3ZlUGF0aCA9IGJlc3RQYXRoW2RpYWdvbmFsUGF0aCArIDFdLFxuICAgICAgICAgICAgb2xkUG9zID0gKHJlbW92ZVBhdGggPyByZW1vdmVQYXRoLm5ld1BvcyA6IDApIC0gZGlhZ29uYWxQYXRoO1xuICAgICAgICBpZiAoYWRkUGF0aCkge1xuICAgICAgICAgIC8vIE5vIG9uZSBlbHNlIGlzIGdvaW5nIHRvIGF0dGVtcHQgdG8gdXNlIHRoaXMgdmFsdWUsIGNsZWFyIGl0XG4gICAgICAgICAgYmVzdFBhdGhbZGlhZ29uYWxQYXRoIC0gMV0gPSB1bmRlZmluZWQ7XG4gICAgICAgIH1cblxuICAgICAgICBsZXQgY2FuQWRkID0gYWRkUGF0aCAmJiBhZGRQYXRoLm5ld1BvcyArIDEgPCBuZXdMZW4sXG4gICAgICAgICAgICBjYW5SZW1vdmUgPSByZW1vdmVQYXRoICYmIDAgPD0gb2xkUG9zICYmIG9sZFBvcyA8IG9sZExlbjtcbiAgICAgICAgaWYgKCFjYW5BZGQgJiYgIWNhblJlbW92ZSkge1xuICAgICAgICAgIC8vIElmIHRoaXMgcGF0aCBpcyBhIHRlcm1pbmFsIHRoZW4gcHJ1bmVcbiAgICAgICAgICBiZXN0UGF0aFtkaWFnb25hbFBhdGhdID0gdW5kZWZpbmVkO1xuICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICB9XG5cbiAgICAgICAgLy8gU2VsZWN0IHRoZSBkaWFnb25hbCB0aGF0IHdlIHdhbnQgdG8gYnJhbmNoIGZyb20uIFdlIHNlbGVjdCB0aGUgcHJpb3JcbiAgICAgICAgLy8gcGF0aCB3aG9zZSBwb3NpdGlvbiBpbiB0aGUgbmV3IHN0cmluZyBpcyB0aGUgZmFydGhlc3QgZnJvbSB0aGUgb3JpZ2luXG4gICAgICAgIC8vIGFuZCBkb2VzIG5vdCBwYXNzIHRoZSBib3VuZHMgb2YgdGhlIGRpZmYgZ3JhcGhcbiAgICAgICAgaWYgKCFjYW5BZGQgfHwgKGNhblJlbW92ZSAmJiBhZGRQYXRoLm5ld1BvcyA8IHJlbW92ZVBhdGgubmV3UG9zKSkge1xuICAgICAgICAgIGJhc2VQYXRoID0gY2xvbmVQYXRoKHJlbW92ZVBhdGgpO1xuICAgICAgICAgIHNlbGYucHVzaENvbXBvbmVudChiYXNlUGF0aC5jb21wb25lbnRzLCB1bmRlZmluZWQsIHRydWUpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGJhc2VQYXRoID0gYWRkUGF0aDsgLy8gTm8gbmVlZCB0byBjbG9uZSwgd2UndmUgcHVsbGVkIGl0IGZyb20gdGhlIGxpc3RcbiAgICAgICAgICBiYXNlUGF0aC5uZXdQb3MrKztcbiAgICAgICAgICBzZWxmLnB1c2hDb21wb25lbnQoYmFzZVBhdGguY29tcG9uZW50cywgdHJ1ZSwgdW5kZWZpbmVkKTtcbiAgICAgICAgfVxuXG4gICAgICAgIG9sZFBvcyA9IHNlbGYuZXh0cmFjdENvbW1vbihiYXNlUGF0aCwgbmV3U3RyaW5nLCBvbGRTdHJpbmcsIGRpYWdvbmFsUGF0aCk7XG5cbiAgICAgICAgLy8gSWYgd2UgaGF2ZSBoaXQgdGhlIGVuZCBvZiBib3RoIHN0cmluZ3MsIHRoZW4gd2UgYXJlIGRvbmVcbiAgICAgICAgaWYgKGJhc2VQYXRoLm5ld1BvcyArIDEgPj0gbmV3TGVuICYmIG9sZFBvcyArIDEgPj0gb2xkTGVuKSB7XG4gICAgICAgICAgcmV0dXJuIGRvbmUoYnVpbGRWYWx1ZXMoc2VsZiwgYmFzZVBhdGguY29tcG9uZW50cywgbmV3U3RyaW5nLCBvbGRTdHJpbmcsIHNlbGYudXNlTG9uZ2VzdFRva2VuKSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgLy8gT3RoZXJ3aXNlIHRyYWNrIHRoaXMgcGF0aCBhcyBhIHBvdGVudGlhbCBjYW5kaWRhdGUgYW5kIGNvbnRpbnVlLlxuICAgICAgICAgIGJlc3RQYXRoW2RpYWdvbmFsUGF0aF0gPSBiYXNlUGF0aDtcbiAgICAgICAgfVxuICAgICAgfVxuXG4gICAgICBlZGl0TGVuZ3RoKys7XG4gICAgfVxuXG4gICAgLy8gUGVyZm9ybXMgdGhlIGxlbmd0aCBvZiBlZGl0IGl0ZXJhdGlvbi4gSXMgYSBiaXQgZnVnbHkgYXMgdGhpcyBoYXMgdG8gc3VwcG9ydCB0aGVcbiAgICAvLyBzeW5jIGFuZCBhc3luYyBtb2RlIHdoaWNoIGlzIG5ldmVyIGZ1bi4gTG9vcHMgb3ZlciBleGVjRWRpdExlbmd0aCB1bnRpbCBhIHZhbHVlXG4gICAgLy8gaXMgcHJvZHVjZWQuXG4gICAgaWYgKGNhbGxiYWNrKSB7XG4gICAgICAoZnVuY3Rpb24gZXhlYygpIHtcbiAgICAgICAgc2V0VGltZW91dChmdW5jdGlvbigpIHtcbiAgICAgICAgICAvLyBUaGlzIHNob3VsZCBub3QgaGFwcGVuLCBidXQgd2Ugd2FudCB0byBiZSBzYWZlLlxuICAgICAgICAgIC8qIGlzdGFuYnVsIGlnbm9yZSBuZXh0ICovXG4gICAgICAgICAgaWYgKGVkaXRMZW5ndGggPiBtYXhFZGl0TGVuZ3RoKSB7XG4gICAgICAgICAgICByZXR1cm4gY2FsbGJhY2soKTtcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBpZiAoIWV4ZWNFZGl0TGVuZ3RoKCkpIHtcbiAgICAgICAgICAgIGV4ZWMoKTtcbiAgICAgICAgICB9XG4gICAgICAgIH0sIDApO1xuICAgICAgfSgpKTtcbiAgICB9IGVsc2Uge1xuICAgICAgd2hpbGUgKGVkaXRMZW5ndGggPD0gbWF4RWRpdExlbmd0aCkge1xuICAgICAgICBsZXQgcmV0ID0gZXhlY0VkaXRMZW5ndGgoKTtcbiAgICAgICAgaWYgKHJldCkge1xuICAgICAgICAgIHJldHVybiByZXQ7XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9XG4gIH0sXG5cbiAgcHVzaENvbXBvbmVudChjb21wb25lbnRzLCBhZGRlZCwgcmVtb3ZlZCkge1xuICAgIGxldCBsYXN0ID0gY29tcG9uZW50c1tjb21wb25lbnRzLmxlbmd0aCAtIDFdO1xuICAgIGlmIChsYXN0ICYmIGxhc3QuYWRkZWQgPT09IGFkZGVkICYmIGxhc3QucmVtb3ZlZCA9PT0gcmVtb3ZlZCkge1xuICAgICAgLy8gV2UgbmVlZCB0byBjbG9uZSBoZXJlIGFzIHRoZSBjb21wb25lbnQgY2xvbmUgb3BlcmF0aW9uIGlzIGp1c3RcbiAgICAgIC8vIGFzIHNoYWxsb3cgYXJyYXkgY2xvbmVcbiAgICAgIGNvbXBvbmVudHNbY29tcG9uZW50cy5sZW5ndGggLSAxXSA9IHtjb3VudDogbGFzdC5jb3VudCArIDEsIGFkZGVkOiBhZGRlZCwgcmVtb3ZlZDogcmVtb3ZlZCB9O1xuICAgIH0gZWxzZSB7XG4gICAgICBjb21wb25lbnRzLnB1c2goe2NvdW50OiAxLCBhZGRlZDogYWRkZWQsIHJlbW92ZWQ6IHJlbW92ZWQgfSk7XG4gICAgfVxuICB9LFxuICBleHRyYWN0Q29tbW9uKGJhc2VQYXRoLCBuZXdTdHJpbmcsIG9sZFN0cmluZywgZGlhZ29uYWxQYXRoKSB7XG4gICAgbGV0IG5ld0xlbiA9IG5ld1N0cmluZy5sZW5ndGgsXG4gICAgICAgIG9sZExlbiA9IG9sZFN0cmluZy5sZW5ndGgsXG4gICAgICAgIG5ld1BvcyA9IGJhc2VQYXRoLm5ld1BvcyxcbiAgICAgICAgb2xkUG9zID0gbmV3UG9zIC0gZGlhZ29uYWxQYXRoLFxuXG4gICAgICAgIGNvbW1vbkNvdW50ID0gMDtcbiAgICB3aGlsZSAobmV3UG9zICsgMSA8IG5ld0xlbiAmJiBvbGRQb3MgKyAxIDwgb2xkTGVuICYmIHRoaXMuZXF1YWxzKG5ld1N0cmluZ1tuZXdQb3MgKyAxXSwgb2xkU3RyaW5nW29sZFBvcyArIDFdKSkge1xuICAgICAgbmV3UG9zKys7XG4gICAgICBvbGRQb3MrKztcbiAgICAgIGNvbW1vbkNvdW50Kys7XG4gICAgfVxuXG4gICAgaWYgKGNvbW1vbkNvdW50KSB7XG4gICAgICBiYXNlUGF0aC5jb21wb25lbnRzLnB1c2goe2NvdW50OiBjb21tb25Db3VudH0pO1xuICAgIH1cblxuICAgIGJhc2VQYXRoLm5ld1BvcyA9IG5ld1BvcztcbiAgICByZXR1cm4gb2xkUG9zO1xuICB9LFxuXG4gIGVxdWFscyhsZWZ0LCByaWdodCkge1xuICAgIGlmICh0aGlzLm9wdGlvbnMuY29tcGFyYXRvcikge1xuICAgICAgcmV0dXJuIHRoaXMub3B0aW9ucy5jb21wYXJhdG9yKGxlZnQsIHJpZ2h0KTtcbiAgICB9IGVsc2Uge1xuICAgICAgcmV0dXJuIGxlZnQgPT09IHJpZ2h0XG4gICAgICAgIHx8ICh0aGlzLm9wdGlvbnMuaWdub3JlQ2FzZSAmJiBsZWZ0LnRvTG93ZXJDYXNlKCkgPT09IHJpZ2h0LnRvTG93ZXJDYXNlKCkpO1xuICAgIH1cbiAgfSxcbiAgcmVtb3ZlRW1wdHkoYXJyYXkpIHtcbiAgICBsZXQgcmV0ID0gW107XG4gICAgZm9yIChsZXQgaSA9IDA7IGkgPCBhcnJheS5sZW5ndGg7IGkrKykge1xuICAgICAgaWYgKGFycmF5W2ldKSB7XG4gICAgICAgIHJldC5wdXNoKGFycmF5W2ldKTtcbiAgICAgIH1cbiAgICB9XG4gICAgcmV0dXJuIHJldDtcbiAgfSxcbiAgY2FzdElucHV0KHZhbHVlKSB7XG4gICAgcmV0dXJuIHZhbHVlO1xuICB9LFxuICB0b2tlbml6ZSh2YWx1ZSkge1xuICAgIHJldHVybiB2YWx1ZS5zcGxpdCgnJyk7XG4gIH0sXG4gIGpvaW4oY2hhcnMpIHtcbiAgICByZXR1cm4gY2hhcnMuam9pbignJyk7XG4gIH1cbn07XG5cbmZ1bmN0aW9uIGJ1aWxkVmFsdWVzKGRpZmYsIGNvbXBvbmVudHMsIG5ld1N0cmluZywgb2xkU3RyaW5nLCB1c2VMb25nZXN0VG9rZW4pIHtcbiAgbGV0IGNvbXBvbmVudFBvcyA9IDAsXG4gICAgICBjb21wb25lbnRMZW4gPSBjb21wb25lbnRzLmxlbmd0aCxcbiAgICAgIG5ld1BvcyA9IDAsXG4gICAgICBvbGRQb3MgPSAwO1xuXG4gIGZvciAoOyBjb21wb25lbnRQb3MgPCBjb21wb25lbnRMZW47IGNvbXBvbmVudFBvcysrKSB7XG4gICAgbGV0IGNvbXBvbmVudCA9IGNvbXBvbmVudHNbY29tcG9uZW50UG9zXTtcbiAgICBpZiAoIWNvbXBvbmVudC5yZW1vdmVkKSB7XG4gICAgICBpZiAoIWNvbXBvbmVudC5hZGRlZCAmJiB1c2VMb25nZXN0VG9rZW4pIHtcbiAgICAgICAgbGV0IHZhbHVlID0gbmV3U3RyaW5nLnNsaWNlKG5ld1BvcywgbmV3UG9zICsgY29tcG9uZW50LmNvdW50KTtcbiAgICAgICAgdmFsdWUgPSB2YWx1ZS5tYXAoZnVuY3Rpb24odmFsdWUsIGkpIHtcbiAgICAgICAgICBsZXQgb2xkVmFsdWUgPSBvbGRTdHJpbmdbb2xkUG9zICsgaV07XG4gICAgICAgICAgcmV0dXJuIG9sZFZhbHVlLmxlbmd0aCA+IHZhbHVlLmxlbmd0aCA/IG9sZFZhbHVlIDogdmFsdWU7XG4gICAgICAgIH0pO1xuXG4gICAgICAgIGNvbXBvbmVudC52YWx1ZSA9IGRpZmYuam9pbih2YWx1ZSk7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBjb21wb25lbnQudmFsdWUgPSBkaWZmLmpvaW4obmV3U3RyaW5nLnNsaWNlKG5ld1BvcywgbmV3UG9zICsgY29tcG9uZW50LmNvdW50KSk7XG4gICAgICB9XG4gICAgICBuZXdQb3MgKz0gY29tcG9uZW50LmNvdW50O1xuXG4gICAgICAvLyBDb21tb24gY2FzZVxuICAgICAgaWYgKCFjb21wb25lbnQuYWRkZWQpIHtcbiAgICAgICAgb2xkUG9zICs9IGNvbXBvbmVudC5jb3VudDtcbiAgICAgIH1cbiAgICB9IGVsc2Uge1xuICAgICAgY29tcG9uZW50LnZhbHVlID0gZGlmZi5qb2luKG9sZFN0cmluZy5zbGljZShvbGRQb3MsIG9sZFBvcyArIGNvbXBvbmVudC5jb3VudCkpO1xuICAgICAgb2xkUG9zICs9IGNvbXBvbmVudC5jb3VudDtcblxuICAgICAgLy8gUmV2ZXJzZSBhZGQgYW5kIHJlbW92ZSBzbyByZW1vdmVzIGFyZSBvdXRwdXQgZmlyc3QgdG8gbWF0Y2ggY29tbW9uIGNvbnZlbnRpb25cbiAgICAgIC8vIFRoZSBkaWZmaW5nIGFsZ29yaXRobSBpcyB0aWVkIHRvIGFkZCB0aGVuIHJlbW92ZSBvdXRwdXQgYW5kIHRoaXMgaXMgdGhlIHNpbXBsZXN0XG4gICAgICAvLyByb3V0ZSB0byBnZXQgdGhlIGRlc2lyZWQgb3V0cHV0IHdpdGggbWluaW1hbCBvdmVyaGVhZC5cbiAgICAgIGlmIChjb21wb25lbnRQb3MgJiYgY29tcG9uZW50c1tjb21wb25lbnRQb3MgLSAxXS5hZGRlZCkge1xuICAgICAgICBsZXQgdG1wID0gY29tcG9uZW50c1tjb21wb25lbnRQb3MgLSAxXTtcbiAgICAgICAgY29tcG9uZW50c1tjb21wb25lbnRQb3MgLSAxXSA9IGNvbXBvbmVudHNbY29tcG9uZW50UG9zXTtcbiAgICAgICAgY29tcG9uZW50c1tjb21wb25lbnRQb3NdID0gdG1wO1xuICAgICAgfVxuICAgIH1cbiAgfVxuXG4gIC8vIFNwZWNpYWwgY2FzZSBoYW5kbGUgZm9yIHdoZW4gb25lIHRlcm1pbmFsIGlzIGlnbm9yZWQgKGkuZS4gd2hpdGVzcGFjZSkuXG4gIC8vIEZvciB0aGlzIGNhc2Ugd2UgbWVyZ2UgdGhlIHRlcm1pbmFsIGludG8gdGhlIHByaW9yIHN0cmluZyBhbmQgZHJvcCB0aGUgY2hhbmdlLlxuICAvLyBUaGlzIGlzIG9ubHkgYXZhaWxhYmxlIGZvciBzdHJpbmcgbW9kZS5cbiAgbGV0IGxhc3RDb21wb25lbnQgPSBjb21wb25lbnRzW2NvbXBvbmVudExlbiAtIDFdO1xuICBpZiAoY29tcG9uZW50TGVuID4gMVxuICAgICAgJiYgdHlwZW9mIGxhc3RDb21wb25lbnQudmFsdWUgPT09ICdzdHJpbmcnXG4gICAgICAmJiAobGFzdENvbXBvbmVudC5hZGRlZCB8fCBsYXN0Q29tcG9uZW50LnJlbW92ZWQpXG4gICAgICAmJiBkaWZmLmVxdWFscygnJywgbGFzdENvbXBvbmVudC52YWx1ZSkpIHtcbiAgICBjb21wb25lbnRzW2NvbXBvbmVudExlbiAtIDJdLnZhbHVlICs9IGxhc3RDb21wb25lbnQudmFsdWU7XG4gICAgY29tcG9uZW50cy5wb3AoKTtcbiAgfVxuXG4gIHJldHVybiBjb21wb25lbnRzO1xufVxuXG5mdW5jdGlvbiBjbG9uZVBhdGgocGF0aCkge1xuICByZXR1cm4geyBuZXdQb3M6IHBhdGgubmV3UG9zLCBjb21wb25lbnRzOiBwYXRoLmNvbXBvbmVudHMuc2xpY2UoMCkgfTtcbn1cbiJdfQ==
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/character.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/character.js
          new file mode 100644
          index 00000000000000..7ddfa205e394a9
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/character.js
          @@ -0,0 +1,37 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.diffChars = diffChars;
          +exports.characterDiff = void 0;
          +
          +/*istanbul ignore end*/
          +var
          +/*istanbul ignore start*/
          +_base = _interopRequireDefault(require("./base"))
          +/*istanbul ignore end*/
          +;
          +
          +/*istanbul ignore start*/ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
          +
          +/*istanbul ignore end*/
          +var characterDiff = new
          +/*istanbul ignore start*/
          +_base
          +/*istanbul ignore end*/
          +[
          +/*istanbul ignore start*/
          +"default"
          +/*istanbul ignore end*/
          +]();
          +
          +/*istanbul ignore start*/
          +exports.characterDiff = characterDiff;
          +
          +/*istanbul ignore end*/
          +function diffChars(oldStr, newStr, options) {
          +  return characterDiff.diff(oldStr, newStr, options);
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL2NoYXJhY3Rlci5qcyJdLCJuYW1lcyI6WyJjaGFyYWN0ZXJEaWZmIiwiRGlmZiIsImRpZmZDaGFycyIsIm9sZFN0ciIsIm5ld1N0ciIsIm9wdGlvbnMiLCJkaWZmIl0sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTs7Ozs7QUFFTyxJQUFNQSxhQUFhLEdBQUc7QUFBSUM7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUEsQ0FBSixFQUF0Qjs7Ozs7O0FBQ0EsU0FBU0MsU0FBVCxDQUFtQkMsTUFBbkIsRUFBMkJDLE1BQTNCLEVBQW1DQyxPQUFuQyxFQUE0QztBQUFFLFNBQU9MLGFBQWEsQ0FBQ00sSUFBZCxDQUFtQkgsTUFBbkIsRUFBMkJDLE1BQTNCLEVBQW1DQyxPQUFuQyxDQUFQO0FBQXFEIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IERpZmYgZnJvbSAnLi9iYXNlJztcblxuZXhwb3J0IGNvbnN0IGNoYXJhY3RlckRpZmYgPSBuZXcgRGlmZigpO1xuZXhwb3J0IGZ1bmN0aW9uIGRpZmZDaGFycyhvbGRTdHIsIG5ld1N0ciwgb3B0aW9ucykgeyByZXR1cm4gY2hhcmFjdGVyRGlmZi5kaWZmKG9sZFN0ciwgbmV3U3RyLCBvcHRpb25zKTsgfVxuIl19
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/css.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/css.js
          new file mode 100644
          index 00000000000000..e3ad1fcba5f0eb
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/css.js
          @@ -0,0 +1,41 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.diffCss = diffCss;
          +exports.cssDiff = void 0;
          +
          +/*istanbul ignore end*/
          +var
          +/*istanbul ignore start*/
          +_base = _interopRequireDefault(require("./base"))
          +/*istanbul ignore end*/
          +;
          +
          +/*istanbul ignore start*/ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
          +
          +/*istanbul ignore end*/
          +var cssDiff = new
          +/*istanbul ignore start*/
          +_base
          +/*istanbul ignore end*/
          +[
          +/*istanbul ignore start*/
          +"default"
          +/*istanbul ignore end*/
          +]();
          +
          +/*istanbul ignore start*/
          +exports.cssDiff = cssDiff;
          +
          +/*istanbul ignore end*/
          +cssDiff.tokenize = function (value) {
          +  return value.split(/([{}:;,]|\s+)/);
          +};
          +
          +function diffCss(oldStr, newStr, callback) {
          +  return cssDiff.diff(oldStr, newStr, callback);
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL2Nzcy5qcyJdLCJuYW1lcyI6WyJjc3NEaWZmIiwiRGlmZiIsInRva2VuaXplIiwidmFsdWUiLCJzcGxpdCIsImRpZmZDc3MiLCJvbGRTdHIiLCJuZXdTdHIiLCJjYWxsYmFjayIsImRpZmYiXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBOzs7OztBQUVPLElBQU1BLE9BQU8sR0FBRztBQUFJQztBQUFBQTtBQUFBQTtBQUFBQTtBQUFBQTtBQUFBQTtBQUFBQTtBQUFBQSxDQUFKLEVBQWhCOzs7Ozs7QUFDUEQsT0FBTyxDQUFDRSxRQUFSLEdBQW1CLFVBQVNDLEtBQVQsRUFBZ0I7QUFDakMsU0FBT0EsS0FBSyxDQUFDQyxLQUFOLENBQVksZUFBWixDQUFQO0FBQ0QsQ0FGRDs7QUFJTyxTQUFTQyxPQUFULENBQWlCQyxNQUFqQixFQUF5QkMsTUFBekIsRUFBaUNDLFFBQWpDLEVBQTJDO0FBQUUsU0FBT1IsT0FBTyxDQUFDUyxJQUFSLENBQWFILE1BQWIsRUFBcUJDLE1BQXJCLEVBQTZCQyxRQUE3QixDQUFQO0FBQWdEIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IERpZmYgZnJvbSAnLi9iYXNlJztcblxuZXhwb3J0IGNvbnN0IGNzc0RpZmYgPSBuZXcgRGlmZigpO1xuY3NzRGlmZi50b2tlbml6ZSA9IGZ1bmN0aW9uKHZhbHVlKSB7XG4gIHJldHVybiB2YWx1ZS5zcGxpdCgvKFt7fTo7LF18XFxzKykvKTtcbn07XG5cbmV4cG9ydCBmdW5jdGlvbiBkaWZmQ3NzKG9sZFN0ciwgbmV3U3RyLCBjYWxsYmFjaykgeyByZXR1cm4gY3NzRGlmZi5kaWZmKG9sZFN0ciwgbmV3U3RyLCBjYWxsYmFjayk7IH1cbiJdfQ==
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/json.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/json.js
          new file mode 100644
          index 00000000000000..67c2f175f73b4f
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/json.js
          @@ -0,0 +1,163 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.diffJson = diffJson;
          +exports.canonicalize = canonicalize;
          +exports.jsonDiff = void 0;
          +
          +/*istanbul ignore end*/
          +var
          +/*istanbul ignore start*/
          +_base = _interopRequireDefault(require("./base"))
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_line = require("./line")
          +/*istanbul ignore end*/
          +;
          +
          +/*istanbul ignore start*/ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
          +
          +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
          +
          +/*istanbul ignore end*/
          +var objectPrototypeToString = Object.prototype.toString;
          +var jsonDiff = new
          +/*istanbul ignore start*/
          +_base
          +/*istanbul ignore end*/
          +[
          +/*istanbul ignore start*/
          +"default"
          +/*istanbul ignore end*/
          +](); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
          +// dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
          +
          +/*istanbul ignore start*/
          +exports.jsonDiff = jsonDiff;
          +
          +/*istanbul ignore end*/
          +jsonDiff.useLongestToken = true;
          +jsonDiff.tokenize =
          +/*istanbul ignore start*/
          +_line
          +/*istanbul ignore end*/
          +.
          +/*istanbul ignore start*/
          +lineDiff
          +/*istanbul ignore end*/
          +.tokenize;
          +
          +jsonDiff.castInput = function (value) {
          +  /*istanbul ignore start*/
          +  var _this$options =
          +  /*istanbul ignore end*/
          +  this.options,
          +      undefinedReplacement = _this$options.undefinedReplacement,
          +      _this$options$stringi = _this$options.stringifyReplacer,
          +      stringifyReplacer = _this$options$stringi === void 0 ? function (k, v)
          +  /*istanbul ignore start*/
          +  {
          +    return (
          +      /*istanbul ignore end*/
          +      typeof v === 'undefined' ? undefinedReplacement : v
          +    );
          +  } : _this$options$stringi;
          +  return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, '  ');
          +};
          +
          +jsonDiff.equals = function (left, right) {
          +  return (
          +    /*istanbul ignore start*/
          +    _base
          +    /*istanbul ignore end*/
          +    [
          +    /*istanbul ignore start*/
          +    "default"
          +    /*istanbul ignore end*/
          +    ].prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'))
          +  );
          +};
          +
          +function diffJson(oldObj, newObj, options) {
          +  return jsonDiff.diff(oldObj, newObj, options);
          +} // This function handles the presence of circular references by bailing out when encountering an
          +// object that is already on the "stack" of items being processed. Accepts an optional replacer
          +
          +
          +function canonicalize(obj, stack, replacementStack, replacer, key) {
          +  stack = stack || [];
          +  replacementStack = replacementStack || [];
          +
          +  if (replacer) {
          +    obj = replacer(key, obj);
          +  }
          +
          +  var i;
          +
          +  for (i = 0; i < stack.length; i += 1) {
          +    if (stack[i] === obj) {
          +      return replacementStack[i];
          +    }
          +  }
          +
          +  var canonicalizedObj;
          +
          +  if ('[object Array]' === objectPrototypeToString.call(obj)) {
          +    stack.push(obj);
          +    canonicalizedObj = new Array(obj.length);
          +    replacementStack.push(canonicalizedObj);
          +
          +    for (i = 0; i < obj.length; i += 1) {
          +      canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
          +    }
          +
          +    stack.pop();
          +    replacementStack.pop();
          +    return canonicalizedObj;
          +  }
          +
          +  if (obj && obj.toJSON) {
          +    obj = obj.toJSON();
          +  }
          +
          +  if (
          +  /*istanbul ignore start*/
          +  _typeof(
          +  /*istanbul ignore end*/
          +  obj) === 'object' && obj !== null) {
          +    stack.push(obj);
          +    canonicalizedObj = {};
          +    replacementStack.push(canonicalizedObj);
          +
          +    var sortedKeys = [],
          +        _key;
          +
          +    for (_key in obj) {
          +      /* istanbul ignore else */
          +      if (obj.hasOwnProperty(_key)) {
          +        sortedKeys.push(_key);
          +      }
          +    }
          +
          +    sortedKeys.sort();
          +
          +    for (i = 0; i < sortedKeys.length; i += 1) {
          +      _key = sortedKeys[i];
          +      canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
          +    }
          +
          +    stack.pop();
          +    replacementStack.pop();
          +  } else {
          +    canonicalizedObj = obj;
          +  }
          +
          +  return canonicalizedObj;
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL2pzb24uanMiXSwibmFtZXMiOlsib2JqZWN0UHJvdG90eXBlVG9TdHJpbmciLCJPYmplY3QiLCJwcm90b3R5cGUiLCJ0b1N0cmluZyIsImpzb25EaWZmIiwiRGlmZiIsInVzZUxvbmdlc3RUb2tlbiIsInRva2VuaXplIiwibGluZURpZmYiLCJjYXN0SW5wdXQiLCJ2YWx1ZSIsIm9wdGlvbnMiLCJ1bmRlZmluZWRSZXBsYWNlbWVudCIsInN0cmluZ2lmeVJlcGxhY2VyIiwiayIsInYiLCJKU09OIiwic3RyaW5naWZ5IiwiY2Fub25pY2FsaXplIiwiZXF1YWxzIiwibGVmdCIsInJpZ2h0IiwiY2FsbCIsInJlcGxhY2UiLCJkaWZmSnNvbiIsIm9sZE9iaiIsIm5ld09iaiIsImRpZmYiLCJvYmoiLCJzdGFjayIsInJlcGxhY2VtZW50U3RhY2siLCJyZXBsYWNlciIsImtleSIsImkiLCJsZW5ndGgiLCJjYW5vbmljYWxpemVkT2JqIiwicHVzaCIsIkFycmF5IiwicG9wIiwidG9KU09OIiwic29ydGVkS2V5cyIsImhhc093blByb3BlcnR5Iiwic29ydCJdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBOztBQUNBO0FBQUE7QUFBQTtBQUFBO0FBQUE7Ozs7Ozs7QUFFQSxJQUFNQSx1QkFBdUIsR0FBR0MsTUFBTSxDQUFDQyxTQUFQLENBQWlCQyxRQUFqRDtBQUdPLElBQU1DLFFBQVEsR0FBRztBQUFJQztBQUFBQTtBQUFBQTtBQUFBQTtBQUFBQTtBQUFBQTtBQUFBQTtBQUFBQSxDQUFKLEVBQWpCLEMsQ0FDUDtBQUNBOzs7Ozs7QUFDQUQsUUFBUSxDQUFDRSxlQUFULEdBQTJCLElBQTNCO0FBRUFGLFFBQVEsQ0FBQ0csUUFBVDtBQUFvQkM7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQTtBQUFBLENBQVNELFFBQTdCOztBQUNBSCxRQUFRLENBQUNLLFNBQVQsR0FBcUIsVUFBU0MsS0FBVCxFQUFnQjtBQUFBO0FBQUE7QUFBQTtBQUMrRSxPQUFLQyxPQURwRjtBQUFBLE1BQzVCQyxvQkFENEIsaUJBQzVCQSxvQkFENEI7QUFBQSw0Q0FDTkMsaUJBRE07QUFBQSxNQUNOQSxpQkFETSxzQ0FDYyxVQUFDQyxDQUFELEVBQUlDLENBQUo7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFVLGFBQU9BLENBQVAsS0FBYSxXQUFiLEdBQTJCSCxvQkFBM0IsR0FBa0RHO0FBQTVEO0FBQUEsR0FEZDtBQUduQyxTQUFPLE9BQU9MLEtBQVAsS0FBaUIsUUFBakIsR0FBNEJBLEtBQTVCLEdBQW9DTSxJQUFJLENBQUNDLFNBQUwsQ0FBZUMsWUFBWSxDQUFDUixLQUFELEVBQVEsSUFBUixFQUFjLElBQWQsRUFBb0JHLGlCQUFwQixDQUEzQixFQUFtRUEsaUJBQW5FLEVBQXNGLElBQXRGLENBQTNDO0FBQ0QsQ0FKRDs7QUFLQVQsUUFBUSxDQUFDZSxNQUFULEdBQWtCLFVBQVNDLElBQVQsRUFBZUMsS0FBZixFQUFzQjtBQUN0QyxTQUFPaEI7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUEsTUFBS0gsU0FBTCxDQUFlaUIsTUFBZixDQUFzQkcsSUFBdEIsQ0FBMkJsQixRQUEzQixFQUFxQ2dCLElBQUksQ0FBQ0csT0FBTCxDQUFhLFlBQWIsRUFBMkIsSUFBM0IsQ0FBckMsRUFBdUVGLEtBQUssQ0FBQ0UsT0FBTixDQUFjLFlBQWQsRUFBNEIsSUFBNUIsQ0FBdkU7QUFBUDtBQUNELENBRkQ7O0FBSU8sU0FBU0MsUUFBVCxDQUFrQkMsTUFBbEIsRUFBMEJDLE1BQTFCLEVBQWtDZixPQUFsQyxFQUEyQztBQUFFLFNBQU9QLFFBQVEsQ0FBQ3VCLElBQVQsQ0FBY0YsTUFBZCxFQUFzQkMsTUFBdEIsRUFBOEJmLE9BQTlCLENBQVA7QUFBZ0QsQyxDQUVwRztBQUNBOzs7QUFDTyxTQUFTTyxZQUFULENBQXNCVSxHQUF0QixFQUEyQkMsS0FBM0IsRUFBa0NDLGdCQUFsQyxFQUFvREMsUUFBcEQsRUFBOERDLEdBQTlELEVBQW1FO0FBQ3hFSCxFQUFBQSxLQUFLLEdBQUdBLEtBQUssSUFBSSxFQUFqQjtBQUNBQyxFQUFBQSxnQkFBZ0IsR0FBR0EsZ0JBQWdCLElBQUksRUFBdkM7O0FBRUEsTUFBSUMsUUFBSixFQUFjO0FBQ1pILElBQUFBLEdBQUcsR0FBR0csUUFBUSxDQUFDQyxHQUFELEVBQU1KLEdBQU4sQ0FBZDtBQUNEOztBQUVELE1BQUlLLENBQUo7O0FBRUEsT0FBS0EsQ0FBQyxHQUFHLENBQVQsRUFBWUEsQ0FBQyxHQUFHSixLQUFLLENBQUNLLE1BQXRCLEVBQThCRCxDQUFDLElBQUksQ0FBbkMsRUFBc0M7QUFDcEMsUUFBSUosS0FBSyxDQUFDSSxDQUFELENBQUwsS0FBYUwsR0FBakIsRUFBc0I7QUFDcEIsYUFBT0UsZ0JBQWdCLENBQUNHLENBQUQsQ0FBdkI7QUFDRDtBQUNGOztBQUVELE1BQUlFLGdCQUFKOztBQUVBLE1BQUkscUJBQXFCbkMsdUJBQXVCLENBQUNzQixJQUF4QixDQUE2Qk0sR0FBN0IsQ0FBekIsRUFBNEQ7QUFDMURDLElBQUFBLEtBQUssQ0FBQ08sSUFBTixDQUFXUixHQUFYO0FBQ0FPLElBQUFBLGdCQUFnQixHQUFHLElBQUlFLEtBQUosQ0FBVVQsR0FBRyxDQUFDTSxNQUFkLENBQW5CO0FBQ0FKLElBQUFBLGdCQUFnQixDQUFDTSxJQUFqQixDQUFzQkQsZ0JBQXRCOztBQUNBLFNBQUtGLENBQUMsR0FBRyxDQUFULEVBQVlBLENBQUMsR0FBR0wsR0FBRyxDQUFDTSxNQUFwQixFQUE0QkQsQ0FBQyxJQUFJLENBQWpDLEVBQW9DO0FBQ2xDRSxNQUFBQSxnQkFBZ0IsQ0FBQ0YsQ0FBRCxDQUFoQixHQUFzQmYsWUFBWSxDQUFDVSxHQUFHLENBQUNLLENBQUQsQ0FBSixFQUFTSixLQUFULEVBQWdCQyxnQkFBaEIsRUFBa0NDLFFBQWxDLEVBQTRDQyxHQUE1QyxDQUFsQztBQUNEOztBQUNESCxJQUFBQSxLQUFLLENBQUNTLEdBQU47QUFDQVIsSUFBQUEsZ0JBQWdCLENBQUNRLEdBQWpCO0FBQ0EsV0FBT0gsZ0JBQVA7QUFDRDs7QUFFRCxNQUFJUCxHQUFHLElBQUlBLEdBQUcsQ0FBQ1csTUFBZixFQUF1QjtBQUNyQlgsSUFBQUEsR0FBRyxHQUFHQSxHQUFHLENBQUNXLE1BQUosRUFBTjtBQUNEOztBQUVEO0FBQUk7QUFBQTtBQUFBO0FBQU9YLEVBQUFBLEdBQVAsTUFBZSxRQUFmLElBQTJCQSxHQUFHLEtBQUssSUFBdkMsRUFBNkM7QUFDM0NDLElBQUFBLEtBQUssQ0FBQ08sSUFBTixDQUFXUixHQUFYO0FBQ0FPLElBQUFBLGdCQUFnQixHQUFHLEVBQW5CO0FBQ0FMLElBQUFBLGdCQUFnQixDQUFDTSxJQUFqQixDQUFzQkQsZ0JBQXRCOztBQUNBLFFBQUlLLFVBQVUsR0FBRyxFQUFqQjtBQUFBLFFBQ0lSLElBREo7O0FBRUEsU0FBS0EsSUFBTCxJQUFZSixHQUFaLEVBQWlCO0FBQ2Y7QUFDQSxVQUFJQSxHQUFHLENBQUNhLGNBQUosQ0FBbUJULElBQW5CLENBQUosRUFBNkI7QUFDM0JRLFFBQUFBLFVBQVUsQ0FBQ0osSUFBWCxDQUFnQkosSUFBaEI7QUFDRDtBQUNGOztBQUNEUSxJQUFBQSxVQUFVLENBQUNFLElBQVg7O0FBQ0EsU0FBS1QsQ0FBQyxHQUFHLENBQVQsRUFBWUEsQ0FBQyxHQUFHTyxVQUFVLENBQUNOLE1BQTNCLEVBQW1DRCxDQUFDLElBQUksQ0FBeEMsRUFBMkM7QUFDekNELE1BQUFBLElBQUcsR0FBR1EsVUFBVSxDQUFDUCxDQUFELENBQWhCO0FBQ0FFLE1BQUFBLGdCQUFnQixDQUFDSCxJQUFELENBQWhCLEdBQXdCZCxZQUFZLENBQUNVLEdBQUcsQ0FBQ0ksSUFBRCxDQUFKLEVBQVdILEtBQVgsRUFBa0JDLGdCQUFsQixFQUFvQ0MsUUFBcEMsRUFBOENDLElBQTlDLENBQXBDO0FBQ0Q7O0FBQ0RILElBQUFBLEtBQUssQ0FBQ1MsR0FBTjtBQUNBUixJQUFBQSxnQkFBZ0IsQ0FBQ1EsR0FBakI7QUFDRCxHQW5CRCxNQW1CTztBQUNMSCxJQUFBQSxnQkFBZ0IsR0FBR1AsR0FBbkI7QUFDRDs7QUFDRCxTQUFPTyxnQkFBUDtBQUNEIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IERpZmYgZnJvbSAnLi9iYXNlJztcbmltcG9ydCB7bGluZURpZmZ9IGZyb20gJy4vbGluZSc7XG5cbmNvbnN0IG9iamVjdFByb3RvdHlwZVRvU3RyaW5nID0gT2JqZWN0LnByb3RvdHlwZS50b1N0cmluZztcblxuXG5leHBvcnQgY29uc3QganNvbkRpZmYgPSBuZXcgRGlmZigpO1xuLy8gRGlzY3JpbWluYXRlIGJldHdlZW4gdHdvIGxpbmVzIG9mIHByZXR0eS1wcmludGVkLCBzZXJpYWxpemVkIEpTT04gd2hlcmUgb25lIG9mIHRoZW0gaGFzIGFcbi8vIGRhbmdsaW5nIGNvbW1hIGFuZCB0aGUgb3RoZXIgZG9lc24ndC4gVHVybnMgb3V0IGluY2x1ZGluZyB0aGUgZGFuZ2xpbmcgY29tbWEgeWllbGRzIHRoZSBuaWNlc3Qgb3V0cHV0OlxuanNvbkRpZmYudXNlTG9uZ2VzdFRva2VuID0gdHJ1ZTtcblxuanNvbkRpZmYudG9rZW5pemUgPSBsaW5lRGlmZi50b2tlbml6ZTtcbmpzb25EaWZmLmNhc3RJbnB1dCA9IGZ1bmN0aW9uKHZhbHVlKSB7XG4gIGNvbnN0IHt1bmRlZmluZWRSZXBsYWNlbWVudCwgc3RyaW5naWZ5UmVwbGFjZXIgPSAoaywgdikgPT4gdHlwZW9mIHYgPT09ICd1bmRlZmluZWQnID8gdW5kZWZpbmVkUmVwbGFjZW1lbnQgOiB2fSA9IHRoaXMub3B0aW9ucztcblxuICByZXR1cm4gdHlwZW9mIHZhbHVlID09PSAnc3RyaW5nJyA/IHZhbHVlIDogSlNPTi5zdHJpbmdpZnkoY2Fub25pY2FsaXplKHZhbHVlLCBudWxsLCBudWxsLCBzdHJpbmdpZnlSZXBsYWNlciksIHN0cmluZ2lmeVJlcGxhY2VyLCAnICAnKTtcbn07XG5qc29uRGlmZi5lcXVhbHMgPSBmdW5jdGlvbihsZWZ0LCByaWdodCkge1xuICByZXR1cm4gRGlmZi5wcm90b3R5cGUuZXF1YWxzLmNhbGwoanNvbkRpZmYsIGxlZnQucmVwbGFjZSgvLChbXFxyXFxuXSkvZywgJyQxJyksIHJpZ2h0LnJlcGxhY2UoLywoW1xcclxcbl0pL2csICckMScpKTtcbn07XG5cbmV4cG9ydCBmdW5jdGlvbiBkaWZmSnNvbihvbGRPYmosIG5ld09iaiwgb3B0aW9ucykgeyByZXR1cm4ganNvbkRpZmYuZGlmZihvbGRPYmosIG5ld09iaiwgb3B0aW9ucyk7IH1cblxuLy8gVGhpcyBmdW5jdGlvbiBoYW5kbGVzIHRoZSBwcmVzZW5jZSBvZiBjaXJjdWxhciByZWZlcmVuY2VzIGJ5IGJhaWxpbmcgb3V0IHdoZW4gZW5jb3VudGVyaW5nIGFuXG4vLyBvYmplY3QgdGhhdCBpcyBhbHJlYWR5IG9uIHRoZSBcInN0YWNrXCIgb2YgaXRlbXMgYmVpbmcgcHJvY2Vzc2VkLiBBY2NlcHRzIGFuIG9wdGlvbmFsIHJlcGxhY2VyXG5leHBvcnQgZnVuY3Rpb24gY2Fub25pY2FsaXplKG9iaiwgc3RhY2ssIHJlcGxhY2VtZW50U3RhY2ssIHJlcGxhY2VyLCBrZXkpIHtcbiAgc3RhY2sgPSBzdGFjayB8fCBbXTtcbiAgcmVwbGFjZW1lbnRTdGFjayA9IHJlcGxhY2VtZW50U3RhY2sgfHwgW107XG5cbiAgaWYgKHJlcGxhY2VyKSB7XG4gICAgb2JqID0gcmVwbGFjZXIoa2V5LCBvYmopO1xuICB9XG5cbiAgbGV0IGk7XG5cbiAgZm9yIChpID0gMDsgaSA8IHN0YWNrLmxlbmd0aDsgaSArPSAxKSB7XG4gICAgaWYgKHN0YWNrW2ldID09PSBvYmopIHtcbiAgICAgIHJldHVybiByZXBsYWNlbWVudFN0YWNrW2ldO1xuICAgIH1cbiAgfVxuXG4gIGxldCBjYW5vbmljYWxpemVkT2JqO1xuXG4gIGlmICgnW29iamVjdCBBcnJheV0nID09PSBvYmplY3RQcm90b3R5cGVUb1N0cmluZy5jYWxsKG9iaikpIHtcbiAgICBzdGFjay5wdXNoKG9iaik7XG4gICAgY2Fub25pY2FsaXplZE9iaiA9IG5ldyBBcnJheShvYmoubGVuZ3RoKTtcbiAgICByZXBsYWNlbWVudFN0YWNrLnB1c2goY2Fub25pY2FsaXplZE9iaik7XG4gICAgZm9yIChpID0gMDsgaSA8IG9iai5sZW5ndGg7IGkgKz0gMSkge1xuICAgICAgY2Fub25pY2FsaXplZE9ialtpXSA9IGNhbm9uaWNhbGl6ZShvYmpbaV0sIHN0YWNrLCByZXBsYWNlbWVudFN0YWNrLCByZXBsYWNlciwga2V5KTtcbiAgICB9XG4gICAgc3RhY2sucG9wKCk7XG4gICAgcmVwbGFjZW1lbnRTdGFjay5wb3AoKTtcbiAgICByZXR1cm4gY2Fub25pY2FsaXplZE9iajtcbiAgfVxuXG4gIGlmIChvYmogJiYgb2JqLnRvSlNPTikge1xuICAgIG9iaiA9IG9iai50b0pTT04oKTtcbiAgfVxuXG4gIGlmICh0eXBlb2Ygb2JqID09PSAnb2JqZWN0JyAmJiBvYmogIT09IG51bGwpIHtcbiAgICBzdGFjay5wdXNoKG9iaik7XG4gICAgY2Fub25pY2FsaXplZE9iaiA9IHt9O1xuICAgIHJlcGxhY2VtZW50U3RhY2sucHVzaChjYW5vbmljYWxpemVkT2JqKTtcbiAgICBsZXQgc29ydGVkS2V5cyA9IFtdLFxuICAgICAgICBrZXk7XG4gICAgZm9yIChrZXkgaW4gb2JqKSB7XG4gICAgICAvKiBpc3RhbmJ1bCBpZ25vcmUgZWxzZSAqL1xuICAgICAgaWYgKG9iai5oYXNPd25Qcm9wZXJ0eShrZXkpKSB7XG4gICAgICAgIHNvcnRlZEtleXMucHVzaChrZXkpO1xuICAgICAgfVxuICAgIH1cbiAgICBzb3J0ZWRLZXlzLnNvcnQoKTtcbiAgICBmb3IgKGkgPSAwOyBpIDwgc29ydGVkS2V5cy5sZW5ndGg7IGkgKz0gMSkge1xuICAgICAga2V5ID0gc29ydGVkS2V5c1tpXTtcbiAgICAgIGNhbm9uaWNhbGl6ZWRPYmpba2V5XSA9IGNhbm9uaWNhbGl6ZShvYmpba2V5XSwgc3RhY2ssIHJlcGxhY2VtZW50U3RhY2ssIHJlcGxhY2VyLCBrZXkpO1xuICAgIH1cbiAgICBzdGFjay5wb3AoKTtcbiAgICByZXBsYWNlbWVudFN0YWNrLnBvcCgpO1xuICB9IGVsc2Uge1xuICAgIGNhbm9uaWNhbGl6ZWRPYmogPSBvYmo7XG4gIH1cbiAgcmV0dXJuIGNhbm9uaWNhbGl6ZWRPYmo7XG59XG4iXX0=
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/line.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/line.js
          new file mode 100644
          index 00000000000000..855fe30b9cc2c8
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/line.js
          @@ -0,0 +1,89 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.diffLines = diffLines;
          +exports.diffTrimmedLines = diffTrimmedLines;
          +exports.lineDiff = void 0;
          +
          +/*istanbul ignore end*/
          +var
          +/*istanbul ignore start*/
          +_base = _interopRequireDefault(require("./base"))
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_params = require("../util/params")
          +/*istanbul ignore end*/
          +;
          +
          +/*istanbul ignore start*/ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
          +
          +/*istanbul ignore end*/
          +var lineDiff = new
          +/*istanbul ignore start*/
          +_base
          +/*istanbul ignore end*/
          +[
          +/*istanbul ignore start*/
          +"default"
          +/*istanbul ignore end*/
          +]();
          +
          +/*istanbul ignore start*/
          +exports.lineDiff = lineDiff;
          +
          +/*istanbul ignore end*/
          +lineDiff.tokenize = function (value) {
          +  var retLines = [],
          +      linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
          +
          +  if (!linesAndNewlines[linesAndNewlines.length - 1]) {
          +    linesAndNewlines.pop();
          +  } // Merge the content and line separators into single tokens
          +
          +
          +  for (var i = 0; i < linesAndNewlines.length; i++) {
          +    var line = linesAndNewlines[i];
          +
          +    if (i % 2 && !this.options.newlineIsToken) {
          +      retLines[retLines.length - 1] += line;
          +    } else {
          +      if (this.options.ignoreWhitespace) {
          +        line = line.trim();
          +      }
          +
          +      retLines.push(line);
          +    }
          +  }
          +
          +  return retLines;
          +};
          +
          +function diffLines(oldStr, newStr, callback) {
          +  return lineDiff.diff(oldStr, newStr, callback);
          +}
          +
          +function diffTrimmedLines(oldStr, newStr, callback) {
          +  var options =
          +  /*istanbul ignore start*/
          +  (0,
          +  /*istanbul ignore end*/
          +
          +  /*istanbul ignore start*/
          +  _params
          +  /*istanbul ignore end*/
          +  .
          +  /*istanbul ignore start*/
          +  generateOptions)
          +  /*istanbul ignore end*/
          +  (callback, {
          +    ignoreWhitespace: true
          +  });
          +  return lineDiff.diff(oldStr, newStr, options);
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL2xpbmUuanMiXSwibmFtZXMiOlsibGluZURpZmYiLCJEaWZmIiwidG9rZW5pemUiLCJ2YWx1ZSIsInJldExpbmVzIiwibGluZXNBbmROZXdsaW5lcyIsInNwbGl0IiwibGVuZ3RoIiwicG9wIiwiaSIsImxpbmUiLCJvcHRpb25zIiwibmV3bGluZUlzVG9rZW4iLCJpZ25vcmVXaGl0ZXNwYWNlIiwidHJpbSIsInB1c2giLCJkaWZmTGluZXMiLCJvbGRTdHIiLCJuZXdTdHIiLCJjYWxsYmFjayIsImRpZmYiLCJkaWZmVHJpbW1lZExpbmVzIiwiZ2VuZXJhdGVPcHRpb25zIl0sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7OztBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7O0FBQ0E7QUFBQTtBQUFBO0FBQUE7QUFBQTs7Ozs7QUFFTyxJQUFNQSxRQUFRLEdBQUc7QUFBSUM7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUEsQ0FBSixFQUFqQjs7Ozs7O0FBQ1BELFFBQVEsQ0FBQ0UsUUFBVCxHQUFvQixVQUFTQyxLQUFULEVBQWdCO0FBQ2xDLE1BQUlDLFFBQVEsR0FBRyxFQUFmO0FBQUEsTUFDSUMsZ0JBQWdCLEdBQUdGLEtBQUssQ0FBQ0csS0FBTixDQUFZLFdBQVosQ0FEdkIsQ0FEa0MsQ0FJbEM7O0FBQ0EsTUFBSSxDQUFDRCxnQkFBZ0IsQ0FBQ0EsZ0JBQWdCLENBQUNFLE1BQWpCLEdBQTBCLENBQTNCLENBQXJCLEVBQW9EO0FBQ2xERixJQUFBQSxnQkFBZ0IsQ0FBQ0csR0FBakI7QUFDRCxHQVBpQyxDQVNsQzs7O0FBQ0EsT0FBSyxJQUFJQyxDQUFDLEdBQUcsQ0FBYixFQUFnQkEsQ0FBQyxHQUFHSixnQkFBZ0IsQ0FBQ0UsTUFBckMsRUFBNkNFLENBQUMsRUFBOUMsRUFBa0Q7QUFDaEQsUUFBSUMsSUFBSSxHQUFHTCxnQkFBZ0IsQ0FBQ0ksQ0FBRCxDQUEzQjs7QUFFQSxRQUFJQSxDQUFDLEdBQUcsQ0FBSixJQUFTLENBQUMsS0FBS0UsT0FBTCxDQUFhQyxjQUEzQixFQUEyQztBQUN6Q1IsTUFBQUEsUUFBUSxDQUFDQSxRQUFRLENBQUNHLE1BQVQsR0FBa0IsQ0FBbkIsQ0FBUixJQUFpQ0csSUFBakM7QUFDRCxLQUZELE1BRU87QUFDTCxVQUFJLEtBQUtDLE9BQUwsQ0FBYUUsZ0JBQWpCLEVBQW1DO0FBQ2pDSCxRQUFBQSxJQUFJLEdBQUdBLElBQUksQ0FBQ0ksSUFBTCxFQUFQO0FBQ0Q7O0FBQ0RWLE1BQUFBLFFBQVEsQ0FBQ1csSUFBVCxDQUFjTCxJQUFkO0FBQ0Q7QUFDRjs7QUFFRCxTQUFPTixRQUFQO0FBQ0QsQ0F4QkQ7O0FBMEJPLFNBQVNZLFNBQVQsQ0FBbUJDLE1BQW5CLEVBQTJCQyxNQUEzQixFQUFtQ0MsUUFBbkMsRUFBNkM7QUFBRSxTQUFPbkIsUUFBUSxDQUFDb0IsSUFBVCxDQUFjSCxNQUFkLEVBQXNCQyxNQUF0QixFQUE4QkMsUUFBOUIsQ0FBUDtBQUFpRDs7QUFDaEcsU0FBU0UsZ0JBQVQsQ0FBMEJKLE1BQTFCLEVBQWtDQyxNQUFsQyxFQUEwQ0MsUUFBMUMsRUFBb0Q7QUFDekQsTUFBSVIsT0FBTztBQUFHO0FBQUE7QUFBQTs7QUFBQVc7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQTtBQUFBLEdBQWdCSCxRQUFoQixFQUEwQjtBQUFDTixJQUFBQSxnQkFBZ0IsRUFBRTtBQUFuQixHQUExQixDQUFkO0FBQ0EsU0FBT2IsUUFBUSxDQUFDb0IsSUFBVCxDQUFjSCxNQUFkLEVBQXNCQyxNQUF0QixFQUE4QlAsT0FBOUIsQ0FBUDtBQUNEIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IERpZmYgZnJvbSAnLi9iYXNlJztcbmltcG9ydCB7Z2VuZXJhdGVPcHRpb25zfSBmcm9tICcuLi91dGlsL3BhcmFtcyc7XG5cbmV4cG9ydCBjb25zdCBsaW5lRGlmZiA9IG5ldyBEaWZmKCk7XG5saW5lRGlmZi50b2tlbml6ZSA9IGZ1bmN0aW9uKHZhbHVlKSB7XG4gIGxldCByZXRMaW5lcyA9IFtdLFxuICAgICAgbGluZXNBbmROZXdsaW5lcyA9IHZhbHVlLnNwbGl0KC8oXFxufFxcclxcbikvKTtcblxuICAvLyBJZ25vcmUgdGhlIGZpbmFsIGVtcHR5IHRva2VuIHRoYXQgb2NjdXJzIGlmIHRoZSBzdHJpbmcgZW5kcyB3aXRoIGEgbmV3IGxpbmVcbiAgaWYgKCFsaW5lc0FuZE5ld2xpbmVzW2xpbmVzQW5kTmV3bGluZXMubGVuZ3RoIC0gMV0pIHtcbiAgICBsaW5lc0FuZE5ld2xpbmVzLnBvcCgpO1xuICB9XG5cbiAgLy8gTWVyZ2UgdGhlIGNvbnRlbnQgYW5kIGxpbmUgc2VwYXJhdG9ycyBpbnRvIHNpbmdsZSB0b2tlbnNcbiAgZm9yIChsZXQgaSA9IDA7IGkgPCBsaW5lc0FuZE5ld2xpbmVzLmxlbmd0aDsgaSsrKSB7XG4gICAgbGV0IGxpbmUgPSBsaW5lc0FuZE5ld2xpbmVzW2ldO1xuXG4gICAgaWYgKGkgJSAyICYmICF0aGlzLm9wdGlvbnMubmV3bGluZUlzVG9rZW4pIHtcbiAgICAgIHJldExpbmVzW3JldExpbmVzLmxlbmd0aCAtIDFdICs9IGxpbmU7XG4gICAgfSBlbHNlIHtcbiAgICAgIGlmICh0aGlzLm9wdGlvbnMuaWdub3JlV2hpdGVzcGFjZSkge1xuICAgICAgICBsaW5lID0gbGluZS50cmltKCk7XG4gICAgICB9XG4gICAgICByZXRMaW5lcy5wdXNoKGxpbmUpO1xuICAgIH1cbiAgfVxuXG4gIHJldHVybiByZXRMaW5lcztcbn07XG5cbmV4cG9ydCBmdW5jdGlvbiBkaWZmTGluZXMob2xkU3RyLCBuZXdTdHIsIGNhbGxiYWNrKSB7IHJldHVybiBsaW5lRGlmZi5kaWZmKG9sZFN0ciwgbmV3U3RyLCBjYWxsYmFjayk7IH1cbmV4cG9ydCBmdW5jdGlvbiBkaWZmVHJpbW1lZExpbmVzKG9sZFN0ciwgbmV3U3RyLCBjYWxsYmFjaykge1xuICBsZXQgb3B0aW9ucyA9IGdlbmVyYXRlT3B0aW9ucyhjYWxsYmFjaywge2lnbm9yZVdoaXRlc3BhY2U6IHRydWV9KTtcbiAgcmV0dXJuIGxpbmVEaWZmLmRpZmYob2xkU3RyLCBuZXdTdHIsIG9wdGlvbnMpO1xufVxuIl19
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/sentence.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/sentence.js
          new file mode 100644
          index 00000000000000..95158d6f58f9f9
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/sentence.js
          @@ -0,0 +1,41 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.diffSentences = diffSentences;
          +exports.sentenceDiff = void 0;
          +
          +/*istanbul ignore end*/
          +var
          +/*istanbul ignore start*/
          +_base = _interopRequireDefault(require("./base"))
          +/*istanbul ignore end*/
          +;
          +
          +/*istanbul ignore start*/ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
          +
          +/*istanbul ignore end*/
          +var sentenceDiff = new
          +/*istanbul ignore start*/
          +_base
          +/*istanbul ignore end*/
          +[
          +/*istanbul ignore start*/
          +"default"
          +/*istanbul ignore end*/
          +]();
          +
          +/*istanbul ignore start*/
          +exports.sentenceDiff = sentenceDiff;
          +
          +/*istanbul ignore end*/
          +sentenceDiff.tokenize = function (value) {
          +  return value.split(/(\S.+?[.!?])(?=\s+|$)/);
          +};
          +
          +function diffSentences(oldStr, newStr, callback) {
          +  return sentenceDiff.diff(oldStr, newStr, callback);
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL3NlbnRlbmNlLmpzIl0sIm5hbWVzIjpbInNlbnRlbmNlRGlmZiIsIkRpZmYiLCJ0b2tlbml6ZSIsInZhbHVlIiwic3BsaXQiLCJkaWZmU2VudGVuY2VzIiwib2xkU3RyIiwibmV3U3RyIiwiY2FsbGJhY2siLCJkaWZmIl0sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTs7Ozs7QUFHTyxJQUFNQSxZQUFZLEdBQUc7QUFBSUM7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUEsQ0FBSixFQUFyQjs7Ozs7O0FBQ1BELFlBQVksQ0FBQ0UsUUFBYixHQUF3QixVQUFTQyxLQUFULEVBQWdCO0FBQ3RDLFNBQU9BLEtBQUssQ0FBQ0MsS0FBTixDQUFZLHVCQUFaLENBQVA7QUFDRCxDQUZEOztBQUlPLFNBQVNDLGFBQVQsQ0FBdUJDLE1BQXZCLEVBQStCQyxNQUEvQixFQUF1Q0MsUUFBdkMsRUFBaUQ7QUFBRSxTQUFPUixZQUFZLENBQUNTLElBQWIsQ0FBa0JILE1BQWxCLEVBQTBCQyxNQUExQixFQUFrQ0MsUUFBbEMsQ0FBUDtBQUFxRCIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBEaWZmIGZyb20gJy4vYmFzZSc7XG5cblxuZXhwb3J0IGNvbnN0IHNlbnRlbmNlRGlmZiA9IG5ldyBEaWZmKCk7XG5zZW50ZW5jZURpZmYudG9rZW5pemUgPSBmdW5jdGlvbih2YWx1ZSkge1xuICByZXR1cm4gdmFsdWUuc3BsaXQoLyhcXFMuKz9bLiE/XSkoPz1cXHMrfCQpLyk7XG59O1xuXG5leHBvcnQgZnVuY3Rpb24gZGlmZlNlbnRlbmNlcyhvbGRTdHIsIG5ld1N0ciwgY2FsbGJhY2spIHsgcmV0dXJuIHNlbnRlbmNlRGlmZi5kaWZmKG9sZFN0ciwgbmV3U3RyLCBjYWxsYmFjayk7IH1cbiJdfQ==
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/word.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/word.js
          new file mode 100644
          index 00000000000000..cef7fe17befe60
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/diff/word.js
          @@ -0,0 +1,108 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.diffWords = diffWords;
          +exports.diffWordsWithSpace = diffWordsWithSpace;
          +exports.wordDiff = void 0;
          +
          +/*istanbul ignore end*/
          +var
          +/*istanbul ignore start*/
          +_base = _interopRequireDefault(require("./base"))
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_params = require("../util/params")
          +/*istanbul ignore end*/
          +;
          +
          +/*istanbul ignore start*/ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
          +
          +/*istanbul ignore end*/
          +// Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
          +//
          +// Ranges and exceptions:
          +// Latin-1 Supplement, 0080–00FF
          +//  - U+00D7  × Multiplication sign
          +//  - U+00F7  ÷ Division sign
          +// Latin Extended-A, 0100–017F
          +// Latin Extended-B, 0180–024F
          +// IPA Extensions, 0250–02AF
          +// Spacing Modifier Letters, 02B0–02FF
          +//  - U+02C7  ˇ ˇ  Caron
          +//  - U+02D8  ˘ ˘  Breve
          +//  - U+02D9  ˙ ˙  Dot Above
          +//  - U+02DA  ˚ ˚  Ring Above
          +//  - U+02DB  ˛ ˛  Ogonek
          +//  - U+02DC  ˜ ˜  Small Tilde
          +//  - U+02DD  ˝ ˝  Double Acute Accent
          +// Latin Extended Additional, 1E00–1EFF
          +var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
          +var reWhitespace = /\S/;
          +var wordDiff = new
          +/*istanbul ignore start*/
          +_base
          +/*istanbul ignore end*/
          +[
          +/*istanbul ignore start*/
          +"default"
          +/*istanbul ignore end*/
          +]();
          +
          +/*istanbul ignore start*/
          +exports.wordDiff = wordDiff;
          +
          +/*istanbul ignore end*/
          +wordDiff.equals = function (left, right) {
          +  if (this.options.ignoreCase) {
          +    left = left.toLowerCase();
          +    right = right.toLowerCase();
          +  }
          +
          +  return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
          +};
          +
          +wordDiff.tokenize = function (value) {
          +  // All whitespace symbols except newline group into one token, each newline - in separate token
          +  var tokens = value.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/); // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
          +
          +  for (var i = 0; i < tokens.length - 1; i++) {
          +    // If we have an empty string in the next field and we have only word chars before and after, merge
          +    if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
          +      tokens[i] += tokens[i + 2];
          +      tokens.splice(i + 1, 2);
          +      i--;
          +    }
          +  }
          +
          +  return tokens;
          +};
          +
          +function diffWords(oldStr, newStr, options) {
          +  options =
          +  /*istanbul ignore start*/
          +  (0,
          +  /*istanbul ignore end*/
          +
          +  /*istanbul ignore start*/
          +  _params
          +  /*istanbul ignore end*/
          +  .
          +  /*istanbul ignore start*/
          +  generateOptions)
          +  /*istanbul ignore end*/
          +  (options, {
          +    ignoreWhitespace: true
          +  });
          +  return wordDiff.diff(oldStr, newStr, options);
          +}
          +
          +function diffWordsWithSpace(oldStr, newStr, options) {
          +  return wordDiff.diff(oldStr, newStr, options);
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL3dvcmQuanMiXSwibmFtZXMiOlsiZXh0ZW5kZWRXb3JkQ2hhcnMiLCJyZVdoaXRlc3BhY2UiLCJ3b3JkRGlmZiIsIkRpZmYiLCJlcXVhbHMiLCJsZWZ0IiwicmlnaHQiLCJvcHRpb25zIiwiaWdub3JlQ2FzZSIsInRvTG93ZXJDYXNlIiwiaWdub3JlV2hpdGVzcGFjZSIsInRlc3QiLCJ0b2tlbml6ZSIsInZhbHVlIiwidG9rZW5zIiwic3BsaXQiLCJpIiwibGVuZ3RoIiwic3BsaWNlIiwiZGlmZldvcmRzIiwib2xkU3RyIiwibmV3U3RyIiwiZ2VuZXJhdGVPcHRpb25zIiwiZGlmZiIsImRpZmZXb3Jkc1dpdGhTcGFjZSJdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBOztBQUNBO0FBQUE7QUFBQTtBQUFBO0FBQUE7Ozs7O0FBRUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0EsSUFBTUEsaUJBQWlCLEdBQUcsK0RBQTFCO0FBRUEsSUFBTUMsWUFBWSxHQUFHLElBQXJCO0FBRU8sSUFBTUMsUUFBUSxHQUFHO0FBQUlDO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBLENBQUosRUFBakI7Ozs7OztBQUNQRCxRQUFRLENBQUNFLE1BQVQsR0FBa0IsVUFBU0MsSUFBVCxFQUFlQyxLQUFmLEVBQXNCO0FBQ3RDLE1BQUksS0FBS0MsT0FBTCxDQUFhQyxVQUFqQixFQUE2QjtBQUMzQkgsSUFBQUEsSUFBSSxHQUFHQSxJQUFJLENBQUNJLFdBQUwsRUFBUDtBQUNBSCxJQUFBQSxLQUFLLEdBQUdBLEtBQUssQ0FBQ0csV0FBTixFQUFSO0FBQ0Q7O0FBQ0QsU0FBT0osSUFBSSxLQUFLQyxLQUFULElBQW1CLEtBQUtDLE9BQUwsQ0FBYUcsZ0JBQWIsSUFBaUMsQ0FBQ1QsWUFBWSxDQUFDVSxJQUFiLENBQWtCTixJQUFsQixDQUFsQyxJQUE2RCxDQUFDSixZQUFZLENBQUNVLElBQWIsQ0FBa0JMLEtBQWxCLENBQXhGO0FBQ0QsQ0FORDs7QUFPQUosUUFBUSxDQUFDVSxRQUFULEdBQW9CLFVBQVNDLEtBQVQsRUFBZ0I7QUFDbEM7QUFDQSxNQUFJQyxNQUFNLEdBQUdELEtBQUssQ0FBQ0UsS0FBTixDQUFZLGlDQUFaLENBQWIsQ0FGa0MsQ0FJbEM7O0FBQ0EsT0FBSyxJQUFJQyxDQUFDLEdBQUcsQ0FBYixFQUFnQkEsQ0FBQyxHQUFHRixNQUFNLENBQUNHLE1BQVAsR0FBZ0IsQ0FBcEMsRUFBdUNELENBQUMsRUFBeEMsRUFBNEM7QUFDMUM7QUFDQSxRQUFJLENBQUNGLE1BQU0sQ0FBQ0UsQ0FBQyxHQUFHLENBQUwsQ0FBUCxJQUFrQkYsTUFBTSxDQUFDRSxDQUFDLEdBQUcsQ0FBTCxDQUF4QixJQUNLaEIsaUJBQWlCLENBQUNXLElBQWxCLENBQXVCRyxNQUFNLENBQUNFLENBQUQsQ0FBN0IsQ0FETCxJQUVLaEIsaUJBQWlCLENBQUNXLElBQWxCLENBQXVCRyxNQUFNLENBQUNFLENBQUMsR0FBRyxDQUFMLENBQTdCLENBRlQsRUFFZ0Q7QUFDOUNGLE1BQUFBLE1BQU0sQ0FBQ0UsQ0FBRCxDQUFOLElBQWFGLE1BQU0sQ0FBQ0UsQ0FBQyxHQUFHLENBQUwsQ0FBbkI7QUFDQUYsTUFBQUEsTUFBTSxDQUFDSSxNQUFQLENBQWNGLENBQUMsR0FBRyxDQUFsQixFQUFxQixDQUFyQjtBQUNBQSxNQUFBQSxDQUFDO0FBQ0Y7QUFDRjs7QUFFRCxTQUFPRixNQUFQO0FBQ0QsQ0FqQkQ7O0FBbUJPLFNBQVNLLFNBQVQsQ0FBbUJDLE1BQW5CLEVBQTJCQyxNQUEzQixFQUFtQ2QsT0FBbkMsRUFBNEM7QUFDakRBLEVBQUFBLE9BQU87QUFBRztBQUFBO0FBQUE7O0FBQUFlO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUE7QUFBQSxHQUFnQmYsT0FBaEIsRUFBeUI7QUFBQ0csSUFBQUEsZ0JBQWdCLEVBQUU7QUFBbkIsR0FBekIsQ0FBVjtBQUNBLFNBQU9SLFFBQVEsQ0FBQ3FCLElBQVQsQ0FBY0gsTUFBZCxFQUFzQkMsTUFBdEIsRUFBOEJkLE9BQTlCLENBQVA7QUFDRDs7QUFFTSxTQUFTaUIsa0JBQVQsQ0FBNEJKLE1BQTVCLEVBQW9DQyxNQUFwQyxFQUE0Q2QsT0FBNUMsRUFBcUQ7QUFDMUQsU0FBT0wsUUFBUSxDQUFDcUIsSUFBVCxDQUFjSCxNQUFkLEVBQXNCQyxNQUF0QixFQUE4QmQsT0FBOUIsQ0FBUDtBQUNEIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IERpZmYgZnJvbSAnLi9iYXNlJztcbmltcG9ydCB7Z2VuZXJhdGVPcHRpb25zfSBmcm9tICcuLi91dGlsL3BhcmFtcyc7XG5cbi8vIEJhc2VkIG9uIGh0dHBzOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL0xhdGluX3NjcmlwdF9pbl9Vbmljb2RlXG4vL1xuLy8gUmFuZ2VzIGFuZCBleGNlcHRpb25zOlxuLy8gTGF0aW4tMSBTdXBwbGVtZW50LCAwMDgw4oCTMDBGRlxuLy8gIC0gVSswMEQ3ICDDlyBNdWx0aXBsaWNhdGlvbiBzaWduXG4vLyAgLSBVKzAwRjcgIMO3IERpdmlzaW9uIHNpZ25cbi8vIExhdGluIEV4dGVuZGVkLUEsIDAxMDDigJMwMTdGXG4vLyBMYXRpbiBFeHRlbmRlZC1CLCAwMTgw4oCTMDI0RlxuLy8gSVBBIEV4dGVuc2lvbnMsIDAyNTDigJMwMkFGXG4vLyBTcGFjaW5nIE1vZGlmaWVyIExldHRlcnMsIDAyQjDigJMwMkZGXG4vLyAgLSBVKzAyQzcgIMuHICYjNzExOyAgQ2Fyb25cbi8vICAtIFUrMDJEOCAgy5ggJiM3Mjg7ICBCcmV2ZVxuLy8gIC0gVSswMkQ5ICDLmSAmIzcyOTsgIERvdCBBYm92ZVxuLy8gIC0gVSswMkRBICDLmiAmIzczMDsgIFJpbmcgQWJvdmVcbi8vICAtIFUrMDJEQiAgy5sgJiM3MzE7ICBPZ29uZWtcbi8vICAtIFUrMDJEQyAgy5wgJiM3MzI7ICBTbWFsbCBUaWxkZVxuLy8gIC0gVSswMkREICDLnSAmIzczMzsgIERvdWJsZSBBY3V0ZSBBY2NlbnRcbi8vIExhdGluIEV4dGVuZGVkIEFkZGl0aW9uYWwsIDFFMDDigJMxRUZGXG5jb25zdCBleHRlbmRlZFdvcmRDaGFycyA9IC9eW2EtekEtWlxcdXtDMH0tXFx1e0ZGfVxcdXtEOH0tXFx1e0Y2fVxcdXtGOH0tXFx1ezJDNn1cXHV7MkM4fS1cXHV7MkQ3fVxcdXsyREV9LVxcdXsyRkZ9XFx1ezFFMDB9LVxcdXsxRUZGfV0rJC91O1xuXG5jb25zdCByZVdoaXRlc3BhY2UgPSAvXFxTLztcblxuZXhwb3J0IGNvbnN0IHdvcmREaWZmID0gbmV3IERpZmYoKTtcbndvcmREaWZmLmVxdWFscyA9IGZ1bmN0aW9uKGxlZnQsIHJpZ2h0KSB7XG4gIGlmICh0aGlzLm9wdGlvbnMuaWdub3JlQ2FzZSkge1xuICAgIGxlZnQgPSBsZWZ0LnRvTG93ZXJDYXNlKCk7XG4gICAgcmlnaHQgPSByaWdodC50b0xvd2VyQ2FzZSgpO1xuICB9XG4gIHJldHVybiBsZWZ0ID09PSByaWdodCB8fCAodGhpcy5vcHRpb25zLmlnbm9yZVdoaXRlc3BhY2UgJiYgIXJlV2hpdGVzcGFjZS50ZXN0KGxlZnQpICYmICFyZVdoaXRlc3BhY2UudGVzdChyaWdodCkpO1xufTtcbndvcmREaWZmLnRva2VuaXplID0gZnVuY3Rpb24odmFsdWUpIHtcbiAgLy8gQWxsIHdoaXRlc3BhY2Ugc3ltYm9scyBleGNlcHQgbmV3bGluZSBncm91cCBpbnRvIG9uZSB0b2tlbiwgZWFjaCBuZXdsaW5lIC0gaW4gc2VwYXJhdGUgdG9rZW5cbiAgbGV0IHRva2VucyA9IHZhbHVlLnNwbGl0KC8oW15cXFNcXHJcXG5dK3xbKClbXFxde30nXCJcXHJcXG5dfFxcYikvKTtcblxuICAvLyBKb2luIHRoZSBib3VuZGFyeSBzcGxpdHMgdGhhdCB3ZSBkbyBub3QgY29uc2lkZXIgdG8gYmUgYm91bmRhcmllcy4gVGhpcyBpcyBwcmltYXJpbHkgdGhlIGV4dGVuZGVkIExhdGluIGNoYXJhY3RlciBzZXQuXG4gIGZvciAobGV0IGkgPSAwOyBpIDwgdG9rZW5zLmxlbmd0aCAtIDE7IGkrKykge1xuICAgIC8vIElmIHdlIGhhdmUgYW4gZW1wdHkgc3RyaW5nIGluIHRoZSBuZXh0IGZpZWxkIGFuZCB3ZSBoYXZlIG9ubHkgd29yZCBjaGFycyBiZWZvcmUgYW5kIGFmdGVyLCBtZXJnZVxuICAgIGlmICghdG9rZW5zW2kgKyAxXSAmJiB0b2tlbnNbaSArIDJdXG4gICAgICAgICAgJiYgZXh0ZW5kZWRXb3JkQ2hhcnMudGVzdCh0b2tlbnNbaV0pXG4gICAgICAgICAgJiYgZXh0ZW5kZWRXb3JkQ2hhcnMudGVzdCh0b2tlbnNbaSArIDJdKSkge1xuICAgICAgdG9rZW5zW2ldICs9IHRva2Vuc1tpICsgMl07XG4gICAgICB0b2tlbnMuc3BsaWNlKGkgKyAxLCAyKTtcbiAgICAgIGktLTtcbiAgICB9XG4gIH1cblxuICByZXR1cm4gdG9rZW5zO1xufTtcblxuZXhwb3J0IGZ1bmN0aW9uIGRpZmZXb3JkcyhvbGRTdHIsIG5ld1N0ciwgb3B0aW9ucykge1xuICBvcHRpb25zID0gZ2VuZXJhdGVPcHRpb25zKG9wdGlvbnMsIHtpZ25vcmVXaGl0ZXNwYWNlOiB0cnVlfSk7XG4gIHJldHVybiB3b3JkRGlmZi5kaWZmKG9sZFN0ciwgbmV3U3RyLCBvcHRpb25zKTtcbn1cblxuZXhwb3J0IGZ1bmN0aW9uIGRpZmZXb3Jkc1dpdGhTcGFjZShvbGRTdHIsIG5ld1N0ciwgb3B0aW9ucykge1xuICByZXR1cm4gd29yZERpZmYuZGlmZihvbGRTdHIsIG5ld1N0ciwgb3B0aW9ucyk7XG59XG4iXX0=
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/index.es6.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/index.es6.js
          new file mode 100644
          index 00000000000000..ca0e5917c44a4b
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/index.es6.js
          @@ -0,0 +1,1553 @@
          +function Diff() {}
          +Diff.prototype = {
          +  diff: function diff(oldString, newString) {
          +    var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
          +    var callback = options.callback;
          +
          +    if (typeof options === 'function') {
          +      callback = options;
          +      options = {};
          +    }
          +
          +    this.options = options;
          +    var self = this;
          +
          +    function done(value) {
          +      if (callback) {
          +        setTimeout(function () {
          +          callback(undefined, value);
          +        }, 0);
          +        return true;
          +      } else {
          +        return value;
          +      }
          +    } // Allow subclasses to massage the input prior to running
          +
          +
          +    oldString = this.castInput(oldString);
          +    newString = this.castInput(newString);
          +    oldString = this.removeEmpty(this.tokenize(oldString));
          +    newString = this.removeEmpty(this.tokenize(newString));
          +    var newLen = newString.length,
          +        oldLen = oldString.length;
          +    var editLength = 1;
          +    var maxEditLength = newLen + oldLen;
          +    var bestPath = [{
          +      newPos: -1,
          +      components: []
          +    }]; // Seed editLength = 0, i.e. the content starts with the same values
          +
          +    var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
          +
          +    if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
          +      // Identity per the equality and tokenizer
          +      return done([{
          +        value: this.join(newString),
          +        count: newString.length
          +      }]);
          +    } // Main worker method. checks all permutations of a given edit length for acceptance.
          +
          +
          +    function execEditLength() {
          +      for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
          +        var basePath = void 0;
          +
          +        var addPath = bestPath[diagonalPath - 1],
          +            removePath = bestPath[diagonalPath + 1],
          +            _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
          +
          +        if (addPath) {
          +          // No one else is going to attempt to use this value, clear it
          +          bestPath[diagonalPath - 1] = undefined;
          +        }
          +
          +        var canAdd = addPath && addPath.newPos + 1 < newLen,
          +            canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
          +
          +        if (!canAdd && !canRemove) {
          +          // If this path is a terminal then prune
          +          bestPath[diagonalPath] = undefined;
          +          continue;
          +        } // Select the diagonal that we want to branch from. We select the prior
          +        // path whose position in the new string is the farthest from the origin
          +        // and does not pass the bounds of the diff graph
          +
          +
          +        if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
          +          basePath = clonePath(removePath);
          +          self.pushComponent(basePath.components, undefined, true);
          +        } else {
          +          basePath = addPath; // No need to clone, we've pulled it from the list
          +
          +          basePath.newPos++;
          +          self.pushComponent(basePath.components, true, undefined);
          +        }
          +
          +        _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
          +
          +        if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
          +          return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
          +        } else {
          +          // Otherwise track this path as a potential candidate and continue.
          +          bestPath[diagonalPath] = basePath;
          +        }
          +      }
          +
          +      editLength++;
          +    } // Performs the length of edit iteration. Is a bit fugly as this has to support the
          +    // sync and async mode which is never fun. Loops over execEditLength until a value
          +    // is produced.
          +
          +
          +    if (callback) {
          +      (function exec() {
          +        setTimeout(function () {
          +          // This should not happen, but we want to be safe.
          +
          +          /* istanbul ignore next */
          +          if (editLength > maxEditLength) {
          +            return callback();
          +          }
          +
          +          if (!execEditLength()) {
          +            exec();
          +          }
          +        }, 0);
          +      })();
          +    } else {
          +      while (editLength <= maxEditLength) {
          +        var ret = execEditLength();
          +
          +        if (ret) {
          +          return ret;
          +        }
          +      }
          +    }
          +  },
          +  pushComponent: function pushComponent(components, added, removed) {
          +    var last = components[components.length - 1];
          +
          +    if (last && last.added === added && last.removed === removed) {
          +      // We need to clone here as the component clone operation is just
          +      // as shallow array clone
          +      components[components.length - 1] = {
          +        count: last.count + 1,
          +        added: added,
          +        removed: removed
          +      };
          +    } else {
          +      components.push({
          +        count: 1,
          +        added: added,
          +        removed: removed
          +      });
          +    }
          +  },
          +  extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
          +    var newLen = newString.length,
          +        oldLen = oldString.length,
          +        newPos = basePath.newPos,
          +        oldPos = newPos - diagonalPath,
          +        commonCount = 0;
          +
          +    while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
          +      newPos++;
          +      oldPos++;
          +      commonCount++;
          +    }
          +
          +    if (commonCount) {
          +      basePath.components.push({
          +        count: commonCount
          +      });
          +    }
          +
          +    basePath.newPos = newPos;
          +    return oldPos;
          +  },
          +  equals: function equals(left, right) {
          +    if (this.options.comparator) {
          +      return this.options.comparator(left, right);
          +    } else {
          +      return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
          +    }
          +  },
          +  removeEmpty: function removeEmpty(array) {
          +    var ret = [];
          +
          +    for (var i = 0; i < array.length; i++) {
          +      if (array[i]) {
          +        ret.push(array[i]);
          +      }
          +    }
          +
          +    return ret;
          +  },
          +  castInput: function castInput(value) {
          +    return value;
          +  },
          +  tokenize: function tokenize(value) {
          +    return value.split('');
          +  },
          +  join: function join(chars) {
          +    return chars.join('');
          +  }
          +};
          +
          +function buildValues(diff, components, newString, oldString, useLongestToken) {
          +  var componentPos = 0,
          +      componentLen = components.length,
          +      newPos = 0,
          +      oldPos = 0;
          +
          +  for (; componentPos < componentLen; componentPos++) {
          +    var component = components[componentPos];
          +
          +    if (!component.removed) {
          +      if (!component.added && useLongestToken) {
          +        var value = newString.slice(newPos, newPos + component.count);
          +        value = value.map(function (value, i) {
          +          var oldValue = oldString[oldPos + i];
          +          return oldValue.length > value.length ? oldValue : value;
          +        });
          +        component.value = diff.join(value);
          +      } else {
          +        component.value = diff.join(newString.slice(newPos, newPos + component.count));
          +      }
          +
          +      newPos += component.count; // Common case
          +
          +      if (!component.added) {
          +        oldPos += component.count;
          +      }
          +    } else {
          +      component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
          +      oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
          +      // The diffing algorithm is tied to add then remove output and this is the simplest
          +      // route to get the desired output with minimal overhead.
          +
          +      if (componentPos && components[componentPos - 1].added) {
          +        var tmp = components[componentPos - 1];
          +        components[componentPos - 1] = components[componentPos];
          +        components[componentPos] = tmp;
          +      }
          +    }
          +  } // Special case handle for when one terminal is ignored (i.e. whitespace).
          +  // For this case we merge the terminal into the prior string and drop the change.
          +  // This is only available for string mode.
          +
          +
          +  var lastComponent = components[componentLen - 1];
          +
          +  if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
          +    components[componentLen - 2].value += lastComponent.value;
          +    components.pop();
          +  }
          +
          +  return components;
          +}
          +
          +function clonePath(path) {
          +  return {
          +    newPos: path.newPos,
          +    components: path.components.slice(0)
          +  };
          +}
          +
          +var characterDiff = new Diff();
          +function diffChars(oldStr, newStr, options) {
          +  return characterDiff.diff(oldStr, newStr, options);
          +}
          +
          +function generateOptions(options, defaults) {
          +  if (typeof options === 'function') {
          +    defaults.callback = options;
          +  } else if (options) {
          +    for (var name in options) {
          +      /* istanbul ignore else */
          +      if (options.hasOwnProperty(name)) {
          +        defaults[name] = options[name];
          +      }
          +    }
          +  }
          +
          +  return defaults;
          +}
          +
          +//
          +// Ranges and exceptions:
          +// Latin-1 Supplement, 0080–00FF
          +//  - U+00D7  × Multiplication sign
          +//  - U+00F7  ÷ Division sign
          +// Latin Extended-A, 0100–017F
          +// Latin Extended-B, 0180–024F
          +// IPA Extensions, 0250–02AF
          +// Spacing Modifier Letters, 02B0–02FF
          +//  - U+02C7  ˇ ˇ  Caron
          +//  - U+02D8  ˘ ˘  Breve
          +//  - U+02D9  ˙ ˙  Dot Above
          +//  - U+02DA  ˚ ˚  Ring Above
          +//  - U+02DB  ˛ ˛  Ogonek
          +//  - U+02DC  ˜ ˜  Small Tilde
          +//  - U+02DD  ˝ ˝  Double Acute Accent
          +// Latin Extended Additional, 1E00–1EFF
          +
          +var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
          +var reWhitespace = /\S/;
          +var wordDiff = new Diff();
          +
          +wordDiff.equals = function (left, right) {
          +  if (this.options.ignoreCase) {
          +    left = left.toLowerCase();
          +    right = right.toLowerCase();
          +  }
          +
          +  return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
          +};
          +
          +wordDiff.tokenize = function (value) {
          +  // All whitespace symbols except newline group into one token, each newline - in separate token
          +  var tokens = value.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/); // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
          +
          +  for (var i = 0; i < tokens.length - 1; i++) {
          +    // If we have an empty string in the next field and we have only word chars before and after, merge
          +    if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
          +      tokens[i] += tokens[i + 2];
          +      tokens.splice(i + 1, 2);
          +      i--;
          +    }
          +  }
          +
          +  return tokens;
          +};
          +
          +function diffWords(oldStr, newStr, options) {
          +  options = generateOptions(options, {
          +    ignoreWhitespace: true
          +  });
          +  return wordDiff.diff(oldStr, newStr, options);
          +}
          +function diffWordsWithSpace(oldStr, newStr, options) {
          +  return wordDiff.diff(oldStr, newStr, options);
          +}
          +
          +var lineDiff = new Diff();
          +
          +lineDiff.tokenize = function (value) {
          +  var retLines = [],
          +      linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
          +
          +  if (!linesAndNewlines[linesAndNewlines.length - 1]) {
          +    linesAndNewlines.pop();
          +  } // Merge the content and line separators into single tokens
          +
          +
          +  for (var i = 0; i < linesAndNewlines.length; i++) {
          +    var line = linesAndNewlines[i];
          +
          +    if (i % 2 && !this.options.newlineIsToken) {
          +      retLines[retLines.length - 1] += line;
          +    } else {
          +      if (this.options.ignoreWhitespace) {
          +        line = line.trim();
          +      }
          +
          +      retLines.push(line);
          +    }
          +  }
          +
          +  return retLines;
          +};
          +
          +function diffLines(oldStr, newStr, callback) {
          +  return lineDiff.diff(oldStr, newStr, callback);
          +}
          +function diffTrimmedLines(oldStr, newStr, callback) {
          +  var options = generateOptions(callback, {
          +    ignoreWhitespace: true
          +  });
          +  return lineDiff.diff(oldStr, newStr, options);
          +}
          +
          +var sentenceDiff = new Diff();
          +
          +sentenceDiff.tokenize = function (value) {
          +  return value.split(/(\S.+?[.!?])(?=\s+|$)/);
          +};
          +
          +function diffSentences(oldStr, newStr, callback) {
          +  return sentenceDiff.diff(oldStr, newStr, callback);
          +}
          +
          +var cssDiff = new Diff();
          +
          +cssDiff.tokenize = function (value) {
          +  return value.split(/([{}:;,]|\s+)/);
          +};
          +
          +function diffCss(oldStr, newStr, callback) {
          +  return cssDiff.diff(oldStr, newStr, callback);
          +}
          +
          +function _typeof(obj) {
          +  "@babel/helpers - typeof";
          +
          +  if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
          +    _typeof = function (obj) {
          +      return typeof obj;
          +    };
          +  } else {
          +    _typeof = function (obj) {
          +      return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
          +    };
          +  }
          +
          +  return _typeof(obj);
          +}
          +
          +function _toConsumableArray(arr) {
          +  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
          +}
          +
          +function _arrayWithoutHoles(arr) {
          +  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
          +}
          +
          +function _iterableToArray(iter) {
          +  if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
          +}
          +
          +function _unsupportedIterableToArray(o, minLen) {
          +  if (!o) return;
          +  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
          +  var n = Object.prototype.toString.call(o).slice(8, -1);
          +  if (n === "Object" && o.constructor) n = o.constructor.name;
          +  if (n === "Map" || n === "Set") return Array.from(o);
          +  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
          +}
          +
          +function _arrayLikeToArray(arr, len) {
          +  if (len == null || len > arr.length) len = arr.length;
          +
          +  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
          +
          +  return arr2;
          +}
          +
          +function _nonIterableSpread() {
          +  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
          +}
          +
          +var objectPrototypeToString = Object.prototype.toString;
          +var jsonDiff = new Diff(); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
          +// dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
          +
          +jsonDiff.useLongestToken = true;
          +jsonDiff.tokenize = lineDiff.tokenize;
          +
          +jsonDiff.castInput = function (value) {
          +  var _this$options = this.options,
          +      undefinedReplacement = _this$options.undefinedReplacement,
          +      _this$options$stringi = _this$options.stringifyReplacer,
          +      stringifyReplacer = _this$options$stringi === void 0 ? function (k, v) {
          +    return typeof v === 'undefined' ? undefinedReplacement : v;
          +  } : _this$options$stringi;
          +  return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, '  ');
          +};
          +
          +jsonDiff.equals = function (left, right) {
          +  return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
          +};
          +
          +function diffJson(oldObj, newObj, options) {
          +  return jsonDiff.diff(oldObj, newObj, options);
          +} // This function handles the presence of circular references by bailing out when encountering an
          +// object that is already on the "stack" of items being processed. Accepts an optional replacer
          +
          +function canonicalize(obj, stack, replacementStack, replacer, key) {
          +  stack = stack || [];
          +  replacementStack = replacementStack || [];
          +
          +  if (replacer) {
          +    obj = replacer(key, obj);
          +  }
          +
          +  var i;
          +
          +  for (i = 0; i < stack.length; i += 1) {
          +    if (stack[i] === obj) {
          +      return replacementStack[i];
          +    }
          +  }
          +
          +  var canonicalizedObj;
          +
          +  if ('[object Array]' === objectPrototypeToString.call(obj)) {
          +    stack.push(obj);
          +    canonicalizedObj = new Array(obj.length);
          +    replacementStack.push(canonicalizedObj);
          +
          +    for (i = 0; i < obj.length; i += 1) {
          +      canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
          +    }
          +
          +    stack.pop();
          +    replacementStack.pop();
          +    return canonicalizedObj;
          +  }
          +
          +  if (obj && obj.toJSON) {
          +    obj = obj.toJSON();
          +  }
          +
          +  if (_typeof(obj) === 'object' && obj !== null) {
          +    stack.push(obj);
          +    canonicalizedObj = {};
          +    replacementStack.push(canonicalizedObj);
          +
          +    var sortedKeys = [],
          +        _key;
          +
          +    for (_key in obj) {
          +      /* istanbul ignore else */
          +      if (obj.hasOwnProperty(_key)) {
          +        sortedKeys.push(_key);
          +      }
          +    }
          +
          +    sortedKeys.sort();
          +
          +    for (i = 0; i < sortedKeys.length; i += 1) {
          +      _key = sortedKeys[i];
          +      canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
          +    }
          +
          +    stack.pop();
          +    replacementStack.pop();
          +  } else {
          +    canonicalizedObj = obj;
          +  }
          +
          +  return canonicalizedObj;
          +}
          +
          +var arrayDiff = new Diff();
          +
          +arrayDiff.tokenize = function (value) {
          +  return value.slice();
          +};
          +
          +arrayDiff.join = arrayDiff.removeEmpty = function (value) {
          +  return value;
          +};
          +
          +function diffArrays(oldArr, newArr, callback) {
          +  return arrayDiff.diff(oldArr, newArr, callback);
          +}
          +
          +function parsePatch(uniDiff) {
          +  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
          +  var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
          +      delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
          +      list = [],
          +      i = 0;
          +
          +  function parseIndex() {
          +    var index = {};
          +    list.push(index); // Parse diff metadata
          +
          +    while (i < diffstr.length) {
          +      var line = diffstr[i]; // File header found, end parsing diff metadata
          +
          +      if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
          +        break;
          +      } // Diff index
          +
          +
          +      var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
          +
          +      if (header) {
          +        index.index = header[1];
          +      }
          +
          +      i++;
          +    } // Parse file headers if they are defined. Unified diff requires them, but
          +    // there's no technical issues to have an isolated hunk without file header
          +
          +
          +    parseFileHeader(index);
          +    parseFileHeader(index); // Parse hunks
          +
          +    index.hunks = [];
          +
          +    while (i < diffstr.length) {
          +      var _line = diffstr[i];
          +
          +      if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
          +        break;
          +      } else if (/^@@/.test(_line)) {
          +        index.hunks.push(parseHunk());
          +      } else if (_line && options.strict) {
          +        // Ignore unexpected content unless in strict mode
          +        throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
          +      } else {
          +        i++;
          +      }
          +    }
          +  } // Parses the --- and +++ headers, if none are found, no lines
          +  // are consumed.
          +
          +
          +  function parseFileHeader(index) {
          +    var fileHeader = /^(---|\+\+\+)\s+(.*)$/.exec(diffstr[i]);
          +
          +    if (fileHeader) {
          +      var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
          +      var data = fileHeader[2].split('\t', 2);
          +      var fileName = data[0].replace(/\\\\/g, '\\');
          +
          +      if (/^".*"$/.test(fileName)) {
          +        fileName = fileName.substr(1, fileName.length - 2);
          +      }
          +
          +      index[keyPrefix + 'FileName'] = fileName;
          +      index[keyPrefix + 'Header'] = (data[1] || '').trim();
          +      i++;
          +    }
          +  } // Parses a hunk
          +  // This assumes that we are at the start of a hunk.
          +
          +
          +  function parseHunk() {
          +    var chunkHeaderIndex = i,
          +        chunkHeaderLine = diffstr[i++],
          +        chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
          +    var hunk = {
          +      oldStart: +chunkHeader[1],
          +      oldLines: typeof chunkHeader[2] === 'undefined' ? 1 : +chunkHeader[2],
          +      newStart: +chunkHeader[3],
          +      newLines: typeof chunkHeader[4] === 'undefined' ? 1 : +chunkHeader[4],
          +      lines: [],
          +      linedelimiters: []
          +    }; // Unified Diff Format quirk: If the chunk size is 0,
          +    // the first number is one lower than one would expect.
          +    // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
          +
          +    if (hunk.oldLines === 0) {
          +      hunk.oldStart += 1;
          +    }
          +
          +    if (hunk.newLines === 0) {
          +      hunk.newStart += 1;
          +    }
          +
          +    var addCount = 0,
          +        removeCount = 0;
          +
          +    for (; i < diffstr.length; i++) {
          +      // Lines starting with '---' could be mistaken for the "remove line" operation
          +      // But they could be the header for the next file. Therefore prune such cases out.
          +      if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
          +        break;
          +      }
          +
          +      var operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? ' ' : diffstr[i][0];
          +
          +      if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
          +        hunk.lines.push(diffstr[i]);
          +        hunk.linedelimiters.push(delimiters[i] || '\n');
          +
          +        if (operation === '+') {
          +          addCount++;
          +        } else if (operation === '-') {
          +          removeCount++;
          +        } else if (operation === ' ') {
          +          addCount++;
          +          removeCount++;
          +        }
          +      } else {
          +        break;
          +      }
          +    } // Handle the empty block count case
          +
          +
          +    if (!addCount && hunk.newLines === 1) {
          +      hunk.newLines = 0;
          +    }
          +
          +    if (!removeCount && hunk.oldLines === 1) {
          +      hunk.oldLines = 0;
          +    } // Perform optional sanity checking
          +
          +
          +    if (options.strict) {
          +      if (addCount !== hunk.newLines) {
          +        throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
          +      }
          +
          +      if (removeCount !== hunk.oldLines) {
          +        throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
          +      }
          +    }
          +
          +    return hunk;
          +  }
          +
          +  while (i < diffstr.length) {
          +    parseIndex();
          +  }
          +
          +  return list;
          +}
          +
          +// Iterator that traverses in the range of [min, max], stepping
          +// by distance from a given start position. I.e. for [0, 4], with
          +// start of 2, this will iterate 2, 3, 1, 4, 0.
          +function distanceIterator (start, minLine, maxLine) {
          +  var wantForward = true,
          +      backwardExhausted = false,
          +      forwardExhausted = false,
          +      localOffset = 1;
          +  return function iterator() {
          +    if (wantForward && !forwardExhausted) {
          +      if (backwardExhausted) {
          +        localOffset++;
          +      } else {
          +        wantForward = false;
          +      } // Check if trying to fit beyond text length, and if not, check it fits
          +      // after offset location (or desired location on first iteration)
          +
          +
          +      if (start + localOffset <= maxLine) {
          +        return localOffset;
          +      }
          +
          +      forwardExhausted = true;
          +    }
          +
          +    if (!backwardExhausted) {
          +      if (!forwardExhausted) {
          +        wantForward = true;
          +      } // Check if trying to fit before text beginning, and if not, check it fits
          +      // before offset location
          +
          +
          +      if (minLine <= start - localOffset) {
          +        return -localOffset++;
          +      }
          +
          +      backwardExhausted = true;
          +      return iterator();
          +    } // We tried to fit hunk before text beginning and beyond text length, then
          +    // hunk can't fit on the text. Return undefined
          +
          +  };
          +}
          +
          +function applyPatch(source, uniDiff) {
          +  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
          +
          +  if (typeof uniDiff === 'string') {
          +    uniDiff = parsePatch(uniDiff);
          +  }
          +
          +  if (Array.isArray(uniDiff)) {
          +    if (uniDiff.length > 1) {
          +      throw new Error('applyPatch only works with a single input.');
          +    }
          +
          +    uniDiff = uniDiff[0];
          +  } // Apply the diff to the input
          +
          +
          +  var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
          +      delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
          +      hunks = uniDiff.hunks,
          +      compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) {
          +    return line === patchContent;
          +  },
          +      errorCount = 0,
          +      fuzzFactor = options.fuzzFactor || 0,
          +      minLine = 0,
          +      offset = 0,
          +      removeEOFNL,
          +      addEOFNL;
          +  /**
          +   * Checks if the hunk exactly fits on the provided location
          +   */
          +
          +
          +  function hunkFits(hunk, toPos) {
          +    for (var j = 0; j < hunk.lines.length; j++) {
          +      var line = hunk.lines[j],
          +          operation = line.length > 0 ? line[0] : ' ',
          +          content = line.length > 0 ? line.substr(1) : line;
          +
          +      if (operation === ' ' || operation === '-') {
          +        // Context sanity check
          +        if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
          +          errorCount++;
          +
          +          if (errorCount > fuzzFactor) {
          +            return false;
          +          }
          +        }
          +
          +        toPos++;
          +      }
          +    }
          +
          +    return true;
          +  } // Search best fit offsets for each hunk based on the previous ones
          +
          +
          +  for (var i = 0; i < hunks.length; i++) {
          +    var hunk = hunks[i],
          +        maxLine = lines.length - hunk.oldLines,
          +        localOffset = 0,
          +        toPos = offset + hunk.oldStart - 1;
          +    var iterator = distanceIterator(toPos, minLine, maxLine);
          +
          +    for (; localOffset !== undefined; localOffset = iterator()) {
          +      if (hunkFits(hunk, toPos + localOffset)) {
          +        hunk.offset = offset += localOffset;
          +        break;
          +      }
          +    }
          +
          +    if (localOffset === undefined) {
          +      return false;
          +    } // Set lower text limit to end of the current hunk, so next ones don't try
          +    // to fit over already patched text
          +
          +
          +    minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
          +  } // Apply patch hunks
          +
          +
          +  var diffOffset = 0;
          +
          +  for (var _i = 0; _i < hunks.length; _i++) {
          +    var _hunk = hunks[_i],
          +        _toPos = _hunk.oldStart + _hunk.offset + diffOffset - 1;
          +
          +    diffOffset += _hunk.newLines - _hunk.oldLines;
          +
          +    for (var j = 0; j < _hunk.lines.length; j++) {
          +      var line = _hunk.lines[j],
          +          operation = line.length > 0 ? line[0] : ' ',
          +          content = line.length > 0 ? line.substr(1) : line,
          +          delimiter = _hunk.linedelimiters[j];
          +
          +      if (operation === ' ') {
          +        _toPos++;
          +      } else if (operation === '-') {
          +        lines.splice(_toPos, 1);
          +        delimiters.splice(_toPos, 1);
          +        /* istanbul ignore else */
          +      } else if (operation === '+') {
          +        lines.splice(_toPos, 0, content);
          +        delimiters.splice(_toPos, 0, delimiter);
          +        _toPos++;
          +      } else if (operation === '\\') {
          +        var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
          +
          +        if (previousOperation === '+') {
          +          removeEOFNL = true;
          +        } else if (previousOperation === '-') {
          +          addEOFNL = true;
          +        }
          +      }
          +    }
          +  } // Handle EOFNL insertion/removal
          +
          +
          +  if (removeEOFNL) {
          +    while (!lines[lines.length - 1]) {
          +      lines.pop();
          +      delimiters.pop();
          +    }
          +  } else if (addEOFNL) {
          +    lines.push('');
          +    delimiters.push('\n');
          +  }
          +
          +  for (var _k = 0; _k < lines.length - 1; _k++) {
          +    lines[_k] = lines[_k] + delimiters[_k];
          +  }
          +
          +  return lines.join('');
          +} // Wrapper that supports multiple file patches via callbacks.
          +
          +function applyPatches(uniDiff, options) {
          +  if (typeof uniDiff === 'string') {
          +    uniDiff = parsePatch(uniDiff);
          +  }
          +
          +  var currentIndex = 0;
          +
          +  function processIndex() {
          +    var index = uniDiff[currentIndex++];
          +
          +    if (!index) {
          +      return options.complete();
          +    }
          +
          +    options.loadFile(index, function (err, data) {
          +      if (err) {
          +        return options.complete(err);
          +      }
          +
          +      var updatedContent = applyPatch(data, index, options);
          +      options.patched(index, updatedContent, function (err) {
          +        if (err) {
          +          return options.complete(err);
          +        }
          +
          +        processIndex();
          +      });
          +    });
          +  }
          +
          +  processIndex();
          +}
          +
          +function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
          +  if (!options) {
          +    options = {};
          +  }
          +
          +  if (typeof options.context === 'undefined') {
          +    options.context = 4;
          +  }
          +
          +  var diff = diffLines(oldStr, newStr, options);
          +  diff.push({
          +    value: '',
          +    lines: []
          +  }); // Append an empty value to make cleanup easier
          +
          +  function contextLines(lines) {
          +    return lines.map(function (entry) {
          +      return ' ' + entry;
          +    });
          +  }
          +
          +  var hunks = [];
          +  var oldRangeStart = 0,
          +      newRangeStart = 0,
          +      curRange = [],
          +      oldLine = 1,
          +      newLine = 1;
          +
          +  var _loop = function _loop(i) {
          +    var current = diff[i],
          +        lines = current.lines || current.value.replace(/\n$/, '').split('\n');
          +    current.lines = lines;
          +
          +    if (current.added || current.removed) {
          +      var _curRange;
          +
          +      // If we have previous context, start with that
          +      if (!oldRangeStart) {
          +        var prev = diff[i - 1];
          +        oldRangeStart = oldLine;
          +        newRangeStart = newLine;
          +
          +        if (prev) {
          +          curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
          +          oldRangeStart -= curRange.length;
          +          newRangeStart -= curRange.length;
          +        }
          +      } // Output our changes
          +
          +
          +      (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
          +        return (current.added ? '+' : '-') + entry;
          +      }))); // Track the updated file position
          +
          +
          +      if (current.added) {
          +        newLine += lines.length;
          +      } else {
          +        oldLine += lines.length;
          +      }
          +    } else {
          +      // Identical context lines. Track line changes
          +      if (oldRangeStart) {
          +        // Close out any changes that have been output (or join overlapping)
          +        if (lines.length <= options.context * 2 && i < diff.length - 2) {
          +          var _curRange2;
          +
          +          // Overlapping
          +          (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
          +        } else {
          +          var _curRange3;
          +
          +          // end the range and output
          +          var contextSize = Math.min(lines.length, options.context);
          +
          +          (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
          +
          +          var hunk = {
          +            oldStart: oldRangeStart,
          +            oldLines: oldLine - oldRangeStart + contextSize,
          +            newStart: newRangeStart,
          +            newLines: newLine - newRangeStart + contextSize,
          +            lines: curRange
          +          };
          +
          +          if (i >= diff.length - 2 && lines.length <= options.context) {
          +            // EOF is inside this hunk
          +            var oldEOFNewline = /\n$/.test(oldStr);
          +            var newEOFNewline = /\n$/.test(newStr);
          +            var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
          +
          +            if (!oldEOFNewline && noNlBeforeAdds && oldStr.length > 0) {
          +              // special case: old has no eol and no trailing context; no-nl can end up before adds
          +              // however, if the old file is empty, do not output the no-nl line
          +              curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
          +            }
          +
          +            if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
          +              curRange.push('\\ No newline at end of file');
          +            }
          +          }
          +
          +          hunks.push(hunk);
          +          oldRangeStart = 0;
          +          newRangeStart = 0;
          +          curRange = [];
          +        }
          +      }
          +
          +      oldLine += lines.length;
          +      newLine += lines.length;
          +    }
          +  };
          +
          +  for (var i = 0; i < diff.length; i++) {
          +    _loop(i);
          +  }
          +
          +  return {
          +    oldFileName: oldFileName,
          +    newFileName: newFileName,
          +    oldHeader: oldHeader,
          +    newHeader: newHeader,
          +    hunks: hunks
          +  };
          +}
          +function formatPatch(diff) {
          +  var ret = [];
          +
          +  if (diff.oldFileName == diff.newFileName) {
          +    ret.push('Index: ' + diff.oldFileName);
          +  }
          +
          +  ret.push('===================================================================');
          +  ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
          +  ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
          +
          +  for (var i = 0; i < diff.hunks.length; i++) {
          +    var hunk = diff.hunks[i]; // Unified Diff Format quirk: If the chunk size is 0,
          +    // the first number is one lower than one would expect.
          +    // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
          +
          +    if (hunk.oldLines === 0) {
          +      hunk.oldStart -= 1;
          +    }
          +
          +    if (hunk.newLines === 0) {
          +      hunk.newStart -= 1;
          +    }
          +
          +    ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
          +    ret.push.apply(ret, hunk.lines);
          +  }
          +
          +  return ret.join('\n') + '\n';
          +}
          +function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
          +  return formatPatch(structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options));
          +}
          +function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
          +  return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
          +}
          +
          +function arrayEqual(a, b) {
          +  if (a.length !== b.length) {
          +    return false;
          +  }
          +
          +  return arrayStartsWith(a, b);
          +}
          +function arrayStartsWith(array, start) {
          +  if (start.length > array.length) {
          +    return false;
          +  }
          +
          +  for (var i = 0; i < start.length; i++) {
          +    if (start[i] !== array[i]) {
          +      return false;
          +    }
          +  }
          +
          +  return true;
          +}
          +
          +function calcLineCount(hunk) {
          +  var _calcOldNewLineCount = calcOldNewLineCount(hunk.lines),
          +      oldLines = _calcOldNewLineCount.oldLines,
          +      newLines = _calcOldNewLineCount.newLines;
          +
          +  if (oldLines !== undefined) {
          +    hunk.oldLines = oldLines;
          +  } else {
          +    delete hunk.oldLines;
          +  }
          +
          +  if (newLines !== undefined) {
          +    hunk.newLines = newLines;
          +  } else {
          +    delete hunk.newLines;
          +  }
          +}
          +function merge(mine, theirs, base) {
          +  mine = loadPatch(mine, base);
          +  theirs = loadPatch(theirs, base);
          +  var ret = {}; // For index we just let it pass through as it doesn't have any necessary meaning.
          +  // Leaving sanity checks on this to the API consumer that may know more about the
          +  // meaning in their own context.
          +
          +  if (mine.index || theirs.index) {
          +    ret.index = mine.index || theirs.index;
          +  }
          +
          +  if (mine.newFileName || theirs.newFileName) {
          +    if (!fileNameChanged(mine)) {
          +      // No header or no change in ours, use theirs (and ours if theirs does not exist)
          +      ret.oldFileName = theirs.oldFileName || mine.oldFileName;
          +      ret.newFileName = theirs.newFileName || mine.newFileName;
          +      ret.oldHeader = theirs.oldHeader || mine.oldHeader;
          +      ret.newHeader = theirs.newHeader || mine.newHeader;
          +    } else if (!fileNameChanged(theirs)) {
          +      // No header or no change in theirs, use ours
          +      ret.oldFileName = mine.oldFileName;
          +      ret.newFileName = mine.newFileName;
          +      ret.oldHeader = mine.oldHeader;
          +      ret.newHeader = mine.newHeader;
          +    } else {
          +      // Both changed... figure it out
          +      ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
          +      ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
          +      ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
          +      ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
          +    }
          +  }
          +
          +  ret.hunks = [];
          +  var mineIndex = 0,
          +      theirsIndex = 0,
          +      mineOffset = 0,
          +      theirsOffset = 0;
          +
          +  while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
          +    var mineCurrent = mine.hunks[mineIndex] || {
          +      oldStart: Infinity
          +    },
          +        theirsCurrent = theirs.hunks[theirsIndex] || {
          +      oldStart: Infinity
          +    };
          +
          +    if (hunkBefore(mineCurrent, theirsCurrent)) {
          +      // This patch does not overlap with any of the others, yay.
          +      ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
          +      mineIndex++;
          +      theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
          +    } else if (hunkBefore(theirsCurrent, mineCurrent)) {
          +      // This patch does not overlap with any of the others, yay.
          +      ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
          +      theirsIndex++;
          +      mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
          +    } else {
          +      // Overlap, merge as best we can
          +      var mergedHunk = {
          +        oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
          +        oldLines: 0,
          +        newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
          +        newLines: 0,
          +        lines: []
          +      };
          +      mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
          +      theirsIndex++;
          +      mineIndex++;
          +      ret.hunks.push(mergedHunk);
          +    }
          +  }
          +
          +  return ret;
          +}
          +
          +function loadPatch(param, base) {
          +  if (typeof param === 'string') {
          +    if (/^@@/m.test(param) || /^Index:/m.test(param)) {
          +      return parsePatch(param)[0];
          +    }
          +
          +    if (!base) {
          +      throw new Error('Must provide a base reference or pass in a patch');
          +    }
          +
          +    return structuredPatch(undefined, undefined, base, param);
          +  }
          +
          +  return param;
          +}
          +
          +function fileNameChanged(patch) {
          +  return patch.newFileName && patch.newFileName !== patch.oldFileName;
          +}
          +
          +function selectField(index, mine, theirs) {
          +  if (mine === theirs) {
          +    return mine;
          +  } else {
          +    index.conflict = true;
          +    return {
          +      mine: mine,
          +      theirs: theirs
          +    };
          +  }
          +}
          +
          +function hunkBefore(test, check) {
          +  return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
          +}
          +
          +function cloneHunk(hunk, offset) {
          +  return {
          +    oldStart: hunk.oldStart,
          +    oldLines: hunk.oldLines,
          +    newStart: hunk.newStart + offset,
          +    newLines: hunk.newLines,
          +    lines: hunk.lines
          +  };
          +}
          +
          +function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
          +  // This will generally result in a conflicted hunk, but there are cases where the context
          +  // is the only overlap where we can successfully merge the content here.
          +  var mine = {
          +    offset: mineOffset,
          +    lines: mineLines,
          +    index: 0
          +  },
          +      their = {
          +    offset: theirOffset,
          +    lines: theirLines,
          +    index: 0
          +  }; // Handle any leading content
          +
          +  insertLeading(hunk, mine, their);
          +  insertLeading(hunk, their, mine); // Now in the overlap content. Scan through and select the best changes from each.
          +
          +  while (mine.index < mine.lines.length && their.index < their.lines.length) {
          +    var mineCurrent = mine.lines[mine.index],
          +        theirCurrent = their.lines[their.index];
          +
          +    if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
          +      // Both modified ...
          +      mutualChange(hunk, mine, their);
          +    } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
          +      var _hunk$lines;
          +
          +      // Mine inserted
          +      (_hunk$lines = hunk.lines).push.apply(_hunk$lines, _toConsumableArray(collectChange(mine)));
          +    } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
          +      var _hunk$lines2;
          +
          +      // Theirs inserted
          +      (_hunk$lines2 = hunk.lines).push.apply(_hunk$lines2, _toConsumableArray(collectChange(their)));
          +    } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
          +      // Mine removed or edited
          +      removal(hunk, mine, their);
          +    } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
          +      // Their removed or edited
          +      removal(hunk, their, mine, true);
          +    } else if (mineCurrent === theirCurrent) {
          +      // Context identity
          +      hunk.lines.push(mineCurrent);
          +      mine.index++;
          +      their.index++;
          +    } else {
          +      // Context mismatch
          +      conflict(hunk, collectChange(mine), collectChange(their));
          +    }
          +  } // Now push anything that may be remaining
          +
          +
          +  insertTrailing(hunk, mine);
          +  insertTrailing(hunk, their);
          +  calcLineCount(hunk);
          +}
          +
          +function mutualChange(hunk, mine, their) {
          +  var myChanges = collectChange(mine),
          +      theirChanges = collectChange(their);
          +
          +  if (allRemoves(myChanges) && allRemoves(theirChanges)) {
          +    // Special case for remove changes that are supersets of one another
          +    if (arrayStartsWith(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
          +      var _hunk$lines3;
          +
          +      (_hunk$lines3 = hunk.lines).push.apply(_hunk$lines3, _toConsumableArray(myChanges));
          +
          +      return;
          +    } else if (arrayStartsWith(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
          +      var _hunk$lines4;
          +
          +      (_hunk$lines4 = hunk.lines).push.apply(_hunk$lines4, _toConsumableArray(theirChanges));
          +
          +      return;
          +    }
          +  } else if (arrayEqual(myChanges, theirChanges)) {
          +    var _hunk$lines5;
          +
          +    (_hunk$lines5 = hunk.lines).push.apply(_hunk$lines5, _toConsumableArray(myChanges));
          +
          +    return;
          +  }
          +
          +  conflict(hunk, myChanges, theirChanges);
          +}
          +
          +function removal(hunk, mine, their, swap) {
          +  var myChanges = collectChange(mine),
          +      theirChanges = collectContext(their, myChanges);
          +
          +  if (theirChanges.merged) {
          +    var _hunk$lines6;
          +
          +    (_hunk$lines6 = hunk.lines).push.apply(_hunk$lines6, _toConsumableArray(theirChanges.merged));
          +  } else {
          +    conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
          +  }
          +}
          +
          +function conflict(hunk, mine, their) {
          +  hunk.conflict = true;
          +  hunk.lines.push({
          +    conflict: true,
          +    mine: mine,
          +    theirs: their
          +  });
          +}
          +
          +function insertLeading(hunk, insert, their) {
          +  while (insert.offset < their.offset && insert.index < insert.lines.length) {
          +    var line = insert.lines[insert.index++];
          +    hunk.lines.push(line);
          +    insert.offset++;
          +  }
          +}
          +
          +function insertTrailing(hunk, insert) {
          +  while (insert.index < insert.lines.length) {
          +    var line = insert.lines[insert.index++];
          +    hunk.lines.push(line);
          +  }
          +}
          +
          +function collectChange(state) {
          +  var ret = [],
          +      operation = state.lines[state.index][0];
          +
          +  while (state.index < state.lines.length) {
          +    var line = state.lines[state.index]; // Group additions that are immediately after subtractions and treat them as one "atomic" modify change.
          +
          +    if (operation === '-' && line[0] === '+') {
          +      operation = '+';
          +    }
          +
          +    if (operation === line[0]) {
          +      ret.push(line);
          +      state.index++;
          +    } else {
          +      break;
          +    }
          +  }
          +
          +  return ret;
          +}
          +
          +function collectContext(state, matchChanges) {
          +  var changes = [],
          +      merged = [],
          +      matchIndex = 0,
          +      contextChanges = false,
          +      conflicted = false;
          +
          +  while (matchIndex < matchChanges.length && state.index < state.lines.length) {
          +    var change = state.lines[state.index],
          +        match = matchChanges[matchIndex]; // Once we've hit our add, then we are done
          +
          +    if (match[0] === '+') {
          +      break;
          +    }
          +
          +    contextChanges = contextChanges || change[0] !== ' ';
          +    merged.push(match);
          +    matchIndex++; // Consume any additions in the other block as a conflict to attempt
          +    // to pull in the remaining context after this
          +
          +    if (change[0] === '+') {
          +      conflicted = true;
          +
          +      while (change[0] === '+') {
          +        changes.push(change);
          +        change = state.lines[++state.index];
          +      }
          +    }
          +
          +    if (match.substr(1) === change.substr(1)) {
          +      changes.push(change);
          +      state.index++;
          +    } else {
          +      conflicted = true;
          +    }
          +  }
          +
          +  if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
          +    conflicted = true;
          +  }
          +
          +  if (conflicted) {
          +    return changes;
          +  }
          +
          +  while (matchIndex < matchChanges.length) {
          +    merged.push(matchChanges[matchIndex++]);
          +  }
          +
          +  return {
          +    merged: merged,
          +    changes: changes
          +  };
          +}
          +
          +function allRemoves(changes) {
          +  return changes.reduce(function (prev, change) {
          +    return prev && change[0] === '-';
          +  }, true);
          +}
          +
          +function skipRemoveSuperset(state, removeChanges, delta) {
          +  for (var i = 0; i < delta; i++) {
          +    var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
          +
          +    if (state.lines[state.index + i] !== ' ' + changeContent) {
          +      return false;
          +    }
          +  }
          +
          +  state.index += delta;
          +  return true;
          +}
          +
          +function calcOldNewLineCount(lines) {
          +  var oldLines = 0;
          +  var newLines = 0;
          +  lines.forEach(function (line) {
          +    if (typeof line !== 'string') {
          +      var myCount = calcOldNewLineCount(line.mine);
          +      var theirCount = calcOldNewLineCount(line.theirs);
          +
          +      if (oldLines !== undefined) {
          +        if (myCount.oldLines === theirCount.oldLines) {
          +          oldLines += myCount.oldLines;
          +        } else {
          +          oldLines = undefined;
          +        }
          +      }
          +
          +      if (newLines !== undefined) {
          +        if (myCount.newLines === theirCount.newLines) {
          +          newLines += myCount.newLines;
          +        } else {
          +          newLines = undefined;
          +        }
          +      }
          +    } else {
          +      if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) {
          +        newLines++;
          +      }
          +
          +      if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) {
          +        oldLines++;
          +      }
          +    }
          +  });
          +  return {
          +    oldLines: oldLines,
          +    newLines: newLines
          +  };
          +}
          +
          +// See: http://code.google.com/p/google-diff-match-patch/wiki/API
          +function convertChangesToDMP(changes) {
          +  var ret = [],
          +      change,
          +      operation;
          +
          +  for (var i = 0; i < changes.length; i++) {
          +    change = changes[i];
          +
          +    if (change.added) {
          +      operation = 1;
          +    } else if (change.removed) {
          +      operation = -1;
          +    } else {
          +      operation = 0;
          +    }
          +
          +    ret.push([operation, change.value]);
          +  }
          +
          +  return ret;
          +}
          +
          +function convertChangesToXML(changes) {
          +  var ret = [];
          +
          +  for (var i = 0; i < changes.length; i++) {
          +    var change = changes[i];
          +
          +    if (change.added) {
          +      ret.push('');
          +    } else if (change.removed) {
          +      ret.push('');
          +    }
          +
          +    ret.push(escapeHTML(change.value));
          +
          +    if (change.added) {
          +      ret.push('');
          +    } else if (change.removed) {
          +      ret.push('');
          +    }
          +  }
          +
          +  return ret.join('');
          +}
          +
          +function escapeHTML(s) {
          +  var n = s;
          +  n = n.replace(/&/g, '&');
          +  n = n.replace(//g, '>');
          +  n = n.replace(/"/g, '"');
          +  return n;
          +}
          +
          +export { Diff, applyPatch, applyPatches, canonicalize, convertChangesToDMP, convertChangesToXML, createPatch, createTwoFilesPatch, diffArrays, diffChars, diffCss, diffJson, diffLines, diffSentences, diffTrimmedLines, diffWords, diffWordsWithSpace, merge, parsePatch, structuredPatch };
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/index.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/index.js
          new file mode 100644
          index 00000000000000..920f0feeb0caf9
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/index.js
          @@ -0,0 +1,216 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +Object.defineProperty(exports, "Diff", {
          +  enumerable: true,
          +  get: function get() {
          +    return _base["default"];
          +  }
          +});
          +Object.defineProperty(exports, "diffChars", {
          +  enumerable: true,
          +  get: function get() {
          +    return _character.diffChars;
          +  }
          +});
          +Object.defineProperty(exports, "diffWords", {
          +  enumerable: true,
          +  get: function get() {
          +    return _word.diffWords;
          +  }
          +});
          +Object.defineProperty(exports, "diffWordsWithSpace", {
          +  enumerable: true,
          +  get: function get() {
          +    return _word.diffWordsWithSpace;
          +  }
          +});
          +Object.defineProperty(exports, "diffLines", {
          +  enumerable: true,
          +  get: function get() {
          +    return _line.diffLines;
          +  }
          +});
          +Object.defineProperty(exports, "diffTrimmedLines", {
          +  enumerable: true,
          +  get: function get() {
          +    return _line.diffTrimmedLines;
          +  }
          +});
          +Object.defineProperty(exports, "diffSentences", {
          +  enumerable: true,
          +  get: function get() {
          +    return _sentence.diffSentences;
          +  }
          +});
          +Object.defineProperty(exports, "diffCss", {
          +  enumerable: true,
          +  get: function get() {
          +    return _css.diffCss;
          +  }
          +});
          +Object.defineProperty(exports, "diffJson", {
          +  enumerable: true,
          +  get: function get() {
          +    return _json.diffJson;
          +  }
          +});
          +Object.defineProperty(exports, "canonicalize", {
          +  enumerable: true,
          +  get: function get() {
          +    return _json.canonicalize;
          +  }
          +});
          +Object.defineProperty(exports, "diffArrays", {
          +  enumerable: true,
          +  get: function get() {
          +    return _array.diffArrays;
          +  }
          +});
          +Object.defineProperty(exports, "applyPatch", {
          +  enumerable: true,
          +  get: function get() {
          +    return _apply.applyPatch;
          +  }
          +});
          +Object.defineProperty(exports, "applyPatches", {
          +  enumerable: true,
          +  get: function get() {
          +    return _apply.applyPatches;
          +  }
          +});
          +Object.defineProperty(exports, "parsePatch", {
          +  enumerable: true,
          +  get: function get() {
          +    return _parse.parsePatch;
          +  }
          +});
          +Object.defineProperty(exports, "merge", {
          +  enumerable: true,
          +  get: function get() {
          +    return _merge.merge;
          +  }
          +});
          +Object.defineProperty(exports, "structuredPatch", {
          +  enumerable: true,
          +  get: function get() {
          +    return _create.structuredPatch;
          +  }
          +});
          +Object.defineProperty(exports, "createTwoFilesPatch", {
          +  enumerable: true,
          +  get: function get() {
          +    return _create.createTwoFilesPatch;
          +  }
          +});
          +Object.defineProperty(exports, "createPatch", {
          +  enumerable: true,
          +  get: function get() {
          +    return _create.createPatch;
          +  }
          +});
          +Object.defineProperty(exports, "convertChangesToDMP", {
          +  enumerable: true,
          +  get: function get() {
          +    return _dmp.convertChangesToDMP;
          +  }
          +});
          +Object.defineProperty(exports, "convertChangesToXML", {
          +  enumerable: true,
          +  get: function get() {
          +    return _xml.convertChangesToXML;
          +  }
          +});
          +
          +/*istanbul ignore end*/
          +var
          +/*istanbul ignore start*/
          +_base = _interopRequireDefault(require("./diff/base"))
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_character = require("./diff/character")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_word = require("./diff/word")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_line = require("./diff/line")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_sentence = require("./diff/sentence")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_css = require("./diff/css")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_json = require("./diff/json")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_array = require("./diff/array")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_apply = require("./patch/apply")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_parse = require("./patch/parse")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_merge = require("./patch/merge")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_create = require("./patch/create")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_dmp = require("./convert/dmp")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_xml = require("./convert/xml")
          +/*istanbul ignore end*/
          +;
          +
          +/*istanbul ignore start*/ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
          +
          +/*istanbul ignore end*/
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQWdCQTtBQUFBO0FBQUE7QUFBQTtBQUFBOztBQUNBO0FBQUE7QUFBQTtBQUFBO0FBQUE7O0FBQ0E7QUFBQTtBQUFBO0FBQUE7QUFBQTs7QUFDQTtBQUFBO0FBQUE7QUFBQTtBQUFBOztBQUNBO0FBQUE7QUFBQTtBQUFBO0FBQUE7O0FBRUE7QUFBQTtBQUFBO0FBQUE7QUFBQTs7QUFDQTtBQUFBO0FBQUE7QUFBQTtBQUFBOztBQUVBO0FBQUE7QUFBQTtBQUFBO0FBQUE7O0FBRUE7QUFBQTtBQUFBO0FBQUE7QUFBQTs7QUFDQTtBQUFBO0FBQUE7QUFBQTtBQUFBOztBQUNBO0FBQUE7QUFBQTtBQUFBO0FBQUE7O0FBQ0E7QUFBQTtBQUFBO0FBQUE7QUFBQTs7QUFFQTtBQUFBO0FBQUE7QUFBQTtBQUFBOztBQUNBO0FBQUE7QUFBQTtBQUFBO0FBQUEiLCJzb3VyY2VzQ29udGVudCI6WyIvKiBTZWUgTElDRU5TRSBmaWxlIGZvciB0ZXJtcyBvZiB1c2UgKi9cblxuLypcbiAqIFRleHQgZGlmZiBpbXBsZW1lbnRhdGlvbi5cbiAqXG4gKiBUaGlzIGxpYnJhcnkgc3VwcG9ydHMgdGhlIGZvbGxvd2luZyBBUElTOlxuICogSnNEaWZmLmRpZmZDaGFyczogQ2hhcmFjdGVyIGJ5IGNoYXJhY3RlciBkaWZmXG4gKiBKc0RpZmYuZGlmZldvcmRzOiBXb3JkIChhcyBkZWZpbmVkIGJ5IFxcYiByZWdleCkgZGlmZiB3aGljaCBpZ25vcmVzIHdoaXRlc3BhY2VcbiAqIEpzRGlmZi5kaWZmTGluZXM6IExpbmUgYmFzZWQgZGlmZlxuICpcbiAqIEpzRGlmZi5kaWZmQ3NzOiBEaWZmIHRhcmdldGVkIGF0IENTUyBjb250ZW50XG4gKlxuICogVGhlc2UgbWV0aG9kcyBhcmUgYmFzZWQgb24gdGhlIGltcGxlbWVudGF0aW9uIHByb3Bvc2VkIGluXG4gKiBcIkFuIE8oTkQpIERpZmZlcmVuY2UgQWxnb3JpdGhtIGFuZCBpdHMgVmFyaWF0aW9uc1wiIChNeWVycywgMTk4NikuXG4gKiBodHRwOi8vY2l0ZXNlZXJ4LmlzdC5wc3UuZWR1L3ZpZXdkb2Mvc3VtbWFyeT9kb2k9MTAuMS4xLjQuNjkyN1xuICovXG5pbXBvcnQgRGlmZiBmcm9tICcuL2RpZmYvYmFzZSc7XG5pbXBvcnQge2RpZmZDaGFyc30gZnJvbSAnLi9kaWZmL2NoYXJhY3Rlcic7XG5pbXBvcnQge2RpZmZXb3JkcywgZGlmZldvcmRzV2l0aFNwYWNlfSBmcm9tICcuL2RpZmYvd29yZCc7XG5pbXBvcnQge2RpZmZMaW5lcywgZGlmZlRyaW1tZWRMaW5lc30gZnJvbSAnLi9kaWZmL2xpbmUnO1xuaW1wb3J0IHtkaWZmU2VudGVuY2VzfSBmcm9tICcuL2RpZmYvc2VudGVuY2UnO1xuXG5pbXBvcnQge2RpZmZDc3N9IGZyb20gJy4vZGlmZi9jc3MnO1xuaW1wb3J0IHtkaWZmSnNvbiwgY2Fub25pY2FsaXplfSBmcm9tICcuL2RpZmYvanNvbic7XG5cbmltcG9ydCB7ZGlmZkFycmF5c30gZnJvbSAnLi9kaWZmL2FycmF5JztcblxuaW1wb3J0IHthcHBseVBhdGNoLCBhcHBseVBhdGNoZXN9IGZyb20gJy4vcGF0Y2gvYXBwbHknO1xuaW1wb3J0IHtwYXJzZVBhdGNofSBmcm9tICcuL3BhdGNoL3BhcnNlJztcbmltcG9ydCB7bWVyZ2V9IGZyb20gJy4vcGF0Y2gvbWVyZ2UnO1xuaW1wb3J0IHtzdHJ1Y3R1cmVkUGF0Y2gsIGNyZWF0ZVR3b0ZpbGVzUGF0Y2gsIGNyZWF0ZVBhdGNofSBmcm9tICcuL3BhdGNoL2NyZWF0ZSc7XG5cbmltcG9ydCB7Y29udmVydENoYW5nZXNUb0RNUH0gZnJvbSAnLi9jb252ZXJ0L2RtcCc7XG5pbXBvcnQge2NvbnZlcnRDaGFuZ2VzVG9YTUx9IGZyb20gJy4vY29udmVydC94bWwnO1xuXG5leHBvcnQge1xuICBEaWZmLFxuXG4gIGRpZmZDaGFycyxcbiAgZGlmZldvcmRzLFxuICBkaWZmV29yZHNXaXRoU3BhY2UsXG4gIGRpZmZMaW5lcyxcbiAgZGlmZlRyaW1tZWRMaW5lcyxcbiAgZGlmZlNlbnRlbmNlcyxcblxuICBkaWZmQ3NzLFxuICBkaWZmSnNvbixcblxuICBkaWZmQXJyYXlzLFxuXG4gIHN0cnVjdHVyZWRQYXRjaCxcbiAgY3JlYXRlVHdvRmlsZXNQYXRjaCxcbiAgY3JlYXRlUGF0Y2gsXG4gIGFwcGx5UGF0Y2gsXG4gIGFwcGx5UGF0Y2hlcyxcbiAgcGFyc2VQYXRjaCxcbiAgbWVyZ2UsXG4gIGNvbnZlcnRDaGFuZ2VzVG9ETVAsXG4gIGNvbnZlcnRDaGFuZ2VzVG9YTUwsXG4gIGNhbm9uaWNhbGl6ZVxufTtcbiJdfQ==
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/index.mjs b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/index.mjs
          new file mode 100644
          index 00000000000000..ca0e5917c44a4b
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/index.mjs
          @@ -0,0 +1,1553 @@
          +function Diff() {}
          +Diff.prototype = {
          +  diff: function diff(oldString, newString) {
          +    var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
          +    var callback = options.callback;
          +
          +    if (typeof options === 'function') {
          +      callback = options;
          +      options = {};
          +    }
          +
          +    this.options = options;
          +    var self = this;
          +
          +    function done(value) {
          +      if (callback) {
          +        setTimeout(function () {
          +          callback(undefined, value);
          +        }, 0);
          +        return true;
          +      } else {
          +        return value;
          +      }
          +    } // Allow subclasses to massage the input prior to running
          +
          +
          +    oldString = this.castInput(oldString);
          +    newString = this.castInput(newString);
          +    oldString = this.removeEmpty(this.tokenize(oldString));
          +    newString = this.removeEmpty(this.tokenize(newString));
          +    var newLen = newString.length,
          +        oldLen = oldString.length;
          +    var editLength = 1;
          +    var maxEditLength = newLen + oldLen;
          +    var bestPath = [{
          +      newPos: -1,
          +      components: []
          +    }]; // Seed editLength = 0, i.e. the content starts with the same values
          +
          +    var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
          +
          +    if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
          +      // Identity per the equality and tokenizer
          +      return done([{
          +        value: this.join(newString),
          +        count: newString.length
          +      }]);
          +    } // Main worker method. checks all permutations of a given edit length for acceptance.
          +
          +
          +    function execEditLength() {
          +      for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
          +        var basePath = void 0;
          +
          +        var addPath = bestPath[diagonalPath - 1],
          +            removePath = bestPath[diagonalPath + 1],
          +            _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
          +
          +        if (addPath) {
          +          // No one else is going to attempt to use this value, clear it
          +          bestPath[diagonalPath - 1] = undefined;
          +        }
          +
          +        var canAdd = addPath && addPath.newPos + 1 < newLen,
          +            canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
          +
          +        if (!canAdd && !canRemove) {
          +          // If this path is a terminal then prune
          +          bestPath[diagonalPath] = undefined;
          +          continue;
          +        } // Select the diagonal that we want to branch from. We select the prior
          +        // path whose position in the new string is the farthest from the origin
          +        // and does not pass the bounds of the diff graph
          +
          +
          +        if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
          +          basePath = clonePath(removePath);
          +          self.pushComponent(basePath.components, undefined, true);
          +        } else {
          +          basePath = addPath; // No need to clone, we've pulled it from the list
          +
          +          basePath.newPos++;
          +          self.pushComponent(basePath.components, true, undefined);
          +        }
          +
          +        _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
          +
          +        if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
          +          return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
          +        } else {
          +          // Otherwise track this path as a potential candidate and continue.
          +          bestPath[diagonalPath] = basePath;
          +        }
          +      }
          +
          +      editLength++;
          +    } // Performs the length of edit iteration. Is a bit fugly as this has to support the
          +    // sync and async mode which is never fun. Loops over execEditLength until a value
          +    // is produced.
          +
          +
          +    if (callback) {
          +      (function exec() {
          +        setTimeout(function () {
          +          // This should not happen, but we want to be safe.
          +
          +          /* istanbul ignore next */
          +          if (editLength > maxEditLength) {
          +            return callback();
          +          }
          +
          +          if (!execEditLength()) {
          +            exec();
          +          }
          +        }, 0);
          +      })();
          +    } else {
          +      while (editLength <= maxEditLength) {
          +        var ret = execEditLength();
          +
          +        if (ret) {
          +          return ret;
          +        }
          +      }
          +    }
          +  },
          +  pushComponent: function pushComponent(components, added, removed) {
          +    var last = components[components.length - 1];
          +
          +    if (last && last.added === added && last.removed === removed) {
          +      // We need to clone here as the component clone operation is just
          +      // as shallow array clone
          +      components[components.length - 1] = {
          +        count: last.count + 1,
          +        added: added,
          +        removed: removed
          +      };
          +    } else {
          +      components.push({
          +        count: 1,
          +        added: added,
          +        removed: removed
          +      });
          +    }
          +  },
          +  extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
          +    var newLen = newString.length,
          +        oldLen = oldString.length,
          +        newPos = basePath.newPos,
          +        oldPos = newPos - diagonalPath,
          +        commonCount = 0;
          +
          +    while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
          +      newPos++;
          +      oldPos++;
          +      commonCount++;
          +    }
          +
          +    if (commonCount) {
          +      basePath.components.push({
          +        count: commonCount
          +      });
          +    }
          +
          +    basePath.newPos = newPos;
          +    return oldPos;
          +  },
          +  equals: function equals(left, right) {
          +    if (this.options.comparator) {
          +      return this.options.comparator(left, right);
          +    } else {
          +      return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
          +    }
          +  },
          +  removeEmpty: function removeEmpty(array) {
          +    var ret = [];
          +
          +    for (var i = 0; i < array.length; i++) {
          +      if (array[i]) {
          +        ret.push(array[i]);
          +      }
          +    }
          +
          +    return ret;
          +  },
          +  castInput: function castInput(value) {
          +    return value;
          +  },
          +  tokenize: function tokenize(value) {
          +    return value.split('');
          +  },
          +  join: function join(chars) {
          +    return chars.join('');
          +  }
          +};
          +
          +function buildValues(diff, components, newString, oldString, useLongestToken) {
          +  var componentPos = 0,
          +      componentLen = components.length,
          +      newPos = 0,
          +      oldPos = 0;
          +
          +  for (; componentPos < componentLen; componentPos++) {
          +    var component = components[componentPos];
          +
          +    if (!component.removed) {
          +      if (!component.added && useLongestToken) {
          +        var value = newString.slice(newPos, newPos + component.count);
          +        value = value.map(function (value, i) {
          +          var oldValue = oldString[oldPos + i];
          +          return oldValue.length > value.length ? oldValue : value;
          +        });
          +        component.value = diff.join(value);
          +      } else {
          +        component.value = diff.join(newString.slice(newPos, newPos + component.count));
          +      }
          +
          +      newPos += component.count; // Common case
          +
          +      if (!component.added) {
          +        oldPos += component.count;
          +      }
          +    } else {
          +      component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
          +      oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
          +      // The diffing algorithm is tied to add then remove output and this is the simplest
          +      // route to get the desired output with minimal overhead.
          +
          +      if (componentPos && components[componentPos - 1].added) {
          +        var tmp = components[componentPos - 1];
          +        components[componentPos - 1] = components[componentPos];
          +        components[componentPos] = tmp;
          +      }
          +    }
          +  } // Special case handle for when one terminal is ignored (i.e. whitespace).
          +  // For this case we merge the terminal into the prior string and drop the change.
          +  // This is only available for string mode.
          +
          +
          +  var lastComponent = components[componentLen - 1];
          +
          +  if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
          +    components[componentLen - 2].value += lastComponent.value;
          +    components.pop();
          +  }
          +
          +  return components;
          +}
          +
          +function clonePath(path) {
          +  return {
          +    newPos: path.newPos,
          +    components: path.components.slice(0)
          +  };
          +}
          +
          +var characterDiff = new Diff();
          +function diffChars(oldStr, newStr, options) {
          +  return characterDiff.diff(oldStr, newStr, options);
          +}
          +
          +function generateOptions(options, defaults) {
          +  if (typeof options === 'function') {
          +    defaults.callback = options;
          +  } else if (options) {
          +    for (var name in options) {
          +      /* istanbul ignore else */
          +      if (options.hasOwnProperty(name)) {
          +        defaults[name] = options[name];
          +      }
          +    }
          +  }
          +
          +  return defaults;
          +}
          +
          +//
          +// Ranges and exceptions:
          +// Latin-1 Supplement, 0080–00FF
          +//  - U+00D7  × Multiplication sign
          +//  - U+00F7  ÷ Division sign
          +// Latin Extended-A, 0100–017F
          +// Latin Extended-B, 0180–024F
          +// IPA Extensions, 0250–02AF
          +// Spacing Modifier Letters, 02B0–02FF
          +//  - U+02C7  ˇ ˇ  Caron
          +//  - U+02D8  ˘ ˘  Breve
          +//  - U+02D9  ˙ ˙  Dot Above
          +//  - U+02DA  ˚ ˚  Ring Above
          +//  - U+02DB  ˛ ˛  Ogonek
          +//  - U+02DC  ˜ ˜  Small Tilde
          +//  - U+02DD  ˝ ˝  Double Acute Accent
          +// Latin Extended Additional, 1E00–1EFF
          +
          +var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
          +var reWhitespace = /\S/;
          +var wordDiff = new Diff();
          +
          +wordDiff.equals = function (left, right) {
          +  if (this.options.ignoreCase) {
          +    left = left.toLowerCase();
          +    right = right.toLowerCase();
          +  }
          +
          +  return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
          +};
          +
          +wordDiff.tokenize = function (value) {
          +  // All whitespace symbols except newline group into one token, each newline - in separate token
          +  var tokens = value.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/); // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
          +
          +  for (var i = 0; i < tokens.length - 1; i++) {
          +    // If we have an empty string in the next field and we have only word chars before and after, merge
          +    if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
          +      tokens[i] += tokens[i + 2];
          +      tokens.splice(i + 1, 2);
          +      i--;
          +    }
          +  }
          +
          +  return tokens;
          +};
          +
          +function diffWords(oldStr, newStr, options) {
          +  options = generateOptions(options, {
          +    ignoreWhitespace: true
          +  });
          +  return wordDiff.diff(oldStr, newStr, options);
          +}
          +function diffWordsWithSpace(oldStr, newStr, options) {
          +  return wordDiff.diff(oldStr, newStr, options);
          +}
          +
          +var lineDiff = new Diff();
          +
          +lineDiff.tokenize = function (value) {
          +  var retLines = [],
          +      linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
          +
          +  if (!linesAndNewlines[linesAndNewlines.length - 1]) {
          +    linesAndNewlines.pop();
          +  } // Merge the content and line separators into single tokens
          +
          +
          +  for (var i = 0; i < linesAndNewlines.length; i++) {
          +    var line = linesAndNewlines[i];
          +
          +    if (i % 2 && !this.options.newlineIsToken) {
          +      retLines[retLines.length - 1] += line;
          +    } else {
          +      if (this.options.ignoreWhitespace) {
          +        line = line.trim();
          +      }
          +
          +      retLines.push(line);
          +    }
          +  }
          +
          +  return retLines;
          +};
          +
          +function diffLines(oldStr, newStr, callback) {
          +  return lineDiff.diff(oldStr, newStr, callback);
          +}
          +function diffTrimmedLines(oldStr, newStr, callback) {
          +  var options = generateOptions(callback, {
          +    ignoreWhitespace: true
          +  });
          +  return lineDiff.diff(oldStr, newStr, options);
          +}
          +
          +var sentenceDiff = new Diff();
          +
          +sentenceDiff.tokenize = function (value) {
          +  return value.split(/(\S.+?[.!?])(?=\s+|$)/);
          +};
          +
          +function diffSentences(oldStr, newStr, callback) {
          +  return sentenceDiff.diff(oldStr, newStr, callback);
          +}
          +
          +var cssDiff = new Diff();
          +
          +cssDiff.tokenize = function (value) {
          +  return value.split(/([{}:;,]|\s+)/);
          +};
          +
          +function diffCss(oldStr, newStr, callback) {
          +  return cssDiff.diff(oldStr, newStr, callback);
          +}
          +
          +function _typeof(obj) {
          +  "@babel/helpers - typeof";
          +
          +  if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
          +    _typeof = function (obj) {
          +      return typeof obj;
          +    };
          +  } else {
          +    _typeof = function (obj) {
          +      return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
          +    };
          +  }
          +
          +  return _typeof(obj);
          +}
          +
          +function _toConsumableArray(arr) {
          +  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
          +}
          +
          +function _arrayWithoutHoles(arr) {
          +  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
          +}
          +
          +function _iterableToArray(iter) {
          +  if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
          +}
          +
          +function _unsupportedIterableToArray(o, minLen) {
          +  if (!o) return;
          +  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
          +  var n = Object.prototype.toString.call(o).slice(8, -1);
          +  if (n === "Object" && o.constructor) n = o.constructor.name;
          +  if (n === "Map" || n === "Set") return Array.from(o);
          +  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
          +}
          +
          +function _arrayLikeToArray(arr, len) {
          +  if (len == null || len > arr.length) len = arr.length;
          +
          +  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
          +
          +  return arr2;
          +}
          +
          +function _nonIterableSpread() {
          +  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
          +}
          +
          +var objectPrototypeToString = Object.prototype.toString;
          +var jsonDiff = new Diff(); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
          +// dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
          +
          +jsonDiff.useLongestToken = true;
          +jsonDiff.tokenize = lineDiff.tokenize;
          +
          +jsonDiff.castInput = function (value) {
          +  var _this$options = this.options,
          +      undefinedReplacement = _this$options.undefinedReplacement,
          +      _this$options$stringi = _this$options.stringifyReplacer,
          +      stringifyReplacer = _this$options$stringi === void 0 ? function (k, v) {
          +    return typeof v === 'undefined' ? undefinedReplacement : v;
          +  } : _this$options$stringi;
          +  return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, '  ');
          +};
          +
          +jsonDiff.equals = function (left, right) {
          +  return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
          +};
          +
          +function diffJson(oldObj, newObj, options) {
          +  return jsonDiff.diff(oldObj, newObj, options);
          +} // This function handles the presence of circular references by bailing out when encountering an
          +// object that is already on the "stack" of items being processed. Accepts an optional replacer
          +
          +function canonicalize(obj, stack, replacementStack, replacer, key) {
          +  stack = stack || [];
          +  replacementStack = replacementStack || [];
          +
          +  if (replacer) {
          +    obj = replacer(key, obj);
          +  }
          +
          +  var i;
          +
          +  for (i = 0; i < stack.length; i += 1) {
          +    if (stack[i] === obj) {
          +      return replacementStack[i];
          +    }
          +  }
          +
          +  var canonicalizedObj;
          +
          +  if ('[object Array]' === objectPrototypeToString.call(obj)) {
          +    stack.push(obj);
          +    canonicalizedObj = new Array(obj.length);
          +    replacementStack.push(canonicalizedObj);
          +
          +    for (i = 0; i < obj.length; i += 1) {
          +      canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
          +    }
          +
          +    stack.pop();
          +    replacementStack.pop();
          +    return canonicalizedObj;
          +  }
          +
          +  if (obj && obj.toJSON) {
          +    obj = obj.toJSON();
          +  }
          +
          +  if (_typeof(obj) === 'object' && obj !== null) {
          +    stack.push(obj);
          +    canonicalizedObj = {};
          +    replacementStack.push(canonicalizedObj);
          +
          +    var sortedKeys = [],
          +        _key;
          +
          +    for (_key in obj) {
          +      /* istanbul ignore else */
          +      if (obj.hasOwnProperty(_key)) {
          +        sortedKeys.push(_key);
          +      }
          +    }
          +
          +    sortedKeys.sort();
          +
          +    for (i = 0; i < sortedKeys.length; i += 1) {
          +      _key = sortedKeys[i];
          +      canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
          +    }
          +
          +    stack.pop();
          +    replacementStack.pop();
          +  } else {
          +    canonicalizedObj = obj;
          +  }
          +
          +  return canonicalizedObj;
          +}
          +
          +var arrayDiff = new Diff();
          +
          +arrayDiff.tokenize = function (value) {
          +  return value.slice();
          +};
          +
          +arrayDiff.join = arrayDiff.removeEmpty = function (value) {
          +  return value;
          +};
          +
          +function diffArrays(oldArr, newArr, callback) {
          +  return arrayDiff.diff(oldArr, newArr, callback);
          +}
          +
          +function parsePatch(uniDiff) {
          +  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
          +  var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
          +      delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
          +      list = [],
          +      i = 0;
          +
          +  function parseIndex() {
          +    var index = {};
          +    list.push(index); // Parse diff metadata
          +
          +    while (i < diffstr.length) {
          +      var line = diffstr[i]; // File header found, end parsing diff metadata
          +
          +      if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
          +        break;
          +      } // Diff index
          +
          +
          +      var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
          +
          +      if (header) {
          +        index.index = header[1];
          +      }
          +
          +      i++;
          +    } // Parse file headers if they are defined. Unified diff requires them, but
          +    // there's no technical issues to have an isolated hunk without file header
          +
          +
          +    parseFileHeader(index);
          +    parseFileHeader(index); // Parse hunks
          +
          +    index.hunks = [];
          +
          +    while (i < diffstr.length) {
          +      var _line = diffstr[i];
          +
          +      if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
          +        break;
          +      } else if (/^@@/.test(_line)) {
          +        index.hunks.push(parseHunk());
          +      } else if (_line && options.strict) {
          +        // Ignore unexpected content unless in strict mode
          +        throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
          +      } else {
          +        i++;
          +      }
          +    }
          +  } // Parses the --- and +++ headers, if none are found, no lines
          +  // are consumed.
          +
          +
          +  function parseFileHeader(index) {
          +    var fileHeader = /^(---|\+\+\+)\s+(.*)$/.exec(diffstr[i]);
          +
          +    if (fileHeader) {
          +      var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
          +      var data = fileHeader[2].split('\t', 2);
          +      var fileName = data[0].replace(/\\\\/g, '\\');
          +
          +      if (/^".*"$/.test(fileName)) {
          +        fileName = fileName.substr(1, fileName.length - 2);
          +      }
          +
          +      index[keyPrefix + 'FileName'] = fileName;
          +      index[keyPrefix + 'Header'] = (data[1] || '').trim();
          +      i++;
          +    }
          +  } // Parses a hunk
          +  // This assumes that we are at the start of a hunk.
          +
          +
          +  function parseHunk() {
          +    var chunkHeaderIndex = i,
          +        chunkHeaderLine = diffstr[i++],
          +        chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
          +    var hunk = {
          +      oldStart: +chunkHeader[1],
          +      oldLines: typeof chunkHeader[2] === 'undefined' ? 1 : +chunkHeader[2],
          +      newStart: +chunkHeader[3],
          +      newLines: typeof chunkHeader[4] === 'undefined' ? 1 : +chunkHeader[4],
          +      lines: [],
          +      linedelimiters: []
          +    }; // Unified Diff Format quirk: If the chunk size is 0,
          +    // the first number is one lower than one would expect.
          +    // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
          +
          +    if (hunk.oldLines === 0) {
          +      hunk.oldStart += 1;
          +    }
          +
          +    if (hunk.newLines === 0) {
          +      hunk.newStart += 1;
          +    }
          +
          +    var addCount = 0,
          +        removeCount = 0;
          +
          +    for (; i < diffstr.length; i++) {
          +      // Lines starting with '---' could be mistaken for the "remove line" operation
          +      // But they could be the header for the next file. Therefore prune such cases out.
          +      if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
          +        break;
          +      }
          +
          +      var operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? ' ' : diffstr[i][0];
          +
          +      if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
          +        hunk.lines.push(diffstr[i]);
          +        hunk.linedelimiters.push(delimiters[i] || '\n');
          +
          +        if (operation === '+') {
          +          addCount++;
          +        } else if (operation === '-') {
          +          removeCount++;
          +        } else if (operation === ' ') {
          +          addCount++;
          +          removeCount++;
          +        }
          +      } else {
          +        break;
          +      }
          +    } // Handle the empty block count case
          +
          +
          +    if (!addCount && hunk.newLines === 1) {
          +      hunk.newLines = 0;
          +    }
          +
          +    if (!removeCount && hunk.oldLines === 1) {
          +      hunk.oldLines = 0;
          +    } // Perform optional sanity checking
          +
          +
          +    if (options.strict) {
          +      if (addCount !== hunk.newLines) {
          +        throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
          +      }
          +
          +      if (removeCount !== hunk.oldLines) {
          +        throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
          +      }
          +    }
          +
          +    return hunk;
          +  }
          +
          +  while (i < diffstr.length) {
          +    parseIndex();
          +  }
          +
          +  return list;
          +}
          +
          +// Iterator that traverses in the range of [min, max], stepping
          +// by distance from a given start position. I.e. for [0, 4], with
          +// start of 2, this will iterate 2, 3, 1, 4, 0.
          +function distanceIterator (start, minLine, maxLine) {
          +  var wantForward = true,
          +      backwardExhausted = false,
          +      forwardExhausted = false,
          +      localOffset = 1;
          +  return function iterator() {
          +    if (wantForward && !forwardExhausted) {
          +      if (backwardExhausted) {
          +        localOffset++;
          +      } else {
          +        wantForward = false;
          +      } // Check if trying to fit beyond text length, and if not, check it fits
          +      // after offset location (or desired location on first iteration)
          +
          +
          +      if (start + localOffset <= maxLine) {
          +        return localOffset;
          +      }
          +
          +      forwardExhausted = true;
          +    }
          +
          +    if (!backwardExhausted) {
          +      if (!forwardExhausted) {
          +        wantForward = true;
          +      } // Check if trying to fit before text beginning, and if not, check it fits
          +      // before offset location
          +
          +
          +      if (minLine <= start - localOffset) {
          +        return -localOffset++;
          +      }
          +
          +      backwardExhausted = true;
          +      return iterator();
          +    } // We tried to fit hunk before text beginning and beyond text length, then
          +    // hunk can't fit on the text. Return undefined
          +
          +  };
          +}
          +
          +function applyPatch(source, uniDiff) {
          +  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
          +
          +  if (typeof uniDiff === 'string') {
          +    uniDiff = parsePatch(uniDiff);
          +  }
          +
          +  if (Array.isArray(uniDiff)) {
          +    if (uniDiff.length > 1) {
          +      throw new Error('applyPatch only works with a single input.');
          +    }
          +
          +    uniDiff = uniDiff[0];
          +  } // Apply the diff to the input
          +
          +
          +  var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
          +      delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
          +      hunks = uniDiff.hunks,
          +      compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) {
          +    return line === patchContent;
          +  },
          +      errorCount = 0,
          +      fuzzFactor = options.fuzzFactor || 0,
          +      minLine = 0,
          +      offset = 0,
          +      removeEOFNL,
          +      addEOFNL;
          +  /**
          +   * Checks if the hunk exactly fits on the provided location
          +   */
          +
          +
          +  function hunkFits(hunk, toPos) {
          +    for (var j = 0; j < hunk.lines.length; j++) {
          +      var line = hunk.lines[j],
          +          operation = line.length > 0 ? line[0] : ' ',
          +          content = line.length > 0 ? line.substr(1) : line;
          +
          +      if (operation === ' ' || operation === '-') {
          +        // Context sanity check
          +        if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
          +          errorCount++;
          +
          +          if (errorCount > fuzzFactor) {
          +            return false;
          +          }
          +        }
          +
          +        toPos++;
          +      }
          +    }
          +
          +    return true;
          +  } // Search best fit offsets for each hunk based on the previous ones
          +
          +
          +  for (var i = 0; i < hunks.length; i++) {
          +    var hunk = hunks[i],
          +        maxLine = lines.length - hunk.oldLines,
          +        localOffset = 0,
          +        toPos = offset + hunk.oldStart - 1;
          +    var iterator = distanceIterator(toPos, minLine, maxLine);
          +
          +    for (; localOffset !== undefined; localOffset = iterator()) {
          +      if (hunkFits(hunk, toPos + localOffset)) {
          +        hunk.offset = offset += localOffset;
          +        break;
          +      }
          +    }
          +
          +    if (localOffset === undefined) {
          +      return false;
          +    } // Set lower text limit to end of the current hunk, so next ones don't try
          +    // to fit over already patched text
          +
          +
          +    minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
          +  } // Apply patch hunks
          +
          +
          +  var diffOffset = 0;
          +
          +  for (var _i = 0; _i < hunks.length; _i++) {
          +    var _hunk = hunks[_i],
          +        _toPos = _hunk.oldStart + _hunk.offset + diffOffset - 1;
          +
          +    diffOffset += _hunk.newLines - _hunk.oldLines;
          +
          +    for (var j = 0; j < _hunk.lines.length; j++) {
          +      var line = _hunk.lines[j],
          +          operation = line.length > 0 ? line[0] : ' ',
          +          content = line.length > 0 ? line.substr(1) : line,
          +          delimiter = _hunk.linedelimiters[j];
          +
          +      if (operation === ' ') {
          +        _toPos++;
          +      } else if (operation === '-') {
          +        lines.splice(_toPos, 1);
          +        delimiters.splice(_toPos, 1);
          +        /* istanbul ignore else */
          +      } else if (operation === '+') {
          +        lines.splice(_toPos, 0, content);
          +        delimiters.splice(_toPos, 0, delimiter);
          +        _toPos++;
          +      } else if (operation === '\\') {
          +        var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
          +
          +        if (previousOperation === '+') {
          +          removeEOFNL = true;
          +        } else if (previousOperation === '-') {
          +          addEOFNL = true;
          +        }
          +      }
          +    }
          +  } // Handle EOFNL insertion/removal
          +
          +
          +  if (removeEOFNL) {
          +    while (!lines[lines.length - 1]) {
          +      lines.pop();
          +      delimiters.pop();
          +    }
          +  } else if (addEOFNL) {
          +    lines.push('');
          +    delimiters.push('\n');
          +  }
          +
          +  for (var _k = 0; _k < lines.length - 1; _k++) {
          +    lines[_k] = lines[_k] + delimiters[_k];
          +  }
          +
          +  return lines.join('');
          +} // Wrapper that supports multiple file patches via callbacks.
          +
          +function applyPatches(uniDiff, options) {
          +  if (typeof uniDiff === 'string') {
          +    uniDiff = parsePatch(uniDiff);
          +  }
          +
          +  var currentIndex = 0;
          +
          +  function processIndex() {
          +    var index = uniDiff[currentIndex++];
          +
          +    if (!index) {
          +      return options.complete();
          +    }
          +
          +    options.loadFile(index, function (err, data) {
          +      if (err) {
          +        return options.complete(err);
          +      }
          +
          +      var updatedContent = applyPatch(data, index, options);
          +      options.patched(index, updatedContent, function (err) {
          +        if (err) {
          +          return options.complete(err);
          +        }
          +
          +        processIndex();
          +      });
          +    });
          +  }
          +
          +  processIndex();
          +}
          +
          +function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
          +  if (!options) {
          +    options = {};
          +  }
          +
          +  if (typeof options.context === 'undefined') {
          +    options.context = 4;
          +  }
          +
          +  var diff = diffLines(oldStr, newStr, options);
          +  diff.push({
          +    value: '',
          +    lines: []
          +  }); // Append an empty value to make cleanup easier
          +
          +  function contextLines(lines) {
          +    return lines.map(function (entry) {
          +      return ' ' + entry;
          +    });
          +  }
          +
          +  var hunks = [];
          +  var oldRangeStart = 0,
          +      newRangeStart = 0,
          +      curRange = [],
          +      oldLine = 1,
          +      newLine = 1;
          +
          +  var _loop = function _loop(i) {
          +    var current = diff[i],
          +        lines = current.lines || current.value.replace(/\n$/, '').split('\n');
          +    current.lines = lines;
          +
          +    if (current.added || current.removed) {
          +      var _curRange;
          +
          +      // If we have previous context, start with that
          +      if (!oldRangeStart) {
          +        var prev = diff[i - 1];
          +        oldRangeStart = oldLine;
          +        newRangeStart = newLine;
          +
          +        if (prev) {
          +          curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
          +          oldRangeStart -= curRange.length;
          +          newRangeStart -= curRange.length;
          +        }
          +      } // Output our changes
          +
          +
          +      (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
          +        return (current.added ? '+' : '-') + entry;
          +      }))); // Track the updated file position
          +
          +
          +      if (current.added) {
          +        newLine += lines.length;
          +      } else {
          +        oldLine += lines.length;
          +      }
          +    } else {
          +      // Identical context lines. Track line changes
          +      if (oldRangeStart) {
          +        // Close out any changes that have been output (or join overlapping)
          +        if (lines.length <= options.context * 2 && i < diff.length - 2) {
          +          var _curRange2;
          +
          +          // Overlapping
          +          (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
          +        } else {
          +          var _curRange3;
          +
          +          // end the range and output
          +          var contextSize = Math.min(lines.length, options.context);
          +
          +          (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
          +
          +          var hunk = {
          +            oldStart: oldRangeStart,
          +            oldLines: oldLine - oldRangeStart + contextSize,
          +            newStart: newRangeStart,
          +            newLines: newLine - newRangeStart + contextSize,
          +            lines: curRange
          +          };
          +
          +          if (i >= diff.length - 2 && lines.length <= options.context) {
          +            // EOF is inside this hunk
          +            var oldEOFNewline = /\n$/.test(oldStr);
          +            var newEOFNewline = /\n$/.test(newStr);
          +            var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
          +
          +            if (!oldEOFNewline && noNlBeforeAdds && oldStr.length > 0) {
          +              // special case: old has no eol and no trailing context; no-nl can end up before adds
          +              // however, if the old file is empty, do not output the no-nl line
          +              curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
          +            }
          +
          +            if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
          +              curRange.push('\\ No newline at end of file');
          +            }
          +          }
          +
          +          hunks.push(hunk);
          +          oldRangeStart = 0;
          +          newRangeStart = 0;
          +          curRange = [];
          +        }
          +      }
          +
          +      oldLine += lines.length;
          +      newLine += lines.length;
          +    }
          +  };
          +
          +  for (var i = 0; i < diff.length; i++) {
          +    _loop(i);
          +  }
          +
          +  return {
          +    oldFileName: oldFileName,
          +    newFileName: newFileName,
          +    oldHeader: oldHeader,
          +    newHeader: newHeader,
          +    hunks: hunks
          +  };
          +}
          +function formatPatch(diff) {
          +  var ret = [];
          +
          +  if (diff.oldFileName == diff.newFileName) {
          +    ret.push('Index: ' + diff.oldFileName);
          +  }
          +
          +  ret.push('===================================================================');
          +  ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
          +  ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
          +
          +  for (var i = 0; i < diff.hunks.length; i++) {
          +    var hunk = diff.hunks[i]; // Unified Diff Format quirk: If the chunk size is 0,
          +    // the first number is one lower than one would expect.
          +    // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
          +
          +    if (hunk.oldLines === 0) {
          +      hunk.oldStart -= 1;
          +    }
          +
          +    if (hunk.newLines === 0) {
          +      hunk.newStart -= 1;
          +    }
          +
          +    ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
          +    ret.push.apply(ret, hunk.lines);
          +  }
          +
          +  return ret.join('\n') + '\n';
          +}
          +function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
          +  return formatPatch(structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options));
          +}
          +function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
          +  return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
          +}
          +
          +function arrayEqual(a, b) {
          +  if (a.length !== b.length) {
          +    return false;
          +  }
          +
          +  return arrayStartsWith(a, b);
          +}
          +function arrayStartsWith(array, start) {
          +  if (start.length > array.length) {
          +    return false;
          +  }
          +
          +  for (var i = 0; i < start.length; i++) {
          +    if (start[i] !== array[i]) {
          +      return false;
          +    }
          +  }
          +
          +  return true;
          +}
          +
          +function calcLineCount(hunk) {
          +  var _calcOldNewLineCount = calcOldNewLineCount(hunk.lines),
          +      oldLines = _calcOldNewLineCount.oldLines,
          +      newLines = _calcOldNewLineCount.newLines;
          +
          +  if (oldLines !== undefined) {
          +    hunk.oldLines = oldLines;
          +  } else {
          +    delete hunk.oldLines;
          +  }
          +
          +  if (newLines !== undefined) {
          +    hunk.newLines = newLines;
          +  } else {
          +    delete hunk.newLines;
          +  }
          +}
          +function merge(mine, theirs, base) {
          +  mine = loadPatch(mine, base);
          +  theirs = loadPatch(theirs, base);
          +  var ret = {}; // For index we just let it pass through as it doesn't have any necessary meaning.
          +  // Leaving sanity checks on this to the API consumer that may know more about the
          +  // meaning in their own context.
          +
          +  if (mine.index || theirs.index) {
          +    ret.index = mine.index || theirs.index;
          +  }
          +
          +  if (mine.newFileName || theirs.newFileName) {
          +    if (!fileNameChanged(mine)) {
          +      // No header or no change in ours, use theirs (and ours if theirs does not exist)
          +      ret.oldFileName = theirs.oldFileName || mine.oldFileName;
          +      ret.newFileName = theirs.newFileName || mine.newFileName;
          +      ret.oldHeader = theirs.oldHeader || mine.oldHeader;
          +      ret.newHeader = theirs.newHeader || mine.newHeader;
          +    } else if (!fileNameChanged(theirs)) {
          +      // No header or no change in theirs, use ours
          +      ret.oldFileName = mine.oldFileName;
          +      ret.newFileName = mine.newFileName;
          +      ret.oldHeader = mine.oldHeader;
          +      ret.newHeader = mine.newHeader;
          +    } else {
          +      // Both changed... figure it out
          +      ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
          +      ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
          +      ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
          +      ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
          +    }
          +  }
          +
          +  ret.hunks = [];
          +  var mineIndex = 0,
          +      theirsIndex = 0,
          +      mineOffset = 0,
          +      theirsOffset = 0;
          +
          +  while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
          +    var mineCurrent = mine.hunks[mineIndex] || {
          +      oldStart: Infinity
          +    },
          +        theirsCurrent = theirs.hunks[theirsIndex] || {
          +      oldStart: Infinity
          +    };
          +
          +    if (hunkBefore(mineCurrent, theirsCurrent)) {
          +      // This patch does not overlap with any of the others, yay.
          +      ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
          +      mineIndex++;
          +      theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
          +    } else if (hunkBefore(theirsCurrent, mineCurrent)) {
          +      // This patch does not overlap with any of the others, yay.
          +      ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
          +      theirsIndex++;
          +      mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
          +    } else {
          +      // Overlap, merge as best we can
          +      var mergedHunk = {
          +        oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
          +        oldLines: 0,
          +        newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
          +        newLines: 0,
          +        lines: []
          +      };
          +      mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
          +      theirsIndex++;
          +      mineIndex++;
          +      ret.hunks.push(mergedHunk);
          +    }
          +  }
          +
          +  return ret;
          +}
          +
          +function loadPatch(param, base) {
          +  if (typeof param === 'string') {
          +    if (/^@@/m.test(param) || /^Index:/m.test(param)) {
          +      return parsePatch(param)[0];
          +    }
          +
          +    if (!base) {
          +      throw new Error('Must provide a base reference or pass in a patch');
          +    }
          +
          +    return structuredPatch(undefined, undefined, base, param);
          +  }
          +
          +  return param;
          +}
          +
          +function fileNameChanged(patch) {
          +  return patch.newFileName && patch.newFileName !== patch.oldFileName;
          +}
          +
          +function selectField(index, mine, theirs) {
          +  if (mine === theirs) {
          +    return mine;
          +  } else {
          +    index.conflict = true;
          +    return {
          +      mine: mine,
          +      theirs: theirs
          +    };
          +  }
          +}
          +
          +function hunkBefore(test, check) {
          +  return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
          +}
          +
          +function cloneHunk(hunk, offset) {
          +  return {
          +    oldStart: hunk.oldStart,
          +    oldLines: hunk.oldLines,
          +    newStart: hunk.newStart + offset,
          +    newLines: hunk.newLines,
          +    lines: hunk.lines
          +  };
          +}
          +
          +function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
          +  // This will generally result in a conflicted hunk, but there are cases where the context
          +  // is the only overlap where we can successfully merge the content here.
          +  var mine = {
          +    offset: mineOffset,
          +    lines: mineLines,
          +    index: 0
          +  },
          +      their = {
          +    offset: theirOffset,
          +    lines: theirLines,
          +    index: 0
          +  }; // Handle any leading content
          +
          +  insertLeading(hunk, mine, their);
          +  insertLeading(hunk, their, mine); // Now in the overlap content. Scan through and select the best changes from each.
          +
          +  while (mine.index < mine.lines.length && their.index < their.lines.length) {
          +    var mineCurrent = mine.lines[mine.index],
          +        theirCurrent = their.lines[their.index];
          +
          +    if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
          +      // Both modified ...
          +      mutualChange(hunk, mine, their);
          +    } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
          +      var _hunk$lines;
          +
          +      // Mine inserted
          +      (_hunk$lines = hunk.lines).push.apply(_hunk$lines, _toConsumableArray(collectChange(mine)));
          +    } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
          +      var _hunk$lines2;
          +
          +      // Theirs inserted
          +      (_hunk$lines2 = hunk.lines).push.apply(_hunk$lines2, _toConsumableArray(collectChange(their)));
          +    } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
          +      // Mine removed or edited
          +      removal(hunk, mine, their);
          +    } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
          +      // Their removed or edited
          +      removal(hunk, their, mine, true);
          +    } else if (mineCurrent === theirCurrent) {
          +      // Context identity
          +      hunk.lines.push(mineCurrent);
          +      mine.index++;
          +      their.index++;
          +    } else {
          +      // Context mismatch
          +      conflict(hunk, collectChange(mine), collectChange(their));
          +    }
          +  } // Now push anything that may be remaining
          +
          +
          +  insertTrailing(hunk, mine);
          +  insertTrailing(hunk, their);
          +  calcLineCount(hunk);
          +}
          +
          +function mutualChange(hunk, mine, their) {
          +  var myChanges = collectChange(mine),
          +      theirChanges = collectChange(their);
          +
          +  if (allRemoves(myChanges) && allRemoves(theirChanges)) {
          +    // Special case for remove changes that are supersets of one another
          +    if (arrayStartsWith(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
          +      var _hunk$lines3;
          +
          +      (_hunk$lines3 = hunk.lines).push.apply(_hunk$lines3, _toConsumableArray(myChanges));
          +
          +      return;
          +    } else if (arrayStartsWith(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
          +      var _hunk$lines4;
          +
          +      (_hunk$lines4 = hunk.lines).push.apply(_hunk$lines4, _toConsumableArray(theirChanges));
          +
          +      return;
          +    }
          +  } else if (arrayEqual(myChanges, theirChanges)) {
          +    var _hunk$lines5;
          +
          +    (_hunk$lines5 = hunk.lines).push.apply(_hunk$lines5, _toConsumableArray(myChanges));
          +
          +    return;
          +  }
          +
          +  conflict(hunk, myChanges, theirChanges);
          +}
          +
          +function removal(hunk, mine, their, swap) {
          +  var myChanges = collectChange(mine),
          +      theirChanges = collectContext(their, myChanges);
          +
          +  if (theirChanges.merged) {
          +    var _hunk$lines6;
          +
          +    (_hunk$lines6 = hunk.lines).push.apply(_hunk$lines6, _toConsumableArray(theirChanges.merged));
          +  } else {
          +    conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
          +  }
          +}
          +
          +function conflict(hunk, mine, their) {
          +  hunk.conflict = true;
          +  hunk.lines.push({
          +    conflict: true,
          +    mine: mine,
          +    theirs: their
          +  });
          +}
          +
          +function insertLeading(hunk, insert, their) {
          +  while (insert.offset < their.offset && insert.index < insert.lines.length) {
          +    var line = insert.lines[insert.index++];
          +    hunk.lines.push(line);
          +    insert.offset++;
          +  }
          +}
          +
          +function insertTrailing(hunk, insert) {
          +  while (insert.index < insert.lines.length) {
          +    var line = insert.lines[insert.index++];
          +    hunk.lines.push(line);
          +  }
          +}
          +
          +function collectChange(state) {
          +  var ret = [],
          +      operation = state.lines[state.index][0];
          +
          +  while (state.index < state.lines.length) {
          +    var line = state.lines[state.index]; // Group additions that are immediately after subtractions and treat them as one "atomic" modify change.
          +
          +    if (operation === '-' && line[0] === '+') {
          +      operation = '+';
          +    }
          +
          +    if (operation === line[0]) {
          +      ret.push(line);
          +      state.index++;
          +    } else {
          +      break;
          +    }
          +  }
          +
          +  return ret;
          +}
          +
          +function collectContext(state, matchChanges) {
          +  var changes = [],
          +      merged = [],
          +      matchIndex = 0,
          +      contextChanges = false,
          +      conflicted = false;
          +
          +  while (matchIndex < matchChanges.length && state.index < state.lines.length) {
          +    var change = state.lines[state.index],
          +        match = matchChanges[matchIndex]; // Once we've hit our add, then we are done
          +
          +    if (match[0] === '+') {
          +      break;
          +    }
          +
          +    contextChanges = contextChanges || change[0] !== ' ';
          +    merged.push(match);
          +    matchIndex++; // Consume any additions in the other block as a conflict to attempt
          +    // to pull in the remaining context after this
          +
          +    if (change[0] === '+') {
          +      conflicted = true;
          +
          +      while (change[0] === '+') {
          +        changes.push(change);
          +        change = state.lines[++state.index];
          +      }
          +    }
          +
          +    if (match.substr(1) === change.substr(1)) {
          +      changes.push(change);
          +      state.index++;
          +    } else {
          +      conflicted = true;
          +    }
          +  }
          +
          +  if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
          +    conflicted = true;
          +  }
          +
          +  if (conflicted) {
          +    return changes;
          +  }
          +
          +  while (matchIndex < matchChanges.length) {
          +    merged.push(matchChanges[matchIndex++]);
          +  }
          +
          +  return {
          +    merged: merged,
          +    changes: changes
          +  };
          +}
          +
          +function allRemoves(changes) {
          +  return changes.reduce(function (prev, change) {
          +    return prev && change[0] === '-';
          +  }, true);
          +}
          +
          +function skipRemoveSuperset(state, removeChanges, delta) {
          +  for (var i = 0; i < delta; i++) {
          +    var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
          +
          +    if (state.lines[state.index + i] !== ' ' + changeContent) {
          +      return false;
          +    }
          +  }
          +
          +  state.index += delta;
          +  return true;
          +}
          +
          +function calcOldNewLineCount(lines) {
          +  var oldLines = 0;
          +  var newLines = 0;
          +  lines.forEach(function (line) {
          +    if (typeof line !== 'string') {
          +      var myCount = calcOldNewLineCount(line.mine);
          +      var theirCount = calcOldNewLineCount(line.theirs);
          +
          +      if (oldLines !== undefined) {
          +        if (myCount.oldLines === theirCount.oldLines) {
          +          oldLines += myCount.oldLines;
          +        } else {
          +          oldLines = undefined;
          +        }
          +      }
          +
          +      if (newLines !== undefined) {
          +        if (myCount.newLines === theirCount.newLines) {
          +          newLines += myCount.newLines;
          +        } else {
          +          newLines = undefined;
          +        }
          +      }
          +    } else {
          +      if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) {
          +        newLines++;
          +      }
          +
          +      if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) {
          +        oldLines++;
          +      }
          +    }
          +  });
          +  return {
          +    oldLines: oldLines,
          +    newLines: newLines
          +  };
          +}
          +
          +// See: http://code.google.com/p/google-diff-match-patch/wiki/API
          +function convertChangesToDMP(changes) {
          +  var ret = [],
          +      change,
          +      operation;
          +
          +  for (var i = 0; i < changes.length; i++) {
          +    change = changes[i];
          +
          +    if (change.added) {
          +      operation = 1;
          +    } else if (change.removed) {
          +      operation = -1;
          +    } else {
          +      operation = 0;
          +    }
          +
          +    ret.push([operation, change.value]);
          +  }
          +
          +  return ret;
          +}
          +
          +function convertChangesToXML(changes) {
          +  var ret = [];
          +
          +  for (var i = 0; i < changes.length; i++) {
          +    var change = changes[i];
          +
          +    if (change.added) {
          +      ret.push('');
          +    } else if (change.removed) {
          +      ret.push('');
          +    }
          +
          +    ret.push(escapeHTML(change.value));
          +
          +    if (change.added) {
          +      ret.push('');
          +    } else if (change.removed) {
          +      ret.push('');
          +    }
          +  }
          +
          +  return ret.join('');
          +}
          +
          +function escapeHTML(s) {
          +  var n = s;
          +  n = n.replace(/&/g, '&');
          +  n = n.replace(//g, '>');
          +  n = n.replace(/"/g, '"');
          +  return n;
          +}
          +
          +export { Diff, applyPatch, applyPatches, canonicalize, convertChangesToDMP, convertChangesToXML, createPatch, createTwoFilesPatch, diffArrays, diffChars, diffCss, diffJson, diffLines, diffSentences, diffTrimmedLines, diffWords, diffWordsWithSpace, merge, parsePatch, structuredPatch };
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/patch/apply.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/patch/apply.js
          new file mode 100644
          index 00000000000000..21c76ddb76ba78
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/patch/apply.js
          @@ -0,0 +1,238 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.applyPatch = applyPatch;
          +exports.applyPatches = applyPatches;
          +
          +/*istanbul ignore end*/
          +var
          +/*istanbul ignore start*/
          +_parse = require("./parse")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_distanceIterator = _interopRequireDefault(require("../util/distance-iterator"))
          +/*istanbul ignore end*/
          +;
          +
          +/*istanbul ignore start*/ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
          +
          +/*istanbul ignore end*/
          +function applyPatch(source, uniDiff) {
          +  /*istanbul ignore start*/
          +  var
          +  /*istanbul ignore end*/
          +  options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
          +
          +  if (typeof uniDiff === 'string') {
          +    uniDiff =
          +    /*istanbul ignore start*/
          +    (0,
          +    /*istanbul ignore end*/
          +
          +    /*istanbul ignore start*/
          +    _parse
          +    /*istanbul ignore end*/
          +    .
          +    /*istanbul ignore start*/
          +    parsePatch)
          +    /*istanbul ignore end*/
          +    (uniDiff);
          +  }
          +
          +  if (Array.isArray(uniDiff)) {
          +    if (uniDiff.length > 1) {
          +      throw new Error('applyPatch only works with a single input.');
          +    }
          +
          +    uniDiff = uniDiff[0];
          +  } // Apply the diff to the input
          +
          +
          +  var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
          +      delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
          +      hunks = uniDiff.hunks,
          +      compareLine = options.compareLine || function (lineNumber, line, operation, patchContent)
          +  /*istanbul ignore start*/
          +  {
          +    return (
          +      /*istanbul ignore end*/
          +      line === patchContent
          +    );
          +  },
          +      errorCount = 0,
          +      fuzzFactor = options.fuzzFactor || 0,
          +      minLine = 0,
          +      offset = 0,
          +      removeEOFNL,
          +      addEOFNL;
          +  /**
          +   * Checks if the hunk exactly fits on the provided location
          +   */
          +
          +
          +  function hunkFits(hunk, toPos) {
          +    for (var j = 0; j < hunk.lines.length; j++) {
          +      var line = hunk.lines[j],
          +          operation = line.length > 0 ? line[0] : ' ',
          +          content = line.length > 0 ? line.substr(1) : line;
          +
          +      if (operation === ' ' || operation === '-') {
          +        // Context sanity check
          +        if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
          +          errorCount++;
          +
          +          if (errorCount > fuzzFactor) {
          +            return false;
          +          }
          +        }
          +
          +        toPos++;
          +      }
          +    }
          +
          +    return true;
          +  } // Search best fit offsets for each hunk based on the previous ones
          +
          +
          +  for (var i = 0; i < hunks.length; i++) {
          +    var hunk = hunks[i],
          +        maxLine = lines.length - hunk.oldLines,
          +        localOffset = 0,
          +        toPos = offset + hunk.oldStart - 1;
          +    var iterator =
          +    /*istanbul ignore start*/
          +    (0,
          +    /*istanbul ignore end*/
          +
          +    /*istanbul ignore start*/
          +    _distanceIterator
          +    /*istanbul ignore end*/
          +    [
          +    /*istanbul ignore start*/
          +    "default"
          +    /*istanbul ignore end*/
          +    ])(toPos, minLine, maxLine);
          +
          +    for (; localOffset !== undefined; localOffset = iterator()) {
          +      if (hunkFits(hunk, toPos + localOffset)) {
          +        hunk.offset = offset += localOffset;
          +        break;
          +      }
          +    }
          +
          +    if (localOffset === undefined) {
          +      return false;
          +    } // Set lower text limit to end of the current hunk, so next ones don't try
          +    // to fit over already patched text
          +
          +
          +    minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
          +  } // Apply patch hunks
          +
          +
          +  var diffOffset = 0;
          +
          +  for (var _i = 0; _i < hunks.length; _i++) {
          +    var _hunk = hunks[_i],
          +        _toPos = _hunk.oldStart + _hunk.offset + diffOffset - 1;
          +
          +    diffOffset += _hunk.newLines - _hunk.oldLines;
          +
          +    for (var j = 0; j < _hunk.lines.length; j++) {
          +      var line = _hunk.lines[j],
          +          operation = line.length > 0 ? line[0] : ' ',
          +          content = line.length > 0 ? line.substr(1) : line,
          +          delimiter = _hunk.linedelimiters[j];
          +
          +      if (operation === ' ') {
          +        _toPos++;
          +      } else if (operation === '-') {
          +        lines.splice(_toPos, 1);
          +        delimiters.splice(_toPos, 1);
          +        /* istanbul ignore else */
          +      } else if (operation === '+') {
          +        lines.splice(_toPos, 0, content);
          +        delimiters.splice(_toPos, 0, delimiter);
          +        _toPos++;
          +      } else if (operation === '\\') {
          +        var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
          +
          +        if (previousOperation === '+') {
          +          removeEOFNL = true;
          +        } else if (previousOperation === '-') {
          +          addEOFNL = true;
          +        }
          +      }
          +    }
          +  } // Handle EOFNL insertion/removal
          +
          +
          +  if (removeEOFNL) {
          +    while (!lines[lines.length - 1]) {
          +      lines.pop();
          +      delimiters.pop();
          +    }
          +  } else if (addEOFNL) {
          +    lines.push('');
          +    delimiters.push('\n');
          +  }
          +
          +  for (var _k = 0; _k < lines.length - 1; _k++) {
          +    lines[_k] = lines[_k] + delimiters[_k];
          +  }
          +
          +  return lines.join('');
          +} // Wrapper that supports multiple file patches via callbacks.
          +
          +
          +function applyPatches(uniDiff, options) {
          +  if (typeof uniDiff === 'string') {
          +    uniDiff =
          +    /*istanbul ignore start*/
          +    (0,
          +    /*istanbul ignore end*/
          +
          +    /*istanbul ignore start*/
          +    _parse
          +    /*istanbul ignore end*/
          +    .
          +    /*istanbul ignore start*/
          +    parsePatch)
          +    /*istanbul ignore end*/
          +    (uniDiff);
          +  }
          +
          +  var currentIndex = 0;
          +
          +  function processIndex() {
          +    var index = uniDiff[currentIndex++];
          +
          +    if (!index) {
          +      return options.complete();
          +    }
          +
          +    options.loadFile(index, function (err, data) {
          +      if (err) {
          +        return options.complete(err);
          +      }
          +
          +      var updatedContent = applyPatch(data, index, options);
          +      options.patched(index, updatedContent, function (err) {
          +        if (err) {
          +          return options.complete(err);
          +        }
          +
          +        processIndex();
          +      });
          +    });
          +  }
          +
          +  processIndex();
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wYXRjaC9hcHBseS5qcyJdLCJuYW1lcyI6WyJhcHBseVBhdGNoIiwic291cmNlIiwidW5pRGlmZiIsIm9wdGlvbnMiLCJwYXJzZVBhdGNoIiwiQXJyYXkiLCJpc0FycmF5IiwibGVuZ3RoIiwiRXJyb3IiLCJsaW5lcyIsInNwbGl0IiwiZGVsaW1pdGVycyIsIm1hdGNoIiwiaHVua3MiLCJjb21wYXJlTGluZSIsImxpbmVOdW1iZXIiLCJsaW5lIiwib3BlcmF0aW9uIiwicGF0Y2hDb250ZW50IiwiZXJyb3JDb3VudCIsImZ1enpGYWN0b3IiLCJtaW5MaW5lIiwib2Zmc2V0IiwicmVtb3ZlRU9GTkwiLCJhZGRFT0ZOTCIsImh1bmtGaXRzIiwiaHVuayIsInRvUG9zIiwiaiIsImNvbnRlbnQiLCJzdWJzdHIiLCJpIiwibWF4TGluZSIsIm9sZExpbmVzIiwibG9jYWxPZmZzZXQiLCJvbGRTdGFydCIsIml0ZXJhdG9yIiwiZGlzdGFuY2VJdGVyYXRvciIsInVuZGVmaW5lZCIsImRpZmZPZmZzZXQiLCJuZXdMaW5lcyIsImRlbGltaXRlciIsImxpbmVkZWxpbWl0ZXJzIiwic3BsaWNlIiwicHJldmlvdXNPcGVyYXRpb24iLCJwb3AiLCJwdXNoIiwiX2siLCJqb2luIiwiYXBwbHlQYXRjaGVzIiwiY3VycmVudEluZGV4IiwicHJvY2Vzc0luZGV4IiwiaW5kZXgiLCJjb21wbGV0ZSIsImxvYWRGaWxlIiwiZXJyIiwiZGF0YSIsInVwZGF0ZWRDb250ZW50IiwicGF0Y2hlZCJdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7O0FBQ0E7QUFBQTtBQUFBO0FBQUE7QUFBQTs7Ozs7QUFFTyxTQUFTQSxVQUFULENBQW9CQyxNQUFwQixFQUE0QkMsT0FBNUIsRUFBbUQ7QUFBQTtBQUFBO0FBQUE7QUFBZEMsRUFBQUEsT0FBYyx1RUFBSixFQUFJOztBQUN4RCxNQUFJLE9BQU9ELE9BQVAsS0FBbUIsUUFBdkIsRUFBaUM7QUFDL0JBLElBQUFBLE9BQU87QUFBRztBQUFBO0FBQUE7O0FBQUFFO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUE7QUFBQSxLQUFXRixPQUFYLENBQVY7QUFDRDs7QUFFRCxNQUFJRyxLQUFLLENBQUNDLE9BQU4sQ0FBY0osT0FBZCxDQUFKLEVBQTRCO0FBQzFCLFFBQUlBLE9BQU8sQ0FBQ0ssTUFBUixHQUFpQixDQUFyQixFQUF3QjtBQUN0QixZQUFNLElBQUlDLEtBQUosQ0FBVSw0Q0FBVixDQUFOO0FBQ0Q7O0FBRUROLElBQUFBLE9BQU8sR0FBR0EsT0FBTyxDQUFDLENBQUQsQ0FBakI7QUFDRCxHQVh1RCxDQWF4RDs7O0FBQ0EsTUFBSU8sS0FBSyxHQUFHUixNQUFNLENBQUNTLEtBQVAsQ0FBYSxxQkFBYixDQUFaO0FBQUEsTUFDSUMsVUFBVSxHQUFHVixNQUFNLENBQUNXLEtBQVAsQ0FBYSxzQkFBYixLQUF3QyxFQUR6RDtBQUFBLE1BRUlDLEtBQUssR0FBR1gsT0FBTyxDQUFDVyxLQUZwQjtBQUFBLE1BSUlDLFdBQVcsR0FBR1gsT0FBTyxDQUFDVyxXQUFSLElBQXdCLFVBQUNDLFVBQUQsRUFBYUMsSUFBYixFQUFtQkMsU0FBbkIsRUFBOEJDLFlBQTlCO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBK0NGLE1BQUFBLElBQUksS0FBS0U7QUFBeEQ7QUFBQSxHQUoxQztBQUFBLE1BS0lDLFVBQVUsR0FBRyxDQUxqQjtBQUFBLE1BTUlDLFVBQVUsR0FBR2pCLE9BQU8sQ0FBQ2lCLFVBQVIsSUFBc0IsQ0FOdkM7QUFBQSxNQU9JQyxPQUFPLEdBQUcsQ0FQZDtBQUFBLE1BUUlDLE1BQU0sR0FBRyxDQVJiO0FBQUEsTUFVSUMsV0FWSjtBQUFBLE1BV0lDLFFBWEo7QUFhQTs7Ozs7QUFHQSxXQUFTQyxRQUFULENBQWtCQyxJQUFsQixFQUF3QkMsS0FBeEIsRUFBK0I7QUFDN0IsU0FBSyxJQUFJQyxDQUFDLEdBQUcsQ0FBYixFQUFnQkEsQ0FBQyxHQUFHRixJQUFJLENBQUNqQixLQUFMLENBQVdGLE1BQS9CLEVBQXVDcUIsQ0FBQyxFQUF4QyxFQUE0QztBQUMxQyxVQUFJWixJQUFJLEdBQUdVLElBQUksQ0FBQ2pCLEtBQUwsQ0FBV21CLENBQVgsQ0FBWDtBQUFBLFVBQ0lYLFNBQVMsR0FBSUQsSUFBSSxDQUFDVCxNQUFMLEdBQWMsQ0FBZCxHQUFrQlMsSUFBSSxDQUFDLENBQUQsQ0FBdEIsR0FBNEIsR0FEN0M7QUFBQSxVQUVJYSxPQUFPLEdBQUliLElBQUksQ0FBQ1QsTUFBTCxHQUFjLENBQWQsR0FBa0JTLElBQUksQ0FBQ2MsTUFBTCxDQUFZLENBQVosQ0FBbEIsR0FBbUNkLElBRmxEOztBQUlBLFVBQUlDLFNBQVMsS0FBSyxHQUFkLElBQXFCQSxTQUFTLEtBQUssR0FBdkMsRUFBNEM7QUFDMUM7QUFDQSxZQUFJLENBQUNILFdBQVcsQ0FBQ2EsS0FBSyxHQUFHLENBQVQsRUFBWWxCLEtBQUssQ0FBQ2tCLEtBQUQsQ0FBakIsRUFBMEJWLFNBQTFCLEVBQXFDWSxPQUFyQyxDQUFoQixFQUErRDtBQUM3RFYsVUFBQUEsVUFBVTs7QUFFVixjQUFJQSxVQUFVLEdBQUdDLFVBQWpCLEVBQTZCO0FBQzNCLG1CQUFPLEtBQVA7QUFDRDtBQUNGOztBQUNETyxRQUFBQSxLQUFLO0FBQ047QUFDRjs7QUFFRCxXQUFPLElBQVA7QUFDRCxHQWxEdUQsQ0FvRHhEOzs7QUFDQSxPQUFLLElBQUlJLENBQUMsR0FBRyxDQUFiLEVBQWdCQSxDQUFDLEdBQUdsQixLQUFLLENBQUNOLE1BQTFCLEVBQWtDd0IsQ0FBQyxFQUFuQyxFQUF1QztBQUNyQyxRQUFJTCxJQUFJLEdBQUdiLEtBQUssQ0FBQ2tCLENBQUQsQ0FBaEI7QUFBQSxRQUNJQyxPQUFPLEdBQUd2QixLQUFLLENBQUNGLE1BQU4sR0FBZW1CLElBQUksQ0FBQ08sUUFEbEM7QUFBQSxRQUVJQyxXQUFXLEdBQUcsQ0FGbEI7QUFBQSxRQUdJUCxLQUFLLEdBQUdMLE1BQU0sR0FBR0ksSUFBSSxDQUFDUyxRQUFkLEdBQXlCLENBSHJDO0FBS0EsUUFBSUMsUUFBUTtBQUFHO0FBQUE7QUFBQTs7QUFBQUM7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUEsT0FBaUJWLEtBQWpCLEVBQXdCTixPQUF4QixFQUFpQ1csT0FBakMsQ0FBZjs7QUFFQSxXQUFPRSxXQUFXLEtBQUtJLFNBQXZCLEVBQWtDSixXQUFXLEdBQUdFLFFBQVEsRUFBeEQsRUFBNEQ7QUFDMUQsVUFBSVgsUUFBUSxDQUFDQyxJQUFELEVBQU9DLEtBQUssR0FBR08sV0FBZixDQUFaLEVBQXlDO0FBQ3ZDUixRQUFBQSxJQUFJLENBQUNKLE1BQUwsR0FBY0EsTUFBTSxJQUFJWSxXQUF4QjtBQUNBO0FBQ0Q7QUFDRjs7QUFFRCxRQUFJQSxXQUFXLEtBQUtJLFNBQXBCLEVBQStCO0FBQzdCLGFBQU8sS0FBUDtBQUNELEtBakJvQyxDQW1CckM7QUFDQTs7O0FBQ0FqQixJQUFBQSxPQUFPLEdBQUdLLElBQUksQ0FBQ0osTUFBTCxHQUFjSSxJQUFJLENBQUNTLFFBQW5CLEdBQThCVCxJQUFJLENBQUNPLFFBQTdDO0FBQ0QsR0EzRXVELENBNkV4RDs7O0FBQ0EsTUFBSU0sVUFBVSxHQUFHLENBQWpCOztBQUNBLE9BQUssSUFBSVIsRUFBQyxHQUFHLENBQWIsRUFBZ0JBLEVBQUMsR0FBR2xCLEtBQUssQ0FBQ04sTUFBMUIsRUFBa0N3QixFQUFDLEVBQW5DLEVBQXVDO0FBQ3JDLFFBQUlMLEtBQUksR0FBR2IsS0FBSyxDQUFDa0IsRUFBRCxDQUFoQjtBQUFBLFFBQ0lKLE1BQUssR0FBR0QsS0FBSSxDQUFDUyxRQUFMLEdBQWdCVCxLQUFJLENBQUNKLE1BQXJCLEdBQThCaUIsVUFBOUIsR0FBMkMsQ0FEdkQ7O0FBRUFBLElBQUFBLFVBQVUsSUFBSWIsS0FBSSxDQUFDYyxRQUFMLEdBQWdCZCxLQUFJLENBQUNPLFFBQW5DOztBQUVBLFNBQUssSUFBSUwsQ0FBQyxHQUFHLENBQWIsRUFBZ0JBLENBQUMsR0FBR0YsS0FBSSxDQUFDakIsS0FBTCxDQUFXRixNQUEvQixFQUF1Q3FCLENBQUMsRUFBeEMsRUFBNEM7QUFDMUMsVUFBSVosSUFBSSxHQUFHVSxLQUFJLENBQUNqQixLQUFMLENBQVdtQixDQUFYLENBQVg7QUFBQSxVQUNJWCxTQUFTLEdBQUlELElBQUksQ0FBQ1QsTUFBTCxHQUFjLENBQWQsR0FBa0JTLElBQUksQ0FBQyxDQUFELENBQXRCLEdBQTRCLEdBRDdDO0FBQUEsVUFFSWEsT0FBTyxHQUFJYixJQUFJLENBQUNULE1BQUwsR0FBYyxDQUFkLEdBQWtCUyxJQUFJLENBQUNjLE1BQUwsQ0FBWSxDQUFaLENBQWxCLEdBQW1DZCxJQUZsRDtBQUFBLFVBR0l5QixTQUFTLEdBQUdmLEtBQUksQ0FBQ2dCLGNBQUwsQ0FBb0JkLENBQXBCLENBSGhCOztBQUtBLFVBQUlYLFNBQVMsS0FBSyxHQUFsQixFQUF1QjtBQUNyQlUsUUFBQUEsTUFBSztBQUNOLE9BRkQsTUFFTyxJQUFJVixTQUFTLEtBQUssR0FBbEIsRUFBdUI7QUFDNUJSLFFBQUFBLEtBQUssQ0FBQ2tDLE1BQU4sQ0FBYWhCLE1BQWIsRUFBb0IsQ0FBcEI7QUFDQWhCLFFBQUFBLFVBQVUsQ0FBQ2dDLE1BQVgsQ0FBa0JoQixNQUFsQixFQUF5QixDQUF6QjtBQUNGO0FBQ0MsT0FKTSxNQUlBLElBQUlWLFNBQVMsS0FBSyxHQUFsQixFQUF1QjtBQUM1QlIsUUFBQUEsS0FBSyxDQUFDa0MsTUFBTixDQUFhaEIsTUFBYixFQUFvQixDQUFwQixFQUF1QkUsT0FBdkI7QUFDQWxCLFFBQUFBLFVBQVUsQ0FBQ2dDLE1BQVgsQ0FBa0JoQixNQUFsQixFQUF5QixDQUF6QixFQUE0QmMsU0FBNUI7QUFDQWQsUUFBQUEsTUFBSztBQUNOLE9BSk0sTUFJQSxJQUFJVixTQUFTLEtBQUssSUFBbEIsRUFBd0I7QUFDN0IsWUFBSTJCLGlCQUFpQixHQUFHbEIsS0FBSSxDQUFDakIsS0FBTCxDQUFXbUIsQ0FBQyxHQUFHLENBQWYsSUFBb0JGLEtBQUksQ0FBQ2pCLEtBQUwsQ0FBV21CLENBQUMsR0FBRyxDQUFmLEVBQWtCLENBQWxCLENBQXBCLEdBQTJDLElBQW5FOztBQUNBLFlBQUlnQixpQkFBaUIsS0FBSyxHQUExQixFQUErQjtBQUM3QnJCLFVBQUFBLFdBQVcsR0FBRyxJQUFkO0FBQ0QsU0FGRCxNQUVPLElBQUlxQixpQkFBaUIsS0FBSyxHQUExQixFQUErQjtBQUNwQ3BCLFVBQUFBLFFBQVEsR0FBRyxJQUFYO0FBQ0Q7QUFDRjtBQUNGO0FBQ0YsR0E3R3VELENBK0d4RDs7O0FBQ0EsTUFBSUQsV0FBSixFQUFpQjtBQUNmLFdBQU8sQ0FBQ2QsS0FBSyxDQUFDQSxLQUFLLENBQUNGLE1BQU4sR0FBZSxDQUFoQixDQUFiLEVBQWlDO0FBQy9CRSxNQUFBQSxLQUFLLENBQUNvQyxHQUFOO0FBQ0FsQyxNQUFBQSxVQUFVLENBQUNrQyxHQUFYO0FBQ0Q7QUFDRixHQUxELE1BS08sSUFBSXJCLFFBQUosRUFBYztBQUNuQmYsSUFBQUEsS0FBSyxDQUFDcUMsSUFBTixDQUFXLEVBQVg7QUFDQW5DLElBQUFBLFVBQVUsQ0FBQ21DLElBQVgsQ0FBZ0IsSUFBaEI7QUFDRDs7QUFDRCxPQUFLLElBQUlDLEVBQUUsR0FBRyxDQUFkLEVBQWlCQSxFQUFFLEdBQUd0QyxLQUFLLENBQUNGLE1BQU4sR0FBZSxDQUFyQyxFQUF3Q3dDLEVBQUUsRUFBMUMsRUFBOEM7QUFDNUN0QyxJQUFBQSxLQUFLLENBQUNzQyxFQUFELENBQUwsR0FBWXRDLEtBQUssQ0FBQ3NDLEVBQUQsQ0FBTCxHQUFZcEMsVUFBVSxDQUFDb0MsRUFBRCxDQUFsQztBQUNEOztBQUNELFNBQU90QyxLQUFLLENBQUN1QyxJQUFOLENBQVcsRUFBWCxDQUFQO0FBQ0QsQyxDQUVEOzs7QUFDTyxTQUFTQyxZQUFULENBQXNCL0MsT0FBdEIsRUFBK0JDLE9BQS9CLEVBQXdDO0FBQzdDLE1BQUksT0FBT0QsT0FBUCxLQUFtQixRQUF2QixFQUFpQztBQUMvQkEsSUFBQUEsT0FBTztBQUFHO0FBQUE7QUFBQTs7QUFBQUU7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQUE7QUFBQTtBQUFBLEtBQVdGLE9BQVgsQ0FBVjtBQUNEOztBQUVELE1BQUlnRCxZQUFZLEdBQUcsQ0FBbkI7O0FBQ0EsV0FBU0MsWUFBVCxHQUF3QjtBQUN0QixRQUFJQyxLQUFLLEdBQUdsRCxPQUFPLENBQUNnRCxZQUFZLEVBQWIsQ0FBbkI7O0FBQ0EsUUFBSSxDQUFDRSxLQUFMLEVBQVk7QUFDVixhQUFPakQsT0FBTyxDQUFDa0QsUUFBUixFQUFQO0FBQ0Q7O0FBRURsRCxJQUFBQSxPQUFPLENBQUNtRCxRQUFSLENBQWlCRixLQUFqQixFQUF3QixVQUFTRyxHQUFULEVBQWNDLElBQWQsRUFBb0I7QUFDMUMsVUFBSUQsR0FBSixFQUFTO0FBQ1AsZUFBT3BELE9BQU8sQ0FBQ2tELFFBQVIsQ0FBaUJFLEdBQWpCLENBQVA7QUFDRDs7QUFFRCxVQUFJRSxjQUFjLEdBQUd6RCxVQUFVLENBQUN3RCxJQUFELEVBQU9KLEtBQVAsRUFBY2pELE9BQWQsQ0FBL0I7QUFDQUEsTUFBQUEsT0FBTyxDQUFDdUQsT0FBUixDQUFnQk4sS0FBaEIsRUFBdUJLLGNBQXZCLEVBQXVDLFVBQVNGLEdBQVQsRUFBYztBQUNuRCxZQUFJQSxHQUFKLEVBQVM7QUFDUCxpQkFBT3BELE9BQU8sQ0FBQ2tELFFBQVIsQ0FBaUJFLEdBQWpCLENBQVA7QUFDRDs7QUFFREosUUFBQUEsWUFBWTtBQUNiLE9BTkQ7QUFPRCxLQWJEO0FBY0Q7O0FBQ0RBLEVBQUFBLFlBQVk7QUFDYiIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7cGFyc2VQYXRjaH0gZnJvbSAnLi9wYXJzZSc7XG5pbXBvcnQgZGlzdGFuY2VJdGVyYXRvciBmcm9tICcuLi91dGlsL2Rpc3RhbmNlLWl0ZXJhdG9yJztcblxuZXhwb3J0IGZ1bmN0aW9uIGFwcGx5UGF0Y2goc291cmNlLCB1bmlEaWZmLCBvcHRpb25zID0ge30pIHtcbiAgaWYgKHR5cGVvZiB1bmlEaWZmID09PSAnc3RyaW5nJykge1xuICAgIHVuaURpZmYgPSBwYXJzZVBhdGNoKHVuaURpZmYpO1xuICB9XG5cbiAgaWYgKEFycmF5LmlzQXJyYXkodW5pRGlmZikpIHtcbiAgICBpZiAodW5pRGlmZi5sZW5ndGggPiAxKSB7XG4gICAgICB0aHJvdyBuZXcgRXJyb3IoJ2FwcGx5UGF0Y2ggb25seSB3b3JrcyB3aXRoIGEgc2luZ2xlIGlucHV0LicpO1xuICAgIH1cblxuICAgIHVuaURpZmYgPSB1bmlEaWZmWzBdO1xuICB9XG5cbiAgLy8gQXBwbHkgdGhlIGRpZmYgdG8gdGhlIGlucHV0XG4gIGxldCBsaW5lcyA9IHNvdXJjZS5zcGxpdCgvXFxyXFxufFtcXG5cXHZcXGZcXHJcXHg4NV0vKSxcbiAgICAgIGRlbGltaXRlcnMgPSBzb3VyY2UubWF0Y2goL1xcclxcbnxbXFxuXFx2XFxmXFxyXFx4ODVdL2cpIHx8IFtdLFxuICAgICAgaHVua3MgPSB1bmlEaWZmLmh1bmtzLFxuXG4gICAgICBjb21wYXJlTGluZSA9IG9wdGlvbnMuY29tcGFyZUxpbmUgfHwgKChsaW5lTnVtYmVyLCBsaW5lLCBvcGVyYXRpb24sIHBhdGNoQ29udGVudCkgPT4gbGluZSA9PT0gcGF0Y2hDb250ZW50KSxcbiAgICAgIGVycm9yQ291bnQgPSAwLFxuICAgICAgZnV6ekZhY3RvciA9IG9wdGlvbnMuZnV6ekZhY3RvciB8fCAwLFxuICAgICAgbWluTGluZSA9IDAsXG4gICAgICBvZmZzZXQgPSAwLFxuXG4gICAgICByZW1vdmVFT0ZOTCxcbiAgICAgIGFkZEVPRk5MO1xuXG4gIC8qKlxuICAgKiBDaGVja3MgaWYgdGhlIGh1bmsgZXhhY3RseSBmaXRzIG9uIHRoZSBwcm92aWRlZCBsb2NhdGlvblxuICAgKi9cbiAgZnVuY3Rpb24gaHVua0ZpdHMoaHVuaywgdG9Qb3MpIHtcbiAgICBmb3IgKGxldCBqID0gMDsgaiA8IGh1bmsubGluZXMubGVuZ3RoOyBqKyspIHtcbiAgICAgIGxldCBsaW5lID0gaHVuay5saW5lc1tqXSxcbiAgICAgICAgICBvcGVyYXRpb24gPSAobGluZS5sZW5ndGggPiAwID8gbGluZVswXSA6ICcgJyksXG4gICAgICAgICAgY29udGVudCA9IChsaW5lLmxlbmd0aCA+IDAgPyBsaW5lLnN1YnN0cigxKSA6IGxpbmUpO1xuXG4gICAgICBpZiAob3BlcmF0aW9uID09PSAnICcgfHwgb3BlcmF0aW9uID09PSAnLScpIHtcbiAgICAgICAgLy8gQ29udGV4dCBzYW5pdHkgY2hlY2tcbiAgICAgICAgaWYgKCFjb21wYXJlTGluZSh0b1BvcyArIDEsIGxpbmVzW3RvUG9zXSwgb3BlcmF0aW9uLCBjb250ZW50KSkge1xuICAgICAgICAgIGVycm9yQ291bnQrKztcblxuICAgICAgICAgIGlmIChlcnJvckNvdW50ID4gZnV6ekZhY3Rvcikge1xuICAgICAgICAgICAgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICB0b1BvcysrO1xuICAgICAgfVxuICAgIH1cblxuICAgIHJldHVybiB0cnVlO1xuICB9XG5cbiAgLy8gU2VhcmNoIGJlc3QgZml0IG9mZnNldHMgZm9yIGVhY2ggaHVuayBiYXNlZCBvbiB0aGUgcHJldmlvdXMgb25lc1xuICBmb3IgKGxldCBpID0gMDsgaSA8IGh1bmtzLmxlbmd0aDsgaSsrKSB7XG4gICAgbGV0IGh1bmsgPSBodW5rc1tpXSxcbiAgICAgICAgbWF4TGluZSA9IGxpbmVzLmxlbmd0aCAtIGh1bmsub2xkTGluZXMsXG4gICAgICAgIGxvY2FsT2Zmc2V0ID0gMCxcbiAgICAgICAgdG9Qb3MgPSBvZmZzZXQgKyBodW5rLm9sZFN0YXJ0IC0gMTtcblxuICAgIGxldCBpdGVyYXRvciA9IGRpc3RhbmNlSXRlcmF0b3IodG9Qb3MsIG1pbkxpbmUsIG1heExpbmUpO1xuXG4gICAgZm9yICg7IGxvY2FsT2Zmc2V0ICE9PSB1bmRlZmluZWQ7IGxvY2FsT2Zmc2V0ID0gaXRlcmF0b3IoKSkge1xuICAgICAgaWYgKGh1bmtGaXRzKGh1bmssIHRvUG9zICsgbG9jYWxPZmZzZXQpKSB7XG4gICAgICAgIGh1bmsub2Zmc2V0ID0gb2Zmc2V0ICs9IGxvY2FsT2Zmc2V0O1xuICAgICAgICBicmVhaztcbiAgICAgIH1cbiAgICB9XG5cbiAgICBpZiAobG9jYWxPZmZzZXQgPT09IHVuZGVmaW5lZCkge1xuICAgICAgcmV0dXJuIGZhbHNlO1xuICAgIH1cblxuICAgIC8vIFNldCBsb3dlciB0ZXh0IGxpbWl0IHRvIGVuZCBvZiB0aGUgY3VycmVudCBodW5rLCBzbyBuZXh0IG9uZXMgZG9uJ3QgdHJ5XG4gICAgLy8gdG8gZml0IG92ZXIgYWxyZWFkeSBwYXRjaGVkIHRleHRcbiAgICBtaW5MaW5lID0gaHVuay5vZmZzZXQgKyBodW5rLm9sZFN0YXJ0ICsgaHVuay5vbGRMaW5lcztcbiAgfVxuXG4gIC8vIEFwcGx5IHBhdGNoIGh1bmtzXG4gIGxldCBkaWZmT2Zmc2V0ID0gMDtcbiAgZm9yIChsZXQgaSA9IDA7IGkgPCBodW5rcy5sZW5ndGg7IGkrKykge1xuICAgIGxldCBodW5rID0gaHVua3NbaV0sXG4gICAgICAgIHRvUG9zID0gaHVuay5vbGRTdGFydCArIGh1bmsub2Zmc2V0ICsgZGlmZk9mZnNldCAtIDE7XG4gICAgZGlmZk9mZnNldCArPSBodW5rLm5ld0xpbmVzIC0gaHVuay5vbGRMaW5lcztcblxuICAgIGZvciAobGV0IGogPSAwOyBqIDwgaHVuay5saW5lcy5sZW5ndGg7IGorKykge1xuICAgICAgbGV0IGxpbmUgPSBodW5rLmxpbmVzW2pdLFxuICAgICAgICAgIG9wZXJhdGlvbiA9IChsaW5lLmxlbmd0aCA+IDAgPyBsaW5lWzBdIDogJyAnKSxcbiAgICAgICAgICBjb250ZW50ID0gKGxpbmUubGVuZ3RoID4gMCA/IGxpbmUuc3Vic3RyKDEpIDogbGluZSksXG4gICAgICAgICAgZGVsaW1pdGVyID0gaHVuay5saW5lZGVsaW1pdGVyc1tqXTtcblxuICAgICAgaWYgKG9wZXJhdGlvbiA9PT0gJyAnKSB7XG4gICAgICAgIHRvUG9zKys7XG4gICAgICB9IGVsc2UgaWYgKG9wZXJhdGlvbiA9PT0gJy0nKSB7XG4gICAgICAgIGxpbmVzLnNwbGljZSh0b1BvcywgMSk7XG4gICAgICAgIGRlbGltaXRlcnMuc3BsaWNlKHRvUG9zLCAxKTtcbiAgICAgIC8qIGlzdGFuYnVsIGlnbm9yZSBlbHNlICovXG4gICAgICB9IGVsc2UgaWYgKG9wZXJhdGlvbiA9PT0gJysnKSB7XG4gICAgICAgIGxpbmVzLnNwbGljZSh0b1BvcywgMCwgY29udGVudCk7XG4gICAgICAgIGRlbGltaXRlcnMuc3BsaWNlKHRvUG9zLCAwLCBkZWxpbWl0ZXIpO1xuICAgICAgICB0b1BvcysrO1xuICAgICAgfSBlbHNlIGlmIChvcGVyYXRpb24gPT09ICdcXFxcJykge1xuICAgICAgICBsZXQgcHJldmlvdXNPcGVyYXRpb24gPSBodW5rLmxpbmVzW2ogLSAxXSA/IGh1bmsubGluZXNbaiAtIDFdWzBdIDogbnVsbDtcbiAgICAgICAgaWYgKHByZXZpb3VzT3BlcmF0aW9uID09PSAnKycpIHtcbiAgICAgICAgICByZW1vdmVFT0ZOTCA9IHRydWU7XG4gICAgICAgIH0gZWxzZSBpZiAocHJldmlvdXNPcGVyYXRpb24gPT09ICctJykge1xuICAgICAgICAgIGFkZEVPRk5MID0gdHJ1ZTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgfVxuXG4gIC8vIEhhbmRsZSBFT0ZOTCBpbnNlcnRpb24vcmVtb3ZhbFxuICBpZiAocmVtb3ZlRU9GTkwpIHtcbiAgICB3aGlsZSAoIWxpbmVzW2xpbmVzLmxlbmd0aCAtIDFdKSB7XG4gICAgICBsaW5lcy5wb3AoKTtcbiAgICAgIGRlbGltaXRlcnMucG9wKCk7XG4gICAgfVxuICB9IGVsc2UgaWYgKGFkZEVPRk5MKSB7XG4gICAgbGluZXMucHVzaCgnJyk7XG4gICAgZGVsaW1pdGVycy5wdXNoKCdcXG4nKTtcbiAgfVxuICBmb3IgKGxldCBfayA9IDA7IF9rIDwgbGluZXMubGVuZ3RoIC0gMTsgX2srKykge1xuICAgIGxpbmVzW19rXSA9IGxpbmVzW19rXSArIGRlbGltaXRlcnNbX2tdO1xuICB9XG4gIHJldHVybiBsaW5lcy5qb2luKCcnKTtcbn1cblxuLy8gV3JhcHBlciB0aGF0IHN1cHBvcnRzIG11bHRpcGxlIGZpbGUgcGF0Y2hlcyB2aWEgY2FsbGJhY2tzLlxuZXhwb3J0IGZ1bmN0aW9uIGFwcGx5UGF0Y2hlcyh1bmlEaWZmLCBvcHRpb25zKSB7XG4gIGlmICh0eXBlb2YgdW5pRGlmZiA9PT0gJ3N0cmluZycpIHtcbiAgICB1bmlEaWZmID0gcGFyc2VQYXRjaCh1bmlEaWZmKTtcbiAgfVxuXG4gIGxldCBjdXJyZW50SW5kZXggPSAwO1xuICBmdW5jdGlvbiBwcm9jZXNzSW5kZXgoKSB7XG4gICAgbGV0IGluZGV4ID0gdW5pRGlmZltjdXJyZW50SW5kZXgrK107XG4gICAgaWYgKCFpbmRleCkge1xuICAgICAgcmV0dXJuIG9wdGlvbnMuY29tcGxldGUoKTtcbiAgICB9XG5cbiAgICBvcHRpb25zLmxvYWRGaWxlKGluZGV4LCBmdW5jdGlvbihlcnIsIGRhdGEpIHtcbiAgICAgIGlmIChlcnIpIHtcbiAgICAgICAgcmV0dXJuIG9wdGlvbnMuY29tcGxldGUoZXJyKTtcbiAgICAgIH1cblxuICAgICAgbGV0IHVwZGF0ZWRDb250ZW50ID0gYXBwbHlQYXRjaChkYXRhLCBpbmRleCwgb3B0aW9ucyk7XG4gICAgICBvcHRpb25zLnBhdGNoZWQoaW5kZXgsIHVwZGF0ZWRDb250ZW50LCBmdW5jdGlvbihlcnIpIHtcbiAgICAgICAgaWYgKGVycikge1xuICAgICAgICAgIHJldHVybiBvcHRpb25zLmNvbXBsZXRlKGVycik7XG4gICAgICAgIH1cblxuICAgICAgICBwcm9jZXNzSW5kZXgoKTtcbiAgICAgIH0pO1xuICAgIH0pO1xuICB9XG4gIHByb2Nlc3NJbmRleCgpO1xufVxuIl19
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/patch/create.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/patch/create.js
          new file mode 100644
          index 00000000000000..48bb4668442a98
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/patch/create.js
          @@ -0,0 +1,267 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.structuredPatch = structuredPatch;
          +exports.formatPatch = formatPatch;
          +exports.createTwoFilesPatch = createTwoFilesPatch;
          +exports.createPatch = createPatch;
          +
          +/*istanbul ignore end*/
          +var
          +/*istanbul ignore start*/
          +_line = require("../diff/line")
          +/*istanbul ignore end*/
          +;
          +
          +/*istanbul ignore start*/ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
          +
          +function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
          +
          +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
          +
          +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
          +
          +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
          +
          +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
          +
          +/*istanbul ignore end*/
          +function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
          +  if (!options) {
          +    options = {};
          +  }
          +
          +  if (typeof options.context === 'undefined') {
          +    options.context = 4;
          +  }
          +
          +  var diff =
          +  /*istanbul ignore start*/
          +  (0,
          +  /*istanbul ignore end*/
          +
          +  /*istanbul ignore start*/
          +  _line
          +  /*istanbul ignore end*/
          +  .
          +  /*istanbul ignore start*/
          +  diffLines)
          +  /*istanbul ignore end*/
          +  (oldStr, newStr, options);
          +  diff.push({
          +    value: '',
          +    lines: []
          +  }); // Append an empty value to make cleanup easier
          +
          +  function contextLines(lines) {
          +    return lines.map(function (entry) {
          +      return ' ' + entry;
          +    });
          +  }
          +
          +  var hunks = [];
          +  var oldRangeStart = 0,
          +      newRangeStart = 0,
          +      curRange = [],
          +      oldLine = 1,
          +      newLine = 1;
          +
          +  /*istanbul ignore start*/
          +  var _loop = function _loop(
          +  /*istanbul ignore end*/
          +  i) {
          +    var current = diff[i],
          +        lines = current.lines || current.value.replace(/\n$/, '').split('\n');
          +    current.lines = lines;
          +
          +    if (current.added || current.removed) {
          +      /*istanbul ignore start*/
          +      var _curRange;
          +
          +      /*istanbul ignore end*/
          +      // If we have previous context, start with that
          +      if (!oldRangeStart) {
          +        var prev = diff[i - 1];
          +        oldRangeStart = oldLine;
          +        newRangeStart = newLine;
          +
          +        if (prev) {
          +          curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
          +          oldRangeStart -= curRange.length;
          +          newRangeStart -= curRange.length;
          +        }
          +      } // Output our changes
          +
          +
          +      /*istanbul ignore start*/
          +
          +      /*istanbul ignore end*/
          +
          +      /*istanbul ignore start*/
          +      (_curRange =
          +      /*istanbul ignore end*/
          +      curRange).push.apply(
          +      /*istanbul ignore start*/
          +      _curRange
          +      /*istanbul ignore end*/
          +      ,
          +      /*istanbul ignore start*/
          +      _toConsumableArray(
          +      /*istanbul ignore end*/
          +      lines.map(function (entry) {
          +        return (current.added ? '+' : '-') + entry;
          +      }))); // Track the updated file position
          +
          +
          +      if (current.added) {
          +        newLine += lines.length;
          +      } else {
          +        oldLine += lines.length;
          +      }
          +    } else {
          +      // Identical context lines. Track line changes
          +      if (oldRangeStart) {
          +        // Close out any changes that have been output (or join overlapping)
          +        if (lines.length <= options.context * 2 && i < diff.length - 2) {
          +          /*istanbul ignore start*/
          +          var _curRange2;
          +
          +          /*istanbul ignore end*/
          +          // Overlapping
          +
          +          /*istanbul ignore start*/
          +
          +          /*istanbul ignore end*/
          +
          +          /*istanbul ignore start*/
          +          (_curRange2 =
          +          /*istanbul ignore end*/
          +          curRange).push.apply(
          +          /*istanbul ignore start*/
          +          _curRange2
          +          /*istanbul ignore end*/
          +          ,
          +          /*istanbul ignore start*/
          +          _toConsumableArray(
          +          /*istanbul ignore end*/
          +          contextLines(lines)));
          +        } else {
          +          /*istanbul ignore start*/
          +          var _curRange3;
          +
          +          /*istanbul ignore end*/
          +          // end the range and output
          +          var contextSize = Math.min(lines.length, options.context);
          +
          +          /*istanbul ignore start*/
          +
          +          /*istanbul ignore end*/
          +
          +          /*istanbul ignore start*/
          +          (_curRange3 =
          +          /*istanbul ignore end*/
          +          curRange).push.apply(
          +          /*istanbul ignore start*/
          +          _curRange3
          +          /*istanbul ignore end*/
          +          ,
          +          /*istanbul ignore start*/
          +          _toConsumableArray(
          +          /*istanbul ignore end*/
          +          contextLines(lines.slice(0, contextSize))));
          +
          +          var hunk = {
          +            oldStart: oldRangeStart,
          +            oldLines: oldLine - oldRangeStart + contextSize,
          +            newStart: newRangeStart,
          +            newLines: newLine - newRangeStart + contextSize,
          +            lines: curRange
          +          };
          +
          +          if (i >= diff.length - 2 && lines.length <= options.context) {
          +            // EOF is inside this hunk
          +            var oldEOFNewline = /\n$/.test(oldStr);
          +            var newEOFNewline = /\n$/.test(newStr);
          +            var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
          +
          +            if (!oldEOFNewline && noNlBeforeAdds && oldStr.length > 0) {
          +              // special case: old has no eol and no trailing context; no-nl can end up before adds
          +              // however, if the old file is empty, do not output the no-nl line
          +              curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
          +            }
          +
          +            if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
          +              curRange.push('\\ No newline at end of file');
          +            }
          +          }
          +
          +          hunks.push(hunk);
          +          oldRangeStart = 0;
          +          newRangeStart = 0;
          +          curRange = [];
          +        }
          +      }
          +
          +      oldLine += lines.length;
          +      newLine += lines.length;
          +    }
          +  };
          +
          +  for (var i = 0; i < diff.length; i++) {
          +    /*istanbul ignore start*/
          +    _loop(
          +    /*istanbul ignore end*/
          +    i);
          +  }
          +
          +  return {
          +    oldFileName: oldFileName,
          +    newFileName: newFileName,
          +    oldHeader: oldHeader,
          +    newHeader: newHeader,
          +    hunks: hunks
          +  };
          +}
          +
          +function formatPatch(diff) {
          +  var ret = [];
          +
          +  if (diff.oldFileName == diff.newFileName) {
          +    ret.push('Index: ' + diff.oldFileName);
          +  }
          +
          +  ret.push('===================================================================');
          +  ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
          +  ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
          +
          +  for (var i = 0; i < diff.hunks.length; i++) {
          +    var hunk = diff.hunks[i]; // Unified Diff Format quirk: If the chunk size is 0,
          +    // the first number is one lower than one would expect.
          +    // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
          +
          +    if (hunk.oldLines === 0) {
          +      hunk.oldStart -= 1;
          +    }
          +
          +    if (hunk.newLines === 0) {
          +      hunk.newStart -= 1;
          +    }
          +
          +    ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
          +    ret.push.apply(ret, hunk.lines);
          +  }
          +
          +  return ret.join('\n') + '\n';
          +}
          +
          +function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
          +  return formatPatch(structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options));
          +}
          +
          +function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
          +  return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wYXRjaC9jcmVhdGUuanMiXSwibmFtZXMiOlsic3RydWN0dXJlZFBhdGNoIiwib2xkRmlsZU5hbWUiLCJuZXdGaWxlTmFtZSIsIm9sZFN0ciIsIm5ld1N0ciIsIm9sZEhlYWRlciIsIm5ld0hlYWRlciIsIm9wdGlvbnMiLCJjb250ZXh0IiwiZGlmZiIsImRpZmZMaW5lcyIsInB1c2giLCJ2YWx1ZSIsImxpbmVzIiwiY29udGV4dExpbmVzIiwibWFwIiwiZW50cnkiLCJodW5rcyIsIm9sZFJhbmdlU3RhcnQiLCJuZXdSYW5nZVN0YXJ0IiwiY3VyUmFuZ2UiLCJvbGRMaW5lIiwibmV3TGluZSIsImkiLCJjdXJyZW50IiwicmVwbGFjZSIsInNwbGl0IiwiYWRkZWQiLCJyZW1vdmVkIiwicHJldiIsInNsaWNlIiwibGVuZ3RoIiwiY29udGV4dFNpemUiLCJNYXRoIiwibWluIiwiaHVuayIsIm9sZFN0YXJ0Iiwib2xkTGluZXMiLCJuZXdTdGFydCIsIm5ld0xpbmVzIiwib2xkRU9GTmV3bGluZSIsInRlc3QiLCJuZXdFT0ZOZXdsaW5lIiwibm9ObEJlZm9yZUFkZHMiLCJzcGxpY2UiLCJmb3JtYXRQYXRjaCIsInJldCIsImFwcGx5Iiwiam9pbiIsImNyZWF0ZVR3b0ZpbGVzUGF0Y2giLCJjcmVhdGVQYXRjaCIsImZpbGVOYW1lIl0sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBOzs7Ozs7Ozs7Ozs7Ozs7QUFFTyxTQUFTQSxlQUFULENBQXlCQyxXQUF6QixFQUFzQ0MsV0FBdEMsRUFBbURDLE1BQW5ELEVBQTJEQyxNQUEzRCxFQUFtRUMsU0FBbkUsRUFBOEVDLFNBQTlFLEVBQXlGQyxPQUF6RixFQUFrRztBQUN2RyxNQUFJLENBQUNBLE9BQUwsRUFBYztBQUNaQSxJQUFBQSxPQUFPLEdBQUcsRUFBVjtBQUNEOztBQUNELE1BQUksT0FBT0EsT0FBTyxDQUFDQyxPQUFmLEtBQTJCLFdBQS9CLEVBQTRDO0FBQzFDRCxJQUFBQSxPQUFPLENBQUNDLE9BQVIsR0FBa0IsQ0FBbEI7QUFDRDs7QUFFRCxNQUFNQyxJQUFJO0FBQUc7QUFBQTtBQUFBOztBQUFBQztBQUFBQTtBQUFBQTtBQUFBQTtBQUFBQTtBQUFBQTtBQUFBO0FBQUEsR0FBVVAsTUFBVixFQUFrQkMsTUFBbEIsRUFBMEJHLE9BQTFCLENBQWI7QUFDQUUsRUFBQUEsSUFBSSxDQUFDRSxJQUFMLENBQVU7QUFBQ0MsSUFBQUEsS0FBSyxFQUFFLEVBQVI7QUFBWUMsSUFBQUEsS0FBSyxFQUFFO0FBQW5CLEdBQVYsRUFUdUcsQ0FTcEU7O0FBRW5DLFdBQVNDLFlBQVQsQ0FBc0JELEtBQXRCLEVBQTZCO0FBQzNCLFdBQU9BLEtBQUssQ0FBQ0UsR0FBTixDQUFVLFVBQVNDLEtBQVQsRUFBZ0I7QUFBRSxhQUFPLE1BQU1BLEtBQWI7QUFBcUIsS0FBakQsQ0FBUDtBQUNEOztBQUVELE1BQUlDLEtBQUssR0FBRyxFQUFaO0FBQ0EsTUFBSUMsYUFBYSxHQUFHLENBQXBCO0FBQUEsTUFBdUJDLGFBQWEsR0FBRyxDQUF2QztBQUFBLE1BQTBDQyxRQUFRLEdBQUcsRUFBckQ7QUFBQSxNQUNJQyxPQUFPLEdBQUcsQ0FEZDtBQUFBLE1BQ2lCQyxPQUFPLEdBQUcsQ0FEM0I7O0FBaEJ1RztBQUFBO0FBQUE7QUFrQjlGQyxFQUFBQSxDQWxCOEY7QUFtQnJHLFFBQU1DLE9BQU8sR0FBR2YsSUFBSSxDQUFDYyxDQUFELENBQXBCO0FBQUEsUUFDTVYsS0FBSyxHQUFHVyxPQUFPLENBQUNYLEtBQVIsSUFBaUJXLE9BQU8sQ0FBQ1osS0FBUixDQUFjYSxPQUFkLENBQXNCLEtBQXRCLEVBQTZCLEVBQTdCLEVBQWlDQyxLQUFqQyxDQUF1QyxJQUF2QyxDQUQvQjtBQUVBRixJQUFBQSxPQUFPLENBQUNYLEtBQVIsR0FBZ0JBLEtBQWhCOztBQUVBLFFBQUlXLE9BQU8sQ0FBQ0csS0FBUixJQUFpQkgsT0FBTyxDQUFDSSxPQUE3QixFQUFzQztBQUFBO0FBQUE7O0FBQUE7QUFDcEM7QUFDQSxVQUFJLENBQUNWLGFBQUwsRUFBb0I7QUFDbEIsWUFBTVcsSUFBSSxHQUFHcEIsSUFBSSxDQUFDYyxDQUFDLEdBQUcsQ0FBTCxDQUFqQjtBQUNBTCxRQUFBQSxhQUFhLEdBQUdHLE9BQWhCO0FBQ0FGLFFBQUFBLGFBQWEsR0FBR0csT0FBaEI7O0FBRUEsWUFBSU8sSUFBSixFQUFVO0FBQ1JULFVBQUFBLFFBQVEsR0FBR2IsT0FBTyxDQUFDQyxPQUFSLEdBQWtCLENBQWxCLEdBQXNCTSxZQUFZLENBQUNlLElBQUksQ0FBQ2hCLEtBQUwsQ0FBV2lCLEtBQVgsQ0FBaUIsQ0FBQ3ZCLE9BQU8sQ0FBQ0MsT0FBMUIsQ0FBRCxDQUFsQyxHQUF5RSxFQUFwRjtBQUNBVSxVQUFBQSxhQUFhLElBQUlFLFFBQVEsQ0FBQ1csTUFBMUI7QUFDQVosVUFBQUEsYUFBYSxJQUFJQyxRQUFRLENBQUNXLE1BQTFCO0FBQ0Q7QUFDRixPQVptQyxDQWNwQzs7O0FBQ0E7O0FBQUE7O0FBQUE7QUFBQTtBQUFBO0FBQUFYLE1BQUFBLFFBQVEsRUFBQ1QsSUFBVDtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQWtCRSxNQUFBQSxLQUFLLENBQUNFLEdBQU4sQ0FBVSxVQUFTQyxLQUFULEVBQWdCO0FBQzFDLGVBQU8sQ0FBQ1EsT0FBTyxDQUFDRyxLQUFSLEdBQWdCLEdBQWhCLEdBQXNCLEdBQXZCLElBQThCWCxLQUFyQztBQUNELE9BRmlCLENBQWxCLEdBZm9DLENBbUJwQzs7O0FBQ0EsVUFBSVEsT0FBTyxDQUFDRyxLQUFaLEVBQW1CO0FBQ2pCTCxRQUFBQSxPQUFPLElBQUlULEtBQUssQ0FBQ2tCLE1BQWpCO0FBQ0QsT0FGRCxNQUVPO0FBQ0xWLFFBQUFBLE9BQU8sSUFBSVIsS0FBSyxDQUFDa0IsTUFBakI7QUFDRDtBQUNGLEtBekJELE1BeUJPO0FBQ0w7QUFDQSxVQUFJYixhQUFKLEVBQW1CO0FBQ2pCO0FBQ0EsWUFBSUwsS0FBSyxDQUFDa0IsTUFBTixJQUFnQnhCLE9BQU8sQ0FBQ0MsT0FBUixHQUFrQixDQUFsQyxJQUF1Q2UsQ0FBQyxHQUFHZCxJQUFJLENBQUNzQixNQUFMLEdBQWMsQ0FBN0QsRUFBZ0U7QUFBQTtBQUFBOztBQUFBO0FBQzlEOztBQUNBOztBQUFBOztBQUFBO0FBQUE7QUFBQTtBQUFBWCxVQUFBQSxRQUFRLEVBQUNULElBQVQ7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFrQkcsVUFBQUEsWUFBWSxDQUFDRCxLQUFELENBQTlCO0FBQ0QsU0FIRCxNQUdPO0FBQUE7QUFBQTs7QUFBQTtBQUNMO0FBQ0EsY0FBSW1CLFdBQVcsR0FBR0MsSUFBSSxDQUFDQyxHQUFMLENBQVNyQixLQUFLLENBQUNrQixNQUFmLEVBQXVCeEIsT0FBTyxDQUFDQyxPQUEvQixDQUFsQjs7QUFDQTs7QUFBQTs7QUFBQTtBQUFBO0FBQUE7QUFBQVksVUFBQUEsUUFBUSxFQUFDVCxJQUFUO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBa0JHLFVBQUFBLFlBQVksQ0FBQ0QsS0FBSyxDQUFDaUIsS0FBTixDQUFZLENBQVosRUFBZUUsV0FBZixDQUFELENBQTlCOztBQUVBLGNBQUlHLElBQUksR0FBRztBQUNUQyxZQUFBQSxRQUFRLEVBQUVsQixhQUREO0FBRVRtQixZQUFBQSxRQUFRLEVBQUdoQixPQUFPLEdBQUdILGFBQVYsR0FBMEJjLFdBRjVCO0FBR1RNLFlBQUFBLFFBQVEsRUFBRW5CLGFBSEQ7QUFJVG9CLFlBQUFBLFFBQVEsRUFBR2pCLE9BQU8sR0FBR0gsYUFBVixHQUEwQmEsV0FKNUI7QUFLVG5CLFlBQUFBLEtBQUssRUFBRU87QUFMRSxXQUFYOztBQU9BLGNBQUlHLENBQUMsSUFBSWQsSUFBSSxDQUFDc0IsTUFBTCxHQUFjLENBQW5CLElBQXdCbEIsS0FBSyxDQUFDa0IsTUFBTixJQUFnQnhCLE9BQU8sQ0FBQ0MsT0FBcEQsRUFBNkQ7QUFDM0Q7QUFDQSxnQkFBSWdDLGFBQWEsR0FBSyxLQUFELENBQVFDLElBQVIsQ0FBYXRDLE1BQWIsQ0FBckI7QUFDQSxnQkFBSXVDLGFBQWEsR0FBSyxLQUFELENBQVFELElBQVIsQ0FBYXJDLE1BQWIsQ0FBckI7QUFDQSxnQkFBSXVDLGNBQWMsR0FBRzlCLEtBQUssQ0FBQ2tCLE1BQU4sSUFBZ0IsQ0FBaEIsSUFBcUJYLFFBQVEsQ0FBQ1csTUFBVCxHQUFrQkksSUFBSSxDQUFDRSxRQUFqRTs7QUFDQSxnQkFBSSxDQUFDRyxhQUFELElBQWtCRyxjQUFsQixJQUFvQ3hDLE1BQU0sQ0FBQzRCLE1BQVAsR0FBZ0IsQ0FBeEQsRUFBMkQ7QUFDekQ7QUFDQTtBQUNBWCxjQUFBQSxRQUFRLENBQUN3QixNQUFULENBQWdCVCxJQUFJLENBQUNFLFFBQXJCLEVBQStCLENBQS9CLEVBQWtDLDhCQUFsQztBQUNEOztBQUNELGdCQUFLLENBQUNHLGFBQUQsSUFBa0IsQ0FBQ0csY0FBcEIsSUFBdUMsQ0FBQ0QsYUFBNUMsRUFBMkQ7QUFDekR0QixjQUFBQSxRQUFRLENBQUNULElBQVQsQ0FBYyw4QkFBZDtBQUNEO0FBQ0Y7O0FBQ0RNLFVBQUFBLEtBQUssQ0FBQ04sSUFBTixDQUFXd0IsSUFBWDtBQUVBakIsVUFBQUEsYUFBYSxHQUFHLENBQWhCO0FBQ0FDLFVBQUFBLGFBQWEsR0FBRyxDQUFoQjtBQUNBQyxVQUFBQSxRQUFRLEdBQUcsRUFBWDtBQUNEO0FBQ0Y7O0FBQ0RDLE1BQUFBLE9BQU8sSUFBSVIsS0FBSyxDQUFDa0IsTUFBakI7QUFDQVQsTUFBQUEsT0FBTyxJQUFJVCxLQUFLLENBQUNrQixNQUFqQjtBQUNEO0FBMUZvRzs7QUFrQnZHLE9BQUssSUFBSVIsQ0FBQyxHQUFHLENBQWIsRUFBZ0JBLENBQUMsR0FBR2QsSUFBSSxDQUFDc0IsTUFBekIsRUFBaUNSLENBQUMsRUFBbEMsRUFBc0M7QUFBQTtBQUFBO0FBQUE7QUFBN0JBLElBQUFBLENBQTZCO0FBeUVyQzs7QUFFRCxTQUFPO0FBQ0x0QixJQUFBQSxXQUFXLEVBQUVBLFdBRFI7QUFDcUJDLElBQUFBLFdBQVcsRUFBRUEsV0FEbEM7QUFFTEcsSUFBQUEsU0FBUyxFQUFFQSxTQUZOO0FBRWlCQyxJQUFBQSxTQUFTLEVBQUVBLFNBRjVCO0FBR0xXLElBQUFBLEtBQUssRUFBRUE7QUFIRixHQUFQO0FBS0Q7O0FBRU0sU0FBUzRCLFdBQVQsQ0FBcUJwQyxJQUFyQixFQUEyQjtBQUNoQyxNQUFNcUMsR0FBRyxHQUFHLEVBQVo7O0FBQ0EsTUFBSXJDLElBQUksQ0FBQ1IsV0FBTCxJQUFvQlEsSUFBSSxDQUFDUCxXQUE3QixFQUEwQztBQUN4QzRDLElBQUFBLEdBQUcsQ0FBQ25DLElBQUosQ0FBUyxZQUFZRixJQUFJLENBQUNSLFdBQTFCO0FBQ0Q7O0FBQ0Q2QyxFQUFBQSxHQUFHLENBQUNuQyxJQUFKLENBQVMscUVBQVQ7QUFDQW1DLEVBQUFBLEdBQUcsQ0FBQ25DLElBQUosQ0FBUyxTQUFTRixJQUFJLENBQUNSLFdBQWQsSUFBNkIsT0FBT1EsSUFBSSxDQUFDSixTQUFaLEtBQTBCLFdBQTFCLEdBQXdDLEVBQXhDLEdBQTZDLE9BQU9JLElBQUksQ0FBQ0osU0FBdEYsQ0FBVDtBQUNBeUMsRUFBQUEsR0FBRyxDQUFDbkMsSUFBSixDQUFTLFNBQVNGLElBQUksQ0FBQ1AsV0FBZCxJQUE2QixPQUFPTyxJQUFJLENBQUNILFNBQVosS0FBMEIsV0FBMUIsR0FBd0MsRUFBeEMsR0FBNkMsT0FBT0csSUFBSSxDQUFDSCxTQUF0RixDQUFUOztBQUVBLE9BQUssSUFBSWlCLENBQUMsR0FBRyxDQUFiLEVBQWdCQSxDQUFDLEdBQUdkLElBQUksQ0FBQ1EsS0FBTCxDQUFXYyxNQUEvQixFQUF1Q1IsQ0FBQyxFQUF4QyxFQUE0QztBQUMxQyxRQUFNWSxJQUFJLEdBQUcxQixJQUFJLENBQUNRLEtBQUwsQ0FBV00sQ0FBWCxDQUFiLENBRDBDLENBRTFDO0FBQ0E7QUFDQTs7QUFDQSxRQUFJWSxJQUFJLENBQUNFLFFBQUwsS0FBa0IsQ0FBdEIsRUFBeUI7QUFDdkJGLE1BQUFBLElBQUksQ0FBQ0MsUUFBTCxJQUFpQixDQUFqQjtBQUNEOztBQUNELFFBQUlELElBQUksQ0FBQ0ksUUFBTCxLQUFrQixDQUF0QixFQUF5QjtBQUN2QkosTUFBQUEsSUFBSSxDQUFDRyxRQUFMLElBQWlCLENBQWpCO0FBQ0Q7O0FBQ0RRLElBQUFBLEdBQUcsQ0FBQ25DLElBQUosQ0FDRSxTQUFTd0IsSUFBSSxDQUFDQyxRQUFkLEdBQXlCLEdBQXpCLEdBQStCRCxJQUFJLENBQUNFLFFBQXBDLEdBQ0UsSUFERixHQUNTRixJQUFJLENBQUNHLFFBRGQsR0FDeUIsR0FEekIsR0FDK0JILElBQUksQ0FBQ0ksUUFEcEMsR0FFRSxLQUhKO0FBS0FPLElBQUFBLEdBQUcsQ0FBQ25DLElBQUosQ0FBU29DLEtBQVQsQ0FBZUQsR0FBZixFQUFvQlgsSUFBSSxDQUFDdEIsS0FBekI7QUFDRDs7QUFFRCxTQUFPaUMsR0FBRyxDQUFDRSxJQUFKLENBQVMsSUFBVCxJQUFpQixJQUF4QjtBQUNEOztBQUVNLFNBQVNDLG1CQUFULENBQTZCaEQsV0FBN0IsRUFBMENDLFdBQTFDLEVBQXVEQyxNQUF2RCxFQUErREMsTUFBL0QsRUFBdUVDLFNBQXZFLEVBQWtGQyxTQUFsRixFQUE2RkMsT0FBN0YsRUFBc0c7QUFDM0csU0FBT3NDLFdBQVcsQ0FBQzdDLGVBQWUsQ0FBQ0MsV0FBRCxFQUFjQyxXQUFkLEVBQTJCQyxNQUEzQixFQUFtQ0MsTUFBbkMsRUFBMkNDLFNBQTNDLEVBQXNEQyxTQUF0RCxFQUFpRUMsT0FBakUsQ0FBaEIsQ0FBbEI7QUFDRDs7QUFFTSxTQUFTMkMsV0FBVCxDQUFxQkMsUUFBckIsRUFBK0JoRCxNQUEvQixFQUF1Q0MsTUFBdkMsRUFBK0NDLFNBQS9DLEVBQTBEQyxTQUExRCxFQUFxRUMsT0FBckUsRUFBOEU7QUFDbkYsU0FBTzBDLG1CQUFtQixDQUFDRSxRQUFELEVBQVdBLFFBQVgsRUFBcUJoRCxNQUFyQixFQUE2QkMsTUFBN0IsRUFBcUNDLFNBQXJDLEVBQWdEQyxTQUFoRCxFQUEyREMsT0FBM0QsQ0FBMUI7QUFDRCIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7ZGlmZkxpbmVzfSBmcm9tICcuLi9kaWZmL2xpbmUnO1xuXG5leHBvcnQgZnVuY3Rpb24gc3RydWN0dXJlZFBhdGNoKG9sZEZpbGVOYW1lLCBuZXdGaWxlTmFtZSwgb2xkU3RyLCBuZXdTdHIsIG9sZEhlYWRlciwgbmV3SGVhZGVyLCBvcHRpb25zKSB7XG4gIGlmICghb3B0aW9ucykge1xuICAgIG9wdGlvbnMgPSB7fTtcbiAgfVxuICBpZiAodHlwZW9mIG9wdGlvbnMuY29udGV4dCA9PT0gJ3VuZGVmaW5lZCcpIHtcbiAgICBvcHRpb25zLmNvbnRleHQgPSA0O1xuICB9XG5cbiAgY29uc3QgZGlmZiA9IGRpZmZMaW5lcyhvbGRTdHIsIG5ld1N0ciwgb3B0aW9ucyk7XG4gIGRpZmYucHVzaCh7dmFsdWU6ICcnLCBsaW5lczogW119KTsgLy8gQXBwZW5kIGFuIGVtcHR5IHZhbHVlIHRvIG1ha2UgY2xlYW51cCBlYXNpZXJcblxuICBmdW5jdGlvbiBjb250ZXh0TGluZXMobGluZXMpIHtcbiAgICByZXR1cm4gbGluZXMubWFwKGZ1bmN0aW9uKGVudHJ5KSB7IHJldHVybiAnICcgKyBlbnRyeTsgfSk7XG4gIH1cblxuICBsZXQgaHVua3MgPSBbXTtcbiAgbGV0IG9sZFJhbmdlU3RhcnQgPSAwLCBuZXdSYW5nZVN0YXJ0ID0gMCwgY3VyUmFuZ2UgPSBbXSxcbiAgICAgIG9sZExpbmUgPSAxLCBuZXdMaW5lID0gMTtcbiAgZm9yIChsZXQgaSA9IDA7IGkgPCBkaWZmLmxlbmd0aDsgaSsrKSB7XG4gICAgY29uc3QgY3VycmVudCA9IGRpZmZbaV0sXG4gICAgICAgICAgbGluZXMgPSBjdXJyZW50LmxpbmVzIHx8IGN1cnJlbnQudmFsdWUucmVwbGFjZSgvXFxuJC8sICcnKS5zcGxpdCgnXFxuJyk7XG4gICAgY3VycmVudC5saW5lcyA9IGxpbmVzO1xuXG4gICAgaWYgKGN1cnJlbnQuYWRkZWQgfHwgY3VycmVudC5yZW1vdmVkKSB7XG4gICAgICAvLyBJZiB3ZSBoYXZlIHByZXZpb3VzIGNvbnRleHQsIHN0YXJ0IHdpdGggdGhhdFxuICAgICAgaWYgKCFvbGRSYW5nZVN0YXJ0KSB7XG4gICAgICAgIGNvbnN0IHByZXYgPSBkaWZmW2kgLSAxXTtcbiAgICAgICAgb2xkUmFuZ2VTdGFydCA9IG9sZExpbmU7XG4gICAgICAgIG5ld1JhbmdlU3RhcnQgPSBuZXdMaW5lO1xuXG4gICAgICAgIGlmIChwcmV2KSB7XG4gICAgICAgICAgY3VyUmFuZ2UgPSBvcHRpb25zLmNvbnRleHQgPiAwID8gY29udGV4dExpbmVzKHByZXYubGluZXMuc2xpY2UoLW9wdGlvbnMuY29udGV4dCkpIDogW107XG4gICAgICAgICAgb2xkUmFuZ2VTdGFydCAtPSBjdXJSYW5nZS5sZW5ndGg7XG4gICAgICAgICAgbmV3UmFuZ2VTdGFydCAtPSBjdXJSYW5nZS5sZW5ndGg7XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgLy8gT3V0cHV0IG91ciBjaGFuZ2VzXG4gICAgICBjdXJSYW5nZS5wdXNoKC4uLiBsaW5lcy5tYXAoZnVuY3Rpb24oZW50cnkpIHtcbiAgICAgICAgcmV0dXJuIChjdXJyZW50LmFkZGVkID8gJysnIDogJy0nKSArIGVudHJ5O1xuICAgICAgfSkpO1xuXG4gICAgICAvLyBUcmFjayB0aGUgdXBkYXRlZCBmaWxlIHBvc2l0aW9uXG4gICAgICBpZiAoY3VycmVudC5hZGRlZCkge1xuICAgICAgICBuZXdMaW5lICs9IGxpbmVzLmxlbmd0aDtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIG9sZExpbmUgKz0gbGluZXMubGVuZ3RoO1xuICAgICAgfVxuICAgIH0gZWxzZSB7XG4gICAgICAvLyBJZGVudGljYWwgY29udGV4dCBsaW5lcy4gVHJhY2sgbGluZSBjaGFuZ2VzXG4gICAgICBpZiAob2xkUmFuZ2VTdGFydCkge1xuICAgICAgICAvLyBDbG9zZSBvdXQgYW55IGNoYW5nZXMgdGhhdCBoYXZlIGJlZW4gb3V0cHV0IChvciBqb2luIG92ZXJsYXBwaW5nKVxuICAgICAgICBpZiAobGluZXMubGVuZ3RoIDw9IG9wdGlvbnMuY29udGV4dCAqIDIgJiYgaSA8IGRpZmYubGVuZ3RoIC0gMikge1xuICAgICAgICAgIC8vIE92ZXJsYXBwaW5nXG4gICAgICAgICAgY3VyUmFuZ2UucHVzaCguLi4gY29udGV4dExpbmVzKGxpbmVzKSk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgLy8gZW5kIHRoZSByYW5nZSBhbmQgb3V0cHV0XG4gICAgICAgICAgbGV0IGNvbnRleHRTaXplID0gTWF0aC5taW4obGluZXMubGVuZ3RoLCBvcHRpb25zLmNvbnRleHQpO1xuICAgICAgICAgIGN1clJhbmdlLnB1c2goLi4uIGNvbnRleHRMaW5lcyhsaW5lcy5zbGljZSgwLCBjb250ZXh0U2l6ZSkpKTtcblxuICAgICAgICAgIGxldCBodW5rID0ge1xuICAgICAgICAgICAgb2xkU3RhcnQ6IG9sZFJhbmdlU3RhcnQsXG4gICAgICAgICAgICBvbGRMaW5lczogKG9sZExpbmUgLSBvbGRSYW5nZVN0YXJ0ICsgY29udGV4dFNpemUpLFxuICAgICAgICAgICAgbmV3U3RhcnQ6IG5ld1JhbmdlU3RhcnQsXG4gICAgICAgICAgICBuZXdMaW5lczogKG5ld0xpbmUgLSBuZXdSYW5nZVN0YXJ0ICsgY29udGV4dFNpemUpLFxuICAgICAgICAgICAgbGluZXM6IGN1clJhbmdlXG4gICAgICAgICAgfTtcbiAgICAgICAgICBpZiAoaSA+PSBkaWZmLmxlbmd0aCAtIDIgJiYgbGluZXMubGVuZ3RoIDw9IG9wdGlvbnMuY29udGV4dCkge1xuICAgICAgICAgICAgLy8gRU9GIGlzIGluc2lkZSB0aGlzIGh1bmtcbiAgICAgICAgICAgIGxldCBvbGRFT0ZOZXdsaW5lID0gKCgvXFxuJC8pLnRlc3Qob2xkU3RyKSk7XG4gICAgICAgICAgICBsZXQgbmV3RU9GTmV3bGluZSA9ICgoL1xcbiQvKS50ZXN0KG5ld1N0cikpO1xuICAgICAgICAgICAgbGV0IG5vTmxCZWZvcmVBZGRzID0gbGluZXMubGVuZ3RoID09IDAgJiYgY3VyUmFuZ2UubGVuZ3RoID4gaHVuay5vbGRMaW5lcztcbiAgICAgICAgICAgIGlmICghb2xkRU9GTmV3bGluZSAmJiBub05sQmVmb3JlQWRkcyAmJiBvbGRTdHIubGVuZ3RoID4gMCkge1xuICAgICAgICAgICAgICAvLyBzcGVjaWFsIGNhc2U6IG9sZCBoYXMgbm8gZW9sIGFuZCBubyB0cmFpbGluZyBjb250ZXh0OyBuby1ubCBjYW4gZW5kIHVwIGJlZm9yZSBhZGRzXG4gICAgICAgICAgICAgIC8vIGhvd2V2ZXIsIGlmIHRoZSBvbGQgZmlsZSBpcyBlbXB0eSwgZG8gbm90IG91dHB1dCB0aGUgbm8tbmwgbGluZVxuICAgICAgICAgICAgICBjdXJSYW5nZS5zcGxpY2UoaHVuay5vbGRMaW5lcywgMCwgJ1xcXFwgTm8gbmV3bGluZSBhdCBlbmQgb2YgZmlsZScpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKCghb2xkRU9GTmV3bGluZSAmJiAhbm9ObEJlZm9yZUFkZHMpIHx8ICFuZXdFT0ZOZXdsaW5lKSB7XG4gICAgICAgICAgICAgIGN1clJhbmdlLnB1c2goJ1xcXFwgTm8gbmV3bGluZSBhdCBlbmQgb2YgZmlsZScpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgICBodW5rcy5wdXNoKGh1bmspO1xuXG4gICAgICAgICAgb2xkUmFuZ2VTdGFydCA9IDA7XG4gICAgICAgICAgbmV3UmFuZ2VTdGFydCA9IDA7XG4gICAgICAgICAgY3VyUmFuZ2UgPSBbXTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgb2xkTGluZSArPSBsaW5lcy5sZW5ndGg7XG4gICAgICBuZXdMaW5lICs9IGxpbmVzLmxlbmd0aDtcbiAgICB9XG4gIH1cblxuICByZXR1cm4ge1xuICAgIG9sZEZpbGVOYW1lOiBvbGRGaWxlTmFtZSwgbmV3RmlsZU5hbWU6IG5ld0ZpbGVOYW1lLFxuICAgIG9sZEhlYWRlcjogb2xkSGVhZGVyLCBuZXdIZWFkZXI6IG5ld0hlYWRlcixcbiAgICBodW5rczogaHVua3NcbiAgfTtcbn1cblxuZXhwb3J0IGZ1bmN0aW9uIGZvcm1hdFBhdGNoKGRpZmYpIHtcbiAgY29uc3QgcmV0ID0gW107XG4gIGlmIChkaWZmLm9sZEZpbGVOYW1lID09IGRpZmYubmV3RmlsZU5hbWUpIHtcbiAgICByZXQucHVzaCgnSW5kZXg6ICcgKyBkaWZmLm9sZEZpbGVOYW1lKTtcbiAgfVxuICByZXQucHVzaCgnPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PScpO1xuICByZXQucHVzaCgnLS0tICcgKyBkaWZmLm9sZEZpbGVOYW1lICsgKHR5cGVvZiBkaWZmLm9sZEhlYWRlciA9PT0gJ3VuZGVmaW5lZCcgPyAnJyA6ICdcXHQnICsgZGlmZi5vbGRIZWFkZXIpKTtcbiAgcmV0LnB1c2goJysrKyAnICsgZGlmZi5uZXdGaWxlTmFtZSArICh0eXBlb2YgZGlmZi5uZXdIZWFkZXIgPT09ICd1bmRlZmluZWQnID8gJycgOiAnXFx0JyArIGRpZmYubmV3SGVhZGVyKSk7XG5cbiAgZm9yIChsZXQgaSA9IDA7IGkgPCBkaWZmLmh1bmtzLmxlbmd0aDsgaSsrKSB7XG4gICAgY29uc3QgaHVuayA9IGRpZmYuaHVua3NbaV07XG4gICAgLy8gVW5pZmllZCBEaWZmIEZvcm1hdCBxdWlyazogSWYgdGhlIGNodW5rIHNpemUgaXMgMCxcbiAgICAvLyB0aGUgZmlyc3QgbnVtYmVyIGlzIG9uZSBsb3dlciB0aGFuIG9uZSB3b3VsZCBleHBlY3QuXG4gICAgLy8gaHR0cHM6Ly93d3cuYXJ0aW1hLmNvbS93ZWJsb2dzL3ZpZXdwb3N0LmpzcD90aHJlYWQ9MTY0MjkzXG4gICAgaWYgKGh1bmsub2xkTGluZXMgPT09IDApIHtcbiAgICAgIGh1bmsub2xkU3RhcnQgLT0gMTtcbiAgICB9XG4gICAgaWYgKGh1bmsubmV3TGluZXMgPT09IDApIHtcbiAgICAgIGh1bmsubmV3U3RhcnQgLT0gMTtcbiAgICB9XG4gICAgcmV0LnB1c2goXG4gICAgICAnQEAgLScgKyBodW5rLm9sZFN0YXJ0ICsgJywnICsgaHVuay5vbGRMaW5lc1xuICAgICAgKyAnICsnICsgaHVuay5uZXdTdGFydCArICcsJyArIGh1bmsubmV3TGluZXNcbiAgICAgICsgJyBAQCdcbiAgICApO1xuICAgIHJldC5wdXNoLmFwcGx5KHJldCwgaHVuay5saW5lcyk7XG4gIH1cblxuICByZXR1cm4gcmV0LmpvaW4oJ1xcbicpICsgJ1xcbic7XG59XG5cbmV4cG9ydCBmdW5jdGlvbiBjcmVhdGVUd29GaWxlc1BhdGNoKG9sZEZpbGVOYW1lLCBuZXdGaWxlTmFtZSwgb2xkU3RyLCBuZXdTdHIsIG9sZEhlYWRlciwgbmV3SGVhZGVyLCBvcHRpb25zKSB7XG4gIHJldHVybiBmb3JtYXRQYXRjaChzdHJ1Y3R1cmVkUGF0Y2gob2xkRmlsZU5hbWUsIG5ld0ZpbGVOYW1lLCBvbGRTdHIsIG5ld1N0ciwgb2xkSGVhZGVyLCBuZXdIZWFkZXIsIG9wdGlvbnMpKTtcbn1cblxuZXhwb3J0IGZ1bmN0aW9uIGNyZWF0ZVBhdGNoKGZpbGVOYW1lLCBvbGRTdHIsIG5ld1N0ciwgb2xkSGVhZGVyLCBuZXdIZWFkZXIsIG9wdGlvbnMpIHtcbiAgcmV0dXJuIGNyZWF0ZVR3b0ZpbGVzUGF0Y2goZmlsZU5hbWUsIGZpbGVOYW1lLCBvbGRTdHIsIG5ld1N0ciwgb2xkSGVhZGVyLCBuZXdIZWFkZXIsIG9wdGlvbnMpO1xufVxuIl19
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/patch/merge.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/patch/merge.js
          new file mode 100644
          index 00000000000000..b46faaaba8e8b1
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/patch/merge.js
          @@ -0,0 +1,613 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.calcLineCount = calcLineCount;
          +exports.merge = merge;
          +
          +/*istanbul ignore end*/
          +var
          +/*istanbul ignore start*/
          +_create = require("./create")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_parse = require("./parse")
          +/*istanbul ignore end*/
          +;
          +
          +var
          +/*istanbul ignore start*/
          +_array = require("../util/array")
          +/*istanbul ignore end*/
          +;
          +
          +/*istanbul ignore start*/ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
          +
          +function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
          +
          +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
          +
          +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
          +
          +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
          +
          +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
          +
          +/*istanbul ignore end*/
          +function calcLineCount(hunk) {
          +  /*istanbul ignore start*/
          +  var _calcOldNewLineCount =
          +  /*istanbul ignore end*/
          +  calcOldNewLineCount(hunk.lines),
          +      oldLines = _calcOldNewLineCount.oldLines,
          +      newLines = _calcOldNewLineCount.newLines;
          +
          +  if (oldLines !== undefined) {
          +    hunk.oldLines = oldLines;
          +  } else {
          +    delete hunk.oldLines;
          +  }
          +
          +  if (newLines !== undefined) {
          +    hunk.newLines = newLines;
          +  } else {
          +    delete hunk.newLines;
          +  }
          +}
          +
          +function merge(mine, theirs, base) {
          +  mine = loadPatch(mine, base);
          +  theirs = loadPatch(theirs, base);
          +  var ret = {}; // For index we just let it pass through as it doesn't have any necessary meaning.
          +  // Leaving sanity checks on this to the API consumer that may know more about the
          +  // meaning in their own context.
          +
          +  if (mine.index || theirs.index) {
          +    ret.index = mine.index || theirs.index;
          +  }
          +
          +  if (mine.newFileName || theirs.newFileName) {
          +    if (!fileNameChanged(mine)) {
          +      // No header or no change in ours, use theirs (and ours if theirs does not exist)
          +      ret.oldFileName = theirs.oldFileName || mine.oldFileName;
          +      ret.newFileName = theirs.newFileName || mine.newFileName;
          +      ret.oldHeader = theirs.oldHeader || mine.oldHeader;
          +      ret.newHeader = theirs.newHeader || mine.newHeader;
          +    } else if (!fileNameChanged(theirs)) {
          +      // No header or no change in theirs, use ours
          +      ret.oldFileName = mine.oldFileName;
          +      ret.newFileName = mine.newFileName;
          +      ret.oldHeader = mine.oldHeader;
          +      ret.newHeader = mine.newHeader;
          +    } else {
          +      // Both changed... figure it out
          +      ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
          +      ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
          +      ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
          +      ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
          +    }
          +  }
          +
          +  ret.hunks = [];
          +  var mineIndex = 0,
          +      theirsIndex = 0,
          +      mineOffset = 0,
          +      theirsOffset = 0;
          +
          +  while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
          +    var mineCurrent = mine.hunks[mineIndex] || {
          +      oldStart: Infinity
          +    },
          +        theirsCurrent = theirs.hunks[theirsIndex] || {
          +      oldStart: Infinity
          +    };
          +
          +    if (hunkBefore(mineCurrent, theirsCurrent)) {
          +      // This patch does not overlap with any of the others, yay.
          +      ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
          +      mineIndex++;
          +      theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
          +    } else if (hunkBefore(theirsCurrent, mineCurrent)) {
          +      // This patch does not overlap with any of the others, yay.
          +      ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
          +      theirsIndex++;
          +      mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
          +    } else {
          +      // Overlap, merge as best we can
          +      var mergedHunk = {
          +        oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
          +        oldLines: 0,
          +        newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
          +        newLines: 0,
          +        lines: []
          +      };
          +      mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
          +      theirsIndex++;
          +      mineIndex++;
          +      ret.hunks.push(mergedHunk);
          +    }
          +  }
          +
          +  return ret;
          +}
          +
          +function loadPatch(param, base) {
          +  if (typeof param === 'string') {
          +    if (/^@@/m.test(param) || /^Index:/m.test(param)) {
          +      return (
          +        /*istanbul ignore start*/
          +        (0,
          +        /*istanbul ignore end*/
          +
          +        /*istanbul ignore start*/
          +        _parse
          +        /*istanbul ignore end*/
          +        .
          +        /*istanbul ignore start*/
          +        parsePatch)
          +        /*istanbul ignore end*/
          +        (param)[0]
          +      );
          +    }
          +
          +    if (!base) {
          +      throw new Error('Must provide a base reference or pass in a patch');
          +    }
          +
          +    return (
          +      /*istanbul ignore start*/
          +      (0,
          +      /*istanbul ignore end*/
          +
          +      /*istanbul ignore start*/
          +      _create
          +      /*istanbul ignore end*/
          +      .
          +      /*istanbul ignore start*/
          +      structuredPatch)
          +      /*istanbul ignore end*/
          +      (undefined, undefined, base, param)
          +    );
          +  }
          +
          +  return param;
          +}
          +
          +function fileNameChanged(patch) {
          +  return patch.newFileName && patch.newFileName !== patch.oldFileName;
          +}
          +
          +function selectField(index, mine, theirs) {
          +  if (mine === theirs) {
          +    return mine;
          +  } else {
          +    index.conflict = true;
          +    return {
          +      mine: mine,
          +      theirs: theirs
          +    };
          +  }
          +}
          +
          +function hunkBefore(test, check) {
          +  return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
          +}
          +
          +function cloneHunk(hunk, offset) {
          +  return {
          +    oldStart: hunk.oldStart,
          +    oldLines: hunk.oldLines,
          +    newStart: hunk.newStart + offset,
          +    newLines: hunk.newLines,
          +    lines: hunk.lines
          +  };
          +}
          +
          +function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
          +  // This will generally result in a conflicted hunk, but there are cases where the context
          +  // is the only overlap where we can successfully merge the content here.
          +  var mine = {
          +    offset: mineOffset,
          +    lines: mineLines,
          +    index: 0
          +  },
          +      their = {
          +    offset: theirOffset,
          +    lines: theirLines,
          +    index: 0
          +  }; // Handle any leading content
          +
          +  insertLeading(hunk, mine, their);
          +  insertLeading(hunk, their, mine); // Now in the overlap content. Scan through and select the best changes from each.
          +
          +  while (mine.index < mine.lines.length && their.index < their.lines.length) {
          +    var mineCurrent = mine.lines[mine.index],
          +        theirCurrent = their.lines[their.index];
          +
          +    if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
          +      // Both modified ...
          +      mutualChange(hunk, mine, their);
          +    } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
          +      /*istanbul ignore start*/
          +      var _hunk$lines;
          +
          +      /*istanbul ignore end*/
          +      // Mine inserted
          +
          +      /*istanbul ignore start*/
          +
          +      /*istanbul ignore end*/
          +
          +      /*istanbul ignore start*/
          +      (_hunk$lines =
          +      /*istanbul ignore end*/
          +      hunk.lines).push.apply(
          +      /*istanbul ignore start*/
          +      _hunk$lines
          +      /*istanbul ignore end*/
          +      ,
          +      /*istanbul ignore start*/
          +      _toConsumableArray(
          +      /*istanbul ignore end*/
          +      collectChange(mine)));
          +    } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
          +      /*istanbul ignore start*/
          +      var _hunk$lines2;
          +
          +      /*istanbul ignore end*/
          +      // Theirs inserted
          +
          +      /*istanbul ignore start*/
          +
          +      /*istanbul ignore end*/
          +
          +      /*istanbul ignore start*/
          +      (_hunk$lines2 =
          +      /*istanbul ignore end*/
          +      hunk.lines).push.apply(
          +      /*istanbul ignore start*/
          +      _hunk$lines2
          +      /*istanbul ignore end*/
          +      ,
          +      /*istanbul ignore start*/
          +      _toConsumableArray(
          +      /*istanbul ignore end*/
          +      collectChange(their)));
          +    } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
          +      // Mine removed or edited
          +      removal(hunk, mine, their);
          +    } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
          +      // Their removed or edited
          +      removal(hunk, their, mine, true);
          +    } else if (mineCurrent === theirCurrent) {
          +      // Context identity
          +      hunk.lines.push(mineCurrent);
          +      mine.index++;
          +      their.index++;
          +    } else {
          +      // Context mismatch
          +      conflict(hunk, collectChange(mine), collectChange(their));
          +    }
          +  } // Now push anything that may be remaining
          +
          +
          +  insertTrailing(hunk, mine);
          +  insertTrailing(hunk, their);
          +  calcLineCount(hunk);
          +}
          +
          +function mutualChange(hunk, mine, their) {
          +  var myChanges = collectChange(mine),
          +      theirChanges = collectChange(their);
          +
          +  if (allRemoves(myChanges) && allRemoves(theirChanges)) {
          +    // Special case for remove changes that are supersets of one another
          +    if (
          +    /*istanbul ignore start*/
          +    (0,
          +    /*istanbul ignore end*/
          +
          +    /*istanbul ignore start*/
          +    _array
          +    /*istanbul ignore end*/
          +    .
          +    /*istanbul ignore start*/
          +    arrayStartsWith)
          +    /*istanbul ignore end*/
          +    (myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
          +      /*istanbul ignore start*/
          +      var _hunk$lines3;
          +
          +      /*istanbul ignore end*/
          +
          +      /*istanbul ignore start*/
          +
          +      /*istanbul ignore end*/
          +
          +      /*istanbul ignore start*/
          +      (_hunk$lines3 =
          +      /*istanbul ignore end*/
          +      hunk.lines).push.apply(
          +      /*istanbul ignore start*/
          +      _hunk$lines3
          +      /*istanbul ignore end*/
          +      ,
          +      /*istanbul ignore start*/
          +      _toConsumableArray(
          +      /*istanbul ignore end*/
          +      myChanges));
          +
          +      return;
          +    } else if (
          +    /*istanbul ignore start*/
          +    (0,
          +    /*istanbul ignore end*/
          +
          +    /*istanbul ignore start*/
          +    _array
          +    /*istanbul ignore end*/
          +    .
          +    /*istanbul ignore start*/
          +    arrayStartsWith)
          +    /*istanbul ignore end*/
          +    (theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
          +      /*istanbul ignore start*/
          +      var _hunk$lines4;
          +
          +      /*istanbul ignore end*/
          +
          +      /*istanbul ignore start*/
          +
          +      /*istanbul ignore end*/
          +
          +      /*istanbul ignore start*/
          +      (_hunk$lines4 =
          +      /*istanbul ignore end*/
          +      hunk.lines).push.apply(
          +      /*istanbul ignore start*/
          +      _hunk$lines4
          +      /*istanbul ignore end*/
          +      ,
          +      /*istanbul ignore start*/
          +      _toConsumableArray(
          +      /*istanbul ignore end*/
          +      theirChanges));
          +
          +      return;
          +    }
          +  } else if (
          +  /*istanbul ignore start*/
          +  (0,
          +  /*istanbul ignore end*/
          +
          +  /*istanbul ignore start*/
          +  _array
          +  /*istanbul ignore end*/
          +  .
          +  /*istanbul ignore start*/
          +  arrayEqual)
          +  /*istanbul ignore end*/
          +  (myChanges, theirChanges)) {
          +    /*istanbul ignore start*/
          +    var _hunk$lines5;
          +
          +    /*istanbul ignore end*/
          +
          +    /*istanbul ignore start*/
          +
          +    /*istanbul ignore end*/
          +
          +    /*istanbul ignore start*/
          +    (_hunk$lines5 =
          +    /*istanbul ignore end*/
          +    hunk.lines).push.apply(
          +    /*istanbul ignore start*/
          +    _hunk$lines5
          +    /*istanbul ignore end*/
          +    ,
          +    /*istanbul ignore start*/
          +    _toConsumableArray(
          +    /*istanbul ignore end*/
          +    myChanges));
          +
          +    return;
          +  }
          +
          +  conflict(hunk, myChanges, theirChanges);
          +}
          +
          +function removal(hunk, mine, their, swap) {
          +  var myChanges = collectChange(mine),
          +      theirChanges = collectContext(their, myChanges);
          +
          +  if (theirChanges.merged) {
          +    /*istanbul ignore start*/
          +    var _hunk$lines6;
          +
          +    /*istanbul ignore end*/
          +
          +    /*istanbul ignore start*/
          +
          +    /*istanbul ignore end*/
          +
          +    /*istanbul ignore start*/
          +    (_hunk$lines6 =
          +    /*istanbul ignore end*/
          +    hunk.lines).push.apply(
          +    /*istanbul ignore start*/
          +    _hunk$lines6
          +    /*istanbul ignore end*/
          +    ,
          +    /*istanbul ignore start*/
          +    _toConsumableArray(
          +    /*istanbul ignore end*/
          +    theirChanges.merged));
          +  } else {
          +    conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
          +  }
          +}
          +
          +function conflict(hunk, mine, their) {
          +  hunk.conflict = true;
          +  hunk.lines.push({
          +    conflict: true,
          +    mine: mine,
          +    theirs: their
          +  });
          +}
          +
          +function insertLeading(hunk, insert, their) {
          +  while (insert.offset < their.offset && insert.index < insert.lines.length) {
          +    var line = insert.lines[insert.index++];
          +    hunk.lines.push(line);
          +    insert.offset++;
          +  }
          +}
          +
          +function insertTrailing(hunk, insert) {
          +  while (insert.index < insert.lines.length) {
          +    var line = insert.lines[insert.index++];
          +    hunk.lines.push(line);
          +  }
          +}
          +
          +function collectChange(state) {
          +  var ret = [],
          +      operation = state.lines[state.index][0];
          +
          +  while (state.index < state.lines.length) {
          +    var line = state.lines[state.index]; // Group additions that are immediately after subtractions and treat them as one "atomic" modify change.
          +
          +    if (operation === '-' && line[0] === '+') {
          +      operation = '+';
          +    }
          +
          +    if (operation === line[0]) {
          +      ret.push(line);
          +      state.index++;
          +    } else {
          +      break;
          +    }
          +  }
          +
          +  return ret;
          +}
          +
          +function collectContext(state, matchChanges) {
          +  var changes = [],
          +      merged = [],
          +      matchIndex = 0,
          +      contextChanges = false,
          +      conflicted = false;
          +
          +  while (matchIndex < matchChanges.length && state.index < state.lines.length) {
          +    var change = state.lines[state.index],
          +        match = matchChanges[matchIndex]; // Once we've hit our add, then we are done
          +
          +    if (match[0] === '+') {
          +      break;
          +    }
          +
          +    contextChanges = contextChanges || change[0] !== ' ';
          +    merged.push(match);
          +    matchIndex++; // Consume any additions in the other block as a conflict to attempt
          +    // to pull in the remaining context after this
          +
          +    if (change[0] === '+') {
          +      conflicted = true;
          +
          +      while (change[0] === '+') {
          +        changes.push(change);
          +        change = state.lines[++state.index];
          +      }
          +    }
          +
          +    if (match.substr(1) === change.substr(1)) {
          +      changes.push(change);
          +      state.index++;
          +    } else {
          +      conflicted = true;
          +    }
          +  }
          +
          +  if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
          +    conflicted = true;
          +  }
          +
          +  if (conflicted) {
          +    return changes;
          +  }
          +
          +  while (matchIndex < matchChanges.length) {
          +    merged.push(matchChanges[matchIndex++]);
          +  }
          +
          +  return {
          +    merged: merged,
          +    changes: changes
          +  };
          +}
          +
          +function allRemoves(changes) {
          +  return changes.reduce(function (prev, change) {
          +    return prev && change[0] === '-';
          +  }, true);
          +}
          +
          +function skipRemoveSuperset(state, removeChanges, delta) {
          +  for (var i = 0; i < delta; i++) {
          +    var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
          +
          +    if (state.lines[state.index + i] !== ' ' + changeContent) {
          +      return false;
          +    }
          +  }
          +
          +  state.index += delta;
          +  return true;
          +}
          +
          +function calcOldNewLineCount(lines) {
          +  var oldLines = 0;
          +  var newLines = 0;
          +  lines.forEach(function (line) {
          +    if (typeof line !== 'string') {
          +      var myCount = calcOldNewLineCount(line.mine);
          +      var theirCount = calcOldNewLineCount(line.theirs);
          +
          +      if (oldLines !== undefined) {
          +        if (myCount.oldLines === theirCount.oldLines) {
          +          oldLines += myCount.oldLines;
          +        } else {
          +          oldLines = undefined;
          +        }
          +      }
          +
          +      if (newLines !== undefined) {
          +        if (myCount.newLines === theirCount.newLines) {
          +          newLines += myCount.newLines;
          +        } else {
          +          newLines = undefined;
          +        }
          +      }
          +    } else {
          +      if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) {
          +        newLines++;
          +      }
          +
          +      if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) {
          +        oldLines++;
          +      }
          +    }
          +  });
          +  return {
          +    oldLines: oldLines,
          +    newLines: newLines
          +  };
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wYXRjaC9tZXJnZS5qcyJdLCJuYW1lcyI6WyJjYWxjTGluZUNvdW50IiwiaHVuayIsImNhbGNPbGROZXdMaW5lQ291bnQiLCJsaW5lcyIsIm9sZExpbmVzIiwibmV3TGluZXMiLCJ1bmRlZmluZWQiLCJtZXJnZSIsIm1pbmUiLCJ0aGVpcnMiLCJiYXNlIiwibG9hZFBhdGNoIiwicmV0IiwiaW5kZXgiLCJuZXdGaWxlTmFtZSIsImZpbGVOYW1lQ2hhbmdlZCIsIm9sZEZpbGVOYW1lIiwib2xkSGVhZGVyIiwibmV3SGVhZGVyIiwic2VsZWN0RmllbGQiLCJodW5rcyIsIm1pbmVJbmRleCIsInRoZWlyc0luZGV4IiwibWluZU9mZnNldCIsInRoZWlyc09mZnNldCIsImxlbmd0aCIsIm1pbmVDdXJyZW50Iiwib2xkU3RhcnQiLCJJbmZpbml0eSIsInRoZWlyc0N1cnJlbnQiLCJodW5rQmVmb3JlIiwicHVzaCIsImNsb25lSHVuayIsIm1lcmdlZEh1bmsiLCJNYXRoIiwibWluIiwibmV3U3RhcnQiLCJtZXJnZUxpbmVzIiwicGFyYW0iLCJ0ZXN0IiwicGFyc2VQYXRjaCIsIkVycm9yIiwic3RydWN0dXJlZFBhdGNoIiwicGF0Y2giLCJjb25mbGljdCIsImNoZWNrIiwib2Zmc2V0IiwibWluZUxpbmVzIiwidGhlaXJPZmZzZXQiLCJ0aGVpckxpbmVzIiwidGhlaXIiLCJpbnNlcnRMZWFkaW5nIiwidGhlaXJDdXJyZW50IiwibXV0dWFsQ2hhbmdlIiwiY29sbGVjdENoYW5nZSIsInJlbW92YWwiLCJpbnNlcnRUcmFpbGluZyIsIm15Q2hhbmdlcyIsInRoZWlyQ2hhbmdlcyIsImFsbFJlbW92ZXMiLCJhcnJheVN0YXJ0c1dpdGgiLCJza2lwUmVtb3ZlU3VwZXJzZXQiLCJhcnJheUVxdWFsIiwic3dhcCIsImNvbGxlY3RDb250ZXh0IiwibWVyZ2VkIiwiaW5zZXJ0IiwibGluZSIsInN0YXRlIiwib3BlcmF0aW9uIiwibWF0Y2hDaGFuZ2VzIiwiY2hhbmdlcyIsIm1hdGNoSW5kZXgiLCJjb250ZXh0Q2hhbmdlcyIsImNvbmZsaWN0ZWQiLCJjaGFuZ2UiLCJtYXRjaCIsInN1YnN0ciIsInJlZHVjZSIsInByZXYiLCJyZW1vdmVDaGFuZ2VzIiwiZGVsdGEiLCJpIiwiY2hhbmdlQ29udGVudCIsImZvckVhY2giLCJteUNvdW50IiwidGhlaXJDb3VudCJdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7O0FBQ0E7QUFBQTtBQUFBO0FBQUE7QUFBQTs7QUFFQTtBQUFBO0FBQUE7QUFBQTtBQUFBOzs7Ozs7Ozs7Ozs7Ozs7QUFFTyxTQUFTQSxhQUFULENBQXVCQyxJQUF2QixFQUE2QjtBQUFBO0FBQUE7QUFBQTtBQUNMQyxFQUFBQSxtQkFBbUIsQ0FBQ0QsSUFBSSxDQUFDRSxLQUFOLENBRGQ7QUFBQSxNQUMzQkMsUUFEMkIsd0JBQzNCQSxRQUQyQjtBQUFBLE1BQ2pCQyxRQURpQix3QkFDakJBLFFBRGlCOztBQUdsQyxNQUFJRCxRQUFRLEtBQUtFLFNBQWpCLEVBQTRCO0FBQzFCTCxJQUFBQSxJQUFJLENBQUNHLFFBQUwsR0FBZ0JBLFFBQWhCO0FBQ0QsR0FGRCxNQUVPO0FBQ0wsV0FBT0gsSUFBSSxDQUFDRyxRQUFaO0FBQ0Q7O0FBRUQsTUFBSUMsUUFBUSxLQUFLQyxTQUFqQixFQUE0QjtBQUMxQkwsSUFBQUEsSUFBSSxDQUFDSSxRQUFMLEdBQWdCQSxRQUFoQjtBQUNELEdBRkQsTUFFTztBQUNMLFdBQU9KLElBQUksQ0FBQ0ksUUFBWjtBQUNEO0FBQ0Y7O0FBRU0sU0FBU0UsS0FBVCxDQUFlQyxJQUFmLEVBQXFCQyxNQUFyQixFQUE2QkMsSUFBN0IsRUFBbUM7QUFDeENGLEVBQUFBLElBQUksR0FBR0csU0FBUyxDQUFDSCxJQUFELEVBQU9FLElBQVAsQ0FBaEI7QUFDQUQsRUFBQUEsTUFBTSxHQUFHRSxTQUFTLENBQUNGLE1BQUQsRUFBU0MsSUFBVCxDQUFsQjtBQUVBLE1BQUlFLEdBQUcsR0FBRyxFQUFWLENBSndDLENBTXhDO0FBQ0E7QUFDQTs7QUFDQSxNQUFJSixJQUFJLENBQUNLLEtBQUwsSUFBY0osTUFBTSxDQUFDSSxLQUF6QixFQUFnQztBQUM5QkQsSUFBQUEsR0FBRyxDQUFDQyxLQUFKLEdBQVlMLElBQUksQ0FBQ0ssS0FBTCxJQUFjSixNQUFNLENBQUNJLEtBQWpDO0FBQ0Q7O0FBRUQsTUFBSUwsSUFBSSxDQUFDTSxXQUFMLElBQW9CTCxNQUFNLENBQUNLLFdBQS9CLEVBQTRDO0FBQzFDLFFBQUksQ0FBQ0MsZUFBZSxDQUFDUCxJQUFELENBQXBCLEVBQTRCO0FBQzFCO0FBQ0FJLE1BQUFBLEdBQUcsQ0FBQ0ksV0FBSixHQUFrQlAsTUFBTSxDQUFDTyxXQUFQLElBQXNCUixJQUFJLENBQUNRLFdBQTdDO0FBQ0FKLE1BQUFBLEdBQUcsQ0FBQ0UsV0FBSixHQUFrQkwsTUFBTSxDQUFDSyxXQUFQLElBQXNCTixJQUFJLENBQUNNLFdBQTdDO0FBQ0FGLE1BQUFBLEdBQUcsQ0FBQ0ssU0FBSixHQUFnQlIsTUFBTSxDQUFDUSxTQUFQLElBQW9CVCxJQUFJLENBQUNTLFNBQXpDO0FBQ0FMLE1BQUFBLEdBQUcsQ0FBQ00sU0FBSixHQUFnQlQsTUFBTSxDQUFDUyxTQUFQLElBQW9CVixJQUFJLENBQUNVLFNBQXpDO0FBQ0QsS0FORCxNQU1PLElBQUksQ0FBQ0gsZUFBZSxDQUFDTixNQUFELENBQXBCLEVBQThCO0FBQ25DO0FBQ0FHLE1BQUFBLEdBQUcsQ0FBQ0ksV0FBSixHQUFrQlIsSUFBSSxDQUFDUSxXQUF2QjtBQUNBSixNQUFBQSxHQUFHLENBQUNFLFdBQUosR0FBa0JOLElBQUksQ0FBQ00sV0FBdkI7QUFDQUYsTUFBQUEsR0FBRyxDQUFDSyxTQUFKLEdBQWdCVCxJQUFJLENBQUNTLFNBQXJCO0FBQ0FMLE1BQUFBLEdBQUcsQ0FBQ00sU0FBSixHQUFnQlYsSUFBSSxDQUFDVSxTQUFyQjtBQUNELEtBTk0sTUFNQTtBQUNMO0FBQ0FOLE1BQUFBLEdBQUcsQ0FBQ0ksV0FBSixHQUFrQkcsV0FBVyxDQUFDUCxHQUFELEVBQU1KLElBQUksQ0FBQ1EsV0FBWCxFQUF3QlAsTUFBTSxDQUFDTyxXQUEvQixDQUE3QjtBQUNBSixNQUFBQSxHQUFHLENBQUNFLFdBQUosR0FBa0JLLFdBQVcsQ0FBQ1AsR0FBRCxFQUFNSixJQUFJLENBQUNNLFdBQVgsRUFBd0JMLE1BQU0sQ0FBQ0ssV0FBL0IsQ0FBN0I7QUFDQUYsTUFBQUEsR0FBRyxDQUFDSyxTQUFKLEdBQWdCRSxXQUFXLENBQUNQLEdBQUQsRUFBTUosSUFBSSxDQUFDUyxTQUFYLEVBQXNCUixNQUFNLENBQUNRLFNBQTdCLENBQTNCO0FBQ0FMLE1BQUFBLEdBQUcsQ0FBQ00sU0FBSixHQUFnQkMsV0FBVyxDQUFDUCxHQUFELEVBQU1KLElBQUksQ0FBQ1UsU0FBWCxFQUFzQlQsTUFBTSxDQUFDUyxTQUE3QixDQUEzQjtBQUNEO0FBQ0Y7O0FBRUROLEVBQUFBLEdBQUcsQ0FBQ1EsS0FBSixHQUFZLEVBQVo7QUFFQSxNQUFJQyxTQUFTLEdBQUcsQ0FBaEI7QUFBQSxNQUNJQyxXQUFXLEdBQUcsQ0FEbEI7QUFBQSxNQUVJQyxVQUFVLEdBQUcsQ0FGakI7QUFBQSxNQUdJQyxZQUFZLEdBQUcsQ0FIbkI7O0FBS0EsU0FBT0gsU0FBUyxHQUFHYixJQUFJLENBQUNZLEtBQUwsQ0FBV0ssTUFBdkIsSUFBaUNILFdBQVcsR0FBR2IsTUFBTSxDQUFDVyxLQUFQLENBQWFLLE1BQW5FLEVBQTJFO0FBQ3pFLFFBQUlDLFdBQVcsR0FBR2xCLElBQUksQ0FBQ1ksS0FBTCxDQUFXQyxTQUFYLEtBQXlCO0FBQUNNLE1BQUFBLFFBQVEsRUFBRUM7QUFBWCxLQUEzQztBQUFBLFFBQ0lDLGFBQWEsR0FBR3BCLE1BQU0sQ0FBQ1csS0FBUCxDQUFhRSxXQUFiLEtBQTZCO0FBQUNLLE1BQUFBLFFBQVEsRUFBRUM7QUFBWCxLQURqRDs7QUFHQSxRQUFJRSxVQUFVLENBQUNKLFdBQUQsRUFBY0csYUFBZCxDQUFkLEVBQTRDO0FBQzFDO0FBQ0FqQixNQUFBQSxHQUFHLENBQUNRLEtBQUosQ0FBVVcsSUFBVixDQUFlQyxTQUFTLENBQUNOLFdBQUQsRUFBY0gsVUFBZCxDQUF4QjtBQUNBRixNQUFBQSxTQUFTO0FBQ1RHLE1BQUFBLFlBQVksSUFBSUUsV0FBVyxDQUFDckIsUUFBWixHQUF1QnFCLFdBQVcsQ0FBQ3RCLFFBQW5EO0FBQ0QsS0FMRCxNQUtPLElBQUkwQixVQUFVLENBQUNELGFBQUQsRUFBZ0JILFdBQWhCLENBQWQsRUFBNEM7QUFDakQ7QUFDQWQsTUFBQUEsR0FBRyxDQUFDUSxLQUFKLENBQVVXLElBQVYsQ0FBZUMsU0FBUyxDQUFDSCxhQUFELEVBQWdCTCxZQUFoQixDQUF4QjtBQUNBRixNQUFBQSxXQUFXO0FBQ1hDLE1BQUFBLFVBQVUsSUFBSU0sYUFBYSxDQUFDeEIsUUFBZCxHQUF5QndCLGFBQWEsQ0FBQ3pCLFFBQXJEO0FBQ0QsS0FMTSxNQUtBO0FBQ0w7QUFDQSxVQUFJNkIsVUFBVSxHQUFHO0FBQ2ZOLFFBQUFBLFFBQVEsRUFBRU8sSUFBSSxDQUFDQyxHQUFMLENBQVNULFdBQVcsQ0FBQ0MsUUFBckIsRUFBK0JFLGFBQWEsQ0FBQ0YsUUFBN0MsQ0FESztBQUVmdkIsUUFBQUEsUUFBUSxFQUFFLENBRks7QUFHZmdDLFFBQUFBLFFBQVEsRUFBRUYsSUFBSSxDQUFDQyxHQUFMLENBQVNULFdBQVcsQ0FBQ1UsUUFBWixHQUF1QmIsVUFBaEMsRUFBNENNLGFBQWEsQ0FBQ0YsUUFBZCxHQUF5QkgsWUFBckUsQ0FISztBQUlmbkIsUUFBQUEsUUFBUSxFQUFFLENBSks7QUFLZkYsUUFBQUEsS0FBSyxFQUFFO0FBTFEsT0FBakI7QUFPQWtDLE1BQUFBLFVBQVUsQ0FBQ0osVUFBRCxFQUFhUCxXQUFXLENBQUNDLFFBQXpCLEVBQW1DRCxXQUFXLENBQUN2QixLQUEvQyxFQUFzRDBCLGFBQWEsQ0FBQ0YsUUFBcEUsRUFBOEVFLGFBQWEsQ0FBQzFCLEtBQTVGLENBQVY7QUFDQW1CLE1BQUFBLFdBQVc7QUFDWEQsTUFBQUEsU0FBUztBQUVUVCxNQUFBQSxHQUFHLENBQUNRLEtBQUosQ0FBVVcsSUFBVixDQUFlRSxVQUFmO0FBQ0Q7QUFDRjs7QUFFRCxTQUFPckIsR0FBUDtBQUNEOztBQUVELFNBQVNELFNBQVQsQ0FBbUIyQixLQUFuQixFQUEwQjVCLElBQTFCLEVBQWdDO0FBQzlCLE1BQUksT0FBTzRCLEtBQVAsS0FBaUIsUUFBckIsRUFBK0I7QUFDN0IsUUFBSyxNQUFELENBQVNDLElBQVQsQ0FBY0QsS0FBZCxLQUEwQixVQUFELENBQWFDLElBQWIsQ0FBa0JELEtBQWxCLENBQTdCLEVBQXdEO0FBQ3RELGFBQU87QUFBQTtBQUFBO0FBQUE7O0FBQUFFO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUE7QUFBQSxTQUFXRixLQUFYLEVBQWtCLENBQWxCO0FBQVA7QUFDRDs7QUFFRCxRQUFJLENBQUM1QixJQUFMLEVBQVc7QUFDVCxZQUFNLElBQUkrQixLQUFKLENBQVUsa0RBQVYsQ0FBTjtBQUNEOztBQUNELFdBQU87QUFBQTtBQUFBO0FBQUE7O0FBQUFDO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUE7QUFBQSxPQUFnQnBDLFNBQWhCLEVBQTJCQSxTQUEzQixFQUFzQ0ksSUFBdEMsRUFBNEM0QixLQUE1QztBQUFQO0FBQ0Q7O0FBRUQsU0FBT0EsS0FBUDtBQUNEOztBQUVELFNBQVN2QixlQUFULENBQXlCNEIsS0FBekIsRUFBZ0M7QUFDOUIsU0FBT0EsS0FBSyxDQUFDN0IsV0FBTixJQUFxQjZCLEtBQUssQ0FBQzdCLFdBQU4sS0FBc0I2QixLQUFLLENBQUMzQixXQUF4RDtBQUNEOztBQUVELFNBQVNHLFdBQVQsQ0FBcUJOLEtBQXJCLEVBQTRCTCxJQUE1QixFQUFrQ0MsTUFBbEMsRUFBMEM7QUFDeEMsTUFBSUQsSUFBSSxLQUFLQyxNQUFiLEVBQXFCO0FBQ25CLFdBQU9ELElBQVA7QUFDRCxHQUZELE1BRU87QUFDTEssSUFBQUEsS0FBSyxDQUFDK0IsUUFBTixHQUFpQixJQUFqQjtBQUNBLFdBQU87QUFBQ3BDLE1BQUFBLElBQUksRUFBSkEsSUFBRDtBQUFPQyxNQUFBQSxNQUFNLEVBQU5BO0FBQVAsS0FBUDtBQUNEO0FBQ0Y7O0FBRUQsU0FBU3FCLFVBQVQsQ0FBb0JTLElBQXBCLEVBQTBCTSxLQUExQixFQUFpQztBQUMvQixTQUFPTixJQUFJLENBQUNaLFFBQUwsR0FBZ0JrQixLQUFLLENBQUNsQixRQUF0QixJQUNEWSxJQUFJLENBQUNaLFFBQUwsR0FBZ0JZLElBQUksQ0FBQ25DLFFBQXRCLEdBQWtDeUMsS0FBSyxDQUFDbEIsUUFEN0M7QUFFRDs7QUFFRCxTQUFTSyxTQUFULENBQW1CL0IsSUFBbkIsRUFBeUI2QyxNQUF6QixFQUFpQztBQUMvQixTQUFPO0FBQ0xuQixJQUFBQSxRQUFRLEVBQUUxQixJQUFJLENBQUMwQixRQURWO0FBQ29CdkIsSUFBQUEsUUFBUSxFQUFFSCxJQUFJLENBQUNHLFFBRG5DO0FBRUxnQyxJQUFBQSxRQUFRLEVBQUVuQyxJQUFJLENBQUNtQyxRQUFMLEdBQWdCVSxNQUZyQjtBQUU2QnpDLElBQUFBLFFBQVEsRUFBRUosSUFBSSxDQUFDSSxRQUY1QztBQUdMRixJQUFBQSxLQUFLLEVBQUVGLElBQUksQ0FBQ0U7QUFIUCxHQUFQO0FBS0Q7O0FBRUQsU0FBU2tDLFVBQVQsQ0FBb0JwQyxJQUFwQixFQUEwQnNCLFVBQTFCLEVBQXNDd0IsU0FBdEMsRUFBaURDLFdBQWpELEVBQThEQyxVQUE5RCxFQUEwRTtBQUN4RTtBQUNBO0FBQ0EsTUFBSXpDLElBQUksR0FBRztBQUFDc0MsSUFBQUEsTUFBTSxFQUFFdkIsVUFBVDtBQUFxQnBCLElBQUFBLEtBQUssRUFBRTRDLFNBQTVCO0FBQXVDbEMsSUFBQUEsS0FBSyxFQUFFO0FBQTlDLEdBQVg7QUFBQSxNQUNJcUMsS0FBSyxHQUFHO0FBQUNKLElBQUFBLE1BQU0sRUFBRUUsV0FBVDtBQUFzQjdDLElBQUFBLEtBQUssRUFBRThDLFVBQTdCO0FBQXlDcEMsSUFBQUEsS0FBSyxFQUFFO0FBQWhELEdBRFosQ0FId0UsQ0FNeEU7O0FBQ0FzQyxFQUFBQSxhQUFhLENBQUNsRCxJQUFELEVBQU9PLElBQVAsRUFBYTBDLEtBQWIsQ0FBYjtBQUNBQyxFQUFBQSxhQUFhLENBQUNsRCxJQUFELEVBQU9pRCxLQUFQLEVBQWMxQyxJQUFkLENBQWIsQ0FSd0UsQ0FVeEU7O0FBQ0EsU0FBT0EsSUFBSSxDQUFDSyxLQUFMLEdBQWFMLElBQUksQ0FBQ0wsS0FBTCxDQUFXc0IsTUFBeEIsSUFBa0N5QixLQUFLLENBQUNyQyxLQUFOLEdBQWNxQyxLQUFLLENBQUMvQyxLQUFOLENBQVlzQixNQUFuRSxFQUEyRTtBQUN6RSxRQUFJQyxXQUFXLEdBQUdsQixJQUFJLENBQUNMLEtBQUwsQ0FBV0ssSUFBSSxDQUFDSyxLQUFoQixDQUFsQjtBQUFBLFFBQ0l1QyxZQUFZLEdBQUdGLEtBQUssQ0FBQy9DLEtBQU4sQ0FBWStDLEtBQUssQ0FBQ3JDLEtBQWxCLENBRG5COztBQUdBLFFBQUksQ0FBQ2EsV0FBVyxDQUFDLENBQUQsQ0FBWCxLQUFtQixHQUFuQixJQUEwQkEsV0FBVyxDQUFDLENBQUQsQ0FBWCxLQUFtQixHQUE5QyxNQUNJMEIsWUFBWSxDQUFDLENBQUQsQ0FBWixLQUFvQixHQUFwQixJQUEyQkEsWUFBWSxDQUFDLENBQUQsQ0FBWixLQUFvQixHQURuRCxDQUFKLEVBQzZEO0FBQzNEO0FBQ0FDLE1BQUFBLFlBQVksQ0FBQ3BELElBQUQsRUFBT08sSUFBUCxFQUFhMEMsS0FBYixDQUFaO0FBQ0QsS0FKRCxNQUlPLElBQUl4QixXQUFXLENBQUMsQ0FBRCxDQUFYLEtBQW1CLEdBQW5CLElBQTBCMEIsWUFBWSxDQUFDLENBQUQsQ0FBWixLQUFvQixHQUFsRCxFQUF1RDtBQUFBO0FBQUE7O0FBQUE7QUFDNUQ7O0FBQ0E7O0FBQUE7O0FBQUE7QUFBQTtBQUFBO0FBQUFuRCxNQUFBQSxJQUFJLENBQUNFLEtBQUwsRUFBVzRCLElBQVg7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFvQnVCLE1BQUFBLGFBQWEsQ0FBQzlDLElBQUQsQ0FBakM7QUFDRCxLQUhNLE1BR0EsSUFBSTRDLFlBQVksQ0FBQyxDQUFELENBQVosS0FBb0IsR0FBcEIsSUFBMkIxQixXQUFXLENBQUMsQ0FBRCxDQUFYLEtBQW1CLEdBQWxELEVBQXVEO0FBQUE7QUFBQTs7QUFBQTtBQUM1RDs7QUFDQTs7QUFBQTs7QUFBQTtBQUFBO0FBQUE7QUFBQXpCLE1BQUFBLElBQUksQ0FBQ0UsS0FBTCxFQUFXNEIsSUFBWDtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQW9CdUIsTUFBQUEsYUFBYSxDQUFDSixLQUFELENBQWpDO0FBQ0QsS0FITSxNQUdBLElBQUl4QixXQUFXLENBQUMsQ0FBRCxDQUFYLEtBQW1CLEdBQW5CLElBQTBCMEIsWUFBWSxDQUFDLENBQUQsQ0FBWixLQUFvQixHQUFsRCxFQUF1RDtBQUM1RDtBQUNBRyxNQUFBQSxPQUFPLENBQUN0RCxJQUFELEVBQU9PLElBQVAsRUFBYTBDLEtBQWIsQ0FBUDtBQUNELEtBSE0sTUFHQSxJQUFJRSxZQUFZLENBQUMsQ0FBRCxDQUFaLEtBQW9CLEdBQXBCLElBQTJCMUIsV0FBVyxDQUFDLENBQUQsQ0FBWCxLQUFtQixHQUFsRCxFQUF1RDtBQUM1RDtBQUNBNkIsTUFBQUEsT0FBTyxDQUFDdEQsSUFBRCxFQUFPaUQsS0FBUCxFQUFjMUMsSUFBZCxFQUFvQixJQUFwQixDQUFQO0FBQ0QsS0FITSxNQUdBLElBQUlrQixXQUFXLEtBQUswQixZQUFwQixFQUFrQztBQUN2QztBQUNBbkQsTUFBQUEsSUFBSSxDQUFDRSxLQUFMLENBQVc0QixJQUFYLENBQWdCTCxXQUFoQjtBQUNBbEIsTUFBQUEsSUFBSSxDQUFDSyxLQUFMO0FBQ0FxQyxNQUFBQSxLQUFLLENBQUNyQyxLQUFOO0FBQ0QsS0FMTSxNQUtBO0FBQ0w7QUFDQStCLE1BQUFBLFFBQVEsQ0FBQzNDLElBQUQsRUFBT3FELGFBQWEsQ0FBQzlDLElBQUQsQ0FBcEIsRUFBNEI4QyxhQUFhLENBQUNKLEtBQUQsQ0FBekMsQ0FBUjtBQUNEO0FBQ0YsR0F4Q3VFLENBMEN4RTs7O0FBQ0FNLEVBQUFBLGNBQWMsQ0FBQ3ZELElBQUQsRUFBT08sSUFBUCxDQUFkO0FBQ0FnRCxFQUFBQSxjQUFjLENBQUN2RCxJQUFELEVBQU9pRCxLQUFQLENBQWQ7QUFFQWxELEVBQUFBLGFBQWEsQ0FBQ0MsSUFBRCxDQUFiO0FBQ0Q7O0FBRUQsU0FBU29ELFlBQVQsQ0FBc0JwRCxJQUF0QixFQUE0Qk8sSUFBNUIsRUFBa0MwQyxLQUFsQyxFQUF5QztBQUN2QyxNQUFJTyxTQUFTLEdBQUdILGFBQWEsQ0FBQzlDLElBQUQsQ0FBN0I7QUFBQSxNQUNJa0QsWUFBWSxHQUFHSixhQUFhLENBQUNKLEtBQUQsQ0FEaEM7O0FBR0EsTUFBSVMsVUFBVSxDQUFDRixTQUFELENBQVYsSUFBeUJFLFVBQVUsQ0FBQ0QsWUFBRCxDQUF2QyxFQUF1RDtBQUNyRDtBQUNBO0FBQUk7QUFBQTtBQUFBOztBQUFBRTtBQUFBQTtBQUFBQTtBQUFBQTtBQUFBQTtBQUFBQTtBQUFBO0FBQUEsS0FBZ0JILFNBQWhCLEVBQTJCQyxZQUEzQixLQUNHRyxrQkFBa0IsQ0FBQ1gsS0FBRCxFQUFRTyxTQUFSLEVBQW1CQSxTQUFTLENBQUNoQyxNQUFWLEdBQW1CaUMsWUFBWSxDQUFDakMsTUFBbkQsQ0FEekIsRUFDcUY7QUFBQTtBQUFBOztBQUFBOztBQUNuRjs7QUFBQTs7QUFBQTtBQUFBO0FBQUE7QUFBQXhCLE1BQUFBLElBQUksQ0FBQ0UsS0FBTCxFQUFXNEIsSUFBWDtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQW9CMEIsTUFBQUEsU0FBcEI7O0FBQ0E7QUFDRCxLQUpELE1BSU87QUFBSTtBQUFBO0FBQUE7O0FBQUFHO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUE7QUFBQSxLQUFnQkYsWUFBaEIsRUFBOEJELFNBQTlCLEtBQ0pJLGtCQUFrQixDQUFDckQsSUFBRCxFQUFPa0QsWUFBUCxFQUFxQkEsWUFBWSxDQUFDakMsTUFBYixHQUFzQmdDLFNBQVMsQ0FBQ2hDLE1BQXJELENBRGxCLEVBQ2dGO0FBQUE7QUFBQTs7QUFBQTs7QUFDckY7O0FBQUE7O0FBQUE7QUFBQTtBQUFBO0FBQUF4QixNQUFBQSxJQUFJLENBQUNFLEtBQUwsRUFBVzRCLElBQVg7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFvQjJCLE1BQUFBLFlBQXBCOztBQUNBO0FBQ0Q7QUFDRixHQVhELE1BV087QUFBSTtBQUFBO0FBQUE7O0FBQUFJO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUFBO0FBQUE7QUFBQSxHQUFXTCxTQUFYLEVBQXNCQyxZQUF0QixDQUFKLEVBQXlDO0FBQUE7QUFBQTs7QUFBQTs7QUFDOUM7O0FBQUE7O0FBQUE7QUFBQTtBQUFBO0FBQUF6RCxJQUFBQSxJQUFJLENBQUNFLEtBQUwsRUFBVzRCLElBQVg7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFvQjBCLElBQUFBLFNBQXBCOztBQUNBO0FBQ0Q7O0FBRURiLEVBQUFBLFFBQVEsQ0FBQzNDLElBQUQsRUFBT3dELFNBQVAsRUFBa0JDLFlBQWxCLENBQVI7QUFDRDs7QUFFRCxTQUFTSCxPQUFULENBQWlCdEQsSUFBakIsRUFBdUJPLElBQXZCLEVBQTZCMEMsS0FBN0IsRUFBb0NhLElBQXBDLEVBQTBDO0FBQ3hDLE1BQUlOLFNBQVMsR0FBR0gsYUFBYSxDQUFDOUMsSUFBRCxDQUE3QjtBQUFBLE1BQ0lrRCxZQUFZLEdBQUdNLGNBQWMsQ0FBQ2QsS0FBRCxFQUFRTyxTQUFSLENBRGpDOztBQUVBLE1BQUlDLFlBQVksQ0FBQ08sTUFBakIsRUFBeUI7QUFBQTtBQUFBOztBQUFBOztBQUN2Qjs7QUFBQTs7QUFBQTtBQUFBO0FBQUE7QUFBQWhFLElBQUFBLElBQUksQ0FBQ0UsS0FBTCxFQUFXNEIsSUFBWDtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQW9CMkIsSUFBQUEsWUFBWSxDQUFDTyxNQUFqQztBQUNELEdBRkQsTUFFTztBQUNMckIsSUFBQUEsUUFBUSxDQUFDM0MsSUFBRCxFQUFPOEQsSUFBSSxHQUFHTCxZQUFILEdBQWtCRCxTQUE3QixFQUF3Q00sSUFBSSxHQUFHTixTQUFILEdBQWVDLFlBQTNELENBQVI7QUFDRDtBQUNGOztBQUVELFNBQVNkLFFBQVQsQ0FBa0IzQyxJQUFsQixFQUF3Qk8sSUFBeEIsRUFBOEIwQyxLQUE5QixFQUFxQztBQUNuQ2pELEVBQUFBLElBQUksQ0FBQzJDLFFBQUwsR0FBZ0IsSUFBaEI7QUFDQTNDLEVBQUFBLElBQUksQ0FBQ0UsS0FBTCxDQUFXNEIsSUFBWCxDQUFnQjtBQUNkYSxJQUFBQSxRQUFRLEVBQUUsSUFESTtBQUVkcEMsSUFBQUEsSUFBSSxFQUFFQSxJQUZRO0FBR2RDLElBQUFBLE1BQU0sRUFBRXlDO0FBSE0sR0FBaEI7QUFLRDs7QUFFRCxTQUFTQyxhQUFULENBQXVCbEQsSUFBdkIsRUFBNkJpRSxNQUE3QixFQUFxQ2hCLEtBQXJDLEVBQTRDO0FBQzFDLFNBQU9nQixNQUFNLENBQUNwQixNQUFQLEdBQWdCSSxLQUFLLENBQUNKLE1BQXRCLElBQWdDb0IsTUFBTSxDQUFDckQsS0FBUCxHQUFlcUQsTUFBTSxDQUFDL0QsS0FBUCxDQUFhc0IsTUFBbkUsRUFBMkU7QUFDekUsUUFBSTBDLElBQUksR0FBR0QsTUFBTSxDQUFDL0QsS0FBUCxDQUFhK0QsTUFBTSxDQUFDckQsS0FBUCxFQUFiLENBQVg7QUFDQVosSUFBQUEsSUFBSSxDQUFDRSxLQUFMLENBQVc0QixJQUFYLENBQWdCb0MsSUFBaEI7QUFDQUQsSUFBQUEsTUFBTSxDQUFDcEIsTUFBUDtBQUNEO0FBQ0Y7O0FBQ0QsU0FBU1UsY0FBVCxDQUF3QnZELElBQXhCLEVBQThCaUUsTUFBOUIsRUFBc0M7QUFDcEMsU0FBT0EsTUFBTSxDQUFDckQsS0FBUCxHQUFlcUQsTUFBTSxDQUFDL0QsS0FBUCxDQUFhc0IsTUFBbkMsRUFBMkM7QUFDekMsUUFBSTBDLElBQUksR0FBR0QsTUFBTSxDQUFDL0QsS0FBUCxDQUFhK0QsTUFBTSxDQUFDckQsS0FBUCxFQUFiLENBQVg7QUFDQVosSUFBQUEsSUFBSSxDQUFDRSxLQUFMLENBQVc0QixJQUFYLENBQWdCb0MsSUFBaEI7QUFDRDtBQUNGOztBQUVELFNBQVNiLGFBQVQsQ0FBdUJjLEtBQXZCLEVBQThCO0FBQzVCLE1BQUl4RCxHQUFHLEdBQUcsRUFBVjtBQUFBLE1BQ0l5RCxTQUFTLEdBQUdELEtBQUssQ0FBQ2pFLEtBQU4sQ0FBWWlFLEtBQUssQ0FBQ3ZELEtBQWxCLEVBQXlCLENBQXpCLENBRGhCOztBQUVBLFNBQU91RCxLQUFLLENBQUN2RCxLQUFOLEdBQWN1RCxLQUFLLENBQUNqRSxLQUFOLENBQVlzQixNQUFqQyxFQUF5QztBQUN2QyxRQUFJMEMsSUFBSSxHQUFHQyxLQUFLLENBQUNqRSxLQUFOLENBQVlpRSxLQUFLLENBQUN2RCxLQUFsQixDQUFYLENBRHVDLENBR3ZDOztBQUNBLFFBQUl3RCxTQUFTLEtBQUssR0FBZCxJQUFxQkYsSUFBSSxDQUFDLENBQUQsQ0FBSixLQUFZLEdBQXJDLEVBQTBDO0FBQ3hDRSxNQUFBQSxTQUFTLEdBQUcsR0FBWjtBQUNEOztBQUVELFFBQUlBLFNBQVMsS0FBS0YsSUFBSSxDQUFDLENBQUQsQ0FBdEIsRUFBMkI7QUFDekJ2RCxNQUFBQSxHQUFHLENBQUNtQixJQUFKLENBQVNvQyxJQUFUO0FBQ0FDLE1BQUFBLEtBQUssQ0FBQ3ZELEtBQU47QUFDRCxLQUhELE1BR087QUFDTDtBQUNEO0FBQ0Y7O0FBRUQsU0FBT0QsR0FBUDtBQUNEOztBQUNELFNBQVNvRCxjQUFULENBQXdCSSxLQUF4QixFQUErQkUsWUFBL0IsRUFBNkM7QUFDM0MsTUFBSUMsT0FBTyxHQUFHLEVBQWQ7QUFBQSxNQUNJTixNQUFNLEdBQUcsRUFEYjtBQUFBLE1BRUlPLFVBQVUsR0FBRyxDQUZqQjtBQUFBLE1BR0lDLGNBQWMsR0FBRyxLQUhyQjtBQUFBLE1BSUlDLFVBQVUsR0FBRyxLQUpqQjs7QUFLQSxTQUFPRixVQUFVLEdBQUdGLFlBQVksQ0FBQzdDLE1BQTFCLElBQ0UyQyxLQUFLLENBQUN2RCxLQUFOLEdBQWN1RCxLQUFLLENBQUNqRSxLQUFOLENBQVlzQixNQURuQyxFQUMyQztBQUN6QyxRQUFJa0QsTUFBTSxHQUFHUCxLQUFLLENBQUNqRSxLQUFOLENBQVlpRSxLQUFLLENBQUN2RCxLQUFsQixDQUFiO0FBQUEsUUFDSStELEtBQUssR0FBR04sWUFBWSxDQUFDRSxVQUFELENBRHhCLENBRHlDLENBSXpDOztBQUNBLFFBQUlJLEtBQUssQ0FBQyxDQUFELENBQUwsS0FBYSxHQUFqQixFQUFzQjtBQUNwQjtBQUNEOztBQUVESCxJQUFBQSxjQUFjLEdBQUdBLGNBQWMsSUFBSUUsTUFBTSxDQUFDLENBQUQsQ0FBTixLQUFjLEdBQWpEO0FBRUFWLElBQUFBLE1BQU0sQ0FBQ2xDLElBQVAsQ0FBWTZDLEtBQVo7QUFDQUosSUFBQUEsVUFBVSxHQVorQixDQWN6QztBQUNBOztBQUNBLFFBQUlHLE1BQU0sQ0FBQyxDQUFELENBQU4sS0FBYyxHQUFsQixFQUF1QjtBQUNyQkQsTUFBQUEsVUFBVSxHQUFHLElBQWI7O0FBRUEsYUFBT0MsTUFBTSxDQUFDLENBQUQsQ0FBTixLQUFjLEdBQXJCLEVBQTBCO0FBQ3hCSixRQUFBQSxPQUFPLENBQUN4QyxJQUFSLENBQWE0QyxNQUFiO0FBQ0FBLFFBQUFBLE1BQU0sR0FBR1AsS0FBSyxDQUFDakUsS0FBTixDQUFZLEVBQUVpRSxLQUFLLENBQUN2RCxLQUFwQixDQUFUO0FBQ0Q7QUFDRjs7QUFFRCxRQUFJK0QsS0FBSyxDQUFDQyxNQUFOLENBQWEsQ0FBYixNQUFvQkYsTUFBTSxDQUFDRSxNQUFQLENBQWMsQ0FBZCxDQUF4QixFQUEwQztBQUN4Q04sTUFBQUEsT0FBTyxDQUFDeEMsSUFBUixDQUFhNEMsTUFBYjtBQUNBUCxNQUFBQSxLQUFLLENBQUN2RCxLQUFOO0FBQ0QsS0FIRCxNQUdPO0FBQ0w2RCxNQUFBQSxVQUFVLEdBQUcsSUFBYjtBQUNEO0FBQ0Y7O0FBRUQsTUFBSSxDQUFDSixZQUFZLENBQUNFLFVBQUQsQ0FBWixJQUE0QixFQUE3QixFQUFpQyxDQUFqQyxNQUF3QyxHQUF4QyxJQUNHQyxjQURQLEVBQ3VCO0FBQ3JCQyxJQUFBQSxVQUFVLEdBQUcsSUFBYjtBQUNEOztBQUVELE1BQUlBLFVBQUosRUFBZ0I7QUFDZCxXQUFPSCxPQUFQO0FBQ0Q7O0FBRUQsU0FBT0MsVUFBVSxHQUFHRixZQUFZLENBQUM3QyxNQUFqQyxFQUF5QztBQUN2Q3dDLElBQUFBLE1BQU0sQ0FBQ2xDLElBQVAsQ0FBWXVDLFlBQVksQ0FBQ0UsVUFBVSxFQUFYLENBQXhCO0FBQ0Q7O0FBRUQsU0FBTztBQUNMUCxJQUFBQSxNQUFNLEVBQU5BLE1BREs7QUFFTE0sSUFBQUEsT0FBTyxFQUFQQTtBQUZLLEdBQVA7QUFJRDs7QUFFRCxTQUFTWixVQUFULENBQW9CWSxPQUFwQixFQUE2QjtBQUMzQixTQUFPQSxPQUFPLENBQUNPLE1BQVIsQ0FBZSxVQUFTQyxJQUFULEVBQWVKLE1BQWYsRUFBdUI7QUFDM0MsV0FBT0ksSUFBSSxJQUFJSixNQUFNLENBQUMsQ0FBRCxDQUFOLEtBQWMsR0FBN0I7QUFDRCxHQUZNLEVBRUosSUFGSSxDQUFQO0FBR0Q7O0FBQ0QsU0FBU2Qsa0JBQVQsQ0FBNEJPLEtBQTVCLEVBQW1DWSxhQUFuQyxFQUFrREMsS0FBbEQsRUFBeUQ7QUFDdkQsT0FBSyxJQUFJQyxDQUFDLEdBQUcsQ0FBYixFQUFnQkEsQ0FBQyxHQUFHRCxLQUFwQixFQUEyQkMsQ0FBQyxFQUE1QixFQUFnQztBQUM5QixRQUFJQyxhQUFhLEdBQUdILGFBQWEsQ0FBQ0EsYUFBYSxDQUFDdkQsTUFBZCxHQUF1QndELEtBQXZCLEdBQStCQyxDQUFoQyxDQUFiLENBQWdETCxNQUFoRCxDQUF1RCxDQUF2RCxDQUFwQjs7QUFDQSxRQUFJVCxLQUFLLENBQUNqRSxLQUFOLENBQVlpRSxLQUFLLENBQUN2RCxLQUFOLEdBQWNxRSxDQUExQixNQUFpQyxNQUFNQyxhQUEzQyxFQUEwRDtBQUN4RCxhQUFPLEtBQVA7QUFDRDtBQUNGOztBQUVEZixFQUFBQSxLQUFLLENBQUN2RCxLQUFOLElBQWVvRSxLQUFmO0FBQ0EsU0FBTyxJQUFQO0FBQ0Q7O0FBRUQsU0FBUy9FLG1CQUFULENBQTZCQyxLQUE3QixFQUFvQztBQUNsQyxNQUFJQyxRQUFRLEdBQUcsQ0FBZjtBQUNBLE1BQUlDLFFBQVEsR0FBRyxDQUFmO0FBRUFGLEVBQUFBLEtBQUssQ0FBQ2lGLE9BQU4sQ0FBYyxVQUFTakIsSUFBVCxFQUFlO0FBQzNCLFFBQUksT0FBT0EsSUFBUCxLQUFnQixRQUFwQixFQUE4QjtBQUM1QixVQUFJa0IsT0FBTyxHQUFHbkYsbUJBQW1CLENBQUNpRSxJQUFJLENBQUMzRCxJQUFOLENBQWpDO0FBQ0EsVUFBSThFLFVBQVUsR0FBR3BGLG1CQUFtQixDQUFDaUUsSUFBSSxDQUFDMUQsTUFBTixDQUFwQzs7QUFFQSxVQUFJTCxRQUFRLEtBQUtFLFNBQWpCLEVBQTRCO0FBQzFCLFlBQUkrRSxPQUFPLENBQUNqRixRQUFSLEtBQXFCa0YsVUFBVSxDQUFDbEYsUUFBcEMsRUFBOEM7QUFDNUNBLFVBQUFBLFFBQVEsSUFBSWlGLE9BQU8sQ0FBQ2pGLFFBQXBCO0FBQ0QsU0FGRCxNQUVPO0FBQ0xBLFVBQUFBLFFBQVEsR0FBR0UsU0FBWDtBQUNEO0FBQ0Y7O0FBRUQsVUFBSUQsUUFBUSxLQUFLQyxTQUFqQixFQUE0QjtBQUMxQixZQUFJK0UsT0FBTyxDQUFDaEYsUUFBUixLQUFxQmlGLFVBQVUsQ0FBQ2pGLFFBQXBDLEVBQThDO0FBQzVDQSxVQUFBQSxRQUFRLElBQUlnRixPQUFPLENBQUNoRixRQUFwQjtBQUNELFNBRkQsTUFFTztBQUNMQSxVQUFBQSxRQUFRLEdBQUdDLFNBQVg7QUFDRDtBQUNGO0FBQ0YsS0FuQkQsTUFtQk87QUFDTCxVQUFJRCxRQUFRLEtBQUtDLFNBQWIsS0FBMkI2RCxJQUFJLENBQUMsQ0FBRCxDQUFKLEtBQVksR0FBWixJQUFtQkEsSUFBSSxDQUFDLENBQUQsQ0FBSixLQUFZLEdBQTFELENBQUosRUFBb0U7QUFDbEU5RCxRQUFBQSxRQUFRO0FBQ1Q7O0FBQ0QsVUFBSUQsUUFBUSxLQUFLRSxTQUFiLEtBQTJCNkQsSUFBSSxDQUFDLENBQUQsQ0FBSixLQUFZLEdBQVosSUFBbUJBLElBQUksQ0FBQyxDQUFELENBQUosS0FBWSxHQUExRCxDQUFKLEVBQW9FO0FBQ2xFL0QsUUFBQUEsUUFBUTtBQUNUO0FBQ0Y7QUFDRixHQTVCRDtBQThCQSxTQUFPO0FBQUNBLElBQUFBLFFBQVEsRUFBUkEsUUFBRDtBQUFXQyxJQUFBQSxRQUFRLEVBQVJBO0FBQVgsR0FBUDtBQUNEIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHtzdHJ1Y3R1cmVkUGF0Y2h9IGZyb20gJy4vY3JlYXRlJztcbmltcG9ydCB7cGFyc2VQYXRjaH0gZnJvbSAnLi9wYXJzZSc7XG5cbmltcG9ydCB7YXJyYXlFcXVhbCwgYXJyYXlTdGFydHNXaXRofSBmcm9tICcuLi91dGlsL2FycmF5JztcblxuZXhwb3J0IGZ1bmN0aW9uIGNhbGNMaW5lQ291bnQoaHVuaykge1xuICBjb25zdCB7b2xkTGluZXMsIG5ld0xpbmVzfSA9IGNhbGNPbGROZXdMaW5lQ291bnQoaHVuay5saW5lcyk7XG5cbiAgaWYgKG9sZExpbmVzICE9PSB1bmRlZmluZWQpIHtcbiAgICBodW5rLm9sZExpbmVzID0gb2xkTGluZXM7XG4gIH0gZWxzZSB7XG4gICAgZGVsZXRlIGh1bmsub2xkTGluZXM7XG4gIH1cblxuICBpZiAobmV3TGluZXMgIT09IHVuZGVmaW5lZCkge1xuICAgIGh1bmsubmV3TGluZXMgPSBuZXdMaW5lcztcbiAgfSBlbHNlIHtcbiAgICBkZWxldGUgaHVuay5uZXdMaW5lcztcbiAgfVxufVxuXG5leHBvcnQgZnVuY3Rpb24gbWVyZ2UobWluZSwgdGhlaXJzLCBiYXNlKSB7XG4gIG1pbmUgPSBsb2FkUGF0Y2gobWluZSwgYmFzZSk7XG4gIHRoZWlycyA9IGxvYWRQYXRjaCh0aGVpcnMsIGJhc2UpO1xuXG4gIGxldCByZXQgPSB7fTtcblxuICAvLyBGb3IgaW5kZXggd2UganVzdCBsZXQgaXQgcGFzcyB0aHJvdWdoIGFzIGl0IGRvZXNuJ3QgaGF2ZSBhbnkgbmVjZXNzYXJ5IG1lYW5pbmcuXG4gIC8vIExlYXZpbmcgc2FuaXR5IGNoZWNrcyBvbiB0aGlzIHRvIHRoZSBBUEkgY29uc3VtZXIgdGhhdCBtYXkga25vdyBtb3JlIGFib3V0IHRoZVxuICAvLyBtZWFuaW5nIGluIHRoZWlyIG93biBjb250ZXh0LlxuICBpZiAobWluZS5pbmRleCB8fCB0aGVpcnMuaW5kZXgpIHtcbiAgICByZXQuaW5kZXggPSBtaW5lLmluZGV4IHx8IHRoZWlycy5pbmRleDtcbiAgfVxuXG4gIGlmIChtaW5lLm5ld0ZpbGVOYW1lIHx8IHRoZWlycy5uZXdGaWxlTmFtZSkge1xuICAgIGlmICghZmlsZU5hbWVDaGFuZ2VkKG1pbmUpKSB7XG4gICAgICAvLyBObyBoZWFkZXIgb3Igbm8gY2hhbmdlIGluIG91cnMsIHVzZSB0aGVpcnMgKGFuZCBvdXJzIGlmIHRoZWlycyBkb2VzIG5vdCBleGlzdClcbiAgICAgIHJldC5vbGRGaWxlTmFtZSA9IHRoZWlycy5vbGRGaWxlTmFtZSB8fCBtaW5lLm9sZEZpbGVOYW1lO1xuICAgICAgcmV0Lm5ld0ZpbGVOYW1lID0gdGhlaXJzLm5ld0ZpbGVOYW1lIHx8IG1pbmUubmV3RmlsZU5hbWU7XG4gICAgICByZXQub2xkSGVhZGVyID0gdGhlaXJzLm9sZEhlYWRlciB8fCBtaW5lLm9sZEhlYWRlcjtcbiAgICAgIHJldC5uZXdIZWFkZXIgPSB0aGVpcnMubmV3SGVhZGVyIHx8IG1pbmUubmV3SGVhZGVyO1xuICAgIH0gZWxzZSBpZiAoIWZpbGVOYW1lQ2hhbmdlZCh0aGVpcnMpKSB7XG4gICAgICAvLyBObyBoZWFkZXIgb3Igbm8gY2hhbmdlIGluIHRoZWlycywgdXNlIG91cnNcbiAgICAgIHJldC5vbGRGaWxlTmFtZSA9IG1pbmUub2xkRmlsZU5hbWU7XG4gICAgICByZXQubmV3RmlsZU5hbWUgPSBtaW5lLm5ld0ZpbGVOYW1lO1xuICAgICAgcmV0Lm9sZEhlYWRlciA9IG1pbmUub2xkSGVhZGVyO1xuICAgICAgcmV0Lm5ld0hlYWRlciA9IG1pbmUubmV3SGVhZGVyO1xuICAgIH0gZWxzZSB7XG4gICAgICAvLyBCb3RoIGNoYW5nZWQuLi4gZmlndXJlIGl0IG91dFxuICAgICAgcmV0Lm9sZEZpbGVOYW1lID0gc2VsZWN0RmllbGQocmV0LCBtaW5lLm9sZEZpbGVOYW1lLCB0aGVpcnMub2xkRmlsZU5hbWUpO1xuICAgICAgcmV0Lm5ld0ZpbGVOYW1lID0gc2VsZWN0RmllbGQocmV0LCBtaW5lLm5ld0ZpbGVOYW1lLCB0aGVpcnMubmV3RmlsZU5hbWUpO1xuICAgICAgcmV0Lm9sZEhlYWRlciA9IHNlbGVjdEZpZWxkKHJldCwgbWluZS5vbGRIZWFkZXIsIHRoZWlycy5vbGRIZWFkZXIpO1xuICAgICAgcmV0Lm5ld0hlYWRlciA9IHNlbGVjdEZpZWxkKHJldCwgbWluZS5uZXdIZWFkZXIsIHRoZWlycy5uZXdIZWFkZXIpO1xuICAgIH1cbiAgfVxuXG4gIHJldC5odW5rcyA9IFtdO1xuXG4gIGxldCBtaW5lSW5kZXggPSAwLFxuICAgICAgdGhlaXJzSW5kZXggPSAwLFxuICAgICAgbWluZU9mZnNldCA9IDAsXG4gICAgICB0aGVpcnNPZmZzZXQgPSAwO1xuXG4gIHdoaWxlIChtaW5lSW5kZXggPCBtaW5lLmh1bmtzLmxlbmd0aCB8fCB0aGVpcnNJbmRleCA8IHRoZWlycy5odW5rcy5sZW5ndGgpIHtcbiAgICBsZXQgbWluZUN1cnJlbnQgPSBtaW5lLmh1bmtzW21pbmVJbmRleF0gfHwge29sZFN0YXJ0OiBJbmZpbml0eX0sXG4gICAgICAgIHRoZWlyc0N1cnJlbnQgPSB0aGVpcnMuaHVua3NbdGhlaXJzSW5kZXhdIHx8IHtvbGRTdGFydDogSW5maW5pdHl9O1xuXG4gICAgaWYgKGh1bmtCZWZvcmUobWluZUN1cnJlbnQsIHRoZWlyc0N1cnJlbnQpKSB7XG4gICAgICAvLyBUaGlzIHBhdGNoIGRvZXMgbm90IG92ZXJsYXAgd2l0aCBhbnkgb2YgdGhlIG90aGVycywgeWF5LlxuICAgICAgcmV0Lmh1bmtzLnB1c2goY2xvbmVIdW5rKG1pbmVDdXJyZW50LCBtaW5lT2Zmc2V0KSk7XG4gICAgICBtaW5lSW5kZXgrKztcbiAgICAgIHRoZWlyc09mZnNldCArPSBtaW5lQ3VycmVudC5uZXdMaW5lcyAtIG1pbmVDdXJyZW50Lm9sZExpbmVzO1xuICAgIH0gZWxzZSBpZiAoaHVua0JlZm9yZSh0aGVpcnNDdXJyZW50LCBtaW5lQ3VycmVudCkpIHtcbiAgICAgIC8vIFRoaXMgcGF0Y2ggZG9lcyBub3Qgb3ZlcmxhcCB3aXRoIGFueSBvZiB0aGUgb3RoZXJzLCB5YXkuXG4gICAgICByZXQuaHVua3MucHVzaChjbG9uZUh1bmsodGhlaXJzQ3VycmVudCwgdGhlaXJzT2Zmc2V0KSk7XG4gICAgICB0aGVpcnNJbmRleCsrO1xuICAgICAgbWluZU9mZnNldCArPSB0aGVpcnNDdXJyZW50Lm5ld0xpbmVzIC0gdGhlaXJzQ3VycmVudC5vbGRMaW5lcztcbiAgICB9IGVsc2Uge1xuICAgICAgLy8gT3ZlcmxhcCwgbWVyZ2UgYXMgYmVzdCB3ZSBjYW5cbiAgICAgIGxldCBtZXJnZWRIdW5rID0ge1xuICAgICAgICBvbGRTdGFydDogTWF0aC5taW4obWluZUN1cnJlbnQub2xkU3RhcnQsIHRoZWlyc0N1cnJlbnQub2xkU3RhcnQpLFxuICAgICAgICBvbGRMaW5lczogMCxcbiAgICAgICAgbmV3U3RhcnQ6IE1hdGgubWluKG1pbmVDdXJyZW50Lm5ld1N0YXJ0ICsgbWluZU9mZnNldCwgdGhlaXJzQ3VycmVudC5vbGRTdGFydCArIHRoZWlyc09mZnNldCksXG4gICAgICAgIG5ld0xpbmVzOiAwLFxuICAgICAgICBsaW5lczogW11cbiAgICAgIH07XG4gICAgICBtZXJnZUxpbmVzKG1lcmdlZEh1bmssIG1pbmVDdXJyZW50Lm9sZFN0YXJ0LCBtaW5lQ3VycmVudC5saW5lcywgdGhlaXJzQ3VycmVudC5vbGRTdGFydCwgdGhlaXJzQ3VycmVudC5saW5lcyk7XG4gICAgICB0aGVpcnNJbmRleCsrO1xuICAgICAgbWluZUluZGV4Kys7XG5cbiAgICAgIHJldC5odW5rcy5wdXNoKG1lcmdlZEh1bmspO1xuICAgIH1cbiAgfVxuXG4gIHJldHVybiByZXQ7XG59XG5cbmZ1bmN0aW9uIGxvYWRQYXRjaChwYXJhbSwgYmFzZSkge1xuICBpZiAodHlwZW9mIHBhcmFtID09PSAnc3RyaW5nJykge1xuICAgIGlmICgoL15AQC9tKS50ZXN0KHBhcmFtKSB8fCAoKC9eSW5kZXg6L20pLnRlc3QocGFyYW0pKSkge1xuICAgICAgcmV0dXJuIHBhcnNlUGF0Y2gocGFyYW0pWzBdO1xuICAgIH1cblxuICAgIGlmICghYmFzZSkge1xuICAgICAgdGhyb3cgbmV3IEVycm9yKCdNdXN0IHByb3ZpZGUgYSBiYXNlIHJlZmVyZW5jZSBvciBwYXNzIGluIGEgcGF0Y2gnKTtcbiAgICB9XG4gICAgcmV0dXJuIHN0cnVjdHVyZWRQYXRjaCh1bmRlZmluZWQsIHVuZGVmaW5lZCwgYmFzZSwgcGFyYW0pO1xuICB9XG5cbiAgcmV0dXJuIHBhcmFtO1xufVxuXG5mdW5jdGlvbiBmaWxlTmFtZUNoYW5nZWQocGF0Y2gpIHtcbiAgcmV0dXJuIHBhdGNoLm5ld0ZpbGVOYW1lICYmIHBhdGNoLm5ld0ZpbGVOYW1lICE9PSBwYXRjaC5vbGRGaWxlTmFtZTtcbn1cblxuZnVuY3Rpb24gc2VsZWN0RmllbGQoaW5kZXgsIG1pbmUsIHRoZWlycykge1xuICBpZiAobWluZSA9PT0gdGhlaXJzKSB7XG4gICAgcmV0dXJuIG1pbmU7XG4gIH0gZWxzZSB7XG4gICAgaW5kZXguY29uZmxpY3QgPSB0cnVlO1xuICAgIHJldHVybiB7bWluZSwgdGhlaXJzfTtcbiAgfVxufVxuXG5mdW5jdGlvbiBodW5rQmVmb3JlKHRlc3QsIGNoZWNrKSB7XG4gIHJldHVybiB0ZXN0Lm9sZFN0YXJ0IDwgY2hlY2sub2xkU3RhcnRcbiAgICAmJiAodGVzdC5vbGRTdGFydCArIHRlc3Qub2xkTGluZXMpIDwgY2hlY2sub2xkU3RhcnQ7XG59XG5cbmZ1bmN0aW9uIGNsb25lSHVuayhodW5rLCBvZmZzZXQpIHtcbiAgcmV0dXJuIHtcbiAgICBvbGRTdGFydDogaHVuay5vbGRTdGFydCwgb2xkTGluZXM6IGh1bmsub2xkTGluZXMsXG4gICAgbmV3U3RhcnQ6IGh1bmsubmV3U3RhcnQgKyBvZmZzZXQsIG5ld0xpbmVzOiBodW5rLm5ld0xpbmVzLFxuICAgIGxpbmVzOiBodW5rLmxpbmVzXG4gIH07XG59XG5cbmZ1bmN0aW9uIG1lcmdlTGluZXMoaHVuaywgbWluZU9mZnNldCwgbWluZUxpbmVzLCB0aGVpck9mZnNldCwgdGhlaXJMaW5lcykge1xuICAvLyBUaGlzIHdpbGwgZ2VuZXJhbGx5IHJlc3VsdCBpbiBhIGNvbmZsaWN0ZWQgaHVuaywgYnV0IHRoZXJlIGFyZSBjYXNlcyB3aGVyZSB0aGUgY29udGV4dFxuICAvLyBpcyB0aGUgb25seSBvdmVybGFwIHdoZXJlIHdlIGNhbiBzdWNjZXNzZnVsbHkgbWVyZ2UgdGhlIGNvbnRlbnQgaGVyZS5cbiAgbGV0IG1pbmUgPSB7b2Zmc2V0OiBtaW5lT2Zmc2V0LCBsaW5lczogbWluZUxpbmVzLCBpbmRleDogMH0sXG4gICAgICB0aGVpciA9IHtvZmZzZXQ6IHRoZWlyT2Zmc2V0LCBsaW5lczogdGhlaXJMaW5lcywgaW5kZXg6IDB9O1xuXG4gIC8vIEhhbmRsZSBhbnkgbGVhZGluZyBjb250ZW50XG4gIGluc2VydExlYWRpbmcoaHVuaywgbWluZSwgdGhlaXIpO1xuICBpbnNlcnRMZWFkaW5nKGh1bmssIHRoZWlyLCBtaW5lKTtcblxuICAvLyBOb3cgaW4gdGhlIG92ZXJsYXAgY29udGVudC4gU2NhbiB0aHJvdWdoIGFuZCBzZWxlY3QgdGhlIGJlc3QgY2hhbmdlcyBmcm9tIGVhY2guXG4gIHdoaWxlIChtaW5lLmluZGV4IDwgbWluZS5saW5lcy5sZW5ndGggJiYgdGhlaXIuaW5kZXggPCB0aGVpci5saW5lcy5sZW5ndGgpIHtcbiAgICBsZXQgbWluZUN1cnJlbnQgPSBtaW5lLmxpbmVzW21pbmUuaW5kZXhdLFxuICAgICAgICB0aGVpckN1cnJlbnQgPSB0aGVpci5saW5lc1t0aGVpci5pbmRleF07XG5cbiAgICBpZiAoKG1pbmVDdXJyZW50WzBdID09PSAnLScgfHwgbWluZUN1cnJlbnRbMF0gPT09ICcrJylcbiAgICAgICAgJiYgKHRoZWlyQ3VycmVudFswXSA9PT0gJy0nIHx8IHRoZWlyQ3VycmVudFswXSA9PT0gJysnKSkge1xuICAgICAgLy8gQm90aCBtb2RpZmllZCAuLi5cbiAgICAgIG11dHVhbENoYW5nZShodW5rLCBtaW5lLCB0aGVpcik7XG4gICAgfSBlbHNlIGlmIChtaW5lQ3VycmVudFswXSA9PT0gJysnICYmIHRoZWlyQ3VycmVudFswXSA9PT0gJyAnKSB7XG4gICAgICAvLyBNaW5lIGluc2VydGVkXG4gICAgICBodW5rLmxpbmVzLnB1c2goLi4uIGNvbGxlY3RDaGFuZ2UobWluZSkpO1xuICAgIH0gZWxzZSBpZiAodGhlaXJDdXJyZW50WzBdID09PSAnKycgJiYgbWluZUN1cnJlbnRbMF0gPT09ICcgJykge1xuICAgICAgLy8gVGhlaXJzIGluc2VydGVkXG4gICAgICBodW5rLmxpbmVzLnB1c2goLi4uIGNvbGxlY3RDaGFuZ2UodGhlaXIpKTtcbiAgICB9IGVsc2UgaWYgKG1pbmVDdXJyZW50WzBdID09PSAnLScgJiYgdGhlaXJDdXJyZW50WzBdID09PSAnICcpIHtcbiAgICAgIC8vIE1pbmUgcmVtb3ZlZCBvciBlZGl0ZWRcbiAgICAgIHJlbW92YWwoaHVuaywgbWluZSwgdGhlaXIpO1xuICAgIH0gZWxzZSBpZiAodGhlaXJDdXJyZW50WzBdID09PSAnLScgJiYgbWluZUN1cnJlbnRbMF0gPT09ICcgJykge1xuICAgICAgLy8gVGhlaXIgcmVtb3ZlZCBvciBlZGl0ZWRcbiAgICAgIHJlbW92YWwoaHVuaywgdGhlaXIsIG1pbmUsIHRydWUpO1xuICAgIH0gZWxzZSBpZiAobWluZUN1cnJlbnQgPT09IHRoZWlyQ3VycmVudCkge1xuICAgICAgLy8gQ29udGV4dCBpZGVudGl0eVxuICAgICAgaHVuay5saW5lcy5wdXNoKG1pbmVDdXJyZW50KTtcbiAgICAgIG1pbmUuaW5kZXgrKztcbiAgICAgIHRoZWlyLmluZGV4Kys7XG4gICAgfSBlbHNlIHtcbiAgICAgIC8vIENvbnRleHQgbWlzbWF0Y2hcbiAgICAgIGNvbmZsaWN0KGh1bmssIGNvbGxlY3RDaGFuZ2UobWluZSksIGNvbGxlY3RDaGFuZ2UodGhlaXIpKTtcbiAgICB9XG4gIH1cblxuICAvLyBOb3cgcHVzaCBhbnl0aGluZyB0aGF0IG1heSBiZSByZW1haW5pbmdcbiAgaW5zZXJ0VHJhaWxpbmcoaHVuaywgbWluZSk7XG4gIGluc2VydFRyYWlsaW5nKGh1bmssIHRoZWlyKTtcblxuICBjYWxjTGluZUNvdW50KGh1bmspO1xufVxuXG5mdW5jdGlvbiBtdXR1YWxDaGFuZ2UoaHVuaywgbWluZSwgdGhlaXIpIHtcbiAgbGV0IG15Q2hhbmdlcyA9IGNvbGxlY3RDaGFuZ2UobWluZSksXG4gICAgICB0aGVpckNoYW5nZXMgPSBjb2xsZWN0Q2hhbmdlKHRoZWlyKTtcblxuICBpZiAoYWxsUmVtb3ZlcyhteUNoYW5nZXMpICYmIGFsbFJlbW92ZXModGhlaXJDaGFuZ2VzKSkge1xuICAgIC8vIFNwZWNpYWwgY2FzZSBmb3IgcmVtb3ZlIGNoYW5nZXMgdGhhdCBhcmUgc3VwZXJzZXRzIG9mIG9uZSBhbm90aGVyXG4gICAgaWYgKGFycmF5U3RhcnRzV2l0aChteUNoYW5nZXMsIHRoZWlyQ2hhbmdlcylcbiAgICAgICAgJiYgc2tpcFJlbW92ZVN1cGVyc2V0KHRoZWlyLCBteUNoYW5nZXMsIG15Q2hhbmdlcy5sZW5ndGggLSB0aGVpckNoYW5nZXMubGVuZ3RoKSkge1xuICAgICAgaHVuay5saW5lcy5wdXNoKC4uLiBteUNoYW5nZXMpO1xuICAgICAgcmV0dXJuO1xuICAgIH0gZWxzZSBpZiAoYXJyYXlTdGFydHNXaXRoKHRoZWlyQ2hhbmdlcywgbXlDaGFuZ2VzKVxuICAgICAgICAmJiBza2lwUmVtb3ZlU3VwZXJzZXQobWluZSwgdGhlaXJDaGFuZ2VzLCB0aGVpckNoYW5nZXMubGVuZ3RoIC0gbXlDaGFuZ2VzLmxlbmd0aCkpIHtcbiAgICAgIGh1bmsubGluZXMucHVzaCguLi4gdGhlaXJDaGFuZ2VzKTtcbiAgICAgIHJldHVybjtcbiAgICB9XG4gIH0gZWxzZSBpZiAoYXJyYXlFcXVhbChteUNoYW5nZXMsIHRoZWlyQ2hhbmdlcykpIHtcbiAgICBodW5rLmxpbmVzLnB1c2goLi4uIG15Q2hhbmdlcyk7XG4gICAgcmV0dXJuO1xuICB9XG5cbiAgY29uZmxpY3QoaHVuaywgbXlDaGFuZ2VzLCB0aGVpckNoYW5nZXMpO1xufVxuXG5mdW5jdGlvbiByZW1vdmFsKGh1bmssIG1pbmUsIHRoZWlyLCBzd2FwKSB7XG4gIGxldCBteUNoYW5nZXMgPSBjb2xsZWN0Q2hhbmdlKG1pbmUpLFxuICAgICAgdGhlaXJDaGFuZ2VzID0gY29sbGVjdENvbnRleHQodGhlaXIsIG15Q2hhbmdlcyk7XG4gIGlmICh0aGVpckNoYW5nZXMubWVyZ2VkKSB7XG4gICAgaHVuay5saW5lcy5wdXNoKC4uLiB0aGVpckNoYW5nZXMubWVyZ2VkKTtcbiAgfSBlbHNlIHtcbiAgICBjb25mbGljdChodW5rLCBzd2FwID8gdGhlaXJDaGFuZ2VzIDogbXlDaGFuZ2VzLCBzd2FwID8gbXlDaGFuZ2VzIDogdGhlaXJDaGFuZ2VzKTtcbiAgfVxufVxuXG5mdW5jdGlvbiBjb25mbGljdChodW5rLCBtaW5lLCB0aGVpcikge1xuICBodW5rLmNvbmZsaWN0ID0gdHJ1ZTtcbiAgaHVuay5saW5lcy5wdXNoKHtcbiAgICBjb25mbGljdDogdHJ1ZSxcbiAgICBtaW5lOiBtaW5lLFxuICAgIHRoZWlyczogdGhlaXJcbiAgfSk7XG59XG5cbmZ1bmN0aW9uIGluc2VydExlYWRpbmcoaHVuaywgaW5zZXJ0LCB0aGVpcikge1xuICB3aGlsZSAoaW5zZXJ0Lm9mZnNldCA8IHRoZWlyLm9mZnNldCAmJiBpbnNlcnQuaW5kZXggPCBpbnNlcnQubGluZXMubGVuZ3RoKSB7XG4gICAgbGV0IGxpbmUgPSBpbnNlcnQubGluZXNbaW5zZXJ0LmluZGV4KytdO1xuICAgIGh1bmsubGluZXMucHVzaChsaW5lKTtcbiAgICBpbnNlcnQub2Zmc2V0Kys7XG4gIH1cbn1cbmZ1bmN0aW9uIGluc2VydFRyYWlsaW5nKGh1bmssIGluc2VydCkge1xuICB3aGlsZSAoaW5zZXJ0LmluZGV4IDwgaW5zZXJ0LmxpbmVzLmxlbmd0aCkge1xuICAgIGxldCBsaW5lID0gaW5zZXJ0LmxpbmVzW2luc2VydC5pbmRleCsrXTtcbiAgICBodW5rLmxpbmVzLnB1c2gobGluZSk7XG4gIH1cbn1cblxuZnVuY3Rpb24gY29sbGVjdENoYW5nZShzdGF0ZSkge1xuICBsZXQgcmV0ID0gW10sXG4gICAgICBvcGVyYXRpb24gPSBzdGF0ZS5saW5lc1tzdGF0ZS5pbmRleF1bMF07XG4gIHdoaWxlIChzdGF0ZS5pbmRleCA8IHN0YXRlLmxpbmVzLmxlbmd0aCkge1xuICAgIGxldCBsaW5lID0gc3RhdGUubGluZXNbc3RhdGUuaW5kZXhdO1xuXG4gICAgLy8gR3JvdXAgYWRkaXRpb25zIHRoYXQgYXJlIGltbWVkaWF0ZWx5IGFmdGVyIHN1YnRyYWN0aW9ucyBhbmQgdHJlYXQgdGhlbSBhcyBvbmUgXCJhdG9taWNcIiBtb2RpZnkgY2hhbmdlLlxuICAgIGlmIChvcGVyYXRpb24gPT09ICctJyAmJiBsaW5lWzBdID09PSAnKycpIHtcbiAgICAgIG9wZXJhdGlvbiA9ICcrJztcbiAgICB9XG5cbiAgICBpZiAob3BlcmF0aW9uID09PSBsaW5lWzBdKSB7XG4gICAgICByZXQucHVzaChsaW5lKTtcbiAgICAgIHN0YXRlLmluZGV4Kys7XG4gICAgfSBlbHNlIHtcbiAgICAgIGJyZWFrO1xuICAgIH1cbiAgfVxuXG4gIHJldHVybiByZXQ7XG59XG5mdW5jdGlvbiBjb2xsZWN0Q29udGV4dChzdGF0ZSwgbWF0Y2hDaGFuZ2VzKSB7XG4gIGxldCBjaGFuZ2VzID0gW10sXG4gICAgICBtZXJnZWQgPSBbXSxcbiAgICAgIG1hdGNoSW5kZXggPSAwLFxuICAgICAgY29udGV4dENoYW5nZXMgPSBmYWxzZSxcbiAgICAgIGNvbmZsaWN0ZWQgPSBmYWxzZTtcbiAgd2hpbGUgKG1hdGNoSW5kZXggPCBtYXRjaENoYW5nZXMubGVuZ3RoXG4gICAgICAgICYmIHN0YXRlLmluZGV4IDwgc3RhdGUubGluZXMubGVuZ3RoKSB7XG4gICAgbGV0IGNoYW5nZSA9IHN0YXRlLmxpbmVzW3N0YXRlLmluZGV4XSxcbiAgICAgICAgbWF0Y2ggPSBtYXRjaENoYW5nZXNbbWF0Y2hJbmRleF07XG5cbiAgICAvLyBPbmNlIHdlJ3ZlIGhpdCBvdXIgYWRkLCB0aGVuIHdlIGFyZSBkb25lXG4gICAgaWYgKG1hdGNoWzBdID09PSAnKycpIHtcbiAgICAgIGJyZWFrO1xuICAgIH1cblxuICAgIGNvbnRleHRDaGFuZ2VzID0gY29udGV4dENoYW5nZXMgfHwgY2hhbmdlWzBdICE9PSAnICc7XG5cbiAgICBtZXJnZWQucHVzaChtYXRjaCk7XG4gICAgbWF0Y2hJbmRleCsrO1xuXG4gICAgLy8gQ29uc3VtZSBhbnkgYWRkaXRpb25zIGluIHRoZSBvdGhlciBibG9jayBhcyBhIGNvbmZsaWN0IHRvIGF0dGVtcHRcbiAgICAvLyB0byBwdWxsIGluIHRoZSByZW1haW5pbmcgY29udGV4dCBhZnRlciB0aGlzXG4gICAgaWYgKGNoYW5nZVswXSA9PT0gJysnKSB7XG4gICAgICBjb25mbGljdGVkID0gdHJ1ZTtcblxuICAgICAgd2hpbGUgKGNoYW5nZVswXSA9PT0gJysnKSB7XG4gICAgICAgIGNoYW5nZXMucHVzaChjaGFuZ2UpO1xuICAgICAgICBjaGFuZ2UgPSBzdGF0ZS5saW5lc1srK3N0YXRlLmluZGV4XTtcbiAgICAgIH1cbiAgICB9XG5cbiAgICBpZiAobWF0Y2guc3Vic3RyKDEpID09PSBjaGFuZ2Uuc3Vic3RyKDEpKSB7XG4gICAgICBjaGFuZ2VzLnB1c2goY2hhbmdlKTtcbiAgICAgIHN0YXRlLmluZGV4Kys7XG4gICAgfSBlbHNlIHtcbiAgICAgIGNvbmZsaWN0ZWQgPSB0cnVlO1xuICAgIH1cbiAgfVxuXG4gIGlmICgobWF0Y2hDaGFuZ2VzW21hdGNoSW5kZXhdIHx8ICcnKVswXSA9PT0gJysnXG4gICAgICAmJiBjb250ZXh0Q2hhbmdlcykge1xuICAgIGNvbmZsaWN0ZWQgPSB0cnVlO1xuICB9XG5cbiAgaWYgKGNvbmZsaWN0ZWQpIHtcbiAgICByZXR1cm4gY2hhbmdlcztcbiAgfVxuXG4gIHdoaWxlIChtYXRjaEluZGV4IDwgbWF0Y2hDaGFuZ2VzLmxlbmd0aCkge1xuICAgIG1lcmdlZC5wdXNoKG1hdGNoQ2hhbmdlc1ttYXRjaEluZGV4KytdKTtcbiAgfVxuXG4gIHJldHVybiB7XG4gICAgbWVyZ2VkLFxuICAgIGNoYW5nZXNcbiAgfTtcbn1cblxuZnVuY3Rpb24gYWxsUmVtb3ZlcyhjaGFuZ2VzKSB7XG4gIHJldHVybiBjaGFuZ2VzLnJlZHVjZShmdW5jdGlvbihwcmV2LCBjaGFuZ2UpIHtcbiAgICByZXR1cm4gcHJldiAmJiBjaGFuZ2VbMF0gPT09ICctJztcbiAgfSwgdHJ1ZSk7XG59XG5mdW5jdGlvbiBza2lwUmVtb3ZlU3VwZXJzZXQoc3RhdGUsIHJlbW92ZUNoYW5nZXMsIGRlbHRhKSB7XG4gIGZvciAobGV0IGkgPSAwOyBpIDwgZGVsdGE7IGkrKykge1xuICAgIGxldCBjaGFuZ2VDb250ZW50ID0gcmVtb3ZlQ2hhbmdlc1tyZW1vdmVDaGFuZ2VzLmxlbmd0aCAtIGRlbHRhICsgaV0uc3Vic3RyKDEpO1xuICAgIGlmIChzdGF0ZS5saW5lc1tzdGF0ZS5pbmRleCArIGldICE9PSAnICcgKyBjaGFuZ2VDb250ZW50KSB7XG4gICAgICByZXR1cm4gZmFsc2U7XG4gICAgfVxuICB9XG5cbiAgc3RhdGUuaW5kZXggKz0gZGVsdGE7XG4gIHJldHVybiB0cnVlO1xufVxuXG5mdW5jdGlvbiBjYWxjT2xkTmV3TGluZUNvdW50KGxpbmVzKSB7XG4gIGxldCBvbGRMaW5lcyA9IDA7XG4gIGxldCBuZXdMaW5lcyA9IDA7XG5cbiAgbGluZXMuZm9yRWFjaChmdW5jdGlvbihsaW5lKSB7XG4gICAgaWYgKHR5cGVvZiBsaW5lICE9PSAnc3RyaW5nJykge1xuICAgICAgbGV0IG15Q291bnQgPSBjYWxjT2xkTmV3TGluZUNvdW50KGxpbmUubWluZSk7XG4gICAgICBsZXQgdGhlaXJDb3VudCA9IGNhbGNPbGROZXdMaW5lQ291bnQobGluZS50aGVpcnMpO1xuXG4gICAgICBpZiAob2xkTGluZXMgIT09IHVuZGVmaW5lZCkge1xuICAgICAgICBpZiAobXlDb3VudC5vbGRMaW5lcyA9PT0gdGhlaXJDb3VudC5vbGRMaW5lcykge1xuICAgICAgICAgIG9sZExpbmVzICs9IG15Q291bnQub2xkTGluZXM7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgb2xkTGluZXMgPSB1bmRlZmluZWQ7XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgaWYgKG5ld0xpbmVzICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgaWYgKG15Q291bnQubmV3TGluZXMgPT09IHRoZWlyQ291bnQubmV3TGluZXMpIHtcbiAgICAgICAgICBuZXdMaW5lcyArPSBteUNvdW50Lm5ld0xpbmVzO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIG5ld0xpbmVzID0gdW5kZWZpbmVkO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgfSBlbHNlIHtcbiAgICAgIGlmIChuZXdMaW5lcyAhPT0gdW5kZWZpbmVkICYmIChsaW5lWzBdID09PSAnKycgfHwgbGluZVswXSA9PT0gJyAnKSkge1xuICAgICAgICBuZXdMaW5lcysrO1xuICAgICAgfVxuICAgICAgaWYgKG9sZExpbmVzICE9PSB1bmRlZmluZWQgJiYgKGxpbmVbMF0gPT09ICctJyB8fCBsaW5lWzBdID09PSAnICcpKSB7XG4gICAgICAgIG9sZExpbmVzKys7XG4gICAgICB9XG4gICAgfVxuICB9KTtcblxuICByZXR1cm4ge29sZExpbmVzLCBuZXdMaW5lc307XG59XG4iXX0=
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/patch/parse.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/patch/parse.js
          new file mode 100644
          index 00000000000000..f1501048014f1f
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/patch/parse.js
          @@ -0,0 +1,167 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.parsePatch = parsePatch;
          +
          +/*istanbul ignore end*/
          +function parsePatch(uniDiff) {
          +  /*istanbul ignore start*/
          +  var
          +  /*istanbul ignore end*/
          +  options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
          +  var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
          +      delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
          +      list = [],
          +      i = 0;
          +
          +  function parseIndex() {
          +    var index = {};
          +    list.push(index); // Parse diff metadata
          +
          +    while (i < diffstr.length) {
          +      var line = diffstr[i]; // File header found, end parsing diff metadata
          +
          +      if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
          +        break;
          +      } // Diff index
          +
          +
          +      var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
          +
          +      if (header) {
          +        index.index = header[1];
          +      }
          +
          +      i++;
          +    } // Parse file headers if they are defined. Unified diff requires them, but
          +    // there's no technical issues to have an isolated hunk without file header
          +
          +
          +    parseFileHeader(index);
          +    parseFileHeader(index); // Parse hunks
          +
          +    index.hunks = [];
          +
          +    while (i < diffstr.length) {
          +      var _line = diffstr[i];
          +
          +      if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
          +        break;
          +      } else if (/^@@/.test(_line)) {
          +        index.hunks.push(parseHunk());
          +      } else if (_line && options.strict) {
          +        // Ignore unexpected content unless in strict mode
          +        throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
          +      } else {
          +        i++;
          +      }
          +    }
          +  } // Parses the --- and +++ headers, if none are found, no lines
          +  // are consumed.
          +
          +
          +  function parseFileHeader(index) {
          +    var fileHeader = /^(---|\+\+\+)\s+(.*)$/.exec(diffstr[i]);
          +
          +    if (fileHeader) {
          +      var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
          +      var data = fileHeader[2].split('\t', 2);
          +      var fileName = data[0].replace(/\\\\/g, '\\');
          +
          +      if (/^".*"$/.test(fileName)) {
          +        fileName = fileName.substr(1, fileName.length - 2);
          +      }
          +
          +      index[keyPrefix + 'FileName'] = fileName;
          +      index[keyPrefix + 'Header'] = (data[1] || '').trim();
          +      i++;
          +    }
          +  } // Parses a hunk
          +  // This assumes that we are at the start of a hunk.
          +
          +
          +  function parseHunk() {
          +    var chunkHeaderIndex = i,
          +        chunkHeaderLine = diffstr[i++],
          +        chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
          +    var hunk = {
          +      oldStart: +chunkHeader[1],
          +      oldLines: typeof chunkHeader[2] === 'undefined' ? 1 : +chunkHeader[2],
          +      newStart: +chunkHeader[3],
          +      newLines: typeof chunkHeader[4] === 'undefined' ? 1 : +chunkHeader[4],
          +      lines: [],
          +      linedelimiters: []
          +    }; // Unified Diff Format quirk: If the chunk size is 0,
          +    // the first number is one lower than one would expect.
          +    // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
          +
          +    if (hunk.oldLines === 0) {
          +      hunk.oldStart += 1;
          +    }
          +
          +    if (hunk.newLines === 0) {
          +      hunk.newStart += 1;
          +    }
          +
          +    var addCount = 0,
          +        removeCount = 0;
          +
          +    for (; i < diffstr.length; i++) {
          +      // Lines starting with '---' could be mistaken for the "remove line" operation
          +      // But they could be the header for the next file. Therefore prune such cases out.
          +      if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
          +        break;
          +      }
          +
          +      var operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? ' ' : diffstr[i][0];
          +
          +      if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
          +        hunk.lines.push(diffstr[i]);
          +        hunk.linedelimiters.push(delimiters[i] || '\n');
          +
          +        if (operation === '+') {
          +          addCount++;
          +        } else if (operation === '-') {
          +          removeCount++;
          +        } else if (operation === ' ') {
          +          addCount++;
          +          removeCount++;
          +        }
          +      } else {
          +        break;
          +      }
          +    } // Handle the empty block count case
          +
          +
          +    if (!addCount && hunk.newLines === 1) {
          +      hunk.newLines = 0;
          +    }
          +
          +    if (!removeCount && hunk.oldLines === 1) {
          +      hunk.oldLines = 0;
          +    } // Perform optional sanity checking
          +
          +
          +    if (options.strict) {
          +      if (addCount !== hunk.newLines) {
          +        throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
          +      }
          +
          +      if (removeCount !== hunk.oldLines) {
          +        throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
          +      }
          +    }
          +
          +    return hunk;
          +  }
          +
          +  while (i < diffstr.length) {
          +    parseIndex();
          +  }
          +
          +  return list;
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wYXRjaC9wYXJzZS5qcyJdLCJuYW1lcyI6WyJwYXJzZVBhdGNoIiwidW5pRGlmZiIsIm9wdGlvbnMiLCJkaWZmc3RyIiwic3BsaXQiLCJkZWxpbWl0ZXJzIiwibWF0Y2giLCJsaXN0IiwiaSIsInBhcnNlSW5kZXgiLCJpbmRleCIsInB1c2giLCJsZW5ndGgiLCJsaW5lIiwidGVzdCIsImhlYWRlciIsImV4ZWMiLCJwYXJzZUZpbGVIZWFkZXIiLCJodW5rcyIsInBhcnNlSHVuayIsInN0cmljdCIsIkVycm9yIiwiSlNPTiIsInN0cmluZ2lmeSIsImZpbGVIZWFkZXIiLCJrZXlQcmVmaXgiLCJkYXRhIiwiZmlsZU5hbWUiLCJyZXBsYWNlIiwic3Vic3RyIiwidHJpbSIsImNodW5rSGVhZGVySW5kZXgiLCJjaHVua0hlYWRlckxpbmUiLCJjaHVua0hlYWRlciIsImh1bmsiLCJvbGRTdGFydCIsIm9sZExpbmVzIiwibmV3U3RhcnQiLCJuZXdMaW5lcyIsImxpbmVzIiwibGluZWRlbGltaXRlcnMiLCJhZGRDb3VudCIsInJlbW92ZUNvdW50IiwiaW5kZXhPZiIsIm9wZXJhdGlvbiJdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQU8sU0FBU0EsVUFBVCxDQUFvQkMsT0FBcEIsRUFBMkM7QUFBQTtBQUFBO0FBQUE7QUFBZEMsRUFBQUEsT0FBYyx1RUFBSixFQUFJO0FBQ2hELE1BQUlDLE9BQU8sR0FBR0YsT0FBTyxDQUFDRyxLQUFSLENBQWMscUJBQWQsQ0FBZDtBQUFBLE1BQ0lDLFVBQVUsR0FBR0osT0FBTyxDQUFDSyxLQUFSLENBQWMsc0JBQWQsS0FBeUMsRUFEMUQ7QUFBQSxNQUVJQyxJQUFJLEdBQUcsRUFGWDtBQUFBLE1BR0lDLENBQUMsR0FBRyxDQUhSOztBQUtBLFdBQVNDLFVBQVQsR0FBc0I7QUFDcEIsUUFBSUMsS0FBSyxHQUFHLEVBQVo7QUFDQUgsSUFBQUEsSUFBSSxDQUFDSSxJQUFMLENBQVVELEtBQVYsRUFGb0IsQ0FJcEI7O0FBQ0EsV0FBT0YsQ0FBQyxHQUFHTCxPQUFPLENBQUNTLE1BQW5CLEVBQTJCO0FBQ3pCLFVBQUlDLElBQUksR0FBR1YsT0FBTyxDQUFDSyxDQUFELENBQWxCLENBRHlCLENBR3pCOztBQUNBLFVBQUssdUJBQUQsQ0FBMEJNLElBQTFCLENBQStCRCxJQUEvQixDQUFKLEVBQTBDO0FBQ3hDO0FBQ0QsT0FOd0IsQ0FRekI7OztBQUNBLFVBQUlFLE1BQU0sR0FBSSwwQ0FBRCxDQUE2Q0MsSUFBN0MsQ0FBa0RILElBQWxELENBQWI7O0FBQ0EsVUFBSUUsTUFBSixFQUFZO0FBQ1ZMLFFBQUFBLEtBQUssQ0FBQ0EsS0FBTixHQUFjSyxNQUFNLENBQUMsQ0FBRCxDQUFwQjtBQUNEOztBQUVEUCxNQUFBQSxDQUFDO0FBQ0YsS0FwQm1CLENBc0JwQjtBQUNBOzs7QUFDQVMsSUFBQUEsZUFBZSxDQUFDUCxLQUFELENBQWY7QUFDQU8sSUFBQUEsZUFBZSxDQUFDUCxLQUFELENBQWYsQ0F6Qm9CLENBMkJwQjs7QUFDQUEsSUFBQUEsS0FBSyxDQUFDUSxLQUFOLEdBQWMsRUFBZDs7QUFFQSxXQUFPVixDQUFDLEdBQUdMLE9BQU8sQ0FBQ1MsTUFBbkIsRUFBMkI7QUFDekIsVUFBSUMsS0FBSSxHQUFHVixPQUFPLENBQUNLLENBQUQsQ0FBbEI7O0FBRUEsVUFBSyxnQ0FBRCxDQUFtQ00sSUFBbkMsQ0FBd0NELEtBQXhDLENBQUosRUFBbUQ7QUFDakQ7QUFDRCxPQUZELE1BRU8sSUFBSyxLQUFELENBQVFDLElBQVIsQ0FBYUQsS0FBYixDQUFKLEVBQXdCO0FBQzdCSCxRQUFBQSxLQUFLLENBQUNRLEtBQU4sQ0FBWVAsSUFBWixDQUFpQlEsU0FBUyxFQUExQjtBQUNELE9BRk0sTUFFQSxJQUFJTixLQUFJLElBQUlYLE9BQU8sQ0FBQ2tCLE1BQXBCLEVBQTRCO0FBQ2pDO0FBQ0EsY0FBTSxJQUFJQyxLQUFKLENBQVUsbUJBQW1CYixDQUFDLEdBQUcsQ0FBdkIsSUFBNEIsR0FBNUIsR0FBa0NjLElBQUksQ0FBQ0MsU0FBTCxDQUFlVixLQUFmLENBQTVDLENBQU47QUFDRCxPQUhNLE1BR0E7QUFDTEwsUUFBQUEsQ0FBQztBQUNGO0FBQ0Y7QUFDRixHQWxEK0MsQ0FvRGhEO0FBQ0E7OztBQUNBLFdBQVNTLGVBQVQsQ0FBeUJQLEtBQXpCLEVBQWdDO0FBQzlCLFFBQU1jLFVBQVUsR0FBSSx1QkFBRCxDQUEwQlIsSUFBMUIsQ0FBK0JiLE9BQU8sQ0FBQ0ssQ0FBRCxDQUF0QyxDQUFuQjs7QUFDQSxRQUFJZ0IsVUFBSixFQUFnQjtBQUNkLFVBQUlDLFNBQVMsR0FBR0QsVUFBVSxDQUFDLENBQUQsQ0FBVixLQUFrQixLQUFsQixHQUEwQixLQUExQixHQUFrQyxLQUFsRDtBQUNBLFVBQU1FLElBQUksR0FBR0YsVUFBVSxDQUFDLENBQUQsQ0FBVixDQUFjcEIsS0FBZCxDQUFvQixJQUFwQixFQUEwQixDQUExQixDQUFiO0FBQ0EsVUFBSXVCLFFBQVEsR0FBR0QsSUFBSSxDQUFDLENBQUQsQ0FBSixDQUFRRSxPQUFSLENBQWdCLE9BQWhCLEVBQXlCLElBQXpCLENBQWY7O0FBQ0EsVUFBSyxRQUFELENBQVdkLElBQVgsQ0FBZ0JhLFFBQWhCLENBQUosRUFBK0I7QUFDN0JBLFFBQUFBLFFBQVEsR0FBR0EsUUFBUSxDQUFDRSxNQUFULENBQWdCLENBQWhCLEVBQW1CRixRQUFRLENBQUNmLE1BQVQsR0FBa0IsQ0FBckMsQ0FBWDtBQUNEOztBQUNERixNQUFBQSxLQUFLLENBQUNlLFNBQVMsR0FBRyxVQUFiLENBQUwsR0FBZ0NFLFFBQWhDO0FBQ0FqQixNQUFBQSxLQUFLLENBQUNlLFNBQVMsR0FBRyxRQUFiLENBQUwsR0FBOEIsQ0FBQ0MsSUFBSSxDQUFDLENBQUQsQ0FBSixJQUFXLEVBQVosRUFBZ0JJLElBQWhCLEVBQTlCO0FBRUF0QixNQUFBQSxDQUFDO0FBQ0Y7QUFDRixHQXBFK0MsQ0FzRWhEO0FBQ0E7OztBQUNBLFdBQVNXLFNBQVQsR0FBcUI7QUFDbkIsUUFBSVksZ0JBQWdCLEdBQUd2QixDQUF2QjtBQUFBLFFBQ0l3QixlQUFlLEdBQUc3QixPQUFPLENBQUNLLENBQUMsRUFBRixDQUQ3QjtBQUFBLFFBRUl5QixXQUFXLEdBQUdELGVBQWUsQ0FBQzVCLEtBQWhCLENBQXNCLDRDQUF0QixDQUZsQjtBQUlBLFFBQUk4QixJQUFJLEdBQUc7QUFDVEMsTUFBQUEsUUFBUSxFQUFFLENBQUNGLFdBQVcsQ0FBQyxDQUFELENBRGI7QUFFVEcsTUFBQUEsUUFBUSxFQUFFLE9BQU9ILFdBQVcsQ0FBQyxDQUFELENBQWxCLEtBQTBCLFdBQTFCLEdBQXdDLENBQXhDLEdBQTRDLENBQUNBLFdBQVcsQ0FBQyxDQUFELENBRnpEO0FBR1RJLE1BQUFBLFFBQVEsRUFBRSxDQUFDSixXQUFXLENBQUMsQ0FBRCxDQUhiO0FBSVRLLE1BQUFBLFFBQVEsRUFBRSxPQUFPTCxXQUFXLENBQUMsQ0FBRCxDQUFsQixLQUEwQixXQUExQixHQUF3QyxDQUF4QyxHQUE0QyxDQUFDQSxXQUFXLENBQUMsQ0FBRCxDQUp6RDtBQUtUTSxNQUFBQSxLQUFLLEVBQUUsRUFMRTtBQU1UQyxNQUFBQSxjQUFjLEVBQUU7QUFOUCxLQUFYLENBTG1CLENBY25CO0FBQ0E7QUFDQTs7QUFDQSxRQUFJTixJQUFJLENBQUNFLFFBQUwsS0FBa0IsQ0FBdEIsRUFBeUI7QUFDdkJGLE1BQUFBLElBQUksQ0FBQ0MsUUFBTCxJQUFpQixDQUFqQjtBQUNEOztBQUNELFFBQUlELElBQUksQ0FBQ0ksUUFBTCxLQUFrQixDQUF0QixFQUF5QjtBQUN2QkosTUFBQUEsSUFBSSxDQUFDRyxRQUFMLElBQWlCLENBQWpCO0FBQ0Q7O0FBRUQsUUFBSUksUUFBUSxHQUFHLENBQWY7QUFBQSxRQUNJQyxXQUFXLEdBQUcsQ0FEbEI7O0FBRUEsV0FBT2xDLENBQUMsR0FBR0wsT0FBTyxDQUFDUyxNQUFuQixFQUEyQkosQ0FBQyxFQUE1QixFQUFnQztBQUM5QjtBQUNBO0FBQ0EsVUFBSUwsT0FBTyxDQUFDSyxDQUFELENBQVAsQ0FBV21DLE9BQVgsQ0FBbUIsTUFBbkIsTUFBK0IsQ0FBL0IsSUFDTW5DLENBQUMsR0FBRyxDQUFKLEdBQVFMLE9BQU8sQ0FBQ1MsTUFEdEIsSUFFS1QsT0FBTyxDQUFDSyxDQUFDLEdBQUcsQ0FBTCxDQUFQLENBQWVtQyxPQUFmLENBQXVCLE1BQXZCLE1BQW1DLENBRnhDLElBR0t4QyxPQUFPLENBQUNLLENBQUMsR0FBRyxDQUFMLENBQVAsQ0FBZW1DLE9BQWYsQ0FBdUIsSUFBdkIsTUFBaUMsQ0FIMUMsRUFHNkM7QUFDekM7QUFDSDs7QUFDRCxVQUFJQyxTQUFTLEdBQUl6QyxPQUFPLENBQUNLLENBQUQsQ0FBUCxDQUFXSSxNQUFYLElBQXFCLENBQXJCLElBQTBCSixDQUFDLElBQUtMLE9BQU8sQ0FBQ1MsTUFBUixHQUFpQixDQUFsRCxHQUF3RCxHQUF4RCxHQUE4RFQsT0FBTyxDQUFDSyxDQUFELENBQVAsQ0FBVyxDQUFYLENBQTlFOztBQUVBLFVBQUlvQyxTQUFTLEtBQUssR0FBZCxJQUFxQkEsU0FBUyxLQUFLLEdBQW5DLElBQTBDQSxTQUFTLEtBQUssR0FBeEQsSUFBK0RBLFNBQVMsS0FBSyxJQUFqRixFQUF1RjtBQUNyRlYsUUFBQUEsSUFBSSxDQUFDSyxLQUFMLENBQVc1QixJQUFYLENBQWdCUixPQUFPLENBQUNLLENBQUQsQ0FBdkI7QUFDQTBCLFFBQUFBLElBQUksQ0FBQ00sY0FBTCxDQUFvQjdCLElBQXBCLENBQXlCTixVQUFVLENBQUNHLENBQUQsQ0FBVixJQUFpQixJQUExQzs7QUFFQSxZQUFJb0MsU0FBUyxLQUFLLEdBQWxCLEVBQXVCO0FBQ3JCSCxVQUFBQSxRQUFRO0FBQ1QsU0FGRCxNQUVPLElBQUlHLFNBQVMsS0FBSyxHQUFsQixFQUF1QjtBQUM1QkYsVUFBQUEsV0FBVztBQUNaLFNBRk0sTUFFQSxJQUFJRSxTQUFTLEtBQUssR0FBbEIsRUFBdUI7QUFDNUJILFVBQUFBLFFBQVE7QUFDUkMsVUFBQUEsV0FBVztBQUNaO0FBQ0YsT0FaRCxNQVlPO0FBQ0w7QUFDRDtBQUNGLEtBcERrQixDQXNEbkI7OztBQUNBLFFBQUksQ0FBQ0QsUUFBRCxJQUFhUCxJQUFJLENBQUNJLFFBQUwsS0FBa0IsQ0FBbkMsRUFBc0M7QUFDcENKLE1BQUFBLElBQUksQ0FBQ0ksUUFBTCxHQUFnQixDQUFoQjtBQUNEOztBQUNELFFBQUksQ0FBQ0ksV0FBRCxJQUFnQlIsSUFBSSxDQUFDRSxRQUFMLEtBQWtCLENBQXRDLEVBQXlDO0FBQ3ZDRixNQUFBQSxJQUFJLENBQUNFLFFBQUwsR0FBZ0IsQ0FBaEI7QUFDRCxLQTVEa0IsQ0E4RG5COzs7QUFDQSxRQUFJbEMsT0FBTyxDQUFDa0IsTUFBWixFQUFvQjtBQUNsQixVQUFJcUIsUUFBUSxLQUFLUCxJQUFJLENBQUNJLFFBQXRCLEVBQWdDO0FBQzlCLGNBQU0sSUFBSWpCLEtBQUosQ0FBVSxzREFBc0RVLGdCQUFnQixHQUFHLENBQXpFLENBQVYsQ0FBTjtBQUNEOztBQUNELFVBQUlXLFdBQVcsS0FBS1IsSUFBSSxDQUFDRSxRQUF6QixFQUFtQztBQUNqQyxjQUFNLElBQUlmLEtBQUosQ0FBVSx3REFBd0RVLGdCQUFnQixHQUFHLENBQTNFLENBQVYsQ0FBTjtBQUNEO0FBQ0Y7O0FBRUQsV0FBT0csSUFBUDtBQUNEOztBQUVELFNBQU8xQixDQUFDLEdBQUdMLE9BQU8sQ0FBQ1MsTUFBbkIsRUFBMkI7QUFDekJILElBQUFBLFVBQVU7QUFDWDs7QUFFRCxTQUFPRixJQUFQO0FBQ0QiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZnVuY3Rpb24gcGFyc2VQYXRjaCh1bmlEaWZmLCBvcHRpb25zID0ge30pIHtcbiAgbGV0IGRpZmZzdHIgPSB1bmlEaWZmLnNwbGl0KC9cXHJcXG58W1xcblxcdlxcZlxcclxceDg1XS8pLFxuICAgICAgZGVsaW1pdGVycyA9IHVuaURpZmYubWF0Y2goL1xcclxcbnxbXFxuXFx2XFxmXFxyXFx4ODVdL2cpIHx8IFtdLFxuICAgICAgbGlzdCA9IFtdLFxuICAgICAgaSA9IDA7XG5cbiAgZnVuY3Rpb24gcGFyc2VJbmRleCgpIHtcbiAgICBsZXQgaW5kZXggPSB7fTtcbiAgICBsaXN0LnB1c2goaW5kZXgpO1xuXG4gICAgLy8gUGFyc2UgZGlmZiBtZXRhZGF0YVxuICAgIHdoaWxlIChpIDwgZGlmZnN0ci5sZW5ndGgpIHtcbiAgICAgIGxldCBsaW5lID0gZGlmZnN0cltpXTtcblxuICAgICAgLy8gRmlsZSBoZWFkZXIgZm91bmQsIGVuZCBwYXJzaW5nIGRpZmYgbWV0YWRhdGFcbiAgICAgIGlmICgoL14oXFwtXFwtXFwtfFxcK1xcK1xcK3xAQClcXHMvKS50ZXN0KGxpbmUpKSB7XG4gICAgICAgIGJyZWFrO1xuICAgICAgfVxuXG4gICAgICAvLyBEaWZmIGluZGV4XG4gICAgICBsZXQgaGVhZGVyID0gKC9eKD86SW5kZXg6fGRpZmYoPzogLXIgXFx3KykrKVxccysoLis/KVxccyokLykuZXhlYyhsaW5lKTtcbiAgICAgIGlmIChoZWFkZXIpIHtcbiAgICAgICAgaW5kZXguaW5kZXggPSBoZWFkZXJbMV07XG4gICAgICB9XG5cbiAgICAgIGkrKztcbiAgICB9XG5cbiAgICAvLyBQYXJzZSBmaWxlIGhlYWRlcnMgaWYgdGhleSBhcmUgZGVmaW5lZC4gVW5pZmllZCBkaWZmIHJlcXVpcmVzIHRoZW0sIGJ1dFxuICAgIC8vIHRoZXJlJ3Mgbm8gdGVjaG5pY2FsIGlzc3VlcyB0byBoYXZlIGFuIGlzb2xhdGVkIGh1bmsgd2l0aG91dCBmaWxlIGhlYWRlclxuICAgIHBhcnNlRmlsZUhlYWRlcihpbmRleCk7XG4gICAgcGFyc2VGaWxlSGVhZGVyKGluZGV4KTtcblxuICAgIC8vIFBhcnNlIGh1bmtzXG4gICAgaW5kZXguaHVua3MgPSBbXTtcblxuICAgIHdoaWxlIChpIDwgZGlmZnN0ci5sZW5ndGgpIHtcbiAgICAgIGxldCBsaW5lID0gZGlmZnN0cltpXTtcblxuICAgICAgaWYgKCgvXihJbmRleDp8ZGlmZnxcXC1cXC1cXC18XFwrXFwrXFwrKVxccy8pLnRlc3QobGluZSkpIHtcbiAgICAgICAgYnJlYWs7XG4gICAgICB9IGVsc2UgaWYgKCgvXkBALykudGVzdChsaW5lKSkge1xuICAgICAgICBpbmRleC5odW5rcy5wdXNoKHBhcnNlSHVuaygpKTtcbiAgICAgIH0gZWxzZSBpZiAobGluZSAmJiBvcHRpb25zLnN0cmljdCkge1xuICAgICAgICAvLyBJZ25vcmUgdW5leHBlY3RlZCBjb250ZW50IHVubGVzcyBpbiBzdHJpY3QgbW9kZVxuICAgICAgICB0aHJvdyBuZXcgRXJyb3IoJ1Vua25vd24gbGluZSAnICsgKGkgKyAxKSArICcgJyArIEpTT04uc3RyaW5naWZ5KGxpbmUpKTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIGkrKztcbiAgICAgIH1cbiAgICB9XG4gIH1cblxuICAvLyBQYXJzZXMgdGhlIC0tLSBhbmQgKysrIGhlYWRlcnMsIGlmIG5vbmUgYXJlIGZvdW5kLCBubyBsaW5lc1xuICAvLyBhcmUgY29uc3VtZWQuXG4gIGZ1bmN0aW9uIHBhcnNlRmlsZUhlYWRlcihpbmRleCkge1xuICAgIGNvbnN0IGZpbGVIZWFkZXIgPSAoL14oLS0tfFxcK1xcK1xcKylcXHMrKC4qKSQvKS5leGVjKGRpZmZzdHJbaV0pO1xuICAgIGlmIChmaWxlSGVhZGVyKSB7XG4gICAgICBsZXQga2V5UHJlZml4ID0gZmlsZUhlYWRlclsxXSA9PT0gJy0tLScgPyAnb2xkJyA6ICduZXcnO1xuICAgICAgY29uc3QgZGF0YSA9IGZpbGVIZWFkZXJbMl0uc3BsaXQoJ1xcdCcsIDIpO1xuICAgICAgbGV0IGZpbGVOYW1lID0gZGF0YVswXS5yZXBsYWNlKC9cXFxcXFxcXC9nLCAnXFxcXCcpO1xuICAgICAgaWYgKCgvXlwiLipcIiQvKS50ZXN0KGZpbGVOYW1lKSkge1xuICAgICAgICBmaWxlTmFtZSA9IGZpbGVOYW1lLnN1YnN0cigxLCBmaWxlTmFtZS5sZW5ndGggLSAyKTtcbiAgICAgIH1cbiAgICAgIGluZGV4W2tleVByZWZpeCArICdGaWxlTmFtZSddID0gZmlsZU5hbWU7XG4gICAgICBpbmRleFtrZXlQcmVmaXggKyAnSGVhZGVyJ10gPSAoZGF0YVsxXSB8fCAnJykudHJpbSgpO1xuXG4gICAgICBpKys7XG4gICAgfVxuICB9XG5cbiAgLy8gUGFyc2VzIGEgaHVua1xuICAvLyBUaGlzIGFzc3VtZXMgdGhhdCB3ZSBhcmUgYXQgdGhlIHN0YXJ0IG9mIGEgaHVuay5cbiAgZnVuY3Rpb24gcGFyc2VIdW5rKCkge1xuICAgIGxldCBjaHVua0hlYWRlckluZGV4ID0gaSxcbiAgICAgICAgY2h1bmtIZWFkZXJMaW5lID0gZGlmZnN0cltpKytdLFxuICAgICAgICBjaHVua0hlYWRlciA9IGNodW5rSGVhZGVyTGluZS5zcGxpdCgvQEAgLShcXGQrKSg/OiwoXFxkKykpPyBcXCsoXFxkKykoPzosKFxcZCspKT8gQEAvKTtcblxuICAgIGxldCBodW5rID0ge1xuICAgICAgb2xkU3RhcnQ6ICtjaHVua0hlYWRlclsxXSxcbiAgICAgIG9sZExpbmVzOiB0eXBlb2YgY2h1bmtIZWFkZXJbMl0gPT09ICd1bmRlZmluZWQnID8gMSA6ICtjaHVua0hlYWRlclsyXSxcbiAgICAgIG5ld1N0YXJ0OiArY2h1bmtIZWFkZXJbM10sXG4gICAgICBuZXdMaW5lczogdHlwZW9mIGNodW5rSGVhZGVyWzRdID09PSAndW5kZWZpbmVkJyA/IDEgOiArY2h1bmtIZWFkZXJbNF0sXG4gICAgICBsaW5lczogW10sXG4gICAgICBsaW5lZGVsaW1pdGVyczogW11cbiAgICB9O1xuXG4gICAgLy8gVW5pZmllZCBEaWZmIEZvcm1hdCBxdWlyazogSWYgdGhlIGNodW5rIHNpemUgaXMgMCxcbiAgICAvLyB0aGUgZmlyc3QgbnVtYmVyIGlzIG9uZSBsb3dlciB0aGFuIG9uZSB3b3VsZCBleHBlY3QuXG4gICAgLy8gaHR0cHM6Ly93d3cuYXJ0aW1hLmNvbS93ZWJsb2dzL3ZpZXdwb3N0LmpzcD90aHJlYWQ9MTY0MjkzXG4gICAgaWYgKGh1bmsub2xkTGluZXMgPT09IDApIHtcbiAgICAgIGh1bmsub2xkU3RhcnQgKz0gMTtcbiAgICB9XG4gICAgaWYgKGh1bmsubmV3TGluZXMgPT09IDApIHtcbiAgICAgIGh1bmsubmV3U3RhcnQgKz0gMTtcbiAgICB9XG5cbiAgICBsZXQgYWRkQ291bnQgPSAwLFxuICAgICAgICByZW1vdmVDb3VudCA9IDA7XG4gICAgZm9yICg7IGkgPCBkaWZmc3RyLmxlbmd0aDsgaSsrKSB7XG4gICAgICAvLyBMaW5lcyBzdGFydGluZyB3aXRoICctLS0nIGNvdWxkIGJlIG1pc3Rha2VuIGZvciB0aGUgXCJyZW1vdmUgbGluZVwiIG9wZXJhdGlvblxuICAgICAgLy8gQnV0IHRoZXkgY291bGQgYmUgdGhlIGhlYWRlciBmb3IgdGhlIG5leHQgZmlsZS4gVGhlcmVmb3JlIHBydW5lIHN1Y2ggY2FzZXMgb3V0LlxuICAgICAgaWYgKGRpZmZzdHJbaV0uaW5kZXhPZignLS0tICcpID09PSAwXG4gICAgICAgICAgICAmJiAoaSArIDIgPCBkaWZmc3RyLmxlbmd0aClcbiAgICAgICAgICAgICYmIGRpZmZzdHJbaSArIDFdLmluZGV4T2YoJysrKyAnKSA9PT0gMFxuICAgICAgICAgICAgJiYgZGlmZnN0cltpICsgMl0uaW5kZXhPZignQEAnKSA9PT0gMCkge1xuICAgICAgICAgIGJyZWFrO1xuICAgICAgfVxuICAgICAgbGV0IG9wZXJhdGlvbiA9IChkaWZmc3RyW2ldLmxlbmd0aCA9PSAwICYmIGkgIT0gKGRpZmZzdHIubGVuZ3RoIC0gMSkpID8gJyAnIDogZGlmZnN0cltpXVswXTtcblxuICAgICAgaWYgKG9wZXJhdGlvbiA9PT0gJysnIHx8IG9wZXJhdGlvbiA9PT0gJy0nIHx8IG9wZXJhdGlvbiA9PT0gJyAnIHx8IG9wZXJhdGlvbiA9PT0gJ1xcXFwnKSB7XG4gICAgICAgIGh1bmsubGluZXMucHVzaChkaWZmc3RyW2ldKTtcbiAgICAgICAgaHVuay5saW5lZGVsaW1pdGVycy5wdXNoKGRlbGltaXRlcnNbaV0gfHwgJ1xcbicpO1xuXG4gICAgICAgIGlmIChvcGVyYXRpb24gPT09ICcrJykge1xuICAgICAgICAgIGFkZENvdW50Kys7XG4gICAgICAgIH0gZWxzZSBpZiAob3BlcmF0aW9uID09PSAnLScpIHtcbiAgICAgICAgICByZW1vdmVDb3VudCsrO1xuICAgICAgICB9IGVsc2UgaWYgKG9wZXJhdGlvbiA9PT0gJyAnKSB7XG4gICAgICAgICAgYWRkQ291bnQrKztcbiAgICAgICAgICByZW1vdmVDb3VudCsrO1xuICAgICAgICB9XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBicmVhaztcbiAgICAgIH1cbiAgICB9XG5cbiAgICAvLyBIYW5kbGUgdGhlIGVtcHR5IGJsb2NrIGNvdW50IGNhc2VcbiAgICBpZiAoIWFkZENvdW50ICYmIGh1bmsubmV3TGluZXMgPT09IDEpIHtcbiAgICAgIGh1bmsubmV3TGluZXMgPSAwO1xuICAgIH1cbiAgICBpZiAoIXJlbW92ZUNvdW50ICYmIGh1bmsub2xkTGluZXMgPT09IDEpIHtcbiAgICAgIGh1bmsub2xkTGluZXMgPSAwO1xuICAgIH1cblxuICAgIC8vIFBlcmZvcm0gb3B0aW9uYWwgc2FuaXR5IGNoZWNraW5nXG4gICAgaWYgKG9wdGlvbnMuc3RyaWN0KSB7XG4gICAgICBpZiAoYWRkQ291bnQgIT09IGh1bmsubmV3TGluZXMpIHtcbiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdBZGRlZCBsaW5lIGNvdW50IGRpZCBub3QgbWF0Y2ggZm9yIGh1bmsgYXQgbGluZSAnICsgKGNodW5rSGVhZGVySW5kZXggKyAxKSk7XG4gICAgICB9XG4gICAgICBpZiAocmVtb3ZlQ291bnQgIT09IGh1bmsub2xkTGluZXMpIHtcbiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdSZW1vdmVkIGxpbmUgY291bnQgZGlkIG5vdCBtYXRjaCBmb3IgaHVuayBhdCBsaW5lICcgKyAoY2h1bmtIZWFkZXJJbmRleCArIDEpKTtcbiAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4gaHVuaztcbiAgfVxuXG4gIHdoaWxlIChpIDwgZGlmZnN0ci5sZW5ndGgpIHtcbiAgICBwYXJzZUluZGV4KCk7XG4gIH1cblxuICByZXR1cm4gbGlzdDtcbn1cbiJdfQ==
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/util/array.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/util/array.js
          new file mode 100644
          index 00000000000000..aecf67ac817c16
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/util/array.js
          @@ -0,0 +1,32 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.arrayEqual = arrayEqual;
          +exports.arrayStartsWith = arrayStartsWith;
          +
          +/*istanbul ignore end*/
          +function arrayEqual(a, b) {
          +  if (a.length !== b.length) {
          +    return false;
          +  }
          +
          +  return arrayStartsWith(a, b);
          +}
          +
          +function arrayStartsWith(array, start) {
          +  if (start.length > array.length) {
          +    return false;
          +  }
          +
          +  for (var i = 0; i < start.length; i++) {
          +    if (start[i] !== array[i]) {
          +      return false;
          +    }
          +  }
          +
          +  return true;
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsL2FycmF5LmpzIl0sIm5hbWVzIjpbImFycmF5RXF1YWwiLCJhIiwiYiIsImxlbmd0aCIsImFycmF5U3RhcnRzV2l0aCIsImFycmF5Iiwic3RhcnQiLCJpIl0sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQU8sU0FBU0EsVUFBVCxDQUFvQkMsQ0FBcEIsRUFBdUJDLENBQXZCLEVBQTBCO0FBQy9CLE1BQUlELENBQUMsQ0FBQ0UsTUFBRixLQUFhRCxDQUFDLENBQUNDLE1BQW5CLEVBQTJCO0FBQ3pCLFdBQU8sS0FBUDtBQUNEOztBQUVELFNBQU9DLGVBQWUsQ0FBQ0gsQ0FBRCxFQUFJQyxDQUFKLENBQXRCO0FBQ0Q7O0FBRU0sU0FBU0UsZUFBVCxDQUF5QkMsS0FBekIsRUFBZ0NDLEtBQWhDLEVBQXVDO0FBQzVDLE1BQUlBLEtBQUssQ0FBQ0gsTUFBTixHQUFlRSxLQUFLLENBQUNGLE1BQXpCLEVBQWlDO0FBQy9CLFdBQU8sS0FBUDtBQUNEOztBQUVELE9BQUssSUFBSUksQ0FBQyxHQUFHLENBQWIsRUFBZ0JBLENBQUMsR0FBR0QsS0FBSyxDQUFDSCxNQUExQixFQUFrQ0ksQ0FBQyxFQUFuQyxFQUF1QztBQUNyQyxRQUFJRCxLQUFLLENBQUNDLENBQUQsQ0FBTCxLQUFhRixLQUFLLENBQUNFLENBQUQsQ0FBdEIsRUFBMkI7QUFDekIsYUFBTyxLQUFQO0FBQ0Q7QUFDRjs7QUFFRCxTQUFPLElBQVA7QUFDRCIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBmdW5jdGlvbiBhcnJheUVxdWFsKGEsIGIpIHtcbiAgaWYgKGEubGVuZ3RoICE9PSBiLmxlbmd0aCkge1xuICAgIHJldHVybiBmYWxzZTtcbiAgfVxuXG4gIHJldHVybiBhcnJheVN0YXJ0c1dpdGgoYSwgYik7XG59XG5cbmV4cG9ydCBmdW5jdGlvbiBhcnJheVN0YXJ0c1dpdGgoYXJyYXksIHN0YXJ0KSB7XG4gIGlmIChzdGFydC5sZW5ndGggPiBhcnJheS5sZW5ndGgpIHtcbiAgICByZXR1cm4gZmFsc2U7XG4gIH1cblxuICBmb3IgKGxldCBpID0gMDsgaSA8IHN0YXJ0Lmxlbmd0aDsgaSsrKSB7XG4gICAgaWYgKHN0YXJ0W2ldICE9PSBhcnJheVtpXSkge1xuICAgICAgcmV0dXJuIGZhbHNlO1xuICAgIH1cbiAgfVxuXG4gIHJldHVybiB0cnVlO1xufVxuIl19
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/util/distance-iterator.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/util/distance-iterator.js
          new file mode 100644
          index 00000000000000..57c06a3f9cf1ce
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/util/distance-iterator.js
          @@ -0,0 +1,57 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports["default"] = _default;
          +
          +/*istanbul ignore end*/
          +// Iterator that traverses in the range of [min, max], stepping
          +// by distance from a given start position. I.e. for [0, 4], with
          +// start of 2, this will iterate 2, 3, 1, 4, 0.
          +function
          +/*istanbul ignore start*/
          +_default
          +/*istanbul ignore end*/
          +(start, minLine, maxLine) {
          +  var wantForward = true,
          +      backwardExhausted = false,
          +      forwardExhausted = false,
          +      localOffset = 1;
          +  return function iterator() {
          +    if (wantForward && !forwardExhausted) {
          +      if (backwardExhausted) {
          +        localOffset++;
          +      } else {
          +        wantForward = false;
          +      } // Check if trying to fit beyond text length, and if not, check it fits
          +      // after offset location (or desired location on first iteration)
          +
          +
          +      if (start + localOffset <= maxLine) {
          +        return localOffset;
          +      }
          +
          +      forwardExhausted = true;
          +    }
          +
          +    if (!backwardExhausted) {
          +      if (!forwardExhausted) {
          +        wantForward = true;
          +      } // Check if trying to fit before text beginning, and if not, check it fits
          +      // before offset location
          +
          +
          +      if (minLine <= start - localOffset) {
          +        return -localOffset++;
          +      }
          +
          +      backwardExhausted = true;
          +      return iterator();
          +    } // We tried to fit hunk before text beginning and beyond text length, then
          +    // hunk can't fit on the text. Return undefined
          +
          +  };
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsL2Rpc3RhbmNlLWl0ZXJhdG9yLmpzIl0sIm5hbWVzIjpbInN0YXJ0IiwibWluTGluZSIsIm1heExpbmUiLCJ3YW50Rm9yd2FyZCIsImJhY2t3YXJkRXhoYXVzdGVkIiwiZm9yd2FyZEV4aGF1c3RlZCIsImxvY2FsT2Zmc2V0IiwiaXRlcmF0b3IiXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBO0FBQ0E7QUFDQTtBQUNlO0FBQUE7QUFBQTtBQUFBO0FBQUEsQ0FBU0EsS0FBVCxFQUFnQkMsT0FBaEIsRUFBeUJDLE9BQXpCLEVBQWtDO0FBQy9DLE1BQUlDLFdBQVcsR0FBRyxJQUFsQjtBQUFBLE1BQ0lDLGlCQUFpQixHQUFHLEtBRHhCO0FBQUEsTUFFSUMsZ0JBQWdCLEdBQUcsS0FGdkI7QUFBQSxNQUdJQyxXQUFXLEdBQUcsQ0FIbEI7QUFLQSxTQUFPLFNBQVNDLFFBQVQsR0FBb0I7QUFDekIsUUFBSUosV0FBVyxJQUFJLENBQUNFLGdCQUFwQixFQUFzQztBQUNwQyxVQUFJRCxpQkFBSixFQUF1QjtBQUNyQkUsUUFBQUEsV0FBVztBQUNaLE9BRkQsTUFFTztBQUNMSCxRQUFBQSxXQUFXLEdBQUcsS0FBZDtBQUNELE9BTG1DLENBT3BDO0FBQ0E7OztBQUNBLFVBQUlILEtBQUssR0FBR00sV0FBUixJQUF1QkosT0FBM0IsRUFBb0M7QUFDbEMsZUFBT0ksV0FBUDtBQUNEOztBQUVERCxNQUFBQSxnQkFBZ0IsR0FBRyxJQUFuQjtBQUNEOztBQUVELFFBQUksQ0FBQ0QsaUJBQUwsRUFBd0I7QUFDdEIsVUFBSSxDQUFDQyxnQkFBTCxFQUF1QjtBQUNyQkYsUUFBQUEsV0FBVyxHQUFHLElBQWQ7QUFDRCxPQUhxQixDQUt0QjtBQUNBOzs7QUFDQSxVQUFJRixPQUFPLElBQUlELEtBQUssR0FBR00sV0FBdkIsRUFBb0M7QUFDbEMsZUFBTyxDQUFDQSxXQUFXLEVBQW5CO0FBQ0Q7O0FBRURGLE1BQUFBLGlCQUFpQixHQUFHLElBQXBCO0FBQ0EsYUFBT0csUUFBUSxFQUFmO0FBQ0QsS0E5QndCLENBZ0N6QjtBQUNBOztBQUNELEdBbENEO0FBbUNEIiwic291cmNlc0NvbnRlbnQiOlsiLy8gSXRlcmF0b3IgdGhhdCB0cmF2ZXJzZXMgaW4gdGhlIHJhbmdlIG9mIFttaW4sIG1heF0sIHN0ZXBwaW5nXG4vLyBieSBkaXN0YW5jZSBmcm9tIGEgZ2l2ZW4gc3RhcnQgcG9zaXRpb24uIEkuZS4gZm9yIFswLCA0XSwgd2l0aFxuLy8gc3RhcnQgb2YgMiwgdGhpcyB3aWxsIGl0ZXJhdGUgMiwgMywgMSwgNCwgMC5cbmV4cG9ydCBkZWZhdWx0IGZ1bmN0aW9uKHN0YXJ0LCBtaW5MaW5lLCBtYXhMaW5lKSB7XG4gIGxldCB3YW50Rm9yd2FyZCA9IHRydWUsXG4gICAgICBiYWNrd2FyZEV4aGF1c3RlZCA9IGZhbHNlLFxuICAgICAgZm9yd2FyZEV4aGF1c3RlZCA9IGZhbHNlLFxuICAgICAgbG9jYWxPZmZzZXQgPSAxO1xuXG4gIHJldHVybiBmdW5jdGlvbiBpdGVyYXRvcigpIHtcbiAgICBpZiAod2FudEZvcndhcmQgJiYgIWZvcndhcmRFeGhhdXN0ZWQpIHtcbiAgICAgIGlmIChiYWNrd2FyZEV4aGF1c3RlZCkge1xuICAgICAgICBsb2NhbE9mZnNldCsrO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgd2FudEZvcndhcmQgPSBmYWxzZTtcbiAgICAgIH1cblxuICAgICAgLy8gQ2hlY2sgaWYgdHJ5aW5nIHRvIGZpdCBiZXlvbmQgdGV4dCBsZW5ndGgsIGFuZCBpZiBub3QsIGNoZWNrIGl0IGZpdHNcbiAgICAgIC8vIGFmdGVyIG9mZnNldCBsb2NhdGlvbiAob3IgZGVzaXJlZCBsb2NhdGlvbiBvbiBmaXJzdCBpdGVyYXRpb24pXG4gICAgICBpZiAoc3RhcnQgKyBsb2NhbE9mZnNldCA8PSBtYXhMaW5lKSB7XG4gICAgICAgIHJldHVybiBsb2NhbE9mZnNldDtcbiAgICAgIH1cblxuICAgICAgZm9yd2FyZEV4aGF1c3RlZCA9IHRydWU7XG4gICAgfVxuXG4gICAgaWYgKCFiYWNrd2FyZEV4aGF1c3RlZCkge1xuICAgICAgaWYgKCFmb3J3YXJkRXhoYXVzdGVkKSB7XG4gICAgICAgIHdhbnRGb3J3YXJkID0gdHJ1ZTtcbiAgICAgIH1cblxuICAgICAgLy8gQ2hlY2sgaWYgdHJ5aW5nIHRvIGZpdCBiZWZvcmUgdGV4dCBiZWdpbm5pbmcsIGFuZCBpZiBub3QsIGNoZWNrIGl0IGZpdHNcbiAgICAgIC8vIGJlZm9yZSBvZmZzZXQgbG9jYXRpb25cbiAgICAgIGlmIChtaW5MaW5lIDw9IHN0YXJ0IC0gbG9jYWxPZmZzZXQpIHtcbiAgICAgICAgcmV0dXJuIC1sb2NhbE9mZnNldCsrO1xuICAgICAgfVxuXG4gICAgICBiYWNrd2FyZEV4aGF1c3RlZCA9IHRydWU7XG4gICAgICByZXR1cm4gaXRlcmF0b3IoKTtcbiAgICB9XG5cbiAgICAvLyBXZSB0cmllZCB0byBmaXQgaHVuayBiZWZvcmUgdGV4dCBiZWdpbm5pbmcgYW5kIGJleW9uZCB0ZXh0IGxlbmd0aCwgdGhlblxuICAgIC8vIGh1bmsgY2FuJ3QgZml0IG9uIHRoZSB0ZXh0LiBSZXR1cm4gdW5kZWZpbmVkXG4gIH07XG59XG4iXX0=
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/util/params.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/util/params.js
          new file mode 100644
          index 00000000000000..e838eb2f42d157
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/lib/util/params.js
          @@ -0,0 +1,24 @@
          +/*istanbul ignore start*/
          +"use strict";
          +
          +Object.defineProperty(exports, "__esModule", {
          +  value: true
          +});
          +exports.generateOptions = generateOptions;
          +
          +/*istanbul ignore end*/
          +function generateOptions(options, defaults) {
          +  if (typeof options === 'function') {
          +    defaults.callback = options;
          +  } else if (options) {
          +    for (var name in options) {
          +      /* istanbul ignore else */
          +      if (options.hasOwnProperty(name)) {
          +        defaults[name] = options[name];
          +      }
          +    }
          +  }
          +
          +  return defaults;
          +}
          +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsL3BhcmFtcy5qcyJdLCJuYW1lcyI6WyJnZW5lcmF0ZU9wdGlvbnMiLCJvcHRpb25zIiwiZGVmYXVsdHMiLCJjYWxsYmFjayIsIm5hbWUiLCJoYXNPd25Qcm9wZXJ0eSJdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQU8sU0FBU0EsZUFBVCxDQUF5QkMsT0FBekIsRUFBa0NDLFFBQWxDLEVBQTRDO0FBQ2pELE1BQUksT0FBT0QsT0FBUCxLQUFtQixVQUF2QixFQUFtQztBQUNqQ0MsSUFBQUEsUUFBUSxDQUFDQyxRQUFULEdBQW9CRixPQUFwQjtBQUNELEdBRkQsTUFFTyxJQUFJQSxPQUFKLEVBQWE7QUFDbEIsU0FBSyxJQUFJRyxJQUFULElBQWlCSCxPQUFqQixFQUEwQjtBQUN4QjtBQUNBLFVBQUlBLE9BQU8sQ0FBQ0ksY0FBUixDQUF1QkQsSUFBdkIsQ0FBSixFQUFrQztBQUNoQ0YsUUFBQUEsUUFBUSxDQUFDRSxJQUFELENBQVIsR0FBaUJILE9BQU8sQ0FBQ0csSUFBRCxDQUF4QjtBQUNEO0FBQ0Y7QUFDRjs7QUFDRCxTQUFPRixRQUFQO0FBQ0QiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZnVuY3Rpb24gZ2VuZXJhdGVPcHRpb25zKG9wdGlvbnMsIGRlZmF1bHRzKSB7XG4gIGlmICh0eXBlb2Ygb3B0aW9ucyA9PT0gJ2Z1bmN0aW9uJykge1xuICAgIGRlZmF1bHRzLmNhbGxiYWNrID0gb3B0aW9ucztcbiAgfSBlbHNlIGlmIChvcHRpb25zKSB7XG4gICAgZm9yIChsZXQgbmFtZSBpbiBvcHRpb25zKSB7XG4gICAgICAvKiBpc3RhbmJ1bCBpZ25vcmUgZWxzZSAqL1xuICAgICAgaWYgKG9wdGlvbnMuaGFzT3duUHJvcGVydHkobmFtZSkpIHtcbiAgICAgICAgZGVmYXVsdHNbbmFtZV0gPSBvcHRpb25zW25hbWVdO1xuICAgICAgfVxuICAgIH1cbiAgfVxuICByZXR1cm4gZGVmYXVsdHM7XG59XG4iXX0=
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/package.json b/deps/npm/node_modules/libnpmdiff/node_modules/diff/package.json
          new file mode 100644
          index 00000000000000..2b6eea7f1cbff3
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/package.json
          @@ -0,0 +1,87 @@
          +{
          +  "name": "diff",
          +  "version": "5.0.0",
          +  "description": "A javascript text diff implementation.",
          +  "keywords": [
          +    "diff",
          +    "jsdiff",
          +    "compare",
          +    "patch",
          +    "text",
          +    "json",
          +    "css",
          +    "javascript"
          +  ],
          +  "maintainers": [
          +    "Kevin Decker  (http://incaseofstairs.com)"
          +  ],
          +  "bugs": {
          +    "email": "kpdecker@gmail.com",
          +    "url": "http://github.com/kpdecker/jsdiff/issues"
          +  },
          +  "license": "BSD-3-Clause",
          +  "repository": {
          +    "type": "git",
          +    "url": "git://github.com/kpdecker/jsdiff.git"
          +  },
          +  "engines": {
          +    "node": ">=0.3.1"
          +  },
          +  "main": "./lib/index.js",
          +  "module": "./lib/index.es6.js",
          +  "browser": "./dist/diff.js",
          +  "unpkg": "./dist/diff.js",
          +  "exports": {
          +    ".": {
          +      "import": "./lib/index.mjs",
          +      "require": "./lib/index.js"
          +    },
          +    "./package.json": "./package.json",
          +    "./": "./"
          +  },
          +  "scripts": {
          +    "clean": "rm -rf lib/ dist/",
          +    "build:node": "yarn babel --out-dir lib  --source-maps=inline src",
          +    "test": "grunt"
          +  },
          +  "devDependencies": {
          +    "@babel/cli": "^7.2.3",
          +    "@babel/core": "^7.2.2",
          +    "@babel/plugin-transform-modules-commonjs": "^7.2.0",
          +    "@babel/preset-env": "^7.2.3",
          +    "@babel/register": "^7.0.0",
          +    "babel-eslint": "^10.0.1",
          +    "babel-loader": "^8.0.5",
          +    "chai": "^4.2.0",
          +    "colors": "^1.3.3",
          +    "eslint": "^5.12.0",
          +    "grunt": "^1.0.3",
          +    "grunt-babel": "^8.0.0",
          +    "grunt-cli": "^1.3.2",
          +    "grunt-contrib-clean": "^2.0.0",
          +    "grunt-contrib-copy": "^1.0.0",
          +    "grunt-contrib-uglify": "^5.0.0",
          +    "grunt-contrib-watch": "^1.1.0",
          +    "grunt-eslint": "^23.0.0",
          +    "grunt-exec": "^3.0.0",
          +    "grunt-karma": "^4.0.0",
          +    "grunt-mocha-istanbul": "^5.0.2",
          +    "grunt-mocha-test": "^0.13.3",
          +    "grunt-webpack": "^3.1.3",
          +    "istanbul": "github:kpdecker/istanbul",
          +    "karma": "^5.1.1",
          +    "karma-chrome-launcher": "^3.1.0",
          +    "karma-mocha": "^2.0.1",
          +    "karma-mocha-reporter": "^2.0.0",
          +    "karma-sauce-launcher": "^4.1.5",
          +    "karma-sourcemap-loader": "^0.3.6",
          +    "karma-webpack": "^4.0.2",
          +    "mocha": "^6.0.0",
          +    "rollup": "^1.0.2",
          +    "rollup-plugin-babel": "^4.2.0",
          +    "semver": "^7.3.2",
          +    "webpack": "^4.28.3",
          +    "webpack-dev-server": "^3.1.14"
          +  },
          +  "optionalDependencies": {}
          +}
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/release-notes.md b/deps/npm/node_modules/libnpmdiff/node_modules/diff/release-notes.md
          new file mode 100644
          index 00000000000000..acc75aa83d88e4
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/release-notes.md
          @@ -0,0 +1,303 @@
          +# Release Notes
          +
          +## Development
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v5.0.0...master)
          +
          +## v5.0.0
          +
          +- Breaking: UMD export renamed from `JsDiff` to `Diff`.
          +- Breaking: Newlines separated into separate tokens for word diff.
          +- Breaking: Unified diffs now match ["quirks"](https://www.artima.com/weblogs/viewpost.jsp?thread=164293)
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v4.0.1...v5.0.0)
          +
          +## v4.0.1 - January 6th, 2019
          +
          +- Fix main reference path - b826104
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v4.0.0...v4.0.1)
          +
          +## v4.0.0 - January 5th, 2019
          +
          +- [#94](https://github.com/kpdecker/jsdiff/issues/94) - Missing "No newline at end of file" when comparing two texts that do not end in newlines ([@federicotdn](https://api.github.com/users/federicotdn))
          +- [#227](https://github.com/kpdecker/jsdiff/issues/227) - Licence
          +- [#199](https://github.com/kpdecker/jsdiff/issues/199) - Import statement for jsdiff
          +- [#159](https://github.com/kpdecker/jsdiff/issues/159) - applyPatch affecting wrong line number with with new lines
          +- [#8](https://github.com/kpdecker/jsdiff/issues/8) - A new state "replace"
          +- Drop ie9 from karma targets - 79c31bd
          +- Upgrade deps. Convert from webpack to rollup - 2c1a29c
          +- Make ()[]"' as word boundaries between each other - f27b899
          +- jsdiff: Replaced phantomJS by chrome - ec3114e
          +- Add yarn.lock to .npmignore - 29466d8
          +
          +Compatibility notes:
          +
          +- Bower and Component packages no longer supported
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v3.5.0...v4.0.0)
          +
          +## v3.5.0 - March 4th, 2018
          +
          +- Omit redundant slice in join method of diffArrays - 1023590
          +- Support patches with empty lines - fb0f208
          +- Accept a custom JSON replacer function for JSON diffing - 69c7f0a
          +- Optimize parch header parser - 2aec429
          +- Fix typos - e89c832
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v3.4.0...v3.5.0)
          +
          +## v3.4.0 - October 7th, 2017
          +
          +- [#183](https://github.com/kpdecker/jsdiff/issues/183) - Feature request: ability to specify a custom equality checker for `diffArrays`
          +- [#173](https://github.com/kpdecker/jsdiff/issues/173) - Bug: diffArrays gives wrong result on array of booleans
          +- [#158](https://github.com/kpdecker/jsdiff/issues/158) - diffArrays will not compare the empty string in array?
          +- comparator for custom equality checks - 30e141e
          +- count oldLines and newLines when there are conflicts - 53bf384
          +- Fix: diffArrays can compare falsey items - 9e24284
          +- Docs: Replace grunt with npm test - 00e2f94
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v3.3.1...v3.4.0)
          +
          +## v3.3.1 - September 3rd, 2017
          +
          +- [#141](https://github.com/kpdecker/jsdiff/issues/141) - Cannot apply patch because my file delimiter is "/r/n" instead of "/n"
          +- [#192](https://github.com/kpdecker/jsdiff/pull/192) - Fix: Bad merge when adding new files (#189)
          +- correct spelling mistake - 21fa478
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v3.3.0...v3.3.1)
          +
          +## v3.3.0 - July 5th, 2017
          +
          +- [#114](https://github.com/kpdecker/jsdiff/issues/114) - /patch/merge not exported
          +- Gracefully accept invalid newStart in hunks, same as patch(1) does. - d8a3635
          +- Use regex rather than starts/ends with for parsePatch - 6cab62c
          +- Add browser flag - e64f674
          +- refactor: simplified code a bit more - 8f8e0f2
          +- refactor: simplified code a bit - b094a6f
          +- fix: some corrections re ignoreCase option - 3c78fd0
          +- ignoreCase option - 3cbfbb5
          +- Sanitize filename while parsing patches - 2fe8129
          +- Added better installation methods - aced50b
          +- Simple export of functionality - 8690f31
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v3.2.0...v3.3.0)
          +
          +## v3.2.0 - December 26th, 2016
          +
          +- [#156](https://github.com/kpdecker/jsdiff/pull/156) - Add `undefinedReplacement` option to `diffJson` ([@ewnd9](https://api.github.com/users/ewnd9))
          +- [#154](https://github.com/kpdecker/jsdiff/pull/154) - Add `examples` and `images` to `.npmignore`. ([@wtgtybhertgeghgtwtg](https://api.github.com/users/wtgtybhertgeghgtwtg))
          +- [#153](https://github.com/kpdecker/jsdiff/pull/153) - feat(structuredPatch): Pass options to diffLines ([@Kiougar](https://api.github.com/users/Kiougar))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v3.1.0...v3.2.0)
          +
          +## v3.1.0 - November 27th, 2016
          +
          +- [#146](https://github.com/kpdecker/jsdiff/pull/146) - JsDiff.diffArrays to compare arrays ([@wvanderdeijl](https://api.github.com/users/wvanderdeijl))
          +- [#144](https://github.com/kpdecker/jsdiff/pull/144) - Split file using all possible line delimiter instead of hard-coded "/n" and join lines back using the original delimiters ([@soulbeing](https://api.github.com/users/soulbeing))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v3.0.1...v3.1.0)
          +
          +## v3.0.1 - October 9th, 2016
          +
          +- [#139](https://github.com/kpdecker/jsdiff/pull/139) - Make README.md look nicer in npmjs.com ([@takenspc](https://api.github.com/users/takenspc))
          +- [#135](https://github.com/kpdecker/jsdiff/issues/135) - parsePatch combines patches from multiple files into a single IUniDiff when there is no "Index" line ([@ramya-rao-a](https://api.github.com/users/ramya-rao-a))
          +- [#124](https://github.com/kpdecker/jsdiff/issues/124) - IE7/IE8 failure since 2.0.0 ([@boneskull](https://api.github.com/users/boneskull))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v3.0.0...v3.0.1)
          +
          +## v3.0.0 - August 23rd, 2016
          +
          +- [#130](https://github.com/kpdecker/jsdiff/pull/130) - Add callback argument to applyPatches `patched` option ([@piranna](https://api.github.com/users/piranna))
          +- [#120](https://github.com/kpdecker/jsdiff/pull/120) - Correctly handle file names containing spaces ([@adius](https://api.github.com/users/adius))
          +- [#119](https://github.com/kpdecker/jsdiff/pull/119) - Do single reflow ([@wifiextender](https://api.github.com/users/wifiextender))
          +- [#117](https://github.com/kpdecker/jsdiff/pull/117) - Make more usable with long strings. ([@abnbgist](https://api.github.com/users/abnbgist))
          +
          +Compatibility notes:
          +
          +- applyPatches patch callback now is async and requires the callback be called to continue operation
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v2.2.3...v3.0.0)
          +
          +## v2.2.3 - May 31st, 2016
          +
          +- [#118](https://github.com/kpdecker/jsdiff/pull/118) - Add a fix for applying 0-length destination patches ([@chaaz](https://api.github.com/users/chaaz))
          +- [#115](https://github.com/kpdecker/jsdiff/pull/115) - Fixed grammar in README ([@krizalys](https://api.github.com/users/krizalys))
          +- [#113](https://github.com/kpdecker/jsdiff/pull/113) - fix typo ([@vmazare](https://api.github.com/users/vmazare))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v2.2.2...v2.2.3)
          +
          +## v2.2.2 - March 13th, 2016
          +
          +- [#102](https://github.com/kpdecker/jsdiff/issues/102) - diffJson with dates, returns empty curly braces ([@dr-dimitru](https://api.github.com/users/dr-dimitru))
          +- [#97](https://github.com/kpdecker/jsdiff/issues/97) - Whitespaces & diffWords ([@faiwer](https://api.github.com/users/faiwer))
          +- [#92](https://github.com/kpdecker/jsdiff/pull/92) - Fixes typo in the readme ([@bg451](https://api.github.com/users/bg451))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v2.2.1...v2.2.2)
          +
          +## v2.2.1 - November 12th, 2015
          +
          +- [#89](https://github.com/kpdecker/jsdiff/pull/89) - add in display selector to readme ([@FranDias](https://api.github.com/users/FranDias))
          +- [#88](https://github.com/kpdecker/jsdiff/pull/88) - Split diffs based on file headers instead of 'Index:' metadata ([@piranna](https://api.github.com/users/piranna))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v2.2.0...v2.2.1)
          +
          +## v2.2.0 - October 29th, 2015
          +
          +- [#80](https://github.com/kpdecker/jsdiff/pull/80) - Fix a typo: applyPath -> applyPatch ([@fluxxu](https://api.github.com/users/fluxxu))
          +- [#83](https://github.com/kpdecker/jsdiff/pull/83) - Add basic fuzzy matching to applyPatch ([@piranna](https://github.com/piranna))
          +  [Commits](https://github.com/kpdecker/jsdiff/compare/v2.2.0...v2.2.0)
          +
          +## v2.2.0 - October 29th, 2015
          +
          +- [#80](https://github.com/kpdecker/jsdiff/pull/80) - Fix a typo: applyPath -> applyPatch ([@fluxxu](https://api.github.com/users/fluxxu))
          +- [#83](https://github.com/kpdecker/jsdiff/pull/83) - Add basic fuzzy matching to applyPatch ([@piranna](https://github.com/piranna))
          +  [Commits](https://github.com/kpdecker/jsdiff/compare/v2.1.3...v2.2.0)
          +
          +## v2.1.3 - September 30th, 2015
          +
          +- [#78](https://github.com/kpdecker/jsdiff/pull/78) - fix: error throwing when apply patch to empty string ([@21paradox](https://api.github.com/users/21paradox))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v2.1.2...v2.1.3)
          +
          +## v2.1.2 - September 23rd, 2015
          +
          +- [#76](https://github.com/kpdecker/jsdiff/issues/76) - diff headers give error ([@piranna](https://api.github.com/users/piranna))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v2.1.1...v2.1.2)
          +
          +## v2.1.1 - September 9th, 2015
          +
          +- [#73](https://github.com/kpdecker/jsdiff/issues/73) - Is applyPatches() exposed in the API? ([@davidparsson](https://api.github.com/users/davidparsson))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v2.1.0...v2.1.1)
          +
          +## v2.1.0 - August 27th, 2015
          +
          +- [#72](https://github.com/kpdecker/jsdiff/issues/72) - Consider using options object API for flag permutations ([@kpdecker](https://api.github.com/users/kpdecker))
          +- [#70](https://github.com/kpdecker/jsdiff/issues/70) - diffWords treats \n at the end as significant whitespace ([@nesQuick](https://api.github.com/users/nesQuick))
          +- [#69](https://github.com/kpdecker/jsdiff/issues/69) - Missing count ([@wfalkwallace](https://api.github.com/users/wfalkwallace))
          +- [#68](https://github.com/kpdecker/jsdiff/issues/68) - diffLines seems broken ([@wfalkwallace](https://api.github.com/users/wfalkwallace))
          +- [#60](https://github.com/kpdecker/jsdiff/issues/60) - Support multiple diff hunks ([@piranna](https://api.github.com/users/piranna))
          +- [#54](https://github.com/kpdecker/jsdiff/issues/54) - Feature Request: 3-way merge ([@mog422](https://api.github.com/users/mog422))
          +- [#42](https://github.com/kpdecker/jsdiff/issues/42) - Fuzz factor for applyPatch ([@stuartpb](https://api.github.com/users/stuartpb))
          +- Move whitespace ignore out of equals method - 542063c
          +- Include source maps in babel output - 7f7ab21
          +- Merge diff/line and diff/patch implementations - 1597705
          +- Drop map utility method - 1ddc939
          +- Documentation for parsePatch and applyPatches - 27c4b77
          +
          +Compatibility notes:
          +
          +- The undocumented ignoreWhitespace flag has been removed from the Diff equality check directly. This implementation may be copied to diff utilities if dependencies existed on this functionality.
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v2.0.2...v2.1.0)
          +
          +## v2.0.2 - August 8th, 2015
          +
          +- [#67](https://github.com/kpdecker/jsdiff/issues/67) - cannot require from npm module in node ([@commenthol](https://api.github.com/users/commenthol))
          +- Convert to chai since we don’t support IE8 - a96bbad
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v2.0.1...v2.0.2)
          +
          +## v2.0.1 - August 7th, 2015
          +
          +- Add release build at proper step - 57542fd
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v2.0.0...v2.0.1)
          +
          +## v2.0.0 - August 7th, 2015
          +
          +- [#66](https://github.com/kpdecker/jsdiff/issues/66) - Add karma and sauce tests ([@kpdecker](https://api.github.com/users/kpdecker))
          +- [#65](https://github.com/kpdecker/jsdiff/issues/65) - Create component repository for bower ([@kpdecker](https://api.github.com/users/kpdecker))
          +- [#64](https://github.com/kpdecker/jsdiff/issues/64) - Automatically call removeEmpty for all tokenizer calls ([@kpdecker](https://api.github.com/users/kpdecker))
          +- [#62](https://github.com/kpdecker/jsdiff/pull/62) - Allow access to structured object representation of patch data ([@bittrance](https://api.github.com/users/bittrance))
          +- [#61](https://github.com/kpdecker/jsdiff/pull/61) - Use svg instead of png to get better image quality ([@PeterDaveHello](https://api.github.com/users/PeterDaveHello))
          +- [#29](https://github.com/kpdecker/jsdiff/issues/29) - word tokenizer works only for 7 bit ascii ([@plasmagunman](https://api.github.com/users/plasmagunman))
          +
          +Compatibility notes:
          +
          +- `this.removeEmpty` is now called automatically for all instances. If this is not desired, this may be overridden on a per instance basis.
          +- The library has been refactored to use some ES6 features. The external APIs should remain the same, but bower projects that directly referenced the repository will now have to point to the [components/jsdiff](https://github.com/components/jsdiff) repository.
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v1.4.0...v2.0.0)
          +
          +## v1.4.0 - May 6th, 2015
          +
          +- [#57](https://github.com/kpdecker/jsdiff/issues/57) - createPatch -> applyPatch failed. ([@mog422](https://api.github.com/users/mog422))
          +- [#56](https://github.com/kpdecker/jsdiff/pull/56) - Two files patch ([@rgeissert](https://api.github.com/users/rgeissert))
          +- [#14](https://github.com/kpdecker/jsdiff/issues/14) - Flip added and removed order? ([@jakesandlund](https://api.github.com/users/jakesandlund))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v1.3.2...v1.4.0)
          +
          +## v1.3.2 - March 30th, 2015
          +
          +- [#53](https://github.com/kpdecker/jsdiff/pull/53) - Updated README.MD with Bower installation instructions ([@ofbriggs](https://api.github.com/users/ofbriggs))
          +- [#49](https://github.com/kpdecker/jsdiff/issues/49) - Cannot read property 'oldlines' of undefined ([@nwtn](https://api.github.com/users/nwtn))
          +- [#44](https://github.com/kpdecker/jsdiff/issues/44) - invalid-meta jsdiff is missing "main" entry in bower.json
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v1.3.1...v1.3.2)
          +
          +## v1.3.1 - March 13th, 2015
          +
          +- [#52](https://github.com/kpdecker/jsdiff/pull/52) - Fix for #51 Wrong result of JsDiff.diffLines ([@felicienfrancois](https://api.github.com/users/felicienfrancois))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v1.3.0...v1.3.1)
          +
          +## v1.3.0 - March 2nd, 2015
          +
          +- [#47](https://github.com/kpdecker/jsdiff/pull/47) - Adding Diff Trimmed Lines ([@JamesGould123](https://api.github.com/users/JamesGould123))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v1.2.2...v1.3.0)
          +
          +## v1.2.2 - January 26th, 2015
          +
          +- [#45](https://github.com/kpdecker/jsdiff/pull/45) - Fix AMD module loading ([@pedrocarrico](https://api.github.com/users/pedrocarrico))
          +- [#43](https://github.com/kpdecker/jsdiff/pull/43) - added a bower file ([@nbrustein](https://api.github.com/users/nbrustein))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v1.2.1...v1.2.2)
          +
          +## v1.2.1 - December 26th, 2014
          +
          +- [#41](https://github.com/kpdecker/jsdiff/pull/41) - change condition of using node export system. ([@ironhee](https://api.github.com/users/ironhee))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v1.2.0...v1.2.1)
          +
          +## v1.2.0 - November 29th, 2014
          +
          +- [#37](https://github.com/kpdecker/jsdiff/pull/37) - Add support for sentences. ([@vmariano](https://api.github.com/users/vmariano))
          +- [#28](https://github.com/kpdecker/jsdiff/pull/28) - Implemented diffJson ([@papandreou](https://api.github.com/users/papandreou))
          +- [#27](https://github.com/kpdecker/jsdiff/issues/27) - Slow to execute over diffs with a large number of changes ([@termi](https://api.github.com/users/termi))
          +- Allow for optional async diffing - 19385b9
          +- Fix diffChars implementation - eaa44ed
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v1.1.0...v1.2.0)
          +
          +## v1.1.0 - November 25th, 2014
          +
          +- [#33](https://github.com/kpdecker/jsdiff/pull/33) - AMD and global exports ([@ovcharik](https://api.github.com/users/ovcharik))
          +- [#32](https://github.com/kpdecker/jsdiff/pull/32) - Add support for component ([@vmariano](https://api.github.com/users/vmariano))
          +- [#31](https://github.com/kpdecker/jsdiff/pull/31) - Don't rely on Array.prototype.map ([@papandreou](https://api.github.com/users/papandreou))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v1.0.8...v1.1.0)
          +
          +## v1.0.8 - December 22nd, 2013
          +
          +- [#24](https://github.com/kpdecker/jsdiff/pull/24) - Handle windows newlines on non windows machines. ([@benogle](https://api.github.com/users/benogle))
          +- [#23](https://github.com/kpdecker/jsdiff/pull/23) - Prettied up the API formatting a little, and added basic node and web examples ([@airportyh](https://api.github.com/users/airportyh))
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v1.0.7...v1.0.8)
          +
          +## v1.0.7 - September 11th, 2013
          +
          +- [#22](https://github.com/kpdecker/jsdiff/pull/22) - Added variant of WordDiff that doesn't ignore whitespace differences ([@papandreou](https://api.github.com/users/papandreou)
          +
          +- Add 0.10 to travis tests - 243a526
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v1.0.6...v1.0.7)
          +
          +## v1.0.6 - August 30th, 2013
          +
          +- [#19](https://github.com/kpdecker/jsdiff/pull/19) - Explicitly define contents of npm package ([@sindresorhus](https://api.github.com/users/sindresorhus)
          +
          +[Commits](https://github.com/kpdecker/jsdiff/compare/v1.0.5...v1.0.6)
          diff --git a/deps/npm/node_modules/libnpmdiff/node_modules/diff/runtime.js b/deps/npm/node_modules/libnpmdiff/node_modules/diff/runtime.js
          new file mode 100644
          index 00000000000000..82ea7e696aa01b
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/node_modules/diff/runtime.js
          @@ -0,0 +1,3 @@
          +require('@babel/register')({
          +  ignore: ['lib', 'node_modules']
          +});
          diff --git a/deps/npm/node_modules/libnpmdiff/package.json b/deps/npm/node_modules/libnpmdiff/package.json
          new file mode 100644
          index 00000000000000..fab4293e9374eb
          --- /dev/null
          +++ b/deps/npm/node_modules/libnpmdiff/package.json
          @@ -0,0 +1,64 @@
          +{
          +  "name": "libnpmdiff",
          +  "version": "2.0.3",
          +  "description": "The registry diff",
          +  "repository": "https://github.com/npm/libnpmdiff",
          +  "files": [
          +    "index.js",
          +    "lib"
          +  ],
          +  "engines": {
          +    "node": ">=10"
          +  },
          +  "keywords": [
          +    "npm",
          +    "npmcli",
          +    "libnpm",
          +    "cli",
          +    "diff"
          +  ],
          +  "author": "GitHub Inc.",
          +  "contributors": [
          +    {
          +      "name": "Ruy Adorno",
          +      "url": "https://ruyadorno.com",
          +      "twitter": "ruyadorno"
          +    }
          +  ],
          +  "license": "ISC",
          +  "scripts": {
          +    "eslint": "eslint",
          +    "lint": "npm run eslint -- index.js \"lib/**/*.js\" \"test/*.js\"",
          +    "lintfix": "npm run lint -- --fix",
          +    "test": "tap test/*.js",
          +    "posttest": "npm run lint",
          +    "snap": "tap test/*.js",
          +    "preversion": "npm test",
          +    "postversion": "npm publish",
          +    "prepublishOnly": "git push origin --follow-tags"
          +  },
          +  "tap": {
          +    "check-coverage": true
          +  },
          +  "standard": {
          +    "ignore": [
          +      "/tap-snapshots/"
          +    ]
          +  },
          +  "devDependencies": {
          +    "eslint": "^7.18.0",
          +    "eslint-plugin-import": "^2.22.1",
          +    "eslint-plugin-node": "^11.1.0",
          +    "eslint-plugin-promise": "^4.2.1",
          +    "eslint-plugin-standard": "^5.0.0",
          +    "tap": "^14.11.0"
          +  },
          +  "dependencies": {
          +    "@npmcli/disparity-colors": "^1.0.1",
          +    "binary-extensions": "^2.2.0",
          +    "diff": "^5.0.0",
          +    "minimatch": "^3.0.4",
          +    "pacote": "^11.2.3",
          +    "tar": "^6.1.0"
          +  }
          +}
          diff --git a/deps/npm/node_modules/minipass-fetch/lib/request.js b/deps/npm/node_modules/minipass-fetch/lib/request.js
          index 0eb571c95d4301..c5208a7fc1300a 100644
          --- a/deps/npm/node_modules/minipass-fetch/lib/request.js
          +++ b/deps/npm/node_modules/minipass-fetch/lib/request.js
          @@ -32,7 +32,9 @@ class Request extends Body {
                 : input && input.href ? Url.parse(input.href)
                 : Url.parse(`${input}`)
           
          -    if (!isRequest(input))
          +    if (isRequest(input))
          +      init = { ...input[INTERNALS], ...init }
          +    else if (!input || typeof input === 'string')
                 input = {}
           
               const method = (init.method || input.method || 'GET').toUpperCase()
          @@ -61,7 +63,6 @@ class Request extends Body {
               }
           
               const signal = 'signal' in init ? init.signal
          -      : isRequest(input) ? input.signal
                 : null
           
               if (signal !== null && signal !== undefined && !isAbortSignal(signal))
          diff --git a/deps/npm/node_modules/minipass-fetch/package.json b/deps/npm/node_modules/minipass-fetch/package.json
          index a9585c9516c182..df48f372a60796 100644
          --- a/deps/npm/node_modules/minipass-fetch/package.json
          +++ b/deps/npm/node_modules/minipass-fetch/package.json
          @@ -1,6 +1,6 @@
           {
             "name": "minipass-fetch",
          -  "version": "1.3.2",
          +  "version": "1.3.3",
             "description": "An implementation of window.fetch in Node.js using Minipass streams",
             "license": "MIT",
             "main": "lib/index.js",
          @@ -18,7 +18,7 @@
             "devDependencies": {
               "@ungap/url-search-params": "^0.1.2",
               "abort-controller": "^3.0.0",
          -    "abortcontroller-polyfill": "^1.3.0",
          +    "abortcontroller-polyfill": "~1.3.0",
               "form-data": "^2.5.1",
               "parted": "^0.1.1",
               "string-to-arraybuffer": "^1.0.2",
          diff --git a/deps/npm/node_modules/pacote/lib/fetcher.js b/deps/npm/node_modules/pacote/lib/fetcher.js
          index c4e5852daf8a87..ad3cacec89bf48 100644
          --- a/deps/npm/node_modules/pacote/lib/fetcher.js
          +++ b/deps/npm/node_modules/pacote/lib/fetcher.js
          @@ -103,7 +103,7 @@ class FetcherBase {
               this.npmBin = opts.npmBin || 'npm'
           
               // command to install deps for preparing
          -    this.npmInstallCmd = opts.npmInstallCmd || [ 'install' ]
          +    this.npmInstallCmd = opts.npmInstallCmd || [ 'install', '--force' ]
           
               // XXX fill more of this in based on what we know from this.opts
               // we explicitly DO NOT fill in --tag, though, since we are often
          diff --git a/deps/npm/node_modules/pacote/package.json b/deps/npm/node_modules/pacote/package.json
          index b55685a48b2411..959cb1ec488314 100644
          --- a/deps/npm/node_modules/pacote/package.json
          +++ b/deps/npm/node_modules/pacote/package.json
          @@ -1,6 +1,6 @@
           {
             "name": "pacote",
          -  "version": "11.2.3",
          +  "version": "11.2.4",
             "description": "JavaScript package downloader",
             "author": "Isaac Z. Schlueter  (https://izs.me)",
             "bin": {
          diff --git a/deps/npm/node_modules/ssri/CHANGELOG.md b/deps/npm/node_modules/ssri/CHANGELOG.md
          index 822e8506e7c634..3fea458e92ddff 100644
          --- a/deps/npm/node_modules/ssri/CHANGELOG.md
          +++ b/deps/npm/node_modules/ssri/CHANGELOG.md
          @@ -2,6 +2,13 @@
           
           All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
           
          +### [8.0.1](https://github.com/npm/ssri/compare/v8.0.0...v8.0.1) (2021-01-27)
          +
          +
          +### Bug Fixes
          +
          +* simplify regex for strict mode, add tests ([76e2233](https://github.com/npm/ssri/commit/76e223317d971f19e4db8191865bdad5edee40d2))
          +
           ## [8.0.0](https://github.com/npm/ssri/compare/v7.1.0...v8.0.0) (2020-02-18)
           
           
          diff --git a/deps/npm/node_modules/ssri/index.js b/deps/npm/node_modules/ssri/index.js
          index 950548cf28f2e6..2b309849c012a8 100644
          --- a/deps/npm/node_modules/ssri/index.js
          +++ b/deps/npm/node_modules/ssri/index.js
          @@ -9,7 +9,7 @@ const SPEC_ALGORITHMS = ['sha256', 'sha384', 'sha512']
           // rather than [a-z0-9].
           const BASE64_REGEX = /^[a-z0-9+/]+(?:=?=?)$/i
           const SRI_REGEX = /^([a-z0-9]+)-([^?]+)([?\S*]*)$/
          -const STRICT_SRI_REGEX = /^([a-z0-9]+)-([A-Za-z0-9+/=]{44,88})(\?[\x21-\x7E]*)*$/
          +const STRICT_SRI_REGEX = /^([a-z0-9]+)-([A-Za-z0-9+/=]{44,88})(\?[\x21-\x7E]*)?$/
           const VCHAR_REGEX = /^[\x21-\x7E]+$/
           
           const defaultOpts = {
          @@ -24,7 +24,8 @@ const defaultOpts = {
           
           const ssriOpts = (opts = {}) => ({ ...defaultOpts, ...opts })
           
          -const getOptString = options => !options || !options.length ? ''
          +const getOptString = options => !options || !options.length
          +  ? ''
             : `?${options.join('?')}`
           
           const _onEnd = Symbol('_onEnd')
          diff --git a/deps/npm/node_modules/ssri/package.json b/deps/npm/node_modules/ssri/package.json
          index aece8a6fbbd1d5..4af1a3c4c2e4fb 100644
          --- a/deps/npm/node_modules/ssri/package.json
          +++ b/deps/npm/node_modules/ssri/package.json
          @@ -1,6 +1,6 @@
           {
             "name": "ssri",
          -  "version": "8.0.0",
          +  "version": "8.0.1",
             "description": "Standard Subresource Integrity library -- parses, serializes, generates, and verifies integrity metadata according to the SRI spec.",
             "main": "index.js",
             "files": [],
          @@ -42,8 +42,8 @@
               "minipass": "^3.1.1"
             },
             "devDependencies": {
          -    "standard": "^14.3.1",
          -    "standard-version": "^7.1.0",
          +    "standard": "^16.0.3",
          +    "standard-version": "^9.1.0",
               "tap": "^14.10.6"
             },
             "engines": {
          diff --git a/deps/npm/package.json b/deps/npm/package.json
          index da6175dfe80b8e..57b7f48964b816 100644
          --- a/deps/npm/package.json
          +++ b/deps/npm/package.json
          @@ -1,5 +1,5 @@
           {
          -  "version": "7.4.3",
          +  "version": "7.5.1",
             "name": "npm",
             "description": "a package manager for JavaScript",
             "keywords": [
          @@ -42,14 +42,13 @@
               "./package.json": "./package.json"
             },
             "dependencies": {
          -    "@npmcli/arborist": "^2.0.6",
          +    "@npmcli/arborist": "^2.1.1",
               "@npmcli/ci-detect": "^1.2.0",
               "@npmcli/config": "^1.2.8",
               "@npmcli/run-script": "^1.8.1",
               "abbrev": "~1.1.1",
               "ansicolors": "~0.3.2",
               "ansistyles": "~0.1.3",
          -    "aproba": "^2.0.0",
               "archy": "~1.0.0",
               "byte-size": "^7.0.0",
               "cacache": "^15.0.5",
          @@ -60,12 +59,14 @@
               "columnify": "~1.5.4",
               "glob": "^7.1.4",
               "graceful-fs": "^4.2.3",
          -    "hosted-git-info": "^3.0.6",
          +    "hosted-git-info": "^3.0.8",
               "ini": "^2.0.0",
               "init-package-json": "^2.0.1",
               "is-cidr": "^4.0.2",
          +    "json-parse-even-better-errors": "^2.3.1",
               "leven": "^3.1.0",
               "libnpmaccess": "^4.0.1",
          +    "libnpmdiff": "^2.0.3",
               "libnpmfund": "^1.0.2",
               "libnpmhook": "^6.0.1",
               "libnpmorg": "^2.0.1",
          @@ -99,7 +100,7 @@
               "readdir-scoped-modules": "^1.1.0",
               "rimraf": "^3.0.2",
               "semver": "^7.3.4",
          -    "ssri": "^8.0.0",
          +    "ssri": "^8.0.1",
               "tar": "^6.1.0",
               "text-table": "~0.2.0",
               "tiny-relative-date": "^1.3.0",
          @@ -117,7 +118,6 @@
               "abbrev",
               "ansicolors",
               "ansistyles",
          -    "aproba",
               "archy",
               "byte-size",
               "cacache",
          @@ -135,6 +135,7 @@
               "json-parse-even-better-errors",
               "leven",
               "libnpmaccess",
          +    "libnpmdiff",
               "libnpmfund",
               "libnpmhook",
               "libnpmorg",
          @@ -186,7 +187,6 @@
               "eslint-plugin-promise": "^4.2.1",
               "eslint-plugin-standard": "^5.0.0",
               "jsdom": "^16.4.0",
          -    "json-parse-even-better-errors": "^2.3.1",
               "marked-man": "^0.7.0",
               "require-inject": "^1.4.4",
               "tap": "^14.11.0",
          diff --git a/deps/npm/tap-snapshots/test-lib-utils-cmd-list.js-TAP.test.js b/deps/npm/tap-snapshots/test-lib-utils-cmd-list.js-TAP.test.js
          index 68f0d8328a7852..1c91975c7a152b 100644
          --- a/deps/npm/tap-snapshots/test-lib-utils-cmd-list.js-TAP.test.js
          +++ b/deps/npm/tap-snapshots/test-lib-utils-cmd-list.js-TAP.test.js
          @@ -155,6 +155,7 @@ Object {
               "prefix",
               "bin",
               "whoami",
          +    "diff",
               "dist-tag",
               "ping",
               "test",
          diff --git a/deps/npm/tap-snapshots/test-lib-utils-config.js-TAP.test.js b/deps/npm/tap-snapshots/test-lib-utils-config.js-TAP.test.js
          index 1f525e71cab970..39927e600e1232 100644
          --- a/deps/npm/tap-snapshots/test-lib-utils-config.js-TAP.test.js
          +++ b/deps/npm/tap-snapshots/test-lib-utils-config.js-TAP.test.js
          @@ -37,6 +37,14 @@ Object {
               "depth": null,
               "description": true,
               "dev": false,
          +    "diff": Array [],
          +    "diff-dst-prefix": "",
          +    "diff-ignore-all-space": false,
          +    "diff-name-only": false,
          +    "diff-no-prefix": false,
          +    "diff-src-prefix": "",
          +    "diff-text": false,
          +    "diff-unified": null,
               "dry-run": false,
               "editor": "vim",
               "engine-strict": false,
          @@ -346,6 +354,20 @@ Object {
               ],
               "description": "{Boolean TYPE}",
               "dev": "{Boolean TYPE}",
          +    "diff": Array [
          +      "{String TYPE}",
          +      "{Array TYPE}",
          +    ],
          +    "diff-dst-prefix": "{String TYPE}",
          +    "diff-ignore-all-space": "{Boolean TYPE}",
          +    "diff-name-only": "{Boolean TYPE}",
          +    "diff-no-prefix": "{Boolean TYPE}",
          +    "diff-src-prefix": "{String TYPE}",
          +    "diff-text": "{Boolean TYPE}",
          +    "diff-unified": Array [
          +      null,
          +      "{Number TYPE}",
          +    ],
               "dry-run": "{Boolean TYPE}",
               "editor": "{String TYPE}",
               "engine-strict": "{Boolean TYPE}",
          @@ -566,6 +588,14 @@ Object {
               "depth": null,
               "description": true,
               "dev": false,
          +    "diff": Array [],
          +    "diff-dst-prefix": "",
          +    "diff-ignore-all-space": false,
          +    "diff-name-only": false,
          +    "diff-no-prefix": false,
          +    "diff-src-prefix": "",
          +    "diff-text": false,
          +    "diff-unified": null,
               "dry-run": false,
               "editor": "vim",
               "engine-strict": false,
          @@ -875,6 +905,20 @@ Object {
               ],
               "description": "{Boolean TYPE}",
               "dev": "{Boolean TYPE}",
          +    "diff": Array [
          +      "{String TYPE}",
          +      "{Array TYPE}",
          +    ],
          +    "diff-dst-prefix": "{String TYPE}",
          +    "diff-ignore-all-space": "{Boolean TYPE}",
          +    "diff-name-only": "{Boolean TYPE}",
          +    "diff-no-prefix": "{Boolean TYPE}",
          +    "diff-src-prefix": "{String TYPE}",
          +    "diff-text": "{Boolean TYPE}",
          +    "diff-unified": Array [
          +      null,
          +      "{Number TYPE}",
          +    ],
               "dry-run": "{Boolean TYPE}",
               "editor": "{String TYPE}",
               "engine-strict": "{Boolean TYPE}",
          diff --git a/deps/npm/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js b/deps/npm/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js
          index 93606fcd8a0601..47de89e9761484 100644
          --- a/deps/npm/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js
          +++ b/deps/npm/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js
          @@ -30,6 +30,14 @@ Object {
             "commitHooks": "commit-hooks",
             "defaultTag": "tag",
             "depth": "depth",
          +  "diff": undefined,
          +  "diffDstPrefix": undefined,
          +  "diffIgnoreAllSpace": undefined,
          +  "diffNameOnly": undefined,
          +  "diffNoPrefix": undefined,
          +  "diffSrcPrefix": undefined,
          +  "diffText": undefined,
          +  "diffUnified": undefined,
             "dmode": 511,
             "dryRun": "dry-run",
             "editor": "editor",
          diff --git a/deps/npm/tap-snapshots/test-lib-utils-npm-usage.js-TAP.test.js b/deps/npm/tap-snapshots/test-lib-utils-npm-usage.js-TAP.test.js
          new file mode 100644
          index 00000000000000..5fb74fd5efdb57
          --- /dev/null
          +++ b/deps/npm/tap-snapshots/test-lib-utils-npm-usage.js-TAP.test.js
          @@ -0,0 +1,495 @@
          +/* IMPORTANT
          + * This snapshot file is auto-generated, but designed for humans.
          + * It should be checked into source control and tracked carefully.
          + * Re-generate by setting TAP_SNAPSHOT=1 and running tests.
          + * Make sure to inspect the output below.  Do not ignore changes!
          + */
          +'use strict'
          +exports[`test/lib/utils/npm-usage.js TAP basic usage > must match snapshot 1`] = `
          +
          +Usage: npm 
          +
          +npm install        install all the dependencies in your project
          +npm install   add the  dependency to your project
          +npm test           run this project's tests
          +npm run       run the script named 
          +npm  -h   quick help on 
          +npm -l             display usage info for all commands
          +npm help     search for help on 
          +npm help npm       more involved overview
          +
          +All commands:
          +
          +    access, adduser, audit, bin, bugs, cache, ci, completion,
          +    config, dedupe, deprecate, diff, dist-tag, docs, doctor,
          +    edit, exec, explain, explore, find-dupes, fund, get, help,
          +    hook, init, install, install-ci-test, install-test, link,
          +    ll, login, logout, ls, org, outdated, owner, pack, ping,
          +    prefix, profile, prune, publish, rebuild, repo, restart,
          +    root, run-script, search, set, set-script, shrinkwrap, star,
          +    stars, start, stop, team, test, token, uninstall, unpublish,
          +    unstar, update, version, view, whoami
          +
          +Specify configs in the ini-formatted file:
          +    /some/config/file/.npmrc
          +or on the command line via: npm  --key=value
          +
          +More configuration info: npm help config
          +Configuration fields: npm help 7 config
          +
          +npm@{VERSION} {BASEDIR}
          +
          +`
          +
          +exports[`test/lib/utils/npm-usage.js TAP did you mean? > must match snapshot 1`] = `
          +
          +Usage: npm 
          +
          +npm install        install all the dependencies in your project
          +npm install   add the  dependency to your project
          +npm test           run this project's tests
          +npm run       run the script named 
          +npm  -h   quick help on 
          +npm -l             display usage info for all commands
          +npm help     search for help on 
          +npm help npm       more involved overview
          +
          +All commands:
          +
          +    access, adduser, audit, bin, bugs, cache, ci, completion,
          +    config, dedupe, deprecate, diff, dist-tag, docs, doctor,
          +    edit, exec, explain, explore, find-dupes, fund, get, help,
          +    hook, init, install, install-ci-test, install-test, link,
          +    ll, login, logout, ls, org, outdated, owner, pack, ping,
          +    prefix, profile, prune, publish, rebuild, repo, restart,
          +    root, run-script, search, set, set-script, shrinkwrap, star,
          +    stars, start, stop, team, test, token, uninstall, unpublish,
          +    unstar, update, version, view, whoami
          +
          +Specify configs in the ini-formatted file:
          +    /some/config/file/.npmrc
          +or on the command line via: npm  --key=value
          +
          +More configuration info: npm help config
          +Configuration fields: npm help 7 config
          +
          +npm@{VERSION} {BASEDIR}
          +
          +`
          +
          +exports[`test/lib/utils/npm-usage.js TAP did you mean? > must match snapshot 2`] = `
          +
          +Did you mean one of these?
          +    install
          +    uninstall
          +`
          +
          +exports[`test/lib/utils/npm-usage.js TAP set process.stdout.columns columns=0 > must match snapshot 1`] = `
          +
          +Usage: npm 
          +
          +npm install        install all the dependencies in your project
          +npm install   add the  dependency to your project
          +npm test           run this project's tests
          +npm run       run the script named 
          +npm  -h   quick help on 
          +npm -l             display usage info for all commands
          +npm help     search for help on 
          +npm help npm       more involved overview
          +
          +All commands:
          +
          +    access, adduser, audit, bin, bugs, cache, ci, completion,
          +    config, dedupe, deprecate, diff, dist-tag, docs, doctor,
          +    edit, exec, explain, explore, find-dupes, fund, get, help,
          +    hook, init, install, install-ci-test, install-test, link,
          +    ll, login, logout, ls, org, outdated, owner, pack, ping,
          +    prefix, profile, prune, publish, rebuild, repo, restart,
          +    root, run-script, search, set, set-script, shrinkwrap, star,
          +    stars, start, stop, team, test, token, uninstall, unpublish,
          +    unstar, update, version, view, whoami
          +
          +Specify configs in the ini-formatted file:
          +    /some/config/file/.npmrc
          +or on the command line via: npm  --key=value
          +
          +More configuration info: npm help config
          +Configuration fields: npm help 7 config
          +
          +npm@{VERSION} {BASEDIR}
          +
          +`
          +
          +exports[`test/lib/utils/npm-usage.js TAP set process.stdout.columns columns=90 > must match snapshot 1`] = `
          +
          +Usage: npm 
          +
          +npm install        install all the dependencies in your project
          +npm install   add the  dependency to your project
          +npm test           run this project's tests
          +npm run       run the script named 
          +npm  -h   quick help on 
          +npm -l             display usage info for all commands
          +npm help     search for help on 
          +npm help npm       more involved overview
          +
          +All commands:
          +
          +    access, adduser, audit, bin, bugs, cache, ci, completion,
          +    config, dedupe, deprecate, diff, dist-tag, docs, doctor,
          +    edit, exec, explain, explore, find-dupes, fund, get, help,
          +    hook, init, install, install-ci-test, install-test, link,
          +    ll, login, logout, ls, org, outdated, owner, pack, ping,
          +    prefix, profile, prune, publish, rebuild, repo, restart,
          +    root, run-script, search, set, set-script, shrinkwrap, star,
          +    stars, start, stop, team, test, token, uninstall, unpublish,
          +    unstar, update, version, view, whoami
          +
          +Specify configs in the ini-formatted file:
          +    /some/config/file/.npmrc
          +or on the command line via: npm  --key=value
          +
          +More configuration info: npm help config
          +Configuration fields: npm help 7 config
          +
          +npm@{VERSION} {BASEDIR}
          +
          +`
          +
          +exports[`test/lib/utils/npm-usage.js TAP with browser > must match snapshot 1`] = `
          +
          +Usage: npm 
          +
          +npm install        install all the dependencies in your project
          +npm install   add the  dependency to your project
          +npm test           run this project's tests
          +npm run       run the script named 
          +npm  -h   quick help on 
          +npm -l             display usage info for all commands
          +npm help     search for help on  (in a browser)
          +npm help npm       more involved overview (in a browser)
          +
          +All commands:
          +
          +    access, adduser, audit, bin, bugs, cache, ci, completion,
          +    config, dedupe, deprecate, diff, dist-tag, docs, doctor,
          +    edit, exec, explain, explore, find-dupes, fund, get, help,
          +    hook, init, install, install-ci-test, install-test, link,
          +    ll, login, logout, ls, org, outdated, owner, pack, ping,
          +    prefix, profile, prune, publish, rebuild, repo, restart,
          +    root, run-script, search, set, set-script, shrinkwrap, star,
          +    stars, start, stop, team, test, token, uninstall, unpublish,
          +    unstar, update, version, view, whoami
          +
          +Specify configs in the ini-formatted file:
          +    /some/config/file/.npmrc
          +or on the command line via: npm  --key=value
          +
          +More configuration info: npm help config
          +Configuration fields: npm help 7 config
          +
          +npm@{VERSION} {BASEDIR}
          +
          +`
          +
          +exports[`test/lib/utils/npm-usage.js TAP with long > must match snapshot 1`] = `
          +
          +Usage: npm 
          +
          +npm install        install all the dependencies in your project
          +npm install   add the  dependency to your project
          +npm test           run this project's tests
          +npm run       run the script named 
          +npm  -h   quick help on 
          +npm -l             display usage info for all commands
          +npm help     search for help on 
          +npm help npm       more involved overview
          +
          +All commands:
          +
          +    access          npm access public []
          +                    npm access restricted []
          +                    npm access grant   []
          +                    npm access revoke  []
          +                    npm access 2fa-required []
          +                    npm access 2fa-not-required []
          +                    npm access ls-packages [||]
          +                    npm access ls-collaborators [ []]
          +                    npm access edit []
          +
          +    adduser         npm adduser [--registry=url] [--scope=@orgname] [--always-auth]
          +
          +                    aliases: login, add-user
          +
          +    audit           npm audit [--json] [--production]
          +                    npm audit fix [--force|--package-lock-only|--dry-run|--production|--only=(dev|prod)]
          +
          +    bin             npm bin [-g]
          +
          +    bugs            npm bugs []
          +
          +                    alias: issues
          +
          +    cache           npm cache add 
          +                    npm cache add 
          +                    npm cache add 
          +                    npm cache add 
          +                    npm cache add @
          +                    npm cache clean
          +                    npm cache verify
          +
          +    ci              npm ci
          +
          +                    aliases: clean-install, ic, install-clean, isntall-clean
          +
          +    completion      source <(npm completion)
          +
          +    config          npm config set = [= ...]
          +                    npm config get [ [ ...]]
          +                    npm config delete  [ ...]
          +                    npm config list [--json]
          +                    npm config edit
          +                    npm set = [= ...]
          +                    npm get [ [ ...]]
          +
          +                    alias: c
          +
          +    dedupe          npm dedupe
          +
          +                    alias: ddp
          +
          +    deprecate       npm deprecate [@] 
          +
          +    diff            npm diff [...]
          +                    npm diff --diff= [...]
          +                    npm diff --diff= [--diff=] [...]
          +                    npm diff --diff= [--diff=] [...]
          +                    npm diff [--diff-ignore-all-space] [--diff-name-only] [...] [...]
          +
          +    dist-tag        npm dist-tag add @ []
          +                    npm dist-tag rm  
          +                    npm dist-tag ls []
          +
          +                    alias: dist-tags
          +
          +    docs            npm docs [ [ ...]]
          +
          +                    alias: home
          +
          +    doctor          npm doctor
          +
          +    edit            npm edit [/...]
          +
          +    exec            Run a command from a local or remote npm package.
          +
          +                    npm exec -- [@] [args...]
          +                    npm exec --package=[@] --  [args...]
          +                    npm exec -c ' [args...]'
          +                    npm exec --package=foo -c ' [args...]'
          +
          +                    npx [@] [args...]
          +                    npx -p [@]  [args...]
          +                    npx -c ' [args...]'
          +                    npx -p [@] -c ' [args...]'
          +                    Run without --call or positional args to open interactive subshell
          +
          +
          +                    alias: x
          +                    common options:
          +                    --package= (may be specified multiple times)
          +                    -p is a shorthand for --package only when using npx executable
          +                    -c  --call= (may not be mixed with positional arguments)
          +
          +    explain         npm explain 
          +
          +                    alias: why
          +
          +    explore         npm explore  [ -- ]
          +
          +    find-dupes      npm find-dupes
          +
          +    fund            npm fund
          +
          +                    common options: npm fund [--json] [--browser] [--unicode] [[<@scope>/] [--which=]
          +
          +    get             npm get [ ...] (See \`npm config\`)
          +
          +    help            npm help  []
          +
          +                    alias: hlep
          +
          +    hook            npm hook add    [--type=]
          +                    npm hook ls [pkg]
          +                    npm hook rm 
          +                    npm hook update   
          +
          +    init
          +                    npm init [--force|-f|--yes|-y|--scope]
          +                    npm init <@scope> (same as \`npx <@scope>/create\`)
          +                    npm init [<@scope>/] (same as \`npx [<@scope>/]create-\`)
          +
          +                    aliases: create, innit
          +
          +    install         npm install (with no args, in package dir)
          +                    npm install [<@scope>/]
          +                    npm install [<@scope>/]@
          +                    npm install [<@scope>/]@
          +                    npm install [<@scope>/]@
          +                    npm install @npm:
          +                    npm install 
          +                    npm install 
          +                    npm install 
          +                    npm install 
          +                    npm install /
          +
          +                    aliases: i, in, ins, inst, insta, instal, isnt, isnta, isntal, add
          +                    common options: [--save-prod|--save-dev|--save-optional|--save-peer] [--save-exact] [--no-save]
          +
          +    install-ci-test npm install-ci-test [args]
          +                    Same args as \`npm ci\`
          +
          +                    alias: cit
          +
          +    install-test    npm install-test [args]
          +                    Same args as \`npm install\`
          +
          +                    alias: it
          +
          +    link            npm link (in package dir)
          +                    npm link [<@scope>/][@]
          +
          +                    alias: ln
          +
          +    ll              npm ls [[<@scope>/] ...]
          +
          +                    alias: list
          +
          +    login           npm adduser [--registry=url] [--scope=@orgname] [--always-auth]
          +
          +                    aliases: login, add-user
          +
          +    logout          npm logout [--registry=] [--scope=<@scope>]
          +
          +    ls              npm ls [[<@scope>/] ...]
          +
          +                    alias: list
          +
          +    org             npm org set orgname username [developer | admin | owner]
          +                    npm org rm orgname username
          +                    npm org ls orgname []
          +
          +    outdated        npm outdated [[<@scope>/] ...]
          +
          +    owner           npm owner add  [<@scope>/]
          +                    npm owner rm  [<@scope>/]
          +                    npm owner ls [<@scope>/]
          +
          +                    alias: author
          +
          +    pack            npm pack [[<@scope>/]...] [--dry-run]
          +
          +    ping            npm ping
          +                    ping registry
          +
          +    prefix          npm prefix [-g]
          +
          +    profile         npm profile disable-2fa
          +
          +
          +                    common options: npm profile get []
          +
          +
          +    prune           npm prune [[<@scope>/]...] [--production]
          +
          +    publish         npm publish [] [--tag ] [--access ] [--dry-run]
          +
          +                    Publishes '.' if no argument supplied
          +                    Sets tag \`latest\` if no --tag specified
          +
          +    rebuild         npm rebuild [[<@scope>/][@] ...]
          +
          +                    alias: rb
          +
          +    repo            npm repo [ [ ...]]
          +
          +    restart         npm restart [-- ]
          +
          +    root            npm root [-g]
          +
          +    run-script      npm run-script  [-- ]
          +
          +                    aliases: run, rum, urn
          +
          +    search          npm search [-l|--long] [--json] [--parseable] [--no-description] [search terms ...]
          +
          +                    aliases: s, se, find
          +
          +    set             npm set = [= ...] (See \`npm config\`)
          +
          +    set-script      npm set-script [