# Migrating to libp2p@43 <!-- omit in toc -->

A migration guide for refactoring your application code from libp2p v0.42.x to v0.43.0.

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

- [Circuit Relay v2](#circuit-relay-v2)
- [Connection manager autodial](#connection-manager-autodial)

## Circuit Relay v2

libp2p@0.43.x ships with support for [Circuit Relay v2](https://github.com/libp2p/specs/blob/master/relay/circuit-v2.md).  This update to the spec changes the relay from being an open relay by default, and as such quite dangerous to enable, to being a limited relay with a slot reservation mechanism that is much safer.

With version 2, each relay has a limited number of slots available (default: 15) which network peers can reserve use of to transfer small amounts of data to and from other peers (default 128k) for short amounts of time (default: 2 minutes).

This allows network nodes to act as intermediaries between nodes that may otherwise not be able to communicate due to a lack of compatible transports.

To simplify configuration, the client and server parts of the relay have been split apart to make it easier to configure your node as a client and/or a server.

**Before**

```js
import { createLibp2p } from 'libp2p'

const node = await createLibp2p({
  // ... other options
  addresses: {
    listen: {
      '/ip4/123.123.123.123/p2p/QmRelay/p2p-circuit' // optionally configure a static relay
    }
  },
  relay: {
    enabled: true, // enable client portion of relay

    autoRelay: {
      enabled: true, // enable automatically finding network relays
      maxListeners: 2 // limit number of network relays to use
    }

    hop: {
      enabled: true, // enable server portion of relay
      active: true  // dial other nodes on the incoming relay client's behalf
    },

    advertise: {
      enabled: true, // advertise the relay server on this node
      bootDelay: 15 * 60 * 1000,  // how long to wait after startup before advertising
      ttl: 30 * 60 * 1000 // how often to re-advertise
    }
  }
})
```

**After**

```js
import { createLibp2p } from 'libp2p'
import { circuitRelayClient, circuitRelayServer } from 'libp2p/circuit-relay'

const node = await createLibp2p({
  // ... other options
  addresses: {
    listen: {
      '/ip4/123.123.123.123/p2p/QmRelay/p2p-circuit' // optionally configure a static relay
    }
  },
  transports: [
    circuitRelayClient({ // enable client portion of relay
      discoverRelays: 1 // find this number of network relays (default: 0)
    })
  ],
  relay: circuitRelayServer({ // enable server portion of relay
    advertise: {
      bootDelay: 15 * 60 * 1000 // how long to wait after startup before re-advertising
    }
  })
})
```

Please see the [Setup with Relay](https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md#setup-with-relay) section of the configuration for a full breakdown of all the options.

## Connection manager autodial

The `autoDial` configutation option has been removed from the connection manager.

This setting used to control whether libp2p would automatically dial every discovered peer, then it was changed to control whether libp2p would try to dial peers from the peer store to keep the number of connections above `minConnections`.

Instead, just set `minConnections` to `0` if you don't want to keep a minimum number of connections open.

**Before**

```js
import { createLibp2p } from 'libp2p'

const node = await createLibp2p({
  // ... other options
  connectionManager: {
    autoDial: false,
    minConnections: 10,
    maxConnections: 100
  }
}
```

**After**

```js
import { createLibp2p } from 'libp2p'

const node = await createLibp2p({
  // ... other options
  connectionManager: {
    minConnections: 0,
    maxConnections: 100
  }
}
```
