UNPKG

4.47 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 * The amount of time in between sending pings
31 */
32 private keepaliveTimeMs;
33 /**
34 * The amount of time to wait for an acknowledgement after sending a ping
35 */
36 private keepaliveTimeoutMs;
37 /**
38 * Timer reference for timeout that indicates when to send the next ping
39 */
40 private keepaliveIntervalId;
41 /**
42 * Timer reference tracking when the most recent ping will be considered lost
43 */
44 private keepaliveTimeoutId;
45 /**
46 * Indicates whether keepalive pings should be sent without any active calls
47 */
48 private keepaliveWithoutCalls;
49 private userAgent;
50 private activeCalls;
51 private subchannelAddressString;
52 private disconnectListeners;
53 private disconnectHandled;
54 private channelzRef;
55 private readonly channelzEnabled;
56 /**
57 * Name of the remote server, if it is not the same as the subchannel
58 * address, i.e. if connecting through an HTTP CONNECT proxy.
59 */
60 private remoteName;
61 private streamTracker;
62 private keepalivesSent;
63 private messagesSent;
64 private messagesReceived;
65 private lastMessageSentTimestamp;
66 private lastMessageReceivedTimestamp;
67 constructor(session: http2.ClientHttp2Session, subchannelAddress: SubchannelAddress, options: ChannelOptions);
68 private getChannelzInfo;
69 private trace;
70 private keepaliveTrace;
71 private flowControlTrace;
72 private internalsTrace;
73 /**
74 * Indicate to the owner of this object that this transport should no longer
75 * be used. That happens if the connection drops, or if the server sends a
76 * GOAWAY.
77 * @param tooManyPings If true, this was triggered by a GOAWAY with data
78 * indicating that the session was closed becaues the client sent too many
79 * pings.
80 * @returns
81 */
82 private reportDisconnectToOwner;
83 /**
84 * Handle connection drops, but not GOAWAYs.
85 */
86 private handleDisconnect;
87 addDisconnectListener(listener: TransportDisconnectListener): void;
88 private clearKeepaliveTimeout;
89 private sendPing;
90 private startKeepalivePings;
91 /**
92 * Stop keepalive pings when terminating a connection. This discards the
93 * outstanding ping timeout, so it should not be called if the same
94 * connection will still be used.
95 */
96 private stopKeepalivePings;
97 private removeActiveCall;
98 private addActiveCall;
99 createCall(metadata: Metadata, host: string, method: string, listener: SubchannelCallInterceptingListener, subchannelCallStatsTracker: Partial<CallEventTracker>): Http2SubchannelCall;
100 getChannelzRef(): SocketRef;
101 getPeerName(): string;
102 shutdown(): void;
103}
104export interface SubchannelConnector {
105 connect(address: SubchannelAddress, credentials: ChannelCredentials, options: ChannelOptions): Promise<Transport>;
106 shutdown(): void;
107}
108export declare class Http2SubchannelConnector implements SubchannelConnector {
109 private channelTarget;
110 private session;
111 private isShutdown;
112 constructor(channelTarget: GrpcUri);
113 private trace;
114 private createSession;
115 connect(address: SubchannelAddress, credentials: ChannelCredentials, options: ChannelOptions): Promise<Http2Transport>;
116 shutdown(): void;
117}
118export {};