Documentation
¶
Overview ¶
Package session is imported from https://github.com/xtaci/kcp-go
It is a Reliable-UDP library for golang.
This library intents to provide a smooth, resilient, ordered, error-checked and anonymous delivery of streams over UDP packets.
The interfaces of this package aims to be compatible with net.Conn in standard library, but offers powerful features for advanced users.
Index ¶
- func DialWithOptionsReturnConn(ctx context.Context, network, laddr, raddr string, block cipher.BlockCipher) (net.Conn, error)
- func SetGlobalMTU(mtu int32)
- type Listener
- func (l *Listener) Accept() (net.Conn, error)
- func (l *Listener) Addr() net.Addr
- func (l *Listener) Close() error
- func (l *Listener) SetDSCP(dscp int) error
- func (l *Listener) SetDeadline(t time.Time) error
- func (l *Listener) SetReadDeadline(t time.Time) error
- func (l *Listener) SetWriteDeadline(t time.Time) error
- type UDPSession
- func (s *UDPSession) Close() error
- func (s *UDPSession) GetConv() uint32
- func (s *UDPSession) GetRTO() uint32
- func (s *UDPSession) GetSRTT() int32
- func (s *UDPSession) GetSRTTVar() int32
- func (s *UDPSession) IsClient() bool
- func (s *UDPSession) IsServer() bool
- func (s *UDPSession) LocalAddr() net.Addr
- func (s *UDPSession) Read(b []byte) (n int, err error)
- func (s *UDPSession) RemoteAddr() net.Addr
- func (s *UDPSession) SetACKNoDelay(nodelay bool)
- func (s *UDPSession) SetDSCP(dscp int) error
- func (s *UDPSession) SetDeadline(t time.Time) error
- func (s *UDPSession) SetMtu(mtu int) bool
- func (s *UDPSession) SetNoDelay(nodelay, interval, resend uint32, nc bool)
- func (s *UDPSession) SetReadDeadline(t time.Time) error
- func (s *UDPSession) SetStreamMode(enable bool)
- func (s *UDPSession) SetWindowSize(sndwnd, rcvwnd int)
- func (s *UDPSession) SetWriteDeadline(t time.Time) error
- func (s *UDPSession) SetWriteDelay(delay bool)
- func (s *UDPSession) Write(b []byte) (n int, err error)
- func (s *UDPSession) WriteBuffers(v [][]byte) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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 ¶
ListenWithOptions listens for incoming KCP packets addressed to the local address laddr on the network "udp" with packet encryption.
func (*Listener) SetDSCP ¶
SetDSCP sets the 6bit DSCP field in IPv4 header, or 8bit Traffic Class in IPv6 header.
func (*Listener) SetDeadline ¶
SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline.
func (*Listener) SetReadDeadline ¶
SetReadDeadline implements the Conn SetReadDeadline method.
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) GetRTO ¶
func (s *UDPSession) GetRTO() uint32
GetRTO gets current rto of the session
func (*UDPSession) GetSRTT ¶
func (s *UDPSession) GetSRTT() int32
GetSRTT gets current srtt of the session
func (*UDPSession) GetSRTTVar ¶
func (s *UDPSession) GetSRTTVar() int32
GetRTTVar gets current rtt variance of the 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) SetNoDelay ¶
func (s *UDPSession) SetNoDelay(nodelay, interval, resend uint32, nc bool)
SetNoDelay calls KCP NoDelay().
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) SetWindowSize ¶
func (s *UDPSession) SetWindowSize(sndwnd, rcvwnd int)
SetWindowSize set maximum window size.
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