diff --git a/.gitignore b/.gitignore index bfcccea..31925b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +telehash.xcodeproj/project.xcworkspace/xcshareddata/ + ######################### # .gitignore file for Xcode4 and Xcode5 Source projects # diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5ef76c1 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: objective-c +xcode_project: telehash.xcodeproj +xcode_scheme: telehashTests diff --git a/README.md b/README.md index 2b62a68..d265e6b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,25 @@ #Telehash for Objective-C# +## migration from v2 -> v3 progress + +TODO: + +* refactor THPath into THPipe, clean up transports +* update cs2a/cs3a encodings +* handle multiple handshakes to app callback +* rework e3x interface/abstraction to match the spec api +* reorg how the peer/connect works (only need send/receive, not relay to start) + +DONE: + +* renamed THCipherSet* to E3XCipherSet* +* renamed THChannel* to E3XChannel* +* renamed THLine to E3XExchange +* renamed THIdentity to THLink +* renamed THSwitch to THMesh +* removed THMeshBuckets, casualties of "seek" and "link" channel handlers + + Using with CocoaPods -------------------- diff --git a/Telehash Playground/Telehash Playground.xcodeproj/project.pbxproj b/Telehash Playground/Telehash Playground.xcodeproj/project.pbxproj index c96ae7c..91f1da0 100644 --- a/Telehash Playground/Telehash Playground.xcodeproj/project.pbxproj +++ b/Telehash Playground/Telehash Playground.xcodeproj/project.pbxproj @@ -406,7 +406,7 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, - "$(PROJECT_DIR)/../../**", + "$(PROJECT_DIR)/../**", ); INFOPLIST_FILE = "Telehash Playground/Telehash Playground-Info.plist"; LIBRARY_SEARCH_PATHS = ( @@ -433,7 +433,7 @@ HEADER_SEARCH_PATHS = ( "$(inherited)", /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, - "$(PROJECT_DIR)/../../**", + "$(PROJECT_DIR)/../**", ); INFOPLIST_FILE = "Telehash Playground/Telehash Playground-Info.plist"; LIBRARY_SEARCH_PATHS = ( diff --git a/Telehash Playground/Telehash Playground/THAppDelegate.h b/Telehash Playground/Telehash Playground/THAppDelegate.h index 4300a17..45e8aa6 100644 --- a/Telehash Playground/Telehash Playground/THAppDelegate.h +++ b/Telehash Playground/Telehash Playground/THAppDelegate.h @@ -7,8 +7,8 @@ // #import -#import -#import +#import +#import @interface THAppDelegate : NSObject { IBOutlet NSTableView* tableView; @@ -19,14 +19,14 @@ IBOutlet NSTextField* pathField; IBOutlet NSObjectController* objController; IBOutlet NSArrayController* channelArrayController; - THSwitch* thSwitch; + THMesh* thSwitch; } @property NSString* identityPath; @property (assign) IBOutlet NSWindow *window; --(void)channelReady:(THChannel *)channel type:(THChannelType)type firstPacket:(THPacket *)packet; --(BOOL)channel:(THChannel*)channel handlePacket:(THPacket *)packet; +-(void)channelReady:(E3XChannel *)channel type:(THChannelType)type firstPacket:(THPacket *)packet; +-(BOOL)channel:(E3XChannel*)channel handlePacket:(THPacket *)packet; -(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView; - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex; diff --git a/Telehash Playground/Telehash Playground/THAppDelegate.m b/Telehash Playground/Telehash Playground/THAppDelegate.m index baf09a6..ba2ff5f 100644 --- a/Telehash Playground/Telehash Playground/THAppDelegate.m +++ b/Telehash Playground/Telehash Playground/THAppDelegate.m @@ -7,17 +7,17 @@ // #import "THAppDelegate.h" -#import "THIdentity.h" +#import "THLink.h" #import -#import "THSwitch.h" -#import "THCipherSet.h" +#import "THMesh.h" +#import "E3XCipherSet.h" #import "NSData+HexString.h" #import "THTransport.h" #import "THPath.h" -#import "THChannel.h" -#import "THCipherSet2a.h" -#import "THCipherSet3a.h" -#import +#import "E3XChannel.h" +#import "E3XCipherSet2a.h" +#import "E3XCipherSet3a.h" +#import #import #include @@ -26,7 +26,7 @@ @interface THAppDelegate () { NSString* startChannelId; - THReliableChannel* pingChannel; + E3XReliableChannel* pingChannel; } @end @@ -45,26 +45,26 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification -(void)startSwitch:(id)sender { // Insert code here to initialize your application - thSwitch = [THSwitch defaultSwitch]; + thSwitch = [THMesh defaultSwitch]; thSwitch.delegate = self; - THIdentity* baseIdentity = [THIdentity new]; + THLink* baseIdentity = [THLink new]; self.identityPath = pathField.stringValue; - THCipherSet3a* cs3a = [[THCipherSet3a alloc] initWithPublicKeyPath:[NSString stringWithFormat:@"%@/server3.pkey", self.identityPath] privateKeyPath:[NSString stringWithFormat:@"%@/server3.key", self.identityPath]]; + E3XCipherSet3a* cs3a = [[E3XCipherSet3a alloc] initWithPublicKeyPath:[NSString stringWithFormat:@"%@/server3.pkey", self.identityPath] privateKeyPath:[NSString stringWithFormat:@"%@/server3.key", self.identityPath]]; if (!cs3a) { - cs3a = [THCipherSet3a new]; + cs3a = [E3XCipherSet3a new]; [cs3a generateKeys]; [cs3a savePublicKeyPath:[NSString stringWithFormat:@"%@/server3.pkey", self.identityPath] privateKeyPath:[NSString stringWithFormat:@"%@/server3.key", self.identityPath]]; } [baseIdentity addCipherSet:cs3a]; NSLog(@"3a fingerprint %@", [cs3a.fingerprint hexString]); - THCipherSet2a* cs2a = [[THCipherSet2a alloc] initWithPublicKeyPath:[NSString stringWithFormat:@"%@/server.pder", self.identityPath] privateKeyPath:[NSString stringWithFormat:@"%@/server.der", self.identityPath]]; + E3XCipherSet2a* cs2a = [[E3XCipherSet2a alloc] initWithPublicKeyPath:[NSString stringWithFormat:@"%@/server.pder", self.identityPath] privateKeyPath:[NSString stringWithFormat:@"%@/server.der", self.identityPath]]; if (!cs2a) { /* NSFileManager* fm = [NSFileManager defaultManager]; NSError* err; [fm createDirectoryAtPath:@"/tmp/telehash" withIntermediateDirectories:NO attributes:nil error:&err]; */ - cs2a = [THCipherSet2a new]; + cs2a = [E3XCipherSet2a new]; [cs2a generateKeys]; [cs2a.rsaKeys savePublicKey:[NSString stringWithFormat:@"%@/server.pder", self.identityPath] privateKey:[NSString stringWithFormat:@"%@/server.der", self.identityPath]]; } @@ -103,7 +103,7 @@ -(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView; - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex; { NSArray* keys = [thSwitch.openLines allKeys]; - THLine* line = [thSwitch.openLines objectForKey:[keys objectAtIndex:rowIndex]]; + E3XExchange* line = [thSwitch.openLines objectForKey:[keys objectAtIndex:rowIndex]]; return line.toIdentity.hashname; } @@ -114,7 +114,7 @@ -(void)tableViewSelectionDidChange:(NSNotification *)notification } NSArray* keys = [thSwitch.openLines allKeys]; - THLine* line = [thSwitch.openLines objectForKey:[keys objectAtIndex:tableView.selectedRow]]; + E3XExchange* line = [thSwitch.openLines objectForKey:[keys objectAtIndex:tableView.selectedRow]]; if (line) { objController.content = line; channelArrayController.content = line.toIdentity.channels.allValues; @@ -124,12 +124,12 @@ -(void)tableViewSelectionDidChange:(NSNotification *)notification } } --(void)openedLine:(THLine *)line; +-(void)openedLine:(E3XExchange *)line; { [tableView reloadData]; } --(void)channelReady:(THChannel *)channel type:(THChannelType)type firstPacket:(THPacket *)packet; +-(void)channelReady:(E3XChannel *)channel type:(THChannelType)type firstPacket:(THPacket *)packet; { NSLog(@"Channel is ready"); NSLog(@"First packet is %@", packet.json); @@ -142,7 +142,7 @@ -(void)channelReady:(THChannel *)channel type:(THChannelType)type firstPacket:(T -(IBAction)connectToHashname:(id)sender { - THIdentity* connectToIdentity; + THLink* connectToIdentity; NSString* key = [keyField stringValue]; if (key.length > 0) { /* @@ -155,16 +155,16 @@ -(IBAction)connectToHashname:(id)sender } */ } else { - connectToIdentity = [THIdentity identityFromHashname:[hashnameField stringValue]]; + connectToIdentity = [THLink identityFromHashname:[hashnameField stringValue]]; } if (connectToIdentity) { - [thSwitch openLine:connectToIdentity completion:^(THIdentity* openIdentity) { + [thSwitch openLine:connectToIdentity completion:^(THLink* openIdentity) { NSLog(@"We're in the app and connected to %@", connectToIdentity.hashname); }]; } } --(void)thSwitch:(THSwitch *)inSwitch status:(THSwitchStatus)status +-(void)thSwitch:(THMesh *)inSwitch status:(THSwitchStatus)status { NSLog(@"Switch status is now %d", status); if (status == THSwitchOnline && !pingChannel) { @@ -183,12 +183,12 @@ -(void)thSwitch:(THSwitch *)inSwitch status:(THSwitchStatus)status } } --(void)channel:(THChannel *)channel didFailWithError:(NSError *)error +-(void)channel:(E3XChannel *)channel didFailWithError:(NSError *)error { NSLog(@"Got an error: %@", error); } --(BOOL)channel:(THChannel *)channel handlePacket:(THPacket *)packet +-(BOOL)channel:(E3XChannel *)channel handlePacket:(THPacket *)packet { NSLog(@"Handling packet on channel %@ (%@): %@", channel.channelId, channel.type, packet.json); if ([channel.type isEqualToString:@"ping"]) { diff --git a/common/THChannel.h b/common/E3XChannel.h similarity index 70% rename from common/THChannel.h rename to common/E3XChannel.h index 86b249c..bffb7ba 100644 --- a/common/THChannel.h +++ b/common/E3XChannel.h @@ -8,12 +8,12 @@ #import #import "ECDH.h" -#import "THLine.h" +#import "E3XExchange.h" @class THPacket; -@class THIdentity; -@class THChannel; -@class THLine; +@class THLink; +@class E3XChannel; +@class E3XExchange; @class THPacketBuffer; typedef enum { @@ -31,19 +31,19 @@ typedef enum { @protocol THChannelDelegate #pragma mark State Handling --(void)channel:(THChannel*)channel didChangeStateTo:(THChannelState)channelState; +-(void)channel:(E3XChannel*)channel didChangeStateTo:(THChannelState)channelState; #pragma mark Error Handling --(void)channel:(THChannel*)channel didFailWithError:(NSError*)error; --(BOOL)channel:(THChannel*)channel handlePacket:(THPacket*)packet; +-(void)channel:(E3XChannel*)channel didFailWithError:(NSError*)error; +-(BOOL)channel:(E3XChannel*)channel handlePacket:(THPacket*)packet; @end -@interface THChannel : NSObject +@interface E3XChannel : NSObject @property NSNumber* maxSeen; @property NSArray* missing; @property (nonatomic, strong) id delegate; -@property THIdentity* toIdentity; -@property THLine* line; +@property THLink* toIdentity; +@property E3XExchange* line; @property NSNumber* channelId; @property THChannelState state; @property THChannelDirection direction; @@ -52,7 +52,7 @@ typedef enum { @property NSUInteger lastInActivity; @property NSUInteger lastOutActivity; --(id)initToIdentity:(THIdentity*)identity; +-(id)initToIdentity:(THLink*)identity; -(void)sendPacket:(THPacket*)packet; -(void)handlePacket:(THPacket*)packet; -(void)close; diff --git a/common/THChannel.m b/common/E3XChannel.m similarity index 91% rename from common/THChannel.m rename to common/E3XChannel.m index 49975dc..c53ef98 100644 --- a/common/THChannel.m +++ b/common/E3XChannel.m @@ -6,23 +6,23 @@ // Copyright (c) 2013 Telehash Foundation. All rights reserved. // -#import "THChannel.h" +#import "E3XChannel.h" #import "THPacket.h" -#import "THIdentity.h" +#import "THLink.h" #import "RNG.h" #import "NSData+HexString.h" #import "SHA256.h" -#import "THSwitch.h" +#import "THMesh.h" #import "CTRAES256.h" -#import "THLine.h" +#import "E3XExchange.h" #import "THPacketBuffer.h" -@implementation THChannel +@implementation E3XChannel { THChannelState _state; } --(id)initToIdentity:(THIdentity*)identity +-(id)initToIdentity:(THLink*)identity { self = [super init]; if (self) { @@ -33,7 +33,7 @@ -(id)initToIdentity:(THIdentity*)identity self.createdAt = time(NULL); self.lastInActivity = 0; self.lastOutActivity = 0; - THSwitch* defaultSwitch = [THSwitch defaultSwitch]; + THMesh* defaultSwitch = [THMesh defaultSwitch]; self.line = [defaultSwitch lineToHashname:self.toIdentity.hashname]; } return self; diff --git a/common/THCipherSet.h b/common/E3XCipherSet.h similarity index 58% rename from common/THCipherSet.h rename to common/E3XCipherSet.h index e58d907..358ca39 100644 --- a/common/THCipherSet.h +++ b/common/E3XCipherSet.h @@ -9,23 +9,23 @@ #import @class THPacket; -@class THSwitch; -@class THLine; -@class THIdentity; +@class THMesh; +@class E3XExchange; +@class THLink; -@interface THCipherSet : NSObject +@interface E3XCipherSet : NSObject @property (readonly) NSData* fingerprint; @property (readonly) NSData* publicKey; -+(THCipherSet*)cipherSetForOpen:(THPacket*)openPacket; --(THLine*)processOpen:(THPacket*)openPacket; --(void)finalizeLineKeys:(THLine*)line; --(THPacket*)generateOpen:(THLine*)line from:(THIdentity*)fromIdentity; ++(E3XCipherSet*)cipherSetForOpen:(THPacket*)openPacket; +-(E3XExchange*)processOpen:(THPacket*)openPacket; +-(void)finalizeLineKeys:(E3XExchange*)line; +-(THPacket*)generateOpen:(E3XExchange*)line from:(THLink*)fromIdentity; -(void)generateKeys; -(NSString*)identifier; @end @interface THCipherSetLineInfo : NSObject -@property THCipherSet* cipherSet; +@property E3XCipherSet* cipherSet; -(NSData*)encryptLinePacket:(THPacket*)packet; -(void)decryptLinePacket:(THPacket*)packet; @end diff --git a/common/THCipherSet.m b/common/E3XCipherSet.m similarity index 69% rename from common/THCipherSet.m rename to common/E3XCipherSet.m index 222604a..06cd1ba 100644 --- a/common/THCipherSet.m +++ b/common/E3XCipherSet.m @@ -6,29 +6,29 @@ // Copyright (c) 2014 Telehash Foundation. All rights reserved. // -#import "THCipherSet.h" +#import "E3XCipherSet.h" #import "THPacket.h" -#import "THIdentity.h" -#import "THLine.h" -#import "THCipherSet2a.h" -#import "THCipherSet3a.h" +#import "THLink.h" +#import "E3XExchange.h" +#import "E3XCipherSet2a.h" +#import "E3XCipherSet3a.h" #import "CLCLog.h" -@implementation THCipherSet -+(THCipherSet*)cipherSetForOpen:(THPacket *)openPacket +@implementation E3XCipherSet ++(E3XCipherSet*)cipherSetForOpen:(THPacket *)openPacket { unsigned char* bytes = (unsigned char*)openPacket.body.bytes; switch (bytes[0]) { case 0x2a: - return [THCipherSet2a new]; + return [E3XCipherSet2a new]; case 0x3a: - return [THCipherSet3a new]; + return [E3XCipherSet3a new]; default: return nil; } } --(THLine*)processOpen:(THPacket*)openPacket switch:(THSwitch*)thSwitch +-(E3XExchange*)processOpen:(THPacket*)openPacket switch:(THMesh*)thSwitch { CLCLogError(@"Not implemented"); return nil; @@ -40,7 +40,7 @@ -(NSString*)identifier return nil; } --(void)finalizeLineKeys:(THLine *)line +-(void)finalizeLineKeys:(E3XExchange *)line { CLCLogError(@"Not implemented THCipherSet finalizeKeys"); } diff --git a/common/THCipherSet2a.h b/common/E3XCipherSet2a.h similarity index 74% rename from common/THCipherSet2a.h rename to common/E3XCipherSet2a.h index 5110d6f..a58e7ac 100644 --- a/common/THCipherSet2a.h +++ b/common/E3XCipherSet2a.h @@ -6,19 +6,19 @@ // Copyright (c) 2014 Telehash Foundation. All rights reserved. // -#import "THCipherSet.h" +#import "E3XCipherSet.h" @class ECDH; @class RSA; -@interface THCipherSet2a : THCipherSet +@interface E3XCipherSet2a : E3XCipherSet @property (retain) RSA* rsaKeys; -(void)generateKeys; -(id)initWithPublicKeyPath:(NSString*)publicKeyPath privateKeyPath:(NSString*)privateKeyPath; -(id)initWithPublicKey:(NSData *)publicKey privateKey:(NSData *)privateKey; --(THLine*)processOpen:(THPacket*)openPacket; --(void)finalizeLineKeys:(THLine*)line; --(THPacket*)generateOpen:(THLine*)line from:(THIdentity*)fromIdentity; +-(E3XExchange*)processOpen:(THPacket*)openPacket; +-(void)finalizeLineKeys:(E3XExchange*)line; +-(THPacket*)generateOpen:(E3XExchange*)line from:(THLink*)fromIdentity; @end @interface THCipherSetLineInfo2a : THCipherSetLineInfo diff --git a/common/THCipherSet2a.m b/common/E3XCipherSet2a.m similarity index 94% rename from common/THCipherSet2a.m rename to common/E3XCipherSet2a.m index 9af78f2..e317d12 100644 --- a/common/THCipherSet2a.m +++ b/common/E3XCipherSet2a.m @@ -6,15 +6,14 @@ // Copyright (c) 2014 Telehash Foundation. All rights reserved. // -#import "THCipherSet2a.h" +#import "E3XCipherSet2a.h" #import "THPacket.h" -#import "THIdentity.h" -#import "THSwitch.h" +#import "THLink.h" +#import "THMesh.h" #import "SHA256.h" #import "GCMAES256.h" #import "NSString+HexString.h" -#import "THLine.h" -#import "THMeshBuckets.h" +#import "E3XExchange.h" #import "THPendingJob.h" #import "ECDH.h" #import "RNG.h" @@ -61,7 +60,7 @@ -(void)decryptLinePacket:(THPacket*)packet } @end -@implementation THCipherSet2a +@implementation E3XCipherSet2a -(NSString*)identifier { return @"2a"; @@ -77,7 +76,7 @@ -(NSData *)publicKey return self.rsaKeys.DERPublicKey; } --(THLine*)processOpen:(THPacket *)openPacket +-(E3XExchange*)processOpen:(THPacket *)openPacket { // Process an open packet NSData* remoteECCKey = [self.rsaKeys decrypt:[openPacket.body subdataWithRange:NSMakeRange(1, 256)]]; @@ -106,7 +105,7 @@ -(THLine*)processOpen:(THPacket *)openPacket return nil; } - THCipherSet2a* incomingCS = [[THCipherSet2a alloc] initWithPublicKey:innerPacket.body privateKey:nil]; + E3XCipherSet2a* incomingCS = [[E3XCipherSet2a alloc] initWithPublicKey:innerPacket.body privateKey:nil]; if (!incomingCS) { CLCLogInfo(@"Unable to create cipher set for incoming key."); return nil; @@ -116,7 +115,7 @@ -(THLine*)processOpen:(THPacket *)openPacket CLCLogInfo(@"Unable to verify the incoming key fingerprint"); return nil; } - THIdentity* senderIdentity = [THIdentity identityFromParts:[innerPacket.json objectForKey:@"from"] key:incomingCS]; + THLink* senderIdentity = [THLink identityFromParts:[innerPacket.json objectForKey:@"from"] key:incomingCS]; if (!senderIdentity) { CLCLogInfo(@"Unable to validate and verify identity"); return nil; @@ -163,7 +162,7 @@ -(THLine*)processOpen:(THPacket *)openPacket [senderIdentity closeChannels]; } - THLine* newLine = senderIdentity.currentLine; + E3XExchange* newLine = senderIdentity.currentLine; if (newLine) { // This is a partially opened line @@ -173,7 +172,7 @@ -(THLine*)processOpen:(THPacket *)openPacket // TODO temas review //newLine.cipherSetInfo = lineInfo; //?? } else { - newLine = [THLine new]; + newLine = [E3XExchange new]; newLine.toIdentity = senderIdentity; senderIdentity.currentLine = newLine; @@ -188,7 +187,7 @@ -(THLine*)processOpen:(THPacket *)openPacket return newLine; } --(void)finalizeLineKeys:(THLine*)line +-(void)finalizeLineKeys:(E3XExchange*)line { THCipherSetLineInfo2a* lineInfo = (THCipherSetLineInfo2a*)line.cipherSetInfo; // Make sure we have a valid ECDH context @@ -213,7 +212,7 @@ -(void)finalizeLineKeys:(THLine*)line lineInfo.encryptorKey = [SHA256 hashWithData:keyingMaterial]; } --(THPacket*)generateOpen:(THLine*)line from:(THIdentity*)fromIdentity +-(THPacket*)generateOpen:(E3XExchange*)line from:(THLink*)fromIdentity { if (!line.cipherSetInfo) { // FIXME, should be the remote cipherSet @@ -222,7 +221,7 @@ -(THPacket*)generateOpen:(THLine*)line from:(THIdentity*)fromIdentity line.cipherSetInfo = lineInfo; } THCipherSetLineInfo2a* lineInfo = (THCipherSetLineInfo2a*)line.cipherSetInfo; - THCipherSet2a* remoteCS = (THCipherSet2a*)lineInfo.cipherSet; + E3XCipherSet2a* remoteCS = (E3XCipherSet2a*)lineInfo.cipherSet; THPacket* openPacket = [THPacket new]; if (!lineInfo.ecdh) { @@ -241,7 +240,7 @@ -(THPacket*)generateOpen:(THLine*)line from:(THIdentity*)fromIdentity [innerPacket.json setObject:[NSNumber numberWithInteger:at] forKey:@"at"]; NSMutableDictionary* fingerprints = [NSMutableDictionary dictionaryWithCapacity:fromIdentity.cipherParts.count]; for (NSString* csId in fromIdentity.cipherParts) { - THCipherSet* cipherSet = [fromIdentity.cipherParts objectForKey:csId]; + E3XCipherSet* cipherSet = [fromIdentity.cipherParts objectForKey:csId]; [fingerprints setObject:[cipherSet.fingerprint hexString] forKey:csId]; } [innerPacket.json setObject:fingerprints forKey:@"from"]; diff --git a/common/THCipherSet3a.h b/common/E3XCipherSet3a.h similarity index 92% rename from common/THCipherSet3a.h rename to common/E3XCipherSet3a.h index 31b0488..baf0f5d 100644 --- a/common/THCipherSet3a.h +++ b/common/E3XCipherSet3a.h @@ -6,10 +6,10 @@ // Copyright (c) 2014 Telehash Foundation. All rights reserved. // -#import "THCipherSet.h" +#import "E3XCipherSet.h" #include -@interface THCipherSet3a : THCipherSet +@interface E3XCipherSet3a : E3XCipherSet { uint8_t publicKey[crypto_box_PUBLICKEYBYTES]; uint8_t secretKey[crypto_box_SECRETKEYBYTES]; diff --git a/common/THCipherSet3a.m b/common/E3XCipherSet3a.m similarity index 94% rename from common/THCipherSet3a.m rename to common/E3XCipherSet3a.m index e986323..0bb3350 100644 --- a/common/THCipherSet3a.m +++ b/common/E3XCipherSet3a.m @@ -6,12 +6,12 @@ // Copyright (c) 2014 Telehash Foundation. All rights reserved. // -#import "THCipherSet3a.h" +#import "E3XCipherSet3a.h" #import "THPacket.h" #import "SHA256.h" #import "NSData+HexString.h" -#import "THIdentity.h" -#import "THLine.h" +#import "THLink.h" +#import "E3XExchange.h" #import "NSString+HexString.h" #import "RNG.h" #import "CLCLog.h" @@ -19,7 +19,7 @@ static unsigned char csId3a[1] = {0x3a}; static uint8_t nonce3a[crypto_secretbox_NONCEBYTES] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; -@implementation THCipherSet3a +@implementation E3XCipherSet3a -(NSString*)identifier { return @"3a"; @@ -68,7 +68,7 @@ -(NSData*)fingerprint return [SHA256 hashWithData:[NSData dataWithBytesNoCopy:publicKey length:crypto_box_PUBLICKEYBYTES freeWhenDone:NO]]; } --(THLine*)processOpen:(THPacket*)openPacket; +-(E3XExchange*)processOpen:(THPacket*)openPacket; { // Process an open packet NSData* pubLineKey = [openPacket.body subdataWithRange:NSMakeRange(crypto_onetimeauth_BYTES + 1, crypto_box_PUBLICKEYBYTES)]; @@ -91,7 +91,7 @@ -(THLine*)processOpen:(THPacket*)openPacket; } innerPacket.returnPath = openPacket.returnPath; - THCipherSet3a* incomingCS = [[THCipherSet3a alloc] initWithPublicKey:innerPacket.body privateKey:nil]; + E3XCipherSet3a* incomingCS = [[E3XCipherSet3a alloc] initWithPublicKey:innerPacket.body privateKey:nil]; if (!incomingCS) { CLCLogInfo(@"Unable to create cipher set for incoming key."); return nil; @@ -113,7 +113,7 @@ -(THLine*)processOpen:(THPacket*)openPacket; return nil; } - THIdentity* senderIdentity = [THIdentity identityFromParts:[innerPacket.json objectForKey:@"from"] key:incomingCS]; + THLink* senderIdentity = [THLink identityFromParts:[innerPacket.json objectForKey:@"from"] key:incomingCS]; if (!senderIdentity) { CLCLogInfo(@"Unable to validate and verify identity"); return nil; @@ -138,13 +138,13 @@ -(THLine*)processOpen:(THPacket*)openPacket; [senderIdentity closeChannels]; } - THLine* newLine = senderIdentity.currentLine; + E3XExchange* newLine = senderIdentity.currentLine; if (newLine) { // This is a partially opened line THCipherSetLineInfo3a* lineInfo = (THCipherSetLineInfo3a*)newLine.cipherSetInfo; lineInfo.remoteLineKey = pubLineKey; } else { - newLine = [THLine new]; + newLine = [E3XExchange new]; newLine.toIdentity = senderIdentity; senderIdentity.currentLine = newLine; @@ -160,7 +160,7 @@ -(THLine*)processOpen:(THPacket*)openPacket; } --(void)finalizeLineKeys:(THLine*)line +-(void)finalizeLineKeys:(E3XExchange*)line { THCipherSetLineInfo3a* lineInfo = (THCipherSetLineInfo3a*)line.cipherSetInfo; @@ -181,7 +181,7 @@ -(void)finalizeLineKeys:(THLine*)line //CLCLogDebug(@"Encryptor key %@", lineInfo.encryptorKey); } --(THPacket*)generateOpen:(THLine*)line from:(THIdentity*)fromIdentity +-(THPacket*)generateOpen:(E3XExchange*)line from:(THLink*)fromIdentity { if (!line.cipherSetInfo) { THCipherSetLineInfo3a* lineInfo = [THCipherSetLineInfo3a new]; @@ -189,7 +189,7 @@ -(THPacket*)generateOpen:(THLine*)line from:(THIdentity*)fromIdentity line.cipherSetInfo = lineInfo; } THCipherSetLineInfo3a* lineInfo = (THCipherSetLineInfo3a*)line.cipherSetInfo; - THCipherSet3a* remoteCS = (THCipherSet3a*)lineInfo.cipherSet; + E3XCipherSet3a* remoteCS = (E3XCipherSet3a*)lineInfo.cipherSet; THPacket* innerPacket = [THPacket new]; [innerPacket.json setObject:line.toIdentity.hashname forKey:@"to"]; @@ -199,7 +199,7 @@ -(THPacket*)generateOpen:(THLine*)line from:(THIdentity*)fromIdentity [innerPacket.json setObject:[NSNumber numberWithInteger:at] forKey:@"at"]; NSMutableDictionary* fingerprints = [NSMutableDictionary dictionaryWithCapacity:fromIdentity.cipherParts.count]; for (NSString* csId in fromIdentity.cipherParts) { - THCipherSet* cipherSet = [fromIdentity.cipherParts objectForKey:csId]; + E3XCipherSet* cipherSet = [fromIdentity.cipherParts objectForKey:csId]; [fingerprints setObject:[cipherSet.fingerprint hexString] forKey:csId]; } [innerPacket.json setObject:fingerprints forKey:@"from"]; diff --git a/common/THLine.h b/common/E3XExchange.h similarity index 86% rename from common/THLine.h rename to common/E3XExchange.h index a4183e8..a96d790 100644 --- a/common/THLine.h +++ b/common/E3XExchange.h @@ -7,18 +7,18 @@ // #import -#import "THIdentity.h" -#import "THSwitch.h" -#import "THChannel.h" +#import "THLink.h" +#import "THMesh.h" +#import "E3XChannel.h" @class THPacket; -@class THChannel; +@class E3XChannel; @class THCipherSetLineInfo; @class THPath; -@interface THLine : NSObject +@interface E3XExchange : NSObject -@property THIdentity* toIdentity; +@property THLink* toIdentity; @property THCipherSetLineInfo* cipherSetInfo; @property THPacket* cachedOpen; diff --git a/common/THLine.m b/common/E3XExchange.m similarity index 78% rename from common/THLine.m rename to common/E3XExchange.m index 0ce20fc..05e6ebc 100644 --- a/common/THLine.m +++ b/common/E3XExchange.m @@ -7,35 +7,34 @@ // Copyright (c) 2013 Telehash Foundation. All rights reserved. // -#import "THLine.h" +#import "E3XExchange.h" #import "THPacket.h" #import "RNG.h" #import "NSData+HexString.h" #import "SHA256.h" -#import "THIdentity.h" +#import "THLink.h" #import "THRSA.h" -#import "THSwitch.h" +#import "THMesh.h" #import "CTRAES256.h" #import "NSString+HexString.h" -#import "THChannel.h" -#import "THMeshBuckets.h" -#import "THCipherSet.h" +#import "E3XChannel.h" +#import "E3XCipherSet.h" #import "THPeerRelay.h" #import "THPath.h" -#import "THCipherSet2a.h" -#import "THUnreliableChannel.h" -#import "THReliableChannel.h" +#import "E3XCipherSet2a.h" +#import "E3XUnreliableChannel.h" +#import "E3XReliableChannel.h" #import "CLCLog.h" -#import "THCipherSet3a.h" +#import "E3XCipherSet3a.h" #import "THRelay.h" #include @interface THPathHandler : NSObject -@property THLine* line; +@property E3XExchange* line; @end -@implementation THLine +@implementation E3XExchange { NSUInteger _nextChannelId; NSMutableArray* channelHandlers; @@ -56,7 +55,7 @@ -(void)sendOpen; { self.lastOutActivity = time(NULL); - THSwitch* defaultSwitch = [THSwitch defaultSwitch]; + THMesh* defaultSwitch = [THMesh defaultSwitch]; if (!self.cachedOpen) { self.cachedOpen = [defaultSwitch generateOpen:self]; @@ -88,7 +87,7 @@ -(NSUInteger)nextChannelId -(void)openLine; { // Do the distance calc and see if we start at 1 or 2 - THSwitch* thSwitch = [THSwitch defaultSwitch]; + THMesh* thSwitch = [THMesh defaultSwitch]; if ([self.toIdentity.hashname compare:thSwitch.identity.hashname] == NSOrderedAscending) { _nextChannelId = 1; } else { @@ -97,8 +96,8 @@ -(void)openLine; [self.cipherSetInfo.cipherSet finalizeLineKeys:self]; [self.toIdentity.channels enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { // Get all our pending reliable channels spun out - if ([obj class] != [THReliableChannel class]) return; - THReliableChannel* channel = (THReliableChannel*)obj; + if ([obj class] != [E3XReliableChannel class]) return; + E3XReliableChannel* channel = (E3XReliableChannel*)obj; // If the channel already thinks it's good, we'll just ignore it's state if (channel.state == THChannelOpen) return; @@ -132,58 +131,17 @@ -(void)handlePacket:(THPacket *)packet; } NSString* channelType = [innerPacket.json objectForKey:@"type"]; - THSwitch* thSwitch = [THSwitch defaultSwitch]; + THMesh* thSwitch = [THMesh defaultSwitch]; // if the switch is handling it bail if ([thSwitch findPendingSeek:innerPacket]) return; - THChannel* channel = [self.toIdentity.channels objectForKey:channelId]; + E3XChannel* channel = [self.toIdentity.channels objectForKey:channelId]; - if ([channelType isEqualToString:@"seek"]) { - // On a seek we send back what we know about - THPacket* response = [THPacket new]; - [response.json setObject:@(YES) forKey:@"end"]; - [response.json setObject:channelId forKey:@"c"]; - THSwitch* defaultSwitch = [THSwitch defaultSwitch]; - - THIdentity* identity = [THIdentity identityFromHashname:[innerPacket.json objectForKey:@"seek"]]; - NSArray* seeIdentities = [defaultSwitch.meshBuckets closeInBucket:identity]; - NSMutableArray* sees = [NSMutableArray array]; - - if (seeIdentities != nil) { - for (THIdentity* seeIdentity in seeIdentities) { - NSString* seekString = [seeIdentity seekStringForIdentity:identity]; - if (seekString) { - [sees addObject:seekString]; - } - } - } - - [response.json setObject:sees forKey:@"see"]; - - [self sendPacket:response]; - } else if ([channelType isEqualToString:@"link"] && !channel) { - THSwitch* defaultSwitch = [THSwitch defaultSwitch]; - - [defaultSwitch.meshBuckets addIdentity:self.toIdentity]; - - THUnreliableChannel* linkChannel = [[THUnreliableChannel alloc] initToIdentity:self.toIdentity]; - linkChannel.channelId = [innerPacket.json objectForKey:@"c"]; - linkChannel.type = @"link"; - linkChannel.delegate = defaultSwitch.meshBuckets; - linkChannel.lastInActivity = time(NULL); - linkChannel.direction = THChannelInbound; - - THUnreliableChannel* curChannel = (THUnreliableChannel*)[self.toIdentity channelForType:@"link"]; - if (curChannel) { - [self.toIdentity.channels removeObjectForKey:curChannel.channelId]; - } - [defaultSwitch openChannel:linkChannel firstPacket:nil]; - [defaultSwitch.meshBuckets channel:linkChannel handlePacket:innerPacket]; - } else if ([channelType isEqualToString:@"peer"]) { + if ([channelType isEqualToString:@"peer"]) { // TODO: Check this logic in association with the move to channels on identity CLCLogInfo(@"peer request to %@", [innerPacket.json objectForKey:@"peer"]); - THLine* peerLine = [thSwitch lineToHashname:[innerPacket.json objectForKey:@"peer"]]; + E3XExchange* peerLine = [thSwitch lineToHashname:[innerPacket.json objectForKey:@"peer"]]; if (!peerLine) { CLCLogWarning(@"unable to establish line for peer request"); // What? We don't know about this person, bye bye @@ -203,9 +161,9 @@ -(void)handlePacket:(THPacket *)packet; // TODO dan review this flow THPeerRelay* relay = [THPeerRelay new]; - THUnreliableChannel* connectChannel = [[THUnreliableChannel alloc] initToIdentity:peerLine.toIdentity]; + E3XUnreliableChannel* connectChannel = [[E3XUnreliableChannel alloc] initToIdentity:peerLine.toIdentity]; connectChannel.delegate = relay; - THUnreliableChannel* peerChannel = [[THUnreliableChannel alloc] initToIdentity:self.toIdentity]; + E3XUnreliableChannel* peerChannel = [[E3XUnreliableChannel alloc] initToIdentity:self.toIdentity]; peerChannel.channelId = [innerPacket.json objectForKey:@"c"]; peerChannel.delegate = relay; [thSwitch openChannel:peerChannel firstPacket:nil]; @@ -220,13 +178,13 @@ -(void)handlePacket:(THPacket *)packet; // TODO: XXX Can this become a function? is it a generic pattern? NSDictionary* fromParts = [innerPacket.json objectForKey:@"from"]; NSString* highestPart = [[fromParts.allKeys sortedArrayUsingSelector:@selector(compare:)] lastObject]; - THCipherSet* cs; + E3XCipherSet* cs; if ([highestPart isEqualToString:@"3a"]) { - cs = [[THCipherSet3a alloc] initWithPublicKey:innerPacket.body privateKey:nil]; + cs = [[E3XCipherSet3a alloc] initWithPublicKey:innerPacket.body privateKey:nil]; } else if ([highestPart isEqualToString:@"2a"]) { - cs = [[THCipherSet2a alloc] initWithPublicKey:innerPacket.body privateKey:nil]; + cs = [[E3XCipherSet2a alloc] initWithPublicKey:innerPacket.body privateKey:nil]; } - THIdentity* peerIdentity = [THIdentity identityFromParts:fromParts key:cs]; + THLink* peerIdentity = [THLink identityFromParts:fromParts key:cs]; if (!peerIdentity) { // We couldn't verify the identity, so shut it down THPacket* closePacket = [THPacket new]; @@ -273,7 +231,7 @@ -(void)handlePacket:(THPacket *)packet; [peerIdentity addPath:packet.returnPath]; } - THUnreliableChannel* peerChannel = [[THUnreliableChannel alloc] initToIdentity:self.toIdentity]; + E3XUnreliableChannel* peerChannel = [[E3XUnreliableChannel alloc] initToIdentity:self.toIdentity]; peerChannel.channelId = [innerPacket.json objectForKey:@"c"]; peerChannel.type = @"connect"; [thSwitch openChannel:peerChannel firstPacket:nil]; @@ -296,7 +254,7 @@ -(void)handlePacket:(THPacket *)packet; if (channel) { if (seq) { // This is a reliable channel, let's make sure we're in a good state - THReliableChannel* reliableChannel = (THReliableChannel*)channel; + E3XReliableChannel* reliableChannel = (E3XReliableChannel*)channel; if (seq.unsignedIntegerValue == 0 && [[innerPacket.json objectForKey:@"ack"] unsignedIntegerValue] == 0) { reliableChannel.state = THChannelOpen; } @@ -319,13 +277,13 @@ -(void)handlePacket:(THPacket *)packet; return; } - THChannel* newChannel; + E3XChannel* newChannel; THChannelType newChannelType; if (seq && [seq unsignedIntegerValue] == 0) { - newChannel = [[THReliableChannel alloc] initToIdentity:self.toIdentity]; + newChannel = [[E3XReliableChannel alloc] initToIdentity:self.toIdentity]; newChannelType = ReliableChannel; } else { - newChannel = [[THUnreliableChannel alloc] initToIdentity:self.toIdentity]; + newChannel = [[E3XUnreliableChannel alloc] initToIdentity:self.toIdentity]; newChannelType = UnreliableChannel; } @@ -334,7 +292,7 @@ -(void)handlePacket:(THPacket *)packet; newChannel.direction = THChannelInbound; newChannel.type = channelType; - THSwitch* defaultSwitch = [THSwitch defaultSwitch]; + THMesh* defaultSwitch = [THMesh defaultSwitch]; [self.toIdentity.channels setObject:newChannel forKey:channelId]; [newChannel handlePacket:innerPacket]; @@ -384,7 +342,7 @@ -(void)sendPacket:(THPacket *)packet path:(THPath*)path [self.toIdentity.relay sendPacket:lineOutPacket]; } else { CLCLogWarning(@"no path or relay available on line to %@, attempting a re-open", self.toIdentity.hashname); - [[THSwitch defaultSwitch] openLine:self.toIdentity]; + [[THMesh defaultSwitch] openLine:self.toIdentity]; //TODO: we need to pause the channel and buffer before we actually get here... } @@ -397,12 +355,12 @@ -(void)sendPacket:(THPacket *)packet; -(void)close { - [[THSwitch defaultSwitch] closeLine:self]; + [[THMesh defaultSwitch] closeLine:self]; } -(void)negotiatePath { - THSwitch* thSwitch = [THSwitch defaultSwitch]; + THMesh* thSwitch = [THMesh defaultSwitch]; THPacket* pathPacket = [THPacket new]; [pathPacket.json setObject:[thSwitch.identity pathInformationTo:self.toIdentity allowLocal:YES] forKey:@"paths"]; @@ -413,7 +371,7 @@ -(void)negotiatePath THPathHandler* handler = [THPathHandler new]; handler.line = self; - THUnreliableChannel* pathChannel = [[THUnreliableChannel alloc] initToIdentity:self.toIdentity]; + E3XUnreliableChannel* pathChannel = [[E3XUnreliableChannel alloc] initToIdentity:self.toIdentity]; pathChannel.delegate = handler; [thSwitch openChannel:pathChannel firstPacket:pathPacket]; @@ -437,7 +395,7 @@ -(void)removeChannelHandler:(id)handler -(void)handlePath:(THPacket*)packet { - THSwitch* thSwitch = [THSwitch defaultSwitch]; + THMesh* thSwitch = [THMesh defaultSwitch]; // Add the given paths to the identity NSArray* offeredPaths = [packet.json objectForKey:@"paths"]; @@ -480,9 +438,9 @@ -(void)handlePath:(THPacket*)packet @implementation THPathHandler --(BOOL)channel:(THChannel *)channel handlePacket:(THPacket *)packet +-(BOOL)channel:(E3XChannel *)channel handlePacket:(THPacket *)packet { - THSwitch* thSwitch = [THSwitch defaultSwitch]; + THMesh* thSwitch = [THMesh defaultSwitch]; NSDictionary* returnPath = [packet.json objectForKey:@"path"]; // See if our switch has this identity, we can learn our public IP this way @@ -511,11 +469,11 @@ -(BOOL)channel:(THChannel *)channel handlePacket:(THPacket *)packet return YES; } --(void)channel:(THChannel *)channel didChangeStateTo:(THChannelState)channelState +-(void)channel:(E3XChannel *)channel didChangeStateTo:(THChannelState)channelState { } --(void)channel:(THChannel *)channel didFailWithError:(NSError *)error +-(void)channel:(E3XChannel *)channel didFailWithError:(NSError *)error { } diff --git a/common/THReliableChannel.h b/common/E3XReliableChannel.h similarity index 81% rename from common/THReliableChannel.h rename to common/E3XReliableChannel.h index 0b73210..223f56c 100644 --- a/common/THReliableChannel.h +++ b/common/E3XReliableChannel.h @@ -6,9 +6,9 @@ // Copyright (c) 2014 Telehash Foundation. All rights reserved. // -#import "THChannel.h" +#import "E3XChannel.h" -@interface THReliableChannel : THChannel { +@interface E3XReliableChannel : E3XChannel { NSUInteger sequence; NSMutableOrderedSet* inBuffer; THPacketBuffer* inPacketBuffer; @@ -17,7 +17,7 @@ NSUInteger lastProcessed; } @property NSUInteger nextExpectedSequence; --(id)initToIdentity:(THIdentity*)identity; +-(id)initToIdentity:(THLink*)identity; -(void)handlePacket:(THPacket*)packet; -(void)sendPacket:(THPacket*)packet; -(void)flushOut; diff --git a/common/THReliableChannel.m b/common/E3XReliableChannel.m similarity index 97% rename from common/THReliableChannel.m rename to common/E3XReliableChannel.m index 9fad6d6..dd57820 100644 --- a/common/THReliableChannel.m +++ b/common/E3XReliableChannel.m @@ -6,7 +6,7 @@ // Copyright (c) 2014 Telehash Foundation. All rights reserved. // -#import "THReliableChannel.h" +#import "E3XReliableChannel.h" #import "THPacketBuffer.h" #import "THPacket.h" #import "CLCLog.h" @@ -14,15 +14,15 @@ //#define FUZZY_LOSS YES -@interface THReliableChannel() { +@interface E3XReliableChannel() { NSArray* missing; } -(void)checkAckPing:(NSUInteger)packetTime; -(void)delegateHandlePackets; @end -@implementation THReliableChannel --(id)initToIdentity:(THIdentity *)identity; +@implementation E3XReliableChannel +-(id)initToIdentity:(THLink *)identity; { self = [super initToIdentity:identity]; if (self) { diff --git a/common/THUnreliableChannel.h b/common/E3XUnreliableChannel.h similarity index 78% rename from common/THUnreliableChannel.h rename to common/E3XUnreliableChannel.h index 81898ba..9b00e67 100644 --- a/common/THUnreliableChannel.h +++ b/common/E3XUnreliableChannel.h @@ -6,9 +6,9 @@ // Copyright (c) 2014 Telehash Foundation. All rights reserved. // -#import "THChannel.h" +#import "E3XChannel.h" -@interface THUnreliableChannel : THChannel +@interface E3XUnreliableChannel : E3XChannel -(void)handlePacket:(THPacket *)packet; -(void)sendPacket:(THPacket *)packet; @end diff --git a/common/THUnreliableChannel.m b/common/E3XUnreliableChannel.m similarity index 95% rename from common/THUnreliableChannel.m rename to common/E3XUnreliableChannel.m index d4b0858..06e4c53 100644 --- a/common/THUnreliableChannel.m +++ b/common/E3XUnreliableChannel.m @@ -6,11 +6,11 @@ // Copyright (c) 2014 Telehash Foundation. All rights reserved. // -#import "THUnreliableChannel.h" +#import "E3XUnreliableChannel.h" #import "THPacket.h" #import "CLCLog.h" -@implementation THUnreliableChannel +@implementation E3XUnreliableChannel { NSMutableArray* packetBuffer; THChannelState _state; @@ -21,7 +21,7 @@ -(void)dealloc CLCLogDebug(@"gone for unreliable %@", self.channelId); } --(id)initToIdentity:(THIdentity *)identity; +-(id)initToIdentity:(THLink *)identity; { self = [super initToIdentity:identity]; return self; diff --git a/common/THIdentity.h b/common/THLink.h similarity index 69% rename from common/THIdentity.h rename to common/THLink.h index 1ee1e41..d234e25 100644 --- a/common/THIdentity.h +++ b/common/THLink.h @@ -10,19 +10,19 @@ #import "THRSA.h" @class THPacket; -@class THLine; -@class THChannel; -@class THCipherSet; +@class E3XExchange; +@class E3XChannel; +@class E3XCipherSet; @class THPath; @class THRelay; -@interface THIdentity : NSObject +@interface THLink : NSObject -+(id)identityFromParts:(NSDictionary*)parts key:(THCipherSet*)key; ++(id)identityFromParts:(NSDictionary*)parts key:(E3XCipherSet*)key; +(id)identityFromHashname:(NSString*)hashname; -(id)initWithHashname:(NSString*)hashname; --(id)initWithParts:(NSDictionary*)parts key:(THCipherSet*)key; +-(id)initWithParts:(NSDictionary*)parts key:(E3XCipherSet*)key; @property (readonly) NSString* hashname; @property (readonly) BOOL hasLink; @@ -31,7 +31,7 @@ @property NSData* address; @property NSMutableArray* vias; @property NSMutableDictionary* channels; -@property THLine* currentLine; +@property E3XExchange* currentLine; @property NSDictionary* cipherParts; @property NSDictionary* parts; @property NSMutableArray* availablePaths; @@ -41,25 +41,25 @@ @property THRelay* relay; @property NSArray* availableBridges; --(void)addCipherSet:(THCipherSet*)cipherSet; +-(void)addCipherSet:(E3XCipherSet*)cipherSet; -(void)addPath:(THPath*)path; -(void)checkPriorityPath:(THPath*)path; --(void)addVia:(THIdentity*)viaIdentity; +-(void)addVia:(THLink*)viaIdentity; -(void)attachSeedVias; // TODO: Method to create a channel for a type --(NSInteger)distanceFrom:(THIdentity*)identity; +-(NSInteger)distanceFrom:(THLink*)identity; -(void)setIP:(NSString*)ip port:(NSUInteger)port; -(void)sendPacket:(THPacket*)packet; -(void)sendPacket:(THPacket*)packet path:(THPath*)path; -(NSString*)seekString; --(NSString*)seekStringForIdentity:(THIdentity*)identity; +-(NSString*)seekStringForIdentity:(THLink*)identity; --(THChannel*)channelForType:(NSString*)type; +-(E3XChannel*)channelForType:(NSString*)type; --(NSArray*)pathInformationTo:(THIdentity *)toIdentity allowLocal:(BOOL)allowLocal; +-(NSArray*)pathInformationTo:(THLink *)toIdentity allowLocal:(BOOL)allowLocal; -(THPath*)pathMatching:(NSDictionary*)pathInfo; +(NSString*)hashnameForParts:(NSDictionary*)parts; diff --git a/common/THIdentity.m b/common/THLink.m similarity index 86% rename from common/THIdentity.m rename to common/THLink.m index e1ed6f2..dc04dde 100644 --- a/common/THIdentity.m +++ b/common/THLink.m @@ -6,16 +6,16 @@ // Copyright (c) 2013 Telehash Foundation. All rights reserved. // -#import "THIdentity.h" +#import "THLink.h" #import "SHA256.h" #import "NSData+HexString.h" #import "NSString+HexString.h" #import "THPacket.h" -#import "THLine.h" -#import "THSwitch.h" -#import "THChannel.h" +#import "E3XExchange.h" +#import "THMesh.h" +#import "E3XChannel.h" #import "CTRAES256.h" -#import "THCipherSet.h" +#import "E3XCipherSet.h" #import "THPath.h" #import "CLCLog.h" #import "THRelay.h" @@ -23,25 +23,25 @@ static NSMutableDictionary* identityCache; -@interface THIdentity() { +@interface THLink() { NSString* _hashnameCache; } @end -@implementation THIdentity +@implementation THLink + (void)initialize { - if (self == [THIdentity self]) { + if (self == [THLink self]) { identityCache = [NSMutableDictionary dictionary]; } } -+(id)identityFromParts:(NSDictionary *)parts key:(THCipherSet*)cs ++(id)identityFromParts:(NSDictionary *)parts key:(E3XCipherSet*)cs { - THIdentity* identity = [identityCache objectForKey:[THIdentity hashnameForParts:parts]]; + THLink* identity = [identityCache objectForKey:[THLink hashnameForParts:parts]]; if (!identity) { // Load the parts and validate the key - identity = [[THIdentity alloc] initWithParts:parts key:cs]; + identity = [[THLink alloc] initWithParts:parts key:cs]; if (identity) [identityCache setObject:identity forKey:identity.hashname]; } else { // Let's make sure we get it set @@ -54,9 +54,9 @@ +(id)identityFromParts:(NSDictionary *)parts key:(THCipherSet*)cs +(id)identityFromHashname:(NSString *)hashname; { - THIdentity* identity = [identityCache objectForKey:hashname]; + THLink* identity = [identityCache objectForKey:hashname]; if (!identity) { - identity = [[THIdentity alloc] initWithHashname:hashname]; + identity = [[THLink alloc] initWithHashname:hashname]; if (identity) [identityCache setObject:identity forKey:hashname]; } @@ -70,7 +70,7 @@ -(id)init return self; } --(id)initWithParts:(NSDictionary *)parts key:(THCipherSet*)cs +-(id)initWithParts:(NSDictionary *)parts key:(E3XCipherSet*)cs { self = [super init]; if (self) { @@ -121,14 +121,14 @@ -(void)setIP:(NSString*)ip port:(NSUInteger)port; -(NSString*)hashname; { if (!_hashnameCache) { - _hashnameCache = [THIdentity hashnameForParts:self.parts]; + _hashnameCache = [THLink hashnameForParts:self.parts]; } return _hashnameCache; } -(BOOL)hasLink { - THChannel* linkChannel = [self channelForType:@"link"]; + E3XChannel* linkChannel = [self channelForType:@"link"]; if (linkChannel) return YES; return NO; @@ -142,7 +142,7 @@ int nlz(unsigned long x) { return 3; } --(NSInteger)distanceFrom:(THIdentity *)identity; +-(NSInteger)distanceFrom:(THLink *)identity; { NSData* ourHashname = [self.hashname dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO]; const char* ourHashBytes = (const char*)[ourHashname bytes]; @@ -167,7 +167,7 @@ -(NSInteger)distanceFrom:(THIdentity *)identity; -(void)sendPacket:(THPacket *)packet path:(THPath*)path { if (!self.currentLine) { - [[THSwitch defaultSwitch] openLine:self completion:^(THIdentity* lineIdentity) { + [[THMesh defaultSwitch] openLine:self completion:^(THLink* lineIdentity) { [self.currentLine sendPacket:packet path:path]; }]; } else { @@ -180,11 +180,11 @@ -(void)sendPacket:(THPacket *)packet [self sendPacket:packet path:nil]; } --(THChannel*)channelForType:(NSString *)type +-(E3XChannel*)channelForType:(NSString *)type { - __block THChannel* foundChannel = nil; + __block E3XChannel* foundChannel = nil; [self.channels enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - THChannel* channel = (THChannel*)obj; + E3XChannel* channel = (E3XChannel*)obj; if ([channel.type isEqualToString:type]) { foundChannel = channel; *stop = YES; @@ -206,7 +206,7 @@ -(NSString*)seekString } } --(NSString*)seekStringForIdentity:(THIdentity*)identity +-(NSString*)seekStringForIdentity:(THLink*)identity { NSMutableSet* ourIDs = [NSMutableSet setWithArray:[self.cipherParts allKeys]]; [ourIDs intersectSet:[NSSet setWithArray:[identity.cipherParts allKeys]]]; @@ -226,7 +226,7 @@ -(NSString*)seekStringForIdentity:(THIdentity*)identity return nil; } --(void)addCipherSet:(THCipherSet *)cipherSet +-(void)addCipherSet:(E3XCipherSet *)cipherSet { NSMutableDictionary* newParts = [NSMutableDictionary dictionaryWithDictionary:_cipherParts]; if ([newParts objectForKey:cipherSet.identifier] != nil) { @@ -238,7 +238,7 @@ -(void)addCipherSet:(THCipherSet *)cipherSet NSMutableDictionary* fingerprintParts = [NSMutableDictionary dictionaryWithCapacity:newParts.count]; for (NSString* csid in newParts) { - THCipherSet* cs = [newParts objectForKey:csid]; + E3XCipherSet* cs = [newParts objectForKey:csid]; [fingerprintParts setObject:[cs.fingerprint hexString] forKey:csid]; } _parts = fingerprintParts; @@ -251,7 +251,7 @@ -(void)addPath:(THPath *)path if (existingPath) return; // See if this path matches any of ours and flag it as local - THSwitch* thSwitch = [THSwitch defaultSwitch]; + THMesh* thSwitch = [THMesh defaultSwitch]; for (THPath* switchPath in thSwitch.identity.availablePaths) { if ([switchPath pathIsLocalTo:path]) { self.isLocal = YES; @@ -262,7 +262,7 @@ -(void)addPath:(THPath *)path [self.availablePaths addObject:path]; } --(NSArray*)pathInformationTo:(THIdentity *)toIdentity allowLocal:(BOOL)allowLocal +-(NSArray*)pathInformationTo:(THLink *)toIdentity allowLocal:(BOOL)allowLocal { NSMutableArray* paths = [NSMutableArray arrayWithCapacity:self.availablePaths.count]; for(THPath* path in self.availablePaths) { @@ -304,7 +304,7 @@ -(void)checkPriorityPath:(THPath *)path } } --(void)addVia:(THIdentity*)viaIdentity +-(void)addVia:(THLink*)viaIdentity { // quick and dirty to ensure no duups [self.vias removeObject:viaIdentity]; @@ -316,7 +316,7 @@ -(void)attachSeedVias if (!self.isSeed) { NSPredicate* seedFilter = [NSPredicate predicateWithFormat:@"SELF.isSeed == YES"]; NSArray* seeds = [[identityCache allValues] filteredArrayUsingPredicate:seedFilter]; - for (THIdentity* seed in seeds) { + for (THLink* seed in seeds) { [self addVia:seed]; } } @@ -344,7 +344,7 @@ +(NSString*)hashnameForParts:(NSDictionary*)parts -(void)closeChannels { [self.channels enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - THChannel* curChannel = (THChannel*)obj; + E3XChannel* curChannel = (E3XChannel*)obj; if (curChannel.state != THChannelEnded) { curChannel.state = THChannelEnded; } @@ -376,7 +376,7 @@ -(void)reset } if (self.currentLine) { - [[THSwitch defaultSwitch] closeLine:self.currentLine]; + [[THMesh defaultSwitch] closeLine:self.currentLine]; } self.currentLine = nil; diff --git a/common/THSwitch.h b/common/THMesh.h similarity index 62% rename from common/THSwitch.h rename to common/THMesh.h index 510b95e..7ecf45a 100644 --- a/common/THSwitch.h +++ b/common/THMesh.h @@ -9,11 +9,10 @@ #import #import "THTransport.h" -@class THIdentity; -@class THChannel; +@class THLink; +@class E3XChannel; @class THPacket; -@class THLine; -@class THMeshBuckets; +@class E3XExchange; @class THTransport; typedef enum { @@ -27,47 +26,46 @@ typedef enum { THSwitchOnline } THSwitchStatus; -typedef void(^LineOpenBlock)(THIdentity*); +typedef void(^LineOpenBlock)(THLink*); -@class THSwitch; +@class THMesh; @protocol THSwitchDelegate --(void)openedLine:(THLine*)line; --(void)channelReady:(THChannel*)channel type:(THChannelType)type firstPacket:(THPacket*)packet; --(void)thSwitch:(THSwitch*)thSwitch status:(THSwitchStatus)status; +-(void)openedLine:(E3XExchange*)line; +-(void)channelReady:(E3XChannel*)channel type:(THChannelType)type firstPacket:(THPacket*)packet; +-(void)thSwitch:(THMesh*)thSwitch status:(THSwitchStatus)status; @end -@interface THSwitch : NSObject +@interface THMesh : NSObject +(id)defaultSwitch; -@property THMeshBuckets* meshBuckets; @property NSMutableDictionary* openLines; @property NSMutableArray* pendingJobs; -@property THIdentity* identity; +@property THLink* identity; @property id delegate; @property THSwitchStatus status; @property NSMutableDictionary* transports; @property NSMutableArray* potentialBridges; -+(id)THSWitchWithIdentity:(THIdentity*)identity; ++(id)THSWitchWithIdentity:(THLink*)identity; -(void)start; -(void)addTransport:(THTransport*)transport; --(THLine*)lineToHashname:(NSString*)hashname; --(void)openChannel:(THChannel*)channel firstPacket:(THPacket*)packet; +-(E3XExchange*)lineToHashname:(NSString*)hashname; +-(void)openChannel:(E3XChannel*)channel firstPacket:(THPacket*)packet; /// Open a line to the given identity // The identity can be either a complete identity (RSA keys and address filled in) or // just a hashname. The switch will do everything it can to open the line. // The completion block is optional. --(void)openLine:(THIdentity*)toIdentity completion:(LineOpenBlock)lineOpenCompletion; --(void)openLine:(THIdentity*)toIdentity; --(void)closeLine:(THLine*)line; +-(void)openLine:(THLink*)toIdentity completion:(LineOpenBlock)lineOpenCompletion; +-(void)openLine:(THLink*)toIdentity; +-(void)closeLine:(E3XExchange*)line; -(void)loadSeeds:(NSData*)seedData; -(void)updateStatus:(THSwitchStatus)status; --(THPacket*)generateOpen:(THLine*)toLine; +-(THPacket*)generateOpen:(E3XExchange*)toLine; -(void)handlePacket:(THPacket*)packet; -(void)transport:(THTransport *)transport handlePacket:(THPacket *)packet; diff --git a/common/THSwitch.m b/common/THMesh.m similarity index 82% rename from common/THSwitch.m rename to common/THMesh.m index 5686dc8..4d257db 100644 --- a/common/THSwitch.m +++ b/common/THMesh.m @@ -6,37 +6,36 @@ // Copyright (c) 2013 Telehash Foundation. All rights reserved. // -#import "THSwitch.h" +#import "THMesh.h" #import "THPacket.h" -#import "THIdentity.h" +#import "THLink.h" #import "NSString+HexString.h" -#import "THLine.h" -#import "THChannel.h" -#import "THMeshBuckets.h" +#import "E3XExchange.h" +#import "E3XChannel.h" #import "THPendingJob.h" -#import "THCipherSet.h" +#import "E3XCipherSet.h" #import "NSData+HexString.h" -#import "THCipherSet.h" +#import "E3XCipherSet.h" #import "THTransport.h" #import "THPath.h" -#import "THCipherSet2a.h" -#import "THCipherSet3a.h" -#import "THUnreliableChannel.h" +#import "E3XCipherSet2a.h" +#import "E3XCipherSet3a.h" +#import "E3XUnreliableChannel.h" #import "CLCLog.h" #import "THRelay.h" -@interface THSwitch() +@interface THMesh() @end -@implementation THSwitch +@implementation THMesh { - THIdentity* _identity; + THLink* _identity; } +(id)defaultSwitch; { - static THSwitch* sharedSwitch; + static THMesh* sharedSwitch; static dispatch_once_t oneTime; dispatch_once(&oneTime, ^{ sharedSwitch = [[self alloc] init]; @@ -44,9 +43,9 @@ +(id)defaultSwitch; return sharedSwitch; } -+(id)THSWitchWithIdentity:(THIdentity*)identity; ++(id)THSWitchWithIdentity:(THLink*)identity; { - THSwitch* thSwitch = [THSwitch new]; + THMesh* thSwitch = [THMesh new]; if (thSwitch) { } @@ -56,8 +55,6 @@ +(id)THSWitchWithIdentity:(THIdentity*)identity; -(id)init; { if (self) { - self.meshBuckets = [THMeshBuckets new]; - self.meshBuckets.localSwitch = self; self.openLines = [NSMutableDictionary dictionary]; self.pendingJobs = [NSMutableArray array]; self.transports = [NSMutableDictionary dictionary]; @@ -67,20 +64,18 @@ -(id)init; return self; } --(void)setIdentity:(THIdentity *)identity +-(void)setIdentity:(THLink *)identity { _identity = identity; - self.meshBuckets.localIdentity = identity; } --(THIdentity*)identity +-(THLink*)identity { return _identity; } -(void)start { - self.meshBuckets.localIdentity = self.identity; // XXX TODO FIXME For each path start it for (NSString* key in self.transports) { [[self.transports objectForKey:key] start]; @@ -104,16 +99,16 @@ -(void)loadSeeds:(NSData *)seedData; NSArray* paths = [entry objectForKey:@"paths"]; NSDictionary* keys = [entry objectForKey:@"keys"]; // TODO: XXX make this more generic - THIdentity* seedIdentity = [THIdentity new]; + THLink* seedIdentity = [THLink new]; seedIdentity.isSeed = YES; // 2a NSData* keyData = [[NSData alloc] initWithBase64EncodedString:[keys objectForKey:@"2a"] options:0]; - THCipherSet* cs = [[THCipherSet2a alloc] initWithPublicKey:keyData privateKey:nil]; + E3XCipherSet* cs = [[E3XCipherSet2a alloc] initWithPublicKey:keyData privateKey:nil]; [seedIdentity addCipherSet:cs]; // 3a keyData = [[NSData alloc] initWithBase64EncodedString:[keys objectForKey:@"3a"] options:0]; if (keyData) { - cs = [[THCipherSet3a alloc] initWithPublicKey:keyData privateKey:nil]; + cs = [[E3XCipherSet3a alloc] initWithPublicKey:keyData privateKey:nil]; [seedIdentity addCipherSet:cs]; } seedIdentity.parts = [entry objectForKey:@"parts"]; @@ -131,13 +126,13 @@ -(void)loadSeeds:(NSData *)seedData; }]; } --(THLine*)lineToHashname:(NSString*)hashname; +-(E3XExchange*)lineToHashname:(NSString*)hashname; { // XXX: If we don't have a line should we do an open here? // XXX: This is a common lookup, should we cache this another way as well? - __block THLine* ret = nil; + __block E3XExchange* ret = nil; [self.openLines enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - THLine* line = (THLine*)obj; + E3XExchange* line = (E3XExchange*)obj; if ([line.toIdentity.hashname isEqualToString:hashname]) { ret = line; *stop = YES; @@ -147,7 +142,7 @@ -(THLine*)lineToHashname:(NSString*)hashname; return ret; } --(void)channel:(THChannel*)channel line:(THLine*)line firstPacket:(THPacket*)packet +-(void)channel:(E3XChannel*)channel line:(E3XExchange*)line firstPacket:(THPacket*)packet { channel.line = line; if (!channel.channelId || [channel.channelId isEqualToNumber:@0]) { @@ -158,13 +153,13 @@ -(void)channel:(THChannel*)channel line:(THLine*)line firstPacket:(THPacket*)pac if (packet) [channel sendPacket:packet]; } --(void)openChannel:(THChannel *)channel firstPacket:(THPacket *)packet; +-(void)openChannel:(E3XChannel *)channel firstPacket:(THPacket *)packet; { // Check for an already open lines - THLine* channelLine = channel.toIdentity.currentLine; + E3XExchange* channelLine = channel.toIdentity.currentLine; if (!channelLine) { [self.pendingJobs addObject:[THPendingJob pendingJobFor:channel completion:^(id result) { - [self channel:channel line:(THLine*)result firstPacket:packet]; + [self channel:channel line:(E3XExchange*)result firstPacket:packet]; }]]; [self openLine:channel.toIdentity]; } else { @@ -173,12 +168,12 @@ -(void)openChannel:(THChannel *)channel firstPacket:(THPacket *)packet; } --(void)openLine:(THIdentity *)toIdentity +-(void)openLine:(THLink *)toIdentity { [self openLine:toIdentity completion:nil]; } --(void)openLine:(THIdentity *)toIdentity completion:(LineOpenBlock)lineOpenCompletion +-(void)openLine:(THLink *)toIdentity completion:(LineOpenBlock)lineOpenCompletion { if (toIdentity.currentLine && (toIdentity.activePath || toIdentity.relay.peerChannel)) { CLCLogDebug(@"openLine returning currentLine for identity %@", toIdentity.hashname); @@ -191,7 +186,7 @@ -(void)openLine:(THIdentity *)toIdentity completion:(LineOpenBlock)lineOpenCompl for (THPendingJob* pendingJobItem in self.pendingJobs) { if (pendingJobItem.type == PendingIdentity) { - THIdentity* pendingIdentity = (THIdentity*)pendingJobItem.pending; + THLink* pendingIdentity = (THLink*)pendingJobItem.pending; if ([pendingIdentity.hashname isEqualToString:toIdentity.hashname]) { // We're already trying, bail on this one CLCLogWarning(@"Tried to open another line to identity %@ while one pending", toIdentity.hashname); @@ -221,7 +216,7 @@ -(void)openLine:(THIdentity *)toIdentity completion:(LineOpenBlock)lineOpenCompl [self.pendingJobs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { THPendingJob* job = (THPendingJob*)obj; if (job.type == PendingChannel) { - THChannel* channel = (THChannel*)job.pending; + E3XChannel* channel = (E3XChannel*)job.pending; if ([channel.toIdentity.hashname isEqualToString:toIdentity.hashname]) { [self.pendingJobs removeObjectAtIndex:idx]; } @@ -242,7 +237,7 @@ -(void)openLine:(THIdentity *)toIdentity completion:(LineOpenBlock)lineOpenCompl CLCLogDebug(@"identity %@ already has known paths", toIdentity.hashname); if (!toIdentity.currentLine) { - toIdentity.currentLine = [THLine new]; + toIdentity.currentLine = [E3XExchange new]; toIdentity.currentLine.toIdentity = toIdentity; } @@ -267,7 +262,7 @@ -(void)openLine:(THIdentity *)toIdentity completion:(LineOpenBlock)lineOpenCompl toIdentity.relay = relay; toIdentity.relay.toIdentity = toIdentity; - for (THIdentity* viaIdentity in toIdentity.vias) { + for (THLink* viaIdentity in toIdentity.vias) { // if the via has an active line that ISNT a bridge, lets try them if (viaIdentity.currentLine && viaIdentity.activePath) { [toIdentity.relay attachVia:viaIdentity]; @@ -285,24 +280,15 @@ -(void)openLine:(THIdentity *)toIdentity completion:(LineOpenBlock)lineOpenCompl return; } - // Find a way to it from the mesh - if (!existingPendingJob) { - [self.meshBuckets seek:toIdentity completion:^(BOOL found) { - if (found) { - CLCLogDebug(@"identity %@ found in meshbuckets", toIdentity.hashname); - [self openLine:toIdentity completion:lineOpenCompletion]; - } - }]; - } + // TODO ask a router } --(void)closeLine:(THLine *)line +-(void)closeLine:(E3XExchange *)line { if (line.cachedOpen) { line.cachedOpen = nil; } - [self.meshBuckets removeLine:line]; if (line.inLineId) [self.openLines removeObjectForKey:line.inLineId]; if (line.toIdentity.currentLine == line) { @@ -332,12 +318,12 @@ -(BOOL)findPendingSeek:(THPacket *)packet; -(void)processOpen:(THPacket*)incomingPacket { CLCLogInfo(@"Processing an open from %@ with type %@", incomingPacket.returnPath, [incomingPacket.body subdataWithRange:NSMakeRange(0, 1)]); - THCipherSet* cipherSet = [self.identity.cipherParts objectForKey:[[incomingPacket.body subdataWithRange:NSMakeRange(0, 1)] hexString]]; + E3XCipherSet* cipherSet = [self.identity.cipherParts objectForKey:[[incomingPacket.body subdataWithRange:NSMakeRange(0, 1)] hexString]]; if (!cipherSet) { CLCLogInfo(@"Invalid cipher set requested %@", [[incomingPacket.body subdataWithRange:NSMakeRange(0, 1)] hexString]); return; } - THLine* newLine = [cipherSet processOpen:incomingPacket]; + E3XExchange* newLine = [cipherSet processOpen:incomingPacket]; if (!newLine) { CLCLogInfo(@"Unable to process open packet"); return; @@ -356,7 +342,6 @@ -(void)processOpen:(THPacket*)incomingPacket } // remove any existing lines to this hashname - [self.meshBuckets removeLine:newLine]; if (newLine.inLineId) [self.openLines removeObjectForKey:newLine.inLineId]; __block THPendingJob* pendingLineJob = nil; @@ -364,7 +349,7 @@ -(void)processOpen:(THPacket*)incomingPacket THPendingJob* job = (THPendingJob*)obj; if (job.type != PendingIdentity) return; - THIdentity* pendingIdentity = (THIdentity*)job.pending; + THLink* pendingIdentity = (THLink*)job.pending; if ([pendingIdentity.hashname isEqualToString:newLine.toIdentity.hashname]) { pendingLineJob = job; *stop = YES; @@ -372,7 +357,7 @@ -(void)processOpen:(THPacket*)incomingPacket } }]; if (pendingLineJob && newLine.inLineId) { - THIdentity* pendingIdentity = (THIdentity*)pendingLineJob.pending; + THLink* pendingIdentity = (THLink*)pendingLineJob.pending; newLine = pendingIdentity.currentLine; CLCLogInfo(@"Finish opening line %@ for %@", newLine.inLineId, pendingIdentity.hashname); [newLine openLine]; @@ -385,7 +370,6 @@ -(void)processOpen:(THPacket*)incomingPacket if (pendingLineJob) pendingLineJob.handler(newLine); - [self.meshBuckets linkToIdentity:newLine.toIdentity]; } else { [newLine sendOpen]; [newLine openLine]; @@ -399,13 +383,10 @@ -(void)processOpen:(THPacket*)incomingPacket if (pendingLineJob) pendingLineJob.handler(newLine); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - THChannel* linkChannel = [newLine.toIdentity channelForType:@"link"]; - if (!linkChannel) { - [self.meshBuckets linkToIdentity:newLine.toIdentity]; - } + E3XChannel* linkChannel = [newLine.toIdentity channelForType:@"link"]; + // TODO what to do here?? }); - [self.meshBuckets addIdentity:newLine.toIdentity]; } // negotiate path after a short delay to allow any bridge path to come in @@ -422,7 +403,7 @@ -(void)processOpen:(THPacket*)incomingPacket [self.pendingJobs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { THPendingJob* job = (THPendingJob*)obj; if (job.type == PendingChannel) { - THChannel* channel = (THChannel*)job.pending; + E3XChannel* channel = (E3XChannel*)job.pending; if (![channel.toIdentity.hashname isEqualToString:newLine.toIdentity.hashname]) return; [self.pendingJobs removeObjectAtIndex:idx]; job.handler(newLine); @@ -442,7 +423,7 @@ -(void)updateStatus:(THSwitchStatus)status } } --(THPacket*)generateOpen:(THLine *)toLine +-(THPacket*)generateOpen:(E3XExchange *)toLine { // Find our highest matching cipher set NSMutableSet* ourIDs = [NSMutableSet setWithArray:[self.identity.cipherParts allKeys]]; @@ -453,7 +434,7 @@ -(THPacket*)generateOpen:(THLine *)toLine } NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"description" ascending:NO]; NSArray* sortedCSIds = [ourIDs sortedArrayUsingDescriptors:@[sort]]; - THCipherSet* cs = [self.identity.cipherParts objectForKey:[sortedCSIds objectAtIndex:0]]; + E3XCipherSet* cs = [self.identity.cipherParts objectForKey:[sortedCSIds objectAtIndex:0]]; return [cs generateOpen:toLine from:self.identity]; } @@ -466,7 +447,7 @@ -(void)handlePacket:(THPacket *)packet NSString* lineId = [[packet.body subdataWithRange:NSMakeRange(0, 16)] hexString]; //CLCLogInfo(@"Received a line packet for %@", lineId); // Process a line packet - THLine* line = [self.openLines objectForKey:lineId]; + E3XExchange* line = [self.openLines objectForKey:lineId]; // If there is no line to handle this dump it if (line == nil) { CLCLogWarning(@"line %@ not found in openLines", lineId); diff --git a/common/THMeshBuckets.h b/common/THMeshBuckets.h deleted file mode 100644 index a97a412..0000000 --- a/common/THMeshBuckets.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// THMeshBuckets.h -// telehash -// -// Created by Thomas Muldowney on 1/7/14. -// Copyright (c) 2014 Telehash Foundation. All rights reserved. -// - -#import -#import "THChannel.h" - -@class THIdentity; -@class THLine; -@class THSwitch; - -typedef void(^SeekCompletionBlock)(BOOL found); - -@interface THMeshBuckets : NSObject - -@property (nonatomic, assign) THSwitch* localSwitch; -@property THIdentity* localIdentity; -@property NSMutableArray* buckets; -@property NSMutableArray* pendingSeeks; - --(void)linkToIdentity:(THIdentity*)identity; --(void)addIdentity:(THIdentity*)identity; --(void)removeLine:(THLine*)line; --(NSArray*)closeInBucket:(THIdentity*)seekIdentity; --(NSArray*)nearby:(THIdentity*)seekIdentity; --(void)seek:(THIdentity*)seekIdentity completion:(SeekCompletionBlock)completion; -@end diff --git a/common/THMeshBuckets.m b/common/THMeshBuckets.m deleted file mode 100644 index e37a0df..0000000 --- a/common/THMeshBuckets.m +++ /dev/null @@ -1,453 +0,0 @@ -// -// THMeshBuckets.m -// telehash -// -// Created by Thomas Muldowney on 1/7/14. -// Copyright (c) 2014 Telehash Foundation. All rights reserved. -// - -#import "THMeshBuckets.h" -#import "THIdentity.h" -#import "THLine.h" -#import "THPacket.h" -#import "RNG.h" -#import "NSData+HexString.h" -#import "THSwitch.h" -#import "THPendingJob.h" -#import "THChannel.h" -#import "THPath.h" -#import "THRelay.h" -#import "THUnreliableChannel.h" -#import "CLCLog.h" - -#define K_BUCKET_SIZE 8 -#define MAX_LINKS 256 -#define MAX_POTENTIAL_BRIDGES 5 - -@interface PendingSeekJob : NSObject -@property THIdentity* localIdentity; -@property THIdentity* seekingIdentity; -@property THSwitch* localSwitch; -@property NSMutableArray* nearby; -@property NSUInteger runningSearches; -@property (nonatomic, copy) SeekCompletionBlock completion; - --(void)runSeek; --(BOOL)channel:(THChannel *)channel handlePacket:(THPacket *)packet; -@end - -@implementation THMeshBuckets -{ - BOOL pendingPings; - NSUInteger linkTotal; - NSTimer* pingTimer; -} - --(id)init -{ - self = [super init]; - if (self) { - self.buckets = [NSMutableArray arrayWithCapacity:256]; - for (int i = 0; i < 256; ++i) { - [self.buckets insertObject:[NSMutableArray array] atIndex:i]; - } - pingTimer = [NSTimer scheduledTimerWithTimeInterval:25 target:self selector:@selector(pingLines) userInfo:nil repeats:YES]; - } - return self; -} - --(void)pingLines -{ - time_t checkTime = time(NULL); - - [self.buckets enumerateObjectsUsingBlock:^(id obj, NSUInteger bucketIdx, BOOL *stop) { - NSMutableArray* bucket = (NSMutableArray*)obj; - - [bucket enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - THIdentity* identity = (THIdentity*)obj; - THChannel* linkChannel = [identity channelForType:@"link"]; - - if (linkChannel) { - // if our lastInActivity > 50s and the channel is >5s old - if ((checkTime >= linkChannel.lastInActivity + 50) && (checkTime > linkChannel.createdAt + 25)) { - NSUInteger lastInDuration = checkTime - linkChannel.lastInActivity; - CLCLogWarning(@"line inactive for %@ (in duration %d), removing link channel", identity.hashname, lastInDuration); - - [bucket removeObjectAtIndex:idx]; - THChannel* channel = [identity channelForType:@"link"]; - if (channel) { - [identity.channels removeObjectForKey:channel.channelId]; - } - - // TODO: this should be moved to line activity check - [identity reset]; - return; - } - - if (identity.activePath || identity.relay.peerChannel) { - THPacket* pingPacket = [THPacket new]; - [pingPacket.json setObject:@YES forKey:@"seed"]; - - [linkChannel sendPacket:pingPacket]; - } else { - CLCLogWarning(@"no path or relay available for pingLines to %@, attempting a re-open", identity.hashname); - [identity.currentLine sendOpen]; - } - } else { - CLCLogDebug(@"link channel missing for %@ within pingLines, resetting identity", identity.hashname); - [identity reset]; - } - }]; - }]; -} - --(void)linkToIdentity:(THIdentity*)identity -{ - [self addIdentity:identity]; - - THPacket* linkPacket = [THPacket new]; - [linkPacket.json setObject:@YES forKey:@"seed"]; // TODO: Allow for opting out of seeding? - - NSArray* seeIdentities = [self nearby:identity]; - NSMutableArray* sees = [NSMutableArray array]; - - if (seeIdentities != nil) { - for (THIdentity* seeIdentity in seeIdentities) { - NSString* seekString = [seeIdentity seekStringForIdentity:identity]; - if (seekString) { - [sees addObject:seekString]; - } - } - } - - [linkPacket.json setObject:sees forKey:@"see"]; - - THChannel* linkChannel = [identity channelForType:@"link"]; - if (!linkChannel) { - linkChannel = [[THUnreliableChannel alloc] initToIdentity:identity]; - [linkPacket.json setObject:@"link" forKey:@"type"]; - - [[THSwitch defaultSwitch] openChannel:linkChannel firstPacket:linkPacket]; - } else { - [linkChannel sendPacket:linkPacket]; - } - - linkChannel.delegate = self; -} - --(void)addIdentity:(THIdentity *)identity -{ - NSInteger bucketIndex = [self.localIdentity distanceFrom:identity]; - NSMutableArray* bucket = [self.buckets objectAtIndex:bucketIndex]; - if (bucket == nil) { - bucket = [NSMutableArray array]; - } - - THChannel* linkChannel = [identity channelForType:@"link"]; - - // TODO: Check our hints for age on this entry, if it's older we should bump the newest from the bucket if it's full - if (linkTotal >= MAX_LINKS && bucket.count >= K_BUCKET_SIZE) { - // TODO: Evict the oldest - - if (linkChannel) { - // TODO: If we can not evict, we bail on it - THPacket* endLinkPacket = [THPacket new]; - [endLinkPacket.json setObject:@YES forKey:@"end"]; - [endLinkPacket.json setObject:@NO forKey:@"seed"]; - [linkChannel sendPacket:endLinkPacket]; - } - - // TODO: Check the cleanup on the channel and up the chain? - return; - } - - for (NSUInteger i = 0; i < bucket.count; ++i) { - THIdentity* curIdentity = (THIdentity*)[bucket objectAtIndex:i]; - if ([curIdentity.hashname isEqualToString:identity.hashname]) { - return; - } - } - - [bucket addObject:identity]; -} - --(void)removeLine:(THLine *)line -{ - if (!line) return; - NSInteger bucketIndex = [self.localIdentity distanceFrom:line.toIdentity]; - [[self.buckets objectAtIndex:bucketIndex] removeObject:line]; -} - --(NSArray*)closeInBucket:(THIdentity*)seekIdentity -{ - NSInteger bucketIndex = [self.localIdentity distanceFrom:seekIdentity]; - NSArray* bucket = [self.buckets objectAtIndex:bucketIndex]; - NSArray* results = [bucket sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { - NSInteger hash1 = [seekIdentity distanceFrom:obj1]; - NSInteger hash2 = [seekIdentity distanceFrom:obj2]; - - if (hash1 < hash2) { - return NSOrderedDescending; - } else if (hash2 > hash1) { - return NSOrderedAscending; - } - - return NSOrderedSame; - }]; - return [results subarrayWithRange:NSMakeRange(0, MIN(5, results.count))]; -} - --(NSArray*)nearby:(THIdentity*)seekIdentity; -{ - NSMutableArray* entries = [NSMutableArray array]; - NSInteger initialBucketIndex = [self.localIdentity distanceFrom:seekIdentity]; - // First get the closest - [entries addObjectsFromArray:[self closeInBucket:seekIdentity]]; - // Go downwards for better matches - NSInteger curBucketIndex = initialBucketIndex - 1; - while (curBucketIndex >= 0 && [entries count] < 5) { - NSArray* curBucket = [self.buckets objectAtIndex:curBucketIndex]; - if (curBucket.count == 0) { - --curBucketIndex; - continue; - } - [entries addObjectsFromArray:[curBucket subarrayWithRange:NSMakeRange(0, MIN(5 - entries.count, curBucket.count))]]; - --curBucketIndex; - } - // Now just make sure we're full with general entries - curBucketIndex = initialBucketIndex + 1; - while (curBucketIndex < 256) { - NSArray* curBucket = [self.buckets objectAtIndex:curBucketIndex]; - if (curBucket.count == 0) { - ++curBucketIndex; - continue; - } - [entries addObjectsFromArray:[curBucket subarrayWithRange:NSMakeRange(0, MIN(5 - entries.count, curBucket.count))]]; - ++curBucketIndex; - } - return entries; -} - --(void)seek:(THIdentity*)toIdentity completion:(SeekCompletionBlock)completion -{ - CLCLogDebug(@"Seeking for %@", toIdentity.hashname); - - PendingSeekJob* seekJob = [PendingSeekJob new]; - seekJob.localSwitch = self.localSwitch; - seekJob.localIdentity = self.localIdentity; - seekJob.seekingIdentity = toIdentity; - seekJob.completion = completion; - - // NOTE shortterm hack to only query against seeds - NSPredicate* activeFilter = [NSPredicate predicateWithFormat:@"NOT (SELF.hashname MATCHES %@) AND SELF.isBridged == NO AND SELF.hasLink == YES", toIdentity.hashname]; - NSArray* nearby = [[self nearby:toIdentity] filteredArrayUsingPredicate:activeFilter]; - - CLCLogDebug(@"seek for %@ has %d nearby peers", toIdentity.hashname, nearby.count); - - seekJob.nearby = [NSMutableArray arrayWithArray:[nearby subarrayWithRange:NSMakeRange(0, MIN(3, nearby.count))]]; - [self.pendingSeeks setValue:seekJob forKey:toIdentity.hashname]; - - [seekJob.nearby enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - [seekJob runSeek]; - }]; - -} - -// Channel delegate methods - --(BOOL)channel:(THChannel *)channel handlePacket:(THPacket *)packet -{ - THSwitch* defaultSwitch = [THSwitch defaultSwitch]; - if (defaultSwitch.status != THSwitchOnline) { - [defaultSwitch updateStatus:THSwitchOnline]; - } - - NSArray* bridges = [packet.json objectForKey:@"bridge"]; - if (bridges) { - channel.toIdentity.availableBridges = bridges; - [self.localSwitch.potentialBridges addObject:bridges]; - // Let's just maintain 5 potent - if (self.localSwitch.potentialBridges.count > MAX_POTENTIAL_BRIDGES) { - [self.localSwitch.potentialBridges removeObjectAtIndex:0]; - } - } - - THIPv4Transport* transport = [self.localSwitch.transports objectForKey:@"ipv4"]; - for (NSString* seeLine in [packet.json objectForKey:@"see"]) { - NSArray* seeParts = [seeLine componentsSeparatedByString:@","]; - if (seeParts.count < 2) continue; // Minimum of hash,cs - - if ([[seeParts objectAtIndex:0] isEqualToString:self.localIdentity.hashname]) continue; - THIdentity* seeIdentity = [THIdentity identityFromHashname:[seeParts objectAtIndex:0]]; - NSInteger bucketIndex = [self.localIdentity distanceFrom:seeIdentity]; - NSMutableArray* bucket = [self.buckets objectAtIndex:bucketIndex]; - if (bucket == nil) { - bucket = [NSMutableArray array]; - } - - // If we have a link channel already, just skip it - THChannel* linkChannel = [seeIdentity channelForType:@"link"]; - if (seeIdentity.activePath || linkChannel) continue; - - seeIdentity.suggestedCipherSet = [seeParts objectAtIndex:1]; - - // TODO: Check our hints for age on this entry, if it's older we should bump the newest from the bucket if it's full - if (linkTotal >= MAX_LINKS || bucket.count >= K_BUCKET_SIZE) { - break; - } - - [seeIdentity addVia:channel.toIdentity]; - if (seeParts.count == 4) { - [seeIdentity addPath:[[THIPV4Path alloc] initWithTransport:transport ip:[seeParts objectAtIndex:2] port:[[seeParts objectAtIndex:3] integerValue]]]; - } - - // Temas review, this is where our infinite loop happens with hashname lookups - [self.localSwitch openLine:seeIdentity]; - } - - // lets not participate in the DHT anymore - - NSUInteger now = time(NULL); - if (channel.lastOutActivity + 10 < now) { - THPacket* pingPacket = [THPacket new]; - [pingPacket.json setObject:@YES forKey:@"seed"]; - if (channel.lastOutActivity == 0) { - // Add the sees, it's our initial response - NSArray* seeIdentities = [self nearby:channel.toIdentity]; - NSMutableArray* sees = [NSMutableArray array]; - - if (seeIdentities != nil) { - for (THIdentity* seeIdentity in seeIdentities) { - NSString* seekString = [seeIdentity seekStringForIdentity:channel.toIdentity]; - if (seekString) { - [sees addObject:seekString]; - } - } - } - - [pingPacket.json setObject:sees forKey:@"see"]; - } - [channel sendPacket:pingPacket]; - } - - return YES; -} - --(void)channel:(THChannel *)channel didChangeStateTo:(THChannelState)channelState -{ - if (channelState == THChannelEnded || channelState == THChannelErrored) { - CLCLogWarning(@"link channel ended"); - NSMutableArray* bucket = [self.buckets objectAtIndex:[self.localIdentity distanceFrom:channel.toIdentity]]; - [bucket removeObject:channel]; - } -} - --(void)channel:(THChannel *)channel didFailWithError:(NSError *)error -{ - CLCLogWarning(@"link channel errored with error: %@", [error description]); - NSMutableArray* bucket = [self.buckets objectAtIndex:[self.localIdentity distanceFrom:channel.toIdentity]]; - [bucket removeObject:channel]; -} -@end - - -@implementation PendingSeekJob --(void)runSeek -{ - if (self.nearby.count == 0) return; - - // Resort and run the seek - THIdentity* identity = [self.nearby objectAtIndex:0]; - [self.nearby removeObjectAtIndex:0]; - - THSwitch* defaultSwitch = [THSwitch defaultSwitch]; - ++self.runningSearches; - - if (!identity.activePath) return; - - THChannel* seekChannel = [[THUnreliableChannel alloc] initToIdentity:identity]; - seekChannel.delegate = self; - - THPacket* seekPacket = [THPacket new]; - [seekPacket.json setObject:self.seekingIdentity.hashname forKey:@"seek"]; - [seekPacket.json setObject:@"seek" forKey:@"type"]; - - [defaultSwitch openChannel:seekChannel firstPacket:seekPacket]; -} - - -(BOOL)channel:(THChannel*)channel handlePacket:(THPacket*)packet -{ - - NSString* error = [packet.json objectForKey:@"err"]; - if (error) return YES; - - NSArray* sees = [packet.json objectForKey:@"see"]; - - __block BOOL foundIt = NO; - CLCLogDebug(@"Checking for %@ in sees %@", self.seekingIdentity.hashname, sees); - [sees enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - NSString* seeString = (NSString*)obj; - NSArray* seeParts = [seeString componentsSeparatedByString:@","]; - if (seeParts.count < 2) { - CLCLogDebug(@"Invalid see parts: %@", seeParts); - return; - } - if ([[seeParts objectAtIndex:0] isEqualToString:self.seekingIdentity.hashname]) { - CLCLogDebug(@"We found %@!", self.seekingIdentity.hashname); - // this is it! - [self.seekingIdentity addVia:channel.toIdentity]; - self.seekingIdentity.suggestedCipherSet = [seeParts objectAtIndex:1]; - - if (seeParts.count > 2) { - THIPv4Transport* localTransport = [self.localSwitch.transports objectForKey:@"ipv4"]; - if (localTransport) { - NSData* remoteAddress = [THIPV4Path addressTo:[seeParts objectAtIndex:2] port:[[seeParts objectAtIndex:3] integerValue]]; - [self.seekingIdentity addPath:[localTransport returnPathTo:remoteAddress]]; - } - } - foundIt = YES; - *stop = YES; - return; - - } else { - // If they told us to ask ourself ignore it - if ([[seeParts objectAtIndex:0] isEqualToString:self.localIdentity.hashname]) return; - - // If we're moving closer we want to go ahead and start a seek to it - THIdentity* nearIdentity = [THIdentity identityFromHashname:[seeParts objectAtIndex:0]]; - [nearIdentity addVia:channel.toIdentity]; - nearIdentity.suggestedCipherSet = [seeParts objectAtIndex:1]; - [self.nearby addObject:nearIdentity]; - } - }]; - - if (foundIt) { - if (self.completion) self.completion(YES); - return YES; - } - - // Sort on distance and run again - [self.nearby sortUsingComparator:^NSComparisonResult(id obj1, id obj2) { - NSInteger hash1 = [self.seekingIdentity distanceFrom:obj1]; - NSInteger hash2 = [self.seekingIdentity distanceFrom:obj2]; - - if (hash1 < hash2) { - return NSOrderedDescending; - } else if (hash2 > hash1) { - return NSOrderedAscending; - } - - return NSOrderedSame; - }]; - - if (self.nearby.count > 0) { - [self runSeek]; - for (NSUInteger i = self.runningSearches; i < MIN(3, self.nearby.count - 1); ++i) { - [self runSeek]; - } - } - - return YES; -} - -@end diff --git a/common/THPath.h b/common/THPath.h index c07102b..4677877 100644 --- a/common/THPath.h +++ b/common/THPath.h @@ -7,11 +7,11 @@ // #import -#import "THChannel.h" +#import "E3XChannel.h" #import "GCDAsyncUdpSocket.h" @class THPacket; -@class THUnreliableChannel; +@class E3XUnreliableChannel; @class THTransport; @class THPath; diff --git a/common/THPath.m b/common/THPath.m index 11ae167..b183552 100644 --- a/common/THPath.m +++ b/common/THPath.m @@ -8,11 +8,11 @@ #import "THPath.h" #import "THPeerRelay.h" -#import "THSwitch.h" +#import "THMesh.h" #import "GCDAsyncUdpSocket.h" #import "THPacket.h" #import "THTransport.h" -#import "THUnreliableChannel.h" +#import "E3XUnreliableChannel.h" #import "CLCLog.h" #include diff --git a/common/THPeerRelay.h b/common/THPeerRelay.h index 570c438..8d380d4 100644 --- a/common/THPeerRelay.h +++ b/common/THPeerRelay.h @@ -7,13 +7,13 @@ // #import -#import "THChannel.h" +#import "E3XChannel.h" -@class THIdentity; -@class THChannel; +@class THLink; +@class E3XChannel; @interface THPeerRelay : NSObject -@property THChannel* connectChannel; -@property THChannel* peerChannel; +@property E3XChannel* connectChannel; +@property E3XChannel* peerChannel; -(void)sendPacket:(THPacket*)packet; @end diff --git a/common/THPeerRelay.m b/common/THPeerRelay.m index 5903695..fe606d6 100644 --- a/common/THPeerRelay.m +++ b/common/THPeerRelay.m @@ -7,7 +7,7 @@ // #import "THPeerRelay.h" -#import "THIdentity.h" +#import "THLink.h" #import "THPacket.h" #import "CLCLog.h" @@ -23,7 +23,7 @@ -(void)sendPacket:(THPacket *)packet CLCLogWarning(@"THPeerRelay sendPacket called!"); } --(BOOL)channel:(THChannel *)channel handlePacket:(THPacket *)packet +-(BOOL)channel:(E3XChannel *)channel handlePacket:(THPacket *)packet { CLCLogDebug(@"Relay got %@", packet.json); @@ -41,12 +41,12 @@ -(BOOL)channel:(THChannel *)channel handlePacket:(THPacket *)packet return YES; } --(void)channel:(THChannel *)channel didChangeStateTo:(THChannelState)channelState +-(void)channel:(E3XChannel *)channel didChangeStateTo:(THChannelState)channelState { CLCLogWarning(@"THPeerRelay channel didChangeStateTo: %d", channelState); } --(void)channel:(THChannel *)channel didFailWithError:(NSError *)error +-(void)channel:(E3XChannel *)channel didFailWithError:(NSError *)error { CLCLogWarning(@"THPeerRelay channel didFailWithError: %@", [error description]); } diff --git a/common/THPendingJob.m b/common/THPendingJob.m index 45e0b9d..0c49b70 100644 --- a/common/THPendingJob.m +++ b/common/THPendingJob.m @@ -7,9 +7,9 @@ // #import "THPendingJob.h" -#import "THIdentity.h" -#import "THLine.h" -#import "THChannel.h" +#import "THLink.h" +#import "E3XExchange.h" +#import "E3XChannel.h" #import "THPacket.h" @implementation THPendingJob @@ -17,9 +17,9 @@ +(id)pendingJobFor:(id)pendingItem completion:(PendingJobBlock)onCompletion; { THPendingJob* pendingJob = [THPendingJob new]; Class itemClass = [pendingItem class]; - if (itemClass == [THIdentity class]) pendingJob.type = PendingIdentity; - if (itemClass == [THLine class]) pendingJob.type = PendingLine; - if ([itemClass superclass] == [THChannel class]) pendingJob.type = PendingChannel; + if (itemClass == [THLink class]) pendingJob.type = PendingIdentity; + if (itemClass == [E3XExchange class]) pendingJob.type = PendingLine; + if ([itemClass superclass] == [E3XChannel class]) pendingJob.type = PendingChannel; if (itemClass == [THPacket class]) pendingJob.type = PendingSeek; pendingJob.pending = pendingItem; pendingJob.handler = onCompletion; diff --git a/common/THRelay.h b/common/THRelay.h index 62ff288..fd65077 100644 --- a/common/THRelay.h +++ b/common/THRelay.h @@ -7,16 +7,16 @@ // #import -#import "THChannel.h" -#import "THUnreliableChannel.h" +#import "E3XChannel.h" +#import "E3XUnreliableChannel.h" #import "THPath.h" @interface THRelay : NSObject -@property (assign) THIdentity* toIdentity; -@property (retain) THIdentity* relayIdentity; +@property (assign) THLink* toIdentity; +@property (retain) THLink* relayIdentity; @property (retain) THPath* relayedPath; -@property (weak) THUnreliableChannel* peerChannel; --(id)initOnChannel:(THUnreliableChannel*)channel; --(void)attachVia:(THIdentity*)viaIdentity; +@property (weak) E3XUnreliableChannel* peerChannel; +-(id)initOnChannel:(E3XUnreliableChannel*)channel; +-(void)attachVia:(THLink*)viaIdentity; -(void)sendPacket:(THPacket *)packet; @end diff --git a/common/THRelay.m b/common/THRelay.m index aa2ad39..5607ccd 100644 --- a/common/THRelay.m +++ b/common/THRelay.m @@ -11,7 +11,7 @@ #import "THPacket.h" #import "CLCLog.h" #import "THPath.h" -#import "THCipherSet.h" +#import "E3XCipherSet.h" @implementation THRelay @@ -20,7 +20,7 @@ -(void)dealloc CLCLogDebug(@"We lost a relay to %@!", self.toIdentity.hashname); } --(id)initOnChannel:(THUnreliableChannel *)channel +-(id)initOnChannel:(E3XUnreliableChannel *)channel { self = [super init]; if (self) { @@ -30,11 +30,11 @@ -(id)initOnChannel:(THUnreliableChannel *)channel return self; } --(void)attachVia:(THIdentity*)viaIdentity +-(void)attachVia:(THLink*)viaIdentity { - THSwitch* defaultSwitch = [THSwitch defaultSwitch]; + THMesh* defaultSwitch = [THMesh defaultSwitch]; - THUnreliableChannel* peerChannel = [[THUnreliableChannel alloc] initToIdentity:viaIdentity]; + E3XUnreliableChannel* peerChannel = [[E3XUnreliableChannel alloc] initToIdentity:viaIdentity]; peerChannel.type = @"peer"; peerChannel.delegate = self; [defaultSwitch openChannel:peerChannel firstPacket:nil]; @@ -51,7 +51,7 @@ -(void)attachVia:(THIdentity*)viaIdentity [peerPacket.json setObject:paths forKey:@"paths"]; } - THCipherSet* chosenCS = [defaultSwitch.identity.cipherParts objectForKey:self.toIdentity.suggestedCipherSet]; + E3XCipherSet* chosenCS = [defaultSwitch.identity.cipherParts objectForKey:self.toIdentity.suggestedCipherSet]; if (!chosenCS) { CLCLogError(@"We did not actually have a key for the CS %@ to connect to %@", self.toIdentity.suggestedCipherSet, self.toIdentity.hashname); return; @@ -87,7 +87,7 @@ -(void)sendPacket:(THPacket *)packet [self.peerChannel sendPacket:relayPacket]; } --(BOOL)channel:(THChannel *)channel handlePacket:(THPacket *)packet +-(BOOL)channel:(E3XChannel *)channel handlePacket:(THPacket *)packet { THPacket* relayedPacket = [THPacket packetData:packet.body]; if (!relayedPacket) { @@ -109,16 +109,16 @@ -(BOOL)channel:(THChannel *)channel handlePacket:(THPacket *)packet // overwrite our peerChannel and relayIdentity with the one that actually responded if (self.peerChannel.lastInActivity == 0) { - self.peerChannel = (THUnreliableChannel*)channel; + self.peerChannel = (E3XUnreliableChannel*)channel; self.relayIdentity = channel.toIdentity; } - [[THSwitch defaultSwitch] handlePacket:relayedPacket]; + [[THMesh defaultSwitch] handlePacket:relayedPacket]; return YES; } --(void)channel:(THChannel *)channel didFailWithError:(NSError *)error +-(void)channel:(E3XChannel *)channel didFailWithError:(NSError *)error { CLCLogWarning(@"relay peerChannel for %@ didFailWithError: %@", self.toIdentity.hashname, [error description]); @@ -127,7 +127,7 @@ -(void)channel:(THChannel *)channel didFailWithError:(NSError *)error } } --(void)channel:(THChannel *)channel didChangeStateTo:(THChannelState)channelState +-(void)channel:(E3XChannel *)channel didChangeStateTo:(THChannelState)channelState { CLCLogDebug(@"relay peerChannel for %@ didChangeStateTo: %d", self.toIdentity.hashname, channelState); diff --git a/cryptopp/cryptopp/cryptopp.xcodeproj/project.pbxproj b/cryptopp/cryptopp/cryptopp.xcodeproj/project.pbxproj index bd8a4d7..ff915bb 100644 --- a/cryptopp/cryptopp/cryptopp.xcodeproj/project.pbxproj +++ b/cryptopp/cryptopp/cryptopp.xcodeproj/project.pbxproj @@ -928,7 +928,7 @@ 82D221051871D3620015E7EA /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0500; + LastUpgradeCheck = 0610; ORGANIZATIONNAME = "Telehash Foundation"; }; buildConfigurationList = 82D221081871D3620015E7EA /* Build configuration list for PBXProject "cryptopp" */; @@ -1225,7 +1225,7 @@ 8263DA1418BD298500DED8E5 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD)"; + COMBINE_HIDPI_IMAGES = YES; DSTROOT = /tmp/cryptopp.dst; GCC_PREPROCESSOR_DEFINITIONS = "CRYPTOPP_DISABLE_ASM=1"; "GCC_PREPROCESSOR_DEFINITIONS[arch=*]" = "CRYPTOPP_DISABLE_ASM=1"; @@ -1239,7 +1239,7 @@ 8263DA1518BD298500DED8E5 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD)"; + COMBINE_HIDPI_IMAGES = YES; DSTROOT = /tmp/cryptopp.dst; GCC_PREPROCESSOR_DEFINITIONS = "CRYPTOPP_DISABLE_ASM=1"; GCC_WARN_INHIBIT_ALL_WARNINGS = YES; @@ -1253,7 +1253,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -1293,7 +1292,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; diff --git a/telehash.xcodeproj/project.pbxproj b/telehash.xcodeproj/project.pbxproj index c641ad5..4cd5388 100644 --- a/telehash.xcodeproj/project.pbxproj +++ b/telehash.xcodeproj/project.pbxproj @@ -51,34 +51,34 @@ 8231EBC51836BD3600BC41C1 /* NSString+HexString.h in Headers */ = {isa = PBXBuildFile; fileRef = 8231EBC31836BD3600BC41C1 /* NSString+HexString.h */; }; 8231EBC61836BD3600BC41C1 /* NSString+HexString.m in Sources */ = {isa = PBXBuildFile; fileRef = 8231EBC41836BD3600BC41C1 /* NSString+HexString.m */; }; 8231EBC71836BD3600BC41C1 /* NSString+HexString.m in Sources */ = {isa = PBXBuildFile; fileRef = 8231EBC41836BD3600BC41C1 /* NSString+HexString.m */; }; - 8231EC1B1836F37F00BC41C1 /* THLine.h in Headers */ = {isa = PBXBuildFile; fileRef = 8231EC191836F37F00BC41C1 /* THLine.h */; }; - 8231EC1C1836F37F00BC41C1 /* THLine.m in Sources */ = {isa = PBXBuildFile; fileRef = 8231EC1A1836F37F00BC41C1 /* THLine.m */; }; - 8231EC1D1836F37F00BC41C1 /* THLine.m in Sources */ = {isa = PBXBuildFile; fileRef = 8231EC1A1836F37F00BC41C1 /* THLine.m */; }; + 8231EC1B1836F37F00BC41C1 /* E3XExchange.h in Headers */ = {isa = PBXBuildFile; fileRef = 8231EC191836F37F00BC41C1 /* E3XExchange.h */; }; + 8231EC1C1836F37F00BC41C1 /* E3XExchange.m in Sources */ = {isa = PBXBuildFile; fileRef = 8231EC1A1836F37F00BC41C1 /* E3XExchange.m */; }; + 8231EC1D1836F37F00BC41C1 /* E3XExchange.m in Sources */ = {isa = PBXBuildFile; fileRef = 8231EC1A1836F37F00BC41C1 /* E3XExchange.m */; }; 8236E1A718F5EDB600169201 /* THTransport.h in Headers */ = {isa = PBXBuildFile; fileRef = 8236E1A518F5EDB600169201 /* THTransport.h */; }; 8236E1A818F5EDB600169201 /* THTransport.m in Sources */ = {isa = PBXBuildFile; fileRef = 8236E1A618F5EDB600169201 /* THTransport.m */; }; 8236E1A918F5EDB600169201 /* THTransport.m in Sources */ = {isa = PBXBuildFile; fileRef = 8236E1A618F5EDB600169201 /* THTransport.m */; }; 8249D63F1905F6640009F03B /* libsodium.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8249D63E1905F6640009F03B /* libsodium.a */; }; 8249D6411905F6730009F03B /* libsodium.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8249D6401905F6730009F03B /* libsodium.a */; }; - 8249D6441906100C0009F03B /* THCipherSet3a.h in Headers */ = {isa = PBXBuildFile; fileRef = 8249D6421906100C0009F03B /* THCipherSet3a.h */; }; - 8249D6451906100C0009F03B /* THCipherSet3a.m in Sources */ = {isa = PBXBuildFile; fileRef = 8249D6431906100C0009F03B /* THCipherSet3a.m */; }; - 8249D6461906100C0009F03B /* THCipherSet3a.m in Sources */ = {isa = PBXBuildFile; fileRef = 8249D6431906100C0009F03B /* THCipherSet3a.m */; }; - 8249D649190627300009F03B /* THCipherSet2a.h in Headers */ = {isa = PBXBuildFile; fileRef = 8249D647190627300009F03B /* THCipherSet2a.h */; }; - 8249D64A190627300009F03B /* THCipherSet2a.m in Sources */ = {isa = PBXBuildFile; fileRef = 8249D648190627300009F03B /* THCipherSet2a.m */; }; - 8249D64B190627300009F03B /* THCipherSet2a.m in Sources */ = {isa = PBXBuildFile; fileRef = 8249D648190627300009F03B /* THCipherSet2a.m */; }; + 8249D6441906100C0009F03B /* E3XCipherSet3a.h in Headers */ = {isa = PBXBuildFile; fileRef = 8249D6421906100C0009F03B /* E3XCipherSet3a.h */; }; + 8249D6451906100C0009F03B /* E3XCipherSet3a.m in Sources */ = {isa = PBXBuildFile; fileRef = 8249D6431906100C0009F03B /* E3XCipherSet3a.m */; }; + 8249D6461906100C0009F03B /* E3XCipherSet3a.m in Sources */ = {isa = PBXBuildFile; fileRef = 8249D6431906100C0009F03B /* E3XCipherSet3a.m */; }; + 8249D649190627300009F03B /* E3XCipherSet2a.h in Headers */ = {isa = PBXBuildFile; fileRef = 8249D647190627300009F03B /* E3XCipherSet2a.h */; }; + 8249D64A190627300009F03B /* E3XCipherSet2a.m in Sources */ = {isa = PBXBuildFile; fileRef = 8249D648190627300009F03B /* E3XCipherSet2a.m */; }; + 8249D64B190627300009F03B /* E3XCipherSet2a.m in Sources */ = {isa = PBXBuildFile; fileRef = 8249D648190627300009F03B /* E3XCipherSet2a.m */; }; 824F74B3191061D300B4E807 /* CLCLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 824F74B1191061D300B4E807 /* CLCLog.h */; }; 824F74B4191061D300B4E807 /* CLCLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 824F74B2191061D300B4E807 /* CLCLog.m */; }; 824F74B5191061D300B4E807 /* CLCLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 824F74B2191061D300B4E807 /* CLCLog.m */; }; 8251ADB418C02349005CB9E2 /* libcryptopp-osx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8263D95B18BD16F000DED8E5 /* libcryptopp-osx.a */; }; 8251ADBA18C023DC005CB9E2 /* open.pkt in Resources */ = {isa = PBXBuildFile; fileRef = 8251ADB918C023DC005CB9E2 /* open.pkt */; }; - 8251ADBD18C05A26005CB9E2 /* THCipherSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 8251ADBB18C05A26005CB9E2 /* THCipherSet.h */; }; - 8251ADBE18C05A26005CB9E2 /* THCipherSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 8251ADBC18C05A26005CB9E2 /* THCipherSet.m */; }; - 8251ADBF18C05A26005CB9E2 /* THCipherSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 8251ADBC18C05A26005CB9E2 /* THCipherSet.m */; }; - 827CB8AB190C887F001EB8F9 /* THUnreliableChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 827CB8A9190C887F001EB8F9 /* THUnreliableChannel.h */; }; - 827CB8AC190C8880001EB8F9 /* THUnreliableChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 827CB8AA190C887F001EB8F9 /* THUnreliableChannel.m */; }; - 827CB8AD190C8880001EB8F9 /* THUnreliableChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 827CB8AA190C887F001EB8F9 /* THUnreliableChannel.m */; }; - 827CB8B4190C8890001EB8F9 /* THReliableChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 827CB8B2190C8890001EB8F9 /* THReliableChannel.h */; }; - 827CB8B5190C8890001EB8F9 /* THReliableChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 827CB8B3190C8890001EB8F9 /* THReliableChannel.m */; }; - 827CB8B6190C8890001EB8F9 /* THReliableChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 827CB8B3190C8890001EB8F9 /* THReliableChannel.m */; }; + 8251ADBD18C05A26005CB9E2 /* E3XCipherSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 8251ADBB18C05A26005CB9E2 /* E3XCipherSet.h */; }; + 8251ADBE18C05A26005CB9E2 /* E3XCipherSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 8251ADBC18C05A26005CB9E2 /* E3XCipherSet.m */; }; + 8251ADBF18C05A26005CB9E2 /* E3XCipherSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 8251ADBC18C05A26005CB9E2 /* E3XCipherSet.m */; }; + 827CB8AB190C887F001EB8F9 /* E3XUnreliableChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 827CB8A9190C887F001EB8F9 /* E3XUnreliableChannel.h */; }; + 827CB8AC190C8880001EB8F9 /* E3XUnreliableChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 827CB8AA190C887F001EB8F9 /* E3XUnreliableChannel.m */; }; + 827CB8AD190C8880001EB8F9 /* E3XUnreliableChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 827CB8AA190C887F001EB8F9 /* E3XUnreliableChannel.m */; }; + 827CB8B4190C8890001EB8F9 /* E3XReliableChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 827CB8B2190C8890001EB8F9 /* E3XReliableChannel.h */; }; + 827CB8B5190C8890001EB8F9 /* E3XReliableChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 827CB8B3190C8890001EB8F9 /* E3XReliableChannel.m */; }; + 827CB8B6190C8890001EB8F9 /* E3XReliableChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 827CB8B3190C8890001EB8F9 /* E3XReliableChannel.m */; }; 8298FF4918C5B5B0009CD379 /* GCMAES256.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8298FF4718C5B5B0009CD379 /* GCMAES256.mm */; }; 8298FF4A18C5B5B0009CD379 /* GCMAES256.h in Headers */ = {isa = PBXBuildFile; fileRef = 8298FF4818C5B5B0009CD379 /* GCMAES256.h */; }; 8298FF4F18C5B5B4009CD379 /* GCMAES256.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8298FF4718C5B5B0009CD379 /* GCMAES256.mm */; }; @@ -88,24 +88,21 @@ 82A31BA4183457EB005077AD /* NSData+HexString.m in Sources */ = {isa = PBXBuildFile; fileRef = 82A31BA2183457EB005077AD /* NSData+HexString.m */; }; 82A31BA5183457EB005077AD /* NSData+HexString.m in Sources */ = {isa = PBXBuildFile; fileRef = 82A31BA2183457EB005077AD /* NSData+HexString.m */; }; 82B1720317FDE18F00C29EAF /* test.pkt in Resources */ = {isa = PBXBuildFile; fileRef = 82B1720217FDE18F00C29EAF /* test.pkt */; }; - 82B1720617FDE90600C29EAF /* THSwitch.h in Headers */ = {isa = PBXBuildFile; fileRef = 82B1720417FDE90600C29EAF /* THSwitch.h */; }; - 82B1720717FDE90600C29EAF /* THSwitch.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B1720517FDE90600C29EAF /* THSwitch.m */; }; - 82B1720817FDE90600C29EAF /* THSwitch.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B1720517FDE90600C29EAF /* THSwitch.m */; }; - 82B1720B180095B100C29EAF /* THChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 82B17209180095B100C29EAF /* THChannel.h */; }; - 82B1720C180095B100C29EAF /* THChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B1720A180095B100C29EAF /* THChannel.m */; }; - 82B1720D180095B100C29EAF /* THChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B1720A180095B100C29EAF /* THChannel.m */; }; + 82B1720617FDE90600C29EAF /* THMesh.h in Headers */ = {isa = PBXBuildFile; fileRef = 82B1720417FDE90600C29EAF /* THMesh.h */; }; + 82B1720717FDE90600C29EAF /* THMesh.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B1720517FDE90600C29EAF /* THMesh.m */; }; + 82B1720817FDE90600C29EAF /* THMesh.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B1720517FDE90600C29EAF /* THMesh.m */; }; + 82B1720B180095B100C29EAF /* E3XChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 82B17209180095B100C29EAF /* E3XChannel.h */; }; + 82B1720C180095B100C29EAF /* E3XChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B1720A180095B100C29EAF /* E3XChannel.m */; }; + 82B1720D180095B100C29EAF /* E3XChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B1720A180095B100C29EAF /* E3XChannel.m */; }; 82B1721018009A6C00C29EAF /* GCDAsyncUdpSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 82B1720E18009A6C00C29EAF /* GCDAsyncUdpSocket.h */; }; 82B1721118009A6C00C29EAF /* GCDAsyncUdpSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B1720F18009A6C00C29EAF /* GCDAsyncUdpSocket.m */; }; 82B1721218009A6C00C29EAF /* GCDAsyncUdpSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B1720F18009A6C00C29EAF /* GCDAsyncUdpSocket.m */; }; - 82B172151800A51B00C29EAF /* THIdentity.h in Headers */ = {isa = PBXBuildFile; fileRef = 82B172131800A51B00C29EAF /* THIdentity.h */; }; - 82B172161800A51B00C29EAF /* THIdentity.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B172141800A51B00C29EAF /* THIdentity.m */; }; - 82B172171800A51B00C29EAF /* THIdentity.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B172141800A51B00C29EAF /* THIdentity.m */; }; + 82B172151800A51B00C29EAF /* THLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 82B172131800A51B00C29EAF /* THLink.h */; }; + 82B172161800A51B00C29EAF /* THLink.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B172141800A51B00C29EAF /* THLink.m */; }; + 82B172171800A51B00C29EAF /* THLink.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B172141800A51B00C29EAF /* THLink.m */; }; 82B70ACE18404D4900E819F3 /* THPacketBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 82B70ACC18404D4900E819F3 /* THPacketBuffer.h */; }; 82B70ACF18404D4900E819F3 /* THPacketBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B70ACD18404D4900E819F3 /* THPacketBuffer.m */; }; 82B70AD018404D4900E819F3 /* THPacketBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B70ACD18404D4900E819F3 /* THPacketBuffer.m */; }; - 82DB236B187C8343002C74C9 /* THMeshBuckets.h in Headers */ = {isa = PBXBuildFile; fileRef = 82DB2369187C8343002C74C9 /* THMeshBuckets.h */; }; - 82DB236C187C8343002C74C9 /* THMeshBuckets.m in Sources */ = {isa = PBXBuildFile; fileRef = 82DB236A187C8343002C74C9 /* THMeshBuckets.m */; }; - 82DB236D187C8343002C74C9 /* THMeshBuckets.m in Sources */ = {isa = PBXBuildFile; fileRef = 82DB236A187C8343002C74C9 /* THMeshBuckets.m */; }; 82DB2375187C83E4002C74C9 /* THPendingJob.h in Headers */ = {isa = PBXBuildFile; fileRef = 82DB2373187C83E4002C74C9 /* THPendingJob.h */; }; 82DB2376187C83E4002C74C9 /* THPendingJob.m in Sources */ = {isa = PBXBuildFile; fileRef = 82DB2374187C83E4002C74C9 /* THPendingJob.m */; }; 82DB2377187C83E4002C74C9 /* THPendingJob.m in Sources */ = {isa = PBXBuildFile; fileRef = 82DB2374187C83E4002C74C9 /* THPendingJob.m */; }; @@ -246,25 +243,25 @@ 8231EBC31836BD3600BC41C1 /* NSString+HexString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+HexString.h"; sourceTree = ""; }; 8231EBC41836BD3600BC41C1 /* NSString+HexString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+HexString.m"; sourceTree = ""; }; 8231EC081836C60D00BC41C1 /* Telehash Playground.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "Telehash Playground.xcodeproj"; path = "Telehash Playground/Telehash Playground.xcodeproj"; sourceTree = ""; }; - 8231EC191836F37F00BC41C1 /* THLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THLine.h; sourceTree = ""; }; - 8231EC1A1836F37F00BC41C1 /* THLine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THLine.m; sourceTree = ""; }; + 8231EC191836F37F00BC41C1 /* E3XExchange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = E3XExchange.h; sourceTree = ""; }; + 8231EC1A1836F37F00BC41C1 /* E3XExchange.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = E3XExchange.m; sourceTree = ""; }; 8236E1A518F5EDB600169201 /* THTransport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THTransport.h; sourceTree = ""; }; 8236E1A618F5EDB600169201 /* THTransport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THTransport.m; sourceTree = ""; }; 8249D63E1905F6640009F03B /* libsodium.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libsodium.a; path = libsodium/build/lib/libsodium.a; sourceTree = ""; }; 8249D6401905F6730009F03B /* libsodium.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libsodium.a; path = "libsodium/build-ios/lib/libsodium.a"; sourceTree = ""; }; - 8249D6421906100C0009F03B /* THCipherSet3a.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THCipherSet3a.h; sourceTree = ""; }; - 8249D6431906100C0009F03B /* THCipherSet3a.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THCipherSet3a.m; sourceTree = ""; }; - 8249D647190627300009F03B /* THCipherSet2a.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THCipherSet2a.h; sourceTree = ""; }; - 8249D648190627300009F03B /* THCipherSet2a.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THCipherSet2a.m; sourceTree = ""; }; + 8249D6421906100C0009F03B /* E3XCipherSet3a.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = E3XCipherSet3a.h; sourceTree = ""; }; + 8249D6431906100C0009F03B /* E3XCipherSet3a.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = E3XCipherSet3a.m; sourceTree = ""; }; + 8249D647190627300009F03B /* E3XCipherSet2a.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = E3XCipherSet2a.h; sourceTree = ""; }; + 8249D648190627300009F03B /* E3XCipherSet2a.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = E3XCipherSet2a.m; sourceTree = ""; }; 824F74B1191061D300B4E807 /* CLCLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CLCLog.h; sourceTree = ""; }; 824F74B2191061D300B4E807 /* CLCLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CLCLog.m; sourceTree = ""; }; 8251ADB918C023DC005CB9E2 /* open.pkt */ = {isa = PBXFileReference; lastKnownFileType = file; path = open.pkt; sourceTree = ""; }; - 8251ADBB18C05A26005CB9E2 /* THCipherSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THCipherSet.h; sourceTree = ""; }; - 8251ADBC18C05A26005CB9E2 /* THCipherSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THCipherSet.m; sourceTree = ""; }; - 827CB8A9190C887F001EB8F9 /* THUnreliableChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THUnreliableChannel.h; sourceTree = ""; }; - 827CB8AA190C887F001EB8F9 /* THUnreliableChannel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THUnreliableChannel.m; sourceTree = ""; }; - 827CB8B2190C8890001EB8F9 /* THReliableChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THReliableChannel.h; sourceTree = ""; }; - 827CB8B3190C8890001EB8F9 /* THReliableChannel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THReliableChannel.m; sourceTree = ""; }; + 8251ADBB18C05A26005CB9E2 /* E3XCipherSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = E3XCipherSet.h; sourceTree = ""; }; + 8251ADBC18C05A26005CB9E2 /* E3XCipherSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = E3XCipherSet.m; sourceTree = ""; }; + 827CB8A9190C887F001EB8F9 /* E3XUnreliableChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = E3XUnreliableChannel.h; sourceTree = ""; }; + 827CB8AA190C887F001EB8F9 /* E3XUnreliableChannel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = E3XUnreliableChannel.m; sourceTree = ""; }; + 827CB8B2190C8890001EB8F9 /* E3XReliableChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = E3XReliableChannel.h; sourceTree = ""; }; + 827CB8B3190C8890001EB8F9 /* E3XReliableChannel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = E3XReliableChannel.m; sourceTree = ""; }; 8298FF4718C5B5B0009CD379 /* GCMAES256.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GCMAES256.mm; sourceTree = ""; }; 8298FF4818C5B5B0009CD379 /* GCMAES256.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCMAES256.h; sourceTree = ""; }; 8298FF5C18C83ECB009CD379 /* server.der */ = {isa = PBXFileReference; lastKnownFileType = file; path = server.der; sourceTree = ""; }; @@ -272,19 +269,17 @@ 82A31BA1183457EB005077AD /* NSData+HexString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+HexString.h"; sourceTree = ""; }; 82A31BA2183457EB005077AD /* NSData+HexString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+HexString.m"; sourceTree = ""; }; 82B1720217FDE18F00C29EAF /* test.pkt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file; path = test.pkt; sourceTree = ""; }; - 82B1720417FDE90600C29EAF /* THSwitch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THSwitch.h; sourceTree = ""; }; - 82B1720517FDE90600C29EAF /* THSwitch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THSwitch.m; sourceTree = ""; }; - 82B17209180095B100C29EAF /* THChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THChannel.h; sourceTree = ""; }; - 82B1720A180095B100C29EAF /* THChannel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THChannel.m; sourceTree = ""; }; + 82B1720417FDE90600C29EAF /* THMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THMesh.h; sourceTree = ""; }; + 82B1720517FDE90600C29EAF /* THMesh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THMesh.m; sourceTree = ""; }; + 82B17209180095B100C29EAF /* E3XChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = E3XChannel.h; sourceTree = ""; }; + 82B1720A180095B100C29EAF /* E3XChannel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = E3XChannel.m; sourceTree = ""; }; 82B1720E18009A6C00C29EAF /* GCDAsyncUdpSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDAsyncUdpSocket.h; sourceTree = ""; }; 82B1720F18009A6C00C29EAF /* GCDAsyncUdpSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDAsyncUdpSocket.m; sourceTree = ""; }; - 82B172131800A51B00C29EAF /* THIdentity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THIdentity.h; sourceTree = ""; }; - 82B172141800A51B00C29EAF /* THIdentity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THIdentity.m; sourceTree = ""; }; + 82B172131800A51B00C29EAF /* THLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THLink.h; sourceTree = ""; }; + 82B172141800A51B00C29EAF /* THLink.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THLink.m; sourceTree = ""; }; 82B70ACC18404D4900E819F3 /* THPacketBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THPacketBuffer.h; sourceTree = ""; }; 82B70ACD18404D4900E819F3 /* THPacketBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THPacketBuffer.m; sourceTree = ""; }; 82D221361871D3630015E7EA /* cryptopp.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = cryptopp.xcodeproj; path = cryptopp/cryptopp/cryptopp.xcodeproj; sourceTree = ""; }; - 82DB2369187C8343002C74C9 /* THMeshBuckets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THMeshBuckets.h; sourceTree = ""; }; - 82DB236A187C8343002C74C9 /* THMeshBuckets.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THMeshBuckets.m; sourceTree = ""; }; 82DB2373187C83E4002C74C9 /* THPendingJob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THPendingJob.h; sourceTree = ""; }; 82DB2374187C83E4002C74C9 /* THPendingJob.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THPendingJob.m; sourceTree = ""; }; 82EF372F1927AF3D001D3DB4 /* THRelay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THRelay.h; sourceTree = ""; }; @@ -501,40 +496,38 @@ 824F74B2191061D300B4E807 /* CLCLog.m */, 82B1720E18009A6C00C29EAF /* GCDAsyncUdpSocket.h */, 82B1720F18009A6C00C29EAF /* GCDAsyncUdpSocket.m */, - 82B1720417FDE90600C29EAF /* THSwitch.h */, - 82B1720517FDE90600C29EAF /* THSwitch.m */, - 82DB2369187C8343002C74C9 /* THMeshBuckets.h */, - 82DB236A187C8343002C74C9 /* THMeshBuckets.m */, - 82B172131800A51B00C29EAF /* THIdentity.h */, - 82B172141800A51B00C29EAF /* THIdentity.m */, + 82B1720417FDE90600C29EAF /* THMesh.h */, + 82B1720517FDE90600C29EAF /* THMesh.m */, + 82B172131800A51B00C29EAF /* THLink.h */, + 82B172141800A51B00C29EAF /* THLink.m */, 820BADFA18D81476003D7CBA /* THPath.h */, 820BADFB18D81476003D7CBA /* THPath.m */, 8236E1A518F5EDB600169201 /* THTransport.h */, 8236E1A618F5EDB600169201 /* THTransport.m */, - 8231EC191836F37F00BC41C1 /* THLine.h */, - 8231EC1A1836F37F00BC41C1 /* THLine.m */, + 8231EC191836F37F00BC41C1 /* E3XExchange.h */, + 8231EC1A1836F37F00BC41C1 /* E3XExchange.m */, 82EF372F1927AF3D001D3DB4 /* THRelay.h */, 82EF37301927AF3D001D3DB4 /* THRelay.m */, 820BADF118D77EFA003D7CBA /* THPeerRelay.h */, 820BADF218D77EFA003D7CBA /* THPeerRelay.m */, - 82B17209180095B100C29EAF /* THChannel.h */, - 82B1720A180095B100C29EAF /* THChannel.m */, - 827CB8A9190C887F001EB8F9 /* THUnreliableChannel.h */, - 827CB8AA190C887F001EB8F9 /* THUnreliableChannel.m */, - 827CB8B2190C8890001EB8F9 /* THReliableChannel.h */, - 827CB8B3190C8890001EB8F9 /* THReliableChannel.m */, + 82B17209180095B100C29EAF /* E3XChannel.h */, + 82B1720A180095B100C29EAF /* E3XChannel.m */, + 827CB8A9190C887F001EB8F9 /* E3XUnreliableChannel.h */, + 827CB8AA190C887F001EB8F9 /* E3XUnreliableChannel.m */, + 827CB8B2190C8890001EB8F9 /* E3XReliableChannel.h */, + 827CB8B3190C8890001EB8F9 /* E3XReliableChannel.m */, 822C6D4217FCDB31008C04BA /* THPacket.h */, 822C6D4317FCDB31008C04BA /* THPacket.m */, 82B70ACC18404D4900E819F3 /* THPacketBuffer.h */, 82B70ACD18404D4900E819F3 /* THPacketBuffer.m */, 82DB2373187C83E4002C74C9 /* THPendingJob.h */, 82DB2374187C83E4002C74C9 /* THPendingJob.m */, - 8251ADBB18C05A26005CB9E2 /* THCipherSet.h */, - 8251ADBC18C05A26005CB9E2 /* THCipherSet.m */, - 8249D6421906100C0009F03B /* THCipherSet3a.h */, - 8249D6431906100C0009F03B /* THCipherSet3a.m */, - 8249D647190627300009F03B /* THCipherSet2a.h */, - 8249D648190627300009F03B /* THCipherSet2a.m */, + 8251ADBB18C05A26005CB9E2 /* E3XCipherSet.h */, + 8251ADBC18C05A26005CB9E2 /* E3XCipherSet.m */, + 8249D6421906100C0009F03B /* E3XCipherSet3a.h */, + 8249D6431906100C0009F03B /* E3XCipherSet3a.m */, + 8249D647190627300009F03B /* E3XCipherSet2a.h */, + 8249D648190627300009F03B /* E3XCipherSet2a.m */, 82A31BA1183457EB005077AD /* NSData+HexString.h */, 82A31BA2183457EB005077AD /* NSData+HexString.m */, 8231EBC31836BD3600BC41C1 /* NSString+HexString.h */, @@ -568,32 +561,31 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 8251ADBD18C05A26005CB9E2 /* THCipherSet.h in Headers */, + 8251ADBD18C05A26005CB9E2 /* E3XCipherSet.h in Headers */, 82DB2375187C83E4002C74C9 /* THPendingJob.h in Headers */, 820BADF318D77EFA003D7CBA /* THPeerRelay.h in Headers */, 8236E1A718F5EDB600169201 /* THTransport.h in Headers */, 82B70ACE18404D4900E819F3 /* THPacketBuffer.h in Headers */, - 82DB236B187C8343002C74C9 /* THMeshBuckets.h in Headers */, 822C6D2F17FCCD0C008C04BA /* ECDH.h in Headers */, 8218D1C217FA6F410053AFAC /* THRSA.h in Headers */, 822C6D3417FCD3F6008C04BA /* CTRAES256.h in Headers */, - 8249D649190627300009F03B /* THCipherSet2a.h in Headers */, + 8249D649190627300009F03B /* E3XCipherSet2a.h in Headers */, 822C6D3E17FCD8C5008C04BA /* RNG.h in Headers */, 82B1721018009A6C00C29EAF /* GCDAsyncUdpSocket.h in Headers */, - 8231EC1B1836F37F00BC41C1 /* THLine.h in Headers */, + 8231EC1B1836F37F00BC41C1 /* E3XExchange.h in Headers */, 8298FF4A18C5B5B0009CD379 /* GCMAES256.h in Headers */, 824F74B3191061D300B4E807 /* CLCLog.h in Headers */, 822C6D4417FCDB31008C04BA /* THPacket.h in Headers */, 822C6D3917FCD754008C04BA /* SHA256.h in Headers */, - 82B1720B180095B100C29EAF /* THChannel.h in Headers */, - 8249D6441906100C0009F03B /* THCipherSet3a.h in Headers */, - 827CB8B4190C8890001EB8F9 /* THReliableChannel.h in Headers */, - 82B172151800A51B00C29EAF /* THIdentity.h in Headers */, - 827CB8AB190C887F001EB8F9 /* THUnreliableChannel.h in Headers */, + 82B1720B180095B100C29EAF /* E3XChannel.h in Headers */, + 8249D6441906100C0009F03B /* E3XCipherSet3a.h in Headers */, + 827CB8B4190C8890001EB8F9 /* E3XReliableChannel.h in Headers */, + 82B172151800A51B00C29EAF /* THLink.h in Headers */, + 827CB8AB190C887F001EB8F9 /* E3XUnreliableChannel.h in Headers */, 82EF37311927AF3D001D3DB4 /* THRelay.h in Headers */, 8231EBC51836BD3600BC41C1 /* NSString+HexString.h in Headers */, 82A31BA3183457EB005077AD /* NSData+HexString.h in Headers */, - 82B1720617FDE90600C29EAF /* THSwitch.h in Headers */, + 82B1720617FDE90600C29EAF /* THMesh.h in Headers */, 820BADFC18D81476003D7CBA /* THPath.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -798,29 +790,28 @@ 820BADF418D77EFA003D7CBA /* THPeerRelay.m in Sources */, 822C6D4517FCDB31008C04BA /* THPacket.m in Sources */, 822C6D3A17FCD754008C04BA /* SHA256.mm in Sources */, - 8251ADBE18C05A26005CB9E2 /* THCipherSet.m in Sources */, - 8231EC1C1836F37F00BC41C1 /* THLine.m in Sources */, - 82DB236C187C8343002C74C9 /* THMeshBuckets.m in Sources */, - 827CB8AC190C8880001EB8F9 /* THUnreliableChannel.m in Sources */, - 82B1720717FDE90600C29EAF /* THSwitch.m in Sources */, - 8249D64A190627300009F03B /* THCipherSet2a.m in Sources */, + 8251ADBE18C05A26005CB9E2 /* E3XCipherSet.m in Sources */, + 8231EC1C1836F37F00BC41C1 /* E3XExchange.m in Sources */, + 827CB8AC190C8880001EB8F9 /* E3XUnreliableChannel.m in Sources */, + 82B1720717FDE90600C29EAF /* THMesh.m in Sources */, + 8249D64A190627300009F03B /* E3XCipherSet2a.m in Sources */, 822C6D3517FCD3F6008C04BA /* CTRAES256.mm in Sources */, - 8249D6451906100C0009F03B /* THCipherSet3a.m in Sources */, + 8249D6451906100C0009F03B /* E3XCipherSet3a.m in Sources */, 8236E1A818F5EDB600169201 /* THTransport.m in Sources */, 82EF37321927AF3D001D3DB4 /* THRelay.m in Sources */, 82DB2376187C83E4002C74C9 /* THPendingJob.m in Sources */, 8231EBC61836BD3600BC41C1 /* NSString+HexString.m in Sources */, 820BADFD18D81476003D7CBA /* THPath.m in Sources */, - 82B1720C180095B100C29EAF /* THChannel.m in Sources */, + 82B1720C180095B100C29EAF /* E3XChannel.m in Sources */, 82B70ACF18404D4900E819F3 /* THPacketBuffer.m in Sources */, 82B1721118009A6C00C29EAF /* GCDAsyncUdpSocket.m in Sources */, - 827CB8B5190C8890001EB8F9 /* THReliableChannel.m in Sources */, + 827CB8B5190C8890001EB8F9 /* E3XReliableChannel.m in Sources */, 82A31BA4183457EB005077AD /* NSData+HexString.m in Sources */, 822C6D3F17FCD8C5008C04BA /* RNG.mm in Sources */, 824F74B4191061D300B4E807 /* CLCLog.m in Sources */, 822C6D3017FCCD0C008C04BA /* ECDH.mm in Sources */, 8218D17B17FA6E8A0053AFAC /* telehash.m in Sources */, - 82B172161800A51B00C29EAF /* THIdentity.m in Sources */, + 82B172161800A51B00C29EAF /* THLink.m in Sources */, 8298FF4918C5B5B0009CD379 /* GCMAES256.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -841,29 +832,28 @@ 820BADF518D77EFA003D7CBA /* THPeerRelay.m in Sources */, 822C6D4617FCDB31008C04BA /* THPacket.m in Sources */, 822C6D3B17FCD754008C04BA /* SHA256.mm in Sources */, - 8251ADBF18C05A26005CB9E2 /* THCipherSet.m in Sources */, - 8231EC1D1836F37F00BC41C1 /* THLine.m in Sources */, - 82DB236D187C8343002C74C9 /* THMeshBuckets.m in Sources */, - 827CB8AD190C8880001EB8F9 /* THUnreliableChannel.m in Sources */, - 82B1720817FDE90600C29EAF /* THSwitch.m in Sources */, - 8249D64B190627300009F03B /* THCipherSet2a.m in Sources */, + 8251ADBF18C05A26005CB9E2 /* E3XCipherSet.m in Sources */, + 8231EC1D1836F37F00BC41C1 /* E3XExchange.m in Sources */, + 827CB8AD190C8880001EB8F9 /* E3XUnreliableChannel.m in Sources */, + 82B1720817FDE90600C29EAF /* THMesh.m in Sources */, + 8249D64B190627300009F03B /* E3XCipherSet2a.m in Sources */, 822C6D3617FCD3F6008C04BA /* CTRAES256.mm in Sources */, - 8249D6461906100C0009F03B /* THCipherSet3a.m in Sources */, + 8249D6461906100C0009F03B /* E3XCipherSet3a.m in Sources */, 8236E1A918F5EDB600169201 /* THTransport.m in Sources */, 82EF37331927AF3D001D3DB4 /* THRelay.m in Sources */, 82DB2377187C83E4002C74C9 /* THPendingJob.m in Sources */, 8231EBC71836BD3600BC41C1 /* NSString+HexString.m in Sources */, 820BADFE18D81476003D7CBA /* THPath.m in Sources */, - 82B1720D180095B100C29EAF /* THChannel.m in Sources */, + 82B1720D180095B100C29EAF /* E3XChannel.m in Sources */, 82B70AD018404D4900E819F3 /* THPacketBuffer.m in Sources */, 82B1721218009A6C00C29EAF /* GCDAsyncUdpSocket.m in Sources */, - 827CB8B6190C8890001EB8F9 /* THReliableChannel.m in Sources */, + 827CB8B6190C8890001EB8F9 /* E3XReliableChannel.m in Sources */, 82A31BA5183457EB005077AD /* NSData+HexString.m in Sources */, 822C6D4017FCD8C5008C04BA /* RNG.mm in Sources */, 824F74B5191061D300B4E807 /* CLCLog.m in Sources */, 822C6D3117FCCD0C008C04BA /* ECDH.mm in Sources */, 8218D1A417FA6EA50053AFAC /* telehash_ios.m in Sources */, - 82B172171800A51B00C29EAF /* THIdentity.m in Sources */, + 82B172171800A51B00C29EAF /* THLink.m in Sources */, 8298FF4F18C5B5B4009CD379 /* GCMAES256.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1014,8 +1004,12 @@ "$(inherited)", "$(PROJECT_DIR)/cryptopp", "$(PROJECT_DIR)/libsodium/build/include", + /usr/local/include, + ); + LIBRARY_SEARCH_PATHS = ( + "$(PROJECT_DIR)/libsodium/build/lib", + /usr/local/lib, ); - LIBRARY_SEARCH_PATHS = "$(PROJECT_DIR)/libsodium/build/lib"; OTHER_LDFLAGS = ""; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -1030,8 +1024,12 @@ "$(inherited)", "$(PROJECT_DIR)/cryptopp", "$(PROJECT_DIR)/libsodium/build/include", + /usr/local/include, + ); + LIBRARY_SEARCH_PATHS = ( + "$(PROJECT_DIR)/libsodium/build/lib", + /usr/local/lib, ); - LIBRARY_SEARCH_PATHS = "$(PROJECT_DIR)/libsodium/build/lib"; OTHER_LDFLAGS = ""; PRODUCT_NAME = "$(TARGET_NAME)"; }; diff --git a/telehashTests/telehashTests.m b/telehashTests/telehashTests.m index 517cdbd..e6dd258 100644 --- a/telehashTests/telehashTests.m +++ b/telehashTests/telehashTests.m @@ -8,13 +8,13 @@ #import #import "THPacket.h" -#import "THSwitch.h" -#import "THIdentity.h" +#import "THMesh.h" +#import "THLink.h" #import "THPacketBuffer.h" -#import "THCipherSet.h" +#import "E3XCipherSet.h" #import "THPath.h" -#import "THReliableChannel.h" -#import "THChannel.h" +#import "E3XReliableChannel.h" +#import "E3XChannel.h" #include @interface telehashTests : XCTestCase @@ -86,10 +86,10 @@ -(void)testPacketCreation -(void)testIdentityDistance { - THIdentity* origin = [THIdentity new]; + THLink* origin = [THLink new]; [origin setValue:@"736711cf55ff95fa967aa980855a0ee9f7af47d6287374a8cd65e1a36171ef08" forKey:@"_hashnameCache"]; - THIdentity* remote = [THIdentity new]; + THLink* remote = [THLink new]; [remote setValue:@"73654507a9fd1202c6a9381b626d1903a36eafe8a6240bcc726fc668a35d6268" forKey:@"_hashnameCache"]; XCTAssert([origin distanceFrom:remote] == 241, @"Distance should be 241 got %ld", [origin distanceFrom:remote]); @@ -195,8 +195,8 @@ -(void)testPacketBufferMissing; -(void)testReliableChannelSeq { - THIdentity* testIdentity = [THIdentity identityFromHashname:@"abcdef1234567890abcdef1234567890"]; - THReliableChannel* testChannel = [[THReliableChannel alloc] initToIdentity:testIdentity]; + THLink* testIdentity = [THLink identityFromHashname:@"abcdef1234567890abcdef1234567890"]; + E3XReliableChannel* testChannel = [[E3XReliableChannel alloc] initToIdentity:testIdentity]; testChannel.channelId = @42; THPacket* testPacket = [THPacket new];