Commit graph

58 commits

Author SHA1 Message Date
Jan Holesovsky
a2d457d778 nb: Abstract WebSocketHandler.
We don't need a special "WebSocket" class, as websocket itself is just an
upgrade of an existing socket / connection, and trying to come up with a
concept where a Socket class magically upgrades to a WebSocket class would be
messy.

So let's have just a WebSocketHandler, that communicates over a StreamSocket
or SslStreamSocket, and be done with that :-)

Change-Id: I449e4d662fbe2c5b1789e308053e4a71376fe481
2017-03-10 10:47:39 +01:00
Jan Holesovsky
18876119ad nb: SimpleResponseClient is a client, not a socket I guess.
Introduce the appropriate interface instead of the template, so that we can
de-couple the ResponseClient from the Socket itself.

Change-Id: I21892bbce5d83a18ca580a25cfc2efbb05b08705
2017-03-10 10:47:39 +01:00
Ashod Nakashian
69e4123173 nb: de-templatize ServerSocket
Change-Id: I5680bbf24ade807e34f67f7fce4698ffe5364cb2
2017-03-10 10:47:39 +01:00
Ashod Nakashian
9c595755ff nb: move SslStreamSocket to own file
Change-Id: I4b6f2b0b4be3fc595dfeafc8e2b6d3e73694bd49
2017-03-10 10:47:39 +01:00
Ashod Nakashian
18b131f30d nb: more consistent filenames
Change-Id: I2f1ff0b18080d469dc68b75ea0d7b9ddf5ea7d57
2017-03-10 10:47:39 +01:00
Ashod Nakashian
b72dd13cb0 nb: fixme for HTTP handling
Change-Id: I4364e2e4cd3233134c026890ce690abaf46b961d
2017-03-10 10:47:38 +01:00
Ashod Nakashian
fa97687485 nb: safer endianness conversion
Change-Id: I63977e6e99119fef2a61911d07d645a606d4c443
2017-03-10 10:47:38 +01:00
Michael Meeks
86185a2544 Restore plain HTTP, and add 'ssl' parameter to loolnb. 2017-03-10 10:47:38 +01:00
Ashod Nakashian
a8f5923214 nb: cleanup some logging
Change-Id: I28e211e5a727ea308824651f417a91d7b388a30d
Reviewed-on: https://gerrit.libreoffice.org/34452
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
1db8884f60 nb: support websocket payloads larger than 64kb
Change-Id: Ic21e11a70dae74b80ce3b1b604159ec14851972c
Reviewed-on: https://gerrit.libreoffice.org/34450
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
7a904d44bc nb: http request is consumed completely
Change-Id: I3525840deaf3ec95b8e74634ac36f22072bdf476
Reviewed-on: https://gerrit.libreoffice.org/34449
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
b6943b9c2a nb: server socket should accept only on POLLIN
Change-Id: I50e9a7f78e51bbf7e42e3eafde6e32d6538f5657
Reviewed-on: https://gerrit.libreoffice.org/34442
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
fe5545d591 nb: websocket echo test
The new test sends data of of 1 byte to
N bytes and expects the exact same data
returned in response.

This tests both buffering sizes and
websocket frames.

Change-Id: Ic6232b4e899d82d90a0ee7c96e4852ffaaf8e958
Reviewed-on: https://gerrit.libreoffice.org/34441
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
b4ab8f2014 nb: unmask only to the payload end
Change-Id: I511db5fea51ff8c623ca894f9d512749ef9f5a1b
Reviewed-on: https://gerrit.libreoffice.org/34424
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
9d95eec642 nb: support 64kb websocket messages
Change-Id: Id42efabb67137c737899adbe544cb0d2de08422a
Reviewed-on: https://gerrit.libreoffice.org/34423
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
4fbc754b4e nb: enable HTTPS in server
Change-Id: Ib0a4cb29f239bafe477ffab4194d3c91a588c384
2017-03-10 10:47:37 +01:00
Michael Meeks
bc8fca1ec0 WS: cleanup calculation, masking, short reads and other bits. 2017-03-10 10:47:37 +01:00
Ashod Nakashian
de10d8054c nb: SimpleResponseClient can now be an SSL or plain socket
Depending on the base class, which is passed as
template parameter, SimpleResponseClient can
abstract away the underlying socket type.

