Documentation
¶
Index ¶
- Constants
- Variables
- func ConstructModule(tp node.Type, cfg *Config) fx.Option
- func Flags() *flag.FlagSet
- func GenesisFor(net Network) (string, error)
- func Key(kstore keystore.Keystore) (crypto.PrivKey, error)
- func Listen(cfg *Config) func(h hst.Host) (err error)
- func ParseFlags(cmd *cobra.Command, cfg *Config) error
- func WithHost(hst hst.Host) fx.Option
- func WithMetrics() fx.Option
- func WithP2PKey(key crypto.PrivKey) fx.Option
- func WithP2PKeyStr(key string) fx.Option
- type API
- func (api *API) BandwidthForPeer(ctx context.Context, id peer.ID) (metrics.Stats, error)
- func (api *API) BandwidthForProtocol(ctx context.Context, proto protocol.ID) (metrics.Stats, error)
- func (api *API) BandwidthStats(ctx context.Context) (metrics.Stats, error)
- func (api *API) BlockPeer(ctx context.Context, p peer.ID) error
- func (api *API) ClosePeer(ctx context.Context, id peer.ID) error
- func (api *API) Connect(ctx context.Context, pi peer.AddrInfo) error
- func (api *API) Connectedness(ctx context.Context, id peer.ID) (network.Connectedness, error)
- func (api *API) ConnectionState(ctx context.Context, peer peer.ID) ([]ConnectionState, error)
- func (api *API) Info(ctx context.Context) (peer.AddrInfo, error)
- func (api *API) IsProtected(ctx context.Context, id peer.ID, tag string) (bool, error)
- func (api *API) ListBlockedPeers(ctx context.Context) ([]peer.ID, error)
- func (api *API) NATStatus(ctx context.Context) (network.Reachability, error)
- func (api *API) PeerInfo(ctx context.Context, id peer.ID) (peer.AddrInfo, error)
- func (api *API) Peers(ctx context.Context) ([]peer.ID, error)
- func (api *API) Ping(ctx context.Context, peer peer.ID) (time.Duration, error)
- func (api *API) Protect(ctx context.Context, id peer.ID, tag string) error
- func (api *API) PubSubPeers(ctx context.Context, topic string) ([]peer.ID, error)
- func (api *API) PubSubTopics(ctx context.Context) ([]string, error)
- func (api *API) ResourceState(ctx context.Context) (rcmgr.ResourceManagerStat, error)
- func (api *API) UnblockPeer(ctx context.Context, p peer.ID) error
- func (api *API) Unprotect(ctx context.Context, id peer.ID, tag string) (bool, error)
- type Bootstrappers
- type Config
- type ConnectionState
- type HostBase
- type Module
- type Network
- type UserAgent
Constants ¶
const EnvCustomNetwork = "CELESTIA_CUSTOM"
EnvCustomNetwork is the environment variable name used for setting a custom network.
const EnvKeyCelestiaBootstrapper = "CELESTIA_BOOTSTRAPPER"
Variables ¶
var ErrInvalidNetwork = errors.New("params: invalid network")
ErrInvalidNetwork is thrown when unknown network is used.
Functions ¶
func ConstructModule ¶
ConstructModule collects all the components and services related to p2p.
func GenesisFor ¶ added in v0.5.0
GenesisFor reports a hash of a genesis block for a given network. Genesis is strictly defined and can't be modified.
func Listen ¶
Listen returns invoke function that starts listening for inbound connections with libp2p.Host.
func ParseFlags ¶
ParseFlags parses P2P flags from the given cmd and saves them to the passed config.
func WithMetrics ¶ added in v0.8.2
WithMetrics option sets up native libp2p metrics up.
func WithP2PKey ¶
WithP2PKey sets custom Ed25519 private key for p2p networking.
func WithP2PKeyStr ¶
WithP2PKeyStr sets custom hex encoded Ed25519 private key for p2p networking.
Types ¶
type API ¶ added in v0.5.0
type API struct {
Internal struct {
Info func(context.Context) (peer.AddrInfo, error) `perm:"admin"`
Peers func(context.Context) ([]peer.ID, error) `perm:"admin"`
PeerInfo func(ctx context.Context, id peer.ID) (peer.AddrInfo, error) `perm:"admin"`
Connect func(ctx context.Context, pi peer.AddrInfo) error `perm:"admin"`
ClosePeer func(ctx context.Context, id peer.ID) error `perm:"admin"`
Connectedness func(ctx context.Context, id peer.ID) (network.Connectedness, error) `perm:"admin"`
NATStatus func(context.Context) (network.Reachability, error) `perm:"admin"`
BlockPeer func(ctx context.Context, p peer.ID) error `perm:"admin"`
UnblockPeer func(ctx context.Context, p peer.ID) error `perm:"admin"`
ListBlockedPeers func(context.Context) ([]peer.ID, error) `perm:"admin"`
Protect func(ctx context.Context, id peer.ID, tag string) error `perm:"admin"`
Unprotect func(ctx context.Context, id peer.ID, tag string) (bool, error) `perm:"admin"`
IsProtected func(ctx context.Context, id peer.ID, tag string) (bool, error) `perm:"admin"`
BandwidthStats func(context.Context) (metrics.Stats, error) `perm:"admin"`
BandwidthForPeer func(ctx context.Context, id peer.ID) (metrics.Stats, error) `perm:"admin"`
BandwidthForProtocol func(ctx context.Context, proto protocol.ID) (metrics.Stats, error) `perm:"admin"`
ResourceState func(context.Context) (rcmgr.ResourceManagerStat, error) `perm:"admin"`
PubSubPeers func(ctx context.Context, topic string) ([]peer.ID, error) `perm:"admin"`
PubSubTopics func(ctx context.Context) ([]string, error) `perm:"admin"`
Ping func(ctx context.Context, peer peer.ID) (time.Duration, error) `perm:"admin"`
ConnectionState func(context.Context, peer.ID) ([]ConnectionState, error) `perm:"admin"`
}
}
API is a wrapper around Module for the RPC.
func (*API) BandwidthForPeer ¶ added in v0.5.0
func (*API) BandwidthForProtocol ¶ added in v0.5.0
func (*API) BandwidthStats ¶ added in v0.5.0
func (*API) Connectedness ¶ added in v0.5.0
func (*API) ConnectionState ¶ added in v0.21.5
func (*API) IsProtected ¶ added in v0.5.0
func (*API) ListBlockedPeers ¶ added in v0.5.0
func (*API) PubSubPeers ¶ added in v0.5.0
func (*API) PubSubTopics ¶ added in v0.17.1
func (*API) ResourceState ¶ added in v0.5.0
func (*API) UnblockPeer ¶ added in v0.5.0
type Bootstrappers ¶ added in v0.5.0
Bootstrappers is a type definition for nodes that will be used as bootstrappers.
func BootstrappersFor ¶ added in v0.5.0
func BootstrappersFor(net Network) (Bootstrappers, error)
BootstrappersFor returns address information of bootstrap peers for a given network.
type Config ¶
type Config struct {
// ListenAddresses - Addresses to listen to on local NIC.
ListenAddresses []string
// AnnounceAddresses - Addresses to be announced/advertised for peers to connect to
AnnounceAddresses []string
// NoAnnounceAddresses - Addresses the P2P subsystem may know about, but that should not be
// announced/advertised, as undialable from WAN
NoAnnounceAddresses []string
// MutualPeers are peers which have a bidirectional peering agreement with the configured node.
// Connections with those peers are protected from being trimmed, dropped or negatively scored.
// NOTE: Any two peers must bidirectionally configure each other on their MutualPeers field.
MutualPeers []string
// PeerExchange configures the node, whether it should share some peers to a pruned peer.
// This is enabled by default for Bootstrappers.
PeerExchange bool
// ConnManager is a configuration tuple for ConnectionManager.
ConnManager connManagerConfig
// Allowlist for IPColocation PubSub parameter, a list of string CIDRs
IPColocationWhitelist []string
}
Config combines all configuration fields for P2P subsystem.
func DefaultConfig ¶
DefaultConfig returns default configuration for P2P subsystem.
type ConnectionState ¶ added in v0.21.5
type ConnectionState struct {
Info network.ConnectionState
// NumStreams is the number of streams on the connection.
NumStreams int
// Direction specifies whether this is an inbound or an outbound connection.
Direction network.Direction
// Opened is the timestamp when this connection was opened.
Opened time.Time
// Limited indicates that this connection is Limited. It maybe limited by
// bytes or time. In practice, this is a connection formed over a circuit v2
// relay.
Limited bool
}
ConnectionState holds information about a connection.
type Module ¶ added in v0.5.0
type Module interface {
// Info returns address information about the host.
Info(context.Context) (peer.AddrInfo, error)
// Peers returns connected peers.
Peers(context.Context) ([]peer.ID, error)
// PeerInfo returns a small slice of information Peerstore has on the
// given peer.
PeerInfo(ctx context.Context, id peer.ID) (peer.AddrInfo, error)
// Connect ensures there is a connection between this host and the peer with
// given peer.
Connect(ctx context.Context, pi peer.AddrInfo) error
// ClosePeer closes the connection to a given peer.
ClosePeer(ctx context.Context, id peer.ID) error
// Connectedness returns a state signaling connection capabilities.
Connectedness(ctx context.Context, id peer.ID) (network.Connectedness, error)
// ConnectionState returns information about each *active* connection to the peer.
// NOTE: At most cases there should be only a single connection.
ConnectionState(ctx context.Context, id peer.ID) ([]ConnectionState, error)
// NATStatus returns the current NAT status.
NATStatus(context.Context) (network.Reachability, error)
// BlockPeer adds a peer to the set of blocked peers and
// closes any existing connection to that peer.
BlockPeer(ctx context.Context, p peer.ID) error
// UnblockPeer removes a peer from the set of blocked peers.
UnblockPeer(ctx context.Context, p peer.ID) error
// ListBlockedPeers returns a list of blocked peers.
ListBlockedPeers(context.Context) ([]peer.ID, error)
// Protect adds a peer to the list of peers who have a bidirectional
// peering agreement that they are protected from being trimmed, dropped
// or negatively scored.
Protect(ctx context.Context, id peer.ID, tag string) error
// Unprotect removes a peer from the list of peers who have a bidirectional
// peering agreement that they are protected from being trimmed, dropped
// or negatively scored, returning a bool representing whether the given
// peer is protected or not.
Unprotect(ctx context.Context, id peer.ID, tag string) (bool, error)
// IsProtected returns whether the given peer is protected.
IsProtected(ctx context.Context, id peer.ID, tag string) (bool, error)
// BandwidthStats returns a Stats struct with bandwidth metrics for all
// data sent/received by the local peer, regardless of protocol or remote
// peer IDs.
BandwidthStats(context.Context) (metrics.Stats, error)
// BandwidthForPeer returns a Stats struct with bandwidth metrics associated with the given peer.ID.
// The metrics returned include all traffic sent / received for the peer, regardless of protocol.
BandwidthForPeer(ctx context.Context, id peer.ID) (metrics.Stats, error)
// BandwidthForProtocol returns a Stats struct with bandwidth metrics associated with the given
// protocol.ID.
BandwidthForProtocol(ctx context.Context, proto protocol.ID) (metrics.Stats, error)
// ResourceState returns the state of the resource manager.
ResourceState(context.Context) (rcmgr.ResourceManagerStat, error)
// PubSubPeers returns the peer IDs of the peers joined on
// the given topic.
PubSubPeers(ctx context.Context, topic string) ([]peer.ID, error)
// PubSubTopics reports current PubSubTopics the node participates in.
PubSubTopics(ctx context.Context) ([]string, error)
// Ping pings the selected peer and returns time it took or error.
Ping(ctx context.Context, peer peer.ID) (time.Duration, error)
}
Module represents all accessible methods related to the node's p2p host / operations.
type Network ¶ added in v0.5.0
type Network string
Network is a type definition for DA network run by Celestia Node.
const ( // DefaultNetwork is the default network of the current build. DefaultNetwork = Mainnet // Arabica testnet. See: celestiaorg/networks. Arabica Network = "arabica-11" // Mocha testnet. See: celestiaorg/networks. Mocha Network = "mocha-4" // Private can be used to set up any private network, including local testing setups. Private Network = "private" // Celestia mainnet. See: celestiaorg/networks. Mainnet Network = "celestia" // BlockTime is a network block time. // TODO @renaynay @Wondertan (#790) BlockTime = time.Second * 6 )
NOTE: Every time we add a new long-running network, it has to be added here.
func GetNetwork ¶ added in v0.17.1
GetNetwork returns the Network for the given string representation.
func GetNetworks ¶ added in v0.14.0
func GetNetworks() []Network
GetNetworks provides a list of all known networks in order of priority.
func ParseNetwork ¶ added in v0.5.0
ParseNetwork tries to parse the network from the flags and environment, and returns either the parsed network or the build's default network
type UserAgent ¶ added in v0.14.0
type UserAgent struct {
// contains filtered or unexported fields
}