import type { NodeIdString, NodeId } from '../ids/types.js'; import type { NodeContact } from './types.js'; import type { Semaphore } from '@matrixai/async-locks'; import type { ContextCancellable } from '@matrixai/contexts'; export declare class NodeConnectionQueue { protected nodeIdSelf: NodeId; protected nodeIdTarget: NodeId; protected limit: number; protected rateLimitSignal: Semaphore; protected rateLimitDirect: Semaphore; protected nodesContacted: Set; protected nodesFoundSignal: Set; protected nodesFoundDirect: Set; protected queueSignal: Array<[NodeId, NodeId | undefined]>; protected queueDirect: Array<[NodeId, NodeContact]>; protected nodeDistanceCmp: ([nodeId1]: [NodeId, unknown], [nodeId2]: [NodeId, unknown]) => 0 | 1 | -1; protected connectionMade: boolean; nodesRunningSignal: Set>; nodesRunningDirect: Set>; constructor(nodeIdSelf: NodeId, nodeIdTarget: NodeId, limit: number, rateLimitSignal: Semaphore, rateLimitDirect: Semaphore); /** * Adds the node to the queueSignal and found set. * Nodes that are in the found or contacted sets are filtered out. * @param nodeIdTarget * @param nodeIdSignaller */ queueNodeSignal(nodeIdTarget: NodeId, nodeIdSignaller: NodeId | undefined): void; queueNodeDirect(nodeIdTarget: NodeId, nodeContact: NodeContact): void; /** * Uses a bracketing pattern to track the resource * will wait for slot in the `rateLimit` to be free and run the function. * * It will not run the function and return with true under the following conditions * 1. The limit is reached. * 2. The queue is exausted and there are no pending connections. * 3. The function returned true indicating target was connected to */ withNodeSignal(f: (nodeIdTarget: NodeId, nodeIdSignaller: NodeId | undefined) => Promise, ctx: ContextCancellable): Promise; withNodeDirect(f: (nodeIdTarget: NodeId, nodeIdSignaller: NodeContact) => Promise, ctx: ContextCancellable): Promise; /** * Generic with node for shared code between direct and signal queues * @protected */ protected withNode(queue: Array<[NodeId, T]>, rateLimit: Semaphore, nodesRunning: Set>, f: (nodeIdTarget: NodeId, nodeIdSignaller: T) => Promise, ctx: ContextCancellable): Promise; contactedNode(nodeIdTarget: NodeId): void; /** * Resolves under the following conditions * 1. When the queue has an entry * 2. When all active and pending attempts have ended * 3. When the connection has been found */ protected waitForQueue(queue: Array, ctx: ContextCancellable): Promise; } export default NodeConnectionQueue;