Documentation
¶
Index ¶
- Variables
- type Host
- func (h *Host) AddDirectPeer(dp ma.Multiaddr) error
- func (h *Host) ClearDirectPeers()
- func (h *Host) ConnectionManager() manager.ConnectionManager
- func (h *Host) Context() context.Context
- func (h *Host) Dial(remoteAddr ma.Multiaddr) (network.Connection, error)
- func (h *Host) ID() peer.ID
- func (h *Host) LocalAddresses() []ma.Multiaddr
- func (h *Host) Logger() *rainbowlog.Logger
- func (h *Host) Network() network.Network
- func (h *Host) Notify(notifiee host.Notifiee)
- func (h *Host) PeerBlackList() blacklist.PeerBlackList
- func (h *Host) PeerProtocols(protocolIDs []protocol.ID) (peerProtocols []*host.PeerProtocols, err error)
- func (h *Host) PeerStore() store.PeerStore
- func (h *Host) PeerSupportProtocol(pid peer.ID, protocolID protocol.ID) bool
- func (h *Host) ProtocolManager() manager.ProtocolManager
- func (h *Host) RegisterMsgPayloadHandler(protocolID protocol.ID, handler handler.MsgPayloadHandler) error
- func (h *Host) SendMsg(protocolID protocol.ID, receiverPID peer.ID, msgPayload []byte) (err error)
- func (h *Host) Start() (err error)
- func (h *Host) Stop() error
- func (h *Host) UnregisterMsgPayloadHandler(protocolID protocol.ID) error
- type NetworkConfig
- type NetworkType
- type Option
- func WithBlackNetAddr(netAddr ...string) Option
- func WithBlackPIDs(pid ...peer.ID) Option
- func WithBlacklist(blacklist blacklist.PeerBlackList) Option
- func WithConnectionManager(connMgr manager.ConnectionManager) Option
- func WithConnectionSupervisor(supervisor manager.ConnectionSupervisor) Option
- func WithContext(ctx context.Context) Option
- func WithDialLoopbackEnable() Option
- func WithDirectPeer(pid peer.ID, address ma.Multiaddr) Option
- func WithEasyToUseTLS(priKey cc.PriKey) Option
- func WithHandlerExecutorConcurrency(puc uint8) Option
- func WithListenAddresses(addresses ...ma.Multiaddr) Option
- func WithMsgCompressible() Option
- func WithNetworkType(networkType NetworkType) Option
- func WithPayloadHandlerRouterConcurrency(c uint8) Option
- func WithPayloadUnmarshalConcurrency(c uint8) Option
- func WithPeerStore(peerStore store.PeerStore) Option
- func WithPriKey(priKey cc.PriKey) Option
- func WithProtocolExchanger(protocolExr manager.ProtocolExchanger) Option
- func WithProtocolManager(protocolMgr manager.ProtocolManager) Option
- func WithReceiveStreamMgr(receiveStreamMgr manager.ReceiveStreamManager) Option
- func WithSendStreamMgr(sendStreamMgr manager.SendStreamPoolManager) Option
- func WithSendStreamPoolBuilder(builder manager.SendStreamPoolBuilder) Option
- func WithTLS(tlsConfig *tls.Config, pidLoader peer.IDLoader) Option
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilPrivateKey = errors.New("private key is nil") ErrPeerNotConnected = errors.New("peer is not connected") ErrProtocolNotSupported = errors.New("protocol is not supported") ErrSendStreamPoolNotFound = errors.New("send stream pool not found") ErrSendStreamWriteFailed = errors.New("failed to write to send stream") ErrWriteMsgIncompletely = errors.New("write msg incompletely") ErrInvalidAddr = errors.New("invalid address") ErrNoAddressFoundInStore = errors.New("no address found in store") ErrAllDialFailed = errors.New("all dial failed") )
var ( ErrNilTLSConfig = errors.New("nil tls config") ErrUnknownNetworkType = errors.New("unknown network type") )
Functions ¶
This section is empty.
Types ¶
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host is the main struct representing the Rainbow-bee host.
func NewHost ¶
func NewHost(logger *rainbowlog.Logger, opts ...Option) (h *Host, err error)
NewHost creates a new host with the provided options.
func (*Host) AddDirectPeer ¶
AddDirectPeer adds a direct peer to the host.
func (*Host) ClearDirectPeers ¶
func (h *Host) ClearDirectPeers()
ClearDirectPeers removes all direct peers from the host.
func (*Host) ConnectionManager ¶
func (h *Host) ConnectionManager() manager.ConnectionManager
ConnectionManager returns the connection manager associated with the host.
func (*Host) LocalAddresses ¶
LocalAddresses returns the list of multiaddresses the host is listening on.
func (*Host) Logger ¶
func (h *Host) Logger() *rainbowlog.Logger
func (*Host) PeerBlackList ¶
func (h *Host) PeerBlackList() blacklist.PeerBlackList
PeerBlackList returns the peer blacklist associated with the host.
func (*Host) PeerProtocols ¶
func (h *Host) PeerProtocols(protocolIDs []protocol.ID) (peerProtocols []*host.PeerProtocols, err error)
PeerProtocols returns a list of peer protocols that match the specified protocol IDs.
func (*Host) PeerSupportProtocol ¶
PeerSupportProtocol checks if a peer supports a specific protocol.
func (*Host) ProtocolManager ¶
func (h *Host) ProtocolManager() manager.ProtocolManager
ProtocolManager returns the protocol manager associated with the host.
func (*Host) RegisterMsgPayloadHandler ¶
func (h *Host) RegisterMsgPayloadHandler(protocolID protocol.ID, handler handler.MsgPayloadHandler) error
RegisterMsgPayloadHandler registers a message payload handler for a given protocol ID.
func (*Host) SendMsg ¶
SendMsg sends a message payload to a specific peer using the specified protocol ID.
type NetworkConfig ¶
type NetworkConfig struct {
Type NetworkType
Ctx context.Context
PrivateKey cc.PriKey
TLSEnabled bool
TLSConfig *tls.Config
PIDLoader peer.IDLoader
DialLoopbackEnabled bool
// contains filtered or unexported fields
}
NetworkConfig represents the configuration for creating a network instance.
func (NetworkConfig) NewNetwork ¶
func (c NetworkConfig) NewNetwork(logger *rainbowlog.Logger) (network.Network, error)
NewNetwork creates a new network instance based on the configuration.
type NetworkType ¶
type NetworkType uint8
NetworkType represents the type of network.
const ( NetworkTypeUnknown NetworkType = iota NetworkTypeTCP NetworkTypeUDPQuic )
func (NetworkType) String ¶
func (t NetworkType) String() string
String returns the string representation of the NetworkType.
type Option ¶
Option represents a function that configures the Host.
func WithBlackNetAddr ¶
WithBlackNetAddr adds blacklisted network addresses to the Host. Connections to these addresses will be rejected.
func WithBlackPIDs ¶
WithBlackPIDs adds blacklisted peer IDs to the Host. Connections to these peers will be rejected.
func WithBlacklist ¶
func WithBlacklist(blacklist blacklist.PeerBlackList) Option
WithBlacklist sets the peer blacklist for the Host. Blacklisted peers are prevented from connecting to or interacting with the Host.
func WithConnectionManager ¶
func WithConnectionManager(connMgr manager.ConnectionManager) Option
WithConnectionManager sets the connection manager for the Host. The connection manager handles connection establishment and teardown.
func WithConnectionSupervisor ¶
func WithConnectionSupervisor(supervisor manager.ConnectionSupervisor) Option
WithConnectionSupervisor sets the connection supervisor for the Host. The connection supervisor monitors and manages active connections.
func WithContext ¶
WithContext sets the context for the Host. The provided context is used for cancellation and timeout control.
func WithDialLoopbackEnable ¶
func WithDialLoopbackEnable() Option
WithDialLoopbackEnable enables loopback dialing for the Host. When enabled, the Host can establish connections to loopback addresses (e.g., 127.0.0.1). This is particularly useful for testing or local communication scenarios.
func WithDirectPeer ¶
WithDirectPeer adds a direct peer with the given peer ID and address to the Host. Direct peers are used for establishing connections without discovery.
func WithEasyToUseTLS ¶
WithEasyToUseTLS enables TLS with a self-signed certificate and a default peer ID loader. This option simplifies TLS setup for quick start scenarios.
func WithHandlerExecutorConcurrency ¶
WithHandlerExecutorConcurrency sets the concurrency level for the handler executor. Higher concurrency improves handler execution throughput.
func WithListenAddresses ¶
WithListenAddresses sets the listen addresses for the Host. These addresses are used to accept incoming connections.
func WithMsgCompressible ¶
func WithMsgCompressible() Option
WithMsgCompressible enables message compression for the Host. Compressed messages reduce network bandwidth usage.
func WithNetworkType ¶
func WithNetworkType(networkType NetworkType) Option
WithNetworkType sets the network type for the Host. The network type determines the underlying transport protocol.
func WithPayloadHandlerRouterConcurrency ¶
WithPayloadHandlerRouterConcurrency sets the concurrency level for the payload handler router. Higher concurrency improves message routing throughput.
func WithPayloadUnmarshalConcurrency ¶
WithPayloadUnmarshalConcurrency sets the concurrency level for the payload unmarshaler. Higher concurrency improves message processing throughput.
func WithPeerStore ¶
WithPeerStore sets the peer store for the Host. The peer store manages peer information and metadata.
func WithPriKey ¶
WithPriKey sets the private key for the Host. This also sets the local peer ID derived from the private key.
func WithProtocolExchanger ¶
func WithProtocolExchanger(protocolExr manager.ProtocolExchanger) Option
WithProtocolExchanger sets the protocol exchanger for the Host. The protocol exchanger facilitates protocol negotiation and selection between peers.
func WithProtocolManager ¶
func WithProtocolManager(protocolMgr manager.ProtocolManager) Option
WithProtocolManager sets the protocol manager for the Host. The protocol manager is responsible for registering and managing supported protocols.
func WithReceiveStreamMgr ¶
func WithReceiveStreamMgr(receiveStreamMgr manager.ReceiveStreamManager) Option
WithReceiveStreamMgr sets the receive stream manager for the Host. The receive stream manager handles incoming streams and dispatches them to the appropriate handlers.
func WithSendStreamMgr ¶
func WithSendStreamMgr(sendStreamMgr manager.SendStreamPoolManager) Option
WithSendStreamMgr sets the send stream pool manager for the Host. The manager oversees the lifecycle of send streams.
func WithSendStreamPoolBuilder ¶
func WithSendStreamPoolBuilder(builder manager.SendStreamPoolBuilder) Option
WithSendStreamPoolBuilder sets the send stream pool builder for the Host. The builder creates pools of send streams for efficient message transmission.