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

Method proxyStream

proxy/proxy.go:277–310  ·  view source on GitHub ↗

proxyStream proxies type TCP and other underlying types if the connection is defined as a stream oriented ingress rule. connectedLogger is used to log when the connection is acknowledged

(
	tr *tracing.TracedContext,
	rwa connection.ReadWriteAcker,
	dest string,
	originDialer ingress.StreamBasedOriginProxy,
	logger *zerolog.Logger,
)

Source from the content-addressed store, hash-verified

275// ingress rule.
276// connectedLogger is used to log when the connection is acknowledged
277func (p *Proxy) proxyStream(
278 tr *tracing.TracedContext,
279 rwa connection.ReadWriteAcker,
280 dest string,
281 originDialer ingress.StreamBasedOriginProxy,
282 logger *zerolog.Logger,
283) error {
284 ctx := tr.Context
285 _, connectSpan := tr.Tracer().Start(ctx, "stream-connect")
286
287 start := time.Now()
288 originConn, err := originDialer.EstablishConnection(ctx, dest, logger)
289 if err != nil {
290 connectStreamErrors.Inc()
291 tracing.EndWithErrorStatus(connectSpan, err)
292 return err
293 }
294 connectSpan.End()
295 defer func() { _ = originConn.Close() }()
296 logger.Debug().Msg("origin connection established")
297
298 encodedSpans := tr.GetSpans()
299
300 if err := rwa.AckConnection(encodedSpans); err != nil {
301 connectStreamErrors.Inc()
302 return err
303 }
304
305 connectLatency.Observe(float64(time.Since(start).Milliseconds()))
306 logger.Debug().Msg("proxy stream acknowledged")
307
308 originConn.Stream(ctx, rwa, logger)
309 return nil
310}
311
312// proxyTCPStream proxies private network type TCP connections as a stream towards an available origin.
313//

Callers 1

ProxyHTTPMethod · 0.95

Calls 8

EndWithErrorStatusFunction · 0.92
TracerMethod · 0.80
GetSpansMethod · 0.80
StartMethod · 0.65
EstablishConnectionMethod · 0.65
CloseMethod · 0.65
AckConnectionMethod · 0.65
StreamMethod · 0.65

Tested by

no test coverage detected