MOTION  0.01
Framework for mixed-protocol multi-party computation
message_handler.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 <cstdint>
27 #include <vector>
28 
30 
32 
33 // Abstract interface for handling received messages
34 //
35 // An instance of MessageHandler can be registered with the CommunicationLayer
36 // for a given set of message types. Clients can either register a different
37 // handler object for each party or use the same for all parties.
39  public:
40  // virtual destructor to enable inheritance
41  virtual ~MessageHandler() = default;
42 
43  // Method which is called with received messages of the type the handler is
44  // registered for and the id of the sending party.
45  //
46  // This method may be called concurrently with different values of party_id.
47  // The client is responsible for the necessary synchronization.
48  virtual void ReceivedMessage(std::size_t party_id, std::vector<std::uint8_t>&& message) = 0;
49 };
50 
51 // Example message handler which puts received messages into a queue
52 class QueueHandler : public MessageHandler {
53  public:
54  void ReceivedMessage(std::size_t, std::vector<std::uint8_t>&& message) override {
55  messages_.enqueue(std::move(message));
56  };
57 
59 
60  private:
62 };
63 
64 } // namespace encrypto::motion::communication
encrypto::motion::communication::QueueHandler::ReceivedMessage
void ReceivedMessage(std::size_t, std::vector< std::uint8_t > &&message) override
Definition: message_handler.h:54
encrypto::motion::communication::MessageHandler::~MessageHandler
virtual ~MessageHandler()=default
synchronized_queue.h
encrypto::motion::communication::MessageHandler::ReceivedMessage
virtual void ReceivedMessage(std::size_t party_id, std::vector< std::uint8_t > &&message)=0
encrypto::motion::communication::QueueHandler
Definition: message_handler.h:52
encrypto::motion::communication::MessageHandler
Definition: message_handler.h:38
encrypto::motion::BasicSynchronizedQueue
Definition: synchronized_queue.h:57
encrypto::motion::communication
Definition: backend.h:37
encrypto::motion::communication::QueueHandler::GetQueue
SynchronizedQueue< std::vector< std::uint8_t > > & GetQueue()
Definition: message_handler.h:58