Documentation ¶
Index ¶
- Constants
- func ParseInitialConnections(in string) ([]peerstore.PeerInfo, error)
- type Discovery
- type DiscoveryOptions
- type Handler
- type HostNode
- func (node *HostNode) Broadcast(topic string, data []byte) error
- func (node *HostNode) Connect(peerInfo peerstore.PeerInfo) (*Peer, error)
- func (node *HostNode) Connected() bool
- func (node *HostNode) DisconnectPeer(peer *Peer) error
- func (node *HostNode) FindPeerByID(id peer.ID) (*Peer, bool)
- func (node *HostNode) GetContext() context.Context
- func (node *HostNode) GetHost() host.Host
- func (node *HostNode) GetPeerByID(id peer.ID) *Peer
- func (node *HostNode) GetPeerList() []*Peer
- func (node *HostNode) GetPublicKey() *crypto.PubKey
- func (node *HostNode) IsPeerConnected(peerInfo peerstore.PeerInfo) bool
- func (node *HostNode) PeerDiscovered(pi peerstore.PeerInfo)
- func (node *HostNode) PeersConnected() int
- func (node *HostNode) RegisterMessageHandler(messageName string, handler MessageHandler) Handler
- func (node *HostNode) RemoveMessageHandler(handler Handler)
- func (node *HostNode) StartDiscovery() error
- func (node *HostNode) SubscribeMessage(topic string, handler func([]byte, peer.ID)) (*pubsub.Subscription, error)
- func (node *HostNode) UnsubscribeMessage(subscription *pubsub.Subscription)
- type MDNSOptions
- type Message
- type MessageHandler
- type Peer
- func (node *Peer) GetPeerInfo() *peerstore.PeerInfo
- func (node *Peer) HandleVersionMessage(message *pb.VersionMessage) error
- func (node *Peer) IsConnected() bool
- func (node *Peer) IsInbound() bool
- func (node *Peer) IsOutbound() bool
- func (node *Peer) Reject(message string) error
- func (node *Peer) SendMessage(message proto.Message) error
Constants ¶
const ClientVersion = 0
ClientVersion is the version of the client.
Variables ¶
This section is empty.
Functions ¶
func ParseInitialConnections ¶
ParseInitialConnections parses comma separated multiaddresses into peer info.
Types ¶
type Discovery ¶
type Discovery struct {
// contains filtered or unexported fields
}
Discovery is the service to discover other peers.
func NewDiscovery ¶
func NewDiscovery(ctx context.Context, host *HostNode, options DiscoveryOptions) *Discovery
NewDiscovery creates a new discovery service.
func (Discovery) HandlePeerFound ¶
HandlePeerFound registers the peer with the host.
func (Discovery) StartDiscovery ¶
StartDiscovery protocols. Currently, this supports discovery via multicast DNS peer discovery.
TODO: add other discovery protocols such as DHT, etc.
type DiscoveryOptions ¶
type DiscoveryOptions struct { // Optional. Each element is a peer address to connect with. PeerAddresses []ps.PeerInfo MDNS MDNSOptions }
DiscoveryOptions is the options used to discover peers
func NewDiscoveryOptions ¶
func NewDiscoveryOptions() DiscoveryOptions
NewDiscoveryOptions creates a DiscoveryOptions with default values
type HostNode ¶
type HostNode struct {
// contains filtered or unexported fields
}
HostNode is the node for p2p host It's the low level P2P communication layer, the App class handles high level protocols The RPC communication is hanlded by App, not HostNode
func NewHostNode ¶
func NewHostNode(listenAddress multiaddr.Multiaddr, publicKey crypto.PubKey, privateKey crypto.PrivKey, options DiscoveryOptions, timeoutInterval time.Duration, maxPeers int) (*HostNode, error)
NewHostNode creates a host node
func (*HostNode) DisconnectPeer ¶
DisconnectPeer disconnects a peer
func (*HostNode) FindPeerByID ¶
FindPeerByID finds a peer node by ID, returns nil if not found
func (*HostNode) GetContext ¶
GetContext returns the context
func (*HostNode) GetPeerByID ¶
GetPeerByID gets a peer by ID or returns nil if we aren't connected.
func (*HostNode) GetPeerList ¶
GetPeerList returns a list of all peers.
func (*HostNode) GetPublicKey ¶
GetPublicKey returns the public key
func (*HostNode) IsPeerConnected ¶ added in v0.1.2
IsPeerConnected checks if a peer is connected
func (*HostNode) PeerDiscovered ¶
PeerDiscovered is run when peers are discovered.
func (*HostNode) PeersConnected ¶
PeersConnected checks how many peers are connected.
func (*HostNode) RegisterMessageHandler ¶
func (node *HostNode) RegisterMessageHandler(messageName string, handler MessageHandler) Handler
RegisterMessageHandler registers a message handler
func (*HostNode) RemoveMessageHandler ¶
RemoveMessageHandler deregisters a message handler.
func (*HostNode) StartDiscovery ¶
StartDiscovery starts the host node discovering peers.
func (*HostNode) SubscribeMessage ¶
func (node *HostNode) SubscribeMessage(topic string, handler func([]byte, peer.ID)) (*pubsub.Subscription, error)
SubscribeMessage registers a handler for a network topic.
func (*HostNode) UnsubscribeMessage ¶
func (node *HostNode) UnsubscribeMessage(subscription *pubsub.Subscription)
UnsubscribeMessage cancels a subscription to a topic.
type MDNSOptions ¶
MDNSOptions are options for the MDNS discovery mechanism.
type MessageHandler ¶
MessageHandler is a function to handle messages.
type Peer ¶
type Peer struct { ID peer.ID Outbound bool Connecting bool LastPingNonce uint64 LastPingTime time.Time LastMessageTime time.Time Version uint64 ProcessingRequest bool // contains filtered or unexported fields }
Peer is a representation of an external peer.
func (*Peer) GetPeerInfo ¶
GetPeerInfo returns the peer info
func (*Peer) HandleVersionMessage ¶
func (node *Peer) HandleVersionMessage(message *pb.VersionMessage) error
HandleVersionMessage handles VersionMessage from this peer
func (*Peer) IsConnected ¶
IsConnected checks if the peers is considered connected.
func (*Peer) IsOutbound ¶
IsOutbound returns true if the connection is an outbound