{"id":15467905,"url":"https://github.com/rangermauve/hyperswarm-proxy","last_synced_at":"2026-02-13T20:02:03.776Z","repository":{"id":43831064,"uuid":"201979695","full_name":"RangerMauve/hyperswarm-proxy","owner":"RangerMauve","description":"Proxy p2p connections using a duplex stream and Hyperswarm","archived":false,"fork":false,"pushed_at":"2022-03-01T02:05:31.000Z","size":33,"stargazers_count":30,"open_issues_count":1,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-30T17:05:42.560Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RangerMauve.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-12T17:40:51.000Z","updated_at":"2025-01-08T15:55:58.000Z","dependencies_parsed_at":"2022-08-24T06:40:25.077Z","dependency_job_id":null,"html_url":"https://github.com/RangerMauve/hyperswarm-proxy","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RangerMauve%2Fhyperswarm-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RangerMauve%2Fhyperswarm-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RangerMauve%2Fhyperswarm-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RangerMauve%2Fhyperswarm-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RangerMauve","download_url":"https://codeload.github.com/RangerMauve/hyperswarm-proxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251748946,"owners_count":21637418,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T01:30:18.756Z","updated_at":"2026-02-13T20:01:58.738Z","avatar_url":"https://github.com/RangerMauve.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hyperswarm-proxy\nProxy p2p connections using a duplex stream and Hyperswarm\n\n## How it works\n\n- A server initializes an instance of [hyperswarm](https://github.com/hyperswarm/hyperswarm)\n- A client opens a connection to the server (use any duplex stream)\n- Client instance behaves the same as hyperswarm\n- The client asks to join \"topics\"\n- The server starts searching for peers and sends peer information to the client\n- The client chooses which peers to connect to (all of them by default)\n- The server establishes a connection to the peer and proxies it over to the client\n- The client can relay whatever data they want to the peer.\n\n## Server\n\n```js\nconst HyperswarmProxyServer = require('hyperswarm-proxy/server')\n\nconst server = new HyperswarmProxyServer({\n  // The bootstrap nodes to pass to hyperswarm (optional)\n  bootstrap,\n\n  // Whether your server will be sort lived (ephemeral: true)\n  ephemeral,\n\n  // Pass in an existing hyperswarm instance instead of creating a new one (optional)\n  network,\n\n  // Function that takes incoming connections to decide what to do with them\n  // Can be used to notify clients about peers\n  // Disconnect incoming by default\n  handleIncoming: (socket) =\u003e socket.end(),\n})\n\nconst somestream = getStreamForClient()\n\n// Get the server to handle streams from clients\nserver.handleStream(somestream)\n\n// Tell all clients about a peer for a particular topic\n// This is useful in conjunction with `handleIncoming`\n// Use handleIncoming to figure out which topic the connection is from\n// Then tell clients to connect to them using `socket.address()`\nserver.connectClientsTo(SOME_TOPIC, port, hostname)\n\n// Close connections to clients and any connected peers\nserver.destroy(() =\u003e {\n  // Done!\n})\n```\n\n## Client\n\n```js\nconst HyperswarmProxyClient = require('hyperswarm-proxy/client')\n\nconst somestream = getStreamForServer()\n\nconst swarm = new HyperswarmProxyClient({\n  // Pass in the stream which connects to the server\n  // If this isn't passed in, invoke `.reconnect(somestream)` to start connecting\n  connection: somestream,\n\n  // Whether you should autoconnect to peers\n  autoconnect: true,\n\n  // The max number of peers to connect to before stopping to autoconnect\n  maxPeers: 24,\n})\n\n// When we disconnect, reconnect to the server\nswarm.on('disconnected', () =\u003e {\n  swarm.reconnect(getStreamForServer())\n})\n\n// Same as hyperswarm\nswarm.on('connection', (connection, info) =\u003e {\n\n  const stream = getSomeStream(info.topic)\n  // Pipe the data from the connection into something to process it\n  // E.G. `hyperdrive.replicate()`\n  connection.pipe(stream).pipe(connection)\n})\n\nswarm.join(topic)\n\nswarm.leave(topic)\n\n// Listen for peers manually\nswarm.on('peer', (peer) =\u003e {\n  // If autoconnect is `false` you can connect manually here\n  swarm.connect(peer, (err, connection) =\u003e {\n    // Wow\n  })\n})\n\n// Destroy the swarm\nswarm.destroy()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frangermauve%2Fhyperswarm-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frangermauve%2Fhyperswarm-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frangermauve%2Fhyperswarm-proxy/lists"}