Skip to content
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

fix: allow no transports in config #2293

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/libp2p/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ const DefaultConfig: Partial<Libp2pInit> = {
export function validateConfig <T extends ServiceMap = Record<string, unknown>> (opts: RecursivePartial<Libp2pInit<T>>): Libp2pInit<T> {
const resultingOptions: Libp2pInit<T> = mergeOptions(DefaultConfig, opts)

if (resultingOptions.transports == null || resultingOptions.transports.length < 1) {
throw new CodeError(messages.ERR_TRANSPORTS_REQUIRED, codes.ERR_TRANSPORTS_REQUIRED)
}

if (resultingOptions.connectionProtector === null && globalThis.process?.env?.LIBP2P_FORCE_PNET != null) { // eslint-disable-line no-undef
throw new CodeError(messages.ERR_PROTECTOR_REQUIRED, codes.ERR_PROTECTOR_REQUIRED)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/libp2p/src/content-routing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
*/
async put (key: Uint8Array, value: Uint8Array, options?: AbortOptions): Promise<void> {
if (!this.isStarted()) {
throw new CodeError(messages.NOT_STARTED_YET, codes.DHT_NOT_STARTED)
throw new CodeError(messages.NOT_STARTED_YET, codes.ERR_NODE_NOT_STARTED)

Check warning on line 79 in packages/libp2p/src/content-routing/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/libp2p/src/content-routing/index.ts#L79

Added line #L79 was not covered by tests
}

await Promise.all(this.routers.map(async (router) => {
Expand All @@ -90,7 +90,7 @@
*/
async get (key: Uint8Array, options?: AbortOptions): Promise<Uint8Array> {
if (!this.isStarted()) {
throw new CodeError(messages.NOT_STARTED_YET, codes.DHT_NOT_STARTED)
throw new CodeError(messages.NOT_STARTED_YET, codes.ERR_NODE_NOT_STARTED)

Check warning on line 93 in packages/libp2p/src/content-routing/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/libp2p/src/content-routing/index.ts#L93

Added line #L93 was not covered by tests
}

return Promise.any(this.routers.map(async (router) => {
Expand Down
10 changes: 0 additions & 10 deletions packages/libp2p/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
export enum messages {
NOT_STARTED_YET = 'The libp2p node is not started yet',
DHT_DISABLED = 'DHT is not available',
PUBSUB_DISABLED = 'PubSub is not available',
CONN_ENCRYPTION_REQUIRED = 'At least one connection encryption module is required',
ERR_TRANSPORTS_REQUIRED = 'At least one transport module is required',
ERR_PROTECTOR_REQUIRED = 'Private network is enforced, but no protector was provided',
NOT_FOUND = 'Not found'
}

export enum codes {
DHT_DISABLED = 'ERR_DHT_DISABLED',
ERR_PUBSUB_DISABLED = 'ERR_PUBSUB_DISABLED',
PUBSUB_NOT_STARTED = 'ERR_PUBSUB_NOT_STARTED',
DHT_NOT_STARTED = 'ERR_DHT_NOT_STARTED',
CONN_ENCRYPTION_REQUIRED = 'ERR_CONN_ENCRYPTION_REQUIRED',
ERR_TRANSPORTS_REQUIRED = 'ERR_TRANSPORTS_REQUIRED',
ERR_PROTECTOR_REQUIRED = 'ERR_PROTECTOR_REQUIRED',
ERR_PEER_DIAL_INTERCEPTED = 'ERR_PEER_DIAL_INTERCEPTED',
ERR_CONNECTION_INTERCEPTED = 'ERR_CONNECTION_INTERCEPTED',
Expand Down
Loading