Documentation
¶
Index ¶
- Constants
- func NewDecryptReader(r io.Reader, secret []byte) (reader io.Reader, err error)
- func NewEncryptWriter(w io.Writer, secret []byte) (wr io.Writer, err error)
- type Decoder
- type Encoder
- func (e *Encoder) Direction() proto.Direction
- func (e *Encoder) SetCompression(threshold, level int) (err error)
- func (e *Encoder) SetProtocol(protocol proto.Protocol)
- func (e *Encoder) SetState(state *state.Registry)
- func (e *Encoder) SetWriter(w io.Writer)
- func (e *Encoder) Sync(fn func() error) error
- func (e *Encoder) Write(payload []byte) (n int, err error)
- func (e *Encoder) WritePacket(packet proto.Packet) (n int, err error)
- type FrameTooLargeError
- type PacketDecodeError
Constants ¶
const ( VanillaMaximumUncompressedSize = 8 * 1024 * 1024 // 8MiB HardMaximumUncompressedSize = 128 * 1024 * 1024 // 128MiB UncompressedCap = VanillaMaximumUncompressedSize // ServerboundUncompressedCap is the maximum claimed decompressed size for a // serverbound packet. It is tighter than UncompressedCap because serverbound // data comes from the (untrusted) client, limiting how much memory a client // can force the proxy to allocate. Clientbound data keeps UncompressedCap. ServerboundUncompressedCap = 2 * 1024 * 1024 // 2MiB // MaximumFrameLength is the largest packet frame Gate accepts off the wire, // matching vanilla's Varint21FrameDecoder: its length prefix is a VarInt of at // most 21 bits, so a frame can announce up to 2^21-1 bytes. // // This bounds the frame as it arrives, before decompression, so it also caps // compressed frames. The decompressed size is capped separately and higher by // UncompressedCap / ServerboundUncompressedCap. // // Modded backends (Forge/NeoForge) legitimately send config-phase frames well // past 1MiB, e.g. registry sync and mod network queries, so a tighter-than- // vanilla cap here kills those connections. See // https://github.com/minekube/gate/issues/930. MaximumFrameLength = 1<<21 - 1 // 2097151 )
Variables ¶
This section is empty.
Functions ¶
func NewDecryptReader ¶
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder is a synchronized packet decoder for the Minecraft Java edition.
func (*Decoder) Decode ¶
func (d *Decoder) Decode() (ctx *proto.PacketContext, err error)
Decode reads the next packet from the underlying reader. It blocks other calls to Decode until return.
func (*Decoder) SetCompressionThreshold ¶
func (*Decoder) SetProtocol ¶
SetProtocol changes the decoder's protocol version. Safe to call concurrently with Decode.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder is a synchronized packet encoder.
func (*Encoder) SetCompression ¶
func (*Encoder) SetProtocol ¶
func (*Encoder) Sync ¶
Sync locks the encoder while running fn, making sure no write calls are run during this call.
type FrameTooLargeError ¶ added in v0.68.30
type FrameTooLargeError struct {
Length int // the frame length the peer announced
Max int // the maximum length Gate accepts
}
FrameTooLargeError is returned when a peer announces a packet frame longer than MaximumFrameLength. It carries the announced length so callers can decide how loudly to report it: an oversized frame from an untrusted client is noise, while one from a backend server is operator-actionable.
func (*FrameTooLargeError) Error ¶ added in v0.68.30
func (e *FrameTooLargeError) Error() string
type PacketDecodeError ¶ added in v0.74.28
type PacketDecodeError struct {
// Packet is the zero-valued packet instance the decoder tried to fill.
Packet proto.Packet
PacketID proto.PacketID
Protocol proto.Protocol
Direction proto.Direction
// Read and Unread are the payload byte counts the decoder consumed and left
// unread, mirroring the message below.
Read int
Unread int
Err error
}
PacketDecodeError reports that a frame carried a packet this protocol's registry knows, but whose payload could not be decoded into it. Unlike a frame that is not a packet at all, the failing packet is identified here, which is what lets a caller name it (reader.logCloseErr does, for backend connections).
The decoder still returns it wrapped in an errs.SilentError: the default log must stay quiet for untrusted peers, and naming the packet is the caller's decision, not the decoder's. Unwrap keeps the underlying cause (and the io.EOF/io.ErrUnexpectedEOF classification) reachable with errors.Is/errors.As.
func (*PacketDecodeError) Error ¶ added in v0.74.28
func (e *PacketDecodeError) Error() string
func (*PacketDecodeError) Unwrap ¶ added in v0.74.28
func (e *PacketDecodeError) Unwrap() error