Documentation ¶
Overview ¶
Package libp2pclient provides general libp2p client functionality
This package supplies functionality to communicate raw data with libp2p peers, and is useful when building higher-level client that are responsible for processing the data send and and received using this package.
Index ¶
- Variables
- type Client
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context, hostname string) error
- func (c *Client) ConnectAddrs(ctx context.Context, maddrs ...multiaddr.Multiaddr) error
- func (c *Client) Self() peer.ID
- func (c *Client) SendMessage(ctx context.Context, msg proto.Message) error
- func (c *Client) SendRequest(ctx context.Context, msg proto.Message, decodeRsp DecodeResponseFunc) error
- type DecodeResponseFunc
Constants ¶
This section is empty.
Variables ¶
var ErrReadTimeout = fmt.Errorf("timed out reading response")
ErrReadTimeout is an error that occurs when no message is read within the timeout period
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is responsible for sending requests and receiving responses to and from libp2p peers. Each instance of Client communicates with a single peer using a single protocolID.
func New ¶
New creates a new libp2pclient Client that communicates with a specific peer identified by protocolID. If host is nil, then one is created.
func (*Client) Connect ¶
Connect connects the client to the host at the location specified by hostname. The value of hostname is a host or host:port, where the host is a hostname or IP address.
func (*Client) ConnectAddrs ¶
func (*Client) SendMessage ¶
SendMessage sends out a message
func (*Client) SendRequest ¶
func (c *Client) SendRequest(ctx context.Context, msg proto.Message, decodeRsp DecodeResponseFunc) error
SendRequest sends out a request.
type DecodeResponseFunc ¶
DecodeResponseFunc is a function that is passed into this generic libp2p Client to decode a response message. This is needed because the generic client cannot decode the response message since the message is of a type only know to a specific libp2p client using this generic client.