mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-07-01 03:55:33 +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,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
Add a link
Reference in a new issue