mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-04-30 16:21:10 +00:00
build: migrate to Rust edition 2024
This commit is contained in:
parent
37fbf5149e
commit
2e0a878d56
22 changed files with 64 additions and 64 deletions
|
@ -1,5 +1,5 @@
|
|||
[workspace]
|
||||
resolver = "2"
|
||||
resolver = "3"
|
||||
members = [
|
||||
"blah-types",
|
||||
"blahctl",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "blah-types"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[features]
|
||||
default = ["ed25519-dalek/default"]
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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>()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "blahctl"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
|
|
|
@ -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") {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "blahd"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
|
|
@ -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)")?
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)?
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<impl Stream<Item = Result<ServerEvent>> + Unpin> {
|
||||
) -> Result<impl Stream<Item = Result<ServerEvent>> + 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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue