MOTION  0.01
Framework for mixed-protocol multi-party computation
sync_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 <mutex>
28 #include <vector>
29 
30 #include "message_handler.h"
31 
32 namespace encrypto::motion {
33 
34 class Logger;
35 
36 } // namespace encrypto::motion
37 
39 
41  public:
42  SynchronizationHandler(std::size_t my_id, std::size_t number_of_parties,
43  std::shared_ptr<Logger> logger)
44  : my_id_(my_id),
45  number_of_parties_(number_of_parties),
46  synchronization_states_(number_of_parties_, 0),
47  logger_(std::move(logger)) {}
48  std::uint64_t IncrementMySynchronizationState() { return ++synchronization_states_.at(my_id_); }
49  void ReceivedMessage(std::size_t party_id, std::vector<std::uint8_t>&& message) override;
50  void Wait();
51  std::mutex& GetMutex() { return this_party_mutex_; }
52 
53  private:
54  std::size_t my_id_;
55  std::size_t number_of_parties_;
56  std::mutex this_party_mutex_;
57  std::mutex received_synchronization_states_mutex_;
58  std::condition_variable synchronization_states_condition_variable_;
59  std::vector<std::uint64_t> synchronization_states_;
60  std::shared_ptr<Logger> logger_;
61 };
62 
63 } // namespace encrypto::motion::communication
sync_handler.h
encrypto::motion::communication::GetMessage
const encrypto::motion::communication::Message * GetMessage(const void *buf)
Definition: message_generated.h:146
encrypto::motion::communication::SynchronizationHandler
Definition: sync_handler.h:40
encrypto::motion::communication::SynchronizationHandler::IncrementMySynchronizationState
std::uint64_t IncrementMySynchronizationState()
Definition: sync_handler.h:48
logger.h
encrypto::motion
Definition: algorithm_description.cpp:35
encrypto::motion::communication::SynchronizationHandler::SynchronizationHandler
SynchronizationHandler(std::size_t my_id, std::size_t number_of_parties, std::shared_ptr< Logger > logger)
Definition: sync_handler.h:42
encrypto::motion::communication::MessageHandler
Definition: message_handler.h:38
message_handler.h
encrypto::motion::communication::SynchronizationHandler::GetMutex
std::mutex & GetMutex()
Definition: sync_handler.h:51
encrypto::motion::communication::SynchronizationHandler::Wait
void Wait()
Definition: sync_handler.cpp:63
encrypto::motion::communication::SynchronizationHandler::ReceivedMessage
void ReceivedMessage(std::size_t party_id, std::vector< std::uint8_t > &&message) override
Definition: sync_handler.cpp:32
encrypto::motion::communication
Definition: backend.h:37
message_generated.h