MOTION  0.01
Framework for mixed-protocol multi-party computation
dummy_transport.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2020 Lennart Braun
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #pragma once
24 
25 #include "transport.h"
27 
29 
30 class DummyTransport : public Transport {
31  public:
32  // move constructor
34 
35  // create a pair of dummy transports which are connected to each other
36  static std::pair<std::unique_ptr<DummyTransport>, std::unique_ptr<DummyTransport>>
38 
39  // send a message
40  void SendMessage(std::vector<std::uint8_t>&& message) override;
41  void SendMessage(const std::vector<std::uint8_t>& message) override;
42 
43  // check if a new message is available
44  bool Available() const override;
45 
46  // receive message, possibly blocking
47  std::optional<std::vector<std::uint8_t>> ReceiveMessage() override;
48 
49  // shutdown the outgoing part of the transport to signal end of communication
50  void ShutdownSend() override;
51 
52  // shutdown this transport
53  void Shutdown() override;
54 
55  private:
57  DummyTransport(std::shared_ptr<MessageQueueType> send_queue,
58  std::shared_ptr<MessageQueueType> receive_queue) noexcept;
59 
60  std::shared_ptr<MessageQueueType> send_queue_;
61  std::shared_ptr<MessageQueueType> receive_queue_;
62 };
63 
64 } // namespace encrypto::motion::communication
encrypto::motion::communication::DummyTransport::SendMessage
void SendMessage(std::vector< std::uint8_t > &&message) override
Definition: dummy_transport.cpp:45
encrypto::motion::communication::TransportStatistics::number_of_messages_sent
std::size_t number_of_messages_sent
Definition: transport.h:33
encrypto::motion::communication::DummyTransport
Definition: dummy_transport.h:30
encrypto::motion::communication::DummyTransport::Shutdown
void Shutdown() override
Definition: dummy_transport.cpp:75
encrypto::motion::communication::DummyTransport::ReceiveMessage
std::optional< std::vector< std::uint8_t > > ReceiveMessage() override
Definition: dummy_transport.cpp:61
encrypto::motion::communication::DummyTransport::DummyTransport
DummyTransport(DummyTransport &&other)
Definition: dummy_transport.cpp:27
encrypto::motion::communication::Transport
Definition: transport.h:41
encrypto::motion::communication::TransportStatistics::number_of_messages_received
std::size_t number_of_messages_received
Definition: transport.h:34
encrypto::motion::communication::DummyTransport::MakeTransportPair
static std::pair< std::unique_ptr< DummyTransport >, std::unique_ptr< DummyTransport > > MakeTransportPair()
Definition: dummy_transport.cpp:37
transport.h
encrypto::motion::communication::DummyTransport::Available
bool Available() const override
Definition: dummy_transport.cpp:59
synchronized_queue.h
dummy_transport.h
encrypto::motion::communication::TransportStatistics::number_of_bytes_received
std::size_t number_of_bytes_received
Definition: transport.h:36
encrypto::motion::BasicSynchronizedQueue
Definition: synchronized_queue.h:57
encrypto::motion::communication
Definition: backend.h:37
encrypto::motion::communication::DummyTransport::ShutdownSend
void ShutdownSend() override
Definition: dummy_transport.cpp:73
encrypto::motion::communication::Transport::statistics_
TransportStatistics statistics_
Definition: transport.h:70
encrypto::motion::communication::TransportStatistics::number_of_bytes_sent
std::size_t number_of_bytes_sent
Definition: transport.h:35