| Age | Commit message (Collapse) | Author |
|
|
|
The generated HTML files is outdated and it is not referenced
anywhere.
|
|
|
|
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.
|
|
Go 1.22 now support for-range on numeric value.
|
|
|
|
Since Go 1.20, the standard bytes package have the Copy function.
Since Go 1.22, the standard slices package have the Concat function.
|
|
Now that Go has type parameter, we can use it to use the same function
that accept different types for working with slice of int, int64.
|
|
Some of warnings from those linter are false positives, so we just
annotated them.
|
|
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.
|
|
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.
|
|
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
|
|
|
|
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.
|
|
The shadow tool [1] report a variable where its name is declared twice
or more, in different scope.
[1] https://pkg.go.dev/golang.org/x/tools@v0.13.0/go/analysis/passes/shadow
|
|
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.
|
|
|
|
Since cmd package will not be available in documentation, there is no
need to export type and methods in it.
|
|
While at it, realign struct Account to make the size reduced from 32
to 24 bytes (-8).
|
|
This fix some linter warnings on dummy methods and handlers.
|
|
In the server, change the listen port to 9101 to prevent conflict
with autobahn test suite.
In the client, add command "chat" and "chatbot".
The "chat" command run client chart as before.
The "chatbot" command create client for all known accounts and send
N messages continuously.
|
|
When the goroutine for upgrade, reader, or pinger does not receive
any input from its queue after N duration, stop it.
Currently, N equal to ServerOptions ReadWriteTimeout.
This allow unused goroutines released back to system, minimizing
resources usage.
|
|
|
|
The maximum goroutines is quarter of max queue.
The new goroutine for pinger will be dispatched when no goroutine can
consume the current processed connection.
|
|
Adding prefix provide better way to locate and debug the error in the
future.
|
|
The Server now dispatch a goroutine to consume event from poll reader
for each client connection that is ready to read.
The maximum number of goroutine is defined in ServerOptions
maxGoroutineReader, which currently set to 1024.
|
|
|
|
The maxGoroutineUpgrader define maximum goroutines running at the same
time to handle client upgrade.
The new goroutine only dispatched when others are full, so it will
run incrementally not all at once.
Default to defServerMaxGoroutineUpgrader (128) if its not set.
|
|
Using directory testdata that contains Go code seems like not good
choices for future improvement, especially if we want to add shared code
that can be imported by server and client later.
|
|
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.
|
|
Since the autobahn script can only run on Python 2, it become hard to
setup and run the test on distro that does not provide Python 2 anymore.
The autobahn repository recommend to use docker instead.
When testing the server, we simplify it by using make task "test-server".
The test-server task run our test server in background, and then run the
autobahn fuzzingclient from container.
Once the tests completed, we trigger the server to shutdown by sending
text frame with payload "shutdown".
When testing the client, we simplify it by using make task "test-client".
The test-client task run the autobahn fuzzingserver and then
we run our client.
Once client finished, we trigger the server to generate the reports
and cleanup the container.
|
|
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.
|
|
If the HTTP handshake response contains trailing frame, handle it
directly.
If the frame is invalid or control close operation, call Quit directly
to trigger the HandleQuit if its defined by user.
|
|
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.
|
|
Using global debug value for all packages turns out is not a good
idea.
|
|
Instead of comparing the Sprintf value, compare the expected and got
directly.
|
|
The math/rand will be deprecated in Go 1.20.
|
|
In the next Go release (1.20), parsing URL with invalid percent escape
will not throw error anymore [1].
[1] https://github.com/golang/go/issues/56732
|
|
When calling Close, we initialize the internal channel gracefulClose
so the client can check the close response from server on another
goroutine serve() and signal back to Close to continue the closing
process.
This channel is never closed and nil-ed again after Close which
may cause resource leaks.
While at it, use sendClose to minimize duplicate code.
|
|
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".
|
|
Both of those functions actually call send control CLOSE frame and not
exported.
So, instead of duplicating it, we replace it with sendClose.
|
|
The Client have method send that check if the underlying connection (conn)
has been closed or not.
Since the conn can be closed anytime, for example server send to the
control CLOSE frame:
recv -> handleFrame -> handleClose -> Quit
we need to guard the conn with Mutex before calling send to prevent
data race.
|
|
|
|
This is to fix running test with -count=X, where X>1.
|
|
During testing the Client we use the un-exported method send,
while the test cases itself may close the connection and we did not
guard it.
|
|
|
|
We only do lock on exported methods, but when doing testing we call
the send method without lock which cause read and write on Client.conn
at the same time.
|
|
Replace assignment from using ":=" to use variable declaration with
type.
Rationale: clarity and minimize duplicate temporary variables with the
same type.
|
|
Changes,
* Client: from 176 to 144 (-32 bytes)
* ClientManager: from 64 to 40 (-24 bytes)
* Request: from 88 to 72 (-16 bytes)
* Response: from 40 to 24 (-16 bytes)
* route: from 48 to 32 (-16 bytes)
* Server: from 72 to 64 (-8 bytes)
* ServerOptions: from 104 to 96 (s-8 bytes)
Plus other structs in the tests.
|
|
On BenchmarkUpgrader, newHandshake will return nil if the HTTP request
header is invalid, and if we pass this to Server.handleUpgrade it will
cause panic.
This commit fix this by checking error on newHandshake.
|