libp2p-switch
0.37.2

- Intro
- LimitDialer
- Instance
  - dialMany
  - dialSingle
- DialQueue
- Instance
  - push

# Intro

Installable via `npm install --save libp2p-switch`, it can also be used directly in the browser.

## Download

The source is available for download from GitHub. Alternatively, you can install using npm:

    $ npm install --save libp2p-switch

You can then `require()` libp2p-switch as normal:

    const libp2PSwitch = require('libp2p-switch')

## In the Browser

Libp2p-switch should work in any ES2015 environment out of the box.

Usage:

    <script type="text/javascript" src="index.js"></script>

The portable versions of libp2p-switch, including `index.js` and `index.min.js`, are included in the `/dist` folder. Libp2p-switch can also be found on unkpkg.com under

- https://unpkg.com/libp2p-switch/dist/index.min.js
- https://unpkg.com/libp2p-switch/dist/index.js

# LimitDialer

Track dials per peer and limited them.

#### Parameters

1. `perPeerLimit: number`:
2. `dialTimeout: number`:

## instance

### LimitDialer.prototype.dialMany

    dialMany(peer: PeerId, transport: SwarmTransport, addrs: Array<Multiaddr>, callback: function (Error, Connection)): void

Dial a list of multiaddrs on the given transport.

#### Parameters

1. `peer: PeerId`:
2. `transport: SwarmTransport`:
3. `addrs: Array<Multiaddr>`:
4. `callback: function (Error, Connection)`:

#### Returns

`void`

### LimitDialer.prototype.dialSingle

    dialSingle(peer: PeerId, transport: SwarmTransport, addr: Multiaddr, token: CancelToken, callback: function (Error, Connection)): void

Dial a single multiaddr on the given transport.

#### Parameters

1. `peer: PeerId`:
2. `transport: SwarmTransport`:
3. `addr: Multiaddr`:
4. `token: CancelToken`:
5. `callback: function (Error, Connection)`:

#### Returns

`void`

# DialQueue

Queue up the amount of dials to a given peer.

#### Parameters

1. `limit: number`:
2. `dialTimeout: number`:

## instance

### DialQueue.prototype.push

    push(transport: SwarmTransport, addr: Multiaddr, token: CancelToken, callback: function (Error, Connection)): void

Add new work to the queue.

#### Parameters

1. `transport: SwarmTransport`:
2. `addr: Multiaddr`:
3. `token: CancelToken`:
4. `callback: function (Error, Connection)`:

#### Returns

`void`