From 01e09828aecd01ddc09f60ede80319056a41dc03 Mon Sep 17 00:00:00 2001 From: phuslu Date: Wed, 23 Oct 2024 18:56:58 +0800 Subject: [PATCH] refine client comments --- client.go | 14 +++++++++----- client_dialer.go | 22 +++++++++++++++++++--- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index f46b90e..10e364f 100644 --- a/client.go +++ b/client.go @@ -10,16 +10,20 @@ type Dialer interface { DialContext(ctx context.Context, network, addr string) (net.Conn, error) } -// Client is an UDP client that supports DNS protocol. +// Client represents a DNS client that communicates over UDP. +// It supports sending DNS queries to a specified server. type Client struct { - // Address specifies the address of dns server. + // Addr defines the DNS server's address to which the client will send queries. + // This field is used if no custom Dialer is provided. Addr string - // Timeout + // Timeout specifies the maximum duration for a query to complete. + // If a query exceeds this duration, it will result in a timeout error. Timeout time.Duration - // Dialer specifies the dialer for creating TCP/UDP connections. - // If it is set, Addr and Timeout will be ignored. + // Dialer allows for customizing the way connections are established. + // If set, it overrides the Addr field and uses the provided dialer to + // create connections for DNS queries. Dialer Dialer } diff --git a/client_dialer.go b/client_dialer.go index 175e776..331705b 100644 --- a/client_dialer.go +++ b/client_dialer.go @@ -13,9 +13,15 @@ import ( "unsafe" ) +// UDPDialer is a custom dialer for creating UDP connections. +// It manages a pool of connections to optimize performance in scenarios +// where multiple UDP connections to the same server are required. type UDPDialer struct { - Addr *net.UDPAddr - Timeout time.Duration + // Addr specifies the remote UDP address that the dialer will connect to. + Addr *net.UDPAddr + + // MaxConns limits the maximum number of UDP connections that can be created + // and reused. Once this limit is reached, no new connections will be made. MaxConns uint16 once sync.Once @@ -52,9 +58,19 @@ type udpConn struct { mu sync.Mutex } +// HTTPDialer is a custom dialer for creating HTTP connections. +// It allows sending HTTP requests with a specified endpoint, user agent, and transport configuration. type HTTPDialer struct { - Endpoint *url.URL + // Endpoint specifies the HTTP server's URL that the dialer will connect to. + // This is the base address used for sending HTTP requests. + Endpoint *url.URL + + // UserAgent defines the User-Agent header that will be included in the HTTP requests + // sent by this dialer. It can be customized for specific needs. UserAgent string + + // Transport allows for customizing the underlying transport mechanism used + // for making HTTP requests. If set, it overrides the default RoundTripper behavior. Transport http.RoundTripper }