MCPcopy Create free account
hub / github.com/Invisv-Privacy/masque / datagramChunkToStreamData

Method datagramChunkToStreamData

http2/client.go:421–444  ·  view source on GitHub ↗

datagramChunkToStreamData converts an encoded datagram chunk into a UDP raw byte slice. The input parameters are the CONNECT-UDP datagram chunk (chunk) and the payload length (len). It returns the decoded data in a byte slice and its total length.

(chunk []byte, chunkLength int)

Source from the content-addressed store, hash-verified

419// The input parameters are the CONNECT-UDP datagram chunk (chunk) and the payload length (len).
420// It returns the decoded data in a byte slice and its total length.
421func (c *Client) datagramChunkToStreamData(chunk []byte, chunkLength int) ([]byte, int) {
422 if chunkLength < 2 || chunk[0] != 0 {
423 return []byte{}, 0
424 }
425 v := chunk[1]
426 if v&byte(0b11000000) == 0 { // 1-byte length encoding
427 decode := chunk[2:]
428 return decode, chunkLength - 2
429 }
430 if v&byte(0b11000000) == 0x40 { // 2-byte length encoding
431 decode := chunk[3:]
432 return decode, chunkLength - 3
433 }
434 if v&byte(0b11000000) == 0x80 { // 4-byte length encoding
435 decode := chunk[4:]
436 return decode, chunkLength - 4
437 }
438 if v&byte(0b11000000) == 0xc0 { // 8-byte length encoding
439 decode := chunk[9:]
440 return decode, chunkLength - 9
441 }
442 c.logger.Error("Datagram chunk encoding error", "chunk", chunk, "len", chunkLength)
443 return []byte{}, 0
444}
445
446// encodeLoopUDP encodes data and sends it to the proxied UDP stream.
447// |udp.transport| should be the TLS connection's reader from proxy.

Callers 1

decodeLoopUDPMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected