1 /*
2  * Copyright 2019 Google LLC.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     https://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PRIVATE_JOIN_AND_COMPUTE_PRIVATE_JOIN_AND_COMPUTE_RPC_IMPL_H_
17 #define PRIVATE_JOIN_AND_COMPUTE_PRIVATE_JOIN_AND_COMPUTE_RPC_IMPL_H_
18 
19 #include <memory>
20 #include <utility>
21 
22 #include "include/grpcpp/grpcpp.h"
23 #include "include/grpcpp/server_context.h"
24 #include "include/grpcpp/support/status.h"
25 #include "private_join_and_compute/private_join_and_compute.grpc.pb.h"
26 #include "private_join_and_compute/private_join_and_compute.pb.h"
27 #include "private_join_and_compute/protocol_server.h"
28 
29 namespace private_join_and_compute {
30 
31 // Implements the PrivateJoin and Compute RPC-handling Server.
32 class PrivateJoinAndComputeRpcImpl : public PrivateJoinAndComputeRpc::Service {
33  public:
34   // Takes as a parameter an implementation of the server actually implementing
35   // the steps of the protocol.
36   //
37   // Important note: This class will internally create a server message sink
38   // that accepts a SINGLE message in response to a Handle request, and fails
39   // with INVALID_ARGUMENT if more than one message is supplied. All supplied
40   // protocol_server_impls' Handle methods should therefore Send at most one
41   // message to the server_message_sink.
PrivateJoinAndComputeRpcImpl(std::unique_ptr<ProtocolServer> protocol_server_impl)42   explicit PrivateJoinAndComputeRpcImpl(
43       std::unique_ptr<ProtocolServer> protocol_server_impl)
44       : protocol_server_impl_(std::move(protocol_server_impl)) {}
45 
46   // Executes a round of the protocol.
47   ::grpc::Status Handle(::grpc::ServerContext* context,
48                         const ClientMessage* request,
49                         ServerMessage* response) override;
50 
protocol_finished()51   bool protocol_finished() {
52     return protocol_server_impl_->protocol_finished();
53   }
54 
55  private:
56   std::unique_ptr<ProtocolServer> protocol_server_impl_;
57 };
58 
59 }  // namespace private_join_and_compute
60 
61 #endif  // PRIVATE_JOIN_AND_COMPUTE_PRIVATE_JOIN_AND_COMPUTE_RPC_IMPL_H_
62