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

Method encodeLoopUDP

http2/client.go:449–486  ·  view source on GitHub ↗

encodeLoopUDP encodes data and sends it to the proxied UDP stream. |udp.transport| should be the TLS connection's reader from proxy. |src| should be the external data input.

(udp *Conn, src *io.PipeReader)

Source from the content-addressed store, hash-verified

447// |udp.transport| should be the TLS connection's reader from proxy.
448// |src| should be the external data input.
449func (c *Client) encodeLoopUDP(udp *Conn, src *io.PipeReader) {
450 data := make([]byte, 1460)
451loop:
452 for {
453 select {
454 case <-udp.connCtx.Done():
455 break loop
456 default:
457 {
458 n, err := src.Read(data)
459 if err != nil {
460 if err == io.EOF {
461 c.logger.Warn("EOF in udp.transport.Read")
462 break loop
463 }
464 c.logger.Error("Error in encodeLoopUDP src.Read", "id", udp.Sid(), "err", err)
465 break loop
466 }
467
468 if n > 0 {
469 toSend := data[:n]
470 chunk, n := StreamDataToDatagramChunk(toSend, n)
471 if n > 0 {
472 _, err := udp.transport.Write(chunk)
473 if err != nil {
474 c.logger.Error("Error in encodeLoopUDP udp.transport.Write", "id", udp.Sid(), "err", err)
475 break loop
476 }
477 }
478 }
479 }
480 }
481 }
482
483 if err := udp.doClose(); err != nil {
484 c.logger.Error("Error from udp.doClose in encodeLoopUDP", "err", err)
485 }
486}
487
488// decodeLoopUDP decodes data received from the proxied UDP stream.
489// |udp.transport| should be the TLS connection's reader from proxy.

Callers 1

CreateUDPStreamMethod · 0.95

Calls 5

SidMethod · 0.80
doCloseMethod · 0.80
ReadMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected