-
Notifications
You must be signed in to change notification settings - Fork 481
chore: add typedefs #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add typedefs #802
Changes from all commits
26c40c8
7e05c4a
28b9f85
4b309ad
149c19a
d3d6b35
89fd524
2109ef0
32dd055
a5f5160
77a0257
55910c8
1992609
9b863bd
b221e97
9966c6c
aa98bc2
f568f16
ed2d10a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: ci | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: yarn | ||
- run: yarn lint | ||
- uses: gozala/[email protected] | ||
- run: yarn build | ||
- run: yarn aegir dep-check | ||
- uses: ipfs/aegir/actions/bundle-size@master | ||
name: size | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
test-node: | ||
needs: check | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [windows-latest, ubuntu-latest, macos-latest] | ||
node: [12, 14] | ||
fail-fast: true | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- run: yarn | ||
- run: npx nyc --reporter=lcov aegir test -t node -- --bail | ||
- uses: codecov/codecov-action@v1 | ||
test-chrome: | ||
needs: check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: yarn | ||
- run: npx aegir test -t browser -t webworker --bail | ||
test-firefox: | ||
needs: check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: yarn | ||
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless | ||
test-interop: | ||
needs: check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: yarn | ||
- run: cd node_modules/interop-libp2p && yarn && LIBP2P_JS=${GITHUB_WORKSPACE}/src/index.js npx aegir test -t node --bail | ||
test-auto-relay-example: | ||
needs: check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: yarn | ||
- run: cd examples && yarn && npm run test -- auto-relay |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,15 @@ | |
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack", | ||
"leadMaintainer": "Jacob Heun <[email protected]>", | ||
"main": "src/index.js", | ||
"types": "dist/src/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"src/*": [ | ||
"dist/src/*", | ||
"dist/src/*/index" | ||
] | ||
} | ||
}, | ||
"files": [ | ||
"dist", | ||
"src" | ||
|
@@ -53,15 +62,15 @@ | |
"events": "^3.1.0", | ||
"hashlru": "^2.3.0", | ||
"interface-datastore": "^2.0.0", | ||
"ipfs-utils": "^2.2.0", | ||
"ipfs-utils": "^5.0.1", | ||
"it-all": "^1.0.1", | ||
"it-buffer": "^0.1.2", | ||
"it-handshake": "^1.0.1", | ||
"it-length-prefixed": "^3.0.1", | ||
"it-pipe": "^1.1.0", | ||
"it-protocol-buffers": "^0.2.0", | ||
"libp2p-crypto": "^0.18.0", | ||
"libp2p-interfaces": "^0.7.2", | ||
"libp2p-interfaces": "^0.8.0", | ||
"libp2p-utils": "^0.2.2", | ||
"mafmt": "^8.0.0", | ||
"merge-options": "^2.0.0", | ||
|
@@ -88,7 +97,7 @@ | |
"devDependencies": { | ||
"@nodeutils/defaults-deep": "^1.1.0", | ||
"abortable-iterator": "^3.0.0", | ||
"aegir": "^27.0.0", | ||
"aegir": "^29.2.0", | ||
"chai-bytes": "^0.1.2", | ||
"chai-string": "^1.5.0", | ||
"delay": "^4.3.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
'use strict' | ||
|
||
const debug = require('debug') | ||
const log = debug('libp2p:auto-relay') | ||
log.error = debug('libp2p:auto-relay:error') | ||
const log = Object.assign(debug('libp2p:auto-relay'), { | ||
error: debug('libp2p:auto-relay:err') | ||
}) | ||
|
||
const uint8ArrayFromString = require('uint8arrays/from-string') | ||
const uint8ArrayToString = require('uint8arrays/to-string') | ||
|
@@ -19,14 +20,25 @@ const { | |
RELAY_RENDEZVOUS_NS | ||
} = require('./constants') | ||
|
||
/** | ||
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection | ||
* @typedef {import('../peer-store/address-book').Address} Address | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} AutoRelayProperties | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: In js-ipfs we settled on calling injected deps with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably mentioning in the one below, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bo I was referring to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to get a good way for here. So, in the libp2p stand point we have lots of places where we inject libp2p, or some libp2p components on other libp2p components. Moreover, these libp2p components have configurations that users can modify. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe The reason I end up calling those config in js-ipfs is because it is configuration of the component. It is true that user can't modify those but who ever creates a component can provide alternative configuration e.g. in memory repo vs on disk repo etc... Things that user can configure are referred as I don't have strong feeling about naming convention itself, just would love to settle on the same convention across ipfs and libp2p There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Components seems a good alternative. Will wait for other people to weight in before renaming everywhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t think we should block this due to naming convention. Lets just have a separate discussion thread somewhere instead and we can always come back and rename things. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I agree. But let's keep the discussion open until hugo/jacob comments |
||
* @property {import('../')} libp2p | ||
* | ||
* @typedef {Object} AutoRelayOptions | ||
* @property {number} [maxListeners = 1] - maximum number of relays to listen. | ||
*/ | ||
|
||
class AutoRelay { | ||
/** | ||
* Creates an instance of AutoRelay. | ||
* | ||
* @class | ||
* @param {object} props | ||
* @param {Libp2p} props.libp2p | ||
* @param {number} [props.maxListeners = 1] - maximum number of relays to listen. | ||
* @param {AutoRelayProperties & AutoRelayOptions} props | ||
*/ | ||
constructor ({ libp2p, maxListeners = 1 }) { | ||
this._libp2p = libp2p | ||
|
@@ -58,7 +70,7 @@ class AutoRelay { | |
* | ||
* @param {Object} props | ||
* @param {PeerId} props.peerId | ||
* @param {Array<string>} props.protocols | ||
* @param {string[]} props.protocols | ||
* @returns {Promise<void>} | ||
*/ | ||
async _onProtocolChange ({ peerId, protocols }) { | ||
|
@@ -78,6 +90,9 @@ class AutoRelay { | |
// If protocol, check if can hop, store info in the metadataBook and listen on it | ||
try { | ||
const connection = this._connectionManager.get(peerId) | ||
if (!connection) { | ||
return | ||
} | ||
|
||
// Do not hop on a relayed connection | ||
if (connection.remoteAddr.protoCodes().includes(CIRCUIT_PROTO_CODE)) { | ||
|
@@ -171,7 +186,7 @@ class AutoRelay { | |
* 2. Dial and try to listen on the peers we know that support hop but are not connected. | ||
* 3. Search the network. | ||
* | ||
* @param {Array<string>} [peersToIgnore] | ||
* @param {string[]} [peersToIgnore] | ||
* @returns {Promise<void>} | ||
*/ | ||
async _listenOnAvailableHopRelays (peersToIgnore = []) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.