xud
Version:
Exchange Union Daemon
97 lines (96 loc) • 3.53 kB
TypeScript
/// <reference types="node" />
import { EventEmitter } from 'events';
import { ReputationEvent } from '../constants/enums';
import { NodeCreationAttributes, NodeInstance } from '../db/types';
import P2PRepository from './P2PRepository';
import { Address } from './types';
export declare const reputationEventWeight: {
0: number;
1: number;
2: number;
6: number;
5: number;
3: number;
4: number;
7: number;
8: number;
9: number;
10: number;
};
interface NodeList {
on(event: 'node.ban', listener: (nodePubKey: string, events: ReputationEvent[]) => void): this;
emit(event: 'node.ban', nodePubKey: string, events: ReputationEvent[]): boolean;
}
/** Represents a list of nodes for managing network peers activity */
declare class NodeList extends EventEmitter {
private repository;
/** A map of node pub keys to node instances. */
private nodes;
/** A map of node ids to node instances. */
private nodeIdMap;
/** A map of node pub keys to aliases. */
private pubKeyToAliasMap;
/** A map of aliases to node pub keys. */
private aliasToPubKeyMap;
private static readonly BAN_THRESHOLD;
private static readonly MAX_REPUTATION_SCORE;
get count(): number;
constructor(repository: P2PRepository);
private static updateReputationScore;
/**
* Check if a node with a given nodePubKey exists.
*/
has: (nodePubKey: string) => boolean;
forEach: (callback: (node: NodeInstance) => void) => void;
/**
* Get the internal node id for a given nodePubKey.
*/
getNodeById: (nodeId: number) => NodeInstance | undefined;
/**
* Get the alias for a given nodePubKey.
*/
getAlias: (nodePubKey: string) => string | undefined;
getId: (nodePubKey: string) => number | undefined;
get: (nodePubKey: string) => NodeInstance | undefined;
getPubKeyForAlias: (alias: string) => string;
/**
* Ban a node by nodePubKey.
* @returns true if the node was banned, false otherwise
*/
ban: (nodePubKey: string) => Promise<boolean>;
/**
* Remove ban from node by nodePubKey.
* @returns true if ban was removed, false otherwise
*/
unBan: (nodePubKey: string) => Promise<boolean>;
isBanned: (nodePubKey: string) => boolean;
/**
* Load this NodeList from the database.
*/
load: () => Promise<void>;
/**
* Persists a node to the database and adds it to the node list.
*/
createNode: (nodeCreationAttributes: NodeCreationAttributes) => Promise<void>;
/**
* Update a node's addresses.
* @return true if the specified node exists and was updated, false otherwise
*/
updateAddresses: (nodePubKey: string, addresses?: Address[], lastAddress?: Address | undefined) => Promise<boolean>;
/**
* Retrieves up to 10 of the most recent negative reputation events for a node
* from the repository.
* @param node the node for which to retrieve events
* @param newEvent a reputation event that hasn't been added to the repository yet
*/
private getNegativeReputationEvents;
/**
* Add a reputation event to the node's history
* @return true if the specified node exists and the event was added, false otherwise
*/
addReputationEvent: (nodePubKey: string, event: ReputationEvent) => Promise<boolean>;
removeAddress: (nodePubKey: string, address: Address) => Promise<boolean>;
private setBanStatus;
private addNode;
}
export default NodeList;