@microsoft/dev-tunnels-ssh
Version:
SSH library for Dev Tunnels
144 lines • 7.19 kB
TypeScript
/// <reference types="node" />
import { Event, Disposable } from 'vscode-jsonrpc';
import { ChannelRequestMessage, ChannelOpenMessage, ChannelOpenConfirmationMessage } from './messages/connectionMessages';
import { ChannelMetrics } from './metrics/channelMetrics';
import { SshRequestEventArgs } from './events/sshRequestEventArgs';
import { SshChannelClosedEventArgs } from './events/sshChannelClosedEventArgs';
import { CancellationToken } from './util/cancellation';
import { SshExtendedDataEventArgs, SshExtendedDataType } from './events/sshExtendedDataEventArgs';
/**
* Represents a channel on an SSH session. A session may include multiple channels, which
* are multiplexed over the connection. Each channel within a session has a unique integer ID.
*/
export declare class SshChannel implements Disposable {
private readonly connectionService;
readonly channelType: string;
readonly channelId: number;
readonly remoteChannelId: number;
readonly openMessage: ChannelOpenMessage;
openConfirmationMessage: ChannelOpenConfirmationMessage;
static readonly sessionChannelType = "session";
/**
* Default maximum packet size. Channel data payloads larger than the max packet size will
* be broken into chunks before sending. The actual `maxPacketSize` may be smaller (but
* never larger) than the default if requested by the other side.
*/
static readonly defaultMaxPacketSize: number;
/**
* Default maximum window size for received data. The other side will not send more data than
* the window size until it receives an acknowledgement that some of the data was received and
* processed by this side. A non-default `maxWindowSize` may be configured at the time of
* opening the channel.
*/
static readonly defaultMaxWindowSize: number;
private remoteWindowSize;
private maxWindowSizeValue;
private windowSize;
private remoteClosed;
private localClosed;
private sentEof;
private exitStatus?;
private exitSignal?;
private exitErrorMessage?;
private disposed;
private openSendingWindowCompletionSource;
private requestCompletionSources;
private readonly sendSemaphore;
/**
* Gets an object that reports measurements about the channel.
*/
readonly metrics: ChannelMetrics;
private readonly dataReceivedEmitter;
private readonly extendedDataReceivedEmitter;
/**
* Event raised when a data message is received on the channel.
*
* Users of a channel MUST add a `onDataReceived` event handler immediately after a
* channel is opened/accepted, or else all session communication will be blocked.
* (The `SshStream` class does this automatically.)
*
* The event handler must call `adjustWindow` when the data has been consumed,
* to notify the remote side that it may send more data.
*/
readonly onDataReceived: Event<Buffer>;
readonly onExtendedDataReceived: Event<SshExtendedDataEventArgs>;
private readonly eofEmitter;
/**
* Event raised when an EOF message is received on the channel.
*/
readonly onEof: Event<void>;
private readonly closedEmitter;
readonly onClosed: Event<SshChannelClosedEventArgs>;
private readonly requestEmitter;
readonly onRequest: Event<SshRequestEventArgs<ChannelRequestMessage>>;
get session(): import("./sshSession").SshSession;
get isClosed(): boolean;
/**
* Gets the maximum window size for received data. The other side will not send more
* data than the window size until it receives an acknowledgement that some of the data was
* received and processed by this side.
*/
get maxWindowSize(): number;
/**
* Sets the maximum window size for received data. The other side will not send more
* data than the window size until it receives an acknowledgement that some of the data was
* received and processed by this side.
*
* The default value is `defaultMaxWindowSize`. The value may be configured for a channel
* opened by this side by setting `ChannelOpenMessage.maxWindowSize` in the message object
* passed to `SshSession.openChannel()`, or for a channel opened by the other side by
* assigning to this property while handling the `SshSession.onChannelOpening` event.
* Changing the maximum window size at any other time is not valid because the other
* side would not be aware of the change.
*/
set maxWindowSize(value: number);
/**
* Gets the maximum packet size. Channel data payloads larger than the max packet size will
* be broken into chunks before sending. The actual max packet size may be smaller (but
* never larger) than `defaultMaxPacketSize` if requested by the other side.
*/
readonly maxPacketSize: number;
/**
* Sends a channel request and waits for a response.
*
* Note if `wantReply` is `false`, this method returns `true` immediately after sending the
* request, without waiting for a reply.
*
* @returns The authorization status of the response; if false, the other side denied the
* request.
* @throws `ObjectDisposedError` if the channel was closed before sending the request.
* @throws `SshChannelError` if the channel was closed while waiting for a reply to the request.
*/
request(request: ChannelRequestMessage, cancellation?: CancellationToken): Promise<boolean>;
send(data: Buffer, cancellation?: CancellationToken): Promise<void>;
sendExtendedData(dataTypeCode: SshExtendedDataType, data: Buffer, cancellation?: CancellationToken): Promise<void>;
sendCommon(data: Buffer, extendedDataType: SshExtendedDataType | undefined, cancellation?: CancellationToken): Promise<void>;
private sendEof;
handleExtendedDataReceived(data: SshExtendedDataEventArgs): void;
/**
* Adjusts the local receiving window size by the specified amount, notifying
* the remote side that it is free to send more data.
*
* This method MUST be called either immediately or eventually by the
* `onDataReceived` event handler as incoming data is processed.
*/
adjustWindow(messageLength: number): void;
close(cancellation?: CancellationToken): Promise<void>;
close(exitStatus: number, cancellation?: CancellationToken): Promise<void>;
close(exitSignal: string, errorMessage?: string, cancellation?: CancellationToken): Promise<void>;
private closeDefault;
private closeWithStatus;
private closeWithSignal;
private raiseClosedEvent;
dispose(): void;
private disposeInternal;
/**
* Pipes one SSH channel into another, relaying all data between them.
* @param toChannel Channel to which the current channel will be connected via the pipe.
* @returns A promise that resolves when the channels are closed.
*/
pipe(toChannel: SshChannel): Promise<void>;
private cancelPendingRequests;
toString(): string;
}
//# sourceMappingURL=sshChannel.d.ts.map