Skip to content

Commit 3193fbe

Browse files
committed
chore: config typescript
1 parent b894452 commit 3193fbe

File tree

14 files changed

+161
-97
lines changed

14 files changed

+161
-97
lines changed

.aegir.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const after = async () => {
4848
}
4949

5050
module.exports = {
51-
bundlesize: { maxSize: '223kB' },
51+
bundlesize: { maxSize: '225kB' },
5252
hooks: {
5353
pre: before,
5454
post: after

.github/workflows/main.yml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
15-
- run: yarn
16-
- run: yarn lint
15+
- run: npm install
16+
- run: npm run lint
1717
- uses: gozala/[email protected]
18-
- run: yarn build
18+
- run: npm run build
1919
- run: yarn aegir dep-check
2020
- uses: ipfs/aegir/actions/bundle-size@master
2121
name: size
@@ -34,111 +34,111 @@ jobs:
3434
- uses: actions/setup-node@v1
3535
with:
3636
node-version: ${{ matrix.node }}
37-
- run: yarn
37+
- run: npm install
3838
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
3939
- uses: codecov/codecov-action@v1
4040
test-chrome:
4141
needs: check
4242
runs-on: ubuntu-latest
4343
steps:
4444
- uses: actions/checkout@v2
45-
- run: yarn
45+
- run: npm install
4646
- run: npx aegir test -t browser -t webworker --bail
4747
test-firefox:
4848
needs: check
4949
runs-on: ubuntu-latest
5050
steps:
5151
- uses: actions/checkout@v2
52-
- run: yarn
52+
- run: npm install
5353
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
5454
test-interop:
5555
needs: check
5656
runs-on: ubuntu-latest
5757
steps:
5858
- uses: actions/checkout@v2
59-
- run: yarn
59+
- run: npm install
6060
- run: cd node_modules/interop-libp2p && yarn && LIBP2P_JS=${GITHUB_WORKSPACE}/src/index.js npx aegir test -t node --bail
6161
test-auto-relay-example:
6262
needs: check
6363
runs-on: ubuntu-latest
6464
steps:
6565
- uses: actions/checkout@v2
66-
- run: yarn
66+
- run: npm install
6767
- run: cd examples && yarn && npm run test -- auto-relay
6868
test-chat-example:
6969
needs: check
7070
runs-on: ubuntu-latest
7171
steps:
7272
- uses: actions/checkout@v2
73-
- run: yarn
73+
- run: npm install
7474
- run: cd examples && yarn && npm run test -- chat
7575
test-connection-encryption-example:
7676
needs: check
7777
runs-on: ubuntu-latest
7878
steps:
7979
- uses: actions/checkout@v2
80-
- run: yarn
80+
- run: npm install
8181
- run: cd examples && yarn && npm run test -- connection-encryption
8282
test-discovery-mechanisms-example:
8383
needs: check
8484
runs-on: macos-latest
8585
steps:
8686
- uses: actions/checkout@v2
87-
- run: yarn
87+
- run: npm install
8888
- run: cd examples && yarn && npm run test -- discovery-mechanisms
8989
test-echo-example:
9090
needs: check
9191
runs-on: ubuntu-latest
9292
steps:
9393
- uses: actions/checkout@v2
94-
- run: yarn
94+
- run: npm install
9595
- run: cd examples && yarn && npm run test -- echo
9696
test-libp2p-in-the-browser-example:
9797
needs: check
9898
runs-on: macos-latest
9999
steps:
100100
- uses: actions/checkout@v2
101-
- run: yarn
101+
- run: npm install
102102
- run: cd examples && yarn && npm run test -- libp2p-in-the-browser
103103
test-peer-and-content-routing-example:
104104
needs: check
105105
runs-on: ubuntu-latest
106106
steps:
107107
- uses: actions/checkout@v2
108-
- run: yarn
108+
- run: npm install
109109
- run: cd examples && yarn && npm run test -- peer-and-content-routing
110110
test-pnet-example:
111111
needs: check
112112
runs-on: ubuntu-latest
113113
steps:
114114
- uses: actions/checkout@v2
115-
- run: yarn
115+
- run: npm install
116116
- run: cd examples && yarn && npm run test -- pnet
117117
test-protocol-and-stream-muxing-example:
118118
needs: check
119119
runs-on: ubuntu-latest
120120
steps:
121121
- uses: actions/checkout@v2
122-
- run: yarn
122+
- run: npm install
123123
- run: cd examples && yarn && npm run test -- protocol-and-stream-muxing
124124
test-pubsub-example:
125125
needs: check
126126
runs-on: ubuntu-latest
127127
steps:
128128
- uses: actions/checkout@v2
129-
- run: yarn
129+
- run: npm install
130130
- run: cd examples && yarn && npm run test -- pubsub
131131
test-transports-example:
132132
needs: check
133133
runs-on: ubuntu-latest
134134
steps:
135135
- uses: actions/checkout@v2
136-
- run: yarn
136+
- run: npm install
137137
- run: cd examples && yarn && npm run test -- transports
138138
test-webrtc-direct-example:
139139
needs: check
140140
runs-on: ubuntu-latest
141141
steps:
142142
- uses: actions/checkout@v2
143-
- run: yarn
143+
- run: npm install
144144
- run: cd examples && yarn && npm run test -- webrtc-direct

doc/CONFIGURATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ const TCP = require('libp2p-tcp')
599599
const MPLEX = require('libp2p-mplex')
600600
const { NOISE } = require('libp2p-noise')
601601

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

604604
const node = await Libp2p.create({
605605
modules: {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"src"
1919
],
2020
"scripts": {
21+
"prepare": "aegir build --no-bundle",
2122
"lint": "aegir lint",
2223
"build": "aegir build",
2324
"test": "npm run test:node && npm run test:browser",
@@ -81,7 +82,7 @@
8182
"it-protocol-buffers": "^0.2.0",
8283
"it-take": "1.0.0",
8384
"libp2p-crypto": "^0.19.0",
84-
"libp2p-interfaces": "^0.8.1",
85+
"libp2p-interfaces": "libp2p/js-libp2p-interfaces#chore/update-types",
8586
"libp2p-utils": "^0.2.2",
8687
"mafmt": "^8.0.0",
8788
"merge-options": "^3.0.4",

src/dialer/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ const {
3838
*
3939
* @typedef {Object} DialerOptions
4040
* @property {(addresses: Address[]) => Address[]} [options.addressSorter = publicAddressesFirst] - Sort the known addresses of a peer before trying to dial.
41-
* @property {number} [concurrency = MAX_PARALLEL_DIALS] - Number of max concurrent dials.
42-
* @property {number} [perPeerLimit = MAX_PER_PEER_DIALS] - Number of max concurrent dials per peer.
43-
* @property {number} [timeout = DIAL_TIMEOUT] - How long a dial attempt is allowed to take.
41+
* @property {number} [maxParallelDials = MAX_PARALLEL_DIALS] - Number of max concurrent dials.
42+
* @property {number} [maxDialsPerPeer = MAX_PER_PEER_DIALS] - Number of max concurrent dials per peer.
43+
* @property {number} [dialTimeout = DIAL_TIMEOUT] - How long a dial attempt is allowed to take.
4444
* @property {Record<string, Resolver>} [resolvers = {}] - multiaddr resolvers to use when dialing
4545
*
4646
* @typedef DialTarget
@@ -63,18 +63,18 @@ class Dialer {
6363
transportManager,
6464
peerStore,
6565
addressSorter = publicAddressesFirst,
66-
concurrency = MAX_PARALLEL_DIALS,
67-
timeout = DIAL_TIMEOUT,
68-
perPeerLimit = MAX_PER_PEER_DIALS,
66+
maxParallelDials = MAX_PARALLEL_DIALS,
67+
dialTimeout = DIAL_TIMEOUT,
68+
maxDialsPerPeer = MAX_PER_PEER_DIALS,
6969
resolvers = {}
7070
}) {
7171
this.transportManager = transportManager
7272
this.peerStore = peerStore
7373
this.addressSorter = addressSorter
74-
this.concurrency = concurrency
75-
this.timeout = timeout
76-
this.perPeerLimit = perPeerLimit
77-
this.tokens = [...new Array(concurrency)].map((_, index) => index)
74+
this.maxParallelDials = maxParallelDials
75+
this.timeout = dialTimeout
76+
this.maxDialsPerPeer = maxDialsPerPeer
77+
this.tokens = [...new Array(maxParallelDials)].map((_, index) => index)
7878
this._pendingDials = new Map()
7979

8080
for (const [key, value] of Object.entries(resolvers)) {
@@ -208,7 +208,7 @@ class Dialer {
208208
}
209209

210210
getTokens (num) {
211-
const total = Math.min(num, this.perPeerLimit, this.tokens.length)
211+
const total = Math.min(num, this.maxDialsPerPeer, this.tokens.length)
212212
const tokens = this.tokens.splice(0, total)
213213
log('%d tokens request, returning %d, %d remaining', num, total, this.tokens.length)
214214
return tokens

src/identify/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ const { codes } = require('../errors')
3434
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
3535
*/
3636

37+
/**
38+
* @typedef {Object} HostProperties
39+
* @property {string} agentVersion
40+
*/
41+
3742
class IdentifyService {
3843
/**
3944
* @class

src/index.js

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,41 +43,75 @@ const { updateSelfPeerRecord } = require('./record/utils')
4343
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
4444
* @typedef {import('libp2p-interfaces/src/transport/types').TransportFactory} TransportFactory
4545
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory} MuxerFactory
46+
* @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRouting
47+
* @typedef {import('libp2p-interfaces/src/peer-discovery/types').PeerDiscovery} PeerDiscovery
48+
* @typedef {import('libp2p-interfaces/src/peer-routing/types').PeerRouting} PeerRouting
4649
* @typedef {import('libp2p-interfaces/src/crypto/types').Crypto} Crypto
4750
* @typedef {import('libp2p-interfaces/src/pubsub')} Pubsub
51+
* @typedef {import('libp2p-interfaces/src/pubsub').PubsubOptions} PubsubOptions
52+
* @typedef {import('interface-datastore').Datastore} Datastore
4853
*/
4954

5055
/**
56+
* @typedef {Object} RandomWalkOptions
57+
* @property {boolean} [enabled = false]
58+
* @property {number} [queriesPerPeriod = 1]
59+
* @property {number} [interval = 300e3]
60+
* @property {number} [timeout = 10e3]
61+
*
62+
* @typedef {Object} DhtOptions
63+
* @property {boolean} [enabled = false]
64+
* @property {number} [kBucketSize = 20]
65+
* @property {RandomWalkOptions} [randomWalk]
66+
*
67+
* @typedef {Object} KeychainOptions
68+
* @property {Datastore} [datastore]
69+
*
5170
* @typedef {Object} PeerStoreOptions
5271
* @property {boolean} persistence
5372
*
54-
* @typedef {Object} RelayOptions
73+
* @typedef {Object} PubsubLocalOptions
74+
* @property {boolean} enabled
75+
*
76+
* @typedef {Object} MetricsOptions
5577
* @property {boolean} enabled
56-
* @property {import('./circuit').RelayAdvertiseOptions} advertise
57-
* @property {import('./circuit').HopOptions} hop
58-
* @property {import('./circuit').AutoRelayOptions} autoRelay
78+
*
79+
* @typedef {Object} RelayOptions
80+
* @property {boolean} [enabled = true]
81+
* @property {import('./circuit').RelayAdvertiseOptions} [advertise]
82+
* @property {import('./circuit').HopOptions} [hop]
83+
* @property {import('./circuit').AutoRelayOptions} [autoRelay]
5984
*
6085
* @typedef {Object} Libp2pConfig
61-
* @property {Object} [dht] dht module options
62-
* @property {Object} [peerDiscovery]
63-
* @property {Pubsub} [pubsub] pubsub module options
86+
* @property {DhtOptions} [dht] dht module options
87+
* @property {import('./nat-manager').NatManagerOptions} [nat]
88+
* @property {Record<string, Object|boolean>} [peerDiscovery]
89+
* @property {PubsubLocalOptions & PubsubOptions} [pubsub] pubsub module options
6490
* @property {RelayOptions} [relay]
6591
* @property {Record<string, Object>} [transport] transport options indexed by transport key
6692
*
6793
* @typedef {Object} Libp2pModules
6894
* @property {TransportFactory[]} transport
6995
* @property {MuxerFactory[]} streamMuxer
7096
* @property {Crypto[]} connEncryption
97+
* @property {PeerDiscovery[]} [peerDiscovery]
98+
* @property {PeerRouting[]} [peerRouting]
99+
* @property {ContentRouting[]} [contentRouting]
100+
* @property {Object} [dht]
101+
* @property {Pubsub} [pubsub]
71102
*
72103
* @typedef {Object} Libp2pOptions
73104
* @property {Libp2pModules} modules libp2p modules to use
74105
* @property {import('./address-manager').AddressManagerOptions} [addresses]
75106
* @property {import('./connection-manager').ConnectionManagerOptions} [connectionManager]
107+
* @property {Datastore} [datastore]
76108
* @property {import('./dialer').DialerOptions} [dialer]
77-
* @property {import('./metrics').MetricsOptions} [metrics]
78-
* @property {Object} [keychain]
79-
* @property {import('./transport-manager').TransportManagerOptions} [transportManager]
109+
* @property {import('./identify/index').HostProperties} [host] libp2p host
110+
* @property {KeychainOptions & import('./keychain/index').KeychainOptions} [keychain]
111+
* @property {MetricsOptions & import('./metrics').MetricsOptions} [metrics]
112+
* @property {import('./peer-routing').PeerRoutingOptions} [peerRouting]
80113
* @property {PeerStoreOptions & import('./peer-store/persistent').PersistentPeerStoreOptions} [peerStore]
114+
* @property {import('./transport-manager').TransportManagerOptions} [transportManager]
81115
* @property {Libp2pConfig} [config]
82116
*
83117
* @typedef {Object} constructorOptions
@@ -175,7 +209,6 @@ class Libp2p extends EventEmitter {
175209
const keychainOpts = Keychain.generateOptions()
176210

177211
this.keychain = new Keychain(this._options.keychain.datastore, {
178-
passPhrase: this._options.keychain.pass,
179212
...keychainOpts,
180213
...this._options.keychain
181214
})
@@ -227,11 +260,7 @@ class Libp2p extends EventEmitter {
227260
this.dialer = new Dialer({
228261
transportManager: this.transportManager,
229262
peerStore: this.peerStore,
230-
concurrency: this._options.dialer.maxParallelDials,
231-
perPeerLimit: this._options.dialer.maxDialsPerPeer,
232-
timeout: this._options.dialer.dialTimeout,
233-
resolvers: this._options.dialer.resolvers,
234-
addressSorter: this._options.dialer.addressSorter
263+
...this._options.dialer
235264
})
236265

237266
this._modules.transport.forEach((Transport) => {

0 commit comments

Comments
 (0)