MCPcopy
hub / github.com/AdguardTeam/dnsproxy / startDoQServer

Function startDoQServer

upstream/doq_internal_test.go:490–531  ·  view source on GitHub ↗

startDoQServer starts a test DoQ server. Note that it adds its own shutdown to cleanup of t.

(t *testing.T, tlsConf *tls.Config, port int)

Source from the content-addressed store, hash-verified

488// startDoQServer starts a test DoQ server. Note that it adds its own shutdown
489// to cleanup of t.
490func startDoQServer(t *testing.T, tlsConf *tls.Config, port int) (s *testDoQServer) {
491 tlsConf.NextProtos = []string{NextProtoDQ}
492
493 udpAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("127.0.0.1:%d", port))
494 require.NoError(t, err)
495
496 conn, err := net.ListenUDP("udp", udpAddr)
497 require.NoError(t, err)
498 testutil.CleanupAndRequireSuccess(t, conn.Close)
499
500 transport := &quic.Transport{
501 Conn: conn,
502 // Necessary for 0-RTT.
503 VerifySourceAddress: func(a net.Addr) bool {
504 return true
505 },
506 }
507
508 listen, err := transport.ListenEarly(
509 tlsConf,
510 &quic.Config{
511 Allow0RTT: true,
512 },
513 )
514 require.NoError(t, err)
515 testutil.CleanupAndRequireSuccess(t, transport.Close)
516
517 s = &testDoQServer{
518 addr: listen.Addr().String(),
519 listener: listen,
520 // TODO(d.kolyshev): Add a concurrent safe [slog.Handler] wrapper for
521 // [testing.TB] log function.
522 logger: testLogger,
523 conns: map[*quic.Conn]struct{}{},
524 connsMu: &sync.Mutex{},
525 }
526
527 go s.Serve()
528 testutil.CleanupAndRequireSuccess(t, s.Shutdown)
529
530 return s
531}

Callers 4

TestDNSOverQUICFunction · 0.85
TestDNSOverQUIC_0RTTFunction · 0.85

Calls 3

AddrMethod · 0.80
ServeMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…