quic_datagram_v3.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package connection
  2. import (
  3. "context"
  4. "fmt"
  5. "net"
  6. "time"
  7. "github.com/google/uuid"
  8. "github.com/quic-go/quic-go"
  9. "github.com/rs/zerolog"
  10. "github.com/cloudflare/cloudflared/management"
  11. cfdquic "github.com/cloudflare/cloudflared/quic/v3"
  12. "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
  13. )
  14. type datagramV3Connection struct {
  15. conn quic.Connection
  16. // datagramMuxer mux/demux datagrams from quic connection
  17. datagramMuxer cfdquic.DatagramConn
  18. logger *zerolog.Logger
  19. }
  20. func NewDatagramV3Connection(ctx context.Context,
  21. conn quic.Connection,
  22. sessionManager cfdquic.SessionManager,
  23. index uint8,
  24. metrics cfdquic.Metrics,
  25. logger *zerolog.Logger,
  26. ) DatagramSessionHandler {
  27. log := logger.
  28. With().
  29. Int(management.EventTypeKey, int(management.UDP)).
  30. Uint8(LogFieldConnIndex, index).
  31. Logger()
  32. datagramMuxer := cfdquic.NewDatagramConn(conn, sessionManager, index, metrics, &log)
  33. return &datagramV3Connection{
  34. conn,
  35. datagramMuxer,
  36. logger,
  37. }
  38. }
  39. func (d *datagramV3Connection) Serve(ctx context.Context) error {
  40. return d.datagramMuxer.Serve(ctx)
  41. }
  42. func (d *datagramV3Connection) RegisterUdpSession(ctx context.Context, sessionID uuid.UUID, dstIP net.IP, dstPort uint16, closeAfterIdleHint time.Duration, traceContext string) (*pogs.RegisterUdpSessionResponse, error) {
  43. return nil, fmt.Errorf("datagram v3 does not support RegisterUdpSession RPC")
  44. }
  45. func (d *datagramV3Connection) UnregisterUdpSession(ctx context.Context, sessionID uuid.UUID, message string) error {
  46. return fmt.Errorf("datagram v3 does not support UnregisterUdpSession RPC")
  47. }