utp

package module
v0.0.0-...-b6b3a0d Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrReceiveBufferOverflow = fmt.Errorf("receive buffer overflow")

Functions

func Dial

func Dial(network, address string) (net.Conn, error)

Dial attempts to make an outgoing µTP connection to the given address. It is analogous to net.Dial.

func DialContext

func DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext attempts to make an outgoing µTP connection to the given address.

func DialOptions

func DialOptions(network, address string, options ...ConnectOption) (net.Conn, error)

DialOptions attempts to make an outgoing µTP connection to the given address with the given options.

func DialTLS

func DialTLS(network, addr string, config *tls.Config) (*tls.Conn, error)

DialTLS connects to the given network address using net.Dial or utp.Dial as appropriate and then initiates a TLS handshake, returning the resulting TLS connection. DialTLS interprets a nil configuration as equivalent to the zero configuration; see the documentation of tls.Config for the details.

func DialTLSOptions

func DialTLSOptions(network, addr string, config *tls.Config, options ...ConnectOption) (*tls.Conn, error)

DialTLSOptions connects to the given network address using net.Dial or utp.Dial as appropriate and then initiates a TLS handshake, returning the resulting TLS connection. DialTLS interprets a nil configuration as equivalent to the zero configuration; see the documentation of tls.Config for the details.

func DialUTP

func DialUTP(network string, localAddr, remoteAddr *Addr) (net.Conn, error)

DialUTP attempts to make an outgoing µTP connection with the given local and remote address endpoints. It is analogous to net.DialUDP.

func DialUTPOptions

func DialUTPOptions(network string, localAddr, remoteAddr *Addr, options ...ConnectOption) (net.Conn, error)

DialUTPOptions attempts to make an outgoing µTP connection with the given local and remote address endpoints and the given options.

func Listen

func Listen(network string, addr string) (net.Listener, error)

Listen creates a listening µTP socket on the local network address. It is analogous to net.Listen.

func ListenOptions

func ListenOptions(network, addr string, options ...ConnectOption) (net.Listener, error)

ListenOptions creates a listening µTP socket on the local network address with the given options.

func ListenTLS

func ListenTLS(network, laddr string, config *tls.Config) (net.Listener, error)

ListenTLS creates a TLS listener accepting connections on the given network address using net.Listen or utp.Listen as appropriate. The configuration config must be non-nil and must include at least one certificate or else set GetCertificate.

func ListenTLSOptions

func ListenTLSOptions(network, laddr string, config *tls.Config, options ...ConnectOption) (net.Listener, error)

ListenTLSOptions creates a TLS listener accepting connections on the given network address using net.Listen or utp.Listen as appropriate. The configuration config must be non-nil and must include at least one certificate or else set GetCertificate.

func NewConnIdGenerator

func NewConnIdGenerator() libutp.ConnIdGenerator

Types

type Addr

type Addr net.UDPAddr

Addr represents a µTP address.

func ResolveUTPAddr

func ResolveUTPAddr(network, address string) (*Addr, error)

ResolveUTPAddr resolves a µTP address. It is analogous to net.ResolveUDPAddr.

func (*Addr) Network

func (a *Addr) Network() string

Network returns the network of the address ("utp").

func (*Addr) String

func (a *Addr) String() string

String returns the address formatted as a string.

type Conn

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

Conn represents a µTP connection.

func (*Conn) Close

func (c *Conn) Close() error

Close closes a connection.

func (*Conn) LocalAddr

func (u *Conn) LocalAddr() net.Addr

func (*Conn) Read

func (c *Conn) Read(buf []byte) (n int, err error)

Read reads from a Conn.

func (*Conn) ReadContext

func (c *Conn) ReadContext(ctx context.Context, buf []byte) (n int, err error)

ReadContext reads from a Conn.

func (*Conn) RemoteAddr

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

RemoteAddr returns the address of the connection peer.

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

SetDeadline sets a deadline for future read and write operations.

func (*Conn) SetLogger

func (c *Conn) SetLogger(logger *zap.Logger)

SetLogger sets the logger to be used by a connection. The logger will receive debugging information about the socket.

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline sets a read deadline for future read operations.

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets a write deadline for future write operations.

