コード例 #1
0
        public Server(int port, Blockchain.Blockchain chain)
        {
            UPnP upnp = new UPnP(port);

            DataServer.Initialize(IPAddress.Any, port, chain);
            this.Init();
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: EpicoinTM/Epicoin
 public Server(int port, Blockchain.Blockchain chain)
 {
     UPnP.init(new int[1] {
         port
     });
     DataServer.Initialize(IPAddress.Any, port, chain);
     this.Init();
 }
コード例 #3
0
        public static void RunCommand(string commandName, string input)
        {
            blockchain = NetworkFileProvider <Blockchain.Blockchain> .GetModel(Constants.BlockchainStoragePath);

            if (commandName == "connect")
            {
                string template = "{0} -ip {1} -p {2}";
                var    args     = ReverseStringFormat(template, input);
                int    port     = int.Parse(args[2]);

                IPAddress clientIp;

                if (IPAddress.TryParse(args[1], out clientIp))
                {
                    blockchain.RegisterNode($"{clientIp}:{port}");
                    AsynchronousClient.Connect(clientIp, port);
                }
                else
                {
                    Logger.LogLine("incorect command parameters", ConsoleColor.Red);
                }
            }

            if (commandName == "peers")
            {
                if (blockchain.Nodes.Count > 0)
                {
                    foreach (var node in blockchain.Nodes)
                    {
                        Logger.LogLine(node.Address, ConsoleColor.Green);
                    }
                }
                else
                {
                    Logger.LogLine("no peers", ConsoleColor.Red);
                }
            }

            if (commandName == "start-wallet")
            {
                WalletProvider.Initialize();
            }

            if (commandName == "sync")
            {
                var result = blockchain.ResolveConflicts();

                if (result)
                {
                    Logger.LogLine("successfully sync network", ConsoleColor.Green);
                }
                else
                {
                    Logger.LogLine("error while sync network", ConsoleColor.Red);
                }
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            IConfiguration config = Helper.GetConfigFromFile("appsettings.json");

            var blockchain = new Blockchain.Blockchain();
            var unused     = new WebServer(blockchain, config["server"], config["port"]);

            Console.WriteLine($"Serwer o adresie {config["server"]}:{config["port"]} został uruchomiony");
            Console.Read();
        }
コード例 #5
0
 public int GetAmount(string address)
 {
     try
     {
         Blockchain.Blockchain chain = GetBlockchain();
         return(chain.GetBalanceOfAddress(address));
     }
     catch (Exception e)
     {
         Console.WriteLine("[G] " + e.Message);
         return(0);
     }
 }
コード例 #6
0
 public static void Initialize(IPAddress hosAddress, int port, Blockchain.Blockchain chain)
 {
     Address  = hosAddress;
     Port     = port;
     Continue = true;
     Clients  = new List <DataTcpClient>();
     Tasks    = new Queue <DataTcpClient>();
     _sock    = new Socket(hosAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
     Chain    = chain;
     PeerList = new List <string>()
     {
         "epicoin.ddns.net"
     };
 }
コード例 #7
0
ファイル: ClientSettings.cs プロジェクト: supaFool/Denovo
        /// <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
            };
        }
コード例 #8
0
        public static Blockchain.Blockchain AskChain()
        {
            int lenght = AskChainStats().Lenght;

            Blockchain.Blockchain chain = new Blockchain.Blockchain("");

            for (int i = 0; i < lenght; i++)
            {
                Block b = AskBlockNumber(i);
                if (b != null)
                {
                    chain.AddBlock(b);
                }
            }

            return(chain);
        }
コード例 #9
0
 public BlockchainController(IBlockchain block)
 {
     this._blockchain = block as Blockchain.Blockchain;
 }