p2pclient

package
v0.0.0-...-ce94876 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2019 License: MIT, Apache-2.0, MIT Imports: 17 Imported by: 0

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(controlPath, listenPath string) (*Client, error)

NewClient creates a new libp2p daemon client, connecting to a daemon listening on a unix socket at controlPath, and establishing an inbound socket at listenPath.

func (*Client) Close

func (c *Client) Close() error

Close stops the listener socket.

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) FindPeersConnectedToPeer

func (c *Client) FindPeersConnectedToPeer(ctx context.Context, peer peer.ID) (<-chan PeerInfo, error)

FindPeersConnectedToPeer queries the DHT for peers that have an active connection to a given peer.

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) 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) 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 unix socket 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) 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.

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