设为首页 加入收藏

TOP

使用 .NET Core 开发 BT Tracker 服务器(三)
2019-09-17 18:24:21 】 浏览:84
Tags:使用 .NET Core 开发 Tracker 服务器
ut) { // 如果 BT 客户端没有传递 IP,则通过 Context 获得。 if (string.IsNullOrEmpty(input.Ip)) input.Ip = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(); // 本机测试用。 input.Ip = "127.0.0.1"; AnnounceInputParameters inputPara = input; var resultDict = new BDictionary(); // 如果产生了错误,则不执行其他操作,直接返回结果。 if (inputPara.Error.Count == 0) { _bitTorrentManager.UpdatePeer(input.Info_Hash,inputPara); _bitTorrentManager.ClearZombiePeers(input.Info_Hash,TimeSpan.FromMinutes(10)); var peers = _bitTorrentManager.GetPeers(input.Info_Hash); HandlePeersData(resultDict,peers,inputPara); // 构建剩余字段信息 // 客户端等待时间 resultDict.Add(TrackerServerConsts.IntervalKey,new BNumber((int)TimeSpan.FromSeconds(30).TotalSeconds)); // 最小等待间隔 resultDict.Add(TrackerServerConsts.MinIntervalKey,new BNumber((int)TimeSpan.FromSeconds(30).TotalSeconds)); // Tracker 服务器的 Id resultDict.Add(TrackerServerConsts.TrackerIdKey,new BString("Tracker-DEMO")); // 已完成的 Peer 数量 resultDict.Add(TrackerServerConsts.CompleteKey,new BNumber(_bitTorrentManager.GetComplete(input.Info_Hash))); // 非做种状态的 Peer 数量 resultDict.Add(TrackerServerConsts.IncompleteKey,new BNumber(_bitTorrentManager.GetInComplete(input.Info_Hash))); } else { resultDict = inputPara.Error; } // 写入响应结果。 var resultDictBytes = resultDict.EncodeAsBytes(); var response = _httpContextAccessor.HttpContext.Response; response.ContentType = "text/plain;"; response.StatusCode = 200; response.ContentLength = resultDictBytes.Length; await response.Body.WriteAsync(resultDictBytes); }

5.5 测试效果

六、源码下载

本 DEMO 已经托管到 Github 上,有需要的朋友可以自行前往以下地址进行 clone 。

GitHub 仓库地址: https://github.com/GameBelial/BTTrackerDemo

首页 上一页 1 2 3 4 5 6 7 下一页 尾页 3/7/7
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇巧用XML配置校验导入Excel的列数.. 下一篇[古怪问题] Marshal.GetActiveObj..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目