/
var
/
www
/
greso.tech
/
server
/
nsm
/
node_modules
/
@grpc
/
grpc-js
/
build
/
src
/
/var/www/greso.tech/server/nsm/node_modules/@grpc/grpc-js/build/src
mkdir
upload
Name
Size
Mode
Actions
generated/
-
0755
rm
admin.d.ts
447
0644
edit
dl
rm
admin.js
1277
0644
edit
dl
rm
admin.js.map
471
0644
edit
dl
rm
backoff-timeout.d.ts
2187
0644
edit
dl
rm
backoff-timeout.js
5071
0644
edit
dl
rm
backoff-timeout.js.map
2911
0644
edit
dl
rm
call-credentials-filter.d.ts
684
0644
edit
dl
rm
call-credentials-filter.js
3274
0644
edit
dl
rm
call-credentials-filter.js.map
1724
0644
edit
dl
rm
call-credentials.d.ts
2407
0644
edit
dl
rm
call-credentials.js
5178
0644
edit
dl
rm
call-credentials.js.map
3363
0644
edit
dl
rm
call-interface.d.ts
2834
0644
edit
dl
rm
call-interface.js
3143
0644
edit
dl
rm
call-interface.js.map
1888
0644
edit
dl
rm
call-number.d.ts
53
0644
edit
dl
rm
call-number.js
885
0644
edit
dl
rm
call-number.js.map
240
0644
edit
dl
rm
call-stream.d.ts
5795
0644
edit
dl
rm
call-stream.js
30144
0644
edit
dl
rm
call-stream.js.map
18516
0644
edit
dl
rm
call.d.ts
3600
0644
edit
dl
rm
call.js
5073
0644
edit
dl
rm
call.js.map
2885
0644
edit
dl
rm
channel-credentials.d.ts
3859
0644
edit
dl
rm
channel-credentials.js
7316
0644
edit
dl
rm
channel-credentials.js.map
3679
0644
edit
dl
rm
channel-options.d.ts
2753
0644
edit
dl
rm
channel-options.js
2430
0644
edit
dl
rm
channel-options.js.map
1346
0644
edit
dl
rm
channel.d.ts
3747
0644
edit
dl
rm
channel.js
2729
0644
edit
dl
rm
channel.js.map
1423
0644
edit
dl
rm
channelz.d.ts
3900
0644
edit
dl
rm
channelz.js
22980
0644
edit
dl
rm
channelz.js.map
17367
0644
edit
dl
rm
client-interceptors.d.ts
4611
0644
edit
dl
rm
client-interceptors.js
17787
0644
edit
dl
rm
client-interceptors.js.map
10601
0644
edit
dl
rm
client.d.ts
5817
0644
edit
dl
rm
client.js
18974
0644
edit
dl
rm
client.js.map
11855
0644
edit
dl
rm
compression-algorithms.d.ts
94
0644
edit
dl
rm
compression-algorithms.js
1158
0644
edit
dl
rm
compression-algorithms.js.map
311
0644
edit
dl
rm
compression-filter.d.ts
1215
0644
edit
dl
rm
compression-filter.js
10307
0644
edit
dl
rm
compression-filter.js.map
6265
0644
edit
dl
rm
connectivity-state.d.ts
135
0644
edit
dl
rm
connectivity-state.js
1264
0644
edit
dl
rm
connectivity-state.js.map
327
0644
edit
dl
rm
constants.d.ts
944
0644
edit
dl
rm
constants.js
3106
0644
edit
dl
rm
constants.js.map
950
0644
edit
dl
rm
control-plane-status.d.ts
169
0644
edit
dl
rm
control-plane-status.js
1581
0644
edit
dl
rm
control-plane-status.js.map
670
0644
edit
dl
rm
deadline-filter.d.ts
825
0644
edit
dl
rm
deadline-filter.js
3628
0644
edit
dl
rm
deadline-filter.js.map
2579
0644
edit
dl
rm
deadline.d.ts
752
0644
edit
dl
rm
deadline.js
3351
0644
edit
dl
rm
deadline.js.map
1919
0644
edit
dl
rm
duration.d.ts
267
0644
edit
dl
rm
duration.js
1253
0644
edit
dl
rm
duration.js.map
606
0644
edit
dl
rm
error.d.ts
134
0644
edit
dl
rm
error.js
1236
0644
edit
dl
rm
error.js.map
520
0644
edit
dl
rm
events.d.ts
521
0644
edit
dl
rm
events.js
711
0644
edit
dl
rm
events.js.map
131
0644
edit
dl
rm
experimental.d.ts
1314
0644
edit
dl
rm
experimental.js
4211
0644
edit
dl
rm
experimental.js.map
764
0644
edit
dl
rm
filter-stack.d.ts
969
0644
edit
dl
rm
filter-stack.js
2542
0644
edit
dl
rm
filter-stack.js.map
2090
0644
edit
dl
rm
filter.d.ts
1192
0644
edit
dl
rm
filter.js
1111
0644
edit
dl
rm
filter.js.map
464
0644
edit
dl
rm
http_proxy.d.ts
727
0644
edit
dl
rm
http_proxy.js
9424
0644
edit
dl
rm
http_proxy.js.map
6084
0644
edit
dl
rm
index.d.ts
5350
0644
edit
dl
rm
index.js
9234
0644
edit
dl
rm
index.js.map
3099
0644
edit
dl
rm
internal-channel.d.ts
4889
0644
edit
dl
rm
internal-channel.js
21474
0644
edit
dl
rm
internal-channel.js.map
14231
0644
edit
dl
rm
load-balancer-child-handler.d.ts
815
0644
edit
dl
rm
load-balancer-child-handler.js
5236
0644
edit
dl
rm
load-balancer-child-handler.js.map
3246
0644
edit
dl
rm
load-balancer-outlier-detection.d.ts
2663
0644
edit
dl
rm
load-balancer-outlier-detection.js
25785
0644
edit
dl
rm
load-balancer-outlier-detection.js.map
18310
0644
edit
dl
rm
load-balancer-pick-first.d.ts
2828
0644
edit
dl
rm
load-balancer-pick-first.js
17509
0644
edit
dl
rm
load-balancer-pick-first.js.map
9506
0644
edit
dl
rm
load-balancer-round-robin.d.ts
804
0644
edit
dl
rm
load-balancer-round-robin.js
7816
0644
edit
dl
rm
load-balancer-round-robin.js.map
5019
0644
edit
dl
rm
load-balancer.d.ts
4453
0644
edit
dl
rm
load-balancer.js
4845
0644
edit
dl
rm
load-balancer.js.map
2428
0644
edit
dl
rm
load-balancing-call.d.ts
1847
0644
edit
dl
rm
load-balancing-call.js
11647
0644
edit
dl
rm
load-balancing-call.js.map
7531
0644
edit
dl
rm
logging.d.ts
477
0644
edit
dl
rm
logging.js
4006
0644
edit
dl
rm
logging.js.map
2795
0644
edit
dl
rm
make-client.d.ts
3002
0644
edit
dl
rm
make-client.js
5498
0644
edit
dl
rm
make-client.js.map
3112
0644
edit
dl
rm
max-message-size-filter.d.ts
762
0644
edit
dl
rm
max-message-size-filter.js
3360
0644
edit
dl
rm
max-message-size-filter.js.map
1596
0644
edit
dl
rm
metadata.d.ts
3241
0644
edit
dl
rm
metadata.js
8839
0644
edit
dl
rm
metadata.js.map
5645
0644
edit
dl
rm
object-stream.d.ts
1604
0644
edit
dl
rm
object-stream.js
718
0644
edit
dl
rm
object-stream.js.map
145
0644
edit
dl
rm
picker.d.ts
3039
0644
edit
dl
rm
picker.js
3108
0644
edit
dl
rm
picker.js.map
1252
0644
edit
dl
rm
resolver-dns.d.ts
232
0644
edit
dl
rm
resolver-dns.js
13390
0644
edit
dl
rm
resolver-dns.js.map
7558
0644
edit
dl
rm
resolver-ip.d.ts
39
0644
edit
dl
rm
resolver-ip.js
3833
0644
edit
dl
rm
resolver-ip.js.map
2512
0644
edit
dl
rm
resolver-uds.d.ts
39
0644
edit
dl
rm
resolver-uds.js
1522
0644
edit
dl
rm
resolver-uds.js.map
823
0644
edit
dl
rm
resolver.d.ts
4288
0644
edit
dl
rm
resolver.js
3231
0644
edit
dl
rm
resolver.js.map
1399
0644
edit
dl
rm
resolving-call.d.ts
1754
0644
edit
dl
rm
resolving-call.js
10711
0644
edit
dl
rm
resolving-call.js.map
8551
0644
edit
dl
rm
resolving-load-balancer.d.ts
2839
0644
edit
dl
rm
resolving-load-balancer.js
12027
0644
edit
dl
rm
resolving-load-balancer.js.map
6285
0644
edit
dl
rm
retrying-call.d.ts
3528
0644
edit
dl
rm
retrying-call.js
24658
0644
edit
dl
rm
retrying-call.js.map
18318
0644
edit
dl
rm
server-call.d.ts
8283
0644
edit
dl
rm
server-call.js
24281
0644
edit
dl
rm
server-call.js.map
19534
0644
edit
dl
rm
server-credentials.d.ts
511
0644
edit
dl
rm
server-credentials.js
2834
0644
edit
dl
rm
server-credentials.js.map
1787
0644
edit
dl
rm
server.d.ts
2214
0644
edit
dl
rm
server.js
38251
0644
edit
dl
rm
server.js.map
26851
0644
edit
dl
rm
service-config.d.ts
2163
0644
edit
dl
rm
service-config.js
16161
0644
edit
dl
rm
service-config.js.map
10475
0644
edit
dl
rm
status-builder.d.ts
657
0644
edit
dl
rm
status-builder.js
1767
0644
edit
dl
rm
status-builder.js.map
972
0644
edit
dl
rm
stream-decoder.d.ts
313
0644
edit
dl
rm
stream-decoder.js
4267
0644
edit
dl
rm
stream-decoder.js.map
2715
0644
edit
dl
rm
subchannel-address.d.ts
950
0644
edit
dl
rm
subchannel-address.js
2228
0644
edit
dl
rm
subchannel-address.js.map
1195
0644
edit
dl
rm
subchannel-call.d.ts
2258
0644
edit
dl
rm
subchannel-call.js
20012
0644
edit
dl
rm
subchannel-call.js.map
11156
0644
edit
dl
rm
subchannel-interface.d.ts
1842
0644
edit
dl
rm
subchannel-interface.js
1703
0644
edit
dl
rm
subchannel-interface.js.map
974
0644
edit
dl
rm
subchannel-pool.d.ts
1472
0644
edit
dl
rm
subchannel-pool.js
5674
0644
edit
dl
rm
subchannel-pool.js.map
2494
0644
edit
dl
rm
subchannel.d.ts
4654
0644
edit
dl
rm
subchannel.js
14590
0644
edit
dl
rm
subchannel.js.map
8187
0644
edit
dl
rm
tls-helpers.d.ts
149
0644
edit
dl
rm
tls-helpers.js
1272
0644
edit
dl
rm
tls-helpers.js.map
502
0644
edit
dl
rm
transport.d.ts
4473
0644
edit
dl
rm
transport.js
26888
0644
edit
dl
rm
transport.js.map
14801
0644
edit
dl
rm
uri-parser.d.ts
357
0644
edit
dl
rm
uri-parser.js
3274
0644
edit
dl
rm
uri-parser.js.map
2010
0644
edit
dl
rm
Edit:
/var/www/greso.tech/server/nsm/node_modules/@grpc/grpc-js/build/src/transport.js
(26888B)
"use strict"; /* * Copyright 2023 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Http2SubchannelConnector = void 0; const http2 = require("http2"); const tls_1 = require("tls"); const channelz_1 = require("./channelz"); const constants_1 = require("./constants"); const http_proxy_1 = require("./http_proxy"); const logging = require("./logging"); const resolver_1 = require("./resolver"); const subchannel_address_1 = require("./subchannel-address"); const uri_parser_1 = require("./uri-parser"); const net = require("net"); const subchannel_call_1 = require("./subchannel-call"); const call_number_1 = require("./call-number"); const TRACER_NAME = 'transport'; const FLOW_CONTROL_TRACER_NAME = 'transport_flowctrl'; const clientVersion = require('../../package.json').version; const { HTTP2_HEADER_AUTHORITY, HTTP2_HEADER_CONTENT_TYPE, HTTP2_HEADER_METHOD, HTTP2_HEADER_PATH, HTTP2_HEADER_TE, HTTP2_HEADER_USER_AGENT, } = http2.constants; /* setInterval and setTimeout only accept signed 32 bit integers. JS doesn't * have a constant for the max signed 32 bit integer, so this is a simple way * to calculate it */ const KEEPALIVE_MAX_TIME_MS = ~(1 << 31); const KEEPALIVE_TIMEOUT_MS = 20000; const tooManyPingsData = Buffer.from('too_many_pings', 'ascii'); class Http2Transport { constructor(session, subchannelAddress, options) { this.session = session; /** * The amount of time in between sending pings */ this.keepaliveTimeMs = -1; /** * The amount of time to wait for an acknowledgement after sending a ping */ this.keepaliveTimeoutMs = KEEPALIVE_TIMEOUT_MS; /** * Timer reference tracking when the most recent ping will be considered lost */ this.keepaliveTimeoutId = null; /** * Indicates whether keepalive pings should be sent without any active calls */ this.keepaliveWithoutCalls = false; this.activeCalls = new Set(); this.disconnectListeners = []; this.disconnectHandled = false; this.channelzEnabled = true; /** * Name of the remote server, if it is not the same as the subchannel * address, i.e. if connecting through an HTTP CONNECT proxy. */ this.remoteName = null; this.streamTracker = new channelz_1.ChannelzCallTracker(); this.keepalivesSent = 0; this.messagesSent = 0; this.messagesReceived = 0; this.lastMessageSentTimestamp = null; this.lastMessageReceivedTimestamp = null; // Build user-agent string. this.userAgent = [ options['grpc.primary_user_agent'], `grpc-node-js/${clientVersion}`, options['grpc.secondary_user_agent'], ] .filter((e) => e) .join(' '); // remove falsey values first if ('grpc.keepalive_time_ms' in options) { this.keepaliveTimeMs = options['grpc.keepalive_time_ms']; } if ('grpc.keepalive_timeout_ms' in options) { this.keepaliveTimeoutMs = options['grpc.keepalive_timeout_ms']; } if ('grpc.keepalive_permit_without_calls' in options) { this.keepaliveWithoutCalls = options['grpc.keepalive_permit_without_calls'] === 1; } else { this.keepaliveWithoutCalls = false; } this.keepaliveIntervalId = setTimeout(() => { }, 0); clearTimeout(this.keepaliveIntervalId); if (this.keepaliveWithoutCalls) { this.startKeepalivePings(); } this.subchannelAddressString = (0, subchannel_address_1.subchannelAddressToString)(subchannelAddress); if (options['grpc.enable_channelz'] === 0) { this.channelzEnabled = false; } this.channelzRef = (0, channelz_1.registerChannelzSocket)(this.subchannelAddressString, () => this.getChannelzInfo(), this.channelzEnabled); session.once('close', () => { this.trace('session closed'); this.stopKeepalivePings(); this.handleDisconnect(); }); session.once('goaway', (errorCode, lastStreamID, opaqueData) => { let tooManyPings = false; /* See the last paragraph of * https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md#basic-keepalive */ if (errorCode === http2.constants.NGHTTP2_ENHANCE_YOUR_CALM && opaqueData.equals(tooManyPingsData)) { tooManyPings = true; } this.trace('connection closed by GOAWAY with code ' + errorCode); this.reportDisconnectToOwner(tooManyPings); }); session.once('error', error => { /* Do nothing here. Any error should also trigger a close event, which is * where we want to handle that. */ this.trace('connection closed with error ' + error.message); }); if (logging.isTracerEnabled(TRACER_NAME)) { session.on('remoteSettings', (settings) => { this.trace('new settings received' + (this.session !== session ? ' on the old connection' : '') + ': ' + JSON.stringify(settings)); }); session.on('localSettings', (settings) => { this.trace('local settings acknowledged by remote' + (this.session !== session ? ' on the old connection' : '') + ': ' + JSON.stringify(settings)); }); } } getChannelzInfo() { var _a, _b, _c; const sessionSocket = this.session.socket; const remoteAddress = sessionSocket.remoteAddress ? (0, subchannel_address_1.stringToSubchannelAddress)(sessionSocket.remoteAddress, sessionSocket.remotePort) : null; const localAddress = sessionSocket.localAddress ? (0, subchannel_address_1.stringToSubchannelAddress)(sessionSocket.localAddress, sessionSocket.localPort) : null; let tlsInfo; if (this.session.encrypted) { const tlsSocket = sessionSocket; const cipherInfo = tlsSocket.getCipher(); const certificate = tlsSocket.getCertificate(); const peerCertificate = tlsSocket.getPeerCertificate(); tlsInfo = { cipherSuiteStandardName: (_a = cipherInfo.standardName) !== null && _a !== void 0 ? _a : null, cipherSuiteOtherName: cipherInfo.standardName ? null : cipherInfo.name, localCertificate: (certificate && 'raw' in certificate) ? certificate.raw : null, remoteCertificate: (peerCertificate && 'raw' in peerCertificate) ? peerCertificate.raw : null }; } else { tlsInfo = null; } const socketInfo = { remoteAddress: remoteAddress, localAddress: localAddress, security: tlsInfo, remoteName: this.remoteName, streamsStarted: this.streamTracker.callsStarted, streamsSucceeded: this.streamTracker.callsSucceeded, streamsFailed: this.streamTracker.callsFailed, messagesSent: this.messagesSent, messagesReceived: this.messagesReceived, keepAlivesSent: this.keepalivesSent, lastLocalStreamCreatedTimestamp: this.streamTracker.lastCallStartedTimestamp, lastRemoteStreamCreatedTimestamp: null, lastMessageSentTimestamp: this.lastMessageSentTimestamp, lastMessageReceivedTimestamp: this.lastMessageReceivedTimestamp, localFlowControlWindow: (_b = this.session.state.localWindowSize) !== null && _b !== void 0 ? _b : null, remoteFlowControlWindow: (_c = this.session.state.remoteWindowSize) !== null && _c !== void 0 ? _c : null }; return socketInfo; } trace(text) { logging.trace(constants_1.LogVerbosity.DEBUG, TRACER_NAME, '(' + this.channelzRef.id + ') ' + this.subchannelAddressString + ' ' + text); } keepaliveTrace(text) { logging.trace(constants_1.LogVerbosity.DEBUG, 'keepalive', '(' + this.channelzRef.id + ') ' + this.subchannelAddressString + ' ' + text); } flowControlTrace(text) { logging.trace(constants_1.LogVerbosity.DEBUG, FLOW_CONTROL_TRACER_NAME, '(' + this.channelzRef.id + ') ' + this.subchannelAddressString + ' ' + text); } internalsTrace(text) { logging.trace(constants_1.LogVerbosity.DEBUG, 'transport_internals', '(' + this.channelzRef.id + ') ' + this.subchannelAddressString + ' ' + text); } /** * Indicate to the owner of this object that this transport should no longer * be used. That happens if the connection drops, or if the server sends a * GOAWAY. * @param tooManyPings If true, this was triggered by a GOAWAY with data * indicating that the session was closed becaues the client sent too many * pings. * @returns */ reportDisconnectToOwner(tooManyPings) { if (this.disconnectHandled) { return; } this.disconnectHandled = true; this.disconnectListeners.forEach(listener => listener(tooManyPings)); } /** * Handle connection drops, but not GOAWAYs. */ handleDisconnect() { this.reportDisconnectToOwner(false); /* Give calls an event loop cycle to finish naturally before reporting the * disconnnection to them. */ setImmediate(() => { for (const call of this.activeCalls) { call.onDisconnect(); } }); } addDisconnectListener(listener) { this.disconnectListeners.push(listener); } clearKeepaliveTimeout() { if (!this.keepaliveTimeoutId) { return; } clearTimeout(this.keepaliveTimeoutId); this.keepaliveTimeoutId = null; } sendPing() { var _a, _b; if (this.channelzEnabled) { this.keepalivesSent += 1; } this.keepaliveTrace('Sending ping with timeout ' + this.keepaliveTimeoutMs + 'ms'); if (!this.keepaliveTimeoutId) { this.keepaliveTimeoutId = setTimeout(() => { this.keepaliveTrace('Ping timeout passed without response'); this.handleDisconnect(); }, this.keepaliveTimeoutMs); (_b = (_a = this.keepaliveTimeoutId).unref) === null || _b === void 0 ? void 0 : _b.call(_a); } try { this.session.ping((err, duration, payload) => { this.keepaliveTrace('Received ping response'); this.clearKeepaliveTimeout(); }); } catch (e) { /* If we fail to send a ping, the connection is no longer functional, so * we should discard it. */ this.handleDisconnect(); } } startKeepalivePings() { var _a, _b; if (this.keepaliveTimeMs < 0) { return; } this.keepaliveIntervalId = setInterval(() => { this.sendPing(); }, this.keepaliveTimeMs); (_b = (_a = this.keepaliveIntervalId).unref) === null || _b === void 0 ? void 0 : _b.call(_a); /* Don't send a ping immediately because whatever caused us to start * sending pings should also involve some network activity. */ } /** * Stop keepalive pings when terminating a connection. This discards the * outstanding ping timeout, so it should not be called if the same * connection will still be used. */ stopKeepalivePings() { clearInterval(this.keepaliveIntervalId); this.clearKeepaliveTimeout(); } removeActiveCall(call) { this.activeCalls.delete(call); if (this.activeCalls.size === 0) { this.session.unref(); if (!this.keepaliveWithoutCalls) { this.stopKeepalivePings(); } } } addActiveCall(call) { if (this.activeCalls.size === 0) { this.session.ref(); if (!this.keepaliveWithoutCalls) { this.startKeepalivePings(); } } this.activeCalls.add(call); } createCall(metadata, host, method, listener, subchannelCallStatsTracker) { const headers = metadata.toHttp2Headers(); headers[HTTP2_HEADER_AUTHORITY] = host; headers[HTTP2_HEADER_USER_AGENT] = this.userAgent; headers[HTTP2_HEADER_CONTENT_TYPE] = 'application/grpc'; headers[HTTP2_HEADER_METHOD] = 'POST'; headers[HTTP2_HEADER_PATH] = method; headers[HTTP2_HEADER_TE] = 'trailers'; let http2Stream; /* In theory, if an error is thrown by session.request because session has * become unusable (e.g. because it has received a goaway), this subchannel * should soon see the corresponding close or goaway event anyway and leave * READY. But we have seen reports that this does not happen * (https://github.com/googleapis/nodejs-firestore/issues/1023#issuecomment-653204096) * so for defense in depth, we just discard the session when we see an * error here. */ try { http2Stream = this.session.request(headers); } catch (e) { this.handleDisconnect(); throw e; } this.flowControlTrace('local window size: ' + this.session.state.localWindowSize + ' remote window size: ' + this.session.state.remoteWindowSize); this.internalsTrace('session.closed=' + this.session.closed + ' session.destroyed=' + this.session.destroyed + ' session.socket.destroyed=' + this.session.socket.destroyed); let eventTracker; let call; if (this.channelzEnabled) { this.streamTracker.addCallStarted(); eventTracker = { addMessageSent: () => { var _a; this.messagesSent += 1; this.lastMessageSentTimestamp = new Date(); (_a = subchannelCallStatsTracker.addMessageSent) === null || _a === void 0 ? void 0 : _a.call(subchannelCallStatsTracker); }, addMessageReceived: () => { var _a; this.messagesReceived += 1; this.lastMessageReceivedTimestamp = new Date(); (_a = subchannelCallStatsTracker.addMessageReceived) === null || _a === void 0 ? void 0 : _a.call(subchannelCallStatsTracker); }, onCallEnd: status => { var _a; (_a = subchannelCallStatsTracker.onCallEnd) === null || _a === void 0 ? void 0 : _a.call(subchannelCallStatsTracker, status); this.removeActiveCall(call); }, onStreamEnd: success => { var _a; if (success) { this.streamTracker.addCallSucceeded(); } else { this.streamTracker.addCallFailed(); } (_a = subchannelCallStatsTracker.onStreamEnd) === null || _a === void 0 ? void 0 : _a.call(subchannelCallStatsTracker, success); } }; } else { eventTracker = { addMessageSent: () => { var _a; (_a = subchannelCallStatsTracker.addMessageSent) === null || _a === void 0 ? void 0 : _a.call(subchannelCallStatsTracker); }, addMessageReceived: () => { var _a; (_a = subchannelCallStatsTracker.addMessageReceived) === null || _a === void 0 ? void 0 : _a.call(subchannelCallStatsTracker); }, onCallEnd: (status) => { var _a; (_a = subchannelCallStatsTracker.onCallEnd) === null || _a === void 0 ? void 0 : _a.call(subchannelCallStatsTracker, status); this.removeActiveCall(call); }, onStreamEnd: (success) => { var _a; (_a = subchannelCallStatsTracker.onStreamEnd) === null || _a === void 0 ? void 0 : _a.call(subchannelCallStatsTracker, success); } }; } call = new subchannel_call_1.Http2SubchannelCall(http2Stream, eventTracker, listener, this, (0, call_number_1.getNextCallNumber)()); this.addActiveCall(call); return call; } getChannelzRef() { return this.channelzRef; } getPeerName() { return this.subchannelAddressString; } shutdown() { this.session.close(); (0, channelz_1.unregisterChannelzRef)(this.channelzRef); } } class Http2SubchannelConnector { constructor(channelTarget) { this.channelTarget = channelTarget; this.session = null; this.isShutdown = false; } trace(text) { } createSession(address, credentials, options, proxyConnectionResult) { if (this.isShutdown) { return Promise.reject(); } return new Promise((resolve, reject) => { var _a, _b, _c; let remoteName; if (proxyConnectionResult.realTarget) { remoteName = (0, uri_parser_1.uriToString)(proxyConnectionResult.realTarget); this.trace('creating HTTP/2 session through proxy to ' + (0, uri_parser_1.uriToString)(proxyConnectionResult.realTarget)); } else { remoteName = null; this.trace('creating HTTP/2 session to ' + (0, subchannel_address_1.subchannelAddressToString)(address)); } const targetAuthority = (0, resolver_1.getDefaultAuthority)((_a = proxyConnectionResult.realTarget) !== null && _a !== void 0 ? _a : this.channelTarget); let connectionOptions = credentials._getConnectionOptions() || {}; connectionOptions.maxSendHeaderBlockLength = Number.MAX_SAFE_INTEGER; if ('grpc-node.max_session_memory' in options) { connectionOptions.maxSessionMemory = options['grpc-node.max_session_memory']; } else { /* By default, set a very large max session memory limit, to effectively * disable enforcement of the limit. Some testing indicates that Node's * behavior degrades badly when this limit is reached, so we solve that * by disabling the check entirely. */ connectionOptions.maxSessionMemory = Number.MAX_SAFE_INTEGER; } let addressScheme = 'http://'; if ('secureContext' in connectionOptions) { addressScheme = 'https://'; // If provided, the value of grpc.ssl_target_name_override should be used // to override the target hostname when checking server identity. // This option is used for testing only. if (options['grpc.ssl_target_name_override']) { const sslTargetNameOverride = options['grpc.ssl_target_name_override']; connectionOptions.checkServerIdentity = (host, cert) => { return (0, tls_1.checkServerIdentity)(sslTargetNameOverride, cert); }; connectionOptions.servername = sslTargetNameOverride; } else { const authorityHostname = (_c = (_b = (0, uri_parser_1.splitHostPort)(targetAuthority)) === null || _b === void 0 ? void 0 : _b.host) !== null && _c !== void 0 ? _c : 'localhost'; // We want to always set servername to support SNI connectionOptions.servername = authorityHostname; } if (proxyConnectionResult.socket) { /* This is part of the workaround for * https://github.com/nodejs/node/issues/32922. Without that bug, * proxyConnectionResult.socket would always be a plaintext socket and * this would say * connectionOptions.socket = proxyConnectionResult.socket; */ connectionOptions.createConnection = (authority, option) => { return proxyConnectionResult.socket; }; } } else { /* In all but the most recent versions of Node, http2.connect does not use * the options when establishing plaintext connections, so we need to * establish that connection explicitly. */ connectionOptions.createConnection = (authority, option) => { if (proxyConnectionResult.socket) { return proxyConnectionResult.socket; } else { /* net.NetConnectOpts is declared in a way that is more restrictive * than what net.connect will actually accept, so we use the type * assertion to work around that. */ return net.connect(address); } }; } connectionOptions = Object.assign(Object.assign({}, connectionOptions), address); /* http2.connect uses the options here: * https://github.com/nodejs/node/blob/70c32a6d190e2b5d7b9ff9d5b6a459d14e8b7d59/lib/internal/http2/core.js#L3028-L3036 * The spread operator overides earlier values with later ones, so any port * or host values in the options will be used rather than any values extracted * from the first argument. In addition, the path overrides the host and port, * as documented for plaintext connections here: * https://nodejs.org/api/net.html#net_socket_connect_options_connectlistener * and for TLS connections here: * https://nodejs.org/api/tls.html#tls_tls_connect_options_callback. In * earlier versions of Node, http2.connect passes these options to * tls.connect but not net.connect, so in the insecure case we still need * to set the createConnection option above to create the connection * explicitly. We cannot do that in the TLS case because http2.connect * passes necessary additional options to tls.connect. * The first argument just needs to be parseable as a URL and the scheme * determines whether the connection will be established over TLS or not. */ const session = http2.connect(addressScheme + targetAuthority, connectionOptions); this.session = session; session.unref(); session.once('connect', () => { session.removeAllListeners(); resolve(new Http2Transport(session, address, options)); this.session = null; }); session.once('close', () => { this.session = null; reject(); }); session.once('error', error => { this.trace('connection failed with error ' + error.message); }); }); } connect(address, credentials, options) { var _a, _b; if (this.isShutdown) { return Promise.reject(); } /* Pass connection options through to the proxy so that it's able to * upgrade it's connection to support tls if needed. * This is a workaround for https://github.com/nodejs/node/issues/32922 * See https://github.com/grpc/grpc-node/pull/1369 for more info. */ const connectionOptions = credentials._getConnectionOptions() || {}; if ('secureContext' in connectionOptions) { connectionOptions.ALPNProtocols = ['h2']; // If provided, the value of grpc.ssl_target_name_override should be used // to override the target hostname when checking server identity. // This option is used for testing only. if (options['grpc.ssl_target_name_override']) { const sslTargetNameOverride = options['grpc.ssl_target_name_override']; connectionOptions.checkServerIdentity = (host, cert) => { return (0, tls_1.checkServerIdentity)(sslTargetNameOverride, cert); }; connectionOptions.servername = sslTargetNameOverride; } else { if ('grpc.http_connect_target' in options) { /* This is more or less how servername will be set in createSession * if a connection is successfully established through the proxy. * If the proxy is not used, these connectionOptions are discarded * anyway */ const targetPath = (0, resolver_1.getDefaultAuthority)((_a = (0, uri_parser_1.parseUri)(options['grpc.http_connect_target'])) !== null && _a !== void 0 ? _a : { path: 'localhost', }); const hostPort = (0, uri_parser_1.splitHostPort)(targetPath); connectionOptions.servername = (_b = hostPort === null || hostPort === void 0 ? void 0 : hostPort.host) !== null && _b !== void 0 ? _b : targetPath; } } } return (0, http_proxy_1.getProxiedConnection)(address, options, connectionOptions).then(result => this.createSession(address, credentials, options, result)); } shutdown() { var _a; this.isShutdown = true; (_a = this.session) === null || _a === void 0 ? void 0 : _a.close(); this.session = null; } } exports.Http2SubchannelConnector = Http2SubchannelConnector; //# sourceMappingURL=transport.js.map
Save
cmd:
run