StartAndAccept starts QUIC server and waits for Lambda connection
(ctx context.Context, udpConn *net.UDPConn, cfg *config.Config)
| 27 | |
| 28 | // StartAndAccept starts QUIC server and waits for Lambda connection |
| 29 | func (s *Server) StartAndAccept(ctx context.Context, udpConn *net.UDPConn, cfg *config.Config) (quic.Connection, error) { |
| 30 | // Get the local address from our UDP socket (same port used for hole punching) |
| 31 | localAddr := udpConn.LocalAddr().(*net.UDPAddr) |
| 32 | |
| 33 | // Close UDP socket to free the port for QUIC server |
| 34 | udpConn.Close() |
| 35 | |
| 36 | // Small delay to ensure port is released |
| 37 | time.Sleep(shared.DefaultSocketReleaseDelay) |
| 38 | |
| 39 | // Generate TLS config for server |
| 40 | tlsConfig, err := shared.GenerateTLSConfig(shared.TLSConfigOptions{ |
| 41 | Organization: "Orchestrator QUIC Server", |
| 42 | DNSNames: []string{"orchestrator.local"}, |
| 43 | }) |
| 44 | if err != nil { |
| 45 | return nil, fmt.Errorf("failed to generate TLS config: %w", err) |
| 46 | } |
| 47 | |
| 48 | log.Printf("🔗 Starting QUIC server on %s (same port as hole punch)", localAddr.String()) |
| 49 | |
| 50 | // Get mode-based QUIC configuration |
| 51 | streamWindow, connWindow, maxIncomingStreams, maxIncomingUniStreams := shared.GetQUICConfig( |
| 52 | cfg.ModeConfig.BufferSize, |
| 53 | cfg.ModeConfig.MaxStreams, |
| 54 | ) |
| 55 | |
| 56 | log.Printf("🔧 QUIC config for %s mode: stream=%dMB, conn=%dMB, streams=%d", |
| 57 | cfg.Mode, streamWindow/(1024*1024), connWindow/(1024*1024), maxIncomingStreams) |
| 58 | |
| 59 | // Create mode-optimized QUIC configuration |
| 60 | quicConfig := &quic.Config{ |
| 61 | // Flow control optimization based on mode |
| 62 | InitialStreamReceiveWindow: uint64(streamWindow / 2), |
| 63 | MaxStreamReceiveWindow: uint64(streamWindow), |
| 64 | InitialConnectionReceiveWindow: uint64(connWindow / 2), |
| 65 | MaxConnectionReceiveWindow: uint64(connWindow), |
| 66 | |
| 67 | // Stream limits from mode configuration |
| 68 | MaxIncomingStreams: int64(maxIncomingStreams), |
| 69 | MaxIncomingUniStreams: maxIncomingUniStreams, |
| 70 | |
| 71 | // Timeout optimization based on mode |
| 72 | MaxIdleTimeout: cfg.ModeConfig.IdleTimeout, |
| 73 | HandshakeIdleTimeout: shared.QUICHandshakeTimeout, |
| 74 | KeepAlivePeriod: cfg.ModeConfig.KeepAlive, |
| 75 | |
| 76 | // Enable connection migration for better reliability |
| 77 | DisablePathMTUDiscovery: false, |
| 78 | EnableDatagrams: false, // Focus on stream performance |
| 79 | } |
| 80 | |
| 81 | // Create QUIC listener on the same port with optimized config |
| 82 | listener, err := quic.ListenAddr(localAddr.String(), tlsConfig, quicConfig) |
| 83 | if err != nil { |
| 84 | return nil, fmt.Errorf("failed to create QUIC listener: %w", err) |
| 85 | } |
| 86 |
nothing calls this directly
no test coverage detected