diff --git a/Cargo.toml b/Cargo.toml index 2939da7..446d211 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -resolver = "2" +resolver = "3" members = [ "blah-types", "blahctl", diff --git a/blah-types/Cargo.toml b/blah-types/Cargo.toml index ec6b466..5dbb1e0 100644 --- a/blah-types/Cargo.toml +++ b/blah-types/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "blah-types" version = "0.0.0" -edition = "2021" +edition = "2024" [features] default = ["ed25519-dalek/default"] diff --git a/blah-types/benches/crypto_ops.rs b/blah-types/benches/crypto_ops.rs index 9b6f92f..1be802a 100644 --- a/blah-types/benches/crypto_ops.rs +++ b/blah-types/benches/crypto_ops.rs @@ -3,11 +3,11 @@ use std::hint::black_box; use std::time::Instant; use blah_types::msg::{ChatPayload, UserRegisterChallengeResponse, UserRegisterPayload}; -use blah_types::{get_timestamp, Id, PubKey, SignExt, Signee, UserKey}; -use criterion::{criterion_group, criterion_main, Criterion}; +use blah_types::{Id, PubKey, SignExt, Signee, UserKey, get_timestamp}; +use criterion::{Criterion, criterion_group, criterion_main}; use ed25519_dalek::SigningKey; -use rand::rngs::mock::StepRng; use rand::rngs::StdRng; +use rand::rngs::mock::StepRng; use rand::{Rng, SeedableRng}; use sha2::{Digest, Sha256}; @@ -24,7 +24,7 @@ fn bench_register_pow(c: &mut Criterion) { id_key: id_key.clone(), server_url: "http://some.example.com".parse().unwrap(), id_url: "http://another.example.com".parse().unwrap(), - challenge: Some(UserRegisterChallengeResponse::Pow { nonce: rng.gen() }), + challenge: Some(UserRegisterChallengeResponse::Pow { nonce: rng.r#gen() }), }; let mut signee = Signee { nonce: 0, @@ -35,7 +35,7 @@ fn bench_register_pow(c: &mut Criterion) { c.bench_function("register_pow_iter", |b| { b.iter_custom(|iters| { - signee.nonce = rng.gen(); + signee.nonce = rng.r#gen(); let inst = Instant::now(); for _ in 0..iters { diff --git a/blah-types/src/crypto.rs b/blah-types/src/crypto.rs index c58dda7..b2e9786 100644 --- a/blah-types/src/crypto.rs +++ b/blah-types/src/crypto.rs @@ -4,8 +4,8 @@ use std::fmt; use std::str::FromStr; use ed25519_dalek::{ - Signature, SignatureError, Signer, SigningKey, VerifyingKey, PUBLIC_KEY_LENGTH, - SIGNATURE_LENGTH, + PUBLIC_KEY_LENGTH, SIGNATURE_LENGTH, Signature, SignatureError, Signer, SigningKey, + VerifyingKey, }; use rand::RngCore; use serde::{Deserialize, Serialize}; diff --git a/blah-types/src/lib.rs b/blah-types/src/lib.rs index 1c66e52..44ce37a 100644 --- a/blah-types/src/lib.rs +++ b/blah-types/src/lib.rs @@ -3,7 +3,7 @@ pub use bitflags; pub use ed25519_dalek; pub use url; -pub use crypto::{get_timestamp, PubKey, SignExt, Signed, Signee, UserKey}; +pub use crypto::{PubKey, SignExt, Signed, Signee, UserKey, get_timestamp}; pub use msg::Id; #[cfg(not(feature = "schemars"))] @@ -24,8 +24,8 @@ macro_rules! impl_json_schema_as { concat!(module_path!(), "::", stringify!($ty)).into() } - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - gen.subschema_for::<$as_ty>() + fn json_schema(g: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema { + g.subschema_for::<$as_ty>() } } }; diff --git a/blah-types/src/msg.rs b/blah-types/src/msg.rs index 78eddb4..6ff2db7 100644 --- a/blah-types/src/msg.rs +++ b/blah-types/src/msg.rs @@ -3,7 +3,7 @@ use std::fmt; use std::num::ParseIntError; use std::str::FromStr; -use serde::{de, ser, Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de, ser}; use url::Url; use crate::identity::IdUrl; @@ -244,7 +244,7 @@ impl RichText { struct Fmt<'a>(&'a RichText); impl fmt::Display for Fmt<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - for p in &self.0 .0 { + for p in &self.0.0 { f.write_str(&p.text)?; } Ok(()) @@ -259,7 +259,7 @@ impl RichText { struct Fmt<'a>(&'a RichText); impl fmt::Display for Fmt<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - for p in &self.0 .0 { + for p in &self.0.0 { let tags = [ (p.attrs.bold, "", ""), (p.attrs.code, "", ""), @@ -490,9 +490,9 @@ impl_for_bitflags!(ServerPermission, MemberPermission, RoomAttrs); #[cfg(test)] mod tests { - use ed25519_dalek::{SigningKey, PUBLIC_KEY_LENGTH}; - use expect_test::expect; use AddMemberPayload; + use ed25519_dalek::{PUBLIC_KEY_LENGTH, SigningKey}; + use expect_test::expect; use crate::SignExt; diff --git a/blah-types/src/rusqlite_impl.rs b/blah-types/src/rusqlite_impl.rs index 264f571..9d629a8 100644 --- a/blah-types/src/rusqlite_impl.rs +++ b/blah-types/src/rusqlite_impl.rs @@ -1,4 +1,4 @@ -use ed25519_dalek::{VerifyingKey, PUBLIC_KEY_LENGTH}; +use ed25519_dalek::{PUBLIC_KEY_LENGTH, VerifyingKey}; use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef}; use rusqlite::{Result, ToSql}; diff --git a/blah-types/src/server.rs b/blah-types/src/server.rs index fce6c8a..abdf420 100644 --- a/blah-types/src/server.rs +++ b/blah-types/src/server.rs @@ -5,9 +5,9 @@ use std::fmt; use serde::{Deserialize, Serialize}; use url::Url; +use crate::PubKey; use crate::identity::UserIdentityDesc; use crate::msg::{Id, MemberPermission, RoomAttrs, SignedChatMsgWithId}; -use crate::PubKey; /// The response object returned as body on HTTP error status. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/blahctl/Cargo.toml b/blahctl/Cargo.toml index 5ee9052..4e78463 100644 --- a/blahctl/Cargo.toml +++ b/blahctl/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "blahctl" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] anyhow = "1" diff --git a/blahctl/src/main.rs b/blahctl/src/main.rs index f63e778..4096340 100644 --- a/blahctl/src/main.rs +++ b/blahctl/src/main.rs @@ -2,10 +2,10 @@ use std::fs; use std::path::{Path, PathBuf}; use std::time::SystemTime; -use anyhow::{ensure, Context, Result}; +use anyhow::{Context, Result, ensure}; use blah_types::identity::{IdUrl, UserActKeyDesc, UserIdentityDesc, UserProfile}; use blah_types::msg::{RoomAttrs, ServerPermission}; -use blah_types::{bitflags, get_timestamp, PubKey, SignExt}; +use blah_types::{PubKey, SignExt, bitflags, get_timestamp}; use clap::value_parser; use ed25519_dalek::pkcs8::spki::der::pem::LineEnding; use ed25519_dalek::pkcs8::{DecodePrivateKey, DecodePublicKey, EncodePrivateKey}; @@ -13,7 +13,7 @@ use ed25519_dalek::{SigningKey, VerifyingKey}; use humantime::Duration; use rand::thread_rng; use reqwest::Url; -use rusqlite::{named_params, prepare_and_bind, Connection}; +use rusqlite::{Connection, named_params, prepare_and_bind}; use tokio::runtime::Runtime; const USER_AGENT: fn() -> String = || match option_env!("CFG_RELEASE") { diff --git a/blahd/Cargo.toml b/blahd/Cargo.toml index 6f65d01..70cf154 100644 --- a/blahd/Cargo.toml +++ b/blahd/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "blahd" version = "0.0.0" -edition = "2021" +edition = "2024" [features] default = [] diff --git a/blahd/src/bin/blahd.rs b/blahd/src/bin/blahd.rs index fd4ce84..dfdb285 100644 --- a/blahd/src/bin/blahd.rs +++ b/blahd/src/bin/blahd.rs @@ -3,10 +3,10 @@ use std::os::fd::{FromRawFd, OwnedFd}; use std::path::PathBuf; use std::sync::Arc; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{Context, Result, anyhow, bail}; use blahd::config::{Config, ListenConfig}; use blahd::{AppState, Database}; -use tokio::signal::unix::{signal, SignalKind}; +use tokio::signal::unix::{SignalKind, signal}; /// Blah Chat Server #[derive(Debug, clap::Parser)] @@ -65,7 +65,7 @@ async fn main_serve(db: Database, config: Config) -> Result<()> { .context("failed to listen on socket")?, ), ListenConfig::Systemd(_) => { - use rustix::net::{getsockname, SocketAddr}; + use rustix::net::{SocketAddr, getsockname}; let [fd] = sd_notify::listen_fds() .context("failed to get fds from sd_listen_fds(3)")? diff --git a/blahd/src/config.rs b/blahd/src/config.rs index 644c787..0ab95ae 100644 --- a/blahd/src/config.rs +++ b/blahd/src/config.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use serde_constant::ConstBool; -use crate::{database, ServerConfig}; +use crate::{ServerConfig, database}; #[derive(Debug, Clone, Deserialize)] #[serde(deny_unknown_fields)] diff --git a/blahd/src/database.rs b/blahd/src/database.rs index 03cede1..05139b0 100644 --- a/blahd/src/database.rs +++ b/blahd/src/database.rs @@ -1,7 +1,7 @@ use std::num::NonZero; use std::path::PathBuf; -use anyhow::{ensure, Context}; +use anyhow::{Context, ensure}; use blah_types::identity::UserIdentityDesc; use blah_types::msg::{ ChatPayload, MemberPermission, RoomAttrs, ServerPermission, SignedChatMsg, SignedChatMsgWithId, @@ -11,7 +11,7 @@ use blah_types::server::RoomMetadata; use blah_types::{Id, PubKey, Signee, UserKey}; use parking_lot::Mutex; use rusqlite::types::FromSqlError; -use rusqlite::{named_params, params, prepare_cached_and_bind, Connection, OpenFlags, Row}; +use rusqlite::{Connection, OpenFlags, Row, named_params, params, prepare_cached_and_bind}; use serde::Deserialize; use serde_json::value::RawValue as JsonRawValue; diff --git a/blahd/src/event.rs b/blahd/src/event.rs index e1c638f..5366e92 100644 --- a/blahd/src/event.rs +++ b/blahd/src/event.rs @@ -1,5 +1,5 @@ -use std::collections::hash_map::Entry; use std::collections::HashMap; +use std::collections::hash_map::Entry; use std::convert::Infallible; use std::fmt; use std::pin::Pin; @@ -7,22 +7,22 @@ use std::sync::Arc; use std::task::{Context, Poll}; use std::time::Duration; -use anyhow::{bail, Context as _, Result}; -use axum::extract::ws::{close_code, CloseFrame, Message, WebSocket}; +use anyhow::{Context as _, Result, bail}; use axum::extract::WebSocketUpgrade; +use axum::extract::ws::{CloseFrame, Message, WebSocket, close_code}; use axum::response::Response; +use blah_types::Signed; use blah_types::msg::{AuthPayload, SignedChatMsgWithId}; use blah_types::server::{ClientEvent, ServerEvent}; -use blah_types::Signed; use futures_util::future::Either; use futures_util::stream::SplitSink; -use futures_util::{stream_select, SinkExt as _, Stream, StreamExt}; +use futures_util::{SinkExt as _, Stream, StreamExt, stream_select}; use parking_lot::Mutex; -use serde::{de, Deserialize}; +use serde::{Deserialize, de}; use serde_inline_default::serde_inline_default; use tokio::sync::broadcast; -use tokio_stream::wrappers::errors::BroadcastStreamRecvError; use tokio_stream::wrappers::BroadcastStream; +use tokio_stream::wrappers::errors::BroadcastStreamRecvError; use crate::database::TransactionOps; use crate::{AppState, ArcState}; diff --git a/blahd/src/feed.rs b/blahd/src/feed.rs index 35f8d9b..c6e811a 100644 --- a/blahd/src/feed.rs +++ b/blahd/src/feed.rs @@ -3,19 +3,19 @@ use std::fmt; use std::num::NonZero; use std::time::Duration; -use axum::extract::{OriginalUri, Path, Query}; -use axum::http::{header, StatusCode}; -use axum::response::{IntoResponse, Response}; use axum::Json; -use blah_types::msg::{RoomAttrs, SignedChatMsgWithId, WithMsgId}; +use axum::extract::{OriginalUri, Path, Query}; +use axum::http::{StatusCode, header}; +use axum::response::{IntoResponse, Response}; use blah_types::Id; +use blah_types::msg::{RoomAttrs, SignedChatMsgWithId, WithMsgId}; use serde::{Deserialize, Serialize}; use url::Url; use crate::database::TransactionOps; use crate::id::timestamp_of_id; use crate::middleware::ETag; -use crate::{query_room_msgs, ApiError, ArcState, Pagination, HEADER_PUBLIC_NO_CACHE}; +use crate::{ApiError, ArcState, HEADER_PUBLIC_NO_CACHE, Pagination, query_room_msgs}; const JSON_FEED_MIME: &str = "application/feed+json"; const ATOM_FEED_MIME: &str = "application/atom+xml"; diff --git a/blahd/src/id.rs b/blahd/src/id.rs index 9e618bf..3e7d57c 100644 --- a/blahd/src/id.rs +++ b/blahd/src/id.rs @@ -12,8 +12,8 @@ pub fn timestamp_of_id(id: Id) -> u64 { } pub trait IdExt { - fn gen() -> Self; - fn gen_peer_chat_rid() -> Self; + fn gen_new() -> Self; + fn gen_new_peer_chat_rid() -> Self; fn is_peer_chat(&self) -> bool; } @@ -23,7 +23,7 @@ thread_local! { } impl IdExt for Id { - fn gen() -> Self { + fn gen_new() -> Self { let timestamp = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .expect("after UNIX epoch"); @@ -46,8 +46,8 @@ impl IdExt for Id { }) } - fn gen_peer_chat_rid() -> Self { - Id(Self::gen().0 | i64::MIN) + fn gen_new_peer_chat_rid() -> Self { + Id(Self::gen_new().0 | i64::MIN) } fn is_peer_chat(&self) -> bool { diff --git a/blahd/src/lib.rs b/blahd/src/lib.rs index 81a53a1..0c4b4b5 100644 --- a/blahd/src/lib.rs +++ b/blahd/src/lib.rs @@ -6,7 +6,7 @@ use std::time::Duration; use anyhow::Result; use axum::body::Bytes; use axum::extract::{Path, Query, State}; -use axum::http::{header, HeaderName, HeaderValue, StatusCode}; +use axum::http::{HeaderName, HeaderValue, StatusCode, header}; use axum::response::{IntoResponse, NoContent, Response}; use axum::routing::MethodRouter; use axum::{Json, Router}; @@ -20,7 +20,7 @@ use blah_types::server::{ ErrorResponseWithChallenge, RoomList, RoomMember, RoomMemberList, RoomMetadata, RoomMsgs, ServerCapabilities, ServerMetadata, UserIdentityDescResponse, }; -use blah_types::{get_timestamp, Id, PubKey, Signed, UserKey}; +use blah_types::{Id, PubKey, Signed, UserKey, get_timestamp}; use data_encoding::BASE64_NOPAD; use database::{Transaction, TransactionOps}; use id::IdExt; @@ -326,7 +326,7 @@ async fn room_create_group( perm.contains(ServerPermission::CREATE_ROOM), ApiError::PermissionDenied("the user does not have permission to create room"), ); - let rid = Id::gen(); + let rid = Id::gen_new(); conn.create_group(rid, &op.title, op.attrs)?; conn.add_room_member(rid, uid, MemberPermission::ALL)?; Ok(rid) @@ -354,7 +354,7 @@ async fn room_create_peer_chat( .ok() .filter(|(_, perm)| perm.contains(ServerPermission::ACCEPT_PEER_CHAT)) .ok_or(ApiError::PeerUserNotFound)?; - let rid = Id::gen_peer_chat_rid(); + let rid = Id::gen_new_peer_chat_rid(); txn.create_peer_room_with_members(rid, RoomAttrs::PEER_CHAT, src_uid, tgt_uid)?; Ok(rid) })?; @@ -468,7 +468,7 @@ async fn post_room_msg( ApiError::PermissionDenied("the user does not have permission to post in the room"), ); - let cid = Id::gen(); + let cid = Id::gen_new(); txn.add_room_chat_msg(rid, uid, cid, &chat)?; let members = txn .list_room_members(rid, Id::MIN, None)? diff --git a/blahd/src/middleware.rs b/blahd/src/middleware.rs index 67cdc8a..a05849e 100644 --- a/blahd/src/middleware.rs +++ b/blahd/src/middleware.rs @@ -4,16 +4,16 @@ use std::fmt; use std::str::FromStr; use std::sync::Arc; +use axum::Json; use axum::extract::rejection::{JsonRejection, PathRejection, QueryRejection}; use axum::extract::{FromRef, FromRequest, FromRequestParts, Request}; -use axum::http::{header, request, HeaderValue, StatusCode}; +use axum::http::{HeaderValue, StatusCode, header, request}; use axum::response::{IntoResponse, IntoResponseParts, Response, ResponseParts}; -use axum::Json; use blah_types::msg::AuthPayload; use blah_types::server::ErrorObject; use blah_types::{Signed, UserKey}; -use serde::de::DeserializeOwned; use serde::Serialize; +use serde::de::DeserializeOwned; use crate::AppState; diff --git a/blahd/src/register.rs b/blahd/src/register.rs index 2561e4a..0b3f343 100644 --- a/blahd/src/register.rs +++ b/blahd/src/register.rs @@ -9,8 +9,8 @@ use blah_types::msg::{UserRegisterChallengeResponse, UserRegisterPayload}; use blah_types::server::UserRegisterChallenge; use http_body_util::BodyExt; use parking_lot::Mutex; -use rand::rngs::OsRng; use rand::RngCore; +use rand::rngs::OsRng; use serde::Deserialize; use sha2::{Digest, Sha256}; diff --git a/blahd/tests/socket_activate.rs b/blahd/tests/socket_activate.rs index 1a0620c..2ff665b 100644 --- a/blahd/tests/socket_activate.rs +++ b/blahd/tests/socket_activate.rs @@ -8,12 +8,12 @@ use std::process::abort; use std::ptr::null; use std::time::Duration; -use nix::fcntl::{fcntl, FcntlArg, FdFlag}; +use nix::fcntl::{FcntlArg, FdFlag, fcntl}; use nix::libc::execve; -use nix::sys::memfd::{memfd_create, MemFdCreateFlag}; -use nix::sys::signal::{kill, Signal}; -use nix::sys::wait::{waitpid, WaitStatus}; -use nix::unistd::{alarm, dup2, fork, getpid, ForkResult}; +use nix::sys::memfd::{MemFdCreateFlag, memfd_create}; +use nix::sys::signal::{Signal, kill}; +use nix::sys::wait::{WaitStatus, waitpid}; +use nix::unistd::{ForkResult, alarm, dup2, fork, getpid}; use rstest::rstest; use tokio::io::stderr; diff --git a/blahd/tests/webapi.rs b/blahd/tests/webapi.rs index a25247c..b7b2061 100644 --- a/blahd/tests/webapi.rs +++ b/blahd/tests/webapi.rs @@ -26,9 +26,9 @@ use expect_test::expect; use futures_util::future::BoxFuture; use futures_util::{SinkExt, Stream, StreamExt, TryFutureExt}; use parking_lot::Mutex; -use reqwest::{header, Method, StatusCode}; +use reqwest::{Method, StatusCode, header}; use rstest::{fixture, rstest}; -use rusqlite::{params, Connection}; +use rusqlite::{Connection, params}; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -164,7 +164,7 @@ impl Server { async fn connect_ws( &self, auth_user: Option<&User>, - ) -> Result> + Unpin> { + ) -> Result> + Unpin + use<>> { let url = format!("ws://{}/_blah/ws", self.domain()); let (mut ws, _) = tokio_tungstenite::connect_async(url).await.unwrap(); if let Some(user) = auth_user {