/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import type { SupportedTransportsBitmap } from "#common/SupportedTransportsBitmap.js"; import { PeerLossContext } from "#peer/PeerLossContext.js"; import { MessageChannel } from "#protocol/MessageChannel.js"; import type { MessageExchange } from "#protocol/MessageExchange.js"; import type { MRP } from "#protocol/MRP.js"; import { SessionIntervals } from "#session/SessionIntervals.js"; import { AsyncObservable, Bytes, Channel, Duration, Lifetime, ObservableValue, Timestamp } from "@matter/general"; import type { NodeId, TypeFromPartialBitSchema } from "@matter/types"; import type { DecodedMessage, DecodedPacket, Message, Packet, PacketHeader, SessionType } from "../codec/MessageCodec.js"; import type { Fabric } from "../fabric/Fabric.js"; import type { MessageCounter } from "../protocol/MessageCounter.js"; import type { MessageReceptionState } from "../protocol/MessageReceptionState.js"; import type { SessionManager } from "./SessionManager.js"; import { SessionParameters } from "./SessionParameters.js"; export declare abstract class Session { #private; abstract get via(): string; /** Last message sent or received, on the clock of {@link Time.nowUs}. */ timestamp: Timestamp; /** Creation time on the clock of {@link Time.nowUs}, like {@link PeerLossContext.asOf}. */ readonly createdAt: Timestamp; /** * Last message received, on the clock of {@link Time.nowUs}. A session created with `setActiveTimestamp` starts * at its creation time; otherwise 0 until a message arrives. */ activeTimestamp: Timestamp; abstract type: SessionType; protected deferredClose: boolean; protected idleInterval: Duration; protected activeInterval: Duration; protected activeThreshold: Duration; protected readonly dataModelRevision: number; protected readonly interactionModelRevision: number; protected readonly specificationVersion: number; protected readonly maxPathsPerInvoke: number; protected readonly messageCounter: MessageCounter; protected readonly messageReceptionState?: MessageReceptionState; protected readonly supportedTransports: TypeFromPartialBitSchema; protected readonly maxTcpMessageSize?: number; constructor(config: Session.Configuration); get exchanges(): Set; addExchange(exchange: MessageExchange): void; deleteExchange(exchange: MessageExchange): void; get closing(): ObservableValue<[any, ...any[]], void>; notifyActivity(messageReceived: boolean): void; get isPeerActive(): boolean; /** * {@link timestamp} and {@link activeTimestamp} as whole-millisecond wall-clock times as the wall clock reads now, * for exposure as absolute times. An {@link activeTimestamp} of 0 stays 0. */ get wallClockActivity(): { lastInteractionTimestamp: Timestamp; lastActiveTimestamp: Timestamp; }; getIncrementedMessageCounter(): Promise; updateMessageCounter(messageCounter: number, _sourceNodeId?: NodeId, _operationalKey?: Bytes): void; /** * Emits on graceful close. * * During normal operation this should trigger a close message to notify the peer of closure. */ get gracefulClose(): AsyncObservable<[], void>; /** * Once set this flag prevents establishment of new exchanges. */ get isClosing(): boolean; protected static generateNonce(securityFlags: number, messageId: number, nodeId: NodeId): Uint8Array; /** * The peer's session parameters. */ get parameters(): SessionParameters; /** * The largest message the peer accepts over TCP: its announced MAX_TCP_MESSAGE_SIZE, or the spec default when it * announced none. Only meaningful for a session on a TCP channel. Never below {@link MAX_UDP_MESSAGE_SIZE}, because every node accepts that size over UDP anyway * and a smaller value would leave no room to send anything. * * @see {@link MatterSpecification.v161.Core} ยง 4.13.1 */ get peerMaxTcpMessageSize(): number; /** * Additive MRP retransmission margins for the peer's network medium, or undefined if the medium is unknown. * * Applies to every exchange on the session, including those the peer initiates. */ get peerMrpMargins(): MRP.Margins | undefined; /** * Installs the resolver for {@link peerMrpMargins}. A resolver rather than a value because the peer's medium * often becomes known (or changes, e.g. a new thread channel) only after the session exists. */ set peerMrpMarginsResolver(resolver: () => MRP.Margins | undefined); /** * Allows updating the Session timing parameters based on received information from the peer during PASE/CASE initialization */ set timingParameters(intervals: Partial); abstract isSecure: boolean; abstract id: number; abstract peerSessionId: number; abstract nodeId: NodeId | undefined; abstract peerNodeId: NodeId | undefined; abstract associatedFabric: Fabric; abstract supportsMRP: boolean; abstract decode(packet: DecodedPacket, aad?: Bytes): DecodedMessage; abstract encode(message: Message): Packet; static idStrOf(source: Packet | PacketHeader | number): string; /** * Close the session. * * This begins the close process. {@link shutdownLogic} is logic that should run once the session no longer accepts * new exchanges. It may set {@link deferredClose} to prevent the close from proceeding until all exchanges are * finished. Otherwise, the close will proceed immediately. */ initiateClose(shutdownLogic?: () => Promise): Promise; /** * Force-close the session. * * This ends the session's subscriptions for good and closes exchanges without notifying peers. With * {@link PeerLossContext.keepSubscriptions} the subscriptions end only when the session closes. It places the * session in a closing state so no further exchanges are accepted. * * TODO refactor when moving subscriptions away from sessions */ initiateForceClose(context: PeerLossContext): Promise; /** * Whether a communication failure on the session's exchanges leaves the session open instead of marking the peer * lost. The session's owner then ends it. */ get suppressPeerLoss(): boolean; get isClosed(): boolean; /** * The {@link MessageChannel} other components use for session communication. */ get channel(): MessageChannel; get usesMrp(): boolean; get supportsLargeMessages(): boolean; /** Whether outgoing messages set the privacy ("P") flag and obfuscate the header. Gates encode only; off by default. */ get usePrivacy(): boolean; get hasActiveExchanges(): boolean; /** End the session's subscriptions for good. Returns how many were closed. */ closeSubscriptions(_flush?: boolean, _currentExchange?: MessageExchange): Promise; /** * Flush and close the session's subscriptions because the node shuts down, keeping them eligible for * re-establishment on the next start. Subscriptions the session closes later are kept the same way. Returns how * many were closed. */ closeSubscriptionsForShutdown(): Promise; detachChannel(): MessageChannel | undefined; protected close(): Promise; [Symbol.asyncDispose](): Promise; protected get manager(): SessionManager | undefined; protected set channel(channel: MessageChannel); join(...name: unknown[]): Lifetime; /** * Invoked by the manager when the session is "live". * * This is separate from construction because we sometimes discard sessions without installing in a manager or * closing. */ activate(): Lifetime; protected set lifetime(lifetime: Lifetime); } export declare namespace Session { interface CommonConfig { manager?: SessionManager; /** * When setting this to true the session is not automatically registered to a provided session manager. * You need to do this yourself. */ delayManagerRegistration?: true; channel?: Channel; } interface Configuration extends CommonConfig { messageCounter: MessageCounter; messageReceptionState?: MessageReceptionState; sessionParameters?: SessionParameters.Config; setActiveTimestamp: boolean; } } //# sourceMappingURL=Session.d.ts.map