Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
telehash.xcodeproj/project.xcworkspace/xcshareddata/

#########################
# .gitignore file for Xcode4 and Xcode5 Source projects
#
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: objective-c
xcode_project: telehash.xcodeproj
xcode_scheme: telehashTests
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
--------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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 = (
Expand Down
10 changes: 5 additions & 5 deletions Telehash Playground/Telehash Playground/THAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

#import <Cocoa/Cocoa.h>
#import <THSwitch.h>
#import <THChannel.h>
#import <THMesh.h>
#import <E3XChannel.h>

@interface THAppDelegate : NSObject <THSwitchDelegate, THChannelDelegate, NSTableViewDataSource, NSTableViewDelegate> {
IBOutlet NSTableView* tableView;
Expand All @@ -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;
Expand Down
48 changes: 24 additions & 24 deletions Telehash Playground/Telehash Playground/THAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
//

#import "THAppDelegate.h"
#import "THIdentity.h"
#import "THLink.h"
#import <THPacket.h>
#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 <THReliableChannel.h>
#import "E3XChannel.h"
#import "E3XCipherSet2a.h"
#import "E3XCipherSet3a.h"
#import <E3XReliableChannel.h>
#import <CLCLog.h>

#include <arpa/inet.h>
Expand All @@ -26,7 +26,7 @@

@interface THAppDelegate () {
NSString* startChannelId;
THReliableChannel* pingChannel;
E3XReliableChannel* pingChannel;
}
@end

Expand All @@ -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]];
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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) {
/*
Expand All @@ -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) {
Expand All @@ -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"]) {
Expand Down
22 changes: 11 additions & 11 deletions common/THChannel.h → common/E3XChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

#import <Foundation/Foundation.h>
#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 {
Expand All @@ -31,19 +31,19 @@ typedef enum {

@protocol THChannelDelegate <NSObject>
#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<THChannelDelegate> delegate;
@property THIdentity* toIdentity;
@property THLine* line;
@property THLink* toIdentity;
@property E3XExchange* line;
@property NSNumber* channelId;
@property THChannelState state;
@property THChannelDirection direction;
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions common/THChannel.m → common/E3XChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions common/THCipherSet.h → common/E3XCipherSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
#import <Foundation/Foundation.h>

@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
22 changes: 11 additions & 11 deletions common/THCipherSet.m → common/E3XCipherSet.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,7 +40,7 @@ -(NSString*)identifier
return nil;
}

-(void)finalizeLineKeys:(THLine *)line
-(void)finalizeLineKeys:(E3XExchange *)line
{
CLCLogError(@"Not implemented THCipherSet finalizeKeys");
}
Expand Down
Loading