@node-lightning/wire
Version:
Lightning Network Wire Protocol
82 lines (81 loc) • 2.6 kB
TypeScript
/// <reference types="node" />
import { ILogger } from "@node-lightning/logger";
import { Readable } from "stream";
import { IWireMessage } from "../messages/IWireMessage";
import { IPeer, Peer } from "../Peer";
import { GossipFilter } from "./GossipFilter";
export declare enum ReadState {
Ready = 0,
Reading = 1,
Blocked = 2
}
/**
* Implements a decorator for the standard Peer adding functionality for Gossip
* related activities. Messages from the GossipPeer occur after being pushed
* through a GossipFilter to validate they are aokay.
*/
export declare class GossipPeer extends Readable implements IPeer {
readonly peer: Peer;
readonly filter: GossipFilter;
readonly logger: ILogger;
private _readState;
private _receiver;
private _syncRangeTask;
/**
* This class expects to be instantiated by a peer that is read and will
* throw if the peer is not yet in the ready state. This ensures we can
* construct the GossipPeer correctly using the negotiated features
* @param peer
* @param filter
* @param logger
*/
constructor(peer: Peer, filter: GossipFilter, logger: ILogger);
/**
* Returns true if the gossip_queries feature has been negotiated with the
* remote peer.
*/
get gossipQueries(): boolean;
/**
* Performs Gossip synchronization using the negotiated strategy. Currently
* only support gossip_queries
* @param firstBlock
* @param numBlocks
*/
syncRange(firstBlock?: number, numBlocks?: number): Promise<boolean>;
/**
* Enables the receipt of rumor mongered messages.
*/
enableGossip(): void;
/**
* Disables the receipt of rumor mongered messages.
*/
disableGossip(): void;
/**
* Sends the serialized data to the peer.
* @param buf
*/
send(buf: Buffer): void;
/**
* Sends a message to the peer using the default serialization.
* @param msg
*/
sendMessage(msg: IWireMessage): void;
/**
* Disconnects the peer
*/
disconnect(): void;
/**
* Fires when a peer triggers the readable event. This method locks
* to ensure only a single read event occurs at a time.
* @returns
*/
protected _onPeerReadable(): Promise<void>;
/**
* Internally process messages. If the message is a routing related message
* it will pass through the GossipFilter, otherwise it will be immediately
* broadcast.
* @param msg
*/
protected _onPeerMessage(msg: IWireMessage): Promise<IWireMessage[]>;
_read(): void;
}