Change-Id: I59a403357512f329aa2565c1ef55094704e3b4ad
Reviewed-on: https://gerrit.libreoffice.org/34393
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
ff75e8fda2 nb: server can create any socket type on accept
Change-Id: I1a786421628500844277e6a2f1d2fd7b0ac0c3e4
Reviewed-on: https://gerrit.libreoffice.org/34392
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
477be66577 nb: support http and https in parallel
Change-Id: I35f55abc853e8797625bef1b0f60eeda127681b4
Reviewed-on: https://gerrit.libreoffice.org/34391
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
6a2cb967dc nb: use make_shared where possible
Change-Id: I7fb4e7086ac0ce86447db9de4c7ac77cdd7b40af
Reviewed-on: https://gerrit.libreoffice.org/34387
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
62c4828af6 nb: add OpenSSL dependency and initialization
Change-Id: I0d369acbc95db5d2b678032632ac4edfa561cbad
Reviewed-on: https://gerrit.libreoffice.org/34354
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
b5efc65cef nb: ClientSocket -> StreamSocket
StreamSocket has nothing Client-side specific.

Indeed it could be used on the Server-side.

As such, it's data-streaming, rather than client,
hence the new name.

Change-Id: I4e048def968b3a12e11edb49760ed03e3843ae6b
Reviewed-on: https://gerrit.libreoffice.org/34351
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Michael Meeks
3b0b31f5e2 WS: initial masking implementation & better parsing. 2017-03-10 10:47:37 +01:00
Michael Meeks
568569659b WS - basic handshake / upgrade and start of read framing. 2017-03-10 10:47:37 +01:00
Michael Meeks
b16ead036f More WS-ness. 2017-03-10 10:47:37 +01:00
Michael Meeks
d9ff82ce83 Websocket client test with WS=1 2017-03-10 10:47:37 +01:00
Michael Meeks
2f5d3e4412 Bang on the server with some threads. 2017-03-10 10:47:37 +01:00
Michael Meeks
a06fb365cb Get number response / ping bits working. 2017-03-10 10:47:36 +01:00
Michael Meeks
7a225dcbb3 Lean on Poco for request parsing. 2017-03-10 10:47:36 +01:00
Michael Meeks
d254899e74 Initial http header parsing pieces. 2017-03-10 10:47:36 +01:00
Michael Meeks
feb8192ec3 De-templatize and simplify. 2017-03-10 10:47:36 +01:00
Michael Meeks
0263078de7 Handle EOF - ie. zero length reads on sockets.
Close and cleanup sockets nicely.
2017-03-10 10:47:36 +01:00
Michael Meeks
92364f3ebf Implement basic buffering.
The socket now buffers input, and output, updates its poll record too.
We pass a simple message from client to server and back using lamers HTTP.
Sub-classed ClientSocket to provide a simple message handler.
   not very convinced by templatization here, but made it consistent.
   more ideal to have some virtual socket pieces.
