| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5738107 commit 43c25e2
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,56 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const { | ||
| 4 | + Symbol, | ||
| 5 | + } = primordials; | ||
| 6 | + | ||
| 7 | + const { | ||
| 8 | + customInspectSymbol: kInspect, | ||
| 9 | + } = require('internal/util'); | ||
| 10 | + | ||
| 11 | + const { | ||
| 12 | + kHandle: kKeyObjectHandle, | ||
| 13 | + kKeyObject: kKeyObjectInner, | ||
| 14 | + } = require('internal/crypto/util'); | ||
| 15 | + | ||
| 16 | + // Symbols used to hide various private properties and methods from the | ||
| 17 | + // public API. | ||
| 18 | + | ||
| 19 | + const kBlocked = Symbol('kBlocked'); | ||
| 20 | + const kDatagram = Symbol('kDatagram'); | ||
| 21 | + const kDatagramStatus = Symbol('kDatagramStatus'); | ||
| 22 | + const kError = Symbol('kError'); | ||
| 23 | + const kFinishClose = Symbol('kFinishClose'); | ||
| 24 | + const kHandshake = Symbol('kHandshake'); | ||
| 25 | + const kHeaders = Symbol('kHeaders'); | ||
| 26 | + const kOwner = Symbol('kOwner'); | ||
| 27 | + const kNewSession = Symbol('kNewSession'); | ||
| 28 | + const kNewStream = Symbol('kNewStream'); | ||
| 29 | + const kPathValidation = Symbol('kPathValidation'); | ||
| 30 | + const kReset = Symbol('kReset'); | ||
| 31 | + const kSessionTicket = Symbol('kSessionTicket'); | ||
| 32 | + const kTrailers = Symbol('kTrailers'); | ||
| 33 | + const kVersionNegotiation = Symbol('kVersionNegotiation'); | ||
| 34 | + const kPrivateConstructor = Symbol('kPrivateConstructor'); | ||
| 35 | + | ||
| 36 | + module.exports = { | ||
| 37 | + kBlocked, | ||
| 38 | + kDatagram, | ||
| 39 | + kDatagramStatus, | ||
| 40 | + kError, | ||
| 41 | + kFinishClose, | ||
| 42 | + kHandshake, | ||
| 43 | + kHeaders, | ||
| 44 | + kOwner, | ||
| 45 | + kNewSession, | ||
| 46 | + kNewStream, | ||
| 47 | + kPathValidation, | ||
| 48 | + kReset, | ||
| 49 | + kSessionTicket, | ||
| 50 | + kTrailers, | ||
| 51 | + kVersionNegotiation, | ||
| 52 | + kInspect, | ||
| 53 | + kKeyObjectHandle, | ||
| 54 | + kKeyObjectInner, | ||
| 55 | + kPrivateConstructor, | ||
| 56 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -133,7 +133,8 @@ BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const { | |||
| 133 | 133 | "internal/streams/lazy_transform", | |
| 134 | 134 | #endif // !HAVE_OPENSSL | |
| 135 | 135 | #if !NODE_OPENSSL_HAS_QUIC | |
| 136 | - "internal/quic/quic", | ||
| 136 | + "internal/quic/quic", "internal/quic/symbols", "internal/quic/stats", | ||
| 137 | + "internal/quic/state", | ||
| 137 | 138 | #endif // !NODE_OPENSSL_HAS_QUIC | |
| 138 | 139 | "sqlite", // Experimental. | |
| 139 | 140 | "sys", // Deprecated. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,11 +20,11 @@ describe('quic internal endpoint listen defaults', { skip: !hasQuic }, async () | |||
| 20 | 20 | } = require('net'); | |
| 21 | 21 | ||
| 22 | 22 | const { | |
| 23 | - Endpoint, | ||
| 23 | + QuicEndpoint, | ||
| 24 | 24 | } = require('internal/quic/quic'); | |
| 25 | 25 | ||
| 26 | 26 | it('are reasonable and work as expected', async () => { | |
| 27 | - const endpoint = new Endpoint({ | ||
| 27 | + const endpoint = new QuicEndpoint({ | ||
| 28 | 28 | onsession() {}, | |
| 29 | 29 | session: {}, | |
| 30 | 30 | stream: {}, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ describe('quic internal endpoint options', { skip: !hasQuic }, async () => { | |||
| 15 | 15 | } = require('node:assert'); | |
| 16 | 16 | ||
| 17 | 17 | const { | |
| 18 | - Endpoint, | ||
| 18 | + QuicEndpoint, | ||
| 19 | 19 | } = require('internal/quic/quic'); | |
| 20 | 20 | ||
| 21 | 21 | const { | |
@@ -30,17 +30,17 @@ describe('quic internal endpoint options', { skip: !hasQuic }, async () => { | |||
| 30 | 30 | ||
| 31 | 31 | it('invalid options', async () => { | |
| 32 | 32 | ['a', null, false, NaN].forEach((i) => { | |
| 33 | - throws(() => new Endpoint(callbackConfig, i), { | ||
| 33 | + throws(() => new QuicEndpoint(callbackConfig, i), { | ||
| 34 | 34 | code: 'ERR_INVALID_ARG_TYPE', | |
| 35 | 35 | }); | |
| 36 | 36 | }); | |
| 37 | 37 | }); | |
| 38 | 38 | ||
| 39 | 39 | it('valid options', async () => { | |
| 40 | 40 | // Just Works... using all defaults | |
| 41 | - new Endpoint(callbackConfig, {}); | ||
| 42 | - new Endpoint(callbackConfig); | ||
| 43 | - new Endpoint(callbackConfig, undefined); | ||
| 41 | + new QuicEndpoint(callbackConfig, {}); | ||
| 42 | + new QuicEndpoint(callbackConfig); | ||
| 43 | + new QuicEndpoint(callbackConfig, undefined); | ||
| 44 | 44 | }); | |
| 45 | 45 | ||
| 46 | 46 | it('various cases', async () => { | |
@@ -126,12 +126,12 @@ describe('quic internal endpoint options', { skip: !hasQuic }, async () => { | |||
| 126 | 126 | { | |
| 127 | 127 | key: 'cc', | |
| 128 | 128 | valid: [ | |
| 129 | - Endpoint.CC_ALGO_RENO, | ||
| 130 | - Endpoint.CC_ALGO_CUBIC, | ||
| 131 | - Endpoint.CC_ALGO_BBR, | ||
| 132 | - Endpoint.CC_ALGO_RENO_STR, | ||
| 133 | - Endpoint.CC_ALGO_CUBIC_STR, | ||
| 134 | - Endpoint.CC_ALGO_BBR_STR, | ||
| 129 | + QuicEndpoint.CC_ALGO_RENO, | ||
| 130 | + QuicEndpoint.CC_ALGO_CUBIC, | ||
| 131 | + QuicEndpoint.CC_ALGO_BBR, | ||
| 132 | + QuicEndpoint.CC_ALGO_RENO_STR, | ||
| 133 | + QuicEndpoint.CC_ALGO_CUBIC_STR, | ||
| 134 | + QuicEndpoint.CC_ALGO_BBR_STR, | ||
| 135 | 135 | ], | |
| 136 | 136 | invalid: [-1, 4, 1n, 'a', null, false, true, {}, [], () => {}], | |
| 137 | 137 | }, | |
@@ -190,39 +190,39 @@ describe('quic internal endpoint options', { skip: !hasQuic }, async () => { | |||
| 190 | 190 | for (const value of valid) { | |
| 191 | 191 | const options = {}; | |
| 192 | 192 | options[key] = value; | |
| 193 | - new Endpoint(callbackConfig, options); | ||
| 193 | + new QuicEndpoint(callbackConfig, options); | ||
| 194 | 194 | } | |
| 195 | 195 | ||
| 196 | 196 | for (const value of invalid) { | |
| 197 | 197 | const options = {}; | |
| 198 | 198 | options[key] = value; | |
| 199 | - throws(() => new Endpoint(callbackConfig, options), { | ||
| 199 | + throws(() => new QuicEndpoint(callbackConfig, options), { | ||
| 200 | 200 | code: 'ERR_INVALID_ARG_VALUE', | |
| 201 | 201 | }); | |
| 202 | 202 | } | |
| 203 | 203 | } | |
| 204 | 204 | }); | |
| 205 | 205 | ||
| 206 | 206 | it('endpoint can be ref/unrefed without error', async () => { | |
| 207 | - const endpoint = new Endpoint(callbackConfig, {}); | ||
| 207 | + const endpoint = new QuicEndpoint(callbackConfig, {}); | ||
| 208 | 208 | endpoint.unref(); | |
| 209 | 209 | endpoint.ref(); | |
| 210 | 210 | endpoint.close(); | |
| 211 | 211 | await endpoint.closed; | |
| 212 | 212 | }); | |
| 213 | 213 | ||
| 214 | 214 | it('endpoint can be inspected', async () => { | |
| 215 | - const endpoint = new Endpoint(callbackConfig, {}); | ||
| 215 | + const endpoint = new QuicEndpoint(callbackConfig, {}); | ||
| 216 | 216 | strictEqual(typeof inspect(endpoint), 'string'); | |
| 217 | 217 | endpoint.close(); | |
| 218 | 218 | await endpoint.closed; | |
| 219 | 219 | }); | |
| 220 | 220 | ||
| 221 | 221 | it('endpoint with object address', () => { | |
| 222 | - new Endpoint(callbackConfig, { | ||
| 222 | + new QuicEndpoint(callbackConfig, { | ||
| 223 | 223 | address: { host: '127.0.0.1:0' }, | |
| 224 | 224 | }); | |
| 225 | - throws(() => new Endpoint(callbackConfig, { address: '127.0.0.1:0' }), { | ||
| 225 | + throws(() => new QuicEndpoint(callbackConfig, { address: '127.0.0.1:0' }), { | ||
| 226 | 226 | code: 'ERR_INVALID_ARG_TYPE', | |
| 227 | 227 | }); | |
| 228 | 228 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,14 +10,18 @@ const { | |||
| 10 | 10 | ||
| 11 | 11 | describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => { | |
| 12 | 12 | const { | |
| 13 | - Endpoint, | ||
| 13 | + QuicEndpoint, | ||
| 14 | 14 | QuicStreamState, | |
| 15 | 15 | QuicStreamStats, | |
| 16 | - SessionState, | ||
| 17 | - SessionStats, | ||
| 18 | - kFinishClose, | ||
| 16 | + QuicSessionState, | ||
| 17 | + QuicSessionStats, | ||
| 19 | 18 | } = require('internal/quic/quic'); | |
| 20 | 19 | ||
| 20 | + const { | ||
| 21 | + kFinishClose, | ||
| 22 | + kPrivateConstructor, | ||
| 23 | + } = require('internal/quic/symbols'); | ||
| 24 | + | ||
| 21 | 25 | const { | |
| 22 | 26 | inspect, | |
| 23 | 27 | } = require('util'); | |
@@ -29,7 +33,7 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => { | |||
| 29 | 33 | } = require('node:assert'); | |
| 30 | 34 | ||
| 31 | 35 | it('endpoint state', () => { | |
| 32 | - const endpoint = new Endpoint({ | ||
| 36 | + const endpoint = new QuicEndpoint({ | ||
| 33 | 37 | onsession() {}, | |
| 34 | 38 | session: {}, | |
| 35 | 39 | stream: {}, | |
@@ -62,7 +66,7 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => { | |||
| 62 | 66 | }); | |
| 63 | 67 | ||
| 64 | 68 | it('state is not readable after close', () => { | |
| 65 | - const endpoint = new Endpoint({ | ||
| 69 | + const endpoint = new QuicEndpoint({ | ||
| 66 | 70 | onsession() {}, | |
| 67 | 71 | session: {}, | |
| 68 | 72 | stream: {}, | |
@@ -74,24 +78,25 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => { | |||
| 74 | 78 | }); | |
| 75 | 79 | ||
| 76 | 80 | it('state constructor argument is ArrayBuffer', () => { | |
| 77 | - const endpoint = new Endpoint({ | ||
| 81 | + const endpoint = new QuicEndpoint({ | ||
| 78 | 82 | onsession() {}, | |
| 79 | 83 | session: {}, | |
| 80 | 84 | stream: {}, | |
| 81 | 85 | }, {}); | |
| 82 | 86 | const Cons = endpoint.state.constructor; | |
| 83 | - throws(() => new Cons(1), { | ||
| 87 | + throws(() => new Cons(kPrivateConstructor, 1), { | ||
| 84 | 88 | code: 'ERR_INVALID_ARG_TYPE' | |
| 85 | 89 | }); | |
| 86 | 90 | }); | |
| 87 | 91 | ||
| 88 | 92 | it('endpoint stats', () => { | |
| 89 | - const endpoint = new Endpoint({ | ||
| 93 | + const endpoint = new QuicEndpoint({ | ||
| 90 | 94 | onsession() {}, | |
| 91 | 95 | session: {}, | |
| 92 | 96 | stream: {}, | |
| 93 | 97 | }); | |
| 94 | 98 | ||
| 99 | + strictEqual(typeof endpoint.stats.isConnected, 'boolean'); | ||
| 95 | 100 | strictEqual(typeof endpoint.stats.createdAt, 'bigint'); | |
| 96 | 101 | strictEqual(typeof endpoint.stats.destroyedAt, 'bigint'); | |
| 97 | 102 | strictEqual(typeof endpoint.stats.bytesReceived, 'bigint'); | |
@@ -107,6 +112,7 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => { | |||
| 107 | 112 | strictEqual(typeof endpoint.stats.immediateCloseCount, 'bigint'); | |
| 108 | 113 | ||
| 109 | 114 | deepStrictEqual(Object.keys(endpoint.stats.toJSON()), [ | |
| 115 | + 'connected', | ||
| 110 | 116 | 'createdAt', | |
| 111 | 117 | 'destroyedAt', | |
| 112 | 118 | 'bytesReceived', | |
@@ -128,25 +134,26 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => { | |||
| 128 | 134 | }); | |
| 129 | 135 | ||
| 130 | 136 | it('stats are still readble after close', () => { | |
| 131 | - const endpoint = new Endpoint({ | ||
| 137 | + const endpoint = new QuicEndpoint({ | ||
| 132 | 138 | onsession() {}, | |
| 133 | 139 | session: {}, | |
| 134 | 140 | stream: {}, | |
| 135 | 141 | }, {}); | |
| 136 | 142 | strictEqual(typeof endpoint.stats.toJSON(), 'object'); | |
| 137 | 143 | endpoint.stats[kFinishClose](); | |
| 144 | + strictEqual(endpoint.stats.isConnected, false); | ||
| 138 | 145 | strictEqual(typeof endpoint.stats.destroyedAt, 'bigint'); | |
| 139 | 146 | strictEqual(typeof endpoint.stats.toJSON(), 'object'); | |
| 140 | 147 | }); | |
| 141 | 148 | ||
| 142 | 149 | it('stats constructor argument is ArrayBuffer', () => { | |
| 143 | - const endpoint = new Endpoint({ | ||
| 150 | + const endpoint = new QuicEndpoint({ | ||
| 144 | 151 | onsession() {}, | |
| 145 | 152 | session: {}, | |
| 146 | 153 | stream: {}, | |
| 147 | 154 | }, {}); | |
| 148 | 155 | const Cons = endpoint.stats.constructor; | |
| 149 | - throws(() => new Cons(1), { | ||
| 156 | + throws(() => new Cons(kPrivateConstructor, 1), { | ||
| 150 | 157 | code: 'ERR_INVALID_ARG_TYPE', | |
| 151 | 158 | }); | |
| 152 | 159 | }); | |
@@ -156,8 +163,8 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => { | |||
| 156 | 163 | // temporarily while the rest of the functionality is being | |
| 157 | 164 | // implemented. | |
| 158 | 165 | it('stream and session states', () => { | |
| 159 | - const streamState = new QuicStreamState(new ArrayBuffer(1024)); | ||
| 160 | - const sessionState = new SessionState(new ArrayBuffer(1024)); | ||
| 166 | + const streamState = new QuicStreamState(kPrivateConstructor, new ArrayBuffer(1024)); | ||
| 167 | + const sessionState = new QuicSessionState(kPrivateConstructor, new ArrayBuffer(1024)); | ||
| 161 | 168 | ||
| 162 | 169 | strictEqual(streamState.finSent, false); | |
| 163 | 170 | strictEqual(streamState.finReceived, false); | |
@@ -195,8 +202,8 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => { | |||
| 195 | 202 | }); | |
| 196 | 203 | ||
| 197 | 204 | it('stream and session stats', () => { | |
| 198 | - const streamStats = new QuicStreamStats(new ArrayBuffer(1024)); | ||
| 199 | - const sessionStats = new SessionStats(new ArrayBuffer(1024)); | ||
| 205 | + const streamStats = new QuicStreamStats(kPrivateConstructor, new ArrayBuffer(1024)); | ||
| 206 | + const sessionStats = new QuicSessionStats(kPrivateConstructor, new ArrayBuffer(1024)); | ||
| 200 | 207 | strictEqual(streamStats.createdAt, undefined); | |
| 201 | 208 | strictEqual(streamStats.receivedAt, undefined); | |
| 202 | 209 | strictEqual(streamStats.ackedAt, undefined); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments