Documentation ¶
Overview ¶
Package p2p implements qri peer-to-peer communication.
Index ¶
- Constants
- Variables
- func ListPeers(node *QriNode, userID profile.ID, offset, limit int, onlineOnly bool) ([]*config.ProfilePod, error)
- func NewMessageID() string
- func NewTestableQriNode(r repo.Repo, p2pconf *config.P2P, pub event.Publisher) (p2ptest.TestablePeerNode, error)
- func ParseMultiaddrs(addrs []string) (maddrs []ma.Multiaddr, err error)
- type DatasetsListParams
- type HandlerFunc
- type Message
- type MsgType
- type PeerConnectionParams
- type QriNode
- func (n *QriNode) Addrs() peerstore.AddrBook
- func (n *QriNode) Bootstrap(boostrapAddrs []string)
- func (n *QriNode) BootstrapIPFS()
- func (n *QriNode) ClosestConnectedQriPeers(profileID profile.ID, max int) (pid []peer.ID)
- func (n *QriNode) ConnectToPeer(ctx context.Context, p PeerConnectionParams) (*profile.Profile, error)
- func (n *QriNode) ConnectedPeers() []string
- func (n *QriNode) ConnectedQriPeerIDs() []peer.ID
- func (n *QriNode) ConnectedQriProfiles() map[profile.ID]*config.ProfilePod
- func (n *QriNode) DisconnectFromPeer(ctx context.Context, p PeerConnectionParams) error
- func (n *QriNode) EncapsulatedAddresses() []ma.Multiaddr
- func (n *QriNode) GetIPFSNamesys() (namesys.NameSystem, error)
- func (n *QriNode) GoOffline() error
- func (n *QriNode) GoOnline(c context.Context) (err error)
- func (n *QriNode) HandlePeerFound(pinfo peer.AddrInfo)
- func (n *QriNode) Host() host.Host
- func (n *QriNode) IPFS() (*core.IpfsNode, error)
- func (n *QriNode) IPFSCoreAPI() (coreiface.CoreAPI, error)
- func (n *QriNode) Keys() peerstore.KeyBook
- func (n *QriNode) ListenAddresses() ([]string, error)
- func (node *QriNode) MissingManifest(ctx context.Context, m *dag.Manifest) (missing *dag.Manifest, err error)
- func (node *QriNode) NewDAGInfo(ctx context.Context, path, label string) (*dag.Info, error)
- func (node *QriNode) NewManifest(ctx context.Context, path string) (*dag.Manifest, error)
- func (q *QriNode) NewP2PRefResolver() dsref.Resolver
- func (n *QriNode) PeerInfo(pid peer.ID) peer.AddrInfo
- func (n *QriNode) Peers() []peer.ID
- func (n *QriNode) RequestDatasetsList(ctx context.Context, pid peer.ID, p DatasetsListParams) ([]reporef.DatasetRef, error)
- func (n *QriNode) SimpleAddrInfo() peer.AddrInfo
- type QriProfileService
- func (q *QriProfileService) ConnectedPeerProfile(pid peer.ID) *profile.Profile
- func (q *QriProfileService) ConnectedQriPeers() []peer.ID
- func (q *QriProfileService) HandleQriPeerDisconnect(pid peer.ID)
- func (q *QriProfileService) ProfileHandler(s network.Stream)
- func (q *QriProfileService) QriProfileRequest(ctx context.Context, pid peer.ID) error
- func (q *QriProfileService) Start(h host.Host)
- type WrappedStream
Constants ¶
const ( // ProfileProtocolID is the protocol id for the profile exchange service ProfileProtocolID = protocol.ID("/qri/profile/0.1.0") // ProfileTimeout is the length of time we will wait for a response in a // profile exchange ProfileTimeout = time.Minute * 2 )
const MtDatasets = MsgType("list_datasets")
MtDatasets is a dataset list message
const MtProfile = MsgType("profile")
MtProfile is a peer info message
const ( // QriProtocolID is the protocol we use to determing if a node speaks qri // if it speaks the qri protocol, we assume it speaks any of the qri protocols // that we support QriProtocolID = protocol.ID("/qri/0.1.0") )
const ( // ResolveRefProtocolID is the protocol on which qri nodes communicate to // resolve references ResolveRefProtocolID = protocol.ID("/qri/ref/0.1.0") )
Variables ¶
var ( // QriServiceTag marks the type & version of the qri service QriServiceTag = fmt.Sprintf("qri/%s", version.Version) // ErrNotConnected is for a missing required network connection ErrNotConnected = fmt.Errorf("no p2p connection") // ErrQriProtocolNotSupported is returned when a connection can't be upgraded ErrQriProtocolNotSupported = fmt.Errorf("peer doesn't support the qri protocol") // ErrNoQriNode indicates a qri node doesn't exist ErrNoQriNode = fmt.Errorf("p2p: no qri node") )
var ( // ErrPeerNotFound is returned when the profile service cannot find the // peer in question ErrPeerNotFound = fmt.Errorf("peer not found") )
Functions ¶
func ListPeers ¶ added in v0.9.1
func ListPeers(node *QriNode, userID profile.ID, offset, limit int, onlineOnly bool) ([]*config.ProfilePod, error)
ListPeers lists Peers on the qri network userID is the profile identifier of the user making the request
func NewMessageID ¶ added in v0.3.0
func NewMessageID() string
NewMessageID generates a random message identifier
Types ¶
type DatasetsListParams ¶ added in v0.3.0
DatasetsListParams encapsulates options for requesting datasets
type HandlerFunc ¶ added in v0.3.0
type HandlerFunc func(ws *WrappedStream, msg Message) (hangup bool)
HandlerFunc is the signature of a function that can handle p2p messages
type Message ¶
type Message struct { Type MsgType ID string Created time.Time Deadline time.Time // peer that originated this message Initiator peer.ID // Headers proxies the concept of HTTP headers, but with no // mandatory fields. It's intended to be small & simple on purpose // In the future we can upgrade this to map[string]interface{} while keeping // backward compatibility Headers map[string]string // Body carries the payload of a message, if any Body []byte // contains filtered or unexported fields }
Message is a serializable/encodable object that we send & receive on a Stream.
func NewJSONBodyMessage ¶ added in v0.3.0
NewJSONBodyMessage is a convenience wrapper for json-encoding a message
func NewMessage ¶ added in v0.3.0
NewMessage creates a message. provided initiator should always be the peerID of the local node
func (Message) UpdateJSON ¶ added in v0.3.0
UpdateJSON updates a messages by JSON-encoding a body
func (Message) WithHeaders ¶ added in v0.3.0
WithHeaders adds a sequence of key,value,key,value as headers
type PeerConnectionParams ¶ added in v0.3.2
type PeerConnectionParams struct { Peername string ProfileID profile.ID PeerID peer.ID Multiaddr ma.Multiaddr }
PeerConnectionParams defines parameters for the ConnectToPeer command
type QriNode ¶
type QriNode struct { // ID is the node's identifier both locally & on the network // Identity has a relationship to privateKey (hash of PublicKey) ID peer.ID // Online indicates weather this is node is connected to the p2p network Online bool // Discovery service, can be provided by an ipfs node Discovery discovery.Service // Repo is a repository of this node's qri data // note that repo's are built upon a qfs.MuxFS, which // may contain a reference to a functioning IPFS node. In that case // QriNode should piggyback non-qri-specific p2p functionality on the // ipfs node provided by repo Repo repo.Repo // node keeps a set of IOStreams for "node local" io, often to the // command line, to give feedback to the user. These may be piped to // local http handlers/websockets/stdio, but these streams are meant for // local feedback as opposed to p2p connections LocalStreams ioes.IOStreams // contains filtered or unexported fields }
QriNode encapsulates a qri peer-2-peer node
func NewQriNode ¶
func NewQriNode(r repo.Repo, p2pconf *config.P2P, pub event.Publisher, localResolver dsref.Resolver) (node *QriNode, err error)
NewQriNode creates a new node from a configuration. To get a fully connected node that's searching for peers call: n, _ := NewQriNode(r, cfg) n.GoOnline()
func (*QriNode) Bootstrap ¶
Bootstrap samples a subset of peers & requests their peers list This is a naive version of IPFS bootstrapping, which we'll add in once qri's settled on a shared-state implementation
func (*QriNode) BootstrapIPFS ¶
func (n *QriNode) BootstrapIPFS()
BootstrapIPFS connects this node to standard ipfs nodes for file exchange
func (*QriNode) ClosestConnectedQriPeers ¶ added in v0.6.1
ClosestConnectedQriPeers checks if a peer is connected, and if so adds it to the top of a slice cap(max) of peers to try to connect to TODO - In the future we'll use a few tricks to improve on just iterating the list at a bare minimum we should grab a randomized set of peers
func (*QriNode) ConnectToPeer ¶
func (n *QriNode) ConnectToPeer(ctx context.Context, p PeerConnectionParams) (*profile.Profile, error)
ConnectToPeer takes a raw peer ID & tries to work out a route to that peer, explicitly connecting to them.
func (*QriNode) ConnectedPeers ¶
ConnectedPeers lists all IPFS connected peers
func (*QriNode) ConnectedQriPeerIDs ¶ added in v0.3.2
ConnectedQriPeerIDs returns a slice of peer.IDs this peer is currently connected to
func (*QriNode) ConnectedQriProfiles ¶ added in v0.3.0
func (n *QriNode) ConnectedQriProfiles() map[profile.ID]*config.ProfilePod
ConnectedQriProfiles lists all connected peers that support the qri protocol
func (*QriNode) DisconnectFromPeer ¶ added in v0.3.2
func (n *QriNode) DisconnectFromPeer(ctx context.Context, p PeerConnectionParams) error
DisconnectFromPeer explicitly closes a connection to a peer
func (*QriNode) EncapsulatedAddresses ¶
EncapsulatedAddresses returns a slice of full multaddrs for this node
func (*QriNode) GetIPFSNamesys ¶ added in v0.8.0
func (n *QriNode) GetIPFSNamesys() (namesys.NameSystem, error)
GetIPFSNamesys returns a namesystem from IPFS
func (*QriNode) GoOnline ¶ added in v0.6.0
GoOnline puts QriNode on the distributed web, ensuring there's an active peer-2-peer host participating in a peer-2-peer network, and kicks off requests to connect to known bootstrap peers that support the QriProtocol
func (*QriNode) HandlePeerFound ¶
HandlePeerFound deals with the discovery of a peer that may or may not support the qri protocol
func (*QriNode) IPFS ¶ added in v0.9.0
IPFS exposes the core.IPFS node if one exists. This is currently required by things like remoteClient in other packages, which don't work properly with the CoreAPI implementation
func (*QriNode) IPFSCoreAPI ¶ added in v0.8.0
IPFSCoreAPI returns a IPFS API interface instance
func (*QriNode) ListenAddresses ¶ added in v0.3.0
ListenAddresses gives the listening addresses of this node on the p2p network as a slice of strings
func (*QriNode) MissingManifest ¶ added in v0.9.1
func (node *QriNode) MissingManifest(ctx context.Context, m *dag.Manifest) (missing *dag.Manifest, err error)
MissingManifest returns a manifest describing blocks that are not in this node for a given manifest
func (*QriNode) NewDAGInfo ¶ added in v0.9.1
NewDAGInfo generates a DAGInfo for a given node. If a label is given, it will generate a sub-DAGInfo at thea label.
func (*QriNode) NewManifest ¶ added in v0.9.1
NewManifest generates a manifest for a given node
func (*QriNode) NewP2PRefResolver ¶ added in v0.9.12
NewP2PRefResolver creates a resolver backed by a qri node
func (*QriNode) PeerInfo ¶ added in v0.3.2
PeerInfo returns peer peer ID & network multiaddrs from the Host Peerstore
func (*QriNode) RequestDatasetsList ¶
func (n *QriNode) RequestDatasetsList(ctx context.Context, pid peer.ID, p DatasetsListParams) ([]reporef.DatasetRef, error)
RequestDatasetsList gets a list of a peer's datasets
func (*QriNode) SimpleAddrInfo ¶ added in v0.9.10
SimpleAddrInfo returns a PeerInfo with just the ID and Addresses.
type QriProfileService ¶ added in v0.9.12
type QriProfileService struct {
// contains filtered or unexported fields
}
QriProfileService manages the profile exchange. This exchange should happen whenever a node connects to a new peer
func NewQriProfileService ¶ added in v0.9.12
func NewQriProfileService(profiles profile.Store, p event.Publisher) *QriProfileService
NewQriProfileService creates an profile exchange service
func (*QriProfileService) ConnectedPeerProfile ¶ added in v0.9.12
func (q *QriProfileService) ConnectedPeerProfile(pid peer.ID) *profile.Profile
ConnectedPeerProfile returns a profile if that peer id refers to a peer that we have connected to this session.
func (*QriProfileService) ConnectedQriPeers ¶ added in v0.9.12
func (q *QriProfileService) ConnectedQriPeers() []peer.ID
ConnectedQriPeers returns a list of currently connected peers
func (*QriProfileService) HandleQriPeerDisconnect ¶ added in v0.9.12
func (q *QriProfileService) HandleQriPeerDisconnect(pid peer.ID)
HandleQriPeerDisconnect checks if a given peer is a qri peer. If so, it will wait until all profile exchanging has finished Then remove the peer from the peers map, as well as publish that the peer has disconnected.
func (*QriProfileService) ProfileHandler ¶ added in v0.9.12
func (q *QriProfileService) ProfileHandler(s network.Stream)
ProfileHandler listens for profile requests it sends it's node's profile on the given stream whenever a request comes in
func (*QriProfileService) QriProfileRequest ¶ added in v0.9.12
QriProfileRequest determine if the remote peer speaks the qri protocol if it does, it protects the connection and sends a request for the QriIdentifyService to get the peer's qri profile information
func (*QriProfileService) Start ¶ added in v0.9.12
func (q *QriProfileService) Start(h host.Host)
Start adds a profile handler to the host, retains a local reference to the host
type WrappedStream ¶
type WrappedStream struct {
// contains filtered or unexported fields
}
WrappedStream wraps a libp2p stream. We encode/decode whenever we write/read from a stream, so we can just carry the encoders and bufios with us
func WrapStream ¶
func WrapStream(s net.Stream) *WrappedStream
WrapStream takes a stream and complements it with r/w bufios and decoder/encoder. In order to write raw data to the stream we can use wrap.w.Write(). To encode something into it we can wrap.enc.Encode(). Finally, we should wrap.w.Flush() to actually send the data. Handling incoming data works similarly with wrap.r.Read() for raw-reading and wrap.dec.Decode() to decode.