コード例 #1
0
 public Worker(ILogger <Worker> logger, LotusClient lotusClient, LotusClientSetting lotusClientSetting, FilPanManager filPanManager)
 {
     _logger             = logger;
     _lotusClient        = lotusClient;
     _lotusClientSetting = lotusClientSetting;
     _filPanManager      = filPanManager;
 }
コード例 #2
0
ファイル: UploadController.cs プロジェクト: deng/filshare
 public UploadController(ILogger <UploadController> logger, LotusClient lotusClient, LotusClientSetting lotusClientSetting, FilPanManager filPanManager)
 {
     _logger             = logger;
     _lotusClient        = lotusClient;
     _lotusClientSetting = lotusClientSetting;
     _filPanManager      = filPanManager;
 }
コード例 #3
0
 public CloudSpeedManager(ILogger <CloudSpeedManager> logger,
                          IPanPasswordHasher panPasswordHasher, UploadSetting uploadSetting, LotusClient lotusClient)
 {
     _logger            = logger;
     _panPasswordHasher = panPasswordHasher;
     _uploadSetting     = uploadSetting;
     _lotusClient       = lotusClient;
 }
コード例 #4
0
        private async Task <ClientStartDealParams> CreateTTGraphsyncClientStartDealParams(LotusClient lotusClient, ClientStartDealRequest model)
        {
            var dataRef = new TransferDataRef()
            {
                TransferType = TransferType.graphsync.ToString(),
                Root         = new Cid()
                {
                    Value = model.DataCid
                },
            };

            var walletAddress = await lotusClient.WalletDefaultAddress();

            if (!walletAddress.Success)
            {
                _logger.LogError(0, "can't get wallet default address.");
                return(null);
            }
            var dealParams = new ClientStartDealParams()
            {
                Data               = dataRef,
                Miner              = model.Miner,
                MinBlocksDuration  = (ulong)model.Duration,
                EpochPrice         = model.Price,
                Wallet             = walletAddress.Result,
                VerifiedDeal       = false,
                ProviderCollateral = "0"
            };

            return(dealParams);
        }
コード例 #5
0
ファイル: LotusWorker.cs プロジェクト: deng/CloudSpeed
        private async Task ClientStartDeal(LotusClient lotusClient, string fileDealId, string cid, CancellationToken stoppingToken)
        {
            try
            {
                //limit transfering
                while (_transferingDealIdBytes.Count > 0)
                {
                    if (stoppingToken.IsCancellationRequested)
                    {
                        break;
                    }

                    var keys = _transferingDealIdBytes.Keys.ToArray();
                    var maxSizeDealTransfering = LotusMinerSetting.GetMaxTransferingSizeInBytes(_lotusClientSetting.MaxTransferingSize);
                    if (maxSizeDealTransfering == 0 && _transferingDealIdBytes.Count < _lotusClientSetting.MaxTransferingCount)
                    {
                        break;
                    }

                    var sizeTransferingDealIds = _transferingDealIdBytes.Sum(a => a.Value);
                    if (sizeTransferingDealIds < maxSizeDealTransfering && _transferingDealIdBytes.Count < _lotusClientSetting.MaxTransferingCount)
                    {
                        break;
                    }

                    if (sizeTransferingDealIds >= maxSizeDealTransfering)
                    {
                        _logger.LogWarning(0, string.Format("limit transfering by sizes {0} >= {1}(max).", sizeTransferingDealIds, maxSizeDealTransfering));
                    }
                    if (_transferingDealIdBytes.Count > _lotusClientSetting.MaxTransferingCount)
                    {
                        _logger.LogWarning(0, string.Format("limit transfering by count {0} >= {1}(max).", _transferingDealIdBytes.Count, _lotusClientSetting.MaxTransferingCount));
                    }

                    await Task.Delay(10000, stoppingToken);
                }

                if (stoppingToken.IsCancellationRequested)
                {
                    return;
                }

                var fileCid = await _cloudSpeedManager.GetFileCidByCid(cid);

                if (fileCid == null)
                {
                    _logger.LogError(0, string.Format("fileCid not found {0}.", cid));
                    await _cloudSpeedManager.UpdateFileDeal(fileDealId, FileDealStatus.Failed, "fileCid not found");

                    return;
                }
                var fileFullPath = _uploadSetting.GetStoragePath(fileCid.Id);
                if (!File.Exists(fileFullPath))
                {
                    _logger.LogError(0, string.Format("file not found {0}.", cid));
                    await _cloudSpeedManager.UpdateFileDeal(fileDealId, FileDealStatus.Failed, "file not found");

                    return;
                }
                _logger.LogInformation("query file length: {path}", fileFullPath);
                var fileSize = new FileInfo(fileFullPath).Length;

                var online = fileSize < SectorSizeConstants.Bytes512MiB;

                var miner = _lotusClientSetting.GetMinerByFileSize(fileSize, online);

                if (miner == null)
                {
                    online = !online;
                    miner  = _lotusClientSetting.GetMinerByFileSize(fileSize, online);
                }

                if (miner == null)
                {
                    _logger.LogError(0, string.Format("can't found any miner for :{0} {1}.", cid, fileSize));
                    return;
                }

                var minerInfo = await lotusClient.StateMinerInfo(new StateMinerInfoRequest { Miner = miner.Miner });

                if (!minerInfo.Success)
                {
                    _logger.LogError(0, string.Format("can't get state info from :{0}.", miner));
                    return;
                }
                var askingPrice = miner.AskingPrice;
                if (askingPrice == 0)
                {
                    var ask = await lotusClient.ClientQueryAsk(new ClientQueryAskRequest
                    {
                        PeerId = minerInfo.Result.PeerId,
                        Miner  = miner.Miner
                    });

                    if (!ask.Success)
                    {
                        _logger.LogError(0, string.Format("can't query ask from :{0} {1}.", minerInfo.Result.PeerId, miner));
                        return;
                    }
                    if (!decimal.TryParse(ask.Result.Price, out askingPrice))
                    {
                        _logger.LogError(0, string.Format("can't parse ask price :{0}.", ask.Result.Price));
                        return;
                    }
                }

                if (askingPrice == 0)
                {
                    _logger.LogError(0, "asking price should be more than zero.");
                    return;
                }

                _logger.LogInformation("will use askingPrice {askingPrice} for miner {miner}", askingPrice, miner.Miner);

                var minDealDuration = 180 * LotusConstants.EpochsInDay;
                var dealRequest     = new ClientStartDealRequest
                {
                    DataCid     = cid,
                    Miner       = miner.Miner,
                    Duration    = minDealDuration,
                    AskingPrice = askingPrice
                };

                if (online)
                {
                    await _dealerService.OnlineExecute(fileDealId, fileCid.Id, dealRequest);
                }
                else
                {
                    await _dealerService.OfflineExecute(fileDealId, fileCid.Id, dealRequest, stoppingToken);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(0, ex, "lotus client start deal fail:" + ex.ToString());
            }
        }