UNPKG

@node-lightning/wire

Version:
61 lines 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GossipPeer = void 0; const InitFeatureFlags_1 = require("../flags/InitFeatureFlags"); const GossipQueriesSync_1 = require("../gossip/GossipQueriesSync"); const GossipQueriesReceiver_1 = require("./GossipQueriesReceiver"); /** * Retains state for peers based on */ class GossipPeer { constructor(logger, peer) { this.peer = peer; this.logger = logger.sub(GossipPeer.name); this.key = peer.id; if (this.gossipQueries) { this.receiver = new GossipQueriesReceiver_1.GossipQueriesReceiver(this.peer.localFeatures[0], this.peer, this.logger); } } /** * Returns true if the gossip_queries feature has been negotiated with the * remote peer. */ get gossipQueries() { return (this.peer.remoteFeatures.isSet(InitFeatureFlags_1.InitFeatureFlags.gossipQueriesOptional) || this.peer.remoteFeatures.isSet(InitFeatureFlags_1.InitFeatureFlags.gossipQueriesRequired)); } /** * Enables the receipt of rumor mongered messages. */ enableGossip() { if (this.gossipQueries) { this.receiver.activate(); } } /** * Disables the receipt of rumor mongered messages. */ disableGossip() { if (this.gossipQueries) { this.receiver.deactivate(); } } /** * Performs Gossip synchronization using the negotiated strategy. Currently * only support gossip_queries * @param firstBlock * @param numBlocks */ async syncRange(firstBlock, numBlocks) { if (this.gossipQueries) { const chainHash = this.peer.localChains[0]; this.syncTask = new GossipQueriesSync_1.GossipQueriesSync(chainHash, this.peer, this.logger); await this.syncTask.queryRange(firstBlock, numBlocks); this.syncTask = undefined; return true; } return false; } } exports.GossipPeer = GossipPeer; //# sourceMappingURL=GossipPeer.js.map