Example #1
0
        public LocalClient(LocalClientType type, BlockchainDaemon blockchainDaemon, IBoundedStorage<NetworkAddressKey, NetworkAddressWithTime> knownAddressStorage)
        {
            this._type = type;

            this.blockchainDaemon = blockchainDaemon;
            this.shutdownToken = new CancellationTokenSource();

            this.knownAddressCache = new BoundedCache<NetworkAddressKey, NetworkAddressWithTime>
            (
                "KnownAddressCache",
                dataStorage: knownAddressStorage,
                maxFlushMemorySize: 5.THOUSAND(),
                maxCacheMemorySize: 500.THOUSAND(),
                sizeEstimator: knownAddress => 40
            );

            this.connectWorker = new Worker("LocalClient.ConnectWorker", ConnectWorker, true, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
            this.requestBlocksWorker = new Worker("LocalClient.RequestBlocksWorker", RequestBlocksWorker, true, TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(5000));
            this.requestHeadersWorker = new Worker("LocalClient.RequestHeadersWorker", RequestHeadersWorker, true, TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(5000));
            this.statsWorker = new Worker("LocalClient.StatsWorker", StatsWorker, true, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30));

            this.blockchainDaemon.OnWinningBlockChanged += OnWinningBlockChanged;

            switch (this.Type)
            {
                case LocalClientType.MainNet:
                    Messaging.Port = 8333;
                    Messaging.Magic = Messaging.MAGIC_MAIN;
                    break;

                case LocalClientType.TestNet3:
                    Messaging.Port = 18333;
                    Messaging.Magic = Messaging.MAGIC_TESTNET3;
                    break;

                case LocalClientType.ComparisonToolTestNet:
                    Messaging.Port = 18444;
                    Messaging.Magic = Messaging.MAGIC_COMPARISON_TOOL;
                    break;
            }
        }
Example #2
0
        public LocalClient(LocalClientType type, BlockchainDaemon blockchainDaemon, IBoundedStorage <NetworkAddressKey, NetworkAddressWithTime> knownAddressStorage)
        {
            this._type = type;

            this.blockchainDaemon = blockchainDaemon;
            this.shutdownToken    = new CancellationTokenSource();

            this.knownAddressCache = new BoundedCache <NetworkAddressKey, NetworkAddressWithTime>
                                     (
                "KnownAddressCache",
                dataStorage: knownAddressStorage,
                maxFlushMemorySize: 5.THOUSAND(),
                maxCacheMemorySize: 500.THOUSAND(),
                sizeEstimator: knownAddress => 40
                                     );

            this.connectWorker        = new Worker("LocalClient.ConnectWorker", ConnectWorker, true, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
            this.requestBlocksWorker  = new Worker("LocalClient.RequestBlocksWorker", RequestBlocksWorker, true, TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(5000));
            this.requestHeadersWorker = new Worker("LocalClient.RequestHeadersWorker", RequestHeadersWorker, true, TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(5000));
            this.statsWorker          = new Worker("LocalClient.StatsWorker", StatsWorker, true, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30));

            this.blockchainDaemon.OnWinningBlockChanged += OnWinningBlockChanged;

            switch (this.Type)
            {
            case LocalClientType.MainNet:
                Messaging.Port  = 8333;
                Messaging.Magic = Messaging.MAGIC_MAIN;
                break;

            case LocalClientType.TestNet3:
                Messaging.Port  = 18333;
                Messaging.Magic = Messaging.MAGIC_TESTNET3;
                break;

            case LocalClientType.ComparisonToolTestNet:
                Messaging.Port  = 18444;
                Messaging.Magic = Messaging.MAGIC_COMPARISON_TOOL;
                break;
            }
        }