p2ptest

package
v0.9.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2020 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Overview

Package p2ptest defines utilities for qri peer-2-peer testing

Index

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 ConnectQriNodes added in v0.6.0

func ConnectQriNodes(ctx context.Context, nodes []TestablePeerNode) error

ConnectQriNodes takes a slice of unconnected nodes and returns a slice of connected nodes that have upgraded qri connections: They support the qri protocol and have exchanged profile

func GetSomeBlocks added in v0.9.3

func GetSomeBlocks(capi coreiface.CoreAPI, ref reporef.DatasetRef, num int) []string

GetSomeBlocks returns a list of num ids for blocks that are in the referenced dataset.

func MakeIPFSNode added in v0.9.1

func MakeIPFSNode(ctx context.Context) (*core.IpfsNode, coreiface.CoreAPI, error)

MakeIPFSNode creates a single mock IPFS Node

func MakeIPFSSwarm added in v0.9.1

func MakeIPFSSwarm(ctx context.Context, fullIdentity bool, n int) ([]*core.IpfsNode, []coreiface.CoreAPI, error)

MakeIPFSSwarm creates and connects n number of mock IPFS Nodes

func MakeRepoFromIPFSNode added in v0.9.1

func MakeRepoFromIPFSNode(node *core.IpfsNode, username string) (qrirepo.Repo, error)

MakeRepoFromIPFSNode wraps an ipfs node with a mock qri repo

Types

type NodeMakerFunc

type NodeMakerFunc func(repo.Repo, *config.P2P) (TestablePeerNode, error)

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 (*TestNodeFactory) New added in v0.5.2

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) NextInfo added in v0.5.2

func (f *TestNodeFactory) NextInfo() *cfgtest.PeerInfo

NextInfo gets the PeerInfo for the next test Node to be constructed

type TestablePeerNode

type TestablePeerNode interface {
	Host() host.Host
	SimplePeerInfo() pstore.PeerInfo
	UpgradeToQriConnection(pstore.PeerInfo) error
	GoOnline() error
}

TestablePeerNode is used by tests only. Implemented by QriNode

func NewAvailableTestNode added in v0.5.2

func NewAvailableTestNode(r repo.Repo, f *TestNodeFactory) (TestablePeerNode, error)

NewAvailableTestNode constructs a test node that is hooked up and ready to Connect

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL