Documentation ¶
Overview ¶
Package p2ptest defines utilities for qri peer-2-peer testing
Index ¶
- func ConnectNodes(ctx context.Context, nodes []TestablePeerNode) error
- func GetSomeBlocks(capi coreiface.CoreAPI, ref reporef.DatasetRef, num int) []string
- func MakeIPFSNode(ctx context.Context) (*core.IpfsNode, coreiface.CoreAPI, error)
- func MakeIPFSSwarm(ctx context.Context, fullIdentity bool, n int) ([]*core.IpfsNode, []coreiface.CoreAPI, error)
- func MakeRepoFromIPFSNode(ctx context.Context, node *core.IpfsNode, username string, bus event.Bus) (qrirepo.Repo, error)
- type NodeMakerFunc
- type TestNodeFactory
- type TestablePeerNode
- func NewAvailableTestNode(ctx context.Context, r repo.Repo, f *TestNodeFactory) (TestablePeerNode, error)
- func NewNodeWithBus(ctx context.Context, f *TestNodeFactory, bus event.Publisher) (TestablePeerNode, error)
- func NewTestDirNetwork(ctx context.Context, f *TestNodeFactory) ([]TestablePeerNode, error)
- func NewTestNetwork(ctx context.Context, f *TestNodeFactory, num int) ([]TestablePeerNode, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectNodes ¶
func ConnectNodes(ctx context.Context, nodes []TestablePeerNode) error
ConnectNodes creates a basic connection between the nodes. This connection mirrors the connection that would normally occur between two p2p nodes. The Host.Connect function adds the addresses into the peerstore and dials the remote peer. Take a look at https://github.com/libp2p/go-libp2p-core/host/blob/623ffaa4ef2b8dad77933159d0848a393a91c41e/host.go#L36 for more info Connect should always: - add a connections to the peer - add the addrs of the peer to the peerstore - add a tag for each peer in the connmanager
func GetSomeBlocks ¶ added in v0.9.3
GetSomeBlocks returns a list of num ids for blocks that are in the referenced dataset.
func MakeIPFSNode ¶ added in v0.9.1
MakeIPFSNode creates a single mock IPFS Node
Types ¶
type NodeMakerFunc ¶
NodeMakerFunc is a function that constructs a Node from a Repo and options.
type TestNodeFactory ¶ added in v0.5.2
type TestNodeFactory struct {
// contains filtered or unexported fields
}
TestNodeFactory can be used to safetly construct nodes for tests
func NewTestNodeFactory ¶ added in v0.5.2
func NewTestNodeFactory(maker NodeMakerFunc) *TestNodeFactory
NewTestNodeFactory returns a new TestNodeFactory
func NewTestNodeFactoryWithBus ¶ added in v0.9.10
func NewTestNodeFactoryWithBus(maker NodeMakerFunc) *TestNodeFactory
NewTestNodeFactoryWithBus returns a new TestNodeFactory with non nil buses
func (*TestNodeFactory) New ¶ added in v0.5.2
func (f *TestNodeFactory) New(r repo.Repo) (TestablePeerNode, error)
New creates a new Node for testing
func (*TestNodeFactory) NewWithConf ¶ added in v0.5.2
func (f *TestNodeFactory) NewWithConf(r repo.Repo, p2pconf *config.P2P) (TestablePeerNode, error)
NewWithConf creates a new Node for testing using a configuration
func (*TestNodeFactory) NextKeyData ¶ added in v0.10.0
func (f *TestNodeFactory) NextKeyData() *testkeys.KeyData
NextKeyData gets the KeyData for the next test Node to be constructed
type TestablePeerNode ¶
type TestablePeerNode interface { Host() host.Host SimpleAddrInfo() peer.AddrInfo GoOnline(ctx context.Context) error }
TestablePeerNode is used by tests only. Implemented by QriNode
func NewAvailableTestNode ¶ added in v0.5.2
func NewAvailableTestNode(ctx context.Context, r repo.Repo, f *TestNodeFactory) (TestablePeerNode, error)
NewAvailableTestNode constructs a test node that is hooked up and ready to Connect
func NewNodeWithBus ¶ added in v0.9.12
func NewNodeWithBus(ctx context.Context, f *TestNodeFactory, bus event.Publisher) (TestablePeerNode, error)
NewNodeWithBus constructs the next node in the factory, but with the given bus, helpful for tests where you need to subscribe to specific events in order to coordiate timing
func NewTestDirNetwork ¶
func NewTestDirNetwork(ctx context.Context, f *TestNodeFactory) ([]TestablePeerNode, error)
NewTestDirNetwork constructs nodes from the testdata directory, for p2p testing Peers are pulled from the "testdata" directory, and come pre-populated with datasets no peers are connected.
func NewTestNetwork ¶
func NewTestNetwork(ctx context.Context, f *TestNodeFactory, num int) ([]TestablePeerNode, error)
NewTestNetwork constructs nodes to test p2p functionality. each of these peers has no datasets and no peers are connected