p2p

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: LGPL-3.0 Imports: 32 Imported by: 1

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

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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")
)
View Source
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.

View Source
var ErrTimedOut = errors.New("request timed out")

ErrTimedOut defines an error describing a standard timeout.

View Source
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

func BootstrapDht(ctx context.Context, host host.Host) (*dht.IpfsDHT, error)

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

func GetBestBootstrapAddress(ctx context.Context, host *routed.RoutedHost, network string) string

GetBestBootstrapAddress attempts to fetch the best bootstrap node.

func GetExistingPeerIdentity

func GetExistingPeerIdentity() (*crypto.PrivKey, error)

GetExistingPeerIdentity attempts to read an existing p2p identity.

func GetPeerIdentity

func GetPeerIdentity() (*crypto.PrivKey, error)

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 NewHost

func NewHost(ctx context.Context, port int, network string) (*routed.RoutedHost, error)

NewHost initializes a new routed libp2p host with a given context.

func NewPeerIdentity

func NewPeerIdentity() (*crypto.PrivKey, error)

NewPeerIdentity creates a new p2p identity, and writes it to memory.

func WritePeerIdentity

func WritePeerIdentity(identity *crypto.PrivKey) error

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 NewClient

func NewClient(host *routed.RoutedHost, validator *validator.Validator, network string) *Client

NewClient initializes a new client with a given host.

func (*Client) HandleReceiveAliveRequest

func (client *Client) HandleReceiveAliveRequest(stream inet.Stream)

HandleReceiveAliveRequest handles an incoming req_not_dead_lol stream.

func (*Client) HandleReceiveAllChainsRequest

func (client *Client) HandleReceiveAllChainsRequest(stream inet.Stream)

HandleReceiveAllChainsRequest handles an incoming req_all_chains stream.

func (*Client) HandleReceiveBestTransaction

func (client *Client) HandleReceiveBestTransaction(stream inet.Stream)

HandleReceiveBestTransaction handles an incoming req_best_tx stream.

func (*Client) HandleReceiveChainRequest

func (client *Client) HandleReceiveChainRequest(stream inet.Stream)

HandleReceiveChainRequest handles an incoming req_chain stream.

func (*Client) HandleReceiveConfigRequest

func (client *Client) HandleReceiveConfigRequest(stream inet.Stream)

HandleReceiveConfigRequest handles an incoming req_config stream.

func (*Client) HandleReceiveNextTransactionRequest

func (client *Client) HandleReceiveNextTransactionRequest(stream inet.Stream)

HandleReceiveNextTransactionRequest handles an incoming req_next_tx stream.

func (*Client) HandleReceiveTransaction

func (client *Client) HandleReceiveTransaction(stream inet.Stream)

HandleReceiveTransaction handles an incoming pub_tx stream.

func (*Client) PublishTransaction

func (client *Client) PublishTransaction(ctx context.Context, transaction *types.Transaction) error

PublishTransaction publishes a given transaction.

func (*Client) RequestAllChains

func (client *Client) RequestAllChains(sampleSize uint) ([]string, error)

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

func (client *Client) RequestChain(account common.Address, sampleSize uint) (*types.Chain, error)

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

func (client *Client) StartIntermittentSync(duration time.Duration)

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

func (client *Client) StartServingStreams() error

StartServingStreams starts serving all necessary strings.

func (*Client) SyncNetwork

func (client *Client) SyncNetwork() error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL