udpsession

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: GPL-3.0, MIT Imports: 25 Imported by: 0

Documentation

Overview

Package udpsession is imported from https://github.com/xtaci/kcp-go

Index

Constants

This section is empty.

Variables

View Source
var (
	// Number of KCP packet input errors.
	KCPInErrors = metrics.RegisterMetric("errors", "KCPInErrors")

	// Number of KCP packet receive errors.
	KCPReceiveErrors = metrics.RegisterMetric("errors", "KCPReceiveErrors")

	// Number of KCP packet send errors.
	KCPSendErrors = metrics.RegisterMetric("errors", "KCPSendErrors")

	// Number of UDP read errors.
	UDPInErrors = metrics.RegisterMetric("errors", "UDPInErrors")
)

Functions

func DialWithOptionsReturnConn

func DialWithOptionsReturnConn(ctx context.Context, network, laddr, raddr string, block cipher.BlockCipher) (net.Conn, error)

DialWithOptionsReturnConn calls DialWithOptions and returns a generic net.Conn.

func SetGlobalMTU added in v1.5.0

func SetGlobalMTU(mtu int32)

SetGlobalMTU adjust the L2 MTU of all UDP sessions. It does nothing if the MTU value is out of range.

Types

type Listener

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

Listener defines a server which will be waiting to accept incoming UDP connections.

func ListenWithOptions

func ListenWithOptions(laddr string, users map[string]*appctlpb.User) (*Listener, error)

ListenWithOptions listens for incoming KCP packets addressed to the local address laddr on the network "udp" with packet encryption.

func (*Listener) Accept

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

Accept implements the Accept() method in the net.Listener interface.

func (*Listener) Addr

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

Addr returns the listener's network address.

func (*Listener) Close

func (l *Listener) Close() error

Close stops listening on the UDP address, and closes the socket.

func (*Listener) SetDSCP

func (l *Listener) SetDSCP(dscp int) error

SetDSCP sets the 6bit DSCP field in IPv4 header, or 8bit Traffic Class in IPv6 header.

func (*Listener) SetDeadline

func (l *Listener) SetDeadline(t time.Time) error

SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline.

func (*Listener) SetReadDeadline

func (l *Listener) SetReadDeadline(t time.Time) error

SetReadDeadline implements the Conn SetReadDeadline method.

func (*Listener) SetWriteDeadline

func (l *Listener) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the Conn SetWriteDeadline method. This method is not supported.

type UDPSession

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

UDPSession defines a KCP session implemented by UDP.

func DialWithOptions

func DialWithOptions(ctx context.Context, network, laddr, raddr string, block cipher.BlockCipher) (*UDPSession, error)

DialWithOptions connects to the remote address "raddr" on the network "udp" with packet encryption. If "laddr" is empty, an automatic address is used. "block" is the block encryption algorithm to encrypt packets.

func (*UDPSession) Close

func (s *UDPSession) Close() error

Close closes the connection.

To avoid deadlock, caller should never hold s.mu lock before calling this method.

func (*UDPSession) GetConv

func (s *UDPSession) GetConv() uint32

GetConv gets conversation id of a session

func (*UDPSession) IsClient

func (s *UDPSession) IsClient() bool

If this UDP session is owned by client.

func (*UDPSession) IsServer

func (s *UDPSession) IsServer() bool

If this UDP session is owned by proxy server.

func (*UDPSession) LocalAddr

func (s *UDPSession) LocalAddr() net.Addr

LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it.

func (*UDPSession) Read

func (s *UDPSession) Read(b []byte) (n int, err error)

Read implements net.Conn

func (*UDPSession) RemoteAddr

func (s *UDPSession) RemoteAddr() net.Addr

RemoteAddr returns the remote network address. The Addr returned is shared by all invocations of RemoteAddr, so do not modify it.

func (*UDPSession) SetACKNoDelay

func (s *UDPSession) SetACKNoDelay(nodelay bool)

SetACKNoDelay changes ack flush option, set true to flush ack immediately.

func (*UDPSession) SetDSCP

func (s *UDPSession) SetDSCP(dscp int) error

SetDSCP sets the 6bit DSCP field in IPv4 header, or 8bit Traffic Class in IPv6 header.

It has no effect if it's accepted from Listener.

func (*UDPSession) SetDeadline

func (s *UDPSession) SetDeadline(t time.Time) error

SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline.

func (*UDPSession) SetMtu

func (s *UDPSession) SetMtu(mtu int) bool

SetMtu sets the maximum transmission unit (not including UDP header).

func (*UDPSession) SetPollIntervalMs added in v1.12.0

func (s *UDPSession) SetPollIntervalMs(interval uint32)

SetPollIntervalMs set KCP polling interval in milliseconds.

func (*UDPSession) SetReadDeadline

func (s *UDPSession) SetReadDeadline(t time.Time) error

SetReadDeadline implements the Conn SetReadDeadline method.

func (*UDPSession) SetStreamMode

func (s *UDPSession) SetStreamMode(enable bool)

SetStreamMode toggles the stream mode on/off.

func (*UDPSession) SetWriteDeadline

func (s *UDPSession) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the Conn SetWriteDeadline method.

func (*UDPSession) SetWriteDelay

func (s *UDPSession) SetWriteDelay(delay bool)

SetWriteDelay delays write for bulk transfer until the next update interval.

func (*UDPSession) Write

func (s *UDPSession) Write(b []byte) (n int, err error)

Write implements net.Conn

func (*UDPSession) WriteBuffers

func (s *UDPSession) WriteBuffers(v [][]byte) (n int, err error)

WriteBuffers write a vector of byte slices to the underlying connection

Jump to

Keyboard shortcuts

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