2 * Copyright (c) 2012-2014 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 @header SOSEngine.h - Manifest managent engine and decision making for
27 object syncing protocol.
30 #ifndef _SEC_SOSENGINE_H_
31 #define _SEC_SOSENGINE_H_
33 #include <SecureObjectSync/SOSDataSource.h>
34 #include <SecureObjectSync/SOSMessage.h>
35 #include <dispatch/dispatch.h>
40 kSOSEngineInvalidMessageError
= 1,
41 kSOSEngineInternalError
= 2,
44 typedef struct __OpaqueSOSPeer
*SOSPeerRef
;
46 typedef void (^SOSEnginePeerMessageSentBlock
)(bool success
);
49 void SOSEngineCircleChanged_locked(SOSEngineRef engine
, CFStringRef myPeerID
, CFArrayRef trustedPeers
, CFArrayRef untrustedPeers
);
52 // Return a new engine instance for a given data source.
53 SOSEngineRef
SOSEngineCreate(SOSDataSourceRef dataSource
, CFErrorRef
*error
);
55 // Return a snapshot of the current manifest of the engines data source.
56 SOSManifestRef
SOSEngineCopyManifest(SOSEngineRef engine
, CFErrorRef
*error
);
58 // Remove removals and add additions to the (cached) local manifest, and update all peers accordingly
59 bool SOSEngineUpdateLocalManifest(SOSEngineRef engine
, SOSDataSourceTransactionSource source
, struct SOSDigestVector
*removals
, struct SOSDigestVector
*additions
, CFErrorRef
*error
);
61 // Store manifest indexed by it's own digest. Can be retrieved with SOSEngineGetManifestForDigest()
62 void SOSEngineAddManifest(SOSEngineRef engine
, SOSManifestRef manifest
);
64 // Retrive a digest stored with SOSEngineAddManifest()
65 SOSManifestRef
SOSEngineGetManifestForDigest(SOSEngineRef engine
, CFDataRef digest
);
67 // Return the digest for a patched manifest (which is stored in the cache already).
68 CFDataRef
SOSEnginePatchRecordAndCopyDigest(SOSEngineRef engine
, SOSManifestRef base
, SOSManifestRef removals
, SOSManifestRef additions
, CFErrorRef
*error
);
71 bool SOSEngineSetCoderData(SOSEngineRef engine
, CFStringRef peer_id
, CFDataRef data
, CFErrorRef
*error
);
72 CFDataRef
SOSEngineGetCoderData(SOSEngineRef engine
, CFStringRef peer_id
);
75 CFMutableDictionaryRef
SOSEngineGetPeerState(SOSEngineRef engine
, CFStringRef peerID
);
77 // Dispose of an engine when it's no longer needed.
78 void SOSEngineDispose(SOSEngineRef engine
);
80 // Handle incoming message from a remote peer.
81 bool SOSEngineHandleMessage(SOSEngineRef engine
, CFStringRef peerID
,
82 CFDataRef message
, CFErrorRef
*error
);
84 void SOSEngineCircleChanged(SOSEngineRef engine
, CFStringRef myPeerID
, CFArrayRef trustedPeers
, CFArrayRef untrustedPeers
);
86 // Return a message to be sent for the current state. Returns NULL on errors,
87 // return a zero length CFDataRef if there is nothing to send.
88 // If *ProposedManifest is set the caller is responsible for updating their
89 // proposed manifest upon successful transmission of the message.
90 CFDataRef
SOSEngineCreateMessageToSyncToPeer(SOSEngineRef engine
, CFStringRef peerID
, SOSEnginePeerMessageSentBlock
*sentBlock
, CFErrorRef
*error
);
92 CFStringRef
SOSEngineGetMyID(SOSEngineRef engine
);
93 bool SOSEnginePeerDidConnect(SOSEngineRef engine
, CFStringRef peerID
, CFErrorRef
*error
);
95 void logRawMessage(CFDataRef message
, bool sending
, uint64_t seqno
);
97 // TODO: TEMPORARY: Get the list of IDs for cleanup, this shouldn't be used instead transport should iterate KVS.
98 CFArrayRef
SOSEngineGetPeerIDs(SOSEngineRef engine
);
102 #endif /* !_SEC_SOSENGINE_H_ */