A migration guide for refactoring your application code from libp2p v0.43.x to v0.44.0.
The connection manager has been refactored to be simpler and faster. The changes are mostly internal but some configuration options have changed.
Before
import { createLibp2p } from 'libp2p'
const node = await createLibp2p({
connectionManager: {
// this has been renamed to `maxPeerAddrsToDial`
maxAddrsToDial: 20,
// this has been renamed to `maxParallelDialsPerPeer`
maxDialsPerPeer: 20,
// these should now be ranges expressed as MultiaddrFilters
allow: [
'/ip4/0.0.0.0/tcp/123'
],
// these should now be ranges expressed as MultiaddrFilters
deny: [
'/ip4/0.0.0.0/tcp/123'
]
}
})
After
import { createLibp2p } from 'libp2p'
import { MultiaddrFilter } from from '@multiformats/multiaddr'
const node = await createLibp2p({
connectionManager: {
// how many peers to dial at once while trying to ensure the node
// is above minConnections
autoDialConcurrency: 25,
// a low value allows user-initiated dials to take priority over
// auto dials
autoDialPriority: 0,
// this was previously named `maxAddrsToDial`
maxPeerAddrsToDial: 20,
// this was previously named `maxDialsPerPeer`
maxParallelDialsPerPeer: 20
}
})
The denyDialMultiaddr
method on the ConnectionGater
interface no longer receives a peer id. This is to
support gating multiaddr dials for multiaddrs without peer ids.
If the peer id is known it will be present in the multiaddr.
Before
import { createLibp2p } from 'libp2p'
const node = await createLibp2p({
connectionGater: {
denyDialMultiaddr: (peerId, multiaddr) => {
// allow/deny logic here
}
}
})
After
import { createLibp2p } from 'libp2p'
const node = await createLibp2p({
connectionGater: {
denyDialMultiaddr: (multiaddr) => {
if (multiaddr.getPeerId() != null) {
// there is a peer id present in the multiaddr
}
// allow/deny logic here
}
}
})