npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ts-drp/interval-discovery

v0.11.0

Published

The DRP Interval Discovery system is a crucial component of the Distributed Resource Protocol (DRP) that enables peer discovery and connection maintenance between nodes sharing the same object IDs.

Downloads

3

Readme

DRP Interval Discovery

The DRP Interval Discovery system is a crucial component of the Distributed Resource Protocol (DRP) that enables peer discovery and connection maintenance between nodes sharing the same object IDs.

Overview

The interval discovery mechanism ensures that nodes with shared object IDs can:

  • Discover each other on the network
  • Maintain connections with peers
  • Handle peer discovery and connection establishment gracefully

Architecture

The interval discovery system consists of three main components:

  • DRPIntervalDiscovery: Manages the discovery process for a specific object ID
  • IntervalRunner: Handles the periodic execution of discovery tasks
  • NetworkNode: Handles P2P communication between nodes

Sequence Diagram

The following sequence diagram illustrates the discovery process:

sequenceDiagram
    box Node A
    participant Node_A_DRPIntervalDiscovery
    participant Node_A_NetworkNode
    end

    box Node B
    participant Node_B_NetworkNode
    participant Node_B_DRPIntervalDiscovery
    end

    Note over Node_A_DRPIntervalDiscovery: start() called

    loop Every interval
        Node_A_DRPIntervalDiscovery->>Node_A_NetworkNode: getGroupPeers(objectId)

        alt No peers found for objectId
            Note over Node_A_DRPIntervalDiscovery: Start search timer
            Node_A_DRPIntervalDiscovery->>Node_A_NetworkNode: broadcastMessage(DRP_INTERVAL_DISCOVERY_TOPIC)
            Node_A_NetworkNode-->>Node_B_NetworkNode: DRPDiscoveryRequest message

            alt Node B has matching objectId
                Note over Node_B_DRPIntervalDiscovery: handleDiscoveryRequest
                Node_B_DRPIntervalDiscovery->>Node_B_NetworkNode: getGroupPeers(objectId)
                Node_B_DRPIntervalDiscovery->>Node_B_NetworkNode: sendMessage(DRPDiscoveryResponse)
                Node_B_NetworkNode-->>Node_A_NetworkNode: DRPDiscoveryResponse
                Note over Node_A_NetworkNode: Contains peer multiaddrs
                Node_A_NetworkNode-->>Node_A_DRPIntervalDiscovery: handleDiscoveryResponse
                Node_A_DRPIntervalDiscovery->>Node_A_NetworkNode: connect(peer_multiaddrs)
            end
        else Peers found
            Note over Node_A_DRPIntervalDiscovery: Reset search timer
            Note over Node_A_DRPIntervalDiscovery: Skip discovery
        end
    end

    Note over Node_A_DRPIntervalDiscovery: stop() called
    Note over Node_A_DRPIntervalDiscovery: Clear interval timer

Configuration

The interval discovery system can be configured with the following options:

interface DRPIntervalDiscoveryOptions {
	/** Unique identifier for the object */
	readonly id: string;
	/** Network node instance used for peer communication */
	readonly networkNode: DRPNetworkNode;
	/** Interval in milliseconds between discovery attempts. Defaults to 10,000ms */
	readonly interval?: number;
	/** Logger configuration options */
	readonly logConfig?: LoggerOptions;
	/** Duration in milliseconds to search for peers before giving up. Defaults to 5 minutes */
	readonly searchDuration?: number;
}

Key Features

  1. Periodic Discovery Checks

    • Default interval: 10 seconds
    • Configurable through interval option
  2. Peer Discovery

    • Broadcasts discovery messages when no peers are found
    • Uses DRP_INTERVAL_DISCOVERY_TOPIC for discovery messages
    • Includes object ID for targeted peer matching
  3. Connection Management

    • Automatically connects to discovered peers
    • Maintains connections with active peers
    • Handles peer multiaddress information
  4. Search Duration

    • Default duration: 5 minutes
    • Configurable through searchDuration option
    • Prevents indefinite searching for unavailable peers

Usage

import { createDRPDiscovery } from "@ts-drp/interval-discovery";

// Create a new discovery instance
const discovery = createDRPDiscovery({
	id: "unique-object-id",
	networkNode: networkNode,
	interval: 10000, // 10 seconds
	searchDuration: 300000, // 5 minutes
});

// Start the discovery process
discovery.start();

// Stop the discovery process when done
discovery.stop();

Message Types

The discovery system uses two main message types:

  1. DRPDiscoveryRequest

    • Broadcast to discover peers
    • Contains the object ID being searched for
  2. DRPDiscoveryResponse

    • Sent in response to discovery messages
    • Contains peer multiaddresses for connection establishment
    • Includes subscriber information for all peers sharing the object ID

Error Handling

The discovery system includes:

  • Logging of failed peer discoveries and connections
  • Automatic retry mechanism within search duration