relay

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(ln *libp2pnet.LibP2pNet, opts ...NetOption) error

Apply options.

func NewNet

func NewNet(cfg *NetConfig, readySignalC chan struct{}) (protocol.Net, error)

NewNet create a net instance

Types

type CustomTrustRootsConfig

type CustomTrustRootsConfig struct {
	ChainId    string   `mapstructure:"chain_id"`
	TrustRoots []string `mapstructure:"trust_roots"`
}

CustomTrustRootsConfig .

type NetConfig

type NetConfig struct {
	AuthType                string                   `mapstructure:"auth_type"`
	ListenAddr              string                   `mapstructure:"listen_addr"`
	PeerStreamPoolSize      int                      `mapstructure:"peer_stream_pool_size"`
	MaxPeerCountAllow       int                      `mapstructure:"max_peer_count_allow"`
	PeerEliminationStrategy int                      `mapstructure:"peer_elimination_strategy"` // default LIFO
	Seeds                   []string                 `mapstructure:"seeds"`
	TLSConfig               netTlsConfig             `mapstructure:"tls"`
	BlackList               blackList                `mapstructure:"blacklist"`
	IsNetInsecurity         bool                     `mapstructure:"is_net_insecurity"`
	UseNetMsgCompression    bool                     `mapstructure:"use_net_msg_compression"`
	CustomTrustRootsConfigs []CustomTrustRootsConfig `mapstructure:"custom_trust_roots"` // custom trust root
}

NetConfig .

type NetOption

type NetOption func(ln *libp2pnet.LibP2pNet) error

NetOption is a function apply options to net instance.

func WithBlackAddresses

func WithBlackAddresses(blackAddresses ...string) NetOption

WithBlackAddresses set addresses of the nodes for blacklist.

func WithBlackNodeIds

func WithBlackNodeIds(blackNodeIds ...string) NetOption

WithBlackNodeIds set ids of the nodes for blacklist.

func WithCrypto

func WithCrypto(pkMode bool, keyFile string, certFile string) NetOption

WithCrypto set private key file and tls cert file for the net to create connection.

func WithInsecurity

func WithInsecurity(isInsecurity bool) NetOption

WithInsecurity set is insecurity

func WithListenAddr

func WithListenAddr(addr string) NetOption

WithListenAddr set addr that the local net will listen on.

func WithMaxPeerCountAllowed

func WithMaxPeerCountAllowed(max int) NetOption

WithMaxPeerCountAllowed set max count of nodes that connected to us.

func WithPeerEliminationStrategy

func WithPeerEliminationStrategy(strategy int) NetOption

WithPeerEliminationStrategy set the strategy for eliminating node when the count of nodes that connected to us reach the max value.

func WithPeerStreamPoolSize

func WithPeerStreamPoolSize(size int) NetOption

WithPeerStreamPoolSize set the max stream pool size for every node that connected to us.

func WithReadySignalC

func WithReadySignalC(signalC chan struct{}) NetOption

WithReadySignalC set signal channel

func WithSeeds

func WithSeeds(seeds ...string) NetOption

WithSeeds set addresses of discovery service node.

type RelayConfig

type RelayConfig struct {
	NetConfig NetConfig `mapstructure:"net"` // net config
}

RelayConfig .

func LoadRelayCfg

func LoadRelayCfg(configPath string) (*RelayConfig, error)

LoadRelayCfg load relay config file

type RelayService

type RelayService struct {
	// contains filtered or unexported fields
}

RelayService relay service, provide relay function

func NewRelayService

func NewRelayService(cfg *RelayConfig) (*RelayService, error)

NewRelayService create a relay service instance

func (*RelayService) Start

func (rs *RelayService) Start() error

Start RelayService start

func (*RelayService) Stop

func (rs *RelayService) Stop() error

Stop RelayService stop

Jump to

Keyboard shortcuts

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