Skip to content

Commit b621fbd

Browse files
committed
revert: "fix: throw if no conn encryption module provided (#665)"
This reverts commit c038550.
1 parent 24dd1d2 commit b621fbd

File tree

8 files changed

+22
-91
lines changed

8 files changed

+22
-91
lines changed

doc/API.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ Creates an instance of Libp2p.
8585
| Name | Type | Description |
8686
|------|------|-------------|
8787
| options | `object` | libp2p options |
88-
| options.modules | [`Array<object>`](./CONFIGURATION.md#modules) | libp2p [modules](./CONFIGURATION.md#modules) to use |
88+
| options.modules | [`Array<object>`](./CONFIGURATION.md#modules) | libp2p modules to use |
8989
| [options.addresses] | `{ listen: Array<string>, announce: Array<string>, noAnnounce: Array<string> }` | Addresses for transport listening and to advertise to the network |
9090
| [options.config] | `object` | libp2p modules configuration and core configuration |
91-
| [options.connectionManager] | [`object`](./CONFIGURATION.md#configuring-connection-manager) | libp2p Connection Manager [configuration](./CONFIGURATION.md#configuring-connection-manager) |
92-
| [options.transportManager] | [`object`](./CONFIGURATION.md#configuring-transport-manager) | libp2p transport manager [configuration]((./CONFIGURATION.md#configuring-transport-manager)) |
91+
| [options.connectionManager] | [`object`](./CONFIGURATION.md#configuring-connection-manager) | libp2p Connection Manager configuration |
92+
| [options.transportManager] | [`object`](./CONFIGURATION.md#configuring-transport-manager) | libp2p transport manager configuration |
9393
| [options.datastore] | `object` | must implement [ipfs/interface-datastore](https://github.com/ipfs/interface-datastore) (in memory datastore will be used if not provided) |
94-
| [options.dialer] | [`object`](./CONFIGURATION.md#configuring-dialing) | libp2p Dialer [configuration]((./CONFIGURATION.md#configuring-dialing))
95-
| [options.keychain] | [`object`](./CONFIGURATION.md#setup-with-keychain) | keychain [configuration]((./CONFIGURATION.md#setup-with-keychain)) |
96-
| [options.metrics] | [`object`](./CONFIGURATION.md#configuring-metrics) | libp2p Metrics [configuration]((./CONFIGURATION.md#configuring-metrics)) |
94+
| [options.dialer] | [`object`](./CONFIGURATION.md#configuring-dialing) | libp2p Dialer configuration
95+
| [options.keychain] | [`object`](./CONFIGURATION.md#setup-with-keychain) | keychain configuration |
96+
| [options.metrics] | [`object`](./CONFIGURATION.md#configuring-metrics) | libp2p Metrics configuration
9797
| [options.peerId] | [`PeerId`][peer-id] | peerId instance (it will be created if not provided) |
98-
| [options.peerStore] | [`object`](./CONFIGURATION.md#configuring-peerstore) | libp2p PeerStore [configuration]((./CONFIGURATION.md#configuring-peerstore)) |
98+
| [options.peerStore] | [`object`](./CONFIGURATION.md#configuring-peerstore) | libp2p PeerStore configuration |
9999

100100
For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md).
101101

doc/CONFIGURATION.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The libp2p ecosystem contains at least one module for each of these subsystems.
5252

5353
After selecting the modules to use, it is also possible to configure each one according to your needs.
5454

55-
Bear in mind that a **transport** and **connection encryption** are **required**, while all the other subsystems are optional.
55+
Bear in mind that only a **transport** and **connection encryption** are required, while all the other subsystems are optional.
5656

5757
### Transport
5858

examples/discovery-mechanisms/2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const createNode = async () => {
2121
},
2222
config: {
2323
peerDiscovery: {
24-
[MulticastDNS.tag]: {
24+
mdns: {
2525
interval: 20e3,
2626
enabled: true
2727
}

src/errors.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
exports.messages = {
44
NOT_STARTED_YET: 'The libp2p node is not started yet',
5-
DHT_DISABLED: 'DHT is not available',
6-
CONN_ENCRYPTION_REQUIRED: 'At least one connection encryption module is required'
5+
DHT_DISABLED: 'DHT is not available'
76
}
87

98
exports.codes = {
109
DHT_DISABLED: 'ERR_DHT_DISABLED',
1110
PUBSUB_NOT_STARTED: 'ERR_PUBSUB_NOT_STARTED',
1211
DHT_NOT_STARTED: 'ERR_DHT_NOT_STARTED',
13-
CONN_ENCRYPTION_REQUIRED: 'ERR_CONN_ENCRYPTION_REQUIRED',
1412
ERR_CONNECTION_ENDED: 'ERR_CONNECTION_ENDED',
1513
ERR_CONNECTION_FAILED: 'ERR_CONNECTION_FAILED',
1614
ERR_NODE_NOT_STARTED: 'ERR_NODE_NOT_STARTED',

src/index.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ const globalThis = require('ipfs-utils/src/globalthis')
66
const log = debug('libp2p')
77
log.error = debug('libp2p:error')
88

9-
const errCode = require('err-code')
109
const PeerId = require('peer-id')
1110

1211
const peerRouting = require('./peer-routing')
1312
const contentRouting = require('./content-routing')
1413
const pubsub = require('./pubsub')
1514
const getPeer = require('./get-peer')
1615
const { validate: validateConfig } = require('./config')
17-
const { codes, messages } = require('./errors')
16+
const { codes } = require('./errors')
1817

1918
const AddressManager = require('./address-manager')
2019
const ConnectionManager = require('./connection-manager')
@@ -116,13 +115,12 @@ class Libp2p extends EventEmitter {
116115
this.registrar.handle = this.handle
117116

118117
// Attach crypto channels
119-
if (!this._modules.connEncryption || !this._modules.connEncryption.length) {
120-
throw errCode(new Error(messages.CONN_ENCRYPTION_REQUIRED), codes.CONN_ENCRYPTION_REQUIRED)
118+
if (this._modules.connEncryption) {
119+
const cryptos = this._modules.connEncryption
120+
cryptos.forEach((crypto) => {
121+
this.upgrader.cryptos.set(crypto.protocol, crypto)
122+
})
121123
}
122-
const cryptos = this._modules.connEncryption
123-
cryptos.forEach((crypto) => {
124-
this.upgrader.cryptos.set(crypto.protocol, crypto)
125-
})
126124

127125
this.dialer = new Dialer({
128126
transportManager: this.transportManager,

test/core/encryption.spec.js

-57
This file was deleted.

test/core/listening.node.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ chai.use(require('dirty-chai'))
66
const { expect } = chai
77

88
const Transport = require('libp2p-tcp')
9-
const { NOISE: Crypto } = require('libp2p-noise')
109

1110
const { create } = require('../../src')
1211
const peerUtils = require('../utils/creators/peer')
@@ -32,8 +31,7 @@ describe('Listening', () => {
3231
listen: [listenAddr]
3332
},
3433
modules: {
35-
transport: [Transport],
36-
connEncryption: [Crypto]
34+
transport: [Transport]
3735
}
3836
})
3937

test/transports/transport-manager.spec.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const sinon = require('sinon')
99

1010
const multiaddr = require('multiaddr')
1111
const Transport = require('libp2p-websockets')
12-
const { NOISE: Crypto } = require('libp2p-noise')
1312
const AddressManager = require('../../src/address-manager')
1413
const TransportManager = require('../../src/transport-manager')
1514
const mockUpgrader = require('../utils/mockUpgrader')
@@ -111,8 +110,7 @@ describe('libp2p.transportManager', () => {
111110
libp2p = new Libp2p({
112111
peerId,
113112
modules: {
114-
transport: [Transport],
115-
connEncryption: [Crypto]
113+
transport: [Transport]
116114
}
117115
})
118116

@@ -130,8 +128,7 @@ describe('libp2p.transportManager', () => {
130128
libp2p = new Libp2p({
131129
peerId,
132130
modules: {
133-
transport: [spy],
134-
connEncryption: [Crypto]
131+
transport: [spy]
135132
},
136133
config: {
137134
transport: {
@@ -155,8 +152,7 @@ describe('libp2p.transportManager', () => {
155152
libp2p = new Libp2p({
156153
peerId,
157154
modules: {
158-
transport: [Transport],
159-
connEncryption: [Crypto]
155+
transport: [Transport]
160156
}
161157
})
162158

@@ -192,8 +188,7 @@ describe('libp2p.transportManager (dial only)', () => {
192188
listen: [multiaddr('/ip4/127.0.0.1/tcp/0')]
193189
},
194190
modules: {
195-
transport: [Transport],
196-
connEncryption: [Crypto]
191+
transport: [Transport]
197192
}
198193
})
199194

@@ -217,8 +212,7 @@ describe('libp2p.transportManager (dial only)', () => {
217212
faultTolerance: FaultTolerance.NO_FATAL
218213
},
219214
modules: {
220-
transport: [Transport],
221-
connEncryption: [Crypto]
215+
transport: [Transport]
222216
}
223217
})
224218

0 commit comments

Comments
 (0)