UNPKG

@node-lightning/wire

Version:
50 lines (49 loc) 1.76 kB
import { Peer } from "./Peer"; export declare class PingPongState { PING_INTERVAL_MS: number; PONG_TIMEOUT_MS: number; PING_FLOOD_THRESHOLD: number; PONG_REQUIRED_THRESHOLD: number; private _peerClient; private _pingsReceieved; private _lastMessageReceived; private _sendPingIntervalHandle; private _pongTimeoutHandle; private _sentPing; /** * Maintains ping/pong state for a client where by it will perform several functions. Refer to * Bolt01 for all nuances of implementation. * * 0. Upon receipt of a message from the remote server, we reset the ping timeout as * we are aware that the server is still live. * * 1. When there are no messages from a client for a period of time, it will emit a ping * and wait for the pong. If not pong is received, or the pong is invalid, then the * connection is terminated. * * 2. When a ping is received an appropriate pong message will be sent. If pong messages * are received more frequently than 30 second, then they are ignored. If more than * 5 pings are receiced in a 30 second period, then we will close the connection. */ constructor(peerClient: Peer); /** * Starts the PingPongState manager by starting a ping interval that will * consider sending a ping every 60s */ start(): void; /** * Handles incoming messages */ onMessage(m: any): void; /** * Fires prior to the peer being disconnected * and will clean up resources */ onDisconnecting(): void; private _sendPing; private _sendPong; private _onSendPingInterval; private _validatePong; private _pongTimedOut; private _checkForPingFlood; }