1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 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 * http://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 FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_PUBLIC_MANAGER_H 17 #define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_PUBLIC_MANAGER_H 18 19 #include <map> 20 #include <mutex> 21 #include <vector> 22 #include <stdint.h> 23 #include "singleton.h" 24 25 namespace OHOS { 26 namespace EventFwk { 27 class PublishManager : public DelayedSingleton<PublishManager> { 28 public: 29 PublishManager(); 30 31 ~PublishManager(); 32 33 /** 34 * Checks for flood attacks. 35 * 36 * @param appUid Indicates the uid of the event sender. 37 * @return Returns true if success; false otherwise. 38 */ 39 bool CheckIsFloodAttack(pid_t appUid); 40 41 private: 42 std::mutex mutex_; 43 std::map<pid_t, std::vector<int64_t>> floodAttackAppStatistics_; 44 const uint32_t FLOOD_ATTACK_NUMBER_MAX = 20; // Frequency of decision 45 const int64_t FLOOD_ATTACK_INTERVAL_MAX = 5; // Period of decision (unit: millisecond) 46 }; 47 } // namespace EventFwk 48 } // namespace OHOS 49 50 #endif // FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_PUBLIC_MANAGER_H