Skip to content

Commit

Permalink
refine client comments
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Oct 23, 2024
1 parent dc20dcf commit 01e0982
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
14 changes: 9 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
22 changes: 19 additions & 3 deletions client_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 01e0982

Please sign in to comment.