1 /* 2 * Copyright 2020 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 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef FCP_SECAGG_CLIENT_STATE_TRANSITION_LISTENER_INTERFACE_H_ 18 #define FCP_SECAGG_CLIENT_STATE_TRANSITION_LISTENER_INTERFACE_H_ 19 20 #include <cstdint> 21 22 namespace fcp { 23 namespace secagg { 24 25 enum class ClientState : int { 26 INITIAL = 0, 27 R0_ADVERTISE_KEYS = 1, 28 R1_SHARE_KEYS = 2, 29 R2_MASKED_INPUT = 3, 30 R3_UNMASKING = 4, 31 COMPLETED = 5, 32 ABORTED = 6, 33 }; 34 35 // Listens for state transition messages. 36 // 37 // The expected call pattern in the successful case is the following: 38 // - Transition(R0_ADVERTISE_KEYS) 39 // - Started(R0_ADVERTISE_KEYS) 40 // - Stopped(R0_ADVERTISE_KEYS) 41 // - Transition(R1_SHARE_KEYS) 42 // - Started(R1_SHARE_KEYS) 43 // - Stopped(R1_SHARE_KEYS) 44 // - Transition(R2_MASKED_INPUT) 45 // ... 46 // - Transition(COMPLETED) 47 // 48 // It is also possible to have more than one pair of Started and Stopped calls 49 // for any given state. 50 // 51 // If the protocol gets aborted at any point, Transition(ABORTED) would be 52 // called and any remaining Started and Stopped calls would be skipped. 53 class StateTransitionListenerInterface { 54 public: 55 // Called on transition to a new state. 56 virtual void Transition(ClientState new_state) = 0; 57 // Called just before a state starts computation, excluding any idle or 58 // waiting time. 59 virtual void Started(ClientState state) = 0; 60 // Called just after a state stops computation, excluding any idle or 61 // waiting time, or sending messages to to the server. 62 virtual void Stopped(ClientState state) = 0; 63 virtual void set_execution_session_id(int64_t execution_session_id) = 0; 64 65 virtual ~StateTransitionListenerInterface() = default; 66 }; 67 68 } // namespace secagg 69 } // namespace fcp 70 71 #endif // FCP_SECAGG_CLIENT_STATE_TRANSITION_LISTENER_INTERFACE_H_ 72