2017-03-10 10:47:36 +01:00
Michael Meeks
257a79da89 Cleanup comments, naming related warnings etc.
Avoid using 'poll' as a member function, and a local variable.
Avoid using 'fd' as a member function, and a parameter.
Add assertions around wake pipe.
Always setup sockets for polling, strobing events is expected.
2017-03-10 10:47:36 +01:00
Ashod Nakashian
0a05a34f66 nb: move Socket family into own file
Change-Id: I17802f00a6e9e7d920b175b9721b158ea90a9880
Reviewed-on: https://gerrit.libreoffice.org/34238
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:36 +01:00
Ashod Nakashian
22b1ae9553 nb: separate Socket into ClientSocket and ServerSocket
Change-Id: I1aafd6192b955e51b8f1e74c1aad5fc3603f71d6
Reviewed-on: https://gerrit.libreoffice.org/34237
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:36 +01:00
Ashod Nakashian
b6b36f454b nb: refactor the client code into own function
Change-Id: I23735785cc4a66589fd81c7cb0f08476829ba7e8
Reviewed-on: https://gerrit.libreoffice.org/34236
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:36 +01:00
Ashod Nakashian
f41968a726 nb: refactor server code into own function
Change-Id: Iba7363df7452da271fcf9afb54ad1f6177260ddd
Reviewed-on: https://gerrit.libreoffice.org/34235
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:36 +01:00
Ashod Nakashian
10ab785fa4 nb: recreate the poll fds only when needed
Change-Id: I17accfb0339c590b7e155e8fd804e3e32c57e3ed
Reviewed-on: https://gerrit.libreoffice.org/34234
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:36 +01:00
Ashod Nakashian
5ed0c601e3 nb: poll wakeup pipe and simplified polling
Change-Id: I2e688b985d4a9bf7cbe8eef5df10f67bfc96f91c
Reviewed-on: https://gerrit.libreoffice.org/34233
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:36 +01:00
Ashod Nakashian
a8b2f982b6 nb: support N clients and asynchronously communicate with all
Change-Id: I81f63895180141e554072b6cf5300139299f282c
2017-03-10 10:47:36 +01:00
Ashod Nakashian
0edb2f6679 nb: poll using multi-socket poll class SocketPoll
Change-Id: If244c4ec92f70fd458665b88d4da3c5fbcb11077
2017-03-10 10:47:36 +01:00
Ashod Nakashian
f086079d25 nb: SocketPoll class to poll events on N-Sockets
Internally SocketPoll manages the sockets
and handles the polling and firing of callback.

It's thread-safe and handles asynchronous calls
to remove sockets correctly while potentially
being in poll(2).

The choice for using poll(2) compared to epoll
or select are the following:

1. For our use-case, poll(2) works great up to
   a few hundred sockets, which we don't expect
   to have on a single document normally.

2. select(2) has an awkward API (modifies input,
   f.e) and has limit on max fds that we need to
   be mindful of (even if we'll not hit it in
   practice). poll(2) preserves the input and has
   a no-nonsense API that's simple and readable.

3. While select(2) is the most portable, poll(2)
   isn't far behind. Yet in practice we'll probably
   not support other systems than Linux.

4. epoll(2) starts to scale with hundreds or
   thousands of sockets. Meanwhile, it has high
   overhead to adding/removing sockets (context
   switch to kernel and back). Our typical case
   will have a handful to a dozen sockets.
   Hardly a justification for epoll's heavy guns.

Change-Id: Idf88257ea85e061a37af29eed21e38655ff43c9b
2017-03-10 10:47:36 +01:00
Ashod Nakashian
e4563f7d42 nb: ping-pong messages between client and server
Change-Id: I3856dde09764075a138e8574520487e6e5accd90
2017-03-10 10:47:36 +01:00
Ashod Nakashian
85a398ad9c nb: Socket connect supports waiting with timeout
Change-Id: Ib2d713d68f3a27067b121adb356188a164da4589
2017-03-10 10:47:36 +01:00
Ashod Nakashian
976381f633 nb: server now accepts asynchronously
Change-Id: Ic98f31d4f432fc8a06690b94899314b7c9106c69
2017-03-10 10:47:36 +01:00
Ashod Nakashian
d9c88322e2 nb: connect and read asynchronously
Change-Id: I04733f8dbf06f5f31e6b05e7f017ef75c629a015
2017-03-10 10:47:36 +01:00
Ashod Nakashian
3e6ceda91b nb: add polling to Socket
Change-Id: Ie3fd1f271d9c6fa24e8583316e68a443489d1967
2017-03-10 10:47:36 +01:00
Ashod Nakashian
b772f8a860 nb: add socket error getter
Change-Id: Ia0dfd1d6e6bfd2b34b5a9b01c883d78f9bb15e7d
2017-03-10 10:47:36 +01:00