MOTION  0.01
Framework for mixed-protocol multi-party computation
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 <cstddef>
26 #include <optional>
27 #include <stdexcept>
28 #include <vector>
29 
31 
33  std::size_t number_of_messages_sent = 0;
34  std::size_t number_of_messages_received = 0;
35  std::size_t number_of_bytes_sent = 0;
36  std::size_t number_of_bytes_received = 0;
37 };
38 
39 // underlying transport between two parties
40 // e.g. a TCP/QUIC/.. connection, or a pair of local queues
41 class Transport {
42  public:
43  // default constructor
44  Transport() = default;
45  // move constructor
46  Transport(Transport&& other) = default;
47  // virtual destructor
48  virtual ~Transport() = default;
49 
50  // send a message
51  virtual void SendMessage(std::vector<std::uint8_t>&& message) = 0;
52  virtual void SendMessage(const std::vector<std::uint8_t>& message) = 0;
53 
54  // check if a new message is available
55  virtual bool Available() const = 0;
56 
57  // receive message, possibly blocking
58  virtual std::optional<std::vector<std::uint8_t>> ReceiveMessage() = 0;
59 
60  // shutdown the outgoing part of the transport to signal end of communication
61  virtual void ShutdownSend() = 0;
62 
63  // shutdown this transport
64  virtual void Shutdown() = 0;
65 
66  const TransportStatistics& GetStatistics() const;
67  void ResetStatistics();
68 
69  protected:
71 };
72 
73 } // namespace encrypto::motion::communication
encrypto::motion::communication::TransportStatistics::number_of_messages_sent
std::size_t number_of_messages_sent
Definition: transport.h:33
encrypto::motion::communication::Transport::ShutdownSend
virtual void ShutdownSend()=0
encrypto::motion::communication::Transport::Shutdown
virtual void Shutdown()=0
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::Transport::~Transport
virtual ~Transport()=default
transport.h
encrypto::motion::communication::Transport::ResetStatistics
void ResetStatistics()
Definition: transport.cpp:29
encrypto::motion::communication::Transport::ReceiveMessage
virtual std::optional< std::vector< std::uint8_t > > ReceiveMessage()=0
encrypto::motion::communication::TransportStatistics::number_of_bytes_received
std::size_t number_of_bytes_received
Definition: transport.h:36
encrypto::motion::communication::Transport::SendMessage
virtual void SendMessage(std::vector< std::uint8_t > &&message)=0
encrypto::motion::communication::Transport::Transport
Transport()=default
encrypto::motion::communication::Transport::GetStatistics
const TransportStatistics & GetStatistics() const
Definition: transport.cpp:27
encrypto::motion::communication
Definition: backend.h:37
encrypto::motion::communication::TransportStatistics
Definition: transport.h:32
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
encrypto::motion::communication::Transport::Available
virtual bool Available() const =0