UNPKG

lightningdevkit

Version:
100 lines (99 loc) 5.21 kB
import { Result_NoneNoneZ } from '../structs/Result_NoneNoneZ.mjs'; import { Init } from '../structs/Init.mjs'; import { OnionMessage } from '../structs/OnionMessage.mjs'; import { InitFeatures } from '../structs/InitFeatures.mjs'; import { NodeFeatures } from '../structs/NodeFeatures.mjs'; import { CommonBase } from './CommonBase.mjs'; /** An implementation of OnionMessageHandler */ export interface OnionMessageHandlerInterface { /**Handle an incoming `onion_message` message from the given peer. */ handle_onion_message(peer_node_id: Uint8Array, msg: OnionMessage): void; /**Returns the next pending onion message for the peer with the given node id. * * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None */ next_onion_message_for_peer(peer_node_id: Uint8Array): OnionMessage; /**Called when a connection is established with a peer. Can be used to track which peers * advertise onion message support and are online. * * May return an `Err(())` if the features the peer supports are not sufficient to communicate * with us. Implementors should be somewhat conservative about doing so, however, as other * message handlers may still wish to communicate with this peer. * * [`Self::peer_disconnected`] will not be called if `Err(())` is returned. */ peer_connected(their_node_id: Uint8Array, init: Init, inbound: boolean): Result_NoneNoneZ; /**Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to * drop and refuse to forward onion messages to this peer. */ peer_disconnected(their_node_id: Uint8Array): void; /**Performs actions that should happen roughly every ten seconds after startup. Allows handlers * to drop any buffered onion messages intended for prospective peers. */ timer_tick_occurred(): void; /**Gets the node feature flags which this handler itself supports. All available handlers are * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`] * which are broadcasted in our [`NodeAnnouncement`] message. */ provided_node_features(): NodeFeatures; /**Gets the init feature flags which should be sent to the given peer. All available handlers * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`] * which are sent in our [`Init`] message. * * Note that this method is called before [`Self::peer_connected`]. */ provided_init_features(their_node_id: Uint8Array): InitFeatures; } /** * A handler for received [`OnionMessage`]s and for providing generated ones to send. */ export declare class OnionMessageHandler extends CommonBase { /** Creates a new instance of OnionMessageHandler from a given implementation */ static new_impl(arg: OnionMessageHandlerInterface): OnionMessageHandler; /** * Handle an incoming `onion_message` message from the given peer. */ handle_onion_message(peer_node_id: Uint8Array, msg: OnionMessage): void; /** * Returns the next pending onion message for the peer with the given node id. * * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None */ next_onion_message_for_peer(peer_node_id: Uint8Array): OnionMessage; /** * Called when a connection is established with a peer. Can be used to track which peers * advertise onion message support and are online. * * May return an `Err(())` if the features the peer supports are not sufficient to communicate * with us. Implementors should be somewhat conservative about doing so, however, as other * message handlers may still wish to communicate with this peer. * * [`Self::peer_disconnected`] will not be called if `Err(())` is returned. */ peer_connected(their_node_id: Uint8Array, init: Init, inbound: boolean): Result_NoneNoneZ; /** * Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to * drop and refuse to forward onion messages to this peer. */ peer_disconnected(their_node_id: Uint8Array): void; /** * Performs actions that should happen roughly every ten seconds after startup. Allows handlers * to drop any buffered onion messages intended for prospective peers. */ timer_tick_occurred(): void; /** * Gets the node feature flags which this handler itself supports. All available handlers are * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`] * which are broadcasted in our [`NodeAnnouncement`] message. */ provided_node_features(): NodeFeatures; /** * Gets the init feature flags which should be sent to the given peer. All available handlers * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`] * which are sent in our [`Init`] message. * * Note that this method is called before [`Self::peer_connected`]. */ provided_init_features(their_node_id: Uint8Array): InitFeatures; }