Skip to content

Commit

Permalink
chore: config typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Mar 27, 2021
1 parent 8e1743c commit cec3ce7
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const after = async () => {
}

module.exports = {
bundlesize: { maxSize: '223kB' },
bundlesize: { maxSize: '225kB' },
hooks: {
pre: before,
post: after
Expand Down
38 changes: 19 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: yarn lint
- run: npm install
- run: npm run lint
- uses: gozala/[email protected]
- run: yarn build
- run: npm run build
- run: yarn aegir dep-check
- uses: ipfs/aegir/actions/bundle-size@master
name: size
Expand All @@ -34,111 +34,111 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: yarn
- run: npm install
- 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: npm install
- 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: npm install
- 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: npm install
- 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: npm install
- run: cd examples && yarn && npm run test -- auto-relay
test-chat-example:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npm install
- run: cd examples && yarn && npm run test -- chat
test-connection-encryption-example:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npm install
- run: cd examples && yarn && npm run test -- connection-encryption
test-discovery-mechanisms-example:
needs: check
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npm install
- run: cd examples && yarn && npm run test -- discovery-mechanisms
test-echo-example:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npm install
- run: cd examples && yarn && npm run test -- echo
test-libp2p-in-the-browser-example:
needs: check
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npm install
- run: cd examples && yarn && npm run test -- libp2p-in-the-browser
test-peer-and-content-routing-example:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npm install
- run: cd examples && yarn && npm run test -- peer-and-content-routing
test-pnet-example:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npm install
- run: cd examples && yarn && npm run test -- pnet
test-protocol-and-stream-muxing-example:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npm install
- run: cd examples && yarn && npm run test -- protocol-and-stream-muxing
test-pubsub-example:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npm install
- run: cd examples && yarn && npm run test -- pubsub
test-transports-example:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npm install
- run: cd examples && yarn && npm run test -- transports
test-webrtc-direct-example:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: npm install
- run: cd examples && yarn && npm run test -- webrtc-direct
2 changes: 1 addition & 1 deletion doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ const TCP = require('libp2p-tcp')
const MPLEX = require('libp2p-mplex')
const { NOISE } = require('libp2p-noise')

const { FaultTolerance } = require('libp2p/src/transport-manager')}
const { FaultTolerance } = require('libp2p/src/transport-manager')

const node = await Libp2p.create({
modules: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"src"
],
"scripts": {
"prepare": "aegir build --no-bundle",
"lint": "aegir lint",
"build": "aegir build",
"test": "npm run test:node && npm run test:browser",
Expand Down Expand Up @@ -81,7 +82,7 @@
"it-protocol-buffers": "^0.2.0",
"it-take": "1.0.0",
"libp2p-crypto": "^0.19.0",
"libp2p-interfaces": "^0.8.1",
"libp2p-interfaces": "libp2p/js-libp2p-interfaces#chore/update-types",
"libp2p-utils": "^0.2.2",
"mafmt": "^8.0.0",
"merge-options": "^3.0.4",
Expand Down
22 changes: 11 additions & 11 deletions src/dialer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ const {
*
* @typedef {Object} DialerOptions
* @property {(addresses: Address[]) => Address[]} [options.addressSorter = publicAddressesFirst] - Sort the known addresses of a peer before trying to dial.
* @property {number} [concurrency = MAX_PARALLEL_DIALS] - Number of max concurrent dials.
* @property {number} [perPeerLimit = MAX_PER_PEER_DIALS] - Number of max concurrent dials per peer.
* @property {number} [timeout = DIAL_TIMEOUT] - How long a dial attempt is allowed to take.
* @property {number} [maxParallelDials = MAX_PARALLEL_DIALS] - Number of max concurrent dials.
* @property {number} [maxDialsPerPeer = MAX_PER_PEER_DIALS] - Number of max concurrent dials per peer.
* @property {number} [dialTimeout = DIAL_TIMEOUT] - How long a dial attempt is allowed to take.
* @property {Record<string, Resolver>} [resolvers = {}] - multiaddr resolvers to use when dialing
*
* @typedef DialTarget
Expand All @@ -63,18 +63,18 @@ class Dialer {
transportManager,
peerStore,
addressSorter = publicAddressesFirst,
concurrency = MAX_PARALLEL_DIALS,
timeout = DIAL_TIMEOUT,
perPeerLimit = MAX_PER_PEER_DIALS,
maxParallelDials = MAX_PARALLEL_DIALS,
dialTimeout = DIAL_TIMEOUT,
maxDialsPerPeer = MAX_PER_PEER_DIALS,
resolvers = {}
}) {
this.transportManager = transportManager
this.peerStore = peerStore
this.addressSorter = addressSorter
this.concurrency = concurrency
this.timeout = timeout
this.perPeerLimit = perPeerLimit
this.tokens = [...new Array(concurrency)].map((_, index) => index)
this.maxParallelDials = maxParallelDials
this.timeout = dialTimeout
this.maxDialsPerPeer = maxDialsPerPeer
this.tokens = [...new Array(maxParallelDials)].map((_, index) => index)
this._pendingDials = new Map()

for (const [key, value] of Object.entries(resolvers)) {
Expand Down Expand Up @@ -208,7 +208,7 @@ class Dialer {
}

getTokens (num) {
const total = Math.min(num, this.perPeerLimit, this.tokens.length)
const total = Math.min(num, this.maxDialsPerPeer, this.tokens.length)
const tokens = this.tokens.splice(0, total)
log('%d tokens request, returning %d, %d remaining', num, total, this.tokens.length)
return tokens
Expand Down
5 changes: 5 additions & 0 deletions src/identify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const { codes } = require('../errors')
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
*/

/**
* @typedef {Object} HostProperties
* @property {string} agentVersion
*/

class IdentifyService {
/**
* @class
Expand Down
61 changes: 45 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,75 @@ const { updateSelfPeerRecord } = require('./record/utils')
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
* @typedef {import('libp2p-interfaces/src/transport/types').TransportFactory} TransportFactory
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory} MuxerFactory
* @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRouting
* @typedef {import('libp2p-interfaces/src/peer-discovery/types').PeerDiscovery} PeerDiscovery
* @typedef {import('libp2p-interfaces/src/peer-routing/types').PeerRouting} PeerRouting
* @typedef {import('libp2p-interfaces/src/crypto/types').Crypto} Crypto
* @typedef {import('libp2p-interfaces/src/pubsub')} Pubsub
* @typedef {import('libp2p-interfaces/src/pubsub').PubsubOptions} PubsubOptions
* @typedef {import('interface-datastore').Datastore} Datastore
*/

/**
* @typedef {Object} RandomWalkOptions
* @property {boolean} [enabled = false]
* @property {number} [queriesPerPeriod = 1]
* @property {number} [interval = 300e3]
* @property {number} [timeout = 10e3]
*
* @typedef {Object} DhtOptions
* @property {boolean} [enabled = false]
* @property {number} [kBucketSize = 20]
* @property {RandomWalkOptions} [randomWalk]
*
* @typedef {Object} KeychainOptions
* @property {Datastore} [datastore]
*
* @typedef {Object} PeerStoreOptions
* @property {boolean} persistence
*
* @typedef {Object} RelayOptions
* @typedef {Object} PubsubLocalOptions
* @property {boolean} enabled
*
* @typedef {Object} MetricsOptions
* @property {boolean} enabled
* @property {import('./circuit').RelayAdvertiseOptions} advertise
* @property {import('./circuit').HopOptions} hop
* @property {import('./circuit').AutoRelayOptions} autoRelay
*
* @typedef {Object} RelayOptions
* @property {boolean} [enabled = true]
* @property {import('./circuit').RelayAdvertiseOptions} [advertise]
* @property {import('./circuit').HopOptions} [hop]
* @property {import('./circuit').AutoRelayOptions} [autoRelay]
*
* @typedef {Object} Libp2pConfig
* @property {Object} [dht] dht module options
* @property {Object} [peerDiscovery]
* @property {Pubsub} [pubsub] pubsub module options
* @property {DhtOptions} [dht] dht module options
* @property {import('./nat-manager').NatManagerOptions} [nat]
* @property {Record<string, Object|boolean>} [peerDiscovery]
* @property {PubsubLocalOptions & PubsubOptions} [pubsub] pubsub module options
* @property {RelayOptions} [relay]
* @property {Record<string, Object>} [transport] transport options indexed by transport key
*
* @typedef {Object} Libp2pModules
* @property {TransportFactory[]} transport
* @property {MuxerFactory[]} streamMuxer
* @property {Crypto[]} connEncryption
* @property {PeerDiscovery[]} [peerDiscovery]
* @property {PeerRouting[]} [peerRouting]
* @property {ContentRouting[]} [contentRouting]
* @property {Object} [dht]
* @property {Pubsub} [pubsub]
*
* @typedef {Object} Libp2pOptions
* @property {Libp2pModules} modules libp2p modules to use
* @property {import('./address-manager').AddressManagerOptions} [addresses]
* @property {import('./connection-manager').ConnectionManagerOptions} [connectionManager]
* @property {Datastore} [datastore]
* @property {import('./dialer').DialerOptions} [dialer]
* @property {import('./metrics').MetricsOptions} [metrics]
* @property {Object} [keychain]
* @property {import('./transport-manager').TransportManagerOptions} [transportManager]
* @property {import('./identify/index').HostProperties} [host] libp2p host
* @property {KeychainOptions & import('./keychain/index').KeychainOptions} [keychain]
* @property {MetricsOptions & import('./metrics').MetricsOptions} [metrics]
* @property {import('./peer-routing').PeerRoutingOptions} [peerRouting]
* @property {PeerStoreOptions & import('./peer-store/persistent').PersistentPeerStoreOptions} [peerStore]
* @property {import('./transport-manager').TransportManagerOptions} [transportManager]
* @property {Libp2pConfig} [config]
*
* @typedef {Object} constructorOptions
Expand Down Expand Up @@ -175,7 +209,6 @@ class Libp2p extends EventEmitter {
const keychainOpts = Keychain.generateOptions()

this.keychain = new Keychain(this._options.keychain.datastore, {
passPhrase: this._options.keychain.pass,
...keychainOpts,
...this._options.keychain
})
Expand Down Expand Up @@ -227,11 +260,7 @@ class Libp2p extends EventEmitter {
this.dialer = new Dialer({
transportManager: this.transportManager,
peerStore: this.peerStore,
concurrency: this._options.dialer.maxParallelDials,
perPeerLimit: this._options.dialer.maxDialsPerPeer,
timeout: this._options.dialer.dialTimeout,
resolvers: this._options.dialer.resolvers,
addressSorter: this._options.dialer.addressSorter
...this._options.dialer
})

this._modules.transport.forEach((Transport) => {
Expand Down
Loading

0 comments on commit cec3ce7

Please sign in to comment.