MOTION  0.01
Framework for mixed-protocol multi-party computation
output_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 
27 
28 namespace encrypto::motion {
29 
30 class Logger;
31 
32 // Handler for messages of type OutputMessage
34  public:
35  // Create a handler object for a given party
36  OutputMessageHandler(std::size_t party_id, std::shared_ptr<Logger> logger);
37 
38  // Register for an OutputMessage.
39  // Returns a future which can be used to wait for and retrieve the message.
41 
42  // Method which is called on received messages.
43  void ReceivedMessage(std::size_t, std::vector<std::uint8_t>&& message) override;
44 
45  private:
46  std::size_t party_id_;
47  std::shared_ptr<Logger> logger_;
48 
49  std::unordered_map<std::size_t, ReusableFiberPromise<std::vector<std::uint8_t>>>
50  output_message_promises_;
51  // synchronizes access to above map
52  std::mutex output_message_promises_mutex_;
53 };
54 
55 } // namespace encrypto::motion
encrypto::motion::OutputMessageHandler::OutputMessageHandler
OutputMessageHandler(std::size_t party_id, std::shared_ptr< Logger > logger)
Definition: output_message_handler.cpp:34
encrypto::motion::OutputMessageHandler::register_for_output_message
ReusableFiberFuture< std::vector< std::uint8_t > > register_for_output_message(std::size_t gate_id)
Definition: output_message_handler.cpp:37
output_message_generated.h
encrypto::motion::ReusableFuture
Definition: reusable_future.h:129
encrypto::motion::OutputMessageHandler
Definition: output_message_handler.h:33
encrypto::motion::OutputMessageHandler::ReceivedMessage
void ReceivedMessage(std::size_t, std::vector< std::uint8_t > &&message) override
Definition: output_message_handler.cpp:61
encrypto::motion::communication::GetMessage
const encrypto::motion::communication::Message * GetMessage(const void *buf)
Definition: message_generated.h:146
reusable_future.h
encrypto::motion::ReusablePromise::get_future
ReusableFuture< R, MutexType, ConditionVariableType > get_future()
Definition: reusable_future.h:242
encrypto::motion::communication::GetOutputMessage
const encrypto::motion::communication::OutputMessage * GetOutputMessage(const void *buf)
Definition: output_message_generated.h:136
logger.h
encrypto::motion
Definition: algorithm_description.cpp:35
encrypto::motion::communication::MessageHandler
Definition: message_handler.h:38
message_handler.h
encrypto::motion::kVerboseDebug
constexpr bool kVerboseDebug
Definition: constants.h:50
encrypto::motion::ReusablePromise
Definition: reusable_future.h:123
output_message_handler.h
constants.h
message_generated.h