Documentation
¶
Overview ¶
Package wsproto implements the RFC 6455 WebSocket wire format shared by the netplay transports and pkg/online/wsclient: frame reading and writing with slow-loris-safe allocation, the opening handshake's accept key, and the native client upgrade. It is internal to pkg/online; games use netplay or wsclient.
Index ¶
- Constants
- Variables
- func AcceptKey(key string) string
- func ClientUpgrade(w io.Writer, br *bufio.Reader, u *url.URL, header http.Header, ...) (string, error)
- func HostPort(u *url.URL) (string, error)
- func ReadFrame(r *bufio.Reader) (fin bool, opcode byte, payload []byte, masked bool, err error)
- func ReadFrameLimit(r *bufio.Reader, limit uint64) (fin bool, opcode byte, payload []byte, masked bool, err error)
- func WriteFrame(w io.Writer, opcode byte, masked bool, payload []byte) error
- func WriteFrameLimit(w io.Writer, opcode byte, masked bool, payload []byte, limit uint64) error
Constants ¶
const ( OpContinuation = 0x0 OpText = 0x1 OpBinary = 0x2 OpClose = 0x8 OpPing = 0x9 OpPong = 0xA // MaxControlPayload bounds a control frame's payload (RFC 6455 §5.5). MaxControlPayload = 125 // MaxMessageSize is the largest frame payload ReadFrame reads and WriteFrame writes. MaxMessageSize = 4 << 20 // 4 MiB safety cap // EagerAlloc is the largest payload ReadFrameLimit allocates before its bytes arrive. A larger payload grows with the bytes actually received, so a peer that announces a 4 MiB frame and then trickles it (a slow-loris attack) holds memory only for what it has sent (#546). EagerAlloc = 64 << 10 )
Variables ¶
var ( // ErrPayloadTooLarge is returned when a frame's payload exceeds the reader's limit or MaxMessageSize on write. ErrPayloadTooLarge = errors.New("net: payload too large") // ErrInvalidPacket is returned when a frame breaks RFC 6455: a fragmented or oversized control frame, or a reserved control opcode. ErrInvalidPacket = errors.New("net: invalid packet") )
Functions ¶
func AcceptKey ¶
AcceptKey derives the Sec-WebSocket-Accept response value for a client's Sec-WebSocket-Key (RFC 6455 §4.2.2).
func ClientUpgrade ¶
func ClientUpgrade(w io.Writer, br *bufio.Reader, u *url.URL, header http.Header, protocols []string) (string, error)
ClientUpgrade writes the RFC 6455 opening handshake for u to w and validates the server's response read from br, returning the subprotocol the server selected, or "" for none. header carries extra request headers, such as Authorization; entries naming a header the handshake writes itself are skipped. A server that answers a subprotocol the client did not offer is a protocol error.
func HostPort ¶
HostPort joins the URL's host and port, defaulting by scheme and keeping IPv6 literals bracketed; checking for a colon cannot tell a port from an IPv6 address (#546).
func ReadFrameLimit ¶
func ReadFrameLimit(r *bufio.Reader, limit uint64) (fin bool, opcode byte, payload []byte, masked bool, err error)
ReadFrameLimit reads one frame whose payload is at most limit bytes.
func WriteFrame ¶
WriteFrame writes one unfragmented frame of at most MaxMessageSize payload bytes.
Types ¶
This section is empty.