Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Udpate dependencies #1227

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 137 additions & 56 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions contrib/bencode/src/mutable/bencode_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ impl<'a> BRefAccess for BencodeMut<'a> {
fn str(&self) -> Option<&str> {
let bytes = self.bytes()?;

match str::from_utf8(bytes) {
Ok(n) => Some(n),
Err(_) => None,
}
str::from_utf8(bytes).ok()
}

fn int(&self) -> Option<i64> {
Expand Down
5 changes: 1 addition & 4 deletions contrib/bencode/src/reference/bencode_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ impl<'a> BRefAccessExt<'a> for BencodeRef<'a> {
fn str_ext(&self) -> Option<&'a str> {
let bytes = self.bytes_ext()?;

match str::from_utf8(bytes) {
Ok(n) => Some(n),
Err(_) => None,
}
str::from_utf8(bytes).ok()
}

fn bytes_ext(&self) -> Option<&'a [u8]> {
Expand Down
3 changes: 2 additions & 1 deletion contrib/bencode/src/reference/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ fn decode_dict(
})
}
_ => (),
};
}

curr_pos = next_pos;

let (value, next_pos) = decode(bytes, curr_pos, opts, depth + 1)?;
Expand Down
2 changes: 1 addition & 1 deletion packages/test-helpers/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub fn ephemeral_ipv6() -> Configuration {

if let Some(ref mut http_api) = cfg.http_api {
http_api.bind_address.clone_from(&ipv6);
};
}

if let Some(ref mut http_trackers) = cfg.http_trackers {
http_trackers[0].bind_address.clone_from(&ipv6);
Expand Down
6 changes: 3 additions & 3 deletions packages/test-helpers/src/random.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Random data generators for testing.
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use rand::distr::Alphanumeric;
use rand::{rng, Rng};

/// Returns a random alphanumeric string of a certain size.
///
/// It is useful for generating random names, IDs, etc for testing.
pub fn string(size: usize) -> String {
thread_rng().sample_iter(&Alphanumeric).take(size).map(char::from).collect()
rng().sample_iter(&Alphanumeric).take(size).map(char::from).collect()
}
2 changes: 1 addition & 1 deletion packages/torrent-repository/tests/common/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl Repo {
Repo::DashMapMutexStd(repo) => {
repo.torrents.insert(*info_hash, torrent.into());
}
};
}
self.get(info_hash).await
}
}
2 changes: 1 addition & 1 deletion packages/tracker-api-client/src/v1/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Client {

if let Some(token) = &self.connection_info.api_token {
query.add_param(QueryParam::new("token", token));
};
}

self.get_request_with_query(path, query, headers).await
}
Expand Down
2 changes: 1 addition & 1 deletion packages/tracker-client/src/udp/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pub async fn check(remote_addr: &SocketAddr) -> Result<String, String> {
match client.send(connect_request.into()).await {
Ok(_) => (),
Err(e) => tracing::debug!("Error: {e:?}."),
};
}

let process = move |response| {
if matches!(response, Response::Connect(_connect_response)) {
Expand Down
6 changes: 3 additions & 3 deletions packages/tracker-core/src/authentication/key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ use std::sync::Arc;
use std::time::Duration;

use derive_more::Display;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use rand::distr::Alphanumeric;
use rand::{rng, Rng};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use torrust_tracker_clock::clock::Time;
Expand Down Expand Up @@ -81,7 +81,7 @@ pub fn generate_permanent_key() -> PeerKey {
/// * `lifetime`: if `None` the key will be permanent.
#[must_use]
pub fn generate_key(lifetime: Option<Duration>) -> PeerKey {
let random_id: String = thread_rng()
let random_id: String = rng()
.sample_iter(&Alphanumeric)
.take(AUTH_KEY_LENGTH)
.map(char::from)
Expand Down
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub async fn start(config: &Configuration, app_container: &Arc<AppContainer>) ->
http_tracker::start_job(http_tracker_container, registar.give_form(), servers::http::Version::V1).await
{
jobs.push(job);
};
}
}
} else {
tracing::info!("No HTTP blocks in configuration");
Expand All @@ -111,7 +111,7 @@ pub async fn start(config: &Configuration, app_container: &Arc<AppContainer>) ->

if let Some(job) = tracker_apis::start_job(http_api_container, registar.give_form(), servers::apis::Version::V1).await {
jobs.push(job);
};
}
} else {
tracing::info!("No API block in configuration");
}
Expand Down
2 changes: 1 addition & 1 deletion src/console/ci/e2e/logs_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl RunningServices {

if !line.contains(INFO_THRESHOLD) {
continue;
};
}

