Documentation
¶
Index ¶
- Constants
- Variables
- func AddrsFactory(announce []string, noAnnounce []string) func() (_ p2pconfig.AddrsFactory, err error)
- func BlockService(bs blockstore.Blockstore, ex exchange.Interface) blockservice.BlockService
- func ConnectionGater(ds datastore.Batching) (*conngater.BasicConnectionGater, error)
- func ConnectionManager(cfg Config, bpeers Bootstrappers) (coreconnmgr.ConnManager, error)
- func ConstructModule(tp node.Type, cfg *Config) fx.Option
- func ContentRouting(r routing.PeerRouting) routing.ContentRouting
- func DataExchange(params bitSwapParams) (exchange.Interface, blockstore.Blockstore, error)
- func Flags() *flag.FlagSet
- func GenesisFor(net Network) (string, error)
- func ID(key crypto.PrivKey, pstore peerstore.Peerstore) (peer.ID, error)
- func Key(kstore keystore.Keystore) (crypto.PrivKey, error)
- func Listen(listen []string) func(host host.Host) (err error)
- func ParseFlags(cmd *cobra.Command, cfg *Config) error
- func PeerRouting(cfg Config, params routingParams) (routing.PeerRouting, error)
- func PeerStore() (peerstore.Peerstore, error)
- func PubSub(cfg Config, params pubSubParams) (*pubsub.PubSub, error)
- func RoutedHost(base HostBase, r routing.PeerRouting) host.Host
- func WithHost(hst host.Host) fx.Option
- func WithP2PKey(key crypto.PrivKey) fx.Option
- func WithP2PKeyStr(key string) fx.Option
- type API
- type Bootstrappers
- type Config
- type ConnManagerConfig
- type HostBase
- type Module
- type Network
Constants ¶
const EnvCustomNetwork = "CELESTIA_CUSTOM"
EnvCustomNetwork is the environment variable name used for setting a custom network.
Variables ¶
var ErrInvalidNetwork = errors.New("params: invalid network")
ErrInvalidNetwork is thrown when unknown network is used.
Functions ¶
func AddrsFactory ¶
func AddrsFactory(announce []string, noAnnounce []string) func() (_ p2pconfig.AddrsFactory, err error)
AddrsFactory returns a constructor for AddrsFactory.
func BlockService ¶
func BlockService(bs blockstore.Blockstore, ex exchange.Interface) blockservice.BlockService
BlockService constructs IPFS's BlockService for fetching arbitrary Merkle structures.
func ConnectionGater ¶
func ConnectionGater(ds datastore.Batching) (*conngater.BasicConnectionGater, error)
ConnectionGater constructs a BasicConnectionGater.
func ConnectionManager ¶
func ConnectionManager(cfg Config, bpeers Bootstrappers) (coreconnmgr.ConnManager, error)
ConnectionManager provides a constructor for ConnectionManager.
func ConstructModule ¶
ConstructModule collects all the components and services related to p2p.
func ContentRouting ¶
func ContentRouting(r routing.PeerRouting) routing.ContentRouting
ContentRouting constructs nil content routing, as for our use-case existing ContentRouting mechanisms, e.g DHT, are unsuitable
func DataExchange ¶
func DataExchange(params bitSwapParams) (exchange.Interface, blockstore.Blockstore, error)
DataExchange provides a constructor for IPFS block's DataExchange over BitSwap.
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 PeerRouting ¶
func PeerRouting(cfg Config, params routingParams) (routing.PeerRouting, error)
PeerRouting provides constructor for PeerRouting over DHT. Basically, this provides a way to discover peer addresses by respecting public keys.
func RoutedHost ¶
func RoutedHost(base HostBase, r routing.PeerRouting) host.Host
RoutedHost constructs a wrapped Host that may fallback to address discovery, if any top-level operation on the Host is provided with PeerID(Hash(PbK)) only.
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 {
Info func() peer.AddrInfo
Peers func() []peer.ID
PeerInfo func(id peer.ID) peer.AddrInfo
Connect func(ctx context.Context, pi peer.AddrInfo) error
ClosePeer func(id peer.ID) error
Connectedness func(id peer.ID) network.Connectedness
NATStatus func() (network.Reachability, error)
BlockPeer func(p peer.ID) error
UnblockPeer func(p peer.ID) error
ListBlockedPeers func() []peer.ID
Protect func(id peer.ID, tag string)
Unprotect func(id peer.ID, tag string) bool
IsProtected func(id peer.ID, tag string) bool
BandwidthStats func() metrics.Stats
BandwidthForPeer func(id peer.ID) metrics.Stats
BandwidthForProtocol func(proto protocol.ID) metrics.Stats
ResourceState func() (rcmgr.ResourceManagerStat, error)
PubSubPeers func(topic string) []peer.ID
}
API is a wrapper around Module for the RPC. TODO(@distractedm1nd): These structs need to be autogenerated.
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
// a bootstrapper.
Bootstrapper bool
// 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
RoutingTableRefreshPeriod time.Duration
}
Config combines all configuration fields for P2P subsystem.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns default configuration for P2P subsystem.
type ConnManagerConfig ¶
type ConnManagerConfig struct {
// Low and High are watermarks governing the number of connections that'll be maintained.
Low, High int
// GracePeriod is the amount of time a newly opened connection is given before it becomes subject
// to pruning.
GracePeriod time.Duration
}
ConnManagerConfig configures connection manager.
func DefaultConnManagerConfig ¶
func DefaultConnManagerConfig() ConnManagerConfig
DefaultConnManagerConfig returns defaults for ConnManagerConfig.
type HostBase ¶
func Host ¶
func Host(cfg Config, params hostParams, bw *metrics.BandwidthCounter, rm network.ResourceManager) (HostBase, error)
Host returns constructor for Host.
type Module ¶ added in v0.5.0
type Module interface {
// Info returns address information about the host.
Info() peer.AddrInfo
// Peers returns all peer IDs used across all inner stores.
Peers() []peer.ID
// PeerInfo returns a small slice of information Peerstore has on the
// given peer.
PeerInfo(id peer.ID) peer.AddrInfo
// 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(id peer.ID) error
// Connectedness returns a state signaling connection capabilities.
Connectedness(id peer.ID) network.Connectedness
// NATStatus returns the current NAT status.
NATStatus() (network.Reachability, error)
// BlockPeer adds a peer to the set of blocked peers.
BlockPeer(p peer.ID) error
// UnblockPeer removes a peer from the set of blocked peers.
UnblockPeer(p peer.ID) error
// ListBlockedPeers returns a list of blocked peers.
ListBlockedPeers() []peer.ID
// 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(id peer.ID, tag string)
// 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(id peer.ID, tag string) bool
// IsProtected returns whether the given peer is protected.
IsProtected(id peer.ID, tag string) bool
// 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() metrics.Stats
// 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(id peer.ID) metrics.Stats
// BandwidthForProtocol returns a Stats struct with bandwidth metrics associated with the given protocol.ID.
BandwidthForProtocol(proto protocol.ID) metrics.Stats
// ResourceState returns the state of the resource manager.
ResourceState() (rcmgr.ResourceManagerStat, error)
// PubSubPeers returns the peer IDs of the peers joined on
// the given topic.
PubSubPeers(topic string) []peer.ID
}
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 = Arabica // Arabica testnet. See: celestiaorg/networks. Arabica Network = "arabica-2" // Mamaki testnet. See: celestiaorg/networks. Mamaki Network = "mamaki" // Private can be used to set up any private network, including local testing setups. Private Network = "private" // BlockTime is a network block time. // TODO @renaynay @Wondertan (#790) BlockTime = time.Second * 30 )
NOTE: Every time we add a new long-running network, it has to be added here.
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