func (*Conn) Write

func (c *Conn) Write(buf []byte) (n int, err error)

Write writes to a Conn.

func (*Conn) WriteContext

func (c *Conn) WriteContext(ctx context.Context, buf []byte) (n int, err error)

WriteContext writes to a Conn.

type ConnectOption

type ConnectOption func(state *utpDialState)

ConnectOption is the interface which connection options should implement.

func WithBufferSize

func WithBufferSize(readSize int, writeSize int) ConnectOption

WithBufferSize Will set the write buffer size and read buffer size for connection

func WithConnId

func WithConnId(connId uint32) ConnectOption

WithConnId Connect or Accept with certain connection id.If not specified, a random connection id will be generated.

func WithContext

func WithContext(ctx context.Context) ConnectOption

WithContext creates a connection option which specifies a context to be attached to the connection. If the context is closed, the dial operation will be canceled.

func WithLogger

func WithLogger(logger *zap.Logger) ConnectOption

WithLogger creates a connection option which specifies a logger to be attached to the connection. The logger will receive debugging messages about the socket.

func WithMaxPacketSize

func WithMaxPacketSize(size int) ConnectOption

WithMaxPacketSize Will set the maximum packet size for the connection which will send out size of packet.

func WithPacketRouter

func WithPacketRouter(pr *PacketRouter) ConnectOption

func WithSocketManager

func WithSocketManager(sm *SocketManager) ConnectOption

WithSocketManager can share SocketManager with other conn

func WithTLS

func WithTLS(tlsConfig *tls.Config) ConnectOption

WithTLS creates a connection option which specifies a TLS configuration structure to be attached to the connection. If specified, a TLS layer will be established on the connection before Dial returns.

type Listener

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

Listener represents a listening µTP socket.

func ListenUTP

func ListenUTP(network string, localAddr *Addr) (*Listener, error)

ListenUTP creates a listening µTP socket on the local network address. It is analogous to net.ListenUDP.

func ListenUTPOptions

func ListenUTPOptions(network string, localAddr *Addr, options ...ConnectOption) (*Listener, error)

ListenUTPOptions creates a listening µTP socket on the given local network address and with the given options.

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Accept accepts a new µTP connection on a listening socket.

func (*Listener) AcceptContext

func (l *Listener) AcceptContext(ctx context.Context) (net.Conn, error)

AcceptContext accepts a new µTP connection on a listening socket.

func (*Listener) AcceptUTP

func (l *Listener) AcceptUTP() (*Conn, error)

AcceptUTP accepts a new µTP connection on a listening socket.

func (*Listener) AcceptUTPContext

func (l *Listener) AcceptUTPContext(ctx context.Context, connIdSeed uint32) (*Conn, error)

AcceptUTPContext accepts a new µTP connection on a listening socket.

func (*Listener) AcceptUTPWithConnId

func (l *Listener) AcceptUTPWithConnId(connId uint32) (*Conn, error)

AcceptUTPWithConnId accepts a new µTP connection with special connection id on a listening socket.

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns the local address of a Listener.

func (*Listener) Close

func (l *Listener) Close() error

Close closes a Listener.

func (*Listener) LocalAddr

func (u *Listener) LocalAddr() net.Addr

type MessageWriter

type MessageWriter func(buf []byte, addr *net.UDPAddr) (int, error)

type PacketRouter

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

func NewPacketRouter

func NewPacketRouter(mw MessageWriter) *PacketRouter

func (*PacketRouter) ReceiveMessage

func (pr *PacketRouter) ReceiveMessage(buf []byte, addr *net.UDPAddr)

func (*PacketRouter) WriteMsg

func (pr *PacketRouter) WriteMsg(buf []byte, addr *net.UDPAddr) (int, error)

type SocketManager

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

func NewSocketManagerWithOptions

func NewSocketManagerWithOptions(network string, localAddr *net.UDPAddr, options ...ConnectOption) (*SocketManager, error)

func (*SocketManager) LocalAddr

func (sm *SocketManager) LocalAddr() net.Addr

func (*SocketManager) RemoteAddr

func (sm *SocketManager) RemoteAddr() net.Addr

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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