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 TestHelperGenRot13Input(size int) []byte
- func TestHelperRot13(in []byte) ([]byte, error)
- func TestHelperServeConn(conn *UDPSession) error
- type Listener
- func (l *Listener) Accept() (net.Conn, error)
- func (l *Listener) AcceptKCP() (*UDPSession, 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) SetReadBuffer(bytes int) error
- func (l *Listener) SetReadDeadline(t time.Time) error
- func (l *Listener) SetWriteBuffer(bytes int) 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) SetDUP(dup int)
- 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) SetReadBuffer(bytes int) error
- func (s *UDPSession) SetReadDeadline(t time.Time) error
- func (s *UDPSession) SetStreamMode(enable bool)
- func (s *UDPSession) SetWindowSize(sndwnd, rcvwnd int)
- func (s *UDPSession) SetWriteBuffer(bytes int) error
- 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 TestHelperGenRot13Input ¶
TestHelperGenRot13Input generates valid rotate-13 input.
func TestHelperRot13 ¶
TestHelperRot13 returns the rotate-13 of the input.
func TestHelperServeConn ¶
func TestHelperServeConn(conn *UDPSession) error
TestHelperServeConn serves client requests and returns the rotate-13 of the input.
Types ¶
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener defines a server which will be waiting to accept incoming connections.
func ListenWithOptions ¶
ListenWithOptions listens for incoming KCP packets addressed to the local address laddr on the network "udp" with packet encryption.
func (*Listener) Accept ¶
Accept implements the Accept method in the Listener interface; it waits for the next call and returns a generic Conn.
func (*Listener) AcceptKCP ¶
func (l *Listener) AcceptKCP() (*UDPSession, error)
AcceptKCP accepts a KCP connection.
func (*Listener) Addr ¶
Addr returns the listener's network address. The Addr returned is shared by all invocations of Addr, so do not modify it.
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) SetReadBuffer ¶
SetReadBuffer sets the socket read buffer for the Listener
func (*Listener) SetReadDeadline ¶
SetReadDeadline implements the Conn SetReadDeadline method.
func (*Listener) SetWriteBuffer ¶
SetWriteBuffer sets the socket write buffer for the Listener
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) SetDUP ¶
func (s *UDPSession) SetDUP(dup int)
(deprecated)
SetDUP duplicates udp packets for kcp output.
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) SetReadBuffer ¶
func (s *UDPSession) SetReadBuffer(bytes int) error
SetReadBuffer sets the socket read buffer, no effect if it's accepted from Listener
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) SetWriteBuffer ¶
func (s *UDPSession) SetWriteBuffer(bytes int) error
SetWriteBuffer sets the socket write buffer, no effect if it's accepted from Listener
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