MCPcopy
hub / github.com/cloudflare/cloudflared / proxyTCPStream

Method proxyTCPStream

proxy/proxy.go:316–349  ·  view source on GitHub ↗

proxyTCPStream proxies private network type TCP connections as a stream towards an available origin. This is different than proxyStream because it's not leveraged ingress rule services and uses the originDialer from OriginDialerService.

(
	tr *tracing.TracedContext,
	tunnelConn connection.ReadWriteAcker,
	dest netip.AddrPort,
	originDialer ingress.OriginTCPDialer,
	logger *zerolog.Logger,
)

Source from the content-addressed store, hash-verified

314// This is different than proxyStream because it's not leveraged ingress rule services and uses the
315// originDialer from OriginDialerService.
316func (p *Proxy) proxyTCPStream(
317 tr *tracing.TracedContext,
318 tunnelConn connection.ReadWriteAcker,
319 dest netip.AddrPort,
320 originDialer ingress.OriginTCPDialer,
321 logger *zerolog.Logger,
322) error {
323 ctx := tr.Context
324 _, connectSpan := tr.Tracer().Start(ctx, "stream-connect")
325
326 start := time.Now()
327 originConn, err := originDialer.DialTCP(ctx, dest)
328 if err != nil {
329 connectStreamErrors.Inc()
330 tracing.EndWithErrorStatus(connectSpan, err)
331 return err
332 }
333 connectSpan.End()
334 defer func() { _ = originConn.Close() }()
335 logger.Debug().Msg("origin connection established")
336
337 encodedSpans := tr.GetSpans()
338
339 if err := tunnelConn.AckConnection(encodedSpans); err != nil {
340 connectStreamErrors.Inc()
341 return err
342 }
343
344 connectLatency.Observe(float64(time.Since(start).Milliseconds()))
345 logger.Debug().Msg("proxy stream acknowledged")
346
347 stream.Pipe(tunnelConn, originConn, logger)
348 return nil
349}
350
351func (p *Proxy) proxyLocalRequest(proxy ingress.HTTPLocalProxy, w connection.ResponseWriter, req *http.Request, isWebsocket bool) {
352 if isWebsocket {

Callers 1

ProxyTCPMethod · 0.95

Calls 8

EndWithErrorStatusFunction · 0.92
PipeFunction · 0.92
TracerMethod · 0.80
GetSpansMethod · 0.80
StartMethod · 0.65
DialTCPMethod · 0.65
CloseMethod · 0.65
AckConnectionMethod · 0.65

Tested by

no test coverage detected