コード例 #1
0
        public FullNodeTumblerClientConfiguration(TumblingState tumblingState, bool onlyMonitor, bool connectionTest = false, bool useProxy = true)
        {
            this.tumblingState = tumblingState ?? throw new ArgumentNullException(nameof(tumblingState));
            Network            = tumblingState.TumblerNetwork ?? throw new ArgumentNullException(nameof(tumblingState.TumblerNetwork));

            Logs.LogDir = this.tumblingState.NodeSettings.DataDir;

            if (!onlyMonitor || connectionTest)
            {
                TorPath = "tor";

                Cooperative   = true;
                AllowInsecure = true;

                if (tumblingState.TumblerUri != null)
                {
                    TumblerServer = new TumblerUrlBuilder(this.tumblingState.TumblerUri);
                    if (TumblerServer == null)
                    {
                        throw new ConfigException("Tumbler server is not configured");
                    }
                }

                if (useProxy)
                {
                    AliceConnectionSettings = new SocksConnectionSettings()
                    {
                        Proxy = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050)
                    };

                    BobConnectionSettings = new SocksConnectionSettings()
                    {
                        Proxy = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050)
                    };
                }
                else
                {
                    // This mode is only for unit/integration tests, as it allows testing with latency introduced by Tor
                    AliceConnectionSettings = new ConnectionSettingsBase();
                    BobConnectionSettings   = new ConnectionSettingsBase();
                }

                if (connectionTest)
                {
                    return;
                }
            }

            OnlyMonitor = onlyMonitor;
            Logs.Configuration.LogInformation("Network: " + Network);
            DataDir = GetTumbleBitDataDir(this.tumblingState.NodeSettings.DataDir);
            Logs.Configuration.LogInformation("Data directory set to " + DataDir);

            DBreezeRepository = new DBreezeRepository(Path.Combine(DataDir, "db2"));
            Tracker           = new Tracker(DBreezeRepository, Network);

            // Need to use our own ExternalServices implementations to remove RPC dependency
            Services = ExternalServices.CreateFromFullNode(DBreezeRepository, Tracker, this.tumblingState);
        }
