p2pclient

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0, MIT Imports: 17 Imported by: 8

Documentation

Index

Constants

View Source
const MessageSizeMax = 1 << 22 // 4 MB

MessageSizeMax is cribbed from github.com/libp2p/go-libp2p-net

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is the struct that manages a connection to a libp2p daemon.

func NewClient

func NewClient(controlMaddr, listenMaddr multiaddr.Multiaddr) (*Client, error)

NewClient creates a new libp2p daemon client, connecting to a daemon listening on a multi-addr at controlMaddr, and establishing an inbound listening multi-address at listenMaddr

func (*Client) Close

func (c *Client) Close() error

Close stops the listener address.

func (*Client) Connect

func (c *Client) Connect(p peer.ID, addrs []multiaddr.Multiaddr) error

Connect establishes a connection to a peer after populating the Peerstore entry for said peer with a list of addresses.

func (*Client) FindPeer

func (c *Client) FindPeer(peer peer.ID) (PeerInfo, error)

FindPeer queries the daemon for a peer's address.

func (*Client) FindProviders

func (c *Client) FindProviders(ctx context.Context, cid cid.Cid) (<-chan PeerInfo, error)

FindProviders queries the DHT for peers that provide a piece of content identified by a CID.

func (*Client) GetClosestPeers

func (c *Client) GetClosestPeers(ctx context.Context, key []byte) (<-chan peer.ID, error)

GetClosestPeers queries the DHT routing table for peers that are closest to a provided key.

func (*Client) GetPublicKey

func (c *Client) GetPublicKey(peer peer.ID) (crypto.PubKey, error)

GetPublicKey queries the daemon for a peer's address.

func (*Client) GetTopics added in v0.0.4

func (c *Client) GetTopics() ([]string, error)

func (*Client) GetValue

func (c *Client) GetValue(key []byte) ([]byte, error)

GetValue queries the daemon for a value stored at a key.

func (*Client) Identify

func (c *Client) Identify() (peer.ID, []multiaddr.Multiaddr, error)

Identify queries the daemon for its peer ID and listen addresses.

func (*Client) ListPeers added in v0.0.4

func (c *Client) ListPeers() ([]peer.ID, error)

func (*Client) NewStream

func (c *Client) NewStream(peer peer.ID, protos []string) (*StreamInfo, io.ReadWriteCloser, error)

NewStream initializes a new stream on one of the protocols in protos with the specified peer.

func (*Client) NewStreamHandler

func (c *Client) NewStreamHandler(protos []string, handler StreamHandlerFunc) error

NewStreamHandler establishes an inbound multi-address and starts a listener. All inbound connections to the listener are delegated to the provided handler.

func (*Client) Provide

func (c *Client) Provide(id cid.Cid) error

Provide announces that our peer provides content described by a CID.

func (*Client) Publish added in v0.0.4

func (c *Client) Publish(topic string, data []byte) error

func (*Client) PutValue

func (c *Client) PutValue(key []byte, value []byte) error

PutValue sets the value stored at a given key in the DHT to a given value.

func (*Client) SearchValue

func (c *Client) SearchValue(ctx context.Context, key []byte) (<-chan []byte, error)

SearchValue queries the DHT for the best/most valid value stored at a key. Later responses are better.

func (*Client) Subscribe added in v0.0.4

func (c *Client) Subscribe(ctx context.Context, topic string) (<-chan *pb.PSMessage, error)

type PeerInfo

type PeerInfo struct {
	// Id is the peer's ID
	ID peer.ID
	// Addrs are the peer's listen addresses.
	Addrs []ma.Multiaddr
}

PeerInfo wraps the PeerInfo message from our protobuf with richer types.

type StreamHandlerFunc

type StreamHandlerFunc func(*StreamInfo, io.ReadWriteCloser)

StreamHandlerFunc is the type of callbacks executed upon receiving a new stream on a given protocol.

type StreamInfo

type StreamInfo struct {
	Peer  peer.ID
	Addr  ma.Multiaddr
	Proto string
}

StreamInfo wraps the protobuf structure with friendlier types.

Jump to

Keyboard shortcuts

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