예제 #1
0
 public async Task PublishChain(ChainNotify newChain)
 {
     foreach (var peer in _peers.GetAll())
     {
         await peer.Address.AppendPathSegments("api", "block", "sync")
         .PostJsonAsync(newChain.Blocks);
     }
 }
        public async void OnNext(IPeerReputationChange peerReputationChange)
        {
            await SemaphoreSlim.WaitAsync().ConfigureAwait(false);

            try
            {
                var peer = PeerRepository.GetAll().FirstOrDefault(p => p.PeerId.Equals(peerReputationChange.PeerId));
                Guard.Argument(peer, nameof(peer)).NotNull();

                peer.Reputation += peerReputationChange.ReputationEvent.Amount;
                PeerRepository.Update(peer);
            }
            finally
            {
                SemaphoreSlim.Release();
            }
        }
예제 #3
0
        // ReSharper disable once VSTHRD100
        public async void OnNext(IPeerReputationChange peerReputationChange)
        {
            try
            {
                await SemaphoreSlim.WaitAsync().ConfigureAwait(false);

                var peer = PeerRepository.GetAll().FirstOrDefault(p => p.PeerId.Equals(peerReputationChange.PeerId));
                Guard.Argument(peer, nameof(peer)).NotNull();

                // ReSharper disable once PossibleNullReferenceException
                peer.Reputation += peerReputationChange.ReputationEvent.Amount;
                PeerRepository.Update(peer);
            }
            catch (Exception e)
            {
                _logger.Error(e, e.Message);
            }
            finally
            {
                SemaphoreSlim.Release();
            }
        }
예제 #4
0
        public void OnNext(IPeerReputationChange peerReputationChange)
        {
            try
            {
                var peer = PeerRepository.GetAll().FirstOrDefault(p => p.PeerId.Equals(peerReputationChange.PeerId));
                //todo come back to later
                if (peer == null)
                {
                    return;
                }

                Guard.Argument(peer, nameof(peer)).NotNull();

                // ReSharper disable once PossibleNullReferenceException
                peer.Reputation += peerReputationChange.ReputationEvent.Amount;
                PeerRepository.Update(peer);
            }
            catch (Exception e)
            {
                _logger.Error(e, e.Message);
            }
        }
예제 #5
0
 public IEnumerable <Peer> All()
 {
     return(_peers.GetAll());
 }