Documentation
¶
Index ¶
- Constants
- Variables
- func CanListen(addr ma.Multiaddr) bool
- type Conn
- func (c *Conn) AcceptReceiveStream() (network.ReceiveStream, error)
- func (c *Conn) Close() error
- func (c *Conn) LocalAddr() ma.Multiaddr
- func (c *Conn) LocalNetAddr() net.Addr
- func (c *Conn) LocalPeerID() peer.ID
- func (c *Conn) Network() network.Network
- func (c *Conn) OpenSendStream() (network.SendStream, error)
- func (c *Conn) RemoteAddr() ma.Multiaddr
- func (c *Conn) RemoteNetAddr() net.Addr
- func (c *Conn) RemotePeerID() peer.ID
- type Network
- func (n *Network) AcceptedConnChan() <-chan network.Connection
- func (n *Network) Close() error
- func (n *Network) Closed() bool
- func (n *Network) Dial(ctx context.Context, remoteAddr ma.Multiaddr) (network.Connection, error)
- func (n *Network) Disconnect(conn network.Connection) error
- func (n *Network) Listen(ctx context.Context, addresses ...ma.Multiaddr) error
- func (n *Network) ListenAddresses() []ma.Multiaddr
- func (n *Network) LocalPeerID() peer.ID
- func (n *Network) Logger() *rainbowlog.Logger
- type Option
Constants ¶
const (
// NetworkVersion is the current version of tcp network.
NetworkVersion = "v0.0.1"
)
Variables ¶
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 ¶
Types ¶
type Conn ¶
type Conn struct {
network.BasicStatus
// contains filtered or unexported fields
}
func (*Conn) AcceptReceiveStream ¶
func (c *Conn) AcceptReceiveStream() (network.ReceiveStream, error)
func (*Conn) LocalNetAddr ¶
func (*Conn) LocalPeerID ¶
func (*Conn) OpenSendStream ¶
func (c *Conn) OpenSendStream() (network.SendStream, error)
func (*Conn) RemoteAddr ¶
func (*Conn) RemoteNetAddr ¶
func (*Conn) RemotePeerID ¶
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
func NewNetwork ¶
func (*Network) AcceptedConnChan ¶
func (n *Network) AcceptedConnChan() <-chan network.Connection
AcceptedConnChan returns a channel for notifying about new connections.
func (*Network) Disconnect ¶
func (n *Network) Disconnect(conn network.Connection) error
Disconnect a connection.
func (*Network) Listen ¶
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 ¶
ListenAddresses return the list of the local addresses for listeners.
func (*Network) LocalPeerID ¶
func (*Network) Logger ¶
func (n *Network) Logger() *rainbowlog.Logger
type Option ¶
Option represents a function that configures the Network instance.
func WithContext ¶
WithContext sets the context for the Network instance. The provided context is used for cancellation and timeout control.
func WithDialLoopbackEnable ¶
func WithDialLoopbackEnable() Option
WithDialLoopbackEnable returns an Option that enables loopback dialing for the Network. When this option is applied, the Network will allow dialing to loopback addresses (e.g., 127.0.0.1). This is useful for testing or scenarios where local communication is required.
func WithLocalPID ¶
WithLocalPID sets the local peer ID for the Network instance. The local peer ID identifies this node in the network.
func WithLogger ¶
func WithLogger(logger *rainbowlog.Logger) Option
WithLogger sets the logger for the Network instance. The provided logger is wrapped with a sub-logger for consistent labeling.
func WithNoTLS ¶
func WithNoTLS() Option
WithNoTLS disables TLS for the Network instance. Use this option to enforce plaintext communication.
func WithPIDLoader ¶
WithPIDLoader sets the peer ID loader for the Network instance. The peer ID loader is responsible for resolving peer IDs.
func WithTLSConfig ¶
WithTLSConfig sets the TLS configuration for the Network instance. It also enables TLS for secure communication.