コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        private IActorRef CreateJob(HashedMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (message.Hash == null)
            {
                throw new ArgumentNullException(nameof(message.Hash));
            }

            if (message.Hash.Length > 32)
            {
                throw new ArgumentOutOfRangeException(nameof(message.Hash));
            }

            IActorRef actorRef = null;

            try
            {
                var name = $"job-actor-{Util.HashToId(message.Hash.ToHex())}";
                actorRef = Context.ActorOf(JobActor.Props(unitOfWork, httpService), name);
            }
            catch (Exception ex)
            {
                logger.Error($"<<< BoostGraphActor.CreateJob >>>: {ex.ToString()}");
            }

            return(actorRef);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <param name="reason"></param>
        private void Shutdown(HashedMessage message, string reason)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (message.Hash == null)
            {
                throw new ArgumentNullException(nameof(message.Hash));
            }

            if (message.Hash.Length > 32)
            {
                throw new ArgumentOutOfRangeException(nameof(message.Hash));
            }

            if (string.IsNullOrEmpty(reason))
            {
                throw new ArgumentNullException(nameof(reason));
            }

            logger.Warning(reason);

            Context.Stop(Self);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        private async Task <ulong> LastInterpreted(HashedMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (message.Hash == null)
            {
                throw new ArgumentNullException(nameof(message.Hash));
            }

            if (message.Hash.Length > 32)
            {
                throw new ArgumentOutOfRangeException(nameof(message.Hash));
            }

            var blockID = await unitOfWork.BlockID.GetFirstOrDefault(x => x.Hash.Equals(message.Hash.ToHex()));

            lastInterpretedMessage = blockID switch
            {
                null => new LastInterpretedMessage(0, null),
                _ => new LastInterpretedMessage(blockID.Round, blockID),
            };

            return(lastInterpretedMessage.Last > 0 ? lastInterpretedMessage.Last - 1 : lastInterpretedMessage.Last);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task Register(HashedMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (message.Hash == null)
            {
                throw new ArgumentNullException(nameof(message.Hash));
            }

            if (message.Hash.Length > 32)
            {
                throw new ArgumentOutOfRangeException(nameof(message.Hash));
            }

            try
            {
                Id ??= message.Hash;

                if (!Id.SequenceEqual(message.Hash))
                {
                    Shutdown(message, $"<<< JobActor.Register >>>: Received hash mismatch. Got: ({message.Hash}) Expected: ({Id})");
                    return;
                }

                var blocks = await unitOfWork.BlockGraph.GetWhere(x => x.Block.Hash.Equals(message.Hash.ToHex()) && !x.Included);

                if (blocks.Any())
                {
                    var moreBlocks = await unitOfWork.BlockGraph.More(blocks);

                    var blockHashLookup = moreBlocks.ToLookup(i => i.Block.Hash);

                    await unitOfWork.BlockGraph.Include(blocks, httpService.NodeIdentity);
                    await AddOrUpdateJob(blockHashLookup);
                }

                Context.Stop(Self);
            }
            catch (Exception ex)
            {
                logger.Error($"<<< ReplyProvider.Run >>>: {ex.ToString()}");
            }
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private async Task InitializeBlocks(HashedMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (message.Hash == null)
            {
                throw new ArgumentNullException(nameof(message.Hash));
            }

            if (message.Hash.Length > 32)
            {
                throw new ArgumentOutOfRangeException(nameof(message.Hash));
            }

            var blockGraphs = await unitOfWork.BlockGraph.GetWhere(x => x.Block.Hash.Equals(message.Hash.ToHex()) && !x.Included && !x.Replied);

            foreach (var blockGraph in blockGraphs)
            {
                var isSet = await SetOwnBlockGraph(blockGraph);

                if (isSet == null)
                {
                    logger.Warning($"<<< BoostGraphActor.InitializeBlocks >>>: " +
                                   $"Unable to set own block Hash: {blockGraph.Block.Hash} Round: {blockGraph.Block.Round} from node {blockGraph.Block.Node}");
                    continue;
                }

                if (string.IsNullOrEmpty(blockGraph.Block.SignedBlock.PublicKey) || string.IsNullOrEmpty(blockGraph.Block.SignedBlock.Signature))
                {
                    var success = await unitOfWork.BlockGraph.Delete(blockGraph.Id);

                    if (!success)
                    {
                        logger.Error($"<<< BoostGraphActor.InitializeBlocks >>>: Failed to delete block {blockGraph.Block.Hash}");
                        continue;
                    }
                }

                JobDelivery(message);

                await Process(new ProcessBlockMessage(isSet));
            }
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        private async Task Register(HashedMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (message.Hash == null)
            {
                throw new ArgumentNullException(nameof(message.Hash));
            }

            if (message.Hash.Length > 32)
            {
                throw new ArgumentOutOfRangeException(nameof(message.Hash));
            }

            Id ??= message.Hash;

            if (!Id.SequenceEqual(message.Hash))
            {
                Shutdown(message, $"<<< BoostGraphActor.Register >>>: Received hash mismatch. Got: ({message.Hash}) Expected: ({Id})");
                return;
            }

            var lastInterpreted = await LastInterpreted(message);

            if (Graph == null)
            {
                jobActor = CreateJob(message);

                Config = new Config(lastInterpreted, new ulong[totalNodes], httpService.NodeIdentity, (ulong)totalNodes);
                Graph  = new Graph(Config);

                Graph.BlockmaniaInterpreted += (sender, e) => BlockmaniaCallback(sender, e).SwallowException();
            }

            await InitializeBlocks(message);
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        private void Register(HashedMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (message.Hash == null)
            {
                throw new ArgumentNullException(nameof(message.Hash));
            }

            if (message.Hash.Length > 32)
            {
                throw new ArgumentOutOfRangeException(nameof(message.Hash));
            }

            var boostGraph = Exists(message.Hash);

            if (boostGraph != null)
            {
                boostGraph.Tell(message);
            }
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        private void Shutdown(HashedMessage message, string reason)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (message.Hash == null)
            {
                throw new ArgumentNullException(nameof(message.Hash));
            }

            if (message.Hash.Length > 32)
            {
                throw new ArgumentOutOfRangeException(nameof(message.Hash));
            }

            if (string.IsNullOrEmpty(reason))
            {
                throw new ArgumentNullException(nameof(reason));
            }

            Sender.Tell(new GracefulStopMessge(message.Hash, new TimeSpan(1), reason));
        }
コード例 #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public Task RegisterAsync(HashedMessage message)
 {
     actor.Tell(message);
     return(Task.CompletedTask);
 }
コード例 #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="message"></param>
 public void Register(HashedMessage message)
 {
     actor.Tell(message);
 }
コード例 #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        private void JobDelivery(HashedMessage message)
        {
            var name = $"delivery-actor-{Util.HashToId(message.Hash.ToHex())}";

            atLeastOnceDeliveryActor = Context.ActorOf(AtLeastOnceDeliveryActor.Props(jobActor, message.Hash.ToHex()), name);
        }