Rename Upstream::Custom to Upstream::Proxy
And CustomUpstream to ProxyToUpstream. Signed-off-by: Jacob Kiers <code@kiers.eu>
This commit is contained in:
parent
2651ec1f4a
commit
a574163aef
@ -42,7 +42,7 @@ pub struct ServerConfig {
|
|||||||
pub enum Upstream {
|
pub enum Upstream {
|
||||||
Ban,
|
Ban,
|
||||||
Echo,
|
Echo,
|
||||||
Custom(CustomUpstream),
|
Proxy(ProxyToUpstream),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -61,7 +61,7 @@ impl Clone for Addr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct CustomUpstream {
|
pub struct ProxyToUpstream {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub addr: String,
|
pub addr: String,
|
||||||
pub protocol: String,
|
pub protocol: String,
|
||||||
@ -69,14 +69,14 @@ pub struct CustomUpstream {
|
|||||||
addresses: Addr,
|
addresses: Addr,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CustomUpstream {
|
impl ProxyToUpstream {
|
||||||
pub async fn resolve_addresses(&self) -> std::io::Result<Vec<SocketAddr>> {
|
pub async fn resolve_addresses(&self) -> std::io::Result<Vec<SocketAddr>> {
|
||||||
let mut addr = self.addresses.0.lock().await;
|
let mut addr = self.addresses.0.lock().await;
|
||||||
addr.resolve((*self.protocol).into()).await
|
addr.resolve((*self.protocol).into()).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CustomUpstream {
|
impl Default for ProxyToUpstream {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: Default::default(),
|
name: Default::default(),
|
||||||
@ -169,7 +169,7 @@ fn load_config(path: &str) -> Result<ParsedConfig, ConfigError> {
|
|||||||
|
|
||||||
parsed_upstream.insert(
|
parsed_upstream.insert(
|
||||||
name.to_string(),
|
name.to_string(),
|
||||||
Upstream::Custom(CustomUpstream {
|
Upstream::Proxy(ProxyToUpstream {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
addr: format!("{}:{}", upstream_host, upstream_port),
|
addr: format!("{}:{}", upstream_host, upstream_port),
|
||||||
protocol: upstream_url.scheme().to_string(),
|
protocol: upstream_url.scheme().to_string(),
|
||||||
|
@ -94,13 +94,13 @@ async fn process(
|
|||||||
let bytes_tx = inbound_to_inbound.await;
|
let bytes_tx = inbound_to_inbound.await;
|
||||||
debug!("Bytes read: {:?}", bytes_tx);
|
debug!("Bytes read: {:?}", bytes_tx);
|
||||||
}
|
}
|
||||||
Upstream::Custom(custom) => {
|
Upstream::Proxy(config) => {
|
||||||
let outbound = match custom.protocol.as_ref() {
|
let outbound = match config.protocol.as_ref() {
|
||||||
"tcp4" | "tcp6" | "tcp" => {
|
"tcp4" | "tcp6" | "tcp" => {
|
||||||
TcpStream::connect(custom.resolve_addresses().await?.as_slice()).await?
|
TcpStream::connect(config.resolve_addresses().await?.as_slice()).await?
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("Reached unknown protocol: {:?}", custom.protocol);
|
error!("Reached unknown protocol: {:?}", config.protocol);
|
||||||
return Err("Reached unknown protocol".into());
|
return Err("Reached unknown protocol".into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user