if line.contains(UDP_TRACKER_LOG_TARGET) {
if let Some(captures) = udp_re.captures(&clean_line) {
Expand Down
8 changes: 2 additions & 6 deletions src/console/ci/e2e/tracker_container.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::Duration;

use rand::distributions::Alphanumeric;
use rand::distr::Alphanumeric;
use rand::Rng;

use super::docker::{RunOptions, RunningContainer};
Expand Down Expand Up @@ -113,11 +113,7 @@ impl TrackerContainer {
}

fn generate_random_container_name(prefix: &str) -> String {
let rand_string: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(20)
.map(char::from)
.collect();
let rand_string: String = rand::rng().sample_iter(&Alphanumeric).take(20).map(char::from).collect();

format!("{prefix}{rand_string}")
}
Expand Down
18 changes: 9 additions & 9 deletions src/servers/apis/v1/context/auth_key/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ use crate::servers::apis::v1::responses::{invalid_auth_key_param_response, ok_re
/// It returns these types of responses:
///
/// - `200` with a json [`AuthKey`]
/// resource. If the key was generated successfully.
/// resource. If the key was generated successfully.
/// - `400` with an error if the key couldn't been added because of an invalid
/// request.
/// request.
/// - `500` with serialized error in debug format. If the key couldn't be
/// generated.
/// generated.
///
/// Refer to the [API endpoint documentation](crate::servers::apis::v1::context::auth_key#generate-a-new-authentication-key)
/// for more information about this endpoint.
Expand Down Expand Up @@ -57,9 +57,9 @@ pub async fn add_auth_key_handler(
/// It returns two types of responses:
///
/// - `200` with an json [`AuthKey`]
/// resource. If the key was generated successfully.
/// resource. If the key was generated successfully.
/// - `500` with serialized error in debug format. If the key couldn't be
/// generated.
/// generated.
///
/// Refer to the [API endpoint documentation](crate::servers::apis::v1::context::auth_key#generate-a-new-authentication-key)
/// for more information about this endpoint.
Expand Down Expand Up @@ -99,9 +99,9 @@ pub struct KeyParam(String);
/// It returns two types of responses:
///
/// - `200` with an json [`ActionStatus::Ok`](crate::servers::apis::v1::responses::ActionStatus::Ok)
/// response. If the key was deleted successfully.
/// response. If the key was deleted successfully.
/// - `500` with serialized error in debug format. If the key couldn't be
/// deleted.
/// deleted.
///
/// Refer to the [API endpoint documentation](crate::servers::apis::v1::context::auth_key#delete-an-authentication-key)
/// for more information about this endpoint.
Expand All @@ -124,9 +124,9 @@ pub async fn delete_auth_key_handler(
/// It returns two types of responses:
///
/// - `200` with an json [`ActionStatus::Ok`](crate::servers::apis::v1::responses::ActionStatus::Ok)
/// response. If the keys were successfully reloaded.
/// response. If the keys were successfully reloaded.
/// - `500` with serialized error in debug format. If the they couldn't be
/// reloaded.
/// reloaded.
///
/// Refer to the [API endpoint documentation](crate::servers::apis::v1::context::auth_key#reload-authentication-keys)
/// for more information about this endpoint.
Expand Down
2 changes: 1 addition & 1 deletion src/servers/udp/server/launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl Launcher {
stats_event_sender
.send_event(statistics::event::Event::UdpRequestAborted)
.await;
};
}
}
} else {
tokio::task::yield_now().await;
Expand Down
4 changes: 2 additions & 2 deletions src/shared/crypto/ephemeral_instance_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ pub type CipherArrayBlowfish = GenericArray<u8, <CipherBlowfish as BlockSizeUser

lazy_static! {
/// The random static seed.
pub static ref RANDOM_SEED: Seed = Rng::gen(&mut ThreadRng::default());
pub static ref RANDOM_SEED: Seed = Rng::random(&mut ThreadRng::default());

/// The random cipher from the seed.
pub static ref RANDOM_CIPHER_BLOWFISH: CipherBlowfish = CipherBlowfish::new_from_slice(&Rng::gen::<Seed>(&mut ThreadRng::default())).expect("it could not generate key");
pub static ref RANDOM_CIPHER_BLOWFISH: CipherBlowfish = CipherBlowfish::new_from_slice(&Rng::random::<Seed>(&mut ThreadRng::default())).expect("it could not generate key");

/// The constant cipher for testing.
pub static ref ZEROED_TEST_CIPHER_BLOWFISH: CipherBlowfish = CipherBlowfish::new_from_slice(&[0u8; 32]).expect("it could not generate key");
Expand Down
8 changes: 4 additions & 4 deletions tests/common/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ pub fn invalid_info_hashes() -> Vec<String> {
"-1".to_string(),
"1.1".to_string(),
"INVALID INFOHASH".to_string(),
"9c38422213e30bff212b30c360d26f9a0213642".to_string(), // 39-char length instead of 40
"9c38422213e30bff212b30c360d26f9a0213642".to_string(), // 39-char length instead of 40. DevSkim: ignore DS173237
"9c38422213e30bff212b30c360d26f9a0213642&".to_string(), // Invalid char
]
.to_vec()
}

/// Returns a random info hash.
pub fn random_info_hash() -> InfoHash {
let mut rng = rand::thread_rng();
let random_bytes: [u8; 20] = rand::Rng::gen(&mut rng);
let mut rng = rand::rng();
let random_bytes: [u8; 20] = rand::Rng::random(&mut rng);

InfoHash::from_bytes(&random_bytes)
}

/// Returns a random transaction id.
pub fn random_transaction_id() -> TransactionId {
let random_value = rand::Rng::gen::<i32>(&mut rand::thread_rng());
let random_value = rand::Rng::random::<i32>(&mut rand::rng());
TransactionId::new(random_value)
}
12 changes: 6 additions & 6 deletions tests/servers/udp/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async fn send_connection_request(transaction_id: TransactionId, client: &UdpTrac
match client.send(connect_request.into()).await {
Ok(_) => (),
Err(err) => panic!("{err}"),
};
}

let response = match client.receive().await {
Ok(response) => response,
Expand All @@ -52,7 +52,7 @@ async fn should_return_a_bad_request_response_when_the_client_sends_an_empty_req
match client.client.send(&empty_udp_request()).await {
Ok(_) => (),
Err(err) => panic!("{err}"),
};
}

let response = match client.client.receive().await {
Ok(response) => response,
Expand Down Expand Up @@ -94,7 +94,7 @@ mod receiving_a_connection_request {
match client.send(connect_request.into()).await {
Ok(_) => (),
Err(err) => panic!("{err}"),
};
}

let response = match client.receive().await {
Ok(response) => response,
Expand Down Expand Up @@ -146,7 +146,7 @@ mod receiving_an_announce_request {
match client.send(announce_request.into()).await {
Ok(_) => (),
Err(err) => panic!("{err}"),
};
}

match client.receive().await {
Ok(response) => response,
Expand Down Expand Up @@ -276,7 +276,7 @@ mod receiving_an_announce_request {
match client.send(announce_request.into()).await {
Ok(_) => (),
Err(err) => panic!("{err}"),
};
}

assert!(client.receive().await.is_err());

Expand Down Expand Up @@ -333,7 +333,7 @@ mod receiving_an_scrape_request {
match client.send(scrape_request.into()).await {
Ok(_) => (),
Err(err) => panic!("{err}"),
};
}

let response = match client.receive().await {
Ok(response) => response,
Expand Down