tcp

package
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: 19 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	ErrNilTlsCfg                   = errors.New("nil tls config")
	ErrEmptyTlsCerts               = errors.New("empty tls certs")
	ErrNilAddr                     = errors.New("nil addr")
	ErrEmptyListenAddress          = errors.New("empty listen address")
	ErrListenerRequired            = errors.New("at least one listener is required")
	ErrNotTheSameNetwork           = errors.New("not the same network")
	ErrPidMismatch                 = errors.New("pid mismatch")
	ErrNilPIDLoader                = errors.New("pid loader required")
	ErrWrongTcpAddr                = errors.New("wrong tcp address format")
	ErrCanNotDialToUnspecifiedAddr = errors.New("can not dial to unspecified address")
	ErrCanNotDialToLoopbackAddr    = errors.New("can not dial to loopback address")
	ErrNoUsableLocalAddress        = errors.New("no usable local address found")
	ErrLocalPidNotSet              = errors.New("local peer id not set")
	ErrAllDialFailed               = errors.New("all dial failed")

	// ErrConnClosed will be returned if the current connection closed.
	ErrConnClosed = errors.New("connection closed")
	// ErrUnknownDirection will be returned if the direction is unknown.
	ErrUnknownDirection = errors.New("unknown direction")
	// ErrNextProtoMismatch will be returned if next proto mismatch when tls handshaking.
	ErrNextProtoMismatch = errors.New("next proto mismatch")
)

Functions

func CanListen

func CanListen(addr ma.Multiaddr) bool

CanListen return whether address can be listened on.

Types

type Conn

type Conn struct {
	network.BasicStatus
	// contains filtered or unexported fields
}

func NewConn

func NewConn(ctx context.Context, nw *Network, c manet.Conn,
	dir network.Direction) (*Conn, error)

func (*Conn) AcceptReceiveStream

func (c *Conn) AcceptReceiveStream() (network.ReceiveStream, error)

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() ma.Multiaddr

func (*Conn) LocalNetAddr

func (c *Conn) LocalNetAddr() net.Addr

func (*Conn) LocalPeerID

func (c *Conn) LocalPeerID() peer.ID

func (*Conn) Network

func (c *Conn) Network() network.Network

func (*Conn) OpenSendStream

func (c *Conn) OpenSendStream() (network.SendStream, error)

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() ma.Multiaddr

func (*Conn) RemoteNetAddr

func (c *Conn) RemoteNetAddr() net.Addr

func (*Conn) RemotePeerID

func (c *Conn) RemotePeerID() peer.ID

type Network

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

func NewNetwork

func NewNetwork(opt ...Option) (*Network, error)

func (*Network) AcceptedConnChan

func (n *Network) AcceptedConnChan() <-chan network.Connection

AcceptedConnChan returns a channel for notifying about new connections.

func (*Network) Close

func (n *Network) Close() error

func (*Network) Closed

func (n *Network) Closed() bool

func (*Network) Dial

func (n *Network) Dial(ctx context.Context, remoteAddr ma.Multiaddr) (network.Connection, error)

func (*Network) Disconnect

func (n *Network) Disconnect(conn network.Connection) error

Disconnect a connection.

func (*Network) Listen

func (n *Network) Listen(ctx context.Context, addresses ...ma.Multiaddr) error

Listen will run a task that starts creating a listener with the given address and waits for incoming connections to be accepted.

func (*Network) ListenAddresses

func (n *Network) ListenAddresses() []ma.Multiaddr

ListenAddresses return the list of the local addresses for listeners.

func (*Network) LocalPeerID

func (n *Network) LocalPeerID() peer.ID

func (*Network) Logger

func (n *Network) Logger() *rainbowlog.Logger

type Option

type Option func(n *Network) error

Option represents a configuration option for the Network instance.

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets the context for the Network instance.

func WithLocalPID

func WithLocalPID(localPID peer.ID) Option

WithLocalPID sets the local peer ID for the Network instance.

func WithLogger

func WithLogger(logger *rainbowlog.Logger) Option

WithLogger sets the logger for the Network instance.

func WithNoTLS

func WithNoTLS() Option

WithNoTLS disables TLS for the Network instance.

func WithPIDLoader

func WithPIDLoader(pidLoader peer.IDLoader) Option

WithPIDLoader sets the peer ID loader for the Network instance.

func WithTLSConfig

func WithTLSConfig(tlsCfg *tls.Config) Option

WithTLSConfig sets the TLS configuration for the Network instance.

Jump to

Keyboard shortcuts

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