UNPKG

4.33 kBPlain TextView Raw
1/*
2 * Copyright 2019 gRPC authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18import { CompressionAlgorithms } from './compression-algorithms';
19
20/**
21 * An interface that contains options used when initializing a Channel instance.
22 */
23export interface ChannelOptions {
24 'grpc.ssl_target_name_override'?: string;
25 'grpc.primary_user_agent'?: string;
26 'grpc.secondary_user_agent'?: string;
27 'grpc.default_authority'?: string;
28 'grpc.keepalive_time_ms'?: number;
29 'grpc.keepalive_timeout_ms'?: number;
30 'grpc.keepalive_permit_without_calls'?: number;
31 'grpc.service_config'?: string;
32 'grpc.max_concurrent_streams'?: number;
33 'grpc.initial_reconnect_backoff_ms'?: number;
34 'grpc.max_reconnect_backoff_ms'?: number;
35 'grpc.use_local_subchannel_pool'?: number;
36 'grpc.max_send_message_length'?: number;
37 'grpc.max_receive_message_length'?: number;
38 'grpc.enable_http_proxy'?: number;
39 /* http_connect_target and http_connect_creds are used for passing data
40 * around internally, and should not be documented as public-facing options
41 */
42 'grpc.http_connect_target'?: string;
43 'grpc.http_connect_creds'?: string;
44 'grpc.default_compression_algorithm'?: CompressionAlgorithms;
45 'grpc.enable_channelz'?: number;
46 'grpc.dns_min_time_between_resolutions_ms'?: number;
47 'grpc.enable_retries'?: number;
48 'grpc.per_rpc_retry_buffer_size'?: number;
49 /* This option is pattered like a core option, but the core does not have
50 * this option. It is closely related to the option
51 * grpc.per_rpc_retry_buffer_size, which is in the core. The core will likely
52 * implement this functionality using the ResourceQuota mechanism, so there
53 * will probably not be any collision or other inconsistency. */
54 'grpc.retry_buffer_size'?: number;
55 'grpc.max_connection_age_ms'?: number;
56 'grpc.max_connection_age_grace_ms'?: number;
57 'grpc-node.max_session_memory'?: number;
58 'grpc.service_config_disable_resolution'?: number;
59 'grpc.client_idle_timeout_ms'?: number;
60 /**
61 * Set the enableTrace option in TLS clients and servers
62 */
63 'grpc-node.tls_enable_trace'?: number;
64 // eslint-disable-next-line @typescript-eslint/no-explicit-any
65 [key: string]: any;
66}
67
68/**
69 * This is for checking provided options at runtime. This is an object for
70 * easier membership checking.
71 */
72export const recognizedOptions = {
73 'grpc.ssl_target_name_override': true,
74 'grpc.primary_user_agent': true,
75 'grpc.secondary_user_agent': true,
76 'grpc.default_authority': true,
77 'grpc.keepalive_time_ms': true,
78 'grpc.keepalive_timeout_ms': true,
79 'grpc.keepalive_permit_without_calls': true,
80 'grpc.service_config': true,
81 'grpc.max_concurrent_streams': true,
82 'grpc.initial_reconnect_backoff_ms': true,
83 'grpc.max_reconnect_backoff_ms': true,
84 'grpc.use_local_subchannel_pool': true,
85 'grpc.max_send_message_length': true,
86 'grpc.max_receive_message_length': true,
87 'grpc.enable_http_proxy': true,
88 'grpc.enable_channelz': true,
89 'grpc.dns_min_time_between_resolutions_ms': true,
90 'grpc.enable_retries': true,
91 'grpc.per_rpc_retry_buffer_size': true,
92 'grpc.retry_buffer_size': true,
93 'grpc.max_connection_age_ms': true,
94 'grpc.max_connection_age_grace_ms': true,
95 'grpc-node.max_session_memory': true,
96 'grpc.service_config_disable_resolution': true,
97 'grpc.client_idle_timeout_ms': true,
98 'grpc-node.tls_enable_trace': true,
99};
100
101export function channelOptionsEqual(
102 options1: ChannelOptions,
103 options2: ChannelOptions
104) {
105 const keys1 = Object.keys(options1).sort();
106 const keys2 = Object.keys(options2).sort();
107 if (keys1.length !== keys2.length) {
108 return false;
109 }
110 for (let i = 0; i < keys1.length; i += 1) {
111 if (keys1[i] !== keys2[i]) {
112 return false;
113 }
114 if (options1[keys1[i]] !== options2[keys2[i]]) {
115 return false;
116 }
117 }
118 return true;
119}