示例#1
0
        private void ConsumerInventoryToSpread()
        {
            List <PeerConnection> peers =
                Manager.Instance.NetDelegate.ActivePeers.Where(peer => !peer.IsNeedSyncFromPeer && !peer.IsNeedSyncUs).ToList();

            if (this.inventory_spread.IsEmpty || peers.IsNullOrEmpty())
            {
                return;
            }

            InventorySender sender = new InventorySender();

            foreach (var spread in this.inventory_spread)
            {
                foreach (PeerConnection peer in peers)
                {
                    if (peer.GetInventoryReceive(spread.Key) == null &&
                        peer.GetInventorySpread(spread.Key) == null)
                    {
                        peer.AddInventorySpread(spread.Key, Helper.CurrentTimeMillis());
                        sender.Add(spread.Key, peer);
                    }
                    this.inventory_spread.TryRemove(spread.Key, out _);
                }
            }

            sender.SendInventory();
        }
示例#2
0
        private void ConsumerInventoryToFetch()
        {
            List <PeerConnection> peers =
                Manager.Instance.NetDelegate.ActivePeers.Where(peer => peer.IsIdle).ToList();

            if (this.inventory_fetch.IsEmpty || peers.IsNullOrEmpty())
            {
                return;
            }

            InventorySender sender = new InventorySender();
            long            now    = Helper.CurrentTimeMillis();

            foreach (var fetch in this.inventory_fetch)
            {
                if (fetch.Value
                    < now - Parameter.NetParameters.MSG_CACHE_DURATION_IN_BLOCKS * Parameter.ChainParameters.BLOCK_PRODUCED_INTERVAL)
                {
                    Logger.Info(
                        string.Format("This obj is too late to fetch, type: {0} hash: {1}.",
                                      fetch.Key.Type,
                                      fetch.Key.Hash));

                    this.inventory_fetch.TryRemove(fetch.Key, out _);
                    this.inventory_fetch_cache.Remove(fetch.Key.ToString());
                    return;
                }

                peers.Where(peer => peer.GetInventoryReceive(fetch.Key) != null &&
                            sender.GetSize(peer) < Parameter.NetParameters.MAX_TRX_FETCH_PER_PEER)
                .OrderBy(peer => sender.GetSize(peer))
                .FirstOrDefault(peer =>
                {
                    sender.Add(fetch.Key, peer);
                    peer.InventoryRequest.TryAdd(fetch.Key, now);
                    inventory_fetch.TryRemove(fetch.Key, out _);
                    return(true);
                });
            }

            sender.SendFetch();
        }