Documentation ¶
Overview ¶
Package p2p provides common peer-to-peer communications helper methods and definitions.
Index ¶
- Variables
- func BootstrapConfig(ctx context.Context, host *routed.RoutedHost, bootstrapAddress string, ...) (*config.DagConfig, error)
- func BootstrapDht(ctx context.Context, host host.Host) (*dht.IpfsDHT, error)
- func BroadcastDht(ctx context.Context, host *routed.RoutedHost, message []byte, ...) error
- func BroadcastDhtResult(ctx context.Context, host *routed.RoutedHost, message []byte, ...) ([][]byte, error)
- func GetBestBootstrapAddress(ctx context.Context, host *routed.RoutedHost) string
- func GetStreamHeaderProtocolPath(network string, streamProtocol StreamHeaderProtocol) string
- func NewHost(ctx context.Context, port int) (*routed.RoutedHost, error)
- type Client
- func (client *Client) HandlePubTransaction(stream inet.Stream)
- func (client *Client) HandleReceiveBestTransactionRequest(stream inet.Stream)
- func (client *Client) HandleReceiveConfigRequest(stream inet.Stream)
- func (client *Client) HandleReceiveGenesisHashRequest(stream inet.Stream)
- func (client *Client) HandleReceiveTransaction(stream inet.Stream)
- func (client *Client) HandleReceiveTransactionChildHashesRequest(stream inet.Stream)
- func (client *Client) HandleReceiveTransactionRequest(stream inet.Stream)
- func (client *Client) PublishTransaction(ctx context.Context, transaction *types.Transaction) error
- func (client *Client) RequestBestTransactionHash(ctx context.Context, nPeers int) (common.Hash, error)
- func (client *Client) RequestTransactionChildren(ctx context.Context, parentHash common.Hash, nPeers int) ([]common.Hash, error)
- func (client *Client) RequestTransactionWithHash(ctx context.Context, hash common.Hash, nPeers int) (*types.Transaction, error)
- func (client *Client) StartIntermittentSync(ctx context.Context, duration time.Duration)
- func (client *Client) StartServingStream(streamHeaderProtocolPath string, handler func(inet.Stream)) error
- func (client *Client) StartServingStreams(network string) error
- func (client *Client) SyncBestTransaction(ctx context.Context, remoteBestTransactionHash common.Hash) error
- func (client *Client) SyncDag(ctx context.Context) error
- func (client *Client) SyncGenesis(ctx context.Context) error
- type StreamHeaderProtocol
Constants ¶
This section is empty.
Variables ¶
var ( // StreamHeaderProtocolNames represents all stream header protocol names. StreamHeaderProtocolNames = []string{ "pub_transaction", "req_config", "req_best_transaction", "req_transaction", "req_genesis_hash", "req_transaction_children_hashes", } // BootstrapNodes represents all default bootstrap nodes on the given network. BootstrapNodes = []string{ "/ip4/108.41.124.60/tcp/3030/ipfs/QmWy8fZPX4hnTmXtFzgUTa8ZGceHhdhUEj3wonj1r3bMEG", } // WorkingHost is the current global routed host. WorkingHost *routed.RoutedHost // NodePort is the current node port NodePort = 3030 // ErrTimedOut is an error definition representing a timeout. ErrTimedOut = errors.New("timed out") )
var ( // ErrNoWorkingHost represents an error describing a WorkingHost value of nil. ErrNoWorkingHost = errors.New("no working host") // ErrNilHash defines an error describing a situation in which a message has no hash. ErrNilHash = errors.New("hash not set") // ErrNoAvailablePeers defines an error describing an available peer sampling set with a length of 0. ErrNoAvailablePeers = errors.New("no available peers") )
Functions ¶
func BootstrapConfig ¶
func BootstrapConfig(ctx context.Context, host *routed.RoutedHost, bootstrapAddress string, network string) (*config.DagConfig, error)
BootstrapConfig bootstraps a dag config to the list of bootstrap nodes.
func BootstrapDht ¶
BootstrapDht bootstraps the WorkingDHT to the list of bootstrap nodes.
func BroadcastDht ¶
func BroadcastDht(ctx context.Context, host *routed.RoutedHost, message []byte, streamProtocol string, dagIdentifier string) error
BroadcastDht attempts to send a given message to all nodes in a dht at a given endpoint.
func BroadcastDhtResult ¶
func BroadcastDhtResult(ctx context.Context, host *routed.RoutedHost, message []byte, streamProtocol string, dagIdentifier string, nPeers int) ([][]byte, error)
BroadcastDhtResult send a given message to all nodes in a dht, and returns the result from each node.
func GetBestBootstrapAddress ¶
func GetBestBootstrapAddress(ctx context.Context, host *routed.RoutedHost) string
GetBestBootstrapAddress attempts to fetch the best bootstrap node.
func GetStreamHeaderProtocolPath ¶
func GetStreamHeaderProtocolPath(network string, streamProtocol StreamHeaderProtocol) string
GetStreamHeaderProtocolPath attempts to determine the libp2p stream header protocol URI from a given stream protocol and network.
Types ¶
type Client ¶
type Client struct { Network string `json:"network"` // Active network Validator *validator.Validator // Validator }
Client represents an active p2p peer, that of which is serving a list of available stream header protocol paths.
func (*Client) HandlePubTransaction ¶
HandlePubTransaction handles the
func (*Client) HandleReceiveBestTransactionRequest ¶
HandleReceiveBestTransactionRequest handle a new stream requesting for the best transaction hash.
func (*Client) HandleReceiveConfigRequest ¶
HandleReceiveConfigRequest handles a new stream requesting the working dag config.
func (*Client) HandleReceiveGenesisHashRequest ¶
HandleReceiveGenesisHashRequest handles a new stream requesting for the genesis hash of the working dag.
func (*Client) HandleReceiveTransaction ¶
HandleReceiveTransaction handles a new stream sending a transaction.
func (*Client) HandleReceiveTransactionChildHashesRequest ¶
HandleReceiveTransactionChildHashesRequest handles a new stream requesting for the child hashes of a given transaction.
func (*Client) HandleReceiveTransactionRequest ¶
HandleReceiveTransactionRequest handles a new stream requesting transaction metadata with a given hash.
func (*Client) PublishTransaction ¶
PublishTransaction publishes a given transaction.
func (*Client) RequestBestTransactionHash ¶
func (client *Client) RequestBestTransactionHash(ctx context.Context, nPeers int) (common.Hash, error)
RequestBestTransactionHash returns the average best tx hash between nPeers.
func (*Client) RequestTransactionChildren ¶
func (client *Client) RequestTransactionChildren(ctx context.Context, parentHash common.Hash, nPeers int) ([]common.Hash, error)
RequestTransactionChildren requests the children of a transaction from a sampling set of nPeers size.
func (*Client) RequestTransactionWithHash ¶
func (client *Client) RequestTransactionWithHash(ctx context.Context, hash common.Hash, nPeers int) (*types.Transaction, error)
RequestTransactionWithHash requests a given transaction with a given hash from the network. Returns best response from peer sampling set nPeers.
func (*Client) StartIntermittentSync ¶
StartIntermittentSync syncs the dag with a given context and duration.
func (*Client) StartServingStream ¶
func (client *Client) StartServingStream(streamHeaderProtocolPath string, handler func(inet.Stream)) error
StartServingStream starts serving a stream on a given header protocol path.
func (*Client) StartServingStreams ¶
StartServingStreams attempts to start serving all necessary streams
func (*Client) SyncBestTransaction ¶
func (client *Client) SyncBestTransaction(ctx context.Context, remoteBestTransactionHash common.Hash) error
SyncBestTransaction syncs the best local and remote transactions.
type StreamHeaderProtocol ¶
type StreamHeaderProtocol int
StreamHeaderProtocol represents the stream protocol type enum.
const ( PublishTransaction StreamHeaderProtocol = iota RequestConfig RequestBestTransaction RequestTransaction RequestGenesisHash RequestChildHashes )
Stream header protocol definitions