mirror of https://codeberg.org/pzp/pzp-net.git
Rename to pzp and asycify
This commit is contained in:
parent
5b79b9566b
commit
b1de4f6250
|
@ -1,25 +0,0 @@
|
|||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x, 20.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm install
|
||||
- run: npm test
|
|
@ -0,0 +1,13 @@
|
|||
matrix:
|
||||
NODE_VERSION:
|
||||
- 18
|
||||
- 20
|
||||
|
||||
steps:
|
||||
test:
|
||||
when:
|
||||
event: [push]
|
||||
image: node:${NODE_VERSION}
|
||||
commands:
|
||||
- npm install
|
||||
- npm test
|
12
README.md
12
README.md
|
@ -1,14 +1,14 @@
|
|||
**Work in progress**
|
||||
# pzp-net
|
||||
|
||||
PZP plugin to manage connections with hubs and peers
|
||||
|
||||
## Installation
|
||||
|
||||
We're not on npm yet. In your package.json, include this as
|
||||
|
||||
```js
|
||||
"ppppp-net": "github:staltz/ppppp-net"
|
||||
```
|
||||
npm install pzp-net
|
||||
```
|
||||
|
||||
**TODO:**
|
||||
## **TODO:**
|
||||
|
||||
- [x] connect
|
||||
- [x] stage
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const debug = require('debug')('ppppp:net:connections')
|
||||
const debug = require('debug')('pzp:net:connections')
|
||||
const createNotify = require('pull-notify')
|
||||
const run = require('promisify-tuple')
|
||||
const IP = require('ip')
|
||||
|
|
|
@ -91,7 +91,7 @@ function initNet(peer, config) {
|
|||
async function start() {
|
||||
await stats.loaded()
|
||||
glue(infos, connections)
|
||||
queueMicrotask(scheduler.start.bind(scheduler))
|
||||
queueMicrotask(() => scheduler.start.bind(scheduler))
|
||||
}
|
||||
|
||||
function stop() {
|
||||
|
|
|
@ -1,22 +1,30 @@
|
|||
const awaitable = require('pull-awaitable')
|
||||
const run = require('promisify-tuple')
|
||||
const debug = require('debug')('ppppp:net:scheduler')
|
||||
const debug = require('debug')('pzp:net:scheduler')
|
||||
|
||||
/**
|
||||
* @typedef {ReturnType<import('ppppp-db').init>} PPPPPDB
|
||||
* @typedef {ReturnType<import('ppppp-set').init>} PPPPPSet
|
||||
* @typedef {ReturnType<import('pzp-db').init>} PZPDB
|
||||
* @typedef {ReturnType<import('pzp-set').init>} PZPSet
|
||||
* @typedef {`/${string}`} Multiaddr
|
||||
* @typedef {import('./infos')} Infos
|
||||
* @typedef {import('./connections')} Connections
|
||||
* @typedef {{
|
||||
* db?: PPPPPDB;
|
||||
* set?: PPPPPSet;
|
||||
* db?: PZPDB;
|
||||
* set?: PZPSet;
|
||||
* shse: {
|
||||
* pubkey: string;
|
||||
* }
|
||||
* }} Peer
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @typedef {[T] extends [void] ?
|
||||
* (...args: [Error] | []) => void :
|
||||
* (...args: [Error] | [null, T]) => void
|
||||
* } CB
|
||||
*/
|
||||
|
||||
class Scheduler {
|
||||
/** @type {Peer} */
|
||||
#peer
|
||||
|
@ -62,25 +70,34 @@ class Scheduler {
|
|||
}
|
||||
}
|
||||
|
||||
#setupHubDiscovery() {
|
||||
/** @type {Array<Multiaddr> | undefined} */
|
||||
const multiaddrs = this.#peer.set?.values('hubs')
|
||||
if (!multiaddrs) return
|
||||
for (const multiaddr of multiaddrs) {
|
||||
this.#scheduleWithHub(multiaddr)
|
||||
}
|
||||
// @ts-ignore
|
||||
const stopWatch = this.#peer.set?.watch(({subdomain, event, value}) => {
|
||||
if (subdomain === 'hubs' && event === 'add') {
|
||||
this.#scheduleWithHub(value)
|
||||
/**
|
||||
* @param {CB<void>} cb
|
||||
*/
|
||||
#setupHubDiscovery(cb) {
|
||||
this.#peer.set?.values('hubs', null, (err, /** @type {Array<Multiaddr> | undefined} */ multiaddrs) => {
|
||||
if (err) return cb(err)
|
||||
|
||||
if (!multiaddrs) return cb()
|
||||
for (const multiaddr of multiaddrs) {
|
||||
this.#scheduleWithHub(multiaddr)
|
||||
}
|
||||
});
|
||||
// @ts-ignore
|
||||
const stopWatch = this.#peer.set?.watch(({subdomain, event, value}) => {
|
||||
if (subdomain === 'hubs' && event === 'add') {
|
||||
this.#scheduleWithHub(value)
|
||||
}
|
||||
});
|
||||
cb()
|
||||
})
|
||||
}
|
||||
|
||||
start() {
|
||||
/**
|
||||
* @param {CB<void>} cb
|
||||
*/
|
||||
start(cb) {
|
||||
if (!this.#closed) return
|
||||
this.#closed = false
|
||||
this.#setupHubDiscovery();
|
||||
this.#setupHubDiscovery(cb);
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const Path = require('path')
|
||||
const FS = require('fs')
|
||||
const debug = require('debug')('ppppp:net:stats')
|
||||
const debug = require('debug')('pzp:net:stats')
|
||||
const atomic = require('atomic-file-rw')
|
||||
|
||||
/**
|
||||
|
@ -56,13 +56,13 @@ const SelfHealingJSONCodec = {
|
|||
if (!foundCorruption) {
|
||||
foundCorruption = true
|
||||
// prettier-ignore
|
||||
console.warn(`WARNING: ppppp-net found a corrupted ${Stats.FILENAME} file and is attempting to heal it`)
|
||||
console.warn(`WARNING: pzp-net found a corrupted ${Stats.FILENAME} file and is attempting to heal it`)
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
console.error(
|
||||
`ERROR! ppppp-net failed to heal corrupted ${Stats.FILENAME} file`
|
||||
`ERROR! pzp-net failed to heal corrupted ${Stats.FILENAME} file`
|
||||
)
|
||||
return {}
|
||||
},
|
||||
|
|
21
package.json
21
package.json
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"name": "ppppp-net",
|
||||
"version": "1.0.0",
|
||||
"description": "PPPPP plugin to manage connections with hubs and peers",
|
||||
"name": "pzp-net",
|
||||
"version": "0.0.1",
|
||||
"description": "PZP plugin to manage connections with hubs and peers",
|
||||
"author": "Andre Staltz <contact@staltz.com>",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/staltz/ppppp-net",
|
||||
"homepage": "https://codeberg.org/pzp/pzp-net",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:staltz/ppppp-net.git"
|
||||
"url": "git@codeberg.org:pzp/pzp-net.git"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"files": [
|
||||
|
@ -41,8 +41,7 @@
|
|||
"pull-pause": "~0.0.2",
|
||||
"pull-ping": "^2.0.3",
|
||||
"pull-stream": "^3.6.14",
|
||||
"statistics": "^3.3.0",
|
||||
"ziii": "~1.0.2"
|
||||
"statistics": "^3.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/debug": "^4.1.12",
|
||||
|
@ -50,10 +49,10 @@
|
|||
"@types/node": "18",
|
||||
"bs58": "^5.0.0",
|
||||
"c8": "7",
|
||||
"ppppp-caps": "github:staltz/ppppp-caps#93fa810b9a40b78aef4872d4c2a8412cccb52929",
|
||||
"ppppp-db": "github:staltz/ppppp-db#667b33779d98aff12a9b0cd2d7c80469a95cd04e",
|
||||
"ppppp-keypair": "github:staltz/ppppp-keypair#61ef4420578f450dc2cc7b1efc1c5a691a871c74",
|
||||
"ppppp-set": "github:staltz/ppppp-set#8983ba29f03db95a76b4bd9a55aa4392b350fdbb",
|
||||
"pzp-caps": "^1.0.0",
|
||||
"pzp-db": "^1.0.1",
|
||||
"pzp-keypair": "^1.0.0",
|
||||
"pzp-set": "^1.0.0",
|
||||
"prettier": "^2.6.2",
|
||||
"pretty-quick": "^3.1.3",
|
||||
"rimraf": "^4.4.0",
|
||||
|
|
|
@ -2,8 +2,8 @@ const OS = require('node:os')
|
|||
const FS = require('node:fs')
|
||||
const Path = require('node:path')
|
||||
const rimraf = require('rimraf')
|
||||
const caps = require('ppppp-caps')
|
||||
const Keypair = require('ppppp-keypair')
|
||||
const caps = require('pzp-caps')
|
||||
const Keypair = require('pzp-keypair')
|
||||
const net = require('../lib/index')
|
||||
|
||||
function createPeer(config) {
|
||||
|
@ -11,7 +11,7 @@ function createPeer(config) {
|
|||
const name = config.name
|
||||
const tmp = OS.tmpdir()
|
||||
config.global ??= {}
|
||||
config.global.path ??= Path.join(tmp, `ppppp-net-${name}-${Date.now()}`)
|
||||
config.global.path ??= Path.join(tmp, `pzp-net-${name}-${Date.now()}`)
|
||||
config.global.keypair ??= Keypair.generate('ed25519', name)
|
||||
delete config.name
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ function createPeer(config) {
|
|||
}
|
||||
|
||||
function createPeerMock() {
|
||||
const testPath = FS.mkdtempSync(Path.join(OS.tmpdir(), 'ppppp-net-'))
|
||||
const testPath = FS.mkdtempSync(Path.join(OS.tmpdir(), 'pzp-net-'))
|
||||
|
||||
const mockPeer = {
|
||||
addListener() {},
|
||||
|
|
Loading…
Reference in New Issue