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

@aimf/p2p

v0.1.1

Published

P2P Distribution Layer for AIMF using LibP2P

Readme

@aimf/p2p

P2P Distribution Layer for the AI-MCP Framework (AIMF).

Overview

This package provides peer-to-peer networking capabilities for distributed neural storage and data verification. It enables decentralized data replication, consensus-based verification, and peer discovery.

Features

  • P2P Node: Core networking node with peer connections and messaging
  • Replication Manager: Distributed data replication across peers
  • Consensus Manager: Consensus-based data verification
  • Discovery Manager: Peer discovery and reputation tracking

Installation

pnpm add @aimf/p2p

Usage

Creating a P2P Node

import { createP2PNode } from "@aimf/p2p";

const node = createP2PNode({
  maxConnections: 50,
  replicationFactor: 3,
});

await node.start();
console.log("Node ID:", node.getPeerId());
console.log("Addresses:", node.getAddresses());

// Connect to a peer
await node.connectToPeer("/ip4/127.0.0.1/tcp/4001/p2p/peer-id");

// Send a message
const message = node.createMessage("ping", { timestamp: Date.now() });
await node.sendMessage("peer-id", message);

// Store data locally
node.storeBlock({
  id: "block-1",
  data: new Uint8Array([1, 2, 3]),
  neuralHash: "hash1",
  cryptoHash: "hash2",
  timestamp: Date.now(),
  origin: node.getPeerId(),
  replicationCount: 0,
});

await node.stop();

Replicating Data

import { createP2PNode, createReplicationManager } from "@aimf/p2p";

const node = createP2PNode();
await node.start();

const replication = createReplicationManager(node, {
  targetReplicationFactor: 3,
  minReplicationFactor: 2,
});

// Store and replicate a block
const block = {
  id: "block-1",
  data: new Uint8Array([1, 2, 3]),
  neuralHash: "neural-hash",
  cryptoHash: "crypto-hash",
  timestamp: Date.now(),
  origin: node.getPeerId(),
  replicationCount: 0,
};

node.storeBlock(block);
const status = await replication.replicateBlock(block, "high");

console.log("Replicated to:", status.replicatedTo);
console.log("Replication factor:", replication.getReplicationFactor(block.id));

Consensus Verification

import { createP2PNode, createConsensusManager } from "@aimf/p2p";

const node = createP2PNode();
await node.start();

const consensus = createConsensusManager(node, {
  consensusThreshold: 0.66,
  minVerifiers: 3,
});

// Request verification from peers
const result = await consensus.requestVerification(block, 0.66);

console.log("Verified:", result.verified);
console.log("Consensus level:", result.consensusLevel);
console.log("Verifying peers:", result.verifyingPeers);

Peer Discovery

import { createP2PNode, createDiscoveryManager } from "@aimf/p2p";

const node = createP2PNode();
await node.start();

const discovery = createDiscoveryManager(node, {
  announceInterval: 30000,
  maxPeers: 50,
});

discovery.start();

// Get peer information
const activePeers = discovery.getActivePeers();
const verifiedPeers = discovery.getVerifiedPeers();
const bestPeers = discovery.findBestPeers(5);

// Update peer reputation
discovery.updateReputation("peer-id", 0.1);

discovery.stop();

Event Handling

node.on("peer:connect", (peer) => {
  console.log("Connected to:", peer.id);
});

node.on("peer:disconnect", (peer) => {
  console.log("Disconnected from:", peer.id);
});

node.on("data:stored", (block) => {
  console.log("Stored block:", block.id);
});

node.on("replication:complete", (status) => {
  console.log("Replication complete:", status.blockId);
});

node.on("verification:complete", (result) => {
  console.log("Verification result:", result.verified);
});

API Reference

P2PNode

  • createP2PNode(config?) - Create a new P2P node
  • start() - Start the node
  • stop() - Stop the node
  • connectToPeer(address) - Connect to a peer
  • disconnectFromPeer(peerId) - Disconnect from a peer
  • sendMessage(peerId, message) - Send a message
  • broadcast(message) - Broadcast to all peers
  • storeBlock(block) - Store a data block
  • getBlock(blockId) - Retrieve a block
  • on(event, handler) - Add event listener

ReplicationManager

  • createReplicationManager(node, config?) - Create manager
  • replicateBlock(block, priority?) - Replicate a block
  • getReplicationFactor(blockId) - Get replication count
  • isReplicationSatisfied(blockId) - Check if minimum replicas exist
  • getBlockLocations(blockId) - Get peers with the block

ConsensusManager

  • createConsensusManager(node, config?) - Create manager
  • requestVerification(block, threshold?) - Request consensus
  • verifyBlockLocally(blockId, hashes) - Verify locally
  • getVerificationHistory(blockId) - Get history
  • getStatistics() - Get verification statistics

DiscoveryManager

  • createDiscoveryManager(node, config?) - Create manager
  • start() - Start discovery
  • stop() - Stop discovery
  • getKnownPeers() - Get all known peers
  • getActivePeers() - Get recently active peers
  • findBestPeers(count) - Find highest reputation peers
  • updateReputation(peerId, delta) - Adjust reputation

Configuration

P2PConfig

interface P2PConfig {
  listenAddresses: string[];      // Addresses to listen on
  bootstrapPeers: string[];       // Initial peers to connect to
  enableMdns: boolean;            // Enable local discovery
  enableDht: boolean;             // Enable DHT
  dhtClientMode: boolean;         // DHT client mode only
  maxConnections: number;         // Max peer connections
  minConnections: number;         // Min peer connections
  connectionTimeout: number;      // Connection timeout (ms)
  replicationFactor: number;      // Target replicas
  consensusThreshold: number;     // Consensus threshold (0-1)
}

ReplicationConfig

interface ReplicationConfig {
  targetReplicationFactor: number;  // Target replicas
  minReplicationFactor: number;     // Minimum replicas
  replicationTimeout: number;       // Timeout (ms)
  retryAttempts: number;            // Retry count
  retryDelay: number;               // Retry delay (ms)
}

ConsensusConfig

interface ConsensusConfig {
  consensusThreshold: number;   // Required consensus (0-1)
  verificationTimeout: number;  // Timeout (ms)
  minVerifiers: number;         // Minimum verifiers
  maxVerifiers: number;         // Maximum verifiers
}

DiscoveryConfig

interface DiscoveryConfig {
  announceInterval: number;  // Announce interval (ms)
  peerTimeout: number;       // Peer timeout (ms)
  maxPeers: number;          // Max peers to track
  minPeers: number;          // Min peers to maintain
}

Protocol

The P2P layer uses the /aimf/neural/1.0.0 protocol for communication.

Message types:

  • store - Store data block
  • retrieve - Retrieve data block
  • verify - Request verification
  • replicate - Replicate data
  • ping / pong - Connectivity check
  • announce - Presence announcement

License

MIT