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

Commit

Permalink
feat: limit connections number
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Feb 7, 2019
1 parent 7cba3dd commit b36abc3
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@
"joi": "^14.3.0",
"joi-browser": "^13.4.0",
"joi-multiaddr": "^4.0.0",
"libp2p": "~0.24.1",
"libp2p": "libp2p/js-libp2p#master",
"libp2p-bootstrap": "~0.9.3",
"libp2p-crypto": "~0.16.0",
"libp2p-kad-dht": "~0.14.4",
"libp2p-kad-dht": "~0.14.5",
"libp2p-keychain": "~0.3.3",
"libp2p-mdns": "~0.12.0",
"libp2p-mplex": "~0.8.4",
Expand Down
6 changes: 4 additions & 2 deletions src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
}
},
EXPERIMENTAL: {
dht: get(options, 'EXPERIMENTAL.dht', false),
pubsub: get(options, 'EXPERIMENTAL.pubsub', false)
}
},
connectionManager: get(options, 'connectionManager',
get(config, 'connectionManager', {}))
{
maxPeers: get(config, 'Swarm.ConnMgr.HighWater'),
minPeers: get(config, 'Swarm.ConnMgr.LowWater')
})
}

const libp2pOptions = defaultsDeep(get(options, 'libp2p', {}), libp2pDefaults)
Expand Down
8 changes: 7 additions & 1 deletion src/core/runtime/config-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ module.exports = () => ({
'/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
'/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
]
],
Swarm: {
ConnMgr: {
LowWater: 600,
HighWater: 900
}
}
})
8 changes: 7 additions & 1 deletion src/core/runtime/config-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@ module.exports = () => ({
'/ip6/2604:a880:1:20::1d9:6001/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx',
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
'/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
]
],
Swarm: {
ConnMgr: {
LowWater: 600,
HighWater: 900
}
}
})
5 changes: 3 additions & 2 deletions src/core/runtime/libp2p-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const WebSocketStarMulti = require('libp2p-websocket-star-multi')
const Multiplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio')
const Bootstrap = require('libp2p-bootstrap')
const KadDHT = require('libp2p-kad-dht')
const libp2p = require('libp2p')
const defaultsDeep = require('@nodeutils/defaults-deep')
const multiaddr = require('multiaddr')
Expand Down Expand Up @@ -37,7 +38,8 @@ class Node extends libp2p {
wrtcstar.discovery,
wsstar.discovery,
Bootstrap
]
],
dht: KadDHT
},
config: {
peerDiscovery: {
Expand All @@ -52,7 +54,6 @@ class Node extends libp2p {
}
},
EXPERIMENTAL: {
dht: false,
pubsub: false
}
}
Expand Down
1 change: 0 additions & 1 deletion src/core/runtime/libp2p-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class Node extends libp2p {
kBucketSize: 20
},
EXPERIMENTAL: {
dht: false,
pubsub: false
}
}
Expand Down
8 changes: 3 additions & 5 deletions test/core/libp2p.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const PeerBook = require('peer-book')
const WebSocketStar = require('libp2p-websocket-star')
const Multiplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio')
const KadDHT = require('libp2p-kad-dht')
const Libp2p = require('libp2p')

const libp2pComponent = require('../../src/core/components/libp2p')
Expand Down Expand Up @@ -43,7 +44,6 @@ describe('libp2p customization', function () {
}
},
EXPERIMENTAL: {
dht: false,
pubsub: false
}
}
Expand Down Expand Up @@ -92,7 +92,8 @@ describe('libp2p customization', function () {
],
peerDiscovery: [
wsstar.discovery
]
],
dht: KadDHT
}
})
}
Expand Down Expand Up @@ -142,7 +143,6 @@ describe('libp2p customization', function () {
}
},
EXPERIMENTAL: {
dht: false,
pubsub: false
}
})
Expand Down Expand Up @@ -170,7 +170,6 @@ describe('libp2p customization', function () {
}
},
EXPERIMENTAL: {
dht: false,
pubsub: true
},
libp2p: {
Expand Down Expand Up @@ -207,7 +206,6 @@ describe('libp2p customization', function () {
}
},
EXPERIMENTAL: {
dht: false,
pubsub: true
}
})
Expand Down

0 comments on commit b36abc3

Please sign in to comment.