libp2pclient

package
v0.0.0-...-403c8b4 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: Apache-2.0, MIT Imports: 19 Imported by: 0

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

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 libp2pclient 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, decodeRsp DecodeResponseFunc) error

SendRequest sends out a request.

type DecodeResponseFunc

type DecodeResponseFunc func([]byte) error

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.

Jump to

Keyboard shortcuts

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