@@ -12,7 +12,7 @@ use tracing::{info, info_span, warn, Instrument};
1212use uuid:: Uuid ;
1313
1414use crate :: auth:: Authenticator ;
15- use crate :: shared:: { ClientMessage , Delimited , ServerMessage , CONTROL_PORT } ;
15+ use crate :: shared:: { ClientMessage , Delimited , ServerMessage , DEFAULT_CONTROL_PORT } ;
1616
1717/// State structure for the server.
1818pub struct Server {
@@ -30,6 +30,9 @@ pub struct Server {
3030
3131 /// IP address where tunnels will listen on.
3232 bind_tunnels : IpAddr ,
33+
34+ /// TCP port used for control connections with clients.
35+ control_port : u16 ,
3336}
3437
3538impl Server {
@@ -42,6 +45,7 @@ impl Server {
4245 auth : secret. map ( Authenticator :: new) ,
4346 bind_addr : IpAddr :: V4 ( Ipv4Addr :: UNSPECIFIED ) ,
4447 bind_tunnels : IpAddr :: V4 ( Ipv4Addr :: UNSPECIFIED ) ,
48+ control_port : DEFAULT_CONTROL_PORT ,
4549 }
4650 }
4751
@@ -55,11 +59,16 @@ impl Server {
5559 self . bind_tunnels = bind_tunnels;
5660 }
5761
62+ /// Set the TCP port used for control connections with clients.
63+ pub fn set_control_port ( & mut self , control_port : u16 ) {
64+ self . control_port = control_port;
65+ }
66+
5867 /// Start the server, listening for new connections.
5968 pub async fn listen ( self ) -> Result < ( ) > {
6069 let this = Arc :: new ( self ) ;
61- let listener = TcpListener :: bind ( ( this. bind_addr , CONTROL_PORT ) ) . await ?;
62- info ! ( addr = ?this. bind_addr, "server listening" ) ;
70+ let listener = TcpListener :: bind ( ( this. bind_addr , this . control_port ) ) . await ?;
71+ info ! ( addr = ?this. bind_addr, port = this . control_port , "server listening" ) ;
6372
6473 loop {
6574 let ( stream, addr) = listener. accept ( ) . await ?;
0 commit comments