UNPKG

5.04 kBTypeScriptView Raw
1/// <reference types="node" />
2import * as http2 from 'http2';
3import { StatusObject } from './call-interface';
4import { ChannelCredentials } from './channel-credentials';
5import { ChannelOptions } from './channel-options';
6import { SocketRef } from './channelz';
7import { SubchannelAddress } from './subchannel-address';
8import { GrpcUri } from './uri-parser';
9import { Http2SubchannelCall, SubchannelCall, SubchannelCallInterceptingListener } from './subchannel-call';
10import { Metadata } from './metadata';
11export interface CallEventTracker {
12 addMessageSent(): void;
13 addMessageReceived(): void;
14 onCallEnd(status: StatusObject): void;
15 onStreamEnd(success: boolean): void;
16}
17export interface TransportDisconnectListener {
18 (tooManyPings: boolean): void;
19}
20export interface Transport {
21 getChannelzRef(): SocketRef;
22 getPeerName(): string;
23 createCall(metadata: Metadata, host: string, method: string, listener: SubchannelCallInterceptingListener, subchannelCallStatsTracker: Partial<CallEventTracker>): SubchannelCall;
24 addDisconnectListener(listener: TransportDisconnectListener): void;
25 shutdown(): void;
26}
27declare class Http2Transport implements Transport {
28 private session;
29 /**
30 * Name of the remote server, if it is not the same as the subchannel
31 * address, i.e. if connecting through an HTTP CONNECT proxy.
32 */
33 private remoteName;
34 /**
35 * The amount of time in between sending pings
36 */
37 private keepaliveTimeMs;
38 /**
39 * The amount of time to wait for an acknowledgement after sending a ping
40 */
41 private keepaliveTimeoutMs;
42 /**
43 * Timer reference for timeout that indicates when to send the next ping
44 */
45 private keepaliveTimerId;
46 /**
47 * Indicates that the keepalive timer ran out while there were no active
48 * calls, and a ping should be sent the next time a call starts.
49 */
50 private pendingSendKeepalivePing;
51 /**
52 * Timer reference tracking when the most recent ping will be considered lost
53 */
54 private keepaliveTimeoutId;
55 /**
56 * Indicates whether keepalive pings should be sent without any active calls
57 */
58 private keepaliveWithoutCalls;
59 private userAgent;
60 private activeCalls;
61 private subchannelAddressString;
62 private disconnectListeners;
63 private disconnectHandled;
64 private channelzRef;
65 private readonly channelzEnabled;
66 private streamTracker;
67 private keepalivesSent;
68 private messagesSent;
69 private messagesReceived;
70 private lastMessageSentTimestamp;
71 private lastMessageReceivedTimestamp;
72 constructor(session: http2.ClientHttp2Session, subchannelAddress: SubchannelAddress, options: ChannelOptions,
73 /**
74 * Name of the remote server, if it is not the same as the subchannel
75 * address, i.e. if connecting through an HTTP CONNECT proxy.
76 */
77 remoteName: string | null);
78 private getChannelzInfo;
79 private trace;
80 private keepaliveTrace;
81 private flowControlTrace;
82 private internalsTrace;
83 /**
84 * Indicate to the owner of this object that this transport should no longer
85 * be used. That happens if the connection drops, or if the server sends a
86 * GOAWAY.
87 * @param tooManyPings If true, this was triggered by a GOAWAY with data
88 * indicating that the session was closed becaues the client sent too many
89 * pings.
90 * @returns
91 */
92 private reportDisconnectToOwner;
93 /**
94 * Handle connection drops, but not GOAWAYs.
95 */
96 private handleDisconnect;
97 addDisconnectListener(listener: TransportDisconnectListener): void;
98 private clearKeepaliveTimer;
99 private clearKeepaliveTimeout;
100 private canSendPing;
101 private maybeSendPing;
102 /**
103 * Starts the keepalive ping timer if appropriate. If the timer already ran
104 * out while there were no active requests, instead send a ping immediately.
105 * If the ping timer is already running or a ping is currently in flight,
106 * instead do nothing and wait for them to resolve.
107 */
108 private maybeStartKeepalivePingTimer;
109 private stopKeepalivePings;
110 private removeActiveCall;
111 private addActiveCall;
112 createCall(metadata: Metadata, host: string, method: string, listener: SubchannelCallInterceptingListener, subchannelCallStatsTracker: Partial<CallEventTracker>): Http2SubchannelCall;
113 getChannelzRef(): SocketRef;
114 getPeerName(): string;
115 shutdown(): void;
116}
117export interface SubchannelConnector {
118 connect(address: SubchannelAddress, credentials: ChannelCredentials, options: ChannelOptions): Promise<Transport>;
119 shutdown(): void;
120}
121export declare class Http2SubchannelConnector implements SubchannelConnector {
122 private channelTarget;
123 private session;
124 private isShutdown;
125 constructor(channelTarget: GrpcUri);
126 private trace;
127 private createSession;
128 connect(address: SubchannelAddress, credentials: ChannelCredentials, options: ChannelOptions): Promise<Http2Transport>;
129 shutdown(): void;
130}
131export {};