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@
25 #import "TPPeerPermanentInfo.h"
26 #import "TPPeerStableInfo.h"
27 #import "TPPeerDynamicInfo.h"
33 @property (nonatomic, strong) TPPeerPermanentInfo* permanentInfo;
34 @property (nonatomic, strong) TPPeerStableInfo* stableInfo;
35 @property (nonatomic, strong) TPPeerDynamicInfo* dynamicInfo;
40 @implementation TPPeer
44 return self.permanentInfo.peerID;
47 - (instancetype)initWithPermanentInfo:(TPPeerPermanentInfo *)permanentInfo
51 _permanentInfo = permanentInfo;
56 - (TPResult)updateStableInfo:(TPPeerStableInfo *)stableInfo
58 if (![self.permanentInfo.trustSigningKey checkSignature:stableInfo.stableInfoSig
59 matchesData:stableInfo.stableInfoPList]) {
60 return TPResultSignatureMismatch;
62 if ([self.stableInfo isEqualToPeerStableInfo:stableInfo]) {
65 if (self.stableInfo != nil && stableInfo.clock <= self.stableInfo.clock) {
66 return TPResultClockViolation;
68 self.stableInfo = stableInfo;
72 - (TPResult)updateDynamicInfo:(TPPeerDynamicInfo *)dynamicInfo
74 if (![self.permanentInfo.trustSigningKey checkSignature:dynamicInfo.dynamicInfoSig
75 matchesData:dynamicInfo.dynamicInfoPList]) {
76 return TPResultSignatureMismatch;
78 if ([self.dynamicInfo isEqualToPeerDynamicInfo:dynamicInfo]) {
81 if (self.dynamicInfo != nil && dynamicInfo.clock <= self.dynamicInfo.clock) {
82 return TPResultClockViolation;
84 self.dynamicInfo = dynamicInfo;
89 - (void)setCircle:(TPCircle *)circle
92 NSAssert([circle.circleID isEqualToString:self.dynamicInfo.circleID],
93 @"circle property must match dynamicInfo.circleID");
98 - (NSSet<NSString*> *)trustedPeerIDs
100 if (self.dynamicInfo) {
101 NSAssert(self.circle, @"dynamicInfo needs corresponding circle");
102 return self.circle.includedPeerIDs;
104 return [NSSet setWithObject:self.peerID];