Documentation ¶
Index ¶
- Constants
- Variables
- func CanListen(addr ma.Multiaddr) bool
- func NewNetwork(ctx context.Context, logger api.Logger, opt ...Option) (*tcpNetwork, error)
- type Option
- func WithEnableTls(enable bool) Option
- func WithGMTls(enable bool) Option
- func WithGMTlsClientCfg(gmTlsCfg *gmtls.Config) Option
- func WithGMTlsServerCfg(gmTlsCfg *gmtls.Config) Option
- func WithLoadPidFunc(f types.LoadPeerIdFromTlsCertFunc) Option
- func WithLoadPidFuncGm(f types.LoadPeerIdFromGMTlsCertFunc) Option
- func WithLocalPeerId(pid peer.ID) Option
- func WithTlsCfg(tlsCfg *tls.Config) Option
Constants ¶
const (
// TCPNetworkVersion is the current version of tcp network.
TCPNetworkVersion = "v0.0.1"
)
Variables ¶
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") )
var ( // ErrNilTlsCfg will be returned if tls config is nil when network starting. ErrNilTlsCfg = errors.New("nil tls config") // ErrNilGMTlsServerCfg will be returned if gm tls server config is nil when gm tls enabled. ErrNilGMTlsServerCfg = errors.New("nil gm tls server config") // ErrNilGMTlsClientCfg will be returned if gm tls client config is nil when gm tls enabled. ErrNilGMTlsClientCfg = errors.New("nil gm tls client config") // ErrEmptyTlsCerts will be returned if no tls cert given when network starting with tls enabled. ErrEmptyTlsCerts = errors.New("empty tls certs") // ErrGMTlsCertsForServerLack will be returned if the count of certs for gm tls server configuration less than two. ErrGMTlsCertsForServerLack = errors.New("at last two certs required for gm tls server config") // ErrEmptyGMTlsClientCerts will be returned if no certs for gm tls client configuration. ErrEmptyGMTlsClientCerts = errors.New("empty gm tls certs for client") // 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 a 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 ¶
CanListen return whether address can be listened on.
Types ¶
type Option ¶
type Option func(n *tcpNetwork) error
Option is a function to set option value for tcp network.
func WithEnableTls ¶
WithEnableTls set a bool value deciding whether tls enabled.
func WithGMTls ¶
WithGMTls set a bool value deciding whether gm tls used. If enable is true, enableTLS option also will be set true.
func WithGMTlsClientCfg ¶
WithGMTlsClientCfg set a gmtls.Config option value for gmtls client. If enable tls or use gmtls is false, gmtls.Config will not usable.
func WithGMTlsServerCfg ¶
WithGMTlsServerCfg set a gmtls.Config option value for gmtls server. If enable tls or use gmtls is false, gmtls.Config will not usable.
func WithLoadPidFunc ¶
func WithLoadPidFunc(f types.LoadPeerIdFromTlsCertFunc) Option
WithLoadPidFunc set a types.LoadPeerIdFromTlsCertFunc for loading peer.ID from x509 certs when tls handshaking.
func WithLoadPidFuncGm ¶
func WithLoadPidFuncGm(f types.LoadPeerIdFromGMTlsCertFunc) Option
WithLoadPidFuncGm set a types.LoadPeerIdFromGMTlsCertFunc for loading peer.ID from gmx509 certs when gmtls handshaking.
func WithLocalPeerId ¶
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.