2 * Copyright (c) 2012-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@
24 #import <Foundation/Foundation.h>
25 #import <dispatch/queue.h>
28 #import "SOSCloudKeychainClient.h"
29 #import <utilities/debugging.h>
30 #import <Security/SecureObjectSync/SOSInternal.h>
33 kIDSStartPingTestMessage
= 1,
34 kIDSEndPingTestMessage
= 2,
35 kIDSSendOneMessage
= 3,
36 kIDSPeerReceivedACK
= 4,
37 kIDSPeerAvailability
= 6,
38 kIDSPeerAvailabilityDone
= 7,
39 kIDSKeychainSyncIDSFragmentation
= 8,
42 @interface KeychainSyncingOverIDSProxy
: NSObject
<IDSServiceDelegate
>
46 NSMutableDictionary
*deviceIDFromAuthToken
;
49 @
property (retain
, nonatomic
) NSMutableDictionary
*deviceIDFromAuthToken
;
50 @
property (retain
, nonatomic
) NSString
*deviceID
;
51 @
property (retain
, nonatomic
) NSMutableDictionary
*shadowPendingMessages
;
52 @
property (retain
, nonatomic
) NSMutableDictionary
*allFragmentedMessages
;
53 @
property (retain
, atomic
) NSMutableDictionary
*pingTimers
;
54 @
property (retain
, nonatomic
) NSMutableDictionary
*peerNextSendCache
; //dictionary of device ID -> time stamp of when to send next
56 // Only touch these three dictionaries from the dataQueue or you will crash, eventually.
57 @
property (retain
, nonatomic
) NSMutableDictionary
*messagesInFlight
;
58 @
property (retain
, nonatomic
) NSMutableDictionary
*unhandledMessageBuffer
;
59 @
property (retain
, nonatomic
) NSMutableDictionary
*monitor
;
60 @
property (atomic
) dispatch_source_t penaltyTimer
;
61 @
property (atomic
) bool penaltyTimerScheduled
;
62 @
property (retain
, atomic
) NSDictionary
*queuedMessages
;
64 @
property (retain
, atomic
) NSMutableDictionary
*counterValues
;
65 @
property (atomic
) NSInteger outgoingMessages
;
66 @
property (atomic
) NSInteger incomingMessages
;
72 @
property (atomic
) bool isIDSInitDone
;
73 @
property (atomic
) bool shadowDoInitializeIDSService
;
74 @
property (atomic
) bool isSecDRunningAsRoot
;
75 @
property (atomic
) bool doesSecDHavePeer
;
77 @
property (atomic
) dispatch_queue_t calloutQueue
;
78 @
property (atomic
) dispatch_queue_t pingQueue
;
79 @property dispatch_queue_t dataQueue
;
81 @
property (atomic
) bool isLocked
;
82 @
property (atomic
) bool unlockedSinceBoot
;
83 @
property (atomic
) dispatch_source_t retryTimer
;
84 @
property (atomic
) bool retryTimerScheduled
;
85 @
property (atomic
) bool inCallout
;
86 @
property (atomic
) bool setIDSDeviceID
;
87 @
property (atomic
) bool shadowDoSetIDSDeviceID
;
89 @
property (atomic
) bool handleAllPendingMessages
;
90 @
property (atomic
) bool shadowHandleAllPendingMessages
;
91 @
property (atomic
) bool sendRestoredMessages
;
92 @
property (atomic
) bool allowKVSFallBack
;
94 + (KeychainSyncingOverIDSProxy
*) idsProxy
;
98 - (void) doSetIDSDeviceID
;
99 - (void) doIDSInitialization
;
100 - (void) calloutWith
: (void(^)(NSMutableDictionary
*pending
,
101 bool handlePendingMesssages
,
103 dispatch_queue_t queue
,
104 void(^done
)(NSMutableDictionary
*handledMessages
,
105 bool handledPendingMessage
,
106 bool handledSettingDeviceID
))) callout
;
107 - (void) sendKeysCallout
: (NSMutableDictionary
*(^)(NSMutableDictionary
* pending
, NSError
** error
)) handleMessages
;
108 - (void) persistState
;
109 - (void) sendPersistedMessagesAgain
;
110 - (NSDictionary
*) retrievePendingMessages
;
111 - (NSDictionary
*) collectStats
;
112 - (void) scheduleRetryRequestTimer
;
113 - (BOOL
) haveMessagesInFlight
;
114 -(void) printMessage
:(NSDictionary
*) message state
:(NSString
*)state
;
118 NSString
* createErrorString(NSString
* format
, ...)
119 NS_FORMAT_FUNCTION(1, 2);