rainbowbee

package module
v0.0.0-...-6124036 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2025 License: MIT Imports: 25 Imported by: 0

README

rainbow-bee

A p2p network library for Go.

Roadmap

  • Core
    • interface
    • crypto
  • Networks
    • TCP-network
    • UDP-Quic-network
    • WebSocket-network
  • PeerStore
    • protocol book
    • address book
    • peer store
  • Components
    • connection supervisor
    • level connection manager
    • protocol manager
    • protocol exchanger
    • send stream pool
    • send stream pool manager
    • receive stream manager
    • blacklist
  • Host(MVP)
  • Service
    • discovery (protocol based)
    • broadcast
      • pubsub
    • group multicast (in progress)
    • consensus
      • Raft
  • All testcases

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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

func (h *Host) AddDirectPeer(dp ma.Multiaddr) error

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) Context

func (h *Host) Context() context.Context

Context returns the context associated with the host.

func (*Host) Dial

func (h *Host) Dial(remoteAddr ma.Multiaddr) (network.Connection, error)

Dial initiates a connection to a remote address specified by a multiaddress.

func (*Host) ID

func (h *Host) ID() peer.ID

ID returns the local peer ID of the host.

func (*Host) LocalAddresses

func (h *Host) LocalAddresses() []ma.Multiaddr

LocalAddresses returns the list of multiaddresses the host is listening on.

func (*Host) Logger

func (h *Host) Logger() *rainbowlog.Logger

func (*Host) Network

func (h *Host) Network() network.Network

Network returns the network associated with the host.

func (*Host) Notify

func (h *Host) Notify(notifiee host.Notifiee)

Notify adds a notifiee to the host, allowing it to receive notifications.

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) PeerStore

func (h *Host) PeerStore() store.PeerStore

PeerStore returns the peer store associated with the host.

func (*Host) PeerSupportProtocol

func (h *Host) PeerSupportProtocol(pid peer.ID, protocolID protocol.ID) bool

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

func (h *Host) SendMsg(protocolID protocol.ID, receiverPID peer.ID, msgPayload []byte) (err error)

SendMsg sends a message payload to a specific peer using the specified protocol ID.

func (*Host) Start

func (h *Host) Start() (err error)

Start starts the host, allowing it to handle incoming requests or messages.

func (*Host) Stop

func (h *Host) Stop() error

Stop stops the host, closing connections and stopping necessary components.

func (*Host) UnregisterMsgPayloadHandler

func (h *Host) UnregisterMsgPayloadHandler(protocolID protocol.ID) error

UnregisterMsgPayloadHandler unregisters a message payload handler for a given 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

type Option func(*Host) error

Option represents a function that configures the Host.

func WithBlackNetAddr

func WithBlackNetAddr(netAddr ...string) Option

WithBlackNetAddr adds blacklisted network addresses to the Host. Connections to these addresses will be rejected.

func WithBlackPIDs

func WithBlackPIDs(pid ...peer.ID) Option

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

func WithContext(ctx context.Context) Option

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

func WithDirectPeer(pid peer.ID, address ma.Multiaddr) Option

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

func WithEasyToUseTLS(priKey cc.PriKey) Option

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

func WithHandlerExecutorConcurrency(puc uint8) Option

WithHandlerExecutorConcurrency sets the concurrency level for the handler executor. Higher concurrency improves handler execution throughput.

func WithListenAddresses

func WithListenAddresses(addresses ...ma.Multiaddr) Option

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

func WithPayloadHandlerRouterConcurrency(c uint8) Option

WithPayloadHandlerRouterConcurrency sets the concurrency level for the payload handler router. Higher concurrency improves message routing throughput.

func WithPayloadUnmarshalConcurrency

func WithPayloadUnmarshalConcurrency(c uint8) Option

WithPayloadUnmarshalConcurrency sets the concurrency level for the payload unmarshaler. Higher concurrency improves message processing throughput.

func WithPeerStore

func WithPeerStore(peerStore store.PeerStore) Option

WithPeerStore sets the peer store for the Host. The peer store manages peer information and metadata.

func WithPriKey

func WithPriKey(priKey cc.PriKey) Option

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.

func WithTLS

func WithTLS(tlsConfig *tls.Config, pidLoader peer.IDLoader) Option

WithTLS enables TLS for the Host with the provided TLS configuration and peer ID loader. TLS ensures secure communication between peers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL