2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 #import <Foundation/Foundation.h>
27 #import "CKKSOutgoingQueueEntry.h"
29 NS_ASSUME_NONNULL_BEGIN
31 @interface CKKSRateLimiter
: NSObject
<NSSecureCoding
>
33 @
property (readonly
) NSDictionary
* config
; // of NSString : NSNumber
36 * @brief Find out whether outgoing items are okay to send.
37 * @param entry The outgoing object being judged.
38 * @param time Current time.
39 * @param limitTime In case of badness, this will contain the time at which the object may be sent.
40 * @return Badness score from 0 (fine to send immediately) to 5 (overload, keep back), or -1 in case caller does not provide an NSDate object.
42 * judge:at: will set the limitTime object to nil in case of 0 badness. For badnesses 1-4 the time object will indicate when it is okay to send the entry.
43 * At badness 5 judge:at: has determined there is too much activity so the caller should hold off altogether. The limitTime object will indicate when
44 * this overloaded state will end.
46 - (int)judge
:(CKKSOutgoingQueueEntry
* const)entry
48 limitTime
:(NSDate
* _Nonnull __autoreleasing
* _Nonnull
)limitTime
;
51 - (instancetype _Nullable
)initWithCoder
:(NSCoder
* _Nullable
)coder NS_DESIGNATED_INITIALIZER
;
52 - (NSUInteger
)stateSize
;
54 - (NSString
*)diagnostics
;
56 + (BOOL
)supportsSecureCoding
;