1 /*
2 * Copyright 2018 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, softwar
11 * e
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #include "fcp/secagg/client/secagg_client_alive_base_state.h"
19
20 #include <string>
21 #include <utility>
22
23 #include "fcp/secagg/client/secagg_client_aborted_state.h"
24 #include "fcp/secagg/client/secagg_client_state.h"
25 #include "fcp/secagg/client/send_to_server_interface.h"
26 #include "fcp/secagg/client/state_transition_listener_interface.h"
27 #include "fcp/secagg/shared/secagg_messages.pb.h"
28
29 namespace fcp {
30 namespace secagg {
31
SecAggClientAliveBaseState(std::unique_ptr<SendToServerInterface> sender,std::unique_ptr<StateTransitionListenerInterface> transition_listener,ClientState state,AsyncAbort * async_abort)32 SecAggClientAliveBaseState::SecAggClientAliveBaseState(
33 std::unique_ptr<SendToServerInterface> sender,
34 std::unique_ptr<StateTransitionListenerInterface> transition_listener,
35 ClientState state, AsyncAbort* async_abort)
36 : SecAggClientState(std::move(sender), std::move(transition_listener),
37 state),
38 async_abort_(async_abort) {}
39
Abort(const std::string & reason)40 StatusOr<std::unique_ptr<SecAggClientState> > SecAggClientAliveBaseState::Abort(
41 const std::string& reason) {
42 return AbortAndNotifyServer("Abort upon external request for reason <" +
43 reason + ">.");
44 }
45
46 std::unique_ptr<SecAggClientState>
AbortAndNotifyServer(const std::string & reason)47 SecAggClientAliveBaseState::AbortAndNotifyServer(const std::string& reason) {
48 ClientToServerWrapperMessage message_to_server;
49 message_to_server.mutable_abort()->set_diagnostic_info(reason);
50 sender_->Send(&message_to_server);
51 return std::make_unique<SecAggClientAbortedState>(
52 reason, std::move(sender_), std::move(transition_listener_));
53 }
54 } // namespace secagg
55 } // namespace fcp
56