-
Notifications
You must be signed in to change notification settings - Fork 502
feat: configuration validation #1778
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
Merged
Merged
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
6ba3dd8
wip
maschad 68f6e83
wip
maschad 5874c4e
refactor: added connection manager config validation
maschad 71490db
refactor: added addresses config validation (#1573)
maschad 3aeb754
wip
maschad 36f66ef
Merge branch 'master' into feat/configuration-validation
maschad 722dc7a
wip
maschad 27a9789
feat: added fetch validation
maschad 73f9fc7
feat: added default announce filter (#1573)
maschad 893e068
feat: refactored config to validate before returning service (#1573)
maschad 6c5f7fd
Merge branch 'master' into feat/configuration-validation
maschad 1e9b0e3
chore: linting fixes
maschad c70f7c1
wip
maschad dd17fcd
feat: added validation to unpnp and circuit relay transport
maschad df1ba0e
Merge branch 'master' into feat/configuration-validation
maschad f86432a
test: refactor tests + updated config (#1573)
maschad c3ed878
chore: linting (#1573)
maschad be8bd3a
Merge branch 'master' into feat/configuration-validation
maschad 6bd7bec
feat: updated config validation for identify and circuit relay (#1573)
maschad d4ec37a
Merge branch 'master' into feat/configuration-validation
maschad 8e23b59
chore: linting
maschad 083414f
Merge branch 'master' into feat/configuration-validation
maschad 0820b6f
Merge branch 'master' into feat/configuration-validation
maschad 83a5f0e
Merge branch 'master' into feat/configuration-validation
maschad dbbcbbd
Merge branch 'master' into feat/configuration-validation
maschad 0d4c8e4
fix: added transient connection default to identify service (#1573)
maschad a89818a
refactor: Refactored config to be done inside services (#1573)
maschad 264ec7c
Merge branch 'master' into feat/configuration-validation
maschad b4fb523
Merge branch 'master' into feat/configuration-validation
maschad 6c7935a
Merge branch 'master' into feat/configuration-validation
maschad 6638573
Update packages/libp2p/src/circuit-relay/server/index.ts
maschad e0080fb
Merge branch 'master' into feat/configuration-validation
maschad d45851d
feat: added validation to dcutr
maschad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,9 @@ export default { | |
const peerId = await createEd25519PeerId() | ||
const libp2p = await createLibp2p({ | ||
connectionManager: { | ||
inboundConnectionThreshold: Infinity, | ||
inboundConnectionThreshold: 1000, | ||
maxIncomingPendingConnections: 1000, | ||
maxConnections: 1000, | ||
Comment on lines
+28
to
+29
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. The default value for these was fine before, why do these now need to be set? 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. See my comment #1778 |
||
minConnections: 0 | ||
}, | ||
addresses: { | ||
|
@@ -51,7 +53,7 @@ export default { | |
fetch: fetchService(), | ||
relay: circuitRelayServer({ | ||
reservations: { | ||
maxReservations: Infinity | ||
maxReservations: 100000 | ||
} | ||
}) | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { FaultTolerance } from '@libp2p/interface/transport' | ||
import { publicAddressesFirst } from '@libp2p/utils/address-sort' | ||
import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers' | ||
import mergeOptions from 'merge-options' | ||
import { object } from 'yup' | ||
import { validateAddressManagerConfig } from '../address-manager/utils.js' | ||
import { validateConnectionManagerConfig } from '../connection-manager/utils.js' | ||
import type { AddressManagerInit } from '../address-manager' | ||
import type { ConnectionManagerInit } from '../connection-manager/index.js' | ||
import type { Libp2pInit } from '../index.js' | ||
import type { ServiceMap, RecursivePartial } from '@libp2p/interface' | ||
|
||
const DefaultConfig: Partial<Libp2pInit> = { | ||
connectionManager: { | ||
resolvers: { | ||
dnsaddr: dnsaddrResolver | ||
}, | ||
addressSorter: publicAddressesFirst | ||
}, | ||
transportManager: { | ||
faultTolerance: FaultTolerance.FATAL_ALL | ||
} | ||
} | ||
|
||
export function validateConfig <T extends ServiceMap = Record<string, unknown>> (opts: RecursivePartial<Libp2pInit<T>>): Libp2pInit<T> { | ||
const libp2pConfig = object({ | ||
addresses: validateAddressManagerConfig(opts?.addresses as AddressManagerInit), | ||
connectionManager: validateConnectionManagerConfig(opts?.connectionManager as ConnectionManagerInit) | ||
}) | ||
|
||
if ((opts?.services) != null) { | ||
// @ts-expect-error until we resolve https://github.com/libp2p/js-libp2p/pull/1762 and have a better way of discovering type dependencies | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if ((opts.services?.kadDHT || opts.services?.relay || opts.services?.ping) && !opts.services.identify) { | ||
throw new Error('identify service is required when using kadDHT, relay, or ping') | ||
} | ||
} | ||
|
||
const parsedOpts = libp2pConfig.validateSync(opts) | ||
|
||
const resultingOptions: Libp2pInit<T> = mergeOptions(DefaultConfig, parsedOpts) | ||
|
||
return resultingOptions | ||
} | ||
maschad marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { multiaddr } from '@multiformats/multiaddr' | ||
|
||
export const validateMultiaddr = (value: Array<string | undefined> | undefined): boolean => { | ||
value?.forEach((addr) => { | ||
try { | ||
multiaddr(addr) | ||
} catch (err) { | ||
throw new Error(`invalid multiaddr: ${addr}`) | ||
} | ||
}) | ||
return true | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
// https://github.com/libp2p/specs/tree/master/fetch#wire-protocol | ||
export const PROTOCOL_VERSION = '0.0.1' | ||
export const PROTOCOL_NAME = 'fetch' | ||
|
||
export const MAX_INBOUND_STREAMS = 1 | ||
export const MAX_OUTBOUND_STREAMS = 1 | ||
export const TIMEOUT = 60000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it yup doesn't accept
Infinity
as a number?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct