public void RequestDeltaHeightTimerCallback(object state) { //Can improve this later when networking layers get reduced var peerCount = DeltaHeightRanker.GetPeers().Count(); if (_hasLooped && peerCount >= _minimumPeers) { _manualResetEventSlim.Set(); } RequestDeltaHeightFromPeers(); }
public DeltaHeightWatcher(IPeerClient peerClient, IPeerRepository peerRepository, IPeerService peerService, double threshold = 0.5d, int minimumPeers = 2) { _peerClient = peerClient; DeltaHeightRanker = new DeltaHeightRanker(peerRepository, 100, threshold); _peerRepository = peerRepository; _peerService = peerService; _manualResetEventSlim = new ManualResetEventSlim(false); _threshold = threshold; _minimumPeers = minimumPeers; }
private void RequestDeltaHeightFromPeers() { var totalPages = GetPageCount(); _page %= totalPages; _page++; var peers = DeltaHeightRanker.GetPeers().Union(_peerRepository.TakeHighestReputationPeers(_page, _peersPerCycle).Select(x => x.PeerId)); _peerClient.SendMessageToPeers(new LatestDeltaHashRequest(), peers); if (_page >= totalPages && DeltaHeightRanker.GetPeers().Count() >= _minimumPeers) { _hasLooped = true; } }
private void DeltaHeightOnNext(ProtocolMessage protocolMessage) { var peerId = protocolMessage.PeerId; var latestDeltaHash = protocolMessage.FromProtocolMessage <LatestDeltaHashResponse>(); var peer = _peerRepository.Get(peerId); if (peer != null) { peer.Touch(); _peerRepository.Update(peer); } DeltaHeightRanker.Add(peerId, latestDeltaHash); }
private IRankedItem <LatestDeltaHashResponse> GetMostPopularMessage() { //Responses that have fully sync var rankedResponses = DeltaHeightRanker.GetMessagesByMostPopular(); var highestRankedSyncResponse = rankedResponses.Where(x => x.Item.IsSync).FirstOrDefault(); if (highestRankedSyncResponse != null) { return(highestRankedSyncResponse); } //Responses that have not fully sync var highestRankedUnSyncResponse = rankedResponses.FirstOrDefault(); if (highestRankedUnSyncResponse != null) { return(highestRankedUnSyncResponse); } return(null); }