protected override Document GetDocument(InfoHashModel item) { if (item.IsDanger || _wordFilter.Contain(item.Name)) { log.InfoFormat("高危内容,参数:{0}", item.InfoHash); return(null); } var doc = new Document(); doc.AddStringField("InfoHash", item.InfoHash, Field.Store.YES); var nameField = doc.AddTextField("Name", item.Name, Field.Store.YES); nameField.Boost = _rankWords.Contain(item.Name) ? 0.9F : 10F; doc.AddInt32Field("DownNum", item.DownNum, Field.Store.YES); doc.AddInt32Field("FileNum", item.FileNum, Field.Store.YES); doc.AddInt64Field("FileSize", item.FileSize, Field.Store.YES); doc.AddInt64Field("CreateTime", item.CreateTime.Ticks, Field.Store.YES); if (item.Files != null && item.Files.Count > 0) { var flag = false; var names = new HashSet <string>(); var queues = new Queue <TorrentFileModel>(item.Files); while (queues.Count > 0) { var file = queues.Dequeue(); if (file.Files != null && file.Files.Count > 0) { foreach (var fileFile in file.Files) { queues.Enqueue(fileFile); } } else { if (file.Name.IsBlank() || !names.Add(file.Name)) { continue; } if (_wordFilter.Contain(file.Name)) { log.InfoFormat("高危内容,参数:{0}", item.InfoHash); return(null); } if (!flag) { flag = _rankWords.Contain(file.Name); } } } var fileField = doc.AddTextField("Files", string.Join(",", names), Field.Store.YES); fileField.Boost = flag ? 0.1F : 9F; } log.InfoFormat("处理数据:{0}", item.Id.ToString()); return(doc); }
protected override bool RegisterGetPeersMessage(byte[] infoHash, DhtNode node, out TransactionId msgId) { var nodeId = node.CompactEndPoint().ToInt64(); if (_filter.Contain(nodeId)) { msgId = null; return(false); } TransactionId messageId; if (_idMappingInfo.TryGetValue(infoHash, out var idMap)) { if (!idMap.Add(nodeId)) { msgId = null; return(false); } messageId = idMap.TransactionId; if (_mappingInfo.TryGetValue(messageId, out var info)) { info.LastTime = DateTime.Now; } } else { msgId = null; var cleared = false; while (!_bucket.TryTake(out messageId, 1000)) { if (cleared) //清理以后没有过期命令则丢弃该消息 { return(false); } ClearExpireMessage(); cleared = true; } if (!_mappingInfo.TryAdd(messageId, new MapInfo() { LastTime = DateTime.Now, InfoHash = infoHash })) { msgId = null; return(false); } idMap = new IdMapInfo() { TransactionId = messageId }; idMap.Add(nodeId); if (_idMappingInfo.TryAdd(infoHash, idMap)) { msgId = messageId; return(true); } return(false); } msgId = messageId; return(true); }