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 {
|
||||
address: PeerAddress,
|
||||
context: Arc<RwLock<Context>>,
|
||||
listen_port: u32,
|
||||
listen_port: u16,
|
||||
enable_listen: bool,
|
||||
stream: Option<TcpStream>,
|
||||
connection_state: ConnectionState,
|
||||
@@ -146,7 +146,7 @@ impl ServerActor {
|
||||
pub fn new(
|
||||
address: PeerAddress,
|
||||
client_channel: Sender<ClientOperation>,
|
||||
listen_port: u32,
|
||||
listen_port: u16,
|
||||
enable_listen: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
||||
@@ -27,7 +27,7 @@ use std::{
|
||||
};
|
||||
|
||||
use crate::{debug, error, info, trace, warn};
|
||||
const DEFALT_LISTEN_PORT: u32 = 2234;
|
||||
const DEFAULT_LISTEN_PORT: u16 = 2234;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ClientSettings {
|
||||
@@ -35,7 +35,7 @@ pub struct ClientSettings {
|
||||
pub password: String,
|
||||
pub server_address: PeerAddress,
|
||||
pub enable_listen: bool,
|
||||
pub listen_port: u32,
|
||||
pub listen_port: u16,
|
||||
}
|
||||
|
||||
impl ClientSettings {
|
||||
@@ -61,7 +61,7 @@ impl Default for ClientSettings {
|
||||
2416,
|
||||
),
|
||||
enable_listen: true,
|
||||
listen_port: DEFALT_LISTEN_PORT,
|
||||
listen_port: DEFAULT_LISTEN_PORT,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -308,7 +308,7 @@ impl ClientContext {
|
||||
}
|
||||
pub struct Client {
|
||||
enable_listen: bool,
|
||||
listen_port: u32,
|
||||
listen_port: u16,
|
||||
address: PeerAddress,
|
||||
username: String,
|
||||
password: String,
|
||||
|
||||
@@ -68,12 +68,10 @@ impl MessageFactory {
|
||||
pub fn build_no_parent_message() -> Message {
|
||||
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()
|
||||
.write_int32(2)
|
||||
.write_int32(port)
|
||||
// .write_int32(0)
|
||||
// .write_int32(port) // should be different port
|
||||
.write_int32(port.into())
|
||||
.clone()
|
||||
}
|
||||
pub fn build_watch_user(token: u32) -> Message {
|
||||
|
||||
@@ -269,7 +269,7 @@ pub struct Listen {}
|
||||
|
||||
impl Listen {
|
||||
pub fn start(
|
||||
port: u32,
|
||||
port: u16,
|
||||
client_sender: Sender<ClientOperation>,
|
||||
client_context: Arc<RwLock<ClientContext>>,
|
||||
own_username: String,
|
||||
|
||||
Reference in New Issue
Block a user