This commit is contained in:
桥下红药
2026-01-17 17:25:22 +08:00
parent 4dfb706073
commit 192dad7519
3 changed files with 12 additions and 14 deletions
+9 -10
View File
@@ -1,7 +1,7 @@
[package]
name = "dht-crawler"
version = "0.0.4"
edition = "2021"
edition = "2024"
authors = ["桥下红药 <1121744186@qq.com>"]
description = "高性能的 Rust DHT(分布式哈希表)爬虫库,用于爬取 BitTorrent DHT 网络中的种子信息"
license = "MIT"
@@ -29,9 +29,11 @@ bytes = "1.0"
bloomfilter = "1.0"
ahash = "0.8"
serde_bytes = "0.11.19"
metrics = "0.24"
[dev-dependencies]
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "tracing-log"] }
mimalloc = "0.1"
[features]
@@ -42,16 +44,13 @@ mimalloc = []
name = "dht_crawler_example"
path = "examples/main.rs"
# ==================== 性能优化配置 ====================
[profile.release]
opt-level = 3 # 最高优化级别
lto = "fat" # 链接时优化(LTO)- 显著提升性能
codegen-units = 1 # 单编译单元 - 更好的优化但编译慢
panic = "abort" # panic时直接终止 - 减少二进制大小
strip = true # 移除调试符号 - 减小二进制
opt-level = 3
lto = "fat"
codegen-units = 1
panic = "abort"
strip = true
# 开发时快速编译
[profile.dev]
opt-level = 0
debug = true
+1 -2
View File
@@ -13,8 +13,7 @@ async fn main() -> Result<()> {
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info");
}
// 直接输出到 stdout,避免 _guard 被 drop 导致日志丢失
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.with_ansi(true)
+2 -2
View File
@@ -133,7 +133,7 @@ impl DHTServer {
let node_id = generate_random_id();
let mut rng = rand::thread_rng();
let token_secret: Vec<u8> = (0..10).map(|_| rng.gen()).collect();
let token_secret: Vec<u8> = (0..10).map(|_| rng.r#gen::<u8>()).collect();
// 使用分片队列
// 队列容量:从配置获取
@@ -780,7 +780,7 @@ impl DHTServer {
fn generate_random_id() -> Vec<u8> {
let mut rng = rand::thread_rng();
(0..20).map(|_| rng.gen()).collect()
(0..20).map(|_| rng.r#gen::<u8>()).collect()
}
fn generate_neighbor_target(remote_id: &[u8], local_id: &[u8]) -> Vec<u8> {