diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-29 17:23:22 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-29 17:23:22 +0200 |
| commit | 37effc3e136c73afd4d6ba37d23a91766795d0f7 (patch) | |
| tree | e5a1684231df52f48088dd053d57132d390e5a02 /libcmix-network/client.hpp | |
| parent | f7f0e8c53bc8231264346ef91e2f533164a25562 (diff) | |
| download | cmix-37effc3e136c73afd4d6ba37d23a91766795d0f7.tar.gz cmix-37effc3e136c73afd4d6ba37d23a91766795d0f7.tar.bz2 cmix-37effc3e136c73afd4d6ba37d23a91766795d0f7.zip | |
This changset triggered a storm of changes.
Added the behaviour for receiving a public_share message from our
previous node when not being the first node ourselves. This
triggered the whitespace bug below, which sparked the network
rewrite.
Rewrote network protocol to first send the size of the message it's
sending in a 32bit integer in network byte order.
Fixed a bug where whitespace in the received buffer would be skipped.
leading to broken protobuf messages.
NextNode no longers inherits from client but owns one, and some
functions needed to be forwarded.
Diffstat (limited to 'libcmix-network/client.hpp')
| -rw-r--r-- | libcmix-network/client.hpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/libcmix-network/client.hpp b/libcmix-network/client.hpp index 981283b..cb81418 100644 --- a/libcmix-network/client.hpp +++ b/libcmix-network/client.hpp @@ -31,24 +31,18 @@ protected: boost::asio::ip::tcp::socket socket; private: - /*! - * \brief buffer Internal private buffer used to receive messages. - */ boost::asio::streambuf buffer; - /*! - * \brief done The done function being called when this is done operating. - */ OnDoneFT done; + + std::vector<uint8_t> received_bytes_to_vector(size_t read_bytes); + + void handle_receive_size(MessageHandler message_handler, boost::system::error_code const& ec, size_t read_bytes); + + void handle_receive_message(MessageHandler message_handler, boost::system::error_code const& ec, size_t read_bytes); - /*! - * \brief handle_receive - * \param message_handler The function to call when a message has been received. - * \param ec A possible error that occured during receiving. - * \param read_bytes The number of bytes read. - */ - void handle_receive(MessageHandler message_handler, boost::system::error_code const& ec, size_t read_bytes); - + std::array<uint8_t, 4> prepare_length_prefix(uint32_t length); + public: /*! * \brief Client @@ -56,15 +50,23 @@ public: */ Client(boost::asio::ip::tcp::socket&& socket); + void async_connect(std::string next_host, std::string next_port, std::function<void()> on_connect); + + void send(std::string message); + /*! * \brief receive * \param message_handler The function to call when a message has been received. */ void receive(MessageHandler message_handler); + void close(); + /*! * \brief on_done sets the done callback. * \param f The new done callback function. */ void on_done(OnDoneFT f); + + }; |
