Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Aug 6, 2024
1 parent 75820d4 commit 42e2277
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 214 deletions.
455 changes: 312 additions & 143 deletions Cargo.lock

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bson = "2.9.0"
anyhow = "1.0.81"
bson = "2.11.0"
anyhow = "1.0.86"
azalea-chat = { git = "https://github.com/mat-1/azalea", default-features = false, rev = "1b6e0244606cf7917e68918d32928550aabf85b0" }
default-net = "0.22.0"
dotenv = "0.15.0"
libc = "0.2.153"
libc = "0.2.155"
perfect_rand = "0.2.0"
pnet = "0.34.0"
pnet_macros = "0.34.0"
pnet_macros_support = "0.34.0"
pnet = "0.35.0"
pnet_macros = "0.35.0"
pnet_macros_support = "0.35.0"
rand = "0.8.5"
regex = "1.10.3"
serde = "1.0.197"
serde_json = "1.0.114"
tokio = { version = "1.36.0", features = ["rt"] }
regex = "1.10.6"
serde = "1.0.204"
serde_json = "1.0.122"
tokio = { version = "1.39.2", features = ["rt"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
futures-util = "0.3.30"
lru-cache = "0.1.2"
toml = "0.8.11"
reqwest = { version = "0.11.26", default-features = false, features = [
toml = "0.8.19"
reqwest = { version = "0.12.5", default-features = false, features = [
"json",
"rustls-tls",
] }
parking_lot = "0.12.1"
parking_lot = "0.12.3"
enum-utils = "0.1.2"
flate2 = "1.0.28"
async-trait = "0.1.77"
mongodb = "2.8.1"
flate2 = "1.0.31"
async-trait = "0.1.81"
mongodb = "3.0.1"

[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }
Expand Down
2 changes: 1 addition & 1 deletion src/database/bulk_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<M: Send + Sync> CollectionExt for mongodb::Collection<M> {
if let Some(ref write_concern) = self.write_concern() {
command.insert("writeConcern", to_bson(write_concern)?);
}
let res = db.run_command(command, None).await?;
let res = db.run_command(command).await?;

Ok(bson::from_document(res)?)
}
Expand Down
42 changes: 14 additions & 28 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use futures_util::{stream::StreamExt, TryStreamExt};
use lru_cache::LruCache;
use mongodb::{
bson::doc,
options::{ClientOptions, FindOptions, Hint, ResolverConfig, UpdateOptions},
options::{ClientOptions, Hint},
Client, Collection,
};
use parking_lot::Mutex;
Expand Down Expand Up @@ -42,24 +42,22 @@ pub struct CachedIpHash {

impl Database {
pub async fn connect(mongodb_uri: &str) -> anyhow::Result<Self> {
let client_options =
ClientOptions::parse_with_resolver_config(mongodb_uri, ResolverConfig::cloudflare())
.await?;
let client_options = ClientOptions::parse(mongodb_uri).await?;

let client = Client::with_options(client_options)?;

// ping the database to make sure it's up
client
.database("mcscanner")
.run_command(doc! {"ping": 1}, None)
.run_command(doc! {"ping": 1})
.await?;

// download bad ips
let mut bad_ips = HashSet::new();
let mut cursor = client
.database("mcscanner")
.collection::<Document>("bad_servers")
.find(None, None)
.find(doc! {})
.await
.expect("bad servers collection must exist");
while let Some(Ok(doc)) = cursor.next().await {
Expand Down Expand Up @@ -110,7 +108,6 @@ impl Database {
doc! {"$project": {"playerCount": {"$size": {"$objectToArray": "$players"}}, "players": "$players"}},
doc! {"$match": {"playerCount": {"$gt": 1000}}},
],
None,
)
.await
.expect("servers collection must exist");
Expand All @@ -123,7 +120,6 @@ impl Database {
.update_one(
doc! {"_id": doc.get_object_id("_id").expect("_id must be present")},
update,
None,
)
.await
.expect("updating must not fail");
Expand Down Expand Up @@ -163,7 +159,6 @@ impl Database {
.update_one(
doc! {"_id": doc.get_object_id("_id").expect("_id must be present")},
update,
None,
)
.await
.expect("updating must not fail");
Expand Down Expand Up @@ -191,23 +186,20 @@ impl Database {
"timestamp": Bson::DateTime(bson::DateTime::from_system_time(SystemTime::now())),
}
},
// upsert in case the server was already there
UpdateOptions::builder().upsert(true).build(),
)
// upsert in case the server was already there
.upsert(true)
.await?;

// delete all servers with this ip that aren't on 25565
let r = self
.client
.database("mcscanner")
.collection::<Document>("servers")
.delete_many(
doc! {
"addr": u32::from(addr),
"port": { "$ne": 25565 }
},
None,
)
.delete_many(doc! {
"addr": u32::from(addr),
"port": { "$ne": 25565 }
})
.await?;

println!("deleted {} bad servers", r.deleted_count);
Expand Down Expand Up @@ -314,16 +306,10 @@ pub async fn collect_all_servers(

let mut cursor = database
.servers_coll()
.find(
doc_filter,
FindOptions::builder()
// prefer newest first
// .sort(doc! {"_id": 1})
.projection(doc! {"addr": 1, "port": 1, "_id": 0})
.batch_size(2000)
.hint(Some(Hint::Keys(doc! {"addr": 1, "port": 1})))
.build(),
)
.find(doc_filter)
.projection(doc! {"addr": 1, "port": 1, "_id": 0})
.batch_size(2000)
.hint(Hint::Keys(doc! {"addr": 1, "port": 1}))
.await?;

let mut servers = Vec::new();
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(lazy_cell)]

pub mod asns;
pub mod config;
pub mod database;
Expand Down
7 changes: 2 additions & 5 deletions src/modes/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{

use bson::{doc, Document};
use futures_util::StreamExt;
use mongodb::options::AggregateOptions;

use crate::database::{self, Database};

Expand Down Expand Up @@ -40,10 +39,8 @@ pub async fn get_addrs_and_protocol_versions(

let mut cursor = database
.servers_coll()
.aggregate(
pipeline,
AggregateOptions::builder().batch_size(2000).build(),
)
.aggregate(pipeline)
.batch_size(2000)
.await
.unwrap();

Expand Down
18 changes: 6 additions & 12 deletions src/modes/rescan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{

use bson::{doc, Document};
use futures_util::StreamExt;
use mongodb::options::AggregateOptions;
use serde::Deserialize;
use tracing::warn;

Expand Down Expand Up @@ -76,10 +75,8 @@ pub async fn get_ranges(

let mut cursor = database
.servers_coll()
.aggregate(
pipeline,
AggregateOptions::builder().batch_size(2000).build(),
)
.aggregate(pipeline)
.batch_size(2000)
.await
.unwrap();

Expand All @@ -100,13 +97,10 @@ pub async fn get_ranges(
.client
.database("mcscanner")
.collection::<bson::Document>("servers")
.delete_many(
doc! {
"addr": u32::from(addr),
"port": { "$ne": 25565 }
},
None,
)
.delete_many(doc! {
"addr": u32::from(addr),
"port": { "$ne": 25565 }
})
.await?;
// this doesn't actually remove it from the bad_ips database, it just makes it
// so we don't delete twice
Expand Down
11 changes: 4 additions & 7 deletions src/processing/minecraft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,10 @@ impl ProcessableProtocol for protocols::Minecraft {
// check that there were no anonymous players before
let servers_coll = database.servers_coll();
let current_data = servers_coll
.find_one(
doc! {
"addr": u32::from(*target.ip()),
"port": target.port() as u32
},
None,
)
.find_one(doc! {
"addr": u32::from(*target.ip()),
"port": target.port() as u32
})
.await
.unwrap_or_default()
.unwrap_or_default();
Expand Down

0 comments on commit 42e2277

Please sign in to comment.