xref: /aosp_15_r20/external/federated-compute/fcp/secagg/server/secagg_server_r0_advertise_keys_state.h (revision 14675a029014e728ec732f129a32e299b2da0601)
1 /*
2  * Copyright 2019 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_SERVER_SECAGG_SERVER_R0_ADVERTISE_KEYS_STATE_H_
18 #define FCP_SECAGG_SERVER_SECAGG_SERVER_R0_ADVERTISE_KEYS_STATE_H_
19 
20 #include <memory>
21 
22 #include "fcp/secagg/server/secagg_server_state.h"
23 
24 namespace fcp {
25 namespace secagg {
26 
27 // This class is the State for the SecAggServer when it is in the
28 // Round 0: Advertise state. The server begins in this state. This state
29 // collects public ECDH keys from clients, stores the one of them that will be
30 // used later in running the PRNG, and then sends to each client both public
31 // keys from each of its neighbors. It also computes and stores the session ID
32 // from the received keys, and sends the session ID to each client along with
33 // its neighbor's keys. This state should transition to Round 1: Share Keys, but
34 // might transition to Aborted if too many clients abort.
35 
36 class SecAggServerR0AdvertiseKeysState : public SecAggServerState {
37  public:
38   explicit SecAggServerR0AdvertiseKeysState(
39       std::unique_ptr<SecAggServerProtocolImpl> impl);
40 
41   ~SecAggServerR0AdvertiseKeysState() override;
42 
43   // Handles an advertise keys response or abort message from a client.
44   Status HandleMessage(uint32_t client_id,
45                        const ClientToServerWrapperMessage& message) override;
46 
47   bool IsNumberOfIncludedInputsCommitted() const override;
48 
49   int MinimumMessagesNeededForNextRound() const override;
50 
51   int NumberOfPendingClients() const override;
52 
53   StatusOr<std::unique_ptr<SecAggServerState> > ProceedToNextRound() override;
54 
55   // This will return true only after minimum_number_of_clients_to_proceed
56   // clients have sent messages (and not subsequently aborted).
57   bool ReadyForNextRound() const override;
58 
59  private:
60   void HandleAbortClient(uint32_t client_id,
61                          ClientDropReason reason_code) override;
62 };
63 
64 }  // namespace secagg
65 }  // namespace fcp
66 
67 #endif  // FCP_SECAGG_SERVER_SECAGG_SERVER_R0_ADVERTISE_KEYS_STATE_H_
68