fix: use u16 for listen port end-to-end
Port numbers are 16-bit; the codebase had listen_port/listener_port typed as u32, inconsistent with PeerAddress.port (already u16). Migrate the type all the way through the CLI, config, ClientSettings, Client, ServerActor, and the listener entry point. The wire format is preserved: build_set_wait_port_message now takes u16 and widens to u32 via .into() before write_int32. Also rename DEFALT_LISTEN_PORT to DEFAULT_LISTEN_PORT.
This commit is contained in:
@@ -129,7 +129,7 @@ pub enum ServerMessage {
|
|||||||
pub struct ServerActor {
|
pub struct ServerActor {
|
||||||
address: PeerAddress,
|
address: PeerAddress,
|
||||||
context: Arc<RwLock<Context>>,
|
context: Arc<RwLock<Context>>,
|
||||||
listen_port: u32,
|
listen_port: u16,
|
||||||
enable_listen: bool,
|
enable_listen: bool,
|
||||||
stream: Option<TcpStream>,
|
stream: Option<TcpStream>,
|
||||||
connection_state: ConnectionState,
|
connection_state: ConnectionState,
|
||||||
@@ -146,7 +146,7 @@ impl ServerActor {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
address: PeerAddress,
|
address: PeerAddress,
|
||||||
client_channel: Sender<ClientOperation>,
|
client_channel: Sender<ClientOperation>,
|
||||||
listen_port: u32,
|
listen_port: u16,
|
||||||
enable_listen: bool,
|
enable_listen: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{debug, error, info, trace, warn};
|
use crate::{debug, error, info, trace, warn};
|
||||||
const DEFALT_LISTEN_PORT: u32 = 2234;
|
const DEFAULT_LISTEN_PORT: u16 = 2234;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ClientSettings {
|
pub struct ClientSettings {
|
||||||
@@ -35,7 +35,7 @@ pub struct ClientSettings {
|
|||||||
pub password: String,
|
pub password: String,
|
||||||
pub server_address: PeerAddress,
|
pub server_address: PeerAddress,
|
||||||
pub enable_listen: bool,
|
pub enable_listen: bool,
|
||||||
pub listen_port: u32,
|
pub listen_port: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClientSettings {
|
impl ClientSettings {
|
||||||
@@ -61,7 +61,7 @@ impl Default for ClientSettings {
|
|||||||
2416,
|
2416,
|
||||||
),
|
),
|
||||||
enable_listen: true,
|
enable_listen: true,
|
||||||
listen_port: DEFALT_LISTEN_PORT,
|
listen_port: DEFAULT_LISTEN_PORT,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -308,7 +308,7 @@ impl ClientContext {
|
|||||||
}
|
}
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
enable_listen: bool,
|
enable_listen: bool,
|
||||||
listen_port: u32,
|
listen_port: u16,
|
||||||
address: PeerAddress,
|
address: PeerAddress,
|
||||||
username: String,
|
username: String,
|
||||||
password: String,
|
password: String,
|
||||||
|
|||||||
@@ -68,12 +68,10 @@ impl MessageFactory {
|
|||||||
pub fn build_no_parent_message() -> Message {
|
pub fn build_no_parent_message() -> Message {
|
||||||
Message::new().write_int32(71).write_bool(true).clone()
|
Message::new().write_int32(71).write_bool(true).clone()
|
||||||
}
|
}
|
||||||
pub fn build_set_wait_port_message(port: u32) -> Message {
|
pub fn build_set_wait_port_message(port: u16) -> Message {
|
||||||
Message::new()
|
Message::new()
|
||||||
.write_int32(2)
|
.write_int32(2)
|
||||||
.write_int32(port)
|
.write_int32(port.into())
|
||||||
// .write_int32(0)
|
|
||||||
// .write_int32(port) // should be different port
|
|
||||||
.clone()
|
.clone()
|
||||||
}
|
}
|
||||||
pub fn build_watch_user(token: u32) -> Message {
|
pub fn build_watch_user(token: u32) -> Message {
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ pub struct Listen {}
|
|||||||
|
|
||||||
impl Listen {
|
impl Listen {
|
||||||
pub fn start(
|
pub fn start(
|
||||||
port: u32,
|
port: u16,
|
||||||
client_sender: Sender<ClientOperation>,
|
client_sender: Sender<ClientOperation>,
|
||||||
client_context: Arc<RwLock<ClientContext>>,
|
client_context: Arc<RwLock<ClientContext>>,
|
||||||
own_username: String,
|
own_username: String,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ pub struct Cli {
|
|||||||
pub disable_listener: bool,
|
pub disable_listener: bool,
|
||||||
|
|
||||||
#[arg(short, long, env = "LISTENER_PORT", default_value = "2234")]
|
#[arg(short, long, env = "LISTENER_PORT", default_value = "2234")]
|
||||||
pub listener_port: u32,
|
pub listener_port: u16,
|
||||||
|
|
||||||
#[arg(short, long, global = true, action = clap::ArgAction::Count)]
|
#[arg(short, long, global = true, action = clap::ArgAction::Count)]
|
||||||
pub verbose: u8,
|
pub verbose: u8,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ pub struct SearchConfig {
|
|||||||
pub server_host: String,
|
pub server_host: String,
|
||||||
pub server_port: u16,
|
pub server_port: u16,
|
||||||
pub enable_listener: bool,
|
pub enable_listener: bool,
|
||||||
pub listener_port: u32,
|
pub listener_port: u16,
|
||||||
pub query: String,
|
pub query: String,
|
||||||
pub timeout: u64,
|
pub timeout: u64,
|
||||||
pub download_dir: String,
|
pub download_dir: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user