refactor(config): consolidate transport setup and eliminate duplication

Consolidate DoH/DoH3/DoQ transport initialization into a single
SetupTransport method and introduce generic helper functions to eliminate
duplicated IP stack selection logic across transport getters.

This reduces code duplication by ~77 lines while maintaining the same
functionality.
This commit is contained in:
Cuong Manh Le
2026-01-06 18:50:13 +07:00
committed by Cuong Manh Le
parent e4e655414c
commit 2d9603609f
3 changed files with 57 additions and 136 deletions
+2 -2
View File
@@ -63,7 +63,7 @@ type doqConn struct {
mu sync.Mutex
}
func newDOQConnPool(ctx context.Context, uc *UpstreamConfig, addrs []string) *doqConnPool {
func newDOQConnPool(_ context.Context, uc *UpstreamConfig, addrs []string) *doqConnPool {
_, port, _ := net.SplitHostPort(uc.Endpoint)
if port == "" {
port = "853"
@@ -96,7 +96,7 @@ func newDOQConnPool(ctx context.Context, uc *UpstreamConfig, addrs []string) *do
// Resolve performs a DNS query using a pooled QUIC connection.
func (p *doqConnPool) Resolve(ctx context.Context, msg *dns.Msg) (*dns.Msg, error) {
// Retry logic for io.EOF errors (as per original implementation)
for i := 0; i < 5; i++ {
for range 5 {
answer, err := p.doResolve(ctx, msg)
if err == io.EOF {
continue