Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit b36abc3

Browse files
committed
feat: limit connections number
1 parent 7cba3dd commit b36abc3

File tree

7 files changed

+26
-14
lines changed

7 files changed

+26
-14
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@
129129
"joi": "^14.3.0",
130130
"joi-browser": "^13.4.0",
131131
"joi-multiaddr": "^4.0.0",
132-
"libp2p": "~0.24.1",
132+
"libp2p": "libp2p/js-libp2p#master",
133133
"libp2p-bootstrap": "~0.9.3",
134134
"libp2p-crypto": "~0.16.0",
135-
"libp2p-kad-dht": "~0.14.4",
135+
"libp2p-kad-dht": "~0.14.5",
136136
"libp2p-keychain": "~0.3.3",
137137
"libp2p-mdns": "~0.12.0",
138138
"libp2p-mplex": "~0.8.4",

src/core/components/libp2p.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
8484
}
8585
},
8686
EXPERIMENTAL: {
87-
dht: get(options, 'EXPERIMENTAL.dht', false),
8887
pubsub: get(options, 'EXPERIMENTAL.pubsub', false)
8988
}
9089
},
9190
connectionManager: get(options, 'connectionManager',
92-
get(config, 'connectionManager', {}))
91+
{
92+
maxPeers: get(config, 'Swarm.ConnMgr.HighWater'),
93+
minPeers: get(config, 'Swarm.ConnMgr.LowWater')
94+
})
9395
}
9496

9597
const libp2pOptions = defaultsDeep(get(options, 'libp2p', {}), libp2pDefaults)

src/core/runtime/config-browser.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,11 @@ module.exports = () => ({
2525
'/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
2626
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
2727
'/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
28-
]
28+
],
29+
Swarm: {
30+
ConnMgr: {
31+
LowWater: 600,
32+
HighWater: 900
33+
}
34+
}
2935
})

src/core/runtime/config-nodejs.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,11 @@ module.exports = () => ({
3838
'/ip6/2604:a880:1:20::1d9:6001/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx',
3939
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
4040
'/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
41-
]
41+
],
42+
Swarm: {
43+
ConnMgr: {
44+
LowWater: 600,
45+
HighWater: 900
46+
}
47+
}
4248
})

src/core/runtime/libp2p-browser.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const WebSocketStarMulti = require('libp2p-websocket-star-multi')
66
const Multiplex = require('libp2p-mplex')
77
const SECIO = require('libp2p-secio')
88
const Bootstrap = require('libp2p-bootstrap')
9+
const KadDHT = require('libp2p-kad-dht')
910
const libp2p = require('libp2p')
1011
const defaultsDeep = require('@nodeutils/defaults-deep')
1112
const multiaddr = require('multiaddr')
@@ -37,7 +38,8 @@ class Node extends libp2p {
3738
wrtcstar.discovery,
3839
wsstar.discovery,
3940
Bootstrap
40-
]
41+
],
42+
dht: KadDHT
4143
},
4244
config: {
4345
peerDiscovery: {
@@ -52,7 +54,6 @@ class Node extends libp2p {
5254
}
5355
},
5456
EXPERIMENTAL: {
55-
dht: false,
5657
pubsub: false
5758
}
5859
}

src/core/runtime/libp2p-nodejs.js

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class Node extends libp2p {
5656
kBucketSize: 20
5757
},
5858
EXPERIMENTAL: {
59-
dht: false,
6059
pubsub: false
6160
}
6261
}

test/core/libp2p.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const PeerBook = require('peer-book')
1313
const WebSocketStar = require('libp2p-websocket-star')
1414
const Multiplex = require('libp2p-mplex')
1515
const SECIO = require('libp2p-secio')
16+
const KadDHT = require('libp2p-kad-dht')
1617
const Libp2p = require('libp2p')
1718

1819
const libp2pComponent = require('../../src/core/components/libp2p')
@@ -43,7 +44,6 @@ describe('libp2p customization', function () {
4344
}
4445
},
4546
EXPERIMENTAL: {
46-
dht: false,
4747
pubsub: false
4848
}
4949
}
@@ -92,7 +92,8 @@ describe('libp2p customization', function () {
9292
],
9393
peerDiscovery: [
9494
wsstar.discovery
95-
]
95+
],
96+
dht: KadDHT
9697
}
9798
})
9899
}
@@ -142,7 +143,6 @@ describe('libp2p customization', function () {
142143
}
143144
},
144145
EXPERIMENTAL: {
145-
dht: false,
146146
pubsub: false
147147
}
148148
})
@@ -170,7 +170,6 @@ describe('libp2p customization', function () {
170170
}
171171
},
172172
EXPERIMENTAL: {
173-
dht: false,
174173
pubsub: true
175174
},
176175
libp2p: {
@@ -207,7 +206,6 @@ describe('libp2p customization', function () {
207206
}
208207
},
209208
EXPERIMENTAL: {
210-
dht: false,
211209
pubsub: true
212210
}
213211
})

0 commit comments

Comments
 (0)