Ejemplo n.º 1
0
        /// <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
            };
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of <see cref="NetworkAddress"/> using the given parameters.
 /// </summary>
 /// <param name="servs">Services that this node supports</param>
 /// <param name="ip">IP address of this node</param>
 /// <param name="port">Port (use <see cref="Constants"/> for default values)</param>
 /// <param name="time">
 /// Unix timestamp (Now if advertising own address, otherwise the same time received from the other node)
 /// </param>
 public NetworkAddressWithTime(NodeServiceFlags servs, IPAddress ip, ushort port, uint time) : base(servs, ip, port)
 {
     Time = time;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of <see cref="NetworkAddress"/> using the given parameters.
 /// </summary>
 /// <param name="servs">Services that this node supports</param>
 /// <param name="ip">IP address of this node</param>
 /// <param name="port">Port (use <see cref="Constants"/> for default values)</param>
 public NetworkAddress(NodeServiceFlags servs, IPAddress ip, ushort port)
 {
     NodeServices = servs;
     NodeIP       = ip;
     NodePort     = port;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of <see cref="VersionPayload"/> with the given parameters and sets the rest to
 /// default values.
 /// </summary>
 /// <exception cref="ArgumentOutOfRangeException"/>
 /// <param name="ver">Protocol version</param>
 /// <param name="servs">Services supported by this node</param>
 /// <param name="height">Highest block height that this node has</param>
 /// <param name="relay">
 /// Indicates whether <see cref="PayloadType.Inv"/> or <see cref="PayloadType.Tx"/> messages should be sent
 /// to this node
 /// </param>
 public VersionPayload(int ver, NodeServiceFlags servs, int height, bool relay) :
     this(ver, UnixTimeStamp.GetEpochUtcNow(), new NetworkAddress(), new NetworkAddress() { NodeServices = servs },
          0, new BIP0014("Bitcoin.Net", new Version(0, 0, 0)).ToString(), height, relay)
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of <see cref="ClientSettings"/> with the given parameters.
 /// </summary>
 /// <param name="pver">Protocol version</param>
 /// <param name="relay">True to relay blocks and transactions; false otherwise</param>
 /// <param name="ua">User agent</param>
 /// <param name="netType">Network type</param>
 /// <param name="servs">Services supported by this node</param>
 public ClientSettings(int pver, bool relay, BIP0014 ua, NetworkType netType, NodeServiceFlags servs)
     : this(pver, relay, ua.ToString(), netType, servs)
 {
 }