summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2023-07-07Release share v0.48.0 (2023-07-07)v0.48.0Shulhan
This release bring many enhancements to lib/websocket including timeout, handling upgrade and read/write concurrently using goroutine. === Breaking changes * lib/net: changes the WaitRead/Event model on Poll === Bug fixes * lib/websocket: call Quit when handshake contains close or invalid frame * lib/websocket: revert maxBuffer back to 1024 === New features * lib/ascii: add type Set * lib/net: implement generic PollEvent === Enhancements * lib/websocket: add option to set read/write timeout on Server * lib/websocket: handle concurrent upgrade using goroutine * lib/websocket: handle concurrent Server read using goroutines * lib/websocket: handle concurrent ping using goroutines === Chores * websocket/testdata: rewrite autobahn test using container
2023-07-04lib/memfs: fix missing default case in selectShulhan
While at it, fix flaky test on DirWatcher due to race condition when accessing dirKeys.
2023-07-03websocket/examples: enhance the server and clientShulhan
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.
2023-07-03lib/websocket: stop goroutines when no queue received after N durationShulhan
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.
2023-07-01lib/websocket: reformat comments and documentationShulhan
2023-07-01lib/websocket: handle concurrent ping using goroutinesShulhan
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.
2023-07-01lib/websocket: prefix the error with function or method namesShulhan
Adding prefix provide better way to locate and debug the error in the future.
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/websocket: handle concurrent Server read using goroutinesShulhan
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.
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-07-01autobahn: print reports after testing server and clientShulhan
2023-07-01lib/websocket: handle concurrent upgrade using goroutineShulhan
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.
2023-07-01lib/websocket: move the autobahn test to package internalShulhan
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.
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-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-18websocket/testdata: rewrite autobahn test using containerShulhan
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.
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-18lib/websocket: call Quit when handshake contains close or invalid frameShulhan
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.
2023-06-18lib/ascii: add unit and benchmark testsShulhan
The unit and benchmark tests are taken from upstream [1], with author permission on this GitHub comment [2]. [1] https://github.com/elliotwutingfeng/asciiset [2] https://github.com/shuLhan/share/pull/7#issuecomment-1573271518
2023-06-18AUTHORS: add Wu Tingfeng as one of authorShulhan
Wu Tingfeng provide ascii.Set type.
2023-06-18all: move internal/asciiset to asciiShulhan
The asciiset.Set type is exported as ascii.Set.
2023-06-18go.mod: update all dependenciesShulhan
2023-06-06internal: add package asciisetWu Tingfeng
The package asciiset add new type ASCIISet, a bitmap to represent list of ASCII characters for faster lookup. ASCIISet is a 36-byte value, where each bit in the first 32-bytes represents the presence of a given ASCII character in the set. The remaining 4-bytes is a counter for the number of ASCII characters in the set. The 128-bits of the first 16 bytes, starting with the least-significant bit of the lowest word to the most-significant bit of the highest word, map to the full range of all 128 ASCII characters. The 128-bits of the next 16 bytes will be zeroed, ensuring that any non-ASCII character will be reported as not in the set.
2023-06-04Release share v0.47.0 (2023-06-04)v0.47.0Shulhan
=== Breaking changes * email/maildir: major refactoring plus adding unit tests * lib/email: unexport the field ContentType in the field === Bug fixes * lib/dns: fix zone parsing on SOA record with single line * lib/memfs: ignore permission error when scanning directory content * lib/memfs: fix panic when watched file deleted or renamed * lib/email: fix parsing multiple parameters in ContentType === New features * cmd/bcrypt: CLI to compare or generate hash using bcrypt * lib/sql: add type DmlKind * email/maildir: implement Folder * lib/net: add function WaitAlive * lib/smtp: implement Client SendEmail === Enhancements * lib/dns: add option to set debug level in ServerOptions * lib/dns: do not cache empty answers * _bin/go-test-coverhtml: add parameter to run specific test * lib/http: redirect path with slash if request is directory * lib/email: handle obsolete white spaces and comment when unpacking date * lib/email: set the Field Type and unpack its value on ParseField * lib/net: increase the maximum poll events * lib/websocket: increase the max buffer and queue for better throughput === Chores * all: remove any usage of debug.Value in all packages * lib/test: update documentation related to Assert and Data * all: record the contributors of this module in file AUTHORS Signed-off-by: Shulhan <ms@kilabit.info>
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.
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-06-04all: update description of some command and in READMEShulhan
Mention that some of the commands are example of implementation of the library.
2023-06-04all: record the contributors of this module in file AUTHORSShulhan
2023-06-04all: remove the copyright holder in the LICENSE fileShulhan
The idea is to allow other contributors to copyright their code while still referencing the same LICENSE.
2023-06-04lib/email: set the Field Type and unpack its value on ParseFieldShulhan
Once the field Name has detected and its Value is valid, we can unpack the Value based to type that it represent, for example to Date or Mailbox. This changes remove calling to unpack directly in some tests and check an error when testing ParseHeader.
2023-06-04all: git ignore the _bin/bcrypt binaryShulhan
2023-06-04lib/email: handle obsolete white spaces and comment when unpacking dateShulhan
In the obsolete syntax, white space and comments can appear between many more element, for example the folloing Date value are valid Date : Fri, 21 Nov 1997 09(comment): 55 : 06 -0600 This changes handle this by sanitizing the Field value, removing comment and merge multiple spaces into one, before parsing it.
2023-06-04lib/email: add benchmark for IsValidLocalShulhan
2023-06-04lib/email: remove spaces when parsing domain in parseMailboxShulhan
In obsolete syntax for mailbox in Field value, a domain can have space. For example, the following message-id is valid according to RFC 5322 Section A.6.3: message-id:<1234 @ local(blah) .machine .example>\r\n This changes handle this by removing all spaces before validating the domain name.
2023-06-04lib/bytes: use %q to print characters in example codeShulhan
The %q will print the character itself if its printable or an hexadecimal representation.
2023-06-04lib/bytes: add function RemoveSpacesShulhan
Unlike TrimSpaces, which only remove spaces on beginning and end, RemoveSpaces remove all spaces including in between characters.
2023-06-03lib/email: refactoring Field parsingShulhan
Split the parsing into two methods: parseName and parseValue. The error returned from those methods are prefixed by its name.
2023-06-01lib/email: unexport the field ContentType in the fieldShulhan
The field ContentType will be set only when the field Name is "Content-Type" so it's not always exist on each field. To get the field ContentType, use Header.ContentType().
2023-05-30lib/smtp: implement Client SendEmailShulhan
Somehow in 3a1a2715b25f, we include this method without implementing it. The SendEmail method simplify sending email by automatically create [MailTx] for passing it to method Client.MailTx. The test right now use live connection since the Server is not ready yet.
2023-05-30lib/smtp: changes the field name for listener for clarityShulhan
This changes rename field, * listener to listenMta since this is the socket that responsible receiving message from other Mail Trasnfer Agent (MTA). * tlsListener to listenSubmission since this is the socket that responsible receiving message from Mail User Agent (MUA) for submiting new message.
2023-05-30lib/smtp: return pointer to the struct type instead of interfaceShulhan
Even if LocalHandler and LocalStorage is one of implementation of Handler and Storage, it is be better if its return the actual type, to minimize confusion.
2023-05-30lib/test: update documentation related to Assert and DataShulhan
The documentation is based on the article published at https://kilabit.local/journal/2023/go_test_data/ after reviewing and explain how to use both of them to public.
2023-05-30lib/test: add another example for Assert-ing stringShulhan
This example show expected, got, and diff between them.
2023-05-30lib/email: update the package documentationShulhan
Add an overview of all types as building blocks from top to bottom so we can see the relation in each of them.
2023-05-30_doc: remove the author attribute from RFC documentsShulhan
I am not the authors of those RFCs, only make the summary to make it simple to understand and to implement.
2023-05-30lib/email: make the ContentType match case insensitiveShulhan
The GetParamValue and SetBoundary should match any parameter key in case insensitive matter. While at it, add examples for ParseContentType and SetBoundary, and move test for GetParamValue to Example.
2023-05-30lib/email: fix parsing multiple parameters in ContentTypeShulhan
While at it, also fix the ContentType String method to prefix ';' before appending parameter key and value.
2023-05-30lib/smtp: use WaitAlive instead of time.SleepShulhan
This cut the test time to 0.100 second, match with sleep duration.
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.