コード例 #2
0
        public FullNodeTumblerClientConfiguration(TumblingState tumblingState, bool onlyMonitor, bool connectionTest = false)
        {
            this.tumblingState = tumblingState ?? throw new ArgumentNullException(nameof(tumblingState));
            Network            = tumblingState.TumblerNetwork ?? throw new ArgumentNullException(nameof(tumblingState.TumblerNetwork));

            if (!onlyMonitor || connectionTest)
            {
                TorPath = "tor";

                Cooperative   = true;
                AllowInsecure = true;

                if (tumblingState.TumblerUri != null)
                {
                    TumblerServer = new TumblerUrlBuilder(this.tumblingState.TumblerUri);
                    if (TumblerServer == null)
                    {
                        throw new ConfigException("Tumbler server is not configured");
                    }
                }

                AliceConnectionSettings = new SocksConnectionSettings()
                {
                    Proxy = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050)
                };

                // TODO: Need to check what recommended configuration is to prevent Alice/Bob linkage
                BobConnectionSettings = new SocksConnectionSettings()
                {
                    Proxy = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050)
                };

                if (connectionTest)
                {
                    return;
                }
            }

            OnlyMonitor = onlyMonitor;
            Logs.Configuration.LogInformation("Network: " + Network);
            DataDir = Path.Combine(this.tumblingState.NodeSettings.DataDir, "TumbleBit");
            Logs.Configuration.LogInformation("Data directory set to " + DataDir);

            DBreezeRepository = new DBreezeRepository(Path.Combine(DataDir, "db2"));
            Tracker           = new Tracker(DBreezeRepository, Network);

            // Need to use our own ExternalServices implementations to remove RPC dependency
            Services = ExternalServices.CreateFromFullNode(DBreezeRepository, Tracker, this.tumblingState);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: stratistools1/Breezier
        static void Main(string[] args)
        {
            // args[0] = server CTB URL
            // args[1] = cycle number (not too important)
            // args[2] = cookie file path for Tor
            // args[3] & args[4] = -noTor and/or -tumblerProtocol=http |-tumblerProtocol=tcp
            var useTor = !args.Contains("-noTor");
            TumblerProtocolType?tumblerProtocol = null;

            try
            {
                string tumblerProtocolString = args.Where(a => a.StartsWith("-tumblerProtocol=")).Select(a => a.Substring("-tumblerProtocol=".Length).Replace("\"", "")).FirstOrDefault();
                if (tumblerProtocolString != null)
                {
                    tumblerProtocol = Enum.Parse <TumblerProtocolType>(tumblerProtocolString, true);
                }

                if (useTor && tumblerProtocol.HasValue && tumblerProtocol.Value == TumblerProtocolType.Http)
                {
                    Console.WriteLine("TumblerProtocol can only be changed to Http when Tor is disabled. Please use -NoTor switch to disable Tor.");
                    return;
                }
            }
            catch
            {
                Console.WriteLine($"Incorrect tumbling prococol specified; the valid values are {TumblerProtocolType.Tcp} and {TumblerProtocolType.Http}");
                return;
            }

            var serverAddress = new TumblerUrlBuilder(args[0]);
            var cycle         = int.Parse(args[1]);
            var client        = new TumblerClient(Network.Main, serverAddress, cycle);

            var cookieFile = new FileInfo(args[2]);

            IPEndPoint endpoint;

            var settings = new SocksConnectionSettings();

            if (useTor)
            {
                using (var tor = new TorClient("127.0.0.1", 9051, cookieFile))
                {
                    try
                    {
                        tor.ConnectAsync().GetAwaiter().GetResult();
                    }
                    catch
                    {
                        Console.WriteLine("Error in connect");
                    }

                    if (!tor.AuthenticateAsync().GetAwaiter().GetResult())
                    {
                        Console.WriteLine("Error in authenticate");
                    }

                    var endpoints = tor.GetSocksListenersAsync().GetAwaiter().GetResult();
                    endpoint = endpoints.FirstOrDefault();
                    if (endpoint == null)
                    {
                        throw new TorException("Tor has no socks listener", "");
                    }
                }
                settings.Proxy = endpoint;
            }

            var handler = settings.CreateHttpHandler(tumblerProtocol ?? TumblerProtocolType.Tcp);

            if (handler != null)
            {
                client.SetHttpHandler(handler);
            }
            else
            {
                Console.WriteLine("Handler is null");
            }

            Console.WriteLine(DateTime.Now + " Obtaining MasterNode parameters");
            try
            {
                var parameters = client.GetTumblerParameters();
                Console.WriteLine("Core settings");
                Console.WriteLine($"Network: {parameters.Network}");
                Console.WriteLine($"ExpectedAddress: {parameters.ExpectedAddress}");
                Console.WriteLine($"Denomination: {parameters.Denomination}");
                Console.WriteLine($"Fee: {parameters.Fee}");
                Console.WriteLine();

                Console.WriteLine("Standard Server Check");
                Console.WriteLine($" - IsStandard (MasterNode value =? ExpectedValue): {parameters.IsStandard()}");
                Console.WriteLine($"   - Version ({parameters.Version} =? {ClassicTumblerParameters.LAST_VERSION}): {parameters.Version == ClassicTumblerParameters.LAST_VERSION}");
                Console.WriteLine($"   - VoucherKey: {parameters.VoucherKey.CheckKey()}");
                Console.WriteLine($"   - ServerKey: {parameters.ServerKey.CheckKey()}");
                Console.WriteLine($"   - FakePuzzleCount ({parameters.FakePuzzleCount} =? {285}): {parameters.FakePuzzleCount == 285}");
                Console.WriteLine($"   - RealPuzzleCount ({parameters.RealPuzzleCount} =? {15}): {parameters.RealPuzzleCount == 15}");
                Console.WriteLine($"   - RealTransactionCount ({parameters.RealTransactionCount} =? {42}): {parameters.RealTransactionCount == 42}");
                Console.WriteLine($"   - FakeTransactionCount ({parameters.FakeTransactionCount} =? {42}): {parameters.FakeTransactionCount == 42}");
                Console.WriteLine($"   - Denomination ({parameters.Denomination} =? {new Money(0.1m, MoneyUnit.BTC)}): {parameters.Denomination == new Money(0.1m, MoneyUnit.BTC)}");
                Console.WriteLine($"   - Fee ({parameters.Fee} =? {new Money(0.00155m, MoneyUnit.BTC)}): {parameters.Fee == new Money(0.00155m, MoneyUnit.BTC)}");
                Console.WriteLine($"   - FakeFormat ({parameters.FakeFormat} =? {new uint256(Enumerable.Range(0, 32).Select(o => o == 0 ? (byte)0 : (byte)1).ToArray())}): {parameters.FakeFormat == new uint256(Enumerable.Range(0, 32).Select(o => o == 0 ? (byte)0 : (byte)1).ToArray())}");
                Console.WriteLine();

                Console.WriteLine($"Cycles");
                Console.WriteLine($" - CycleGenerator: {parameters.CycleGenerator.FirstCycle.ToString()}");
                Console.WriteLine($" - RegistrationOverlap: {parameters.CycleGenerator.RegistrationOverlap}");
                Console.WriteLine();

                Console.WriteLine("Cryptography");
                Console.WriteLine($" - FakeFormat: {parameters.FakeFormat}");
                Console.WriteLine($" - FakeTransactionCount: {parameters.FakeTransactionCount}");
                Console.WriteLine($" - RealPuzzleCount: {parameters.RealPuzzleCount}");
                Console.WriteLine($" - FakePuzzleCount: {parameters.FakePuzzleCount}");
                Console.WriteLine($" - RealTransactionCount: {parameters.RealTransactionCount}");
                Console.WriteLine($" - Version: {parameters.Version}");
                Console.WriteLine($" - FakeFormat: {parameters.Version}");
                Console.WriteLine();
            }
            catch (Exception ex) { }

            Console.WriteLine();

            Console.WriteLine(DateTime.Now + " Starting tor connectivity test...");
            while (true)
            {
                Stopwatch stopwatch = Stopwatch.StartNew();
                try
                {
                    var parameters = client.GetTumblerParameters();
                    stopwatch.Stop();
                    Console.WriteLine(DateTime.Now + " Received parameter response in " + stopwatch.ElapsedMilliseconds + "ms");
                }
                catch
                {
                    stopwatch.Stop();
                    Console.WriteLine(DateTime.Now + " Timed out after " + stopwatch.ElapsedMilliseconds + "ms");
                }
                Thread.Sleep(1000);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: ArcSin2000X/BreezeProject
        static void Main(string[] args)
        {
            // args[0] = server CTB URL
            // args[1] = cycle number (not too important)
            // args[2] = cookie file path for Tor

            var serverAddress = new TumblerUrlBuilder(args[0]);
            var cycle         = int.Parse(args[1]);
            var client        = new TumblerClient(Network.Main, serverAddress, cycle);

            var cookieFile = new FileInfo(args[2]);

            IPEndPoint endpoint;

            using (var tor = new TorClient("127.0.0.1", 9051, cookieFile))
            {
                try
                {
                    tor.ConnectAsync().GetAwaiter().GetResult();
                }
                catch
                {
                    Console.WriteLine("Error in connect");
                }

                if (!tor.AuthenticateAsync().GetAwaiter().GetResult())
                {
                    Console.WriteLine("Error in authenticate");
                }

                var endpoints = tor.GetSocksListenersAsync().GetAwaiter().GetResult();
                endpoint = endpoints.FirstOrDefault();
                if (endpoint == null)
                {
                    throw new TorException("Tor has no socks listener", "");
                }
            }

            var settings = new SocksConnectionSettings();

            settings.Proxy = endpoint;
            var handler = settings.CreateHttpHandler(TumblerProtocolType.Tcp);

            if (handler != null)
            {
                client.SetHttpHandler(handler);
            }
            else
            {
                Console.WriteLine("Handler is null");
            }

            Console.WriteLine(DateTime.Now + " Starting tor connectivity test...");

            while (true)
            {
                Stopwatch stopwatch = Stopwatch.StartNew();
                try
                {
                    var parameters = client.GetTumblerParameters();
                    stopwatch.Stop();
                    Console.WriteLine(DateTime.Now + " Received parameter response in " + stopwatch.ElapsedMilliseconds + "ms");
                }
                catch
                {
                    stopwatch.Stop();
                    Console.WriteLine(DateTime.Now + " Timed out after " + stopwatch.ElapsedMilliseconds + "ms");
                }
            }
        }