Documentation
¶
Index ¶
- Constants
- Variables
- func DiscoveryService(s ...ServiceDiscovery) func(cfg *Config) error
- func ExchangeKeys(s string) func(cfg *Config) error
- func FromBase64(enablemDNS, enableDHT bool, bb string, d *discovery.DHT, m *discovery.MDNS) func(cfg *Config) error
- func FromYaml(enablemDNS, enableDHT bool, path string, d *discovery.DHT, m *discovery.MDNS) func(cfg *Config) error
- func GenPrivKey(seed int64) (crypto.PrivKey, error)
- func GenericChannelHandlers(h ...Handler) func(cfg *Config) error
- func Handlers(h ...Handler) func(cfg *Config) error
- func Insecure(b bool) func(cfg *Config) error
- func LibP2PLogLevel(l log.LogLevel) func(cfg *Config) error
- func ListenAddresses(ss ...string) func(cfg *Config) error
- func Logger(l log.StandardLogger) func(cfg *Config) error
- func MaxMessageSize(i int) func(cfg *Config) error
- func OwnershipTTLFor(heartbeat time.Duration) time.Duration
- func RoomName(s string) func(cfg *Config) error
- func SealKeyInterval(i int) func(cfg *Config) error
- func SealKeyLength(i int) func(cfg *Config) error
- func WatchStaleDirectConns(h host.Host, opts ...StaleConnsOption) io.Closer
- func WithBlacklist(i ...string) func(cfg *Config) error
- func WithDiscoveryBootstrapPeers(a discovery.AddrList) func(cfg *Config) error
- func WithDiscoveryInterval(t time.Duration) func(cfg *Config) error
- func WithInterfaceAddress(i string) func(cfg *Config) error
- func WithLedgerAnnounceTime(t time.Duration) func(cfg *Config) error
- func WithLedgerInterval(t time.Duration) func(cfg *Config) error
- func WithLibp2pAdditionalOptions(i ...libp2p.Option) func(cfg *Config) error
- func WithLibp2pOptions(i ...libp2p.Option) func(cfg *Config) error
- func WithNetworkService(ns ...NetworkService) func(cfg *Config) error
- func WithOwnership(mode blockchain.OwnershipMode, ttl time.Duration) func(cfg *Config) error
- func WithPrivKey(b []byte) func(cfg *Config) error
- func WithStaticPeer(ip string, p peer.ID) func(cfg *Config) error
- func WithStore(s blockchain.Store) func(cfg *Config) error
- func WithStreamHandler(id protocol.Protocol, h StreamHandler) func(cfg *Config) error
- type Config
- type Gater
- type Handler
- type NetworkService
- type Node
- func (e *Node) BlockSubnet(cidr string) error
- func (e *Node) ConnectionGater() *conngater.BasicConnectionGater
- func (e *Node) Host() host.Host
- func (e *Node) Ledger() (*blockchain.Ledger, error)
- func (e *Node) PeerGater() Gater
- func (e *Node) PublishMessage(m *hub.Message) error
- func (e *Node) Start(ctx context.Context) error
- type OTP
- type OTPConfig
- type Option
- type Sealer
- type ServiceDiscovery
- type StaleConnsOption
- type StreamHandler
- type YAMLConnectionConfig
Constants ¶
const DefaultOwnershipTTL = ownershipTTLHeartbeats * 120 * time.Second
DefaultOwnershipTTL is the liveness window used when ownership is enabled without an explicit TTL. It is OwnershipTTLFor(services.DefaultHealthcheckInterval) — four 120s heartbeats, so 8 minutes — spelled out as a constant because pkg/services imports this package and cannot be imported back.
This was 2 minutes, which was exactly the nominal heartbeat interval and so below the 180s a healthy node can actually take: live nodes were routinely treated as inactive on stock settings.
Variables ¶
var DisableStaleConnsWatcher = func(cfg *Config) error { cfg.DisableStaleConnsWatcher = true return nil }
DisableStaleConnsWatcher starts the node without the watcher that replaces stale direct connections, described in WatchStaleDirectConns.
var EnableGenericHub = func(cfg *Config) error { cfg.GenericHub = true return nil }
EnableGenericHub enables an additional generic hub between peers. This can be used to exchange messages between peers that are not related to any blockchain event. For instance, messages could be used for authentication, or for other sort of application.
var FallbackDefaults libp2p.Option = func(cfg *libp2p.Config) error { for _, def := range defaults { if !def.fallback(cfg) { continue } if err := cfg.Apply(def.opt); err != nil { return err } } return nil }
FallbackDefaults applies default options to the libp2p node if and only if no other relevant options have been applied. will be appended to the options passed into New.
Functions ¶
func DiscoveryService ¶
func DiscoveryService(s ...ServiceDiscovery) func(cfg *Config) error
DiscoveryService Adds the service given as argument to the discovery services
func ExchangeKeys ¶
func FromBase64 ¶
func GenericChannelHandlers ¶ added in v0.13.0
GenericChannelHandlers adds a handler to the list that is called on each received message in the generic channel (not the one allocated for the blockchain)
func ListenAddresses ¶
func MaxMessageSize ¶
func OwnershipTTLFor ¶ added in v0.35.4
OwnershipTTLFor returns the liveness window to use for a network whose alive service heartbeats every heartbeat. Callers that let the operator tune the heartbeat interval must derive the TTL through this function rather than using DefaultOwnershipTTL, or raising the heartbeat alone will start expiring healthy nodes.
func SealKeyInterval ¶
func SealKeyLength ¶
func WatchStaleDirectConns ¶ added in v0.36.0
func WatchStaleDirectConns(h host.Host, opts ...StaleConnsOption) io.Closer
WatchStaleDirectConns closes direct connections that a relayed connection shows to be dead and dials the peer directly again.
A peer that dials through a relay while this host holds a direct connection to it has no working direct connection of its own, because libp2p reuses a direct connection before it dials. The direct connection on this side is then dead, for example because the peer changed networks, but it stays open until the QUIC idle timeout. While it is open, the hole puncher that reacts to the relayed connection finds it and does nothing.
The watcher closes it as soon as the relayed connection arrives. libp2p's hole puncher waits for identify over the relayed connection, so on most paths it then finds no direct connection and dials or hole punches. When identify wins that race, nothing in libp2p tries again, so once identify has given this host the peer's new addresses the watcher dials them itself. It also dials when identify fails, and then relies on the host to find the peer's addresses, as edgevpn's routed host does through the DHT. That dial reaches a peer whose new address accepts incoming connections; a peer behind NAT still needs the hole puncher.
A stale direct connection younger than the grace (see WithStaleConnsGrace) stays open. When it, or any other direct connection, closes and leaves the peer with only relayed connections, the watcher dials the peer directly as well.
Close stops the watcher, cancels its dials and waits for them.
func WithBlacklist ¶ added in v0.8.4
func WithInterfaceAddress ¶
func WithLibp2pOptions ¶
WithLibp2pOptions Overrides defaults options
func WithNetworkService ¶
func WithNetworkService(ns ...NetworkService) func(cfg *Config) error
func WithOwnership ¶ added in v0.35.0
func WithOwnership(mode blockchain.OwnershipMode, ttl time.Duration) func(cfg *Config) error
WithOwnership enables ledger ownership enforcement at the given mode and liveness TTL (a zero ttl uses the node default).
func WithPrivKey ¶ added in v0.19.1
func WithStaticPeer ¶ added in v0.19.1
func WithStreamHandler ¶
func WithStreamHandler(id protocol.Protocol, h StreamHandler) func(cfg *Config) error
WithStreamHandler adds a handler to the list that is called on each received message
Types ¶
type Config ¶
type Config struct {
// ExchangeKey is a Symmetric key used to seal the messages
ExchangeKey string
// RoomName is the OTP token gossip room where all peers are subscribed to
RoomName string
// ListenAddresses is the discovery peer initial bootstrap addresses
ListenAddresses []discovery.AddrList
// Insecure disables secure p2p e2e encrypted communication
Insecure bool
// Handlers are a list of handlers subscribed to messages received by the vpn interface
Handlers, GenericChannelHandler []Handler
MaxMessageSize int
SealKeyInterval int
ServiceDiscovery []ServiceDiscovery
NetworkServices []NetworkService
Logger log.StandardLogger
SealKeyLength int
InterfaceAddress string
Store blockchain.Store
// Handle is a handle consumed by HumanInterfaces to handle received messages
Handle func(bool, *hub.Message)
StreamHandlers map[protocol.Protocol]StreamHandler
AdditionalOptions, Options []libp2p.Option
DiscoveryInterval, LedgerSyncronizationTime, LedgerAnnounceTime time.Duration
DiscoveryBootstrapPeers discovery.AddrList
Whitelist, Blacklist []string
// GenericHub enables generic hub
GenericHub bool
PrivateKey []byte
PeerTable map[string]peer.ID
Sealer Sealer
PeerGater Gater
// OwnershipMode selects ledger ownership enforcement (off/observe/enforce).
// OwnershipTTL is the liveness window after which an inactive owner's
// entries may be reclaimed/reaped.
OwnershipMode blockchain.OwnershipMode
OwnershipTTL time.Duration
// DisableStaleConnsWatcher keeps the node from installing the watcher
// described in WatchStaleDirectConns.
DisableStaleConnsWatcher bool
}
Config is the node configuration
type NetworkService ¶
NetworkService is a service running over the network. It takes a context, a node and a ledger
type Node ¶
type Node struct {
MessageHub *hub.MessageHub
sync.Mutex
// contains filtered or unexported fields
}
func (*Node) BlockSubnet ¶ added in v0.8.4
BlockSubnet blocks the CIDR subnet from connections
func (*Node) ConnectionGater ¶ added in v0.8.4
func (e *Node) ConnectionGater() *conngater.BasicConnectionGater
ConnectionGater returns the underlying libp2p conngater
func (*Node) Ledger ¶
func (e *Node) Ledger() (*blockchain.Ledger, error)
Ledger return the ledger which uses the node connection to broadcast messages
func (*Node) PublishMessage ¶ added in v0.13.0
PublishMessage publishes a message to the generic channel (if enabled) See GenericChannelHandlers(..) to attach handlers to receive messages from this channel.
type ServiceDiscovery ¶
type StaleConnsOption ¶ added in v0.36.0
type StaleConnsOption func(*staleConnsWatcher)
StaleConnsOption configures WatchStaleDirectConns.
func WithStaleConnsGrace ¶ added in v0.36.0
func WithStaleConnsGrace(d time.Duration) StaleConnsOption
WithStaleConnsGrace sets how much older than an incoming relayed connection a direct connection must be before the watcher treats it as stale. The default is network.DialPeerTimeout at the time the watcher is created.
A single dial to a peer can open a direct and a relayed connection: the swarm starts relay addresses 500 ms after direct ones (RelayDelay in p2p/net/swarm/dial_ranker.go) and lets a relay dial already in flight finish after a direct connection succeeds (p2p/net/swarm/dial_worker.go). Such a dial ends within the peer dial timeout. A relayed connection that arrives more than DialPeerTimeout after a direct one opened therefore comes from a new dial by the peer, and the peer dials again only when it has no working direct connection.
func WithStaleConnsLogger ¶ added in v0.36.0
func WithStaleConnsLogger(l log.StandardLogger) StaleConnsOption
WithStaleConnsLogger sets the logger for debug messages about closed connections and dials.
type StreamHandler ¶ added in v0.7.2
type StreamHandler func(*Node, *blockchain.Ledger) func(stream network.Stream)
type YAMLConnectionConfig ¶
type YAMLConnectionConfig struct {
OTP OTP `yaml:"otp"`
RoomName string `yaml:"room"`
Rendezvous string `yaml:"rendezvous"`
MDNS string `yaml:"mdns"`
MaxMessageSize int `yaml:"max_message_size"`
}
func GenerateNewConnectionData ¶
func GenerateNewConnectionData(i ...int) *YAMLConnectionConfig
func (YAMLConnectionConfig) Base64 ¶
func (y YAMLConnectionConfig) Base64() string
Base64 returns the base64 string representation of the connection
func (YAMLConnectionConfig) YAML ¶
func (y YAMLConnectionConfig) YAML() string
YAML returns the connection config as yaml string