package testing
import "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
Index ¶
- func DivulgeAddresses(a, b network.Network)
- func GenSwarm(t testing.TB, opts ...Option) *swarm.Swarm
- func GenUpgrader(t testing.TB, n *swarm.Swarm, connGater connmgr.ConnectionGater, opts ...tptu.Option) transport.Upgrader
- type MockConnectionGater
- func DefaultMockConnectionGater() *MockConnectionGater
- func (m *MockConnectionGater) InterceptAccept(c network.ConnMultiaddrs) (allow bool)
- func (m *MockConnectionGater) InterceptAddrDial(p peer.ID, addr ma.Multiaddr) (allow bool)
- func (m *MockConnectionGater) InterceptPeerDial(p peer.ID) (allow bool)
- func (m *MockConnectionGater) InterceptSecured(d network.Direction, p peer.ID, c network.ConnMultiaddrs) (allow bool)
- func (m *MockConnectionGater) InterceptUpgraded(tc network.Conn) (allow bool, reason control.DisconnectReason)
- type Option
Functions ¶
func DivulgeAddresses ¶
DivulgeAddresses adds swarm a's addresses to swarm b's peerstore.
func GenSwarm ¶
GenSwarm generates a new test swarm.
func GenUpgrader ¶
func GenUpgrader(t testing.TB, n *swarm.Swarm, connGater connmgr.ConnectionGater, opts ...tptu.Option) transport.Upgrader
GenUpgrader creates a new connection upgrader for use with this swarm.
Types ¶
type MockConnectionGater ¶
type MockConnectionGater struct { Dial func(p peer.ID, addr ma.Multiaddr) bool PeerDial func(p peer.ID) bool Accept func(c network.ConnMultiaddrs) bool Secured func(network.Direction, peer.ID, network.ConnMultiaddrs) bool Upgraded func(c network.Conn) (bool, control.DisconnectReason) }
MockConnectionGater is a mock connection gater to be used by the tests.
func DefaultMockConnectionGater ¶
func DefaultMockConnectionGater() *MockConnectionGater
func (*MockConnectionGater) InterceptAccept ¶
func (m *MockConnectionGater) InterceptAccept(c network.ConnMultiaddrs) (allow bool)
func (*MockConnectionGater) InterceptAddrDial ¶
func (*MockConnectionGater) InterceptPeerDial ¶
func (m *MockConnectionGater) InterceptPeerDial(p peer.ID) (allow bool)
func (*MockConnectionGater) InterceptSecured ¶
func (m *MockConnectionGater) InterceptSecured(d network.Direction, p peer.ID, c network.ConnMultiaddrs) (allow bool)
func (*MockConnectionGater) InterceptUpgraded ¶
func (m *MockConnectionGater) InterceptUpgraded(tc network.Conn) (allow bool, reason control.DisconnectReason)
type Option ¶
Option is an option that can be passed when constructing a test swarm.
OptDialOnly prevents the test swarm from listening.
OptDisableQUIC disables QUIC.
OptDisableReuseport disables reuseport in this test swarm.
OptDisableTCP disables TCP.
OptDisableWebRTC disables WebRTC.
OptDisableWebTransport disables WebTransport.
func EventBus ¶
func OptConnGater ¶
func OptConnGater(cg connmgr.ConnectionGater) Option
OptConnGater configures the given connection gater on the test
func OptPeerPrivateKey ¶
OptPeerPrivateKey configures the peer private key which is then used to derive the public key and peer ID.
func WithClock ¶
func WithClock(clock clock) Option
WithClock sets the clock to use for this swarm
func WithSwarmOpts ¶
Source Files ¶
- Version
- v0.42.0 (latest)
- Published
- Jun 18, 2025
- Platform
- linux/amd64
- Imports
- 28 packages
- Last checked
- 1 week ago –
Tools for package owners.