{"id":36603956,"url":"https://github.com/hypercore-protocol/corestore-networker","last_synced_at":"2026-01-12T08:41:51.696Z","repository":{"id":42525727,"uuid":"186587651","full_name":"hypercore-protocol/corestore-networker","owner":"hypercore-protocol","description":"A corestore networking module that uses hyperswarm.","archived":false,"fork":false,"pushed_at":"2023-03-07T04:31:34.000Z","size":204,"stargazers_count":39,"open_issues_count":9,"forks_count":14,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-10-17T04:19:45.123Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/hypercore-protocol.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-14T09:16:01.000Z","updated_at":"2025-08-15T09:35:24.000Z","dependencies_parsed_at":"2024-06-18T18:30:41.503Z","dependency_job_id":null,"html_url":"https://github.com/hypercore-protocol/corestore-networker","commit_stats":null,"previous_names":["andrewosh/corestore-swarm-networking","andrewosh/megastore-swarm-networking","andrewosh/corestore-networker"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/hypercore-protocol/corestore-networker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercore-protocol%2Fcorestore-networker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercore-protocol%2Fcorestore-networker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercore-protocol%2Fcorestore-networker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercore-protocol%2Fcorestore-networker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hypercore-protocol","download_url":"https://codeload.github.com/hypercore-protocol/corestore-networker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercore-protocol%2Fcorestore-networker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28337599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T06:09:07.588Z","status":"ssl_error","status_checked_at":"2026-01-12T06:05:18.301Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-01-12T08:41:51.108Z","updated_at":"2026-01-12T08:41:51.689Z","avatar_url":"https://github.com/hypercore-protocol.png","language":"JavaScript","readme":"# `@corestore/networker`\n[![Build Status](https://travis-ci.com/andrewosh/corestore-networker.svg?branch=master)](https://travis-ci.com/andrewosh/corestore-networker)\n\nA corestore networking module that uses [hyperswarm](https://github.com/hyperswarm/network) to discovery peers. This module powers the networking portion of the [Hyperspace](https://github.com/hyperspace-org/hyperspace).\n\nCalls to `configure` will not be persisted across restarts, so you'll need to use a separate database that maps discovery keys to network configurations. The Hyperdrive daemon uses [Level](https://github.com/level/level) for this.\n\nSince corestore has an all-to-all replication model (any shared cores between two peers will be automatically replicated), only one connection needs to be maintained per peer. If multiple connections are opened to a single peer as a result of that peer announcing many keys, then these connections will be automatically deduplicated by comparing NOISE keypairs.\n\n### Upgrading from corestore-swarm-networking\nThis module's going through a major change + a rename as part of our push to develop [Hyperspace](https://github.com/hyperspace-org/hyperspace). With these updates, `@corestore/networker` and Hyperspace's `network` APIs are now interchangeable! \n\nIf you've previously been using `corestore-swarm-networking` and you'd like to upgrade, [`UPGRADE.md`](https://github.com/andrewosh/corestore-swarm-networking/blob/master/UPGRADE.md) explains the changes.\n\n### Installation\n```\nnpm i @corestore/networker\n```\n\n### Usage\n```js\nconst Networker = require('@corestore/networker')\nconst Corestore = require('corestore')\nconst ram = require('random-access-memory')\n\nconst store = new Corestore(ram)\nawait store.ready()\n\nconst networker = new Networker(store)\n\n// Start announcing or lookup up a discovery key on the DHT.\nawait networker.configure(discoveryKey, { announce: true, lookup: true })\n\n// Stop announcing or looking up a discovery key.\nnetworker.configure(discoveryKey, { announce: false, lookup: false })\n\n// Shut down the swarm (and unnanounce all keys)\nawait networker.close()\n```\n\n### API\n\n#### `const networker = new Networker(corestore, networkingOptions = {})`\nCreates a new SwarmNetworker that will open replication streams on the `corestore` instance argument.\n\n`networkOpts` is an options map that can include all [hyperswarm](https://github.com/hyperswarm/hyperswarm) options (which will be passed to the internal swarm instance) as well as:\n```js\n{\n  id: crypto.randomBytes(32), // A randomly-generated peer ID,\n  keyPair: HypercoreProtocol.keyPair(), // A NOISE keypair that's used across all connections.\n  onauthenticate: (remotePublicKey, cb) =\u003e { cb() }, // A NOISE keypair authentication hook\n  swarm: hyperswarm(), // A hyperswarm instance to use (e.g., hyperswarm-web in the browser)\n}\n```\n\n#### `networker.peers`\nThe list of currently-connected peers. Each Peer object has the form:\n```\n{\n  remotePublicKey: 0xabc..., // The remote peer's NOISE key.\n  remoteAddress: '10.23.4...:8080', // The remote peer's host/port.\n  type: 'tcp' | 'utp', // The connection type\n  stream // The connection's HypercoreProtocol stream\n}\n```\n\n#### `networker.on('peer-add', peer)`\nEmitted when a new connection has been established with `peer`.\n\n#### `networker.on('peer-remove', peer)`\nEmitted when `peer`'s connection has been closed.\n\n#### `await networker.configure(discoveryKey, opts = {})`\nJoin or leave the swarm with the `discoveryKey` argument as the topic.\n\nIf this is the first time `configure` has been called, the swarm instance will be created automatically.\n\nWaits for the topic to be fully joined/left before resolving.\n\n`opts` is an options map of network configuration options that can include:\n```js\n  announce: true, // Announce the discovery key on the swarm\n  lookup: true  // Look up the discovery key on the swarm,\n  flush: true // Wait for a complete swarm flush before resolving.\n```\n\n#### `networker.joined(discoveryKey)`\nReturns `true` if that discovery key is being swarmed.\n\n#### `networker.flushed(discoveryKey)`\nReturns true if the swarm has discovered and attempted to connect to all peers announcing `discoveryKey`.\n\n#### `networker.listen()`\nStarts listening for connections on Hyperswarm's default port.\n\nThis is called automatically before the first call to `configure`.\n\n#### `await networker.close()`\nShut down the swarm networker.\n\nThis will close all replication streams and then destroy the swarm instance. It will wait for all topics to be unannounced, so it might take some time.\n\n### Swarm Extensions\n`@corestore/networker` introduces stream-level extensions that operate on each connection. They adhere to Hypercore's [extension API](https://github.com/hypercore-protocol/hypercore#ext--feedregisterextensionname-handlers).\n\n#### `const ext = await networker.registerExtension(name, { encoding, onmessage, onerror })`\nRegisters an extension with name `name`.\n\nThe `onmessage` and `onerror` handlers are both optional methods. `onerror` is an errback, and `onmessage` must have the signature:\n\n```js\nfunction onmessage (msg, peer) {\n  // `msg` is the (optionally-decoded) message that was received from `peer`.\n  // `peer` is a `Peer` object (described above in `networker.peers`)\n}\n```\n\n#### `ext.send(msg, peer)`\nSend `msg` (which will optionally be encoded by the extension's encoding opt) to `peer`. `peer` must be a Peer object taken from `networker.peers` or emitted by the networker's `peer-add` event.\n\n#### `ext.broadcast(msg)`\nBroadcast `msg` to all currently-connected peers.\n\n#### `ext.destroy()`\nDestroy the extension and unregister it from all connections.\n\n### License\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypercore-protocol%2Fcorestore-networker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhypercore-protocol%2Fcorestore-networker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypercore-protocol%2Fcorestore-networker/lists"}