예제 #1
0
 public TORControllerFixture()
 {
     // TORThread won't stop til the process does
     if (TORThread.ActiveThread is null)
     {
         thread = new TORThread(Configuration);
         thread.Start();
     }
 }
예제 #2
0
        public TORControllerFixture()
        {
            // TORThread won't stop til the process does
            if (TORThread.ActiveThread is null)
            {
                thread = new TORThread(Configuration);
                thread.Start();
            }

            NSRunLoop.Main.RunUntil(NSDate.FromTimeIntervalSinceNow(0.5f));
        }
예제 #3
0
        // port from iOS OnionBrowser


        public async Task StartTor(OnionManagerDelegate managerDelegate)
        {
            // In objective-c this is weak to avoid retain cycle. not sure if we
            // need to replicate cause we got a GC
            var weakDelegate = managerDelegate;

            CancelInitRetry();
            State = TorState.Started;

            if (TorController == null)
            {
                TorController = new TORController("127.0.0.1", 39060);
            }

            if (torThread?.IsCancelled ?? true)
            {
                torThread?.Dispose();
                torThread = null;

                var torConf = this.torBaseConf;

                var args = torConf.Arguments;

                Logger.LogDebug(String.Join(" ", args));

                torConf.Arguments = args;

                torThread = new TORThread(torConf);

                torThread?.Start();

                Logger.LogInfo("Starting Tor");
            }

            await Task.Delay(1000);

            // Wait long enough for Tor itself to have started. It's OK to wait for this
            // because Tor is already trying to connect; this is just the part that polls for
            // progress.

            if (!(TorController?.Connected ?? false))
            {
                // do
                NSError e = null;
                TorController?.Connect(out e);
                if (e != null) // faux catch accomodates bound obj-c)
                {
                    Logger.LogError(e.LocalizedDescription);
                }
            }

            var cookie = Guard.NotNull(nameof(Cookie), Cookie);

            TorController?.AuthenticateWithData(cookie, async(success, error) =>
            {
                using (await mutex.LockAsync())
                {
                    if (success)
                    {
                        NSObject completeObs = null;
                        completeObs          = TorController?.AddObserverForCircuitEstablished((established) =>
                        {
                            if (established)
                            {
                                State = TorState.Connected;

                                TorController?.RemoveObserver(completeObs);
                                CancelInitRetry();
                                Logger.LogDebug("Connection established!");

                                weakDelegate?.TorConnFinished();
                            }
                        }); // TorController.addObserver

                        NSObject progressObs = null;
                        progressObs          = TorController?.AddObserverForStatusEvents(
                            (NSString type, NSString severity, NSString action, NSDictionary <NSString, NSString> arguments) =>
                        {
                            if (type == "STATUS_CLIENT" && action == "BOOTSTRAP")
                            {
                                var progress = Int32.Parse(arguments ![(NSString)"PROGRESS"] !) !;
                                Logger.LogDebug(progress.ToString());

                                weakDelegate?.TorConnProgress(progress);

                                if (progress >= 100)
                                {
                                    TorController?.RemoveObserver(progressObs);
                                }

                                return(true);
                            }

                            return(false);
                        }); // TorController.addObserver
                    }       // if success (authenticate)