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