aboutsummaryrefslogtreecommitdiff
path: root/lib/net
AgeCommit message (Collapse)Author
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2025-01-23all: use for-range with numericShulhan
Go 1.22 now support for-range on numeric value.
2025-01-23lib/net: remove old build tagsShulhan
2024-03-09lib: move package "net/html" to "lib/html"Shulhan
Putting "html" under "net" package make no sense. Another reason is to make the package flat under "lib/" directory.
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-05all: comply with linter recommendations #1Shulhan
Instead of annotating the lines that caught by linters, fix it to comply with the recommendations. This causes several breaking changes, especially related to naming, * api/slack: [Message.IconUrl] become [Message.IconURL] * lib/dns: DefaultSoaMinumumTtl become DefaultSoaMinimumTTL * lib/email: [Message.SetBodyHtml] become [Message.SetBodyHTML] * lib/http: [Client.GenerateHttpRequest] become [Client.GenerateHTTPRequest] * lib/http: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/http: [EndpointRequest.HttpWriter] become [EndpointRequest.HTTPWriter] * lib/http: [EndpointRequest.HttpRequest] become [EndpointRequest.HTTPRequest] * lib/http: [ServerOptions.EnableIndexHtml] become [ServerOptions.EnableIndexHTML] * lib/http: [SSEConn.HttpRequest] become [SSEConn.HTTPRequest] * lib/smtp: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/ssh/sftp: [FileAttrs.SetUid] become [FileAttrs.SetUID] * lib/ssh/sftp: [FileAttrs.Uid] become [FileAttrs.UID]
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
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-11-26lib/net: use [time.Ticker] to loop in WaitAliveShulhan
The Timeout field in net.Dialer sometimes does not have any effect. In the for-loop, we expect that each Dial at least consume 100 ms before returning an error. Turns out, on several occasion, the loop run too quickly, less than the passed timeout. This is probably because the listening address has not been active yet and we run it in the same machine, the OS (or Go?) return immediately without waiting for timeout.
2023-11-25lib/net: add method ReadShulhan
The Read method read packet from raw connection. If the conn parameter is nil it will return [net.ErrClosed]. The bufsize parameter set the size of buffer for each read operation, default to 1024 if not set or invalid (less than 0 or greater than 65535). The timeout parameter set how long to wait for data before considering it as failed. If its not set, less or equal to 0, it will wait forever. If no data received and timeout is set, it will return [ErrReadTimeout]. If there is data received and connection closed at the same time, it will return the data first without error. The subsequent Read will return empty packet with [ErrClosed]. Signed-off-by: Shulhan <ms@kilabit.info>
2023-09-11lib: fix method signature for WriteToShulhan
The WriteTo should return int64 not int.
2023-09-11lib/net: realign struct for better size allocationShulhan
The realignment reduce the cost of the following struct, * ResolvConf: from 96 to 56 bytes (-40) * struct in TestResolvConf_Init: from 56 to 48 bytes (-8)
2023-07-01lib/net: changes the WaitRead/Event model on PollShulhan
Previously, the Pool's WaitRead and WaitReadEVent methods return list of file descriptor (fd) and keeps the fd in the pool. In case we want to process the returned fd concurrently, by running it in different goroutine, the next call WaitRead may return the same fd if its goroutine not fast enought to read from fd. This changes fix this issue by removing list of fd from poll and set the fd flag to blocking mode again after returning it from WaitRead or WaitReadEvent. This changes also remove the ReregisterRead and ReregisterEvent methods since it is not applicable anymore.
2023-07-01lib/net: implement generic PollEventShulhan
The PollEvent contains file descriptor and the underlying event based on OS, unix.EpollEvent on Linux or unix.Kevent_t on BSD. The Poll interface provides two APIs to works with PollEvent, WaitReadEvents that return list of PollEvent ready for read, and ReregisterEvent to register the event back to poll (only for Linux).
2023-06-29lib/net: set the file descriptor to non-block on ReregisterReadShulhan
In case the user of poll changes the fd flags to block for reading or writing and forgot to set it non-block again, this may cause an issue on the poll.
2023-06-04lib/net: increase the maximum poll eventsShulhan
The maxQueue define the number of events that can be read from poll at one time. Using 128 seems to small for high throughput networks. Increasing this number also increase the memory consumed by process. Maybe later we can export this function as option when creating poll.
2023-05-30lib/net: add function WaitAliveShulhan
WaitAlive try to connect to network at address until timeout reached. If connection cannot established it will return an error. Unlike [net.DialTimeout], this function will retry not returning an error immediately if the address has not ready yet.
2023-05-27lib/net: add _test suffix to Example in testShulhan
This is to prevent non-exported functions, type, or variables being used in example.
2023-04-09lib/net: refactoring resolv.conf parser using lib/bytes#ParserShulhan
The lib/io#Reader will be deprecated and replaced with lib/bytes#Parser in the future.
2023-04-02lib/net: add method WriteTo to ResolvConfShulhan
The WriteTo method write the ResolvConf as text.
2023-03-26lib/net: changes the PopulateQuery logicShulhan
Previously, PopulateQuery only add the passed dname if the number of dots is greater than 0. After inspecting the result from dig and getenv, the dots seems does not affect the query. For example, if we have A record for domain "kilabit", both of those tools query name "kilabit" without adding local domain or domain in search.
2022-07-02net/html: use inline replacement to clean up white spacesShulhan
Instead of using bytes.Replace, three times, iterate the plain text manually to clean up the white and multiple spaces. Benchmark result, name old time/op new time/op delta Sanitize-8 4.27µs ±10% 2.64µs ±13% -38.21% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Sanitize-8 4.84kB ± 0% 4.45kB ± 0% -7.94% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Sanitize-8 13.0 ± 0% 6.0 ± 0% -53.85% (p=0.000 n=10+10)
2022-06-27all: move lib/sanitize.HTML to net/html.SanitizeShulhan
Since the sanitize package only contains HTML function, and the html package already exist, we move the function into html package.
2022-06-27net/html: convert the NormalizeForID input letters to lower caseShulhan
While at it, minimize allocation by using the input []byte as output.
2022-06-24net/html: add function NormalizeForIDShulhan
Given an input string, The NormalizeForID normalize it to HTML ID. The normalization follow Mozilla specification [1] rules, - it must not contain whitespace (spaces, tabs etc.), - only ASCII letters, digits, '_', and '-' should be used, and - it should start with a letter. An empty string is equal to "_". Any other unknown characters will be replaced with '_'. If the input does not start with letter, it will be prefixed with '_', unless it start with '_'. [1] https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id.
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2022-04-14lib/net: add method to populate query on ResolvConfShulhan
Given a domain name to be resolved, the PopulateQuery generate list of names to be queried based on registered Domain and Search in the resolv.conf file. The domain name itself will be on top of the list if its contains any dot.
2021-10-14lib/ascii: change signature of ToLower and ToUpperShulhan
Using pointer to slice on method or function is not a Go idiom. It is created when I still new to Go.
2021-03-14all: refactoring the test.Assert and test.AssertBench signatureShulhan
Previously, the test.Assert and test.AssertBench functions has the boolean parameter to print the stack trace of test in case its not equal. Since this parameter is not mandatory and its usually always set to "true", we remove them from function signature to simplify the call to Assert and AssertBench.
2020-11-10net: always return the host name or IP on ParseIPPortShulhan
Previously, if the address is an IP address the returned value is empty, for example "127.0.0.1" will return empty host but with non-nil IP and port. This changes always return the host either as host name (the same as paremeter) or valid IP address.
2020-06-10all: update email addressShulhan
2020-06-06all: use default linter optionsShulhan
2020-05-16all: fix and suppress linter warningsShulhan
2020-04-05html: add function to simplify iterating node in HTML treeShulhan
The NodeIterator have the method Next() that will return the first child or the next sibling of current node, iteratively from top to bottom.
2020-04-05net/html: new package to simplify the golang.org/x/net/htmlShulhan
The x/net/html package currently only provide bare raw functionalities to iterate tree, there is no check for empty node, and no function to get attribute by name without looping it manually. This package extends the package by adding methods to get node's attribute by name, get the first non-empty child, and get the next non-empty sibling.
2020-02-13net: replace single switch-case with if-statementShulhan
2020-01-23net: update comment on ParseIPPortShulhan
2019-12-07net: check and log error on poll's UnregisterReadShulhan
2019-11-14net: handle interrupted system call on epoll WaitShulhan
2019-11-04net: fix the implementation of epollShulhan
While at it, add copyright information.
2019-11-01net: implement network polling using epoll and kqueueShulhan
This is the first implementation of (almost) generic polling. The Poll currently only support the Read events from now, because the most common use case is for handling multiple socket without using goroutines.
2019-06-14ascii: new library for working with ASCII charactersShulhan
This library previously part of bytes package. To make it bytes package consistent (only working with slice of byte), we move all ASCII related constants, variables, and functions into new package.
2019-06-14all: fix nolint formatShulhan
The valid syntax to suppress linter warnings is "//nolint:<name>" with no space between comment and "nolint" and between ":". Also, we move the placement of nolint directive to the top of statements for multiple nolint in the same scope. While at it, fix and supress some linter warnings.
2019-05-21net: add function to convert IPv6 into dot formatShulhan
This function only useful for expanding SPF macro "i" or when generating query for DNS PTR.
2019-05-18net: add function to check if IP address is IPv4 or IPv6Shulhan
Currently, the standard library does not provide a function to check if IP is IPv4 or IPv6. This is a naive implementation that check IP version based on dot or colon.
2019-05-17net: add parameter to check Fully Qualified Domain Name on IsHostnameValidShulhan
Fully Qualified Domain Name (FQDN) is a domain name that have two or more labels.
2019-03-26net: change return value of ParseIPPort to include hostnameShulhan
Previously, if parameter address in ParseIPPort is hostname instead of IP address it will return an error. This commit change the return value to hostname without any error. So, instead of error it will return the hostname in address. This changes affect dns library when creating NewTCPClient and NewUDPClient.
2019-03-01all: fix warnings from linterShulhan
Most of the warnings caused by update to linter which cause global variables declared with grouping "( ... )" and that has been suppressed, are become false-positive again.
2019-02-05lib/net: replace space separators with bytes.ASCIISpacesShulhan
2019-02-05lib/io: rename Reader SkipSpace to SkipSpacesShulhan