internal Enumerator(NodePool pool) { list = pool; index = 0; version = pool.version; Current = default; }
/// <summary> /// Initializes a new instance of <see cref="ClientSettings"/> with the given parameters. /// </summary> /// <exception cref="ArgumentException"/> /// <exception cref="ArgumentNullException"/> /// <param name="listen">True to open a listening socket; false otherwise</param> /// <param name="netType">Network type</param> /// <param name="servs">Services supported by this node</param> /// <param name="nodes">List of peers (can be null)</param> /// <param name="fileMan">File manager</param> /// <param name="utxoDb">UTXO database</param> /// <param name="memPool">Memory pool</param> /// <param name="maxConnection">Maximum number of connections</param> public ClientSettings(bool listen, NetworkType netType, int maxConnection, NodeServiceFlags servs, NodePool nodes, IFileManager fileMan, IUtxoDatabase utxoDb, IMemoryPool memPool) { // TODO: add AcceptSAEAPool here based on listen AcceptIncomingConnections = listen; Network = netType; MaxConnectionCount = maxConnection; Services = servs; AllNodes = nodes ?? new NodePool(maxConnection); FileMan = fileMan ?? throw new ArgumentNullException(); DefaultPort = Network switch { NetworkType.MainNet => Constants.MainNetPort, NetworkType.TestNet => Constants.TestNetPort, NetworkType.RegTest => Constants.RegTestPort, _ => throw new ArgumentException("Undefined network"), }; ListenPort = DefaultPort; // TODO: the following values are for testing, they should be set by the caller // they need more checks for correct and optimal values BufferLength = 16384; // 16 KB int totalBytes = BufferLength * MaxConnectionCount * 2; MaxConnectionEnforcer = new Semaphore(MaxConnectionCount, MaxConnectionCount); SendReceivePool = new SocketAsyncEventArgsPool(MaxConnectionCount * 2); // TODO: can Memory<byte> be used here instead of byte[]? byte[] bufferBlock = new byte[totalBytes]; for (int i = 0; i < MaxConnectionCount * 2; i++) { var sArg = new SocketAsyncEventArgs(); sArg.SetBuffer(bufferBlock, i * BufferLength, BufferLength); SendReceivePool.Push(sArg); } // TODO: find a better way for this supportsIpV6 = NetworkInterface.GetAllNetworkInterfaces().All(x => x.Supports(NetworkInterfaceComponent.IPv6)); var c = new Consensus(netType); var txVer = new TransactionVerifier(false, utxoDb, memPool, c); Blockchain = new Blockchain.Blockchain(FileMan, new BlockVerifier(txVer, c), c) { Time = Time, State = BlockchainState.None }; }