p2p

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadResponseType is returned when a call to a peer returns an
	// unexpected response type.
	ErrBadResponseType = errors.New("bad response type")
)

Functions

This section is empty.

Types

type Encoder

type Encoder interface {
	Encode(interface{}) error
}

Encoder is an interface that implements an Encode method.

type P2P

type P2P interface {
	// RequestHeaderByHash request a header given its hash from a peer.
	RequestHeaderByHash(ctx context.Context, peerID peer.ID, hash []byte) (*pb.Header, error)

	// RequestBlockByHash request a block given its header's hash from a peer.
	RequestBlockByHash(ctx context.Context, peerID peer.ID, hash []byte) (*pb.Block, error)

	// RequestHeadersByNumber request a batch of headers within a range in the main branch of a peer.
	RequestHeadersByNumber(ctx context.Context, peerID peer.ID, from, amount uint64) ([]*pb.Header, error)

	// RequestHeadersByNumber request a batch of blocks within a range in the main branch of a peer.
	RequestBlocksByNumber(ctx context.Context, peerID peer.ID, from, amount uint64) ([]*pb.Block, error)

	// RespondHeaderByHash responds to a HeaderRequest.
	RespondHeaderByHash(ctx context.Context, req *pb.HeaderRequest, enc Encoder, chain chain.Reader) error

	// RespondHeadersByNumber responds to a HeadersRequest.
	RespondHeadersByNumber(ctx context.Context, req *pb.HeadersRequest, enc Encoder, c chain.Reader) error

	// RespondBlockByHash responds to a BlockRequest.
	RespondBlockByHash(ctx context.Context, req *pb.BlockRequest, enc Encoder, chain chain.Reader) error

	// RespondBlocksByNumber responds to a BlocksRequest.
	RespondBlocksByNumber(ctx context.Context, req *pb.BlocksRequest, enc Encoder, c chain.Reader) error
}

P2P is where the p2p APIs are defined.

func NewP2P

func NewP2P(host ihost.Host, p protocol.ID) P2P

NewP2P returns a new p2p handler.

Directories

Path Synopsis
Package mockencoder is a generated GoMock package.
Package mockencoder is a generated GoMock package.
Package mockp2p is a generated GoMock package.
Package mockp2p is a generated GoMock package.

Jump to

Keyboard shortcuts

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