🔧 config: add tcp_listen_port to config file
							parent
							
								
									96af820ffb
								
							
						
					
					
						commit
						ce7a539413
					
				|  | @ -40,12 +40,15 @@ pub (crate) struct Metrics { | |||
| 
 | ||||
| impl App { | ||||
| 	pub async fn new (opt: Opt) -> anyhow::Result <Self> { | ||||
| 		let config = load_config ().await.ok (); | ||||
| 		
 | ||||
| 		let listen_addr = opt.listen_addr.unwrap_or_else (|| String::from ("0.0.0.0:30380")).parse ()?; | ||||
| 		let (endpoint, server_cert) = make_server_endpoint (listen_addr)?; | ||||
| 		
 | ||||
| 		let listen_addr = endpoint.local_addr ()?; | ||||
| 		let tcp_port = opt.tcp_listen_port.or (config.map (|cfg| cfg.tcp_listen_port).flatten ()); | ||||
| 		
 | ||||
| 		let tcp_listener = if let Some (tcp_port) = opt.tcp_listen_port { | ||||
| 		let tcp_listener = if let Some (tcp_port) = tcp_port { | ||||
| 			let cfg = udp_over_tcp::server::Config { | ||||
| 				tcp_port, | ||||
| 				udp_port: listen_addr.port (), | ||||
|  | @ -262,6 +265,7 @@ struct RelayState { | |||
| #[derive (Default)] | ||||
| struct Config { | ||||
| 	ip_nicknames: BTreeMap <[u8; 4], String>, | ||||
| 	tcp_listen_port: Option <u16>, | ||||
| 	webhook_url: Option <String>, | ||||
| } | ||||
| 
 | ||||
|  | @ -269,6 +273,7 @@ impl From <ConfigFile> for Config { | |||
| 	fn from (x: ConfigFile) -> Self { | ||||
| 		Self { | ||||
| 			ip_nicknames: x.ip_nicknames.into_iter ().collect (), | ||||
| 			tcp_listen_port: x.tcp_listen_port, | ||||
| 			webhook_url: x.webhook_url, | ||||
| 		} | ||||
| 	} | ||||
|  | @ -277,6 +282,7 @@ impl From <ConfigFile> for Config { | |||
| #[derive (Deserialize)] | ||||
| struct ConfigFile { | ||||
| 	ip_nicknames: Vec <([u8; 4], String)>, | ||||
| 	tcp_listen_port: Option <u16>, | ||||
| 	webhook_url: Option <String>, | ||||
| } | ||||
| 
 | ||||
|  | @ -319,13 +325,18 @@ impl ConnectEvents { | |||
| 
 | ||||
| struct P4State { | ||||
| 	req_channel: mpsc::Sender <RequestP2ToP4>, | ||||
| } | ||||
| 
 | ||||
| async fn load_config () -> anyhow::Result <ConfigFile> | ||||
| { | ||||
| 	let s = tokio::fs::read_to_string ("config/ptth_quic_relay_server.json").await?; | ||||
| 	let cfg: ConfigFile = serde_json::from_str (&s)?; | ||||
| 	Ok (cfg) | ||||
| } | ||||
| 
 | ||||
| impl RelayState { | ||||
| 	async fn reload_config (&self) -> anyhow::Result <()> { | ||||
| 		let s = tokio::fs::read_to_string ("config/ptth_quic_relay_server.json").await?; | ||||
| 		let config: ConfigFile = serde_json::from_str (&s)?; | ||||
| 		let config = load_config ().await?; | ||||
| 		let config = Arc::new (Config::from (config)); | ||||
| 		
 | ||||
| 		self.config.store (config); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 (on company time)
						(on company time)