Browse Source

Fixed issues with KeyServerLookup management data, that was left null when a sessions was started before KeyServerLookup Thread. Now queue is a static object, and both retreive and examine functions fetch that object before enqueuing or dequeuing.

async_key_management
Edouard Tisserant 7 years ago
parent
commit
dbe438a7b3
6 changed files with 63 additions and 26 deletions
  1. +24
    -0
      iOSTests/iOSTests.m
  2. +2
    -0
      pEpiOSAdapter.xcodeproj/project.pbxproj
  3. +22
    -16
      pEpiOSAdapter/PEPQueue.m
  4. +1
    -0
      pEpiOSAdapter/PEPSession.m
  5. +0
    -4
      pEpiOSAdapter/PEPiOSAdapter.h
  6. +14
    -6
      pEpiOSAdapter/PEPiOSAdapter.m

+ 24
- 0
iOSTests/iOSTests.m View File

@ -72,6 +72,30 @@ PEPSession *session;
}
- (void)testLongKeyServerLookup {
[self pEpSetUp];
[PEPiOSAdapter startKeyserverLookup];
NSMutableDictionary *ident = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"pEpDontAssert", @"username",
@"vb@ulm.ccc.de", @"address",
@"SsI6H9", @"user_id",
nil];
[session updateIdentity:ident];
sleep(2);
[session updateIdentity:ident];
XCTAssert(ident[@"fpr"]);
[PEPiOSAdapter stopKeyserverLookup];
[self pEpCleanUp];
}
- (void)testTrustWords {
[self pEpSetUp];


+ 2
- 0
pEpiOSAdapter.xcodeproj/project.pbxproj View File

@ -180,6 +180,7 @@
64415E471BEA523300F6CBB2 /* C9C2EE39_sec.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = C9C2EE39_sec.asc; path = ../../pEpEngine/test/C9C2EE39_sec.asc; sourceTree = "<group>"; };
64415E571BF0EE1800F6CBB2 /* MCOAddress+PEPIdentity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MCOAddress+PEPIdentity.h"; sourceTree = "<group>"; };
64415E581BF0EE1800F6CBB2 /* MCOAddress+PEPIdentity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MCOAddress+PEPIdentity.m"; sourceTree = "<group>"; };
64415E5A1BF3840500F6CBB2 /* PEPIOSAdapter+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PEPIOSAdapter+Internal.h"; sourceTree = "<group>"; };
64DA24201B83323B000BEE80 /* mailcore2.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = mailcore2.xcodeproj; path = "../mailcore2/build-mac/mailcore2.xcodeproj"; sourceTree = "<group>"; };
64DA243B1B833248000BEE80 /* pEpEngine.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = pEpEngine.xcodeproj; path = "../pEpEngine/build-mac/pEpEngine.xcodeproj"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -244,6 +245,7 @@
350F0ED81B4E997300D9964F /* MCOAbstractMessage+PEPMessage.m */,
35EA58131B565643000B4CC5 /* PEPQueue.h */,
35EA58141B565643000B4CC5 /* PEPQueue.m */,
64415E5A1BF3840500F6CBB2 /* PEPIOSAdapter+Internal.h */,
);
path = pEpiOSAdapter;
sourceTree = "<group>";


+ 22
- 16
pEpiOSAdapter/PEPQueue.m View File

@ -33,14 +33,23 @@
- (void)enqueue:(id)object
{
[_cond lock];
if (_queue)
[_queue insertObject:object atIndex:0];
@synchronized(self) {
if (_queue)
[_queue insertObject:object atIndex:0];
}
[_cond signal];
[_cond unlock];
}
- (BOOL)condwait
{
BOOL res;
@synchronized(self) {
res = _queue && _queue.count == 0;
}
return res;
}
- (id)dequeue
@ -49,18 +58,19 @@
[_cond lock];
while (_queue && _queue.count == 0)
while ([self condwait])
{
[_cond wait];
}
if (_queue)
{
tmp = [_queue lastObject];
[_queue removeLastObject];
@synchronized(self) {
if (_queue)
{
tmp = [_queue lastObject];
[_queue removeLastObject];
}
}
[_cond unlock];
return tmp;
@ -68,13 +78,9 @@
- (void)kill
{
[_cond lock];
_queue = nil;
[_cond signal];
[_cond unlock];
}
- (NSUInteger)count


+ 1
- 0
pEpiOSAdapter/PEPSession.m View File

@ -8,6 +8,7 @@
#import "PEPSession.h"
#import "pEpiOSAdapter.h"
#import "PEPIOSAdapter+Internal.h"
#import "MCOAbstractMessage+PEPMessage.h"
@implementation PEPSession


+ 0
- 4
pEpiOSAdapter/PEPiOSAdapter.h View File

@ -19,8 +19,4 @@
+ (void)setupTrustWordsDB;
+ (void)setupTrustWordsDB:(NSBundle *)rootBundle;
// this message is for internal use only; do not call
+ (void)registerExamineFunction:(PEP_SESSION)session;
@end

+ 14
- 6
pEpiOSAdapter/PEPiOSAdapter.m View File

@ -9,15 +9,16 @@
@import Foundation;
#import "PEPiOSAdapter.h"
#import "PEPIOSAdapter+Internal.h"
#import "MCOAbstractMessage+PEPMessage.h"
#import "PEPQueue.h"
#include "keymanagement.h"
const char* _Nullable SystemDB = NULL;
int examine_identity(pEp_identity *ident, void *management)
{
PEPQueue *q = (__bridge PEPQueue *)management;
//PEPQueue *q = (__bridge PEPQueue *)management;
PEPQueue *q = [PEPiOSAdapter getQueue];
NSMutableDictionary *identity = [[NSMutableDictionary alloc] init];
PEP_identityFromStruct(identity, ident);
@ -28,7 +29,8 @@ int examine_identity(pEp_identity *ident, void *management)
static pEp_identity *retrieve_next_identity(void *management)
{
PEPQueue *q = (__bridge PEPQueue *)management;
//PEPQueue *q = (__bridge PEPQueue *)management;
PEPQueue *q = [PEPiOSAdapter getQueue];
// Dequeue is a blocking operation
// that returns nil when queue is killed
@ -101,8 +103,9 @@ static NSConditionLock *joinCond = nil;
+ (void)keyserverThread:(id)object
{
[joinCond lock];
do_keymanagement(retrieve_next_identity, (__bridge void *)queue);
// FIXME: do_KeyManagement asserts if management is null.
do_keymanagement(retrieve_next_identity, "NOTNULL" /* (__bridge void *)queue */);
// Set and signal join()
[joinCond unlockWithCondition:YES];
@ -142,7 +145,12 @@ static NSConditionLock *joinCond = nil;
+ (void)registerExamineFunction:(PEP_SESSION)session
{
register_examine_function(session, examine_identity, (__bridge void *)queue);
register_examine_function(session, examine_identity, NULL /* (__bridge void *)queue */);
}
+ (PEPQueue*)getQueue
{
return queue;
}
@end

Loading…
Cancel
Save