testpeer

package
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: Apache-2.0, MIT Imports: 50 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectPeers

func ConnectPeers(instances []TestPeer)

ConnectPeers connects the given peers to each other

func MockIpfsHandler added in v0.10.0

func MockIpfsHandler(ctx context.Context, lsys linking.LinkSystem) func(http.ResponseWriter, *http.Request)

func RandTestPeerIdentity added in v0.12.1

func RandTestPeerIdentity() (tnet.Identity, error)

RandTestPeerIdentity is a wrapper around github.com/libp2p/go-libp2p-testing/netutil/RandTestBogusIdentity that ensures the returned identity has an available port. The identity generated by netutil/RandTestBogusIdentity is not guaranteed to have an available port, so we use a net.Listen to check if the port is available and try again if it's not.

func StartAndWaitForReady added in v0.5.0

func StartAndWaitForReady(ctx context.Context, manager datatransfer.Manager) error

Types

type PeerOption added in v0.17.0

type PeerOption func(*peerConfig)

func WithLinkSystem added in v0.17.0

func WithLinkSystem(lsys linking.LinkSystem) PeerOption

type TestPeer

type TestPeer struct {
	ID                 peer.ID
	BitswapServer      *server.Server
	BitswapNetwork     bsnet.BitSwapNetwork
	DatatransferServer datatransfer.Manager
	HttpServer         *TestPeerHttpServer

	Host host.Host

	LinkSystem *linking.LinkSystem
	Cids       map[cid.Cid]struct{}
	Protocol   multicodec.Code
	// contains filtered or unexported fields
}

TestPeer is a test instance of bitswap + dependencies for integration testing

func NewTestBitswapPeer added in v0.5.0

func NewTestBitswapPeer(
	ctx context.Context,
	mn mocknet.Mocknet,
	p tnet.Identity,
	netOptions []bsnet.NetOpt,
	bsOptions []server.Option,
	opts ...PeerOption,
) (TestPeer, error)

NewTestBitswapPeer creates a test peer instance.

NB: It's easy make mistakes by providing the same peer ID to two different instances. To safeguard, use the InstanceGenerator to generate instances. It's just a much better idea.

func NewTestGraphsyncPeer added in v0.5.0

func NewTestGraphsyncPeer(ctx context.Context, mn mocknet.Mocknet, p tnet.Identity, opts ...PeerOption) (TestPeer, error)

func NewTestHttpPeer added in v0.10.0

func NewTestHttpPeer(ctx context.Context, mn mocknet.Mocknet, p tnet.Identity, t *testing.T, opts ...PeerOption) (TestPeer, error)

func (TestPeer) AddrInfo added in v0.5.0

func (i TestPeer) AddrInfo() *peer.AddrInfo

func (*TestPeer) Blockstore

func (i *TestPeer) Blockstore() blockstore.Blockstore

Blockstore returns the block store for this test instance

func (*TestPeer) SetBlockstoreLatency

func (i *TestPeer) SetBlockstoreLatency(t time.Duration) time.Duration

SetBlockstoreLatency customizes the artificial delay on receiving blocks from a blockstore test instance.

type TestPeerGenerator

type TestPeerGenerator struct {
	// contains filtered or unexported fields
}

TestPeerGenerator generates new test peers bitswap+dependencies TODO: add graphsync/markets stack, make protocols choosable

func NewTestPeerGenerator

func NewTestPeerGenerator(ctx context.Context, t *testing.T, mn mocknet.Mocknet, netOptions []bsnet.NetOpt, bsOptions []server.Option) TestPeerGenerator

NewTestPeerGenerator generates a new TestPeerGenerator for the given mocknet

func (*TestPeerGenerator) BitswapPeers added in v0.5.0

func (g *TestPeerGenerator) BitswapPeers(n int, opts ...PeerOption) []TestPeer

BitswapPeers creates N test peers with bitswap + dependencies

func (*TestPeerGenerator) Close

func (g *TestPeerGenerator) Close() error

Close closes the clobal context, shutting down all test peers

func (*TestPeerGenerator) GraphsyncPeers added in v0.5.0

func (g *TestPeerGenerator) GraphsyncPeers(n int, opts ...PeerOption) []TestPeer

GraphsyncPeers creates N test peers with graphsync + dependencies

func (*TestPeerGenerator) HttpPeers added in v0.10.0

func (g *TestPeerGenerator) HttpPeers(n int, opts ...PeerOption) []TestPeer

HttpPeers creates N test peers with http + dependencies

func (*TestPeerGenerator) NextBitswap added in v0.5.0

func (g *TestPeerGenerator) NextBitswap(opts ...PeerOption) TestPeer

NextBitswap generates a new test peer with bitswap + dependencies

func (*TestPeerGenerator) NextGraphsync added in v0.5.0

func (g *TestPeerGenerator) NextGraphsync(opts ...PeerOption) TestPeer

NextGraphsync generates a new test peer with graphsync + dependencies

func (*TestPeerGenerator) NextHttp added in v0.10.0

func (g *TestPeerGenerator) NextHttp(opts ...PeerOption) TestPeer

NextHttp generates a new test peer with http + dependencies

type TestPeerHttpServer added in v0.10.0

type TestPeerHttpServer struct {
	Mux *http.ServeMux
	// contains filtered or unexported fields
}

func NewTestPeerHttpServer added in v0.10.0

func NewTestPeerHttpServer(ctx context.Context, host string, port string) (*TestPeerHttpServer, error)

NewTestPeerHttpServer creates a new HttpServer

func (*TestPeerHttpServer) Close added in v0.10.0

func (s *TestPeerHttpServer) Close() error

Close shutsdown the server and cancels the server context

func (*TestPeerHttpServer) Start added in v0.10.0

func (s *TestPeerHttpServer) Start() error

Start starts the http server, returning an error if the server failed to start

Jump to

Keyboard shortcuts

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