p2pclient

package
v0.6.15 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0, MIT Imports: 19 Imported by: 0

Documentation

Overview

Package p2pclient provides general libp2p client functionality

This package supplies functionality to communicate raw data with libp2p peers. It is useful for building higher-level clients that process data which is sent and received by this package.

Index

Constants

This section is empty.

Variables

View Source
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

func New(p2pHost host.Host, peerID peer.ID, protoID protocol.ID) (*Client, error)

New creates a new Client that communicates with a specific peer identified by protocolID. If host is nil, then one is created.

func (*Client) Close

func (c *Client) Close() error

Close resets and closes the network stream if one exists.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context, hostname string) error

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 (c *Client) ConnectAddrs(ctx context.Context, maddrs ...multiaddr.Multiaddr) error

func (*Client) Self

func (c *Client) Self() peer.ID

Self return the peer ID of this client.

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, msg proto.Message) error

SendMessage sends out a message.

func (*Client) SendRequest

func (c *Client) SendRequest(ctx context.Context, msg proto.Message) *Response

SendRequest sends out a request and reads a response.

type Response

type Response struct {
	Data []byte
	Err  error
	// contains filtered or unexported fields
}

Response is returned by SendRequest and contains the response to the request. It is the caller's responsibility to call Response.Close() after reading the data, to free the message buffer.

func (*Response) Close

func (r *Response) Close()

Close frees the message buffer that holds the response data.

Jump to

Keyboard shortcuts

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