예제 #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();
 }
        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);
                }
            }
        }
        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
        /// <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;
 }