mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-27 16:01:32 +00:00
feat: connection gater (#1142)
Port of https://github.com/libp2p/go-libp2p-core/blob/master/connmgr/gater.go Adds a new configuration key `connectionGater` which allows denying the dialing of certain peers, individual multiaddrs and the creation of connections at certain points in the connection flow. Fixes: https://github.com/libp2p/js-libp2p/issues/175 Refs: https://github.com/libp2p/js-libp2p/issues/744 Refs: https://github.com/libp2p/js-libp2p/issues/769 Co-authored-by: mzdws <8580712+mzdws@user.noreply.gitee.com>
This commit is contained in:
19
test/utils/mock-connection-gater.js
Normal file
19
test/utils/mock-connection-gater.js
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict'
|
||||
|
||||
function mockConnectionGater () {
|
||||
return {
|
||||
denyDialPeer: async () => Promise.resolve(false),
|
||||
denyDialMultiaddr: async () => Promise.resolve(false),
|
||||
denyInboundConnection: async () => Promise.resolve(false),
|
||||
denyOutboundConnection: async () => Promise.resolve(false),
|
||||
denyInboundEncryptedConnection: async () => Promise.resolve(false),
|
||||
denyOutboundEncryptedConnection: async () => Promise.resolve(false),
|
||||
denyInboundUpgradedConnection: async () => Promise.resolve(false),
|
||||
denyOutboundUpgradedConnection: async () => Promise.resolve(false),
|
||||
filterMultiaddrForPeer: async () => Promise.resolve(true)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mockConnectionGater
|
||||
}
|
Reference in New Issue
Block a user