Permalink
Browse files

tor integration

  • Loading branch information...
1 parent a55dfbc commit c16bc346084d825bfe55583d3ef6817aaf343610 @mtigas committed Feb 25, 2012
@@ -13,6 +13,11 @@
696EBD8214F7877900B81BC9 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 696EBD8014F7877900B81BC9 /* InfoPlist.strings */; };
696EBD8414F7877900B81BC9 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 696EBD8314F7877900B81BC9 /* main.m */; };
696EBD8814F7877900B81BC9 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 696EBD8714F7877900B81BC9 /* AppDelegate.m */; };
+ 696F9EAB14F8D5A900BC5FDC /* TorWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 696F9EA914F8D51300BC5FDC /* TorWrapper.m */; };
+ 696F9EAE14F8D6ED00BC5FDC /* tor_main.c in Sources */ = {isa = PBXBuildFile; fileRef = 696F9EAD14F8D6ED00BC5FDC /* tor_main.c */; };
+ 696F9EB014F8DA6900BC5FDC /* torrc in Resources */ = {isa = PBXBuildFile; fileRef = 696F9EAF14F8DA6900BC5FDC /* torrc */; };
+ 696F9EB414F8DD6D00BC5FDC /* ULINetSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 696F9EB314F8DD6D00BC5FDC /* ULINetSocket.m */; };
+ 696F9EB614F8E21200BC5FDC /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 696F9EB514F8E21200BC5FDC /* CFNetwork.framework */; };
69847C4714F788E100288277 /* libcrypto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 69847C3C14F788E100288277 /* libcrypto.a */; };
69847C4814F788E100288277 /* libevent_core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 69847C3D14F788E100288277 /* libevent_core.a */; };
69847C4914F788E100288277 /* libevent_extra.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 69847C3E14F788E100288277 /* libevent_extra.a */; };
@@ -38,6 +43,13 @@
696EBD8514F7877900B81BC9 /* OnionBrowser-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OnionBrowser-Prefix.pch"; sourceTree = "<group>"; };
696EBD8614F7877900B81BC9 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
696EBD8714F7877900B81BC9 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
+ 696F9EA814F8D51300BC5FDC /* TorWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TorWrapper.h; sourceTree = "<group>"; };
+ 696F9EA914F8D51300BC5FDC /* TorWrapper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TorWrapper.m; sourceTree = "<group>"; };
+ 696F9EAD14F8D6ED00BC5FDC /* tor_main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tor_main.c; sourceTree = "<group>"; };
+ 696F9EAF14F8DA6900BC5FDC /* torrc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = torrc; sourceTree = "<group>"; };
+ 696F9EB214F8DD6D00BC5FDC /* ULINetSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ULINetSocket.h; sourceTree = "<group>"; };
+ 696F9EB314F8DD6D00BC5FDC /* ULINetSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ULINetSocket.m; sourceTree = "<group>"; };
+ 696F9EB514F8E21200BC5FDC /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
69847C3C14F788E100288277 /* libcrypto.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcrypto.a; path = ../dependencies/lib/libcrypto.a; sourceTree = "<group>"; };
69847C3D14F788E100288277 /* libevent_core.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libevent_core.a; path = ../dependencies/lib/libevent_core.a; sourceTree = "<group>"; };
69847C3E14F788E100288277 /* libevent_extra.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libevent_extra.a; path = ../dependencies/lib/libevent_extra.a; sourceTree = "<group>"; };
@@ -60,6 +72,7 @@
696EBD7814F7877900B81BC9 /* UIKit.framework in Frameworks */,
696EBD7A14F7877900B81BC9 /* Foundation.framework in Frameworks */,
696EBD7C14F7877900B81BC9 /* CoreGraphics.framework in Frameworks */,
+ 696F9EB614F8E21200BC5FDC /* CFNetwork.framework in Frameworks */,
69847C5414F788E900288277 /* libz.dylib in Frameworks */,
69847C4714F788E100288277 /* libcrypto.a in Frameworks */,
69847C4814F788E100288277 /* libevent_core.a in Frameworks */,
@@ -81,6 +94,8 @@
696EBD6814F7877900B81BC9 = {
isa = PBXGroup;
children = (
+ 696F9EB114F8DD5300BC5FDC /* ThirdParty */,
+ 69BB0A4C14F8D31800E7E909 /* Tor */,
696EBD7D14F7877900B81BC9 /* OnionBrowser */,
696EBD7614F7877900B81BC9 /* Frameworks */,
696EBD7414F7877900B81BC9 /* Products */,
@@ -103,6 +118,7 @@
696EBD7714F7877900B81BC9 /* UIKit.framework */,
696EBD7914F7877900B81BC9 /* Foundation.framework */,
696EBD7B14F7877900B81BC9 /* CoreGraphics.framework */,
+ 696F9EB514F8E21200BC5FDC /* CFNetwork.framework */,
);
name = Frameworks;
sourceTree = "<group>";
@@ -128,6 +144,15 @@
name = "Supporting Files";
sourceTree = "<group>";
};
+ 696F9EB114F8DD5300BC5FDC /* ThirdParty */ = {
+ isa = PBXGroup;
+ children = (
+ 696F9EB214F8DD6D00BC5FDC /* ULINetSocket.h */,
+ 696F9EB314F8DD6D00BC5FDC /* ULINetSocket.m */,
+ );
+ name = ThirdParty;
+ sourceTree = "<group>";
+ };
69847C5514F788F600288277 /* Dependencies */ = {
isa = PBXGroup;
children = (
@@ -146,6 +171,17 @@
name = Dependencies;
sourceTree = "<group>";
};
+ 69BB0A4C14F8D31800E7E909 /* Tor */ = {
+ isa = PBXGroup;
+ children = (
+ 696F9EA814F8D51300BC5FDC /* TorWrapper.h */,
+ 696F9EA914F8D51300BC5FDC /* TorWrapper.m */,
+ 696F9EAD14F8D6ED00BC5FDC /* tor_main.c */,
+ 696F9EAF14F8DA6900BC5FDC /* torrc */,
+ );
+ name = Tor;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -197,6 +233,7 @@
buildActionMask = 2147483647;
files = (
696EBD8214F7877900B81BC9 /* InfoPlist.strings in Resources */,
+ 696F9EB014F8DA6900BC5FDC /* torrc in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -208,7 +245,10 @@
buildActionMask = 2147483647;
files = (
696EBD8414F7877900B81BC9 /* main.m in Sources */,
+ 696F9EAB14F8D5A900BC5FDC /* TorWrapper.m in Sources */,
696EBD8814F7877900B81BC9 /* AppDelegate.m in Sources */,
+ 696F9EAE14F8D6ED00BC5FDC /* tor_main.c in Sources */,
+ 696F9EB414F8DD6D00BC5FDC /* ULINetSocket.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -245,7 +285,11 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- HEADER_SEARCH_PATHS = ../dependencies/include;
+ HEADER_SEARCH_PATHS = (
+ ../dependencies/include,
+ ../dependencies/include/common,
+ ../dependencies/include/or,
+ );
IPHONEOS_DEPLOYMENT_TARGET = 5.1;
LIBRARY_SEARCH_PATHS = ../dependencies/lib;
SDKROOT = iphoneos;
@@ -265,7 +309,11 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- HEADER_SEARCH_PATHS = ../dependencies/include;
+ HEADER_SEARCH_PATHS = (
+ ../dependencies/include,
+ ../dependencies/include/common,
+ ../dependencies/include/or,
+ );
IPHONEOS_DEPLOYMENT_TARGET = 5.1;
LIBRARY_SEARCH_PATHS = ../dependencies/lib;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
@@ -6,9 +6,21 @@
//
#import <UIKit/UIKit.h>
+#import "TorWrapper.h"
+#import "ULINetSocket.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
+@property (nonatomic, retain) TorWrapper *torThread;
+
@property (strong, nonatomic) UIWindow *window;
+@property (nonatomic, retain) NSTimer *torCheckLoopTimer;
+@property (nonatomic, retain) ULINetSocket *mSocket;
+
+- (void)checkTor;
+
+- (void)activateTorCheckLoop;
+- (void)disableTorCheckLoop;
+
@end
@@ -10,7 +10,9 @@
@implementation AppDelegate
-@synthesize window = _window;
+@synthesize window = _window, torThread = _torThread,
+ torCheckLoopTimer = _torCheckLoopTimer,
+ mSocket = _mSocket;
- (void)dealloc
{
@@ -20,12 +22,15 @@ - (void)dealloc
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
+ self.torThread = [[TorWrapper alloc] init];
+ [self.torThread start];
+
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
- /* Test */
+ /*
// Test A
unsigned char *inStrg = (unsigned char*)[@"" cStringUsingEncoding:NSASCIIStringEncoding];
unsigned long lngth = 0;
@@ -117,14 +122,72 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
NSLog(@"should be: 07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6");
NSLog(@"");
NSLog(@"View https://en.wikipedia.org/wiki/SHA-2 for more info");
-
+ */
+
+ [NSTimer scheduledTimerWithTimeInterval:4.0f
+ target:self
+ selector:@selector(activateTorCheckLoop)
+ userInfo:nil
+ repeats:NO];
+
return YES;
}
+- (void)checkTor {
+ // Send a simple HTTP 1.0 header to the server and hopefully we won't be rejected
+ [_mSocket writeString:@"getinfo circuit-status\n\r" encoding:NSUTF8StringEncoding];
+
+}
+
+- (void)netsocketDisconnected:(ULINetSocket*)inNetSocket {
+ NSLog( @"GET Example: Disconnected" );
+ NSLog(@"%@", [_mSocket readString:NSUTF8StringEncoding]);
+}
+
+- (void)netsocket:(ULINetSocket*)inNetSocket dataAvailable:(unsigned)inAmount {
+ NSLog( @"GET Example: Data available (%u)", inAmount );
+ NSLog(@"%@", [_mSocket readString:NSUTF8StringEncoding]);
+}
+
+- (void)netsocketDataSent:(ULINetSocket*)inNetSocket {
+ //NSLog( @"GET Example: Data sent" );
+}
+
+#pragma mark -
+
+- (void)activateTorCheckLoop {
+ NSLog(@"Starting to check loop");
+ [ULINetSocket ignoreBrokenPipes];
+ // Create a new ULINetSocket connected to the host. Since ULINetSocket is asynchronous, the socket is not
+ // connected to the host until the delegate method is called.
+ _mSocket = [[ULINetSocket netsocketConnectedToHost:@"127.0.0.1" port:60602] retain];
+
+ // Schedule the ULINetSocket on the current runloop
+ [_mSocket scheduleOnCurrentRunLoop];
+
+ // Set the ULINetSocket's delegate to ourself
+ [_mSocket setDelegate:self];
+
+ [_mSocket writeString:@"authenticate\n\r" encoding:NSUTF8StringEncoding];
+ [_mSocket writeString:@"setevents circ\n\r" encoding:NSUTF8StringEncoding];
+
+ _torCheckLoopTimer = [NSTimer scheduledTimerWithTimeInterval:4.0f
+ target:self
+ selector:@selector(checkTor)
+ userInfo:nil
+ repeats:YES];
+
+}
+- (void)disableTorCheckLoop {
+ [_torCheckLoopTimer invalidate];
+
+}
+
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+ [self disableTorCheckLoop];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
@@ -141,11 +204,44 @@ - (void)applicationWillEnterForeground:(UIApplication *)application
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
+ [self activateTorCheckLoop];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+ [self activateTorCheckLoop];
+ [self.torThread halt_tor];
+}
+
+
+/*
+- (void) gameLoop {
+ while (running)
+ {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ [self renderFrame];
+ [pool release];
+ }
+}
+
+- (void) startLoop
+{
+ running = YES;
+#ifdef THREADED_ANIMATION
+ [NSThread detachNewThreadSelector:@selector(gameLoop)
+ toTarget:self withObject:nil];
+#else
+ timer = [NSTimer scheduledTimerWithTimeInterval:1.0f/60
+ target:self selector:@selector(renderFrame) userInfo:nil repeats:YES];
+#endif
+}
+
+- (void) stopLoop
+{
+ [timer invalidate];
+ running = NO;
}
+*/
@end
View
@@ -0,0 +1,28 @@
+//
+// TorWrapper.h
+// wut
+//
+// Created by Mike Tigas on 2/22/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#include "or/or.h"
+#include "or/main.h"
+#include <pthread.h>
+
+#define TOR_IS_RUNNING 0
+#define TOR_IS_STOPPING 1
+#define TOR_IS_STOPPED 2
+
+
+@interface TorWrapper : NSThread {
+ NSUInteger status;
+}
+
+@property (atomic) NSUInteger status;
+
+- (void)halt_tor;
+- (void)kill_tor;
+
+@end
Oops, something went wrong.

2 comments on commit c16bc34

Why are you setting "NumEntryGuards 6" - that will make your users stand out, no?

Owner

mtigas replied Oct 10, 2012

@ioerror Early in the lifetime of the app I'd fiddled with the torrc settings a bit for performance reasons. The current version of the torrc no longer does this.

(Sorry for belated reply, was on an extended vacation between the late September and this past weekend.)

Please sign in to comment.