-
Notifications
You must be signed in to change notification settings - Fork 478
fix!: remove @libp2p/components #1427
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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,141 @@ | ||
# Migrating to libp2p@40 <!-- omit in toc --> | ||
|
||
A migration guide for refactoring your application code from libp2p v0.37.x to v0.40.0. | ||
|
||
## Table of Contents <!-- omit in toc --> | ||
|
||
- [Modules](#modules) | ||
- [Autodial](#autodial) | ||
|
||
## Modules | ||
|
||
Modules in the libp2p ecosystem no longer export constructors. This is because internally libp2p has switched to using constructor dependency injection so needs to control the lifecycle of the various components. | ||
|
||
These modules now export factory functions that take the same arguments as the older constructors so migration should be relatively straightforward. | ||
|
||
The most affected place will be where you configure your libp2p node: | ||
|
||
**Before** | ||
|
||
```js | ||
import { createLibp2p } from 'libp2p' | ||
import { TCP } from '@libp2p/tcp' | ||
import { WebSockets } from '@libp2p/websockets' | ||
import { WebRTCStar } from '@libp2p/webrtc-star' | ||
import { WebRTCDirect } from '@libp2p/webrtc-direct' | ||
import { KadDHT } from '@libp2p/kad-dht' | ||
import Gossipsub from '@chainsafe/libp2p-gossipsub' | ||
import { Bootstrap } from '@libp2p/bootstrap' | ||
import { MulticastDNS } from '@libp2p/mdns' | ||
import { Noise } from '@chainsafe/libp2p-noise' | ||
import { Yamux } from '@chainsafe/libp2p-yamux' | ||
import { Mplex } from '@libp2p/mplex' | ||
import { DelegatedContentRouting } from '@libp2p/delegated-content-routing' | ||
import { DelegatedPeerRouting } from '@libp2p/delegated-peer-routing' | ||
import { create as createIpfsHttpClient } from 'ipfs-http-client' | ||
|
||
const star = new WebRTCStar() | ||
const ipfsHttpClinet = createIpfsHttpClient(new URL('https://node0.delegate.ipfs.io')) | ||
|
||
const node = await createLibp2p({ | ||
addresses: { | ||
listen: [ | ||
'/ip4/0.0.0.0/tcp/0' | ||
] | ||
}, | ||
transports: [ | ||
new TCP(), | ||
new WebSockets(), | ||
new WebRTCDirect(), | ||
star | ||
], | ||
peerDiscovery: [ | ||
new Bootstrap({ list: [ ... ] }), | ||
new MulticastDNS(), | ||
star.discovery | ||
], | ||
connectionEncryption: [ | ||
new Noise() | ||
], | ||
streamMuxers: [ | ||
new Yamux(), | ||
new Mplex() | ||
], | ||
contentRouting: [ | ||
new DelegatedContentRouting(ipfsHttpClinet) | ||
], | ||
peerRouting: [ | ||
new DelegatedPeerRouting(ipfsHttpClinet) | ||
], | ||
dht: new KadDHT(), | ||
pubsub: new Gossipsub() | ||
}) | ||
|
||
await node.start() | ||
// ... | ||
``` | ||
|
||
**After** | ||
|
||
```js | ||
import { createLibp2p } from 'libp2p' | ||
import { tcp } from '@libp2p/tcp' | ||
import { webSockets } from '@libp2p/websockets' | ||
import { webRTCStar } from '@libp2p/webrtc-star' | ||
import { webRTCDirect } from '@libp2p/webrtc-direct' | ||
import { kadDHT } from '@libp2p/kad-dht' | ||
import { gossipsub } from '@chainsafe/libp2p-gossipsub' | ||
import { bootstrap } from '@libp2p/bootstrap' | ||
import { mdns } from '@libp2p/mdns' | ||
import { noise } from '@chainsafe/libp2p-noise' | ||
import { yamux } from '@chainsafe/libp2p-yamux' | ||
import { mplex } from '@libp2p/mplex' | ||
import { delegatedContentRouting } from '@libp2p/delegated-content-routing' | ||
import { delegatedPeerRouting } from '@libp2p/delegated-peer-routing' | ||
import { create as createIpfsHttpClient } from 'ipfs-http-client' | ||
|
||
const star = webRTCStar() | ||
const ipfsHttpClinet = createIpfsHttpClient(new URL('https://node0.delegate.ipfs.io')) | ||
|
||
const node = await createLibp2p({ | ||
addresses: { | ||
listen: [ | ||
'/ip4/0.0.0.0/tcp/0' | ||
] | ||
}, | ||
transports: [ | ||
tcp(), | ||
webSockets(), | ||
webRTCDirect(), | ||
star | ||
], | ||
peerDiscovery: [ | ||
bootstrap({ list: [ ... ] }), | ||
mdns(), | ||
star.discovery | ||
], | ||
connectionEncryption: [ | ||
noise() | ||
], | ||
streamMuxers: [ | ||
yamux(), | ||
mplex() | ||
], | ||
contentRouting: [ | ||
delegatedContentRouting(ipfsHttpClinet) | ||
], | ||
peerRouting: [ | ||
delegatedPeerRouting(ipfsHttpClinet) | ||
], | ||
dht: kadDHT(), | ||
pubsub: gossipsub() | ||
}) | ||
|
||
await node.start() | ||
``` | ||
|
||
## Autodial | ||
|
||
In versions of libp2p prior to 0.40.x, when the peer discovery subsystem announced a new peer, that peer would automatically be dialed and a connection held open, subject to [the normal rules on closing connections](https://github.com/libp2p/js-libp2p/blob/master/doc/LIMITS.md#closing-connections). Prior to having a working DHT this was necessary to increase the chances that you would be connected to a peer that could service any network request you might make. The downside to this is that connections are expensive so nodes displayed high CPU usage even when idle. Now that the DHT is in place this is no longer necessary as we can discover nearby peers using that mechanism. | ||
|
||
When dialing a remote peer the [identify protocol](https://docs.libp2p.io/concepts/protocols/#identify) is run, during which we find out which protocols the remote peer supports. This in turn affects the nodes added to [topologies](https://github.com/libp2p/js-libp2p-topology#readme) for a given protocol. Topologies may see fewer nodes added to them as we are now dialing and running identify on fewer peers, though the peers that do get added are likely to be higher value - their PeerIds will be KAD-closer to ours, they would have been dialed directly rather than being random peers on the network, etc. |
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 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.
This is needed until ChainSafe/js-libp2p-noise#229 is released