Documentation ¶
Index ¶
- Constants
- Variables
- func DumpLengthEncodedInt(buffer []byte, n uint64) []byte
- func DumpLengthEncodedString(buffer []byte, bytes []byte) []byte
- func DumpUint16(buffer []byte, n uint16) []byte
- func DumpUint32(buffer []byte, n uint32) []byte
- func IsDisconnectError(err error) bool
- func IsEOFPacket(data []byte) bool
- func IsErrorPacket(data []byte) bool
- func IsOKPacket(data []byte) bool
- func IsResultSetOKPacket(data []byte) bool
- func MakeChangeUser(username, db, authPlugin string, authData []byte) []byte
- func MakeHandshakeResponse(resp *HandshakeResp) []byte
- func ParseChangeUser(data []byte) (username, db string)
- func ParseErrorPacket(data []byte) error
- func ParseLengthEncodedBytes(b []byte) ([]byte, bool, int, error)
- func ParseLengthEncodedInt(b []byte) (num uint64, isNull bool, n int)
- func ParseNullTermString(b []byte) (str []byte, remain []byte)
- func ParseOKPacket(data []byte) *gomysql.Result
- func ReadServerVersion(conn net.Conn) (string, error)
- func WithProxy(pi *PacketIO)
- func WithRemoteAddr(readdr string, addr net.Addr) func(pi *PacketIO)
- func WithWrapError(err error) func(pi *PacketIO)
- func WriteServerVersion(conn net.Conn, serverVersion string) error
- type Capability
- type Command
- type HandshakeResp
- type PacketIO
- func (p *PacketIO) ApplyOpts(opts ...PacketIOption)
- func (p *PacketIO) ClientTLSHandshake(tlsConfig *tls.Config) error
- func (p *PacketIO) Close() error
- func (p *PacketIO) Flush() error
- func (p *PacketIO) GetSequence() uint8
- func (p *PacketIO) GracefulClose() error
- func (p *PacketIO) InBytes() uint64
- func (p *PacketIO) IsPeerActive() bool
- func (p *PacketIO) LastKeepAlive() config.KeepAlive
- func (p *PacketIO) LocalAddr() net.Addr
- func (p *PacketIO) OutBytes() uint64
- func (p *PacketIO) Proxy() *proxyprotocol.Proxy
- func (p *PacketIO) ReadPacket() (data []byte, err error)
- func (p *PacketIO) ReadSSLRequestOrHandshakeResp() (pkt []byte, isSSL bool, err error)
- func (p *PacketIO) RemoteAddr() net.Addr
- func (p *PacketIO) ResetSequence()
- func (p *PacketIO) ServerTLSHandshake(tlsConfig *tls.Config) (tls.ConnectionState, error)
- func (p *PacketIO) SetKeepalive(cfg config.KeepAlive) error
- func (p *PacketIO) TLSConnectionState() tls.ConnectionState
- func (p *PacketIO) WriteEOFPacket(status uint16) error
- func (p *PacketIO) WriteErrPacket(merr *mysql.SQLError) error
- func (p *PacketIO) WriteInitialHandshake(capability Capability, salt []byte, authPlugin string, serverVersion string) error
- func (p *PacketIO) WriteOKPacket(status uint16, header byte) error
- func (p *PacketIO) WritePacket(data []byte, flush bool) (err error)
- func (p *PacketIO) WriteProxyV2(m *proxyprotocol.Proxy) error
- func (p *PacketIO) WriteShaCommand() error
- func (p *PacketIO) WriteSwitchRequest(authPlugin string, salt []byte) error
- func (p *PacketIO) WriteUserError(err error)
- type PacketIOption
- type UserError
Constants ¶
const ( ShaCommand = 1 FastAuthFail = 4 )
const (
// MaxPayloadLen is the max packet payload length.
MaxPayloadLen = 1<<24 - 1
)
Variables ¶
var ( ErrExpectSSLRequest = errors.New("expect a SSLRequest packet") ErrReadConn = errors.New("failed to read the connection") ErrWriteConn = errors.New("failed to write the connection") ErrFlushConn = errors.New("failed to flush the connection") ErrCloseConn = errors.New("failed to close the connection") ErrHandshakeTLS = errors.New("failed to complete tls handshake") )
var ( ServerVersion = mysql.ServerVersion Collation = uint8(mysql.DefaultCollationID) ConnID = 100 Status = mysql.ServerStatusAutocommit )
var (
ErrSaltNotLongEnough = errors.New("salt is not long enough")
)
Functions ¶
func DumpLengthEncodedInt ¶
func DumpLengthEncodedString ¶
DumpLengthEncodedString dumps string<int>.
func DumpUint16 ¶
func DumpUint32 ¶
func IsDisconnectError ¶
IsDisconnectError returns whether the error is caused by peer disconnection.
func IsEOFPacket ¶
IsEOFPacket returns true if it's an EOF packet.
func IsErrorPacket ¶
IsErrorPacket returns true if it's an error packet.
func IsOKPacket ¶
IsOKPacket returns true if it's an OK packet (but not ResultSet OK).
func IsResultSetOKPacket ¶
IsResultSetOKPacket returns true if it's an OK packet after the result set when CLIENT_DEPRECATE_EOF is enabled. A row packet may also begin with 0xfe, so we need to judge it with the packet length. See https://mariadb.com/kb/en/result-set-packets/
func MakeChangeUser ¶
MakeChangeUser creates the data of COM_CHANGE_USER. It's only used for testing.
func MakeHandshakeResponse ¶
func MakeHandshakeResponse(resp *HandshakeResp) []byte
func ParseChangeUser ¶
ParseChangeUser parses the data of COM_CHANGE_USER.
func ParseErrorPacket ¶
ParseErrorPacket transforms an error packet into a MyError object.
func ParseNullTermString ¶
func ParseOKPacket ¶
ParseOKPacket transforms an OK packet into a Result object.
func ReadServerVersion ¶
ReadServerVersion only reads server version.
func WithWrapError ¶
Types ¶
type Capability ¶
type Capability uint32
const ( ClientLongPassword Capability = 1 << iota ClientFoundRows ClientLongFlag ClientConnectWithDB ClientNoSchema ClientCompress ClientODBC ClientLocalFiles ClientIgnoreSpace ClientProtocol41 ClientInteractive ClientSSL ClientIgnoreSigpipe ClientTransactions ClientReserved ClientSecureConnection ClientMultiStatements ClientMultiResults ClientPSMultiResults ClientPluginAuth ClientConnectAttrs ClientPluginAuthLenencClientData ClientCanHandleExpiredPasswords ClientSessionTrack ClientDeprecateEOF ClientOptionalResultsetMetadata ClientZstdCompressionAlgorithm ClientQueryAttributes MultiFactorAuthentication ClientCapabilityExtension ClientSSLVerifyServerCert ClientRememberOptions )
Capability flags. Ref https://dev.mysql.com/doc/dev/mysql-server/latest/group__group__cs__capabilities__flags.html.
func ParseInitialHandshake ¶
func ParseInitialHandshake(data []byte) (Capability, string)
ParseInitialHandshake parses the initial handshake received from the server.
func (*Capability) MarshalText ¶
func (f *Capability) MarshalText() ([]byte, error)
func (Capability) String ¶
func (f Capability) String() string
func (Capability) Uint32 ¶
func (f Capability) Uint32() uint32
func (*Capability) UnmarshalText ¶
func (f *Capability) UnmarshalText(o []byte) error
type Command ¶
type Command byte
const ( ComSleep Command = iota ComQuit ComInitDB ComQuery ComFieldList ComCreateDB ComDropDB ComRefresh ComDeprecated1 ComStatistics ComProcessInfo ComConnect ComProcessKill ComDebug ComPing ComTime ComDelayedInsert ComChangeUser ComBinlogDump ComTableDump ComConnectOut ComRegisterSlave ComStmtPrepare ComStmtExecute ComStmtSendLongData ComStmtClose ComStmtReset ComSetOption ComStmtFetch ComDaemon ComBinlogDumpGtid ComResetConnection ComEnd // Not a real command )
Command information. Ref https://dev.mysql.com/doc/dev/mysql-server/latest/my__command_8h.html#ae2ff1badf13d2b8099af8b47831281e1.
func (*Command) MarshalText ¶
func (*Command) UnmarshalText ¶
type HandshakeResp ¶
type HandshakeResp struct { Attrs map[string]string User string DB string AuthPlugin string AuthData []byte Capability uint32 Collation uint8 }
HandshakeResp indicates the response read from the client.
func ParseHandshakeResponse ¶
func ParseHandshakeResponse(data []byte) (*HandshakeResp, error)
type PacketIO ¶
type PacketIO struct {
// contains filtered or unexported fields
}
PacketIO is a helper to read and write sql and proxy protocol.
func NewPacketIO ¶
func (*PacketIO) ApplyOpts ¶
func (p *PacketIO) ApplyOpts(opts ...PacketIOption)
func (*PacketIO) ClientTLSHandshake ¶
func (*PacketIO) GetSequence ¶
GetSequence is used in tests to assert that the sequences on the client and server are equal.
func (*PacketIO) GracefulClose ¶
func (*PacketIO) IsPeerActive ¶
IsPeerActive checks if the peer connection is still active. This function cannot be called concurrently with other functions of PacketIO. This function normally costs 1ms, so don't call it too frequently. This function may incorrectly return true if the system is extremely slow.
func (*PacketIO) LastKeepAlive ¶
LastKeepAlive is used for test.
func (*PacketIO) Proxy ¶
func (p *PacketIO) Proxy() *proxyprotocol.Proxy
Proxy returned parsed proxy header from clients if any.
func (*PacketIO) ReadPacket ¶
ReadPacket reads data and removes the header
func (*PacketIO) ReadSSLRequestOrHandshakeResp ¶
func (*PacketIO) RemoteAddr ¶
func (*PacketIO) ResetSequence ¶
func (p *PacketIO) ResetSequence()
func (*PacketIO) ServerTLSHandshake ¶
func (*PacketIO) TLSConnectionState ¶
func (p *PacketIO) TLSConnectionState() tls.ConnectionState
func (*PacketIO) WriteEOFPacket ¶
WriteEOFPacket writes an EOF packet. It's only for testing.
func (*PacketIO) WriteErrPacket ¶
WriteErrPacket writes an Error packet.
func (*PacketIO) WriteInitialHandshake ¶
func (p *PacketIO) WriteInitialHandshake(capability Capability, salt []byte, authPlugin string, serverVersion string) error
WriteInitialHandshake writes an initial handshake as a server. It's used for tenant-aware routing and testing.
func (*PacketIO) WriteOKPacket ¶
WriteOKPacket writes an OK packet. It's only for testing.
func (*PacketIO) WritePacket ¶
WritePacket writes data without a header
func (*PacketIO) WriteProxyV2 ¶
func (p *PacketIO) WriteProxyV2(m *proxyprotocol.Proxy) error
WriteProxyV2 should only be called at the beginning of connection, before any write operations.
func (*PacketIO) WriteShaCommand ¶
func (*PacketIO) WriteSwitchRequest ¶
WriteSwitchRequest writes a switch request to the client. It's only for testing.
func (*PacketIO) WriteUserError ¶ added in v0.1.1
WriteUserError writes an unknown error to the client.
type PacketIOption ¶
type PacketIOption = func(*PacketIO)
type UserError ¶ added in v0.1.1
type UserError struct {
// contains filtered or unexported fields
}
UserError is returned to the client. err is used to log and userMsg is used to report to the user.