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

@dswarm/proxy

v1.0.0

Published

Proxy p2p connections using a duplex stream and dSwarm

Downloads

8

Readme

dswarm-proxy

Proxy p2p connections using a duplex stream and dSwarm

How it works

  • A server initializes an instance of dSwarm
  • A client opens a connection to the server (use any duplex stream)
  • Client instance behaves the same as dSwarm
  • The client asks to join "topics"
  • The server starts searching for peers and sends peer information to the client
  • The client chooses which peers to connect to (all of them by default)
  • The server establishes a connection to the peer and proxies it over to the client
  • The client can relay whatever data they want to the peer.

Server

const DSwarmProxyServer = require('@dswarm/proxy/server')

const server = new DSwarmProxyServer({
  // The bootstrap nodes to pass to dSwarm (optional)
  bootstrap,

  // Whether your server will be sort lived (ephemeral: true)
  ephemeral,

  // Pass in an existing dSwarm instance instead of creating a new one (optional)
  network,

  // Function that takes incoming connections to decide what to do with them
  // Can be used to notify clients about peers
  // Disconnect incoming by default
  handleIncoming: (socket) => socket.end(),
})

const somestream = getStreamForClient()

// Get the server to handle streams from clients
server.handleStream(somestream)

// Tell all clients about a peer for a particular topic
// This is useful in conjunction with `handleIncoming`
// Use handleIncoming to figure out which topic the connection is from
// Then tell clients to connect to them using `socket.address()`
server.connectClientsTo(SOME_TOPIC, port, hostname)

// Close connections to clients and any connected peers
server.destroy(() => {
  // Done!
})

Client

const DSwarmProxyClient = require('@dswarm/proxy/client')

const somestream = getStreamForServer()

const swarm = new DSwarmProxyClient({
  // Pass in the stream which connects to the server
  // If this isn't passed in, invoke `.reconnect(somestream)` to start connecting
  connection: somestream,

  // Whether you should autoconnect to peers
  autoconnect: true,

  // The max number of peers to connect to before stopping to autoconnect
  maxPeers: 24,
})

// When we disconnect, reconnect to the server
swarm.on('disconnected', () => {
  swarm.reconnect(getStreamForServer())
})

// Same as dSwarm
swarm.on('connection', (connection, info) => {

  const stream = getSomeStream(info.topic)
  // Pipe the data from the connection into something to process it
  // E.G. `ddrive.replicate()`
  connection.pipe(stream).pipe(connection)
})

swarm.join(topic)

swarm.leave(topic)

// Listen for peers manually
swarm.on('peer', (peer) => {
  // If autoconnect is `false` you can connect manually here
  swarm.connect(peer, (err, connection) => {
    // Wow
  })
})

// Destroy the swarm
swarm.destroy()