aboutsummaryrefslogtreecommitdiff
path: root/lib/websocket/funcs.go
AgeCommit message (Collapse)Author
11 daysall: apply go fixShulhan
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.
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.
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-09-13lib/websocket: replace package "math/rand" with "crypto/rand"Shulhan
The rand.Seed has been deprecated since Go 1.20 (we use 1.20 in go.mod). The problem is if the user of this module is using Go tools < v1.20, there is no guarantee that the Seed is initialize randomly.
2023-06-29lib/websocket: add option to set read/write timeout on ServerShulhan
The ReadWriteTimeout define the maximum duration the server wait when receiving/sending packet from/to client before considering the connection as broken. Default read-write timeout is 30 seconds if not set. This changes affect the exported function Send and Recv by adding additional parameter timeout to both of them.
2023-06-18lib/websocket: revert maxBuffer back to 1024Shulhan
In 25d09e2625f we increase the maxBuffer to 4096 to try increasing the performance when handling large payload. Turns out increasing this make the server cannot handle larger payload.
2023-06-04lib/websocket: increase the max buffer and queue for better throughputShulhan
The maxBuffer increased from 1024 to 4096 bytes. The reason that we use 1024 previously is related to MTU size and maximum payload in TCP (although its higher, 1460 bytes). The maxQueue increase from 128 to 4096.
2022-10-10lib/websocket: check for EAGAIN and EINTR when reading raw socketShulhan
This fix tests that sometimes fail when running with -count=X, where X > 1, $ go test -race -count=30 -timeout=30s ./lib/websocket Upon inspecting, when client sending larger payload, for example 65536 bytes, server sometimes only read half of them and return an error "resource temporarily unavailable" or "interrupted system call".
2022-06-09lib/websocket: refactoring codeShulhan
Replace assignment from using ":=" to use variable declaration with type. Rationale: clarity and minimize duplicate temporary variables with the same type.
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2020-08-31websocket: remove logging on Send functionShulhan
2020-08-11websocket: reformat some filesShulhan
2020-06-06all: use default linter optionsShulhan
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-03-17websocket: remove global random number generatorShulhan
Turn out rand.NewSource is not routine safe, replace it with default Source and seed it on init().
2019-03-12websocket: handle EAGAIN when sending large packetShulhan
When sending large packet, the send buffer may be full, which thrown error EAGAIN or "resource temporarily unavailable". To handle, this we check the errno returned from unix.Write.
2019-03-11websocket: handle possible half write on Send()Shulhan
When sending large payload, there is a possibility that a single Write may not send all packet due to buffer or size limit on TCP.
2019-03-07websocket: remove pool of slice bytesShulhan
2019-03-06websocket: refactoring handling fragmentation on serverShulhan
The temporary storage for continuous frame is moved from server to ClientManager, to prevent data race when modifying it and to allow one central function to clear it (when client closed). Another changes is on server handle parameter on HandleText and HandleBin. Previously, we pass the frame to handler, now we pass the payload since that is the real message the client send.
2019-03-06websocket: simplify reading packet on function Recv()Shulhan
2019-03-05websocket: unexport the Frame Pack methodShulhan
The method Pack on single frame is not usable in the point of view of implementor, since we prefer NewFrameXxx to create frame by operation code.
2019-03-05websocket: replace concatBytes with our bytes.ConcatShulhan
function Concat in package bytes is more flexible, allow two or more slice of byte in parameters.
2019-03-04websocket: inline the magic key, instead of globalShulhan
Since the magic key only used once, there is no need to make it global variable.
2019-03-04websocket: suppress gosec linter warning on package "crypto/sha1"Shulhan
Package sha1 is required to generate handshake key per specification.
2019-03-04websocket: split the global functions into separated fileShulhan
The idea is to make the websocket.go only for global constants and variables.