feat(auth): add authentication protocol definitions and build configuration

- Add TokenClaims message for JWT payload structure with user id, issuer, timestamps, and scopes
- Implement IssueTokenRequest/Response for creating access and refresh tokens with TTL support
- Create RefreshTokenRequest/Response for token rotation functionality
- Define RevokeTokenRequest/Response with support for single token or user-wide revocation
- Add VerifyTokenRequest/Response for validating JWT tokens with detailed claims information
- Implement signing key distribution system with GetSigningKeysRequest/Response
- Create TokenService gRPC service with IssueToken, RefreshToken, RevokeToken, VerifyToken, and GetSigningKeys methods
- Add build.rs configuration to compile proto files using tonic_prost_build
- Include channel, channel_settings, member, and permission protocol definitions for IM services
- Generate Rust code bindings through pb/core.rs and pb/im.rs modules
This commit is contained in:
zhenyi
2026-06-10 23:45:40 +08:00
commit 06e8ee96a5
43 changed files with 9671 additions and 0 deletions
+115
View File
@@ -0,0 +1,115 @@
use std::sync::Arc;
use actix_web::{web, App, HttpServer};
use crate::engine::heartbeat::HeartbeatManager;
use crate::engine::packet::Packet;
use crate::engine::session::SessionStore;
#[derive(Debug, Clone)]
pub struct EngineConfig {
pub ping_interval: u64,
pub ping_timeout: u64,
pub max_payload: usize,
pub path: String,
}
impl Default for EngineConfig {
fn default() -> Self {
Self {
ping_interval: 25000,
ping_timeout: 20000,
max_payload: 1_000_000,
path: "/engine.io/".to_string(),
}
}
}
pub struct EngineServer {
pub config: EngineConfig,
pub store: SessionStore,
on_message: Arc<dyn Fn(String, Packet) + Send + Sync>,
}
impl EngineServer {
pub fn new(
config: EngineConfig,
on_message: impl Fn(String, Packet) + Send + Sync + 'static,
) -> Self {
Self {
config,
store: SessionStore::new(),
on_message: Arc::new(on_message),
}
}
pub fn with_store(
config: EngineConfig,
store: SessionStore,
on_message: impl Fn(String, Packet) + Send + Sync + 'static,
) -> Self {
Self {
config,
store,
on_message: Arc::new(on_message),
}
}
pub async fn run_http(self: Arc<Self>, addr: &str) -> std::io::Result<()> {
let store = self.store.clone();
let config = self.config.clone();
let on_message = self.on_message.clone();
// Start heartbeat manager to clean up stale sessions
let heartbeat = Arc::new(HeartbeatManager::new(
store.clone(),
config.ping_interval,
config.ping_timeout,
));
let heartbeat_handle = heartbeat.start();
tracing::info!("Engine.IO HTTP server listening on {}", addr);
let result = HttpServer::new(move || {
App::new()
.app_data(web::Data::new(store.clone()))
.app_data(web::Data::new(config.clone()))
.app_data(web::Data::new(on_message.clone()))
.route(
"/engine.io/",
web::get().to(crate::engine::polling::polling_get),
)
.route(
"/engine.io/",
web::post().to(crate::engine::polling::polling_post),
)
.route(
"/engine.io/",
web::get().to(crate::engine::websocket::websocket_handler),
)
})
.bind(addr)?
.run()
.await;
heartbeat_handle.abort();
result
}
pub async fn run_webtransport(
&self,
port: u16,
cert_path: &str,
key_path: &str,
) -> Result<(), Box<dyn std::error::Error>> {
crate::engine::webtransport::run_webtransport_server(
port,
cert_path,
key_path,
self.store.clone(),
self.config.clone(),
self.on_message.clone(),
)
.await
}
}