summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-10-29 15:23:00 +0800
committer魏曹先生 <1992414357@qq.com>2025-10-29 15:23:00 +0800
commitb48073e4c9a2ca80dd0503efc5b6ab121d504028 (patch)
tree366a85665784b637c705ee6ba32f900789c392bc /crates
parent20af0f0daaa67dbb34184b5f855a75c2eb1864d3 (diff)
feat: Add port override capability to server entry
The server_entry function now accepts an optional port_override parameter that allows specifying a custom port instead of using the configured port from vault configuration. When port_override is greater than 0, it takes precedence over the configured port.
Diffstat (limited to 'crates')
-rw-r--r--crates/vcs_actions/src/connection/action_service.rs26
1 files changed, 18 insertions, 8 deletions
diff --git a/crates/vcs_actions/src/connection/action_service.rs b/crates/vcs_actions/src/connection/action_service.rs
index 3786fc5..d9ddaab 100644
--- a/crates/vcs_actions/src/connection/action_service.rs
+++ b/crates/vcs_actions/src/connection/action_service.rs
@@ -21,21 +21,23 @@ use crate::{
};
// Start the server with a Vault using the specified directory
-pub async fn server_entry(vault_path: impl Into<PathBuf>) -> Result<(), TcpTargetError> {
+pub async fn server_entry(
+ vault_path: impl Into<PathBuf>,
+ port_override: u16,
+) -> Result<(), TcpTargetError> {
// Read the vault cfg
let vault_cfg = VaultConfig::read().await?;
// Create TCPListener
- let listener = create_tcp_listener(&vault_cfg).await?;
+ let listener = create_tcp_listener(&vault_cfg, port_override).await?;
// Initialize the vault
let vault: Arc<Vault> = init_vault(vault_cfg, vault_path.into()).await?;
// Lock the vault
- vault.lock().map_err(|e| {
- error!("{}", e);
- TcpTargetError::Locked(e.to_string())
- })?;
+ vault
+ .lock()
+ .map_err(|e| TcpTargetError::Locked(e.to_string()))?;
// Create ActionPool
let action_pool: Arc<ActionPool> = Arc::new(server_action_pool());
@@ -50,9 +52,17 @@ pub async fn server_entry(vault_path: impl Into<PathBuf>) -> Result<(), TcpTarge
Ok(())
}
-async fn create_tcp_listener(cfg: &VaultConfig) -> Result<TcpListener, TcpTargetError> {
+async fn create_tcp_listener(
+ cfg: &VaultConfig,
+ port_override: u16,
+) -> Result<TcpListener, TcpTargetError> {
let local_bind_addr = cfg.server_config().local_bind();
- let bind_port = cfg.server_config().port();
+ let port = if port_override > 0 {
+ port_override // Override -> PORT > 0
+ } else {
+ cfg.server_config().port() // Default -> Port = 0
+ };
+ let bind_port = port;
let sock_addr = SocketAddr::new(*local_bind_addr, bind_port);
let listener = TcpListener::bind(sock_addr).await?;