Esempio n. 1
0
        public override async Task OnConnectedAsync(ConnectionContext connection)
        {
            var context = connection.GetHttpContext();

            if (context == null || !context.WebSockets.IsWebSocketRequest)
            {
                connection.Abort();
                return;
            }

            var websocket = await context.WebSockets.AcceptWebSocketAsync()
                            .ConfigureAwait(false);

            var node = new NodeInfo {
                Address = new IPEndPoint(context.Connection.RemoteIpAddress, context.Connection.RemotePort),
                Socket  = websocket
            };

            _blockchain.AddNode(node);
            _logger.LogInformation($"Added node with {node.Address} address.");

            node.ReceiveAsync()
            .ConfigureAwait(false);

            _logger.LogInformation($"Receiving data from {node.Address} address.");
        }
Esempio n. 2
0
 public bool RegisterNode([FromBody][Required] string node)
 {
     if (ModelState.IsValid)
     {
         return(Blockchain.AddNode(node));
     }
     else
     {
         throw new HttpResponseException(HttpStatusCode.BadRequest);
     }
 }
Esempio n. 3
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();
            services.AddServerSideBlazor();
            services.AddWebSockets(x => {
                x.ReceiveBufferSize = 512;
                x.KeepAliveInterval = TimeSpan.FromSeconds(120);
            });

            var blockchain = new Blockchain();

            blockchain.CreateGenesisBlock();
            blockchain.AddNode(new NodeInfo {
                Address = IPEndPoint.Parse("127.0.0.1:5000")
            });
            services.AddSingleton(blockchain);
        }