Documentation ¶
Index ¶
- Variables
- func GetPeerProtocolVersion(ps peerstore.Peerstore, pid peer.ID) string
- func GetPeerProtocols(ps peerstore.Peerstore, pid peer.ID) []string
- func GetPeerUserAgent(ps peerstore.Peerstore, pid peer.ID) string
- type MonitorConfig
- type Node
- func (n *Node) AddConnectionGater(connGaters ...coreConnmgr.ConnectionGater)
- func (n *Node) AddMessageHandler(messageHandlers ...sets.MessageHandler)
- func (n *Node) AddNodeEventHandler(eventHandler ...sets.NodeEventHandler)
- func (n *Node) AddNotifee(notifees ...network.Notifiee)
- func (n *Node) AddPubSubEventHandler(eventHandler ...sets.PubSubEventHandler)
- func (n *Node) AddValidator(validator sets.Validator)
- func (n *Node) Addrs() []multiaddr.Multiaddr
- func (n *Node) Connect(maddr multiaddr.Multiaddr) error
- func (n *Node) Host() host.Host
- func (n *Node) Peerstore() peerstore.Peerstore
- func (n *Node) PubSub() *pubsub.PubSub
- func (n *Node) RemoveNotifee(notifees ...network.Notifiee)
- func (n *Node) Start(ctx context.Context) error
- func (n *Node) Subscribe(topic string) (*Subscription, error)
- func (n *Node) Subscription(topic string) (*Subscription, error)
- func (n *Node) Unsubscribe(topic string) error
- func (n *Node) Wait() <-chan error
- type Options
- func ConnectionLimit(low, high int, grace time.Duration) Options
- func ConnectionLogger() Options
- func Denylist(addrs []multiaddr.Multiaddr) Options
- func DialTimeout(t time.Duration) Options
- func DirectPeers(addrs []multiaddr.Multiaddr) Options
- func DisablePubSub() Options
- func Discovery(bootstrapAddrs []multiaddr.Multiaddr) Options
- func ExternalAddr(addr multiaddr.Multiaddr) Options
- func ListenAddrs(addrs []multiaddr.Multiaddr) Options
- func Logger(logger log.Logger) Options
- func MessagePrivKey(sk crypto.PrivKey) Options
- func Monitor(cfg MonitorConfig) Options
- func PeerLogger() Options
- func PeerPrivKey(sk crypto.PrivKey) Options
- func PeerScoring(params *pubsub.PeerScoreParams, thresholds *pubsub.PeerScoreThresholds, ...) Options
- func PubsubEventTracer(tracer pubsub.EventTracer) Options
- func RateLimiter(cfg RateLimiterConfig) Options
- func UserAgent(userAgent string) Options
- type RateLimiterConfig
- type Subscription
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadySubscribed = errors.New("topic is already subscribed")
var ErrConnectionClosed = errors.New("connection is closed")
var ErrNilMessage = errors.New("message is nil")
var ErrNotSubscribed = errors.New("topic is not subscribed")
var ErrPubSubDisabled = errors.New("pubsub protocol is disabled")
Functions ¶
func GetPeerProtocolVersion ¶
Types ¶
type MonitorConfig ¶
type MonitorConfig struct { // ShowLogOnChange enables logging immediately when the number of peers // or connections changes. ShowLogOnChange bool // ShowLogInterval specifies the interval between logging. // When ShowLogOnChange is true, then the delay resets after each change. ShowLogInterval time.Duration }
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a single node in the P2P network. It wraps the libp2p library to provide an easier to use and use-case agnostic interface for the pubsub system.
func (*Node) AddConnectionGater ¶
func (n *Node) AddConnectionGater(connGaters ...coreConnmgr.ConnectionGater)
func (*Node) AddMessageHandler ¶
func (n *Node) AddMessageHandler(messageHandlers ...sets.MessageHandler)
func (*Node) AddNodeEventHandler ¶
func (n *Node) AddNodeEventHandler(eventHandler ...sets.NodeEventHandler)
func (*Node) AddNotifee ¶
func (*Node) AddPubSubEventHandler ¶
func (n *Node) AddPubSubEventHandler(eventHandler ...sets.PubSubEventHandler)
func (*Node) AddValidator ¶
func (*Node) RemoveNotifee ¶
func (*Node) Subscription ¶
func (n *Node) Subscription(topic string) (*Subscription, error)
func (*Node) Unsubscribe ¶
type Options ¶
func ConnectionLimit ¶
ConnectionLimit limits the number of connections. When the number of connections reaches a high value, then as many connections will be dropped until we reach a low number of connections.
func ConnectionLogger ¶
func ConnectionLogger() Options
ConnectionLogger logs connected and disconnected hosts,
func Denylist ¶
func Denylist(addrs []multiaddr.Multiaddr) Options
Denylist allows to block peer by their IP addresses or IDs.
func DialTimeout ¶
DialTimeout sets dial timeout for libp2p nodes.
func DirectPeers ¶
func DirectPeers(addrs []multiaddr.Multiaddr) Options
DirectPeers enforces direct connection with given peers. Note that the direct connection should be symmetrically configured at both ends.
func Discovery ¶
func Discovery(bootstrapAddrs []multiaddr.Multiaddr) Options
Discovery configures node to use kad-dht for node discovery.
func ExternalAddr ¶
func ExternalAddr(addr multiaddr.Multiaddr) Options
ExternalAddr configures node to advertise the given addresses.
func ListenAddrs ¶
func ListenAddrs(addrs []multiaddr.Multiaddr) Options
ListenAddrs configures node to listen on the given addresses.
func MessagePrivKey ¶
MessagePrivKey configures node to use given key to sign messages.
func Monitor ¶
func Monitor(cfg MonitorConfig) Options
func PeerLogger ¶
func PeerLogger() Options
PeerLogger logs all peers handled by libp2p's pubsub system.
func PeerPrivKey ¶
PeerPrivKey configures node to use given key as its identity.
func PeerScoring ¶
func PeerScoring( params *pubsub.PeerScoreParams, thresholds *pubsub.PeerScoreThresholds, topicScoreParams func(topic string) *pubsub.TopicScoreParams) Options
PeerScoring configures peer scoring parameters used in a pubsub system.
func PubsubEventTracer ¶
func PubsubEventTracer(tracer pubsub.EventTracer) Options
PubsubEventTracer provides a tracer for the pubsub system.
func RateLimiter ¶
func RateLimiter(cfg RateLimiterConfig) Options
RateLimiter limits the number of bytes which is allowed to receive from the network using the token bucket algorithm: https://en.wikipedia.org/wiki/Token_bucket
bytesPerSecond is the maximum number of bytes/s that can be received from a single peer.
burstSize is a burst value in bytes applied for a messages received from a singe peer.
type RateLimiterConfig ¶
type RateLimiterConfig struct { // BytesPerSecond is the maximum rate of messages in bytes/s that can be // created by a single peer. BytesPerSecond float64 // BurstSize is a burst value in bytes for a messages created from a singe // peer. BurstSize int // RelayBytesPerSecond is the maximum rate of messages in bytes/s that can // be relayed by a single relay. RelayBytesPerSecond float64 // RelayBurstSize is a burst value in bytes for a messages relayed by // a singe peer. RelayBurstSize int }
RateLimiterConfig is a configuration for the RateLimiter option.
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
func (*Subscription) Next ¶
func (s *Subscription) Next() chan *pubsub.Message
func (*Subscription) Publish ¶
func (s *Subscription) Publish(msg []byte) error