rainbowbee

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

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

Go to latest
Published: Mar 25, 2024 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 (
	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
	// 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 an option function for configuring a Host.

func WithBlackNetAddr

func WithBlackNetAddr(netAddr ...string) Option

WithBlackNetAddr adds blacklisted network addresses to the Host.

func WithBlackPIDs

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

WithBlackPIDs adds blacklisted peer IDs to the Host.

func WithBlacklist

func WithBlacklist(blacklist blacklist.PeerBlackList) Option

WithBlacklist sets the peer blacklist for the Host.

func WithConnectionManager

func WithConnectionManager(connMgr manager.ConnectionManager) Option

WithConnectionManager sets the connection manager for the Host.

func WithConnectionSupervisor

func WithConnectionSupervisor(supervisor manager.ConnectionSupervisor) Option

WithConnectionSupervisor sets the connection supervisor for the Host.

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets the context for the Host.

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.

func WithEasyToUseTLS

func WithEasyToUseTLS(priKey cc.PriKey) Option

WithEasyToUseTLS will perform the same logic as WithPriKey and use the given priKey to generate a tls.Config with a self-signed certificate and also set up a corresponding PIDLoader. This option facilitates quick start for users who do not require custom tls.Config.

func WithHandlerExecutorConcurrency

func WithHandlerExecutorConcurrency(puc uint8) Option

WithHandlerExecutorConcurrency sets the concurrency of the handler executor.

func WithListenAddresses

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

WithListenAddresses sets the listen addresses for the Host.

func WithMsgCompressible

func WithMsgCompressible() Option

WithMsgCompressible sets the Host to compress messages.

func WithNetworkType

func WithNetworkType(networkType NetworkType) Option

WithNetworkType sets the network type for the Host.

func WithPayloadHandlerRouterConcurrency

func WithPayloadHandlerRouterConcurrency(c uint8) Option

WithPayloadHandlerRouterConcurrency sets the concurrency of the payload handler router.

func WithPayloadUnmarshalConcurrency

func WithPayloadUnmarshalConcurrency(c uint8) Option

WithPayloadUnmarshalConcurrency sets the concurrency of the payload unmarshaler.

func WithPeerStore

func WithPeerStore(peerStore store.PeerStore) Option

WithPeerStore sets the peer store for the Host.

func WithPriKey

func WithPriKey(priKey cc.PriKey) Option

WithPriKey sets the private key for the Host. This Option will also set the Local PID at the same time.

func WithProtocolExchanger

func WithProtocolExchanger(protocolExr manager.ProtocolExchanger) Option

WithProtocolExchanger sets the protocol exchanger for the Host.

func WithProtocolManager

func WithProtocolManager(protocolMgr manager.ProtocolManager) Option

WithProtocolManager sets the protocol manager for the Host.

func WithReceiveStreamMgr

func WithReceiveStreamMgr(receiveStreamMgr manager.ReceiveStreamManager) Option

WithReceiveStreamMgr sets the receive stream manager for the Host.

func WithSendStreamMgr

func WithSendStreamMgr(sendStreamMgr manager.SendStreamPoolManager) Option

WithSendStreamMgr sets the send stream pool manager for the Host.

func WithSendStreamPoolBuilder

func WithSendStreamPoolBuilder(builder manager.SendStreamPoolBuilder) Option

WithSendStreamPoolBuilder sets the send stream pool builder for the Host.

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.

Jump to

Keyboard shortcuts

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