Documentation ¶
Overview ¶
Package p2p outlines helper methods and types for p2p communications.
Package p2p outlines helper methods and types for p2p communications.
Package p2p outlines helper methods and types for p2p communications.
Package p2p outlines helper methods and types for p2p communications.
Package p2p outlines helper methods and types for p2p communications.
Package p2p outlines helper methods and types for p2p communications.
Package p2p outlines helper methods and types for p2p communications.
Index ¶
- Variables
- func BootstrapConfig(ctx context.Context, host *routed.RoutedHost, bootstrapAddress string, ...) (*config.ChainConfig, 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, ...) (responses [][]byte, err error)
- func CheckPeerCompatible(ctx context.Context, host *routed.RoutedHost, peer peer.ID, network string) bool
- func GetBestBootstrapAddress(ctx context.Context, host *routed.RoutedHost, network string) string
- func GetExistingPeerIdentity() (*crypto.PrivKey, error)
- func GetPeerIdentity() (*crypto.PrivKey, error)
- func GetStreamHeaderProtocolPath(network string, streamProtocol StreamHeaderProtocol) string
- func NewHost(ctx context.Context, port int, network string) (*routed.RoutedHost, error)
- func NewPeerIdentity() (*crypto.PrivKey, error)
- func WritePeerIdentity(identity *crypto.PrivKey) error
- type Client
- func (client *Client) HandleReceiveAliveRequest(stream inet.Stream)
- func (client *Client) HandleReceiveAllChainsRequest(stream inet.Stream)
- func (client *Client) HandleReceiveBestTransaction(stream inet.Stream)
- func (client *Client) HandleReceiveChainRequest(stream inet.Stream)
- func (client *Client) HandleReceiveConfigRequest(stream inet.Stream)
- func (client *Client) HandleReceiveNextTransactionRequest(stream inet.Stream)
- func (client *Client) HandleReceiveTransaction(stream inet.Stream)
- func (client *Client) PublishTransaction(ctx context.Context, transaction *types.Transaction) error
- func (client *Client) RequestAllChains(sampleSize uint) ([]string, error)
- func (client *Client) RequestBestTransaction(account common.Address, sampleSize uint) (common.Hash, error)
- func (client *Client) RequestChain(account common.Address, sampleSize uint) (*types.Chain, error)
- func (client *Client) RequestNextTransaction(lastTransactionHash common.Hash, account common.Address, sampleSize uint) (*types.Transaction, error)
- func (client *Client) StartIntermittentSync(duration time.Duration)
- func (client *Client) StartServingStream(streamHeaderProtocolPath string, handler func(inet.Stream)) error
- func (client *Client) StartServingStreams() error
- func (client *Client) SyncNetwork() error
- type StreamHeaderProtocol
Constants ¶
This section is empty.
Variables ¶
var ( // WorkingHost represents the global routed host. WorkingHost *routed.RoutedHost // WorkingSub represents the working pubsub instance. WorkingSub *simplesub.SimpleSub // ErrNoWorkingHost represents an error describing a WorkingHost value of nil. ErrNoWorkingHost = errors.New("no working host") )
var ( // ErrIdentityAlreadyExists is an error definition describing a duplicate peer identity value (already an identity in p2p/). ErrIdentityAlreadyExists = errors.New("identity already exists") // ErrNoExistingIdentity is an error definition describing the lack of a p2p identity. ErrNoExistingIdentity = errors.New("no existing identity") )
var BootstrapNodes = []string{
"/ip4/108.41.124.60/tcp/3000/ipfs/QmWRdp5HQ1SfENPnLFrXviY9gr6Y5BcWYbkWuqDkZSizAj",
"/ip4/108.41.124.60/tcp/3003/ipfs/QmYEaiPPsqtPes1AtPZA1zpqozmDzfgFJv3ygjTjLVXedp",
"/ip4/174.129.191.246/tcp/3000/ipfs/QmUXThFht8qoZGdKLMVmr8Bk34VJ9oS3WWw3a25jeZucYd",
"/ip4/54.234.2.165/tcp/3000/ipfs/Qma3QTswnKK48gzsaVhzakPApY4kPuBGsZLS1i837gns2s",
}
BootstrapNodes represents all default bootstrap nodes on the given network.
var ErrTimedOut = errors.New("request timed out")
ErrTimedOut defines an error describing a standard timeout.
var StreamHeaderProtocolNames = []string{
"pub_transaction",
"req_config",
"req_best_transaction",
"req_transaction",
"req_genesis_hash",
"req_transaction_children_hashes",
"req_chain",
"req_all_chains",
"req_next_transaction",
"req_not_dead_lol",
}
StreamHeaderProtocolNames represents all stream header protocol names.
Functions ¶
func BootstrapConfig ¶
func BootstrapConfig(ctx context.Context, host *routed.RoutedHost, bootstrapAddress string, network string) (*config.ChainConfig, error)
BootstrapConfig bootstraps the network's working config with a given host.
func BootstrapDht ¶
BootstrapDht bootstraps a KadDht 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) (responses [][]byte, err error)
BroadcastDhtResult send a given message to all nodes in a dht, and returns the result from each node.
func CheckPeerCompatible ¶ added in v0.6.1
func CheckPeerCompatible(ctx context.Context, host *routed.RoutedHost, peer peer.ID, network string) bool
CheckPeerCompatible checks that a given peer is compatible with the working host.
func GetBestBootstrapAddress ¶
GetBestBootstrapAddress attempts to fetch the best bootstrap node.
func GetExistingPeerIdentity ¶
GetExistingPeerIdentity attempts to read an existing p2p identity.
func GetPeerIdentity ¶
GetPeerIdentity gets the peer identity. If no identity exists persistently, it creates one.
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.
func NewPeerIdentity ¶
NewPeerIdentity creates a new p2p identity, and writes it to memory.
func WritePeerIdentity ¶
WritePeerIdentity writes a given p2p identity to persistent memory.
Types ¶
type Client ¶
type Client struct { Host *routed.RoutedHost `json:"host"` // Host Validator *validator.Validator `json:"validator"` // Validator Network string `json:"network"` // Network }
Client represents a peer on the network with a known routed libp2p host.
func (*Client) HandleReceiveAliveRequest ¶
HandleReceiveAliveRequest handles an incoming req_not_dead_lol stream.
func (*Client) HandleReceiveAllChainsRequest ¶
HandleReceiveAllChainsRequest handles an incoming req_all_chains stream.
func (*Client) HandleReceiveBestTransaction ¶
HandleReceiveBestTransaction handles an incoming req_best_tx stream.
func (*Client) HandleReceiveChainRequest ¶
HandleReceiveChainRequest handles an incoming req_chain stream.
func (*Client) HandleReceiveConfigRequest ¶
HandleReceiveConfigRequest handles an incoming req_config stream.
func (*Client) HandleReceiveNextTransactionRequest ¶
HandleReceiveNextTransactionRequest handles an incoming req_next_tx stream.
func (*Client) HandleReceiveTransaction ¶
HandleReceiveTransaction handles an incoming pub_tx stream.
func (*Client) PublishTransaction ¶
PublishTransaction publishes a given transaction.
func (*Client) RequestAllChains ¶
RequestAllChains requests all chain addresses from the working network with a given sample size.
func (*Client) RequestBestTransaction ¶
func (client *Client) RequestBestTransaction(account common.Address, sampleSize uint) (common.Hash, error)
RequestBestTransaction requests the best transaction hash.
func (*Client) RequestChain ¶
RequestChain requests a chain from the working network with a given sample size.
func (*Client) RequestNextTransaction ¶
func (client *Client) RequestNextTransaction(lastTransactionHash common.Hash, account common.Address, sampleSize uint) (*types.Transaction, error)
RequestNextTransaction requests the next transaction with a given account chain address, and sample size.
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 given stream.
func (*Client) StartServingStreams ¶
StartServingStreams starts serving all necessary strings.
func (*Client) SyncNetwork ¶
SyncNetwork syncs all available chains and state roots.
type StreamHeaderProtocol ¶
type StreamHeaderProtocol int
StreamHeaderProtocol represents the stream protocol type enum.
const ( PublishTransaction StreamHeaderProtocol = iota RequestConfig RequestBestTransaction RequestTransaction RequestGenesisHash RequestChildHashes RequestChain RequestAllChains RequestNextTransaction RequestAlive )
Stream header protocol definitions