1
This commit is contained in:
@@ -6,10 +6,8 @@ use std::sync::atomic::{AtomicU64, Ordering};
|
|||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use quinn::{Endpoint, ServerConfig, TransportConfig};
|
use quinn::{Endpoint, ServerConfig, TransportConfig};
|
||||||
use quinn::crypto::rustls::QuicServerConfig;
|
|
||||||
use rcgen::{CertifiedKey, generate_simple_self_signed};
|
use rcgen::{CertifiedKey, generate_simple_self_signed};
|
||||||
use rustls::pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer};
|
use rustls::pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer};
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
|
||||||
use tokio::net::UdpSocket;
|
use tokio::net::UdpSocket;
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||||
@@ -90,10 +88,8 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn run_ping_responder(addr: SocketAddr) -> Result<()> {
|
async fn run_ping_responder(addr: SocketAddr) -> Result<()> {
|
||||||
let socket = match UdpSocket::bind(format!("0.0.0.0:{}", addr.port() + 10000)).await {
|
let socket = UdpSocket::bind(format!("0.0.0.0:{}", addr.port() + 10000)).await
|
||||||
Ok(s) => s,
|
.or_else(|_| async { UdpSocket::bind("0.0.0.0:0").await })?;
|
||||||
Err(_) => UdpSocket::bind("0.0.0.0:0").await?,
|
|
||||||
};
|
|
||||||
|
|
||||||
info!("Ping responder listening on {}", socket.local_addr()?);
|
info!("Ping responder listening on {}", socket.local_addr()?);
|
||||||
|
|
||||||
@@ -133,9 +129,7 @@ fn build_server_config() -> Result<ServerConfig> {
|
|||||||
transport.max_idle_timeout(Some(Duration::from_secs(60).try_into()?));
|
transport.max_idle_timeout(Some(Duration::from_secs(60).try_into()?));
|
||||||
transport.keep_alive_interval(Some(Duration::from_secs(10)));
|
transport.keep_alive_interval(Some(Duration::from_secs(10)));
|
||||||
|
|
||||||
let quic_crypto = QuicServerConfig::try_from(Arc::new(server_crypto))
|
let mut server_config = ServerConfig::with_crypto(Arc::new(server_crypto));
|
||||||
.context("rustls 配置转为 QUIC 失败")?;
|
|
||||||
let mut server_config = ServerConfig::with_crypto(Arc::new(quic_crypto));
|
|
||||||
server_config.transport_config(Arc::new(transport));
|
server_config.transport_config(Arc::new(transport));
|
||||||
|
|
||||||
Ok(server_config)
|
Ok(server_config)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use axum::{
|
|||||||
body::Body,
|
body::Body,
|
||||||
extract::{Path, State},
|
extract::{Path, State},
|
||||||
http::{header, StatusCode},
|
http::{header, StatusCode},
|
||||||
response::{Html, IntoResponse, Response},
|
response::{Html, Response},
|
||||||
Json,
|
Json,
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
@@ -70,7 +70,7 @@ pub async fn download_page(State(state): State<Arc<AppState>>) -> Html<String> {
|
|||||||
"http://localhost:3000".to_string()
|
"http://localhost:3000".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
let html = format!(r#"<!DOCTYPE html>
|
let html = format!(r##"<!DOCTYPE html>
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
@@ -187,7 +187,7 @@ pub async fn download_page(State(state): State<Arc<AppState>>) -> Html<String> {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>"#,
|
</html>"##,
|
||||||
server_name = config.server_name,
|
server_name = config.server_name,
|
||||||
server_url = server_url,
|
server_url = server_url,
|
||||||
version = config.client_version,
|
version = config.client_version,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ pub async fn list_friends(
|
|||||||
match rows {
|
match rows {
|
||||||
Ok(friends) => {
|
Ok(friends) => {
|
||||||
let dtos: Vec<_> = friends.into_iter().map(|(id, username, avatar_seed, status)| {
|
let dtos: Vec<_> = friends.into_iter().map(|(id, username, avatar_seed, status)| {
|
||||||
let is_online = state.presence.is_online(id);
|
let is_online = state.presence.is_online(&id);
|
||||||
FriendDto { id, username, avatar_seed, is_online, status }
|
FriendDto { id, username, avatar_seed, is_online, status }
|
||||||
}).collect();
|
}).collect();
|
||||||
(StatusCode::OK, Json(serde_json::json!(dtos))).into_response()
|
(StatusCode::OK, Json(serde_json::json!(dtos))).into_response()
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ pub async fn search_users(
|
|||||||
"id": id,
|
"id": id,
|
||||||
"username": username,
|
"username": username,
|
||||||
"avatar_seed": avatar_seed,
|
"avatar_seed": avatar_seed,
|
||||||
"is_online": state.presence.is_online(id),
|
"is_online": state.presence.is_online(&id),
|
||||||
})).collect();
|
})).collect();
|
||||||
(StatusCode::OK, Json(serde_json::json!(dtos))).into_response()
|
(StatusCode::OK, Json(serde_json::json!(dtos))).into_response()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user