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

refactor!: move fetch protocol into separate package #2193

Closed
wants to merge 9 commits into from
Closed
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
2 changes: 1 addition & 1 deletion doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ For more information see https://docs.libp2p.io/concepts/nat/autonat/#what-is-au

```ts
import { createLibp2p } from 'libp2p'
import { autoNATService } from 'libp2p/autonat'
import { autoNATService } from '@libp2p/autonat'

const node = await createLibp2p({
services: {
Expand Down
96 changes: 96 additions & 0 deletions doc/migrations/v0.46-v1.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!--Specify versions for migration below-->
# Migrating to libp2p@1.0.0 <!-- omit in toc -->

A migration guide for refactoring your application code from libp2p `v0.46` to `v1.0.0`.

## Table of Contents <!-- omit in toc -->

- [AutoNAT](#autonat)
- [Fetch](#fetch)
- [KeyChain](#keychain)
- [Pnet](#pnet)
- [Metrics](#metrics)

## AutoNAT

The AutoNAT service is now published in its own package.

**Before**

```ts
import { autoNATService } from 'libp2p/autonat'
```

**After**

```ts
import { autoNATService } from '@libp2p/autonat'
```

## Fetch

The Fetch service is now publisehd as it's own package.

**Before**

```ts
import { autoNATService } from 'libp2p/fetch'
```

**After**

```ts
import { autoNATService } from '@libp2p/fetch'
```

## KeyChain

The KeyChain object is no longer included on Libp2p and must be instantiated explicitly if desired.

**Before**

```ts
import type { KeyChain } from '@libp2p/interface/keychain'

const libp2p = await createLibp2p(...)

const keychain: KeyChain = libp2p.keychain
```

**After**

```ts
import { keychain, type Keychain } from '@libp2p/keychain'

const libp2p = await createLibp2p({
...
services: {
keychain: keychain()
}
})

const keychain: Keychain = libp2p.services.keychain
```

## Pnet

The pnet module is now published in its own package.

**Before**

```ts
import { preSharedKey, generateKey } from 'libp2p/pnet'
```

**After**

```ts
import { preSharedKey, generateKey } from '@libp2p/pnet'
```

## Metrics

The following metrics were renamed:

`libp2p_dialler_pending_dials` => `libp2p_dial_queue_pending_dials`
`libp2p_dialler_in_progress_dials` => `libp2p_dial_queue_in_progress_dials`
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export class MockDiscovery extends TypedEventEmitter<PeerDiscoveryEvents> implem
this.safeDispatchEvent<PeerInfo>('peer', {
detail: {
id: peerId,
multiaddrs: [multiaddr('/ip4/127.0.0.1/tcp/8000')],
protocols: []
multiaddrs: [multiaddr('/ip4/127.0.0.1/tcp/8000')]
}
})
}, this.options.discoveryDelay ?? 1000)
Expand Down
2 changes: 0 additions & 2 deletions packages/interface-compliance-tests/src/pubsub/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export default (common: TestSetup<PubSub, PubSubArgs>): void => {

await start(...Object.values(components))

expect(pubsub.isStarted()).to.equal(true)
expect(components.registrar.register).to.have.property('callCount', 1)
})

Expand All @@ -62,7 +61,6 @@ export default (common: TestSetup<PubSub, PubSubArgs>): void => {
await start(...Object.values(components))
await stop(...Object.values(components))

expect(pubsub.isStarted()).to.equal(false)
expect(components.registrar.unregister).to.have.property('callCount', 1)
})

Expand Down
7 changes: 7 additions & 0 deletions packages/interface/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,10 @@ export class InvalidCryptoTransmissionError extends Error {

static readonly code = 'ERR_INVALID_CRYPTO_TRANSMISSION'
}

// Error codes

export const ERR_TIMEOUT = 'ERR_TIMEOUT'
export const ERR_INVALID_MESSAGE = 'ERR_INVALID_MESSAGE'
export const ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS'
export const ERR_KEY_ALREADY_EXISTS = 'ERR_KEY_ALREADY_EXISTS'
15 changes: 0 additions & 15 deletions packages/interface/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import type { Connection, NewStreamOptions, Stream } from './connection/index.js'
import type { ContentRouting } from './content-routing/index.js'
import type { TypedEventTarget } from './events.js'
import type { KeyChain } from './keychain/index.js'
import type { Metrics } from './metrics/index.js'
import type { PeerId } from './peer-id/index.js'
import type { PeerInfo } from './peer-info/index.js'
Expand Down Expand Up @@ -377,20 +376,6 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
*/
contentRouting: ContentRouting

/**
* The keychain contains the keys used by the current node, and can create new
* keys, export them, import them, etc.
*
* @example
*
* ```js
* const keyInfo = await libp2p.keychain.createKey('new key')
* console.info(keyInfo)
* // { id: '...', name: 'new key' }
* ```
*/
keychain: KeyChain

/**
* The metrics subsystem allows recording values to assess the health/performance
* of the running node.
Expand Down
167 changes: 0 additions & 167 deletions packages/interface/src/keychain/index.ts

This file was deleted.

14 changes: 13 additions & 1 deletion packages/interface/src/peer-info/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import type { PeerId } from '../peer-id/index.js'
import type { Multiaddr } from '@multiformats/multiaddr'

/**
* A `PeerInfo` is a lightweight object that represents a remote peer, it can be
* obtained from peer discovery mechanisms, HTTP RPC endpoints, etc.
*
* @see https://docs.libp2p.io/concepts/fundamentals/peers/#peer-info
*/
export interface PeerInfo {
/**
* The identifier of the remote peer
*/
id: PeerId

/**
* The multiaddrs a peer is listening on
*/
multiaddrs: Multiaddr[]
protocols: string[]
}
2 changes: 0 additions & 2 deletions packages/interface/src/startable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* Implemented by components that have a lifecycle
*/
export interface Startable {
isStarted(): boolean

/**
* If implemented, this method will be invoked before the start method.
*
Expand Down
3 changes: 0 additions & 3 deletions packages/interface/src/topology/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import type { Connection } from '../connection/index.js'
import type { PeerId } from '../peer-id/index.js'

export interface Topology {
min?: number
max?: number

/**
* If true, invoke `onConnect` for this topology on transient (e.g. short-lived
* and/or data-limited) connections. (default: false)
Expand Down
Loading
Loading