Optimize, fix memory zeroing and refactor BinaryQueue 70/240670/6
authorMateusz Cegielka <m.cegielka@samsung.com>
Mon, 10 Aug 2020 11:24:35 +0000 (13:24 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 2 Sep 2020 08:54:48 +0000 (08:54 +0000)
commit39b2753ce5be83421d819cc0a60b9bda628291f7
tree716c81d4461c96eb451af85968253d3ded16cc0d
parent8e9da70e3c15bddc9831702dbd0e97dfe19d2790
Optimize, fix memory zeroing and refactor BinaryQueue

BinaryQueue is a class responsible for buffering data received from
sockets before deserialization, vendored from DPL. It stores the
received data as a list of blocks, which is probably the optimal
approach given the constraints of the services framework here. However,
its implementation is a little inefficient and incorrect:

- Stores data in std::vector<unsigned char> instead of RawBuffer.
  Because of that, any piece of data that passes through a socket may
  live in memory much longer than it should.
- Erases elements from the front of a std::vector. This means all the
  other elements need to be shifted, which could even result in
  quadratic complexity given large enough socket reads and small enough
  messages.
- Always copies incoming data. This means all of incoming traffic has to
  be copied one more time than it needs to.

I have fixed the first issue in the obvious way. To fix the second
issue, I have added a new member that tracks how many bytes have been
read from the first bucket in the queue, which makes physically erasing
elements from the vector unnecessary. Lastly, I changed the push
signature from taking a pointer and a size to taking a RawBuffer&&,
which eliminated some copies and made the remaining ones more explicit.

Change-Id: I36932d5492815e38bf1cdab249327d26c9805ac6
13 files changed:
misc/ckm_db_tool/db-wrapper.cpp
src/manager/client-async/service.cpp
src/manager/client/client-common.cpp
src/manager/common/message-buffer.cpp
src/manager/common/message-buffer.h
src/manager/crypto/sw-backend/store.cpp
src/manager/crypto/tz-backend/store.cpp
src/manager/dpl/core/include/dpl/binary_queue.h
src/manager/dpl/core/src/binary_queue.cpp
src/manager/main/thread-service.cpp
src/manager/service/encryption-service.cpp
unit-tests/test_binary-queue.cpp
unit-tests/test_serialization.cpp