Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents a list of nodes for managing network peers activity

Hierarchy

  • EventEmitter
    • NodeList

Index

Constructors

constructor

Properties

Private aliasToPubKeyMap

aliasToPubKeyMap: Map<string, string> = new Map<string, string>()

A map of aliases to node pub keys.

Private nodeIdMap

nodeIdMap: Map<number, NodeInstance> = new Map<number, NodeInstance>()

A map of node ids to node instances.

Private nodes

nodes: Map<string, NodeInstance> = new Map<string, NodeInstance>()

A map of node pub keys to node instances.

Private pubKeyToAliasMap

pubKeyToAliasMap: Map<string, string> = new Map<string, string>()

A map of node pub keys to aliases.

Private repository

repository: P2PRepository

Static Private Readonly BAN_THRESHOLD

BAN_THRESHOLD: -50 = -50

Static Private Readonly MAX_REPUTATION_SCORE

MAX_REPUTATION_SCORE: 100 = 100

Static defaultMaxListeners

defaultMaxListeners: number

Static Readonly errorMonitor

errorMonitor: keyof symbol

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Accessors

count

  • get count(): number

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

Private addNode

addReputationEvent

  • addReputationEvent(nodePubKey: string, event: ReputationEvent): Promise<boolean>
  • Add a reputation event to the node's history

    Parameters

    Returns Promise<boolean>

    true if the specified node exists and the event was added, false otherwise

ban

  • ban(nodePubKey: string): Promise<boolean>
  • Ban a node by nodePubKey.

    Parameters

    • nodePubKey: string

    Returns Promise<boolean>

    true if the node was banned, false otherwise

createNode

emit

  • emit(event: "node.ban", nodePubKey: string, events: ReputationEvent[]): boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

forEach

get

getAlias

  • getAlias(nodePubKey: string): undefined | string
  • Get the alias for a given nodePubKey.

    Parameters

    • nodePubKey: string

    Returns undefined | string

getId

  • getId(nodePubKey: string): undefined | number

getMaxListeners

  • getMaxListeners(): number

Private getNegativeReputationEvents

  • Retrieves up to 10 of the most recent negative reputation events for a node from the repository.

    Parameters

    • node: NodeInstance

      the node for which to retrieve events

    • Optional newEvent: ReputationEvent

      a reputation event that hasn't been added to the repository yet

    Returns Promise<ReputationEvent[]>

getNodeById

getPubKeyForAlias

  • getPubKeyForAlias(alias: string): string

has

  • has(nodePubKey: string): boolean
  • Check if a node with a given nodePubKey exists.

    Parameters

    • nodePubKey: string

    Returns boolean

isBanned

  • isBanned(nodePubKey: string): boolean

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

load

  • load(): Promise<void>

off

  • off(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: "node.ban", listener: (nodePubKey: string, events: ReputationEvent[]) => void): this

once

  • once(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAddress

  • removeAddress(nodePubKey: string, address: Address): Promise<boolean>

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

Private setBanStatus

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

unBan

  • unBan(nodePubKey: string): Promise<boolean>
  • Remove ban from node by nodePubKey.

    Parameters

    • nodePubKey: string

    Returns Promise<boolean>

    true if ban was removed, false otherwise

updateAddresses

  • updateAddresses(nodePubKey: string, addresses?: Address[], lastAddress?: Address): Promise<boolean>
  • Update a node's addresses.

    Parameters

    • nodePubKey: string
    • Default value addresses: Address[] = []
    • Optional lastAddress: Address

    Returns Promise<boolean>

    true if the specified node exists and was updated, false otherwise

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Static Private updateReputationScore

Generated using TypeDoc