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 🙏

© 2024 – Pkg Stats / Ryan Hefner

replication-simulator

v2.0.0

Published

Simulate network conditions for replicated data structures

Downloads

6

Readme

Replication Simulator

A module for simulating hyperswarm networks.

Usage

const RAM = require('random-access-memory')
const Autobase = require('@holepunchto/autobase-next')
const Hypercore = require('hypercore')
const { Replicator, Network } = require('replication-simulator')

const net = new Network()

const writer = new Hypercore(RAM.reusable())
await writer.ready()

const reader = new Hypercore(RAM.reusable(), { key: writer.key }),

const swarm1 = net.swarm()
const swarm2 = net.swarm()

swarm1.on('connection', conn => writer.replicate(conn))
swarm2.on('connection', conn => reader.replicate(conn))

await swarm1.join(writer.discoveryKey)
await swarm2.join(reader.discoveryKey)

await writer.append('0')

// ... wait for sync
console.log(reader.length) // 1

await net.down() // stop

await writer.append('1')

// ... wait for sync
console.log(reader.length) // 1

net.up() // resume

// ... wait for sync
console.log(reader.length) // 2

Swarm API

const swarm = Network.createSwarm(network)

Create a new swarm. If network is provided, the swarm shall be added to the network.

swarm.publicKey

Public key associated with this swarm, peers will always see connection.remotePublicKey as this value.

swarm.connections

Active connections.

swarm.join(topic)

Join a topic.

swarm.leave(topic)

Leave a topic.

swarm.disconnect()

Disconnect from all peers.

swarm.connect(peer)

Connect with a given peer (be sure to keep track of connections outside of networks...).

swarm.on('connection', stream => { ... })

Swarm emits a connection event with the stream.

swarm.hasPeer(remotePublicKey)

Check if the swarm is connected to a given peer.

Network API

A network is a set of bases that are all replicating with one another.

const network = new Network()

Create a network.

const swarm = network.swarm()

Create a new swarm within the network.

network.size

The number of bases in the network.

network.has(swarm)

Check if a base is in this network.

network.add(swarm)

Add a base to the network.

await network.delete(swarm)

Delete a base from the network.

network.clear()

Clear all peers from the network. Will not end any ongoing replication streams.

network.merge(otherNetwork)

Combine another network into this one.

const [left, right] await network.split(index)

Split a network into 2 at the given index.

netowrk.connect(swarm)

Ensure all the peers in the network are connected with swarm.

network.disconnect(base)

All peers in the network will disconnect with swarm.

If swarm is in the network, it will remain in the network and can be brought up again with network.up

network.up()

Ensure all peers in the network are connected.

network.down()

All peers in the network will disconnect.

network.destroy()

End all connections and clear the network.

License

MIT