Commit Graph

41 Commits

Author SHA1 Message Date
andri lim 282773af69
Reduce compiler warnings when using new chronos (#149)
* Reduce compiler warnings when using new chronos

* chronos req

* Reduce more warnings
2024-01-22 19:08:17 +07:00
Etan Kissling f8ed9b40a5
replace `utils` module with direct `generate` calls (#148)
The `utils` module uses a convoluted mechanism for filling byte arrays
with random data. The `generate` function can be used directly, making
the `utils` module obsolete.
2023-07-24 22:38:21 +02:00
diegomrsantos 3696e3f3a5
Handle cancellation in close (#143)
* Handle cancellation in close

* Using a future instead of sleepAsync
2023-06-06 22:57:40 +02:00
Tanguy cf8b8ce235
Remove newRng (#132) 2022-11-21 19:29:20 +01:00
Etan Kissling 7b2ed397d6
properly support concurrent message sending (#126)
`nim-websock` suffered from a number of issues that are being addressed:

1. Long messages > `frameSize` (default 1 MB) were split into fragments
   of `frameSize` each. However, when a concurrent message is sent, it
   may be interleaved among the fragments of an already-sending message.
   This is only allowed for control packets without a mux extension.

2. When the WebSocket session is closed, a msg may have been partially
   received. This partial frame was reported as a full message, without
   indication that the receiving was canceled. This behaviour is fixed
   by raising a `WSClosedError` instead of reporting the partial msg.

3. When an individual `send` operation was canceled, it would actually
   stop sending the remainder of a potentially partially sent messages.
   This would corrupt the stream for concurrent and followup operations.
   Cancellation is now inhibited for the message currently sending.
   It is still possible to cancel messages that are not yet scheduled.

4. Messages could get reordered when using asynchronous encoders. This
   is addressed by delaying followup messages until the current message
   is fully encoded and transmitted (except for control packets).

Co-authored-by: Tanguy <tanguy@status.im>
2022-09-06 11:09:21 +02:00
tersec 8a72c0f769
--styleCheck:error (#122)
* --styleCheck:error

* --styleCheck:error iff >= Nim 1.6
2022-07-21 15:38:13 +00:00
Tanguy 92d350fe88
Fix fragmented message sending (#116)
We previously crashed when sending things over 1mb
2022-06-30 17:14:07 +02:00
Jacek Sieka e974acbe0a
test fixes (#115)
* don't use global for server instance
  * it gets shared between tests and causes gcsafe to trigger
* enable `chronosStrictException` in tests
* avoid asynctests dep
* testcommon -> all_tests (like the other projects)
2022-06-20 09:19:38 +02:00
jangko 4a7a058843
add http header hook
fix #101
2022-03-16 08:24:16 +07:00
Tanguy 908632aa07
Fix for styleCheck:usages (#96) 2021-12-27 11:27:21 +01:00
Mark Spanbroek f4e5e6f766 Fix chronos warning 2021-09-21 09:48:36 +02:00
Mark Spanbroek 6f3d5cdb2d Fix remaining GCUnsafe2 warnings
Removes last use of globals in async tests.
2021-09-21 09:45:09 +02:00
Mark Spanbroek 80f62e8fdd Remove unused imports 2021-09-21 09:44:07 +02:00
Mark Spanbroek e974a866b6 Update to latest asynctest, with unittest2 support
Also fixes a number of GcUnsafe2 warnings,
by placing var declarations inside the suite.
2021-09-21 09:35:12 +02:00
Dmitriy Ryajov 0ec755738c
Perform utf-8 validation at message boundaries (#90)
* validate utf8 at the message level

* move utf-8 validation to message

* rename `recv` to `recvMsg`

* add partial frame validation tests

* use `recvMsg` instead of `recv`
2021-08-04 10:23:56 -06:00
Dmitriy Ryajov 06ae75cf7f
add support for DNS resolution (#81)
* add support for DNS resolution

- reworked API to be more consistent
  - string addresses and Uri types will be now resolved
- made the API more consistent

* log failed connection attempt

* agent string can't contain spaces

* add websock topic (#83)

* style

Co-authored-by: Tanguy Cizain <tanguycizain@gmail.com>
2021-07-14 18:51:39 -06:00
jangko b3c60bbd4e
rename nim-ws to nim-websock 2021-06-29 08:50:29 +07:00
Tanguy Cizain 781cb35200
Fix mutual closing (#76)
* add mutual closing test

* fix mutual closing
2021-06-28 14:52:18 +02:00
jangko 5a93ad7867
add deflate compression test cases
* binary data roundtrip
* text data roundtrip
2021-06-20 14:50:54 +07:00
jangko 3a0834943d
fixes copyright header in each .nim file 2021-06-20 11:28:38 +07:00
jangko 32b62989a4
add test cases for multiple extensions flow
using dummy `base64` and `hex` extensions
- check flow client-server flow,
  `hex` to `base64` and `base64` to `hex`
- check for encode-decode roundtrip
2021-06-16 17:44:38 +07:00
Dmitriy Ryajov 5af418f850
add accepts api (#51)
* add accepts api

* Fix partial frame handling and allow extensions to hijack the flow (#56)

* moving files around

* wip

* wip

* move tls example into server example

* add tls functionality

* rename

* rename

* fix tests

* move extension related files to own folder

* use trace instead of debug

* export extensions

* rework partial frame handling and closing

* rework status codes as distincts

* logging

* re-enable extensions processing for frames

* enable all test for non-tls server

* remove tlsserver

* remove offset to mask - don't think we need it

* pass sessions extensions when calling send/recv

* adding encode/decode extensions flow test

* move server/client setup to helpers

* proper frame order execution on decode

* fix tls tests

* fix merge

* add tls support for `accept` call

* fix tests to use accepts & cb
2021-06-14 17:20:28 -06:00
jangko 88e99ff028
fixes failing utf8 test case
it was a buggy test case, not related to windows
but by chance discovered on windows.
2021-06-12 13:39:24 +07:00
Dmitriy Ryajov 3e1599d790
Fix partial frame handling and allow extensions to hijack the flow (#56)
* moving files around

* wip

* wip

* move tls example into server example

* add tls functionality

* rename

* rename

* fix tests

* move extension related files to own folder

* use trace instead of debug

* export extensions

* rework partial frame handling and closing

* rework status codes as distincts

* logging

* re-enable extensions processing for frames

* enable all test for non-tls server

* remove tlsserver

* remove offset to mask - don't think we need it

* pass sessions extensions when calling send/recv

* adding encode/decode extensions flow test

* move server/client setup to helpers

* proper frame order execution on decode

* fix tls tests
2021-06-11 14:04:09 -06:00
andri lim 1fed598d8c
implement extension parameters parser (#44)
fixes #43
2021-05-31 21:02:24 -06:00
Dmitriy Ryajov 64da1a4344
Rework http (#38)
* wip

* wip

* move http under ws folder

* use asyctest

* wip

* wip

* rework response sending

* make example work with latest changes

* wip request/response

* misc

* fix example to use new http layer

* pass tls flags to client

* more cleanup

* unused imports

* more unsused imports

* better headers

* add helpre sendError

* export sendError

* attach selected proto to session

* move proto to session

* handle unsupported version

* fix tests

* comment out for now

* fix utf8 tests

* allow tests to be ran in tls

* misc

* use Port type

* add tls flags

* better api

* run tls tests

* fix tests on windows

* allow running tests with tls

* mic

* wip

* fix autobahn ci

* handle close

* cleanup

* logging and error handling

* remove old stream
2021-05-31 20:39:14 -06:00
andri lim 90c664545d
implement UTF8 handling (#35)
* implement UTF8 handling

or to be precisely, we add UTF8 validator which main duty
is to detect malformed UTF8 sequence using a fast DFA UTF8
decoder.

also enable autobahn UTF8 category tests, much more green :)

fixes #13

* fixes case 7.5.1 Send a close frame with invalid UTF8 payload

* add tests for validateUTF8

- tests for validateUTF8 in raw mode
- tests for validateUTF8 in websocket client/server
2021-05-28 10:47:24 -06:00
Dmitriy Ryajov eb62ec1725
Extract session (#31)
* extract websocket session

* fix tests

* fix frame tests
2021-05-25 16:39:10 -06:00
Dmitriy Ryajov 5d0bcf6375
Client server (#29)
* better client/server separation (WIP)

* add extensions interface

* index out of bounds
2021-05-25 08:02:32 -06:00
Dmitriy Ryajov 0a4121c29d
Fix first frame (#28)
* split out frame

* use new api

* fix import
2021-05-24 18:47:27 -06:00
Dmitriy Ryajov 352bb6b3a4
use binary flag 2021-05-22 03:09:28 -06:00
Arijit Das 1b3e47d2f5
Add support for binary frame 2021-05-22 03:05:57 -06:00
Dmitriy Ryajov f37e4bb19a
Cleanup (#21)
* cleanup

* send payload with ping
2021-05-22 02:26:45 -06:00
jangko 4de768910b
text formatting: consistent indentation
using 2 spaces for both `testtlswebsockets.nim` and
`tests/testwebsockets.nim`
2021-05-22 12:12:41 +07:00
jangko 2ed87ca58d
skip failing test case in `tests/testwebsockets.nim`
on Windows there is bug with message:
`Unhandled exception: Stream is already closed! [AsyncStreamIncorrectDefect]`
caused by the async stream closed more than once.
2021-05-22 12:12:41 +07:00
Arijit Das f8cfcd1f99
Fix webscoket close and fix test cases. 2021-05-22 12:12:41 +07:00
Arijit Das 51d834a0a1
Fix webscoket close and fix test cases. 2021-05-22 12:12:31 +07:00
Arijit Das 6b76bd8261
WIP: Implement websocket TLS. (#7)
* Update http to use chronos http.

* Implement TLS in websocket.

* Add webscoket TLS test.

* Minor nit.

* Add TLS test file.

* Update http to use chronos http. (#6)

* Update http to use chronos http.

* Add stream.nim file.

* Address comments.

* Fix CI failure.

* Minor change.

* Address comments.

* Fix windows CI failing test.

* minor cleanup

* spacess

* more idiomatic connect

* use stew/base10

Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>

* Implement TLS in websocket.

* Minor nit.

* merge master

* wip

* Update http to use chronos http. (#6)

* Update http to use chronos http.

* Add stream.nim file.

* Address comments.

* Fix CI failure.

* Minor change.

* Address comments.

* Fix windows CI failing test.

* minor cleanup

* spacess

* more idiomatic connect

* use stew/base10

Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>

* Update http to use chronos http.

* Implement TLS in websocket.

* Minor nit.

* Update http to use chronos http. (#6)

* Update http to use chronos http.

* Add stream.nim file.

* Address comments.

* Fix CI failure.

* Minor change.

* Address comments.

* Fix windows CI failing test.

* minor cleanup

* spacess

* more idiomatic connect

* use stew/base10

Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>

* Implement TLS in websocket.

* Minor nit.

* add testing keys

* wip

* fix test

* wip

* remove eth dep and add skipdirs

* fix package structure

* fix deps

* check nim version

* Fix CI failure.

* Don't call `ws.stream.closeWait()`

* always close both ends to complete the sequence

* misc

* don't fail on close

* Fix windows CI.

* fix linux x86 builds

* use consistent connect pattern

* move keys to better place

* return dumbResponse

* small cleanup

Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2021-04-13 16:05:58 -06:00
Arijit Das e4f00698ea
Update http to use chronos http. (#6)
* Update http to use chronos http.

* Add stream.nim file.

* Address comments.

* Fix CI failure.

* Minor change.

* Address comments.

* Fix windows CI failing test.

* minor cleanup

* spacess

* more idiomatic connect

* use stew/base10

Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2021-04-05 15:01:10 -06:00
Dmitriy Ryajov 3923a9be20
Rework (#5)
* Use seq[byte] to store data.

* Working bytes conversion.

* Refactor the code.

* Add test.

* Add websocket test and fix closing handshake.

* Add MsgReader to read data in external buffer.

* rework frame reading

* don't do toTitleCase

* fix examples

* use byte for more comfort

* rework message reading + api

* fix tests

* adding specific exception types

* minor cleanup

* fixing tests

* more tests

* check the fin flag at the correct place

* info for debug

* split data not encoded frames

* more tests

* wip - control messages

* closing flow and more explicit exception handling

* test close and pings

* add tests task to nimble

* adding ci

* change recv semantics

* add frame tests

* remove echo

* better frame tests

* fix

* fix

* handle continuation frames properly

* more close logic handling

* wip tests

* handle close reasons properly

* test control frames encoding

* don't pass ws to event callbacks

* fix masking and use correct base64 encoding

* fix ci

* addressing review comments

* fix client example

* i386 ci fix

* wip ci

* fix reading offset

* don't read if socket closed

* fix ci

* wip

* don't read if socket is closed

Co-authored-by: Arijit Das <arijit@status.im>
Co-authored-by: Arijit Das <arijitad.in@gmail.com>
2021-03-18 09:30:21 -06:00
Arijit Das a1ae7d2c70
[WIP] Web socket client implementation. (#2)
* Implement websocket server.

* Implement websocket client.

* Run nimpretty.

* Remove commented code.

* Address comments.

* Address comments on websocket server.

* Use seq[byte] to store data.

* Working bytes conversion.

* Remove result from return

* Refactor the code.

* Minor change.

* Add test.

* Add websocket test and fix closing handshake.

* Add MsgReader to read data in external buffer.
2021-03-10 21:34:14 -06:00