tcp

package
v0.0.0-...-dae542e Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TCPNetworkVersion is the current version of tcp network.
	TCPNetworkVersion = "v0.0.1"
)

Variables

View Source
var (
	// ErrConnClosed will be returned if the current connection closed.
	ErrConnClosed = errors.New("connection closed")
	// ErrUnknownDir will be returned if the direction is unknown.
	ErrUnknownDir = errors.New("unknown direction")
	// ErrNextProtoMismatch will be returned if next proto mismatch when tls handshaking.
	ErrNextProtoMismatch = errors.New("next proto mismatch")
)
View Source
var (
	// ErrNilTlsCfg will be returned if tls config is nil when network starting.
	ErrNilTlsCfg = errors.New("nil tls config")
	// ErrEmptyTlsCerts will be returned if no tls cert given when network starting with tls enabled.
	ErrEmptyTlsCerts = errors.New("empty tls certs")
	// ErrNilAddr will be returned if the listening address is empty.
	ErrNilAddr = errors.New("nil addr")
	// ErrEmptyListenAddress will be returned if no listening address given.
	ErrEmptyListenAddress = errors.New("empty listen address")
	// ErrListenerRequired will be returned if no listener created.
	ErrListenerRequired = errors.New("at least one listener is required")
	// ErrConnRejectedByConnHandler will be returned if connection handler reject a connection when establishing.
	ErrConnRejectedByConnHandler = errors.New("connection rejected by conn handler")
	// ErrNotTheSameNetwork will be returned if the connection disconnected is not created by current network.
	ErrNotTheSameNetwork = errors.New("not the same network")
	// ErrPidMismatch will be returned if the remote peer id is not the expected one.
	ErrPidMismatch = errors.New("pid mismatch")
	// ErrNilLoadPidFunc will be returned if loadPidFunc is nil.
	ErrNilLoadPidFunc = errors.New("load peer id function required")
	// ErrWrongTcpAddr  will be returned if the address is wrong when calling Dial method.
	ErrWrongTcpAddr = errors.New("wrong tcp address format")
	// ErrEmptyLocalPeerId will be returned if load local peer id failed.
	ErrEmptyLocalPeerId = errors.New("empty local peer id")
	// ErrNoUsableLocalAddress will be returned if no usable local address found
	// when the local listening address is an unspecified address.
	ErrNoUsableLocalAddress = errors.New("no usable local address found")
	// ErrLocalPidNotSet will be returned if local peer id not set on insecurity mode.
	ErrLocalPidNotSet = errors.New("local peer id not set")
)

Functions

func CanListen

func CanListen(addr ma.Multiaddr) bool

CanListen return whether address can be listened on.

func NewNetwork

func NewNetwork(ctx context.Context, logger api.Logger, opt ...Option) (*tcpNetwork, error)

NewNetwork create a new network instance with TCP transport.

Types

type Option

type Option func(n *tcpNetwork) error

Option is a function to set option value for tcp network.

func WithEnableTls

func WithEnableTls(enable bool) Option

WithEnableTls set a bool value deciding whether tls enabled.

func WithLoadPidFunc

func WithLoadPidFunc(f types.LoadPeerIdFromCMTlsCertFunc) Option

WithLoadPidFunc set a types.LoadPeerIdFromCMTlsCertFunc for loading peer.ID from cmx509 certs when tls handshaking.

func WithLocalPeerId

func WithLocalPeerId(pid peer.ID) Option

WithLocalPeerId will set the local peer.ID for the network. If LoadPidFunc option set, the local peer.ID set by this method will be overwritten, probably.

func WithTlsCfg

func WithTlsCfg(tlsCfg *cmTls.Config) Option

WithTlsCfg set a cmTls.Config option value. If enable tls is false, cmTls.Config will not usable.

Jump to

Keyboard shortcuts

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