@@ -140,7 +140,7 @@ const {
140
140
141
141
const {
142
142
Buffer,
143
- } = require ( 'node: buffer' ) ;
143
+ } = require ( 'buffer' ) ;
144
144
145
145
const {
146
146
codes : {
@@ -194,6 +194,10 @@ const {
194
194
validateObject,
195
195
} = require ( 'internal/validators' ) ;
196
196
197
+ const {
198
+ InternalX509Certificate,
199
+ } = require ( 'internal/crypto/x509' ) ;
200
+
197
201
const kOwner = Symbol ( 'kOwner' ) ;
198
202
const kHandle = Symbol ( 'kHandle' ) ;
199
203
const kFinishClose = Symbol ( 'kFinishClose' ) ;
@@ -209,6 +213,8 @@ const kNewStream = Symbol('kNewStream');
209
213
const kRemoteAddress = Symbol ( 'kRemoteAddress' ) ;
210
214
const kIsPendingClose = Symbol ( 'kIsPendingClose' ) ;
211
215
const kPendingClose = Symbol ( 'kPendingClose' ) ;
216
+ const kCertificate = Symbol ( 'kCertificate' ) ;
217
+ const kPeerCertificate = Symbol ( 'kPeerCertificate' ) ;
212
218
213
219
/**
214
220
* @typedef {import('../socketaddress.js').SocketAddress } SocketAddress
@@ -1178,12 +1184,23 @@ class Stream extends EventTarget {
1178
1184
1179
1185
/** @type {bigint } */
1180
1186
get id ( ) { return this [ kState ] . id ; }
1187
+
1188
+ /** @type {boolean } */
1189
+ get destroyed ( ) { return this [ kHandle ] === undefined ; }
1190
+
1191
+ destroy ( error ) {
1192
+ // TODO(@jasnell): Implement this.
1193
+ // ordinarily the stream would close naturally when the streams
1194
+ // are closed. Calling destory() forcefully closes the stream
1195
+ // immediately.
1196
+ }
1181
1197
}
1182
1198
ObjectDefineProperties ( Stream . prototype , {
1199
+ destroyed : { __proto__ : null , enumerable : true } ,
1200
+ id : { __proto__ : null , enumerable : true } ,
1183
1201
stats : { __proto__ : null , enumerable : true } ,
1184
1202
state : { __proto__ : null , enumerable : true } ,
1185
1203
session : { __proto__ : null , enumerable : true } ,
1186
- id : { __proto__ : null , enumerable : true } ,
1187
1204
} ) ;
1188
1205
1189
1206
class BidirectionalStream extends Stream {
@@ -1197,6 +1214,22 @@ class BidirectionalStream extends Stream {
1197
1214
/** @type {WritableStream } */
1198
1215
get writable ( ) { return this [ kWritable ] ; }
1199
1216
1217
+ get priority ( ) {
1218
+ if ( this . destroyed ) return 'default' ;
1219
+ const priority = this [ kHandle ] . getPriority ( ) ;
1220
+ if ( priority === 0 ) return 'high' ;
1221
+ if ( priority === 7 ) return 'low' ;
1222
+ return 'default' ;
1223
+ }
1224
+
1225
+ set priority ( val ) {
1226
+ if ( this . destroyed ) return ;
1227
+ let priority = 3 ;
1228
+ if ( val === 'high' ) priority = 0 ;
1229
+ else if ( val === 'low' ) priority = 7 ;
1230
+ this [ kHandle ] . setPriority ( priority , 1 ) ;
1231
+ }
1232
+
1200
1233
[ kInspect ] ( depth , options ) {
1201
1234
if ( depth < 0 )
1202
1235
return this ;
@@ -1207,15 +1240,18 @@ class BidirectionalStream extends Stream {
1207
1240
} ;
1208
1241
1209
1242
return `BidirectionalStream ${ inspect ( {
1210
- stats : this . stats ,
1211
- state : this . state ,
1212
- session : this . session ,
1243
+ destoyed : this . destroyed ,
1244
+ priority : this . priority ,
1213
1245
readable : this . readable ,
1246
+ session : this . session ,
1247
+ state : this . state ,
1248
+ stats : this . stats ,
1214
1249
writable : this . writable ,
1215
1250
} , opts ) } `;
1216
1251
}
1217
1252
}
1218
1253
ObjectDefineProperties ( BidirectionalStream . prototype , {
1254
+ priority : { __proto__ : null , enumerable : true } ,
1219
1255
readable : { __proto__ : null , enumerable : true } ,
1220
1256
writable : { __proto__ : null , enumerable : true } ,
1221
1257
} ) ;
@@ -1238,10 +1274,12 @@ class UnidirectionalInboundStream extends Stream {
1238
1274
} ;
1239
1275
1240
1276
return `UnidirectionalInboundStream ${ inspect ( {
1241
- stats : this . stats ,
1242
- state : this . state ,
1243
- session : this . session ,
1277
+ destroed : this . destroyed ,
1278
+ id : this . id ,
1244
1279
readable : this . readable ,
1280
+ session : this . session ,
1281
+ state : this . state ,
1282
+ stats : this . stats ,
1245
1283
} , opts ) } `;
1246
1284
}
1247
1285
}
@@ -1257,6 +1295,22 @@ class UnidirectionalOutboundStream extends Stream {
1257
1295
/** @type {WritableStream } */
1258
1296
get writable ( ) { return this [ kWritable ] ; }
1259
1297
1298
+ get priority ( ) {
1299
+ if ( this . destroyed ) return 'default' ;
1300
+ const priority = this [ kHandle ] . getPriority ( ) ;
1301
+ if ( priority === 0 ) return 'high' ;
1302
+ if ( priority === 7 ) return 'low' ;
1303
+ return 'default' ;
1304
+ }
1305
+
1306
+ set priority ( val ) {
1307
+ if ( this . destroyed ) return ;
1308
+ let priority = 3 ;
1309
+ if ( val === 'high' ) priority = 0 ;
1310
+ else if ( val === 'low' ) priority = 7 ;
1311
+ this [ kHandle ] . setPriority ( priority , 1 ) ;
1312
+ }
1313
+
1260
1314
[ kInspect ] ( depth , options ) {
1261
1315
if ( depth < 0 )
1262
1316
return this ;
@@ -1267,14 +1321,18 @@ class UnidirectionalOutboundStream extends Stream {
1267
1321
} ;
1268
1322
1269
1323
return `UnidirectionalOutboundStream ${ inspect ( {
1270
- stats : this . stats ,
1271
- state : this . state ,
1324
+ destroyed : this . destroyed ,
1325
+ id : this . id ,
1326
+ priority : this . priority ,
1272
1327
session : this . session ,
1328
+ state : this . state ,
1329
+ stats : this . stats ,
1273
1330
writable : this . writable ,
1274
1331
} , opts ) } `;
1275
1332
}
1276
1333
}
1277
1334
ObjectDefineProperties ( UnidirectionalOutboundStream . prototype , {
1335
+ priority : { __proto__ : null , enumerable : true } ,
1278
1336
writable : { __proto__ : null , enumerable : true } ,
1279
1337
} ) ;
1280
1338
@@ -1722,7 +1780,13 @@ class SessionState {
1722
1780
[ kFinishClose ] ( ) {
1723
1781
// Snapshot the state into a new DataView since the underlying
1724
1782
// buffer will be destroyed.
1725
- this [ kHandle ] = new DataView ( this [ kHandle ] ) ;
1783
+ let u8 = new Uint8Array ( this [ kHandle ] . buffer ,
1784
+ this [ kHandle ] . byteOffset ,
1785
+ this [ kHandle ] . byteLength ) ;
1786
+ u8 = new Uint8Array ( u8 ) ;
1787
+ this [ kHandle ] = new DataView ( u8 . buffer ,
1788
+ u8 . byteOffset ,
1789
+ u8 . byteLength ) ;
1726
1790
}
1727
1791
}
1728
1792
ObjectDefineProperties ( SessionState . prototype , {
@@ -1787,6 +1851,33 @@ class Session extends EventTarget {
1787
1851
} ;
1788
1852
}
1789
1853
1854
+ get certificate ( ) {
1855
+ if ( this . #isClosedOrClosing) return undefined ;
1856
+ if ( this [ kCertificate ] === undefined ) {
1857
+ const cert = this [ kHandle ] . getPeerCertificate ( ) ;
1858
+ if ( cert !== undefined ) {
1859
+ this [ kCertificate ] = new InternalX509Certificate ( cert ) ;
1860
+ }
1861
+ }
1862
+ return this [ kCertificate ] ;
1863
+ }
1864
+
1865
+ get peerCertificate ( ) {
1866
+ if ( this . #isClosedOrClosing) return undefined ;
1867
+ if ( this [ kPeerCertificate ] === undefined ) {
1868
+ const cert = this [ kHandle ] . getPeerCertificate ( ) ;
1869
+ if ( cert !== undefined ) {
1870
+ this [ kPeerCertificate ] = new InternalX509Certificate ( cert ) ;
1871
+ }
1872
+ }
1873
+ return this [ kPeerCertificate ] ;
1874
+ }
1875
+
1876
+ get ephemeralKeyInfo ( ) {
1877
+ if ( this . #isClosedOrClosing) return undefined ;
1878
+ return this [ kHandle ] . getEphemeralKeyInfo ( ) ;
1879
+ }
1880
+
1790
1881
/**
1791
1882
* @returns {BidirectionalStream }
1792
1883
*/
@@ -1953,11 +2044,14 @@ class Session extends EventTarget {
1953
2044
} ;
1954
2045
1955
2046
return `Session ${ inspect ( {
2047
+ certificate : this . certificate ,
1956
2048
closed : this [ kPendingClose ] . promise ,
1957
2049
closing : this [ kIsPendingClose ] ,
1958
2050
destroyed : this . destroyed ,
1959
2051
endpoint : this . endpoint ,
2052
+ ephemeralKeyInfo : this . ephemeralKeyInfo ,
1960
2053
path : this . path ,
2054
+ peerCertificate : this . peerCertificate ,
1961
2055
state : this . state ,
1962
2056
stats : this . stats ,
1963
2057
streams : this [ kStreams ] ,
@@ -1969,11 +2063,13 @@ class Session extends EventTarget {
1969
2063
}
1970
2064
}
1971
2065
ObjectDefineProperties ( Session . prototype , {
2066
+ certificate : { __proto__ : null , enumerable : true } ,
1972
2067
closed : { __proto__ : null , enumerable : true } ,
1973
2068
destroyed : { __proto__ : null , enumerable : true } ,
1974
2069
endpoint : { __proto__ : null , enumerable : true } ,
1975
- localAddress : { __proto__ : null , enumerable : true } ,
1976
- remoteAddress : { __proto__ : null , enumerable : true } ,
2070
+ ephemeralKeyInfo : { __proto__ : null , enumerable : true } ,
2071
+ path : { __proto__ : null , enumerable : true } ,
2072
+ peerCertificate : { __proto__ : null , enumerable : true } ,
1977
2073
state : { __proto__ : null , enumerable : true } ,
1978
2074
stats : { __proto__ : null , enumerable : true } ,
1979
2075
} ) ;
@@ -1990,6 +2086,8 @@ function createSession(handle, endpoint) {
1990
2086
instance [ kEndpoint ] = endpoint ;
1991
2087
instance [ kStreams ] = [ ] ;
1992
2088
instance [ kRemoteAddress ] = undefined ;
2089
+ instance [ kCertificate ] = undefined ;
2090
+ instance [ kPeerCertificate ] = undefined ;
1993
2091
instance [ kIsPendingClose ] = false ;
1994
2092
instance [ kPendingClose ] = Promise . withResolvers ( ) ; // eslint-disable-line node-core/prefer-primordials
1995
2093
handle [ kOwner ] = instance ;
@@ -2215,7 +2313,13 @@ class EndpointState {
2215
2313
[ kFinishClose ] ( ) {
2216
2314
// Snapshot the state into a new DataView since the underlying
2217
2315
// buffer will be destroyed.
2218
- this [ kHandle ] = new DataView ( this [ kHandle ] ) ;
2316
+ let u8 = new Uint8Array ( this [ kHandle ] . buffer ,
2317
+ this [ kHandle ] . byteOffset ,
2318
+ this [ kHandle ] . byteLength ) ;
2319
+ u8 = new Uint8Array ( u8 ) ;
2320
+ this [ kHandle ] = new DataView ( u8 . buffer ,
2321
+ u8 . byteOffset ,
2322
+ u8 . byteLength ) ;
2219
2323
}
2220
2324
}
2221
2325
ObjectDefineProperties ( EndpointState . prototype , {
0 commit comments