aboutsummaryrefslogtreecommitdiff
path: root/lib/dns/dot_client.go
AgeCommit message (Collapse)Author
2026-02-02lib/dns: minimize use of appendShulhan
In handleDoHRequest, we did not need to call append, just copy it as is. In DoTClient and TCPClient, since we already do make, use direct copy instead of another append.
2025-02-04all: remove the nolint tagsShulhan
The "nolint" tag is used to ignore lines from being processed by golangci-lint. Since we are not using golangci-lint anymore, now and in the future, those lines can be removed.
2025-01-23all: replace "lib/bytes.AppendXxx" with standard libraryShulhan
Since Go 1.19, package "encoding/binary.BigEndian" support appending byte order.
2024-03-27lib/dns: refactor [Message.Unpack] to [UnpackMessage]Shulhan
The previous API for Message is a little bit weird. Its provides creating Message manually, but expose the method [UnpackHeaderQuestion], meanwhile the field packet itself is unexported. In order to make it more clear we refactor [Message.Unpack] to function [UnpackMessage] that accept raw DNS packet.
2024-03-05all: comply with linter recommendations #3Shulhan
For HTTP server that use TLS, set the minimum TLS version and ReadHeaderTimeout to mitigate slowloris attack. For HTTP client or server that parameterize the use of InsecureSkipVerify, annotate the line with "nolint:gosec" to allow the code pass the check. Library that still use sha1, in example in DKIM and TOTP, skip the warnings by annotating the line with "nolint:gosec". A pointer variable now allocated their address before assigning its value. Any error that returned now wrapped using "%w". Also, replace error checking using [errors.Is] or [errors.As] instead of using equal or not-equal operators. In "lib/http", replace any usage of "math/rand" with "crypto/rand". Any call of [math/big.Rat.SetString] now annotated with "nolint:gosec" since its false positive, the issue has been fixed in Go >= 1.17.7. Any switch case that does not cover the rest of the possible values now handled by adding the cases or by replacing the "default" case with the rest of values.
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2024-02-25lib/dns: prefix the error message with method namesShulhan
By prefixing the error message it allow us to better track the error message written by application.
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-05-20all: remove any usage of debug.Value in all packagesShulhan
Using global debug value for all packages turns out is not a good idea.
2023-03-25lib/dns: fix all lint warnings suggested by revive and fieldalignmentShulhan
2022-05-12all: rewrite all codes to use "var" instead of ":="Shulhan
Using ":=" simplify the code but we lose the type. For example, v := F() The only way we know what the type of v is by inspecting the function F. Another disadvantages of using ":=" may cause extra variables allocation where two or more variables with same type is declared inside body of function where it could be only one. While at it, we split the struct for test case into separate type.
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2021-11-16lib/dns: refactoring, change signature of client LookupShulhan
Previously, Lookup() method on Client pass the question name, type, and class as parameters. This changes make those parameters into MessageQuestion.
2021-11-15lib/dns: realign all struct fieldsShulhan
Using the fieldalignment, we got the following output, answer.go:15:13: struct with 56 pointer bytes could be 24 = 32 bytes caches.go:27:13: struct with 24 pointer bytes could be 16 = 8 dot_client.go:20:16: struct with 16 pointer bytes could be 8 = 8 hosts_file.go:24:16: struct with 64 pointer bytes could be 48 = 16 message.go:53:14: struct of size 176 could be 168 = 8 rdata_mx.go:20:14: struct with 16 pointer bytes could be 8 = 8 rdata_opt.go:18:15: struct with 16 pointer bytes could be 8 = 8 rdata_srv.go:16:15: struct with 64 pointer bytes could be 56 = 8 rdata_wks.go:30:15: struct with 40 pointer bytes could be 32 = 8 request.go:20:14: struct with 32 pointer bytes could be 24 = 8 resource_record.go:24:21: struct with 56 pointer bytes could be 40 = 16 server.go:76:13: struct with 120 pointer bytes could be 112 = 8 server_options.go:20:20: struct of size 240 could be 224 = 16 tcp_client.go:21:16: struct with 40 pointer bytes could be 24 = 16 udp_client.go:24:16: struct with 24 pointer bytes could be 16 = 8 udp_client_pool.go:25:20: struct with 24 pointer bytes could be 16 = 8 zone_file.go:22:15: struct with 128 pointer bytes could be 120 = 8 zone_parser.go:53:17: struct with 88 pointer bytes could be 72 = 16 Turns out the struct that we frequently used, answer and resource_record, is not optimized. This changes reorder all structs field to save space in memory.
2021-11-14lib/dns: refactoring, introduce new type RecordClassShulhan
Previously, the record class is represented by uint16 using prefix QueryClassXxx. This changes make the record class to be an independent type, to make code more strict (prevent passing invalid value), and readable.
2021-11-14lib/dns: refactoring, create type RecordType to represent type of RRShulhan
Previously, we use uint16 to represent type for ResourceRecord Type or Question type. To make the code more strict, where parameter or return value, must be expected as record type, we add new type to represent the RR type: RecordType. This changes also rename any variable name of QType or qtype to RType or rtype because QType is misleading. The type defined the ResourceRecord to be queried not only question.
2021-11-13lib/dns: use snake case for file namingShulhan
Using snake case make the file naming more readable.