Skip to content

Commit

Permalink
g3proxy: make source config in proxy_float escaper optional
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq committed Aug 19, 2023
1 parent 43f79d1 commit bbf8459
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
4 changes: 3 additions & 1 deletion g3proxy/doc/configuration/escapers/proxy_float.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ The following common keys are supported:
source
------

**required**, **type**: :ref:`url str <conf_value_url_str>` | map | null
**optional**, **type**: :ref:`url str <conf_value_url_str>` | map | null

Set the fetch source for peers.

We support many type of sources. The type is detected by reading the *scheme* field of url,
or the *type* key of the map. See :ref:`sources <config_escaper_dynamic_source>` for all supported type of sources.

**default**: passive

cache
-----

Expand Down
20 changes: 8 additions & 12 deletions g3proxy/src/config/escaper/proxy_float/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) struct ProxyFloatEscaperConfig {
pub(crate) bind_v4: Option<IpAddr>,
pub(crate) bind_v6: Option<IpAddr>,
pub(crate) tls_config: Option<OpensslTlsClientConfigBuilder>,
pub(crate) source: Option<ProxyFloatSource>,
pub(crate) source: ProxyFloatSource,
pub(crate) cache_file: Option<PathBuf>,
pub(crate) refresh_interval: Duration,
pub(crate) tcp_connect_timeout: Duration,
Expand All @@ -67,7 +67,7 @@ impl ProxyFloatEscaperConfig {
bind_v4: None,
bind_v6: None,
tls_config: None,
source: None,
source: ProxyFloatSource::Passive,
cache_file: None,
refresh_interval: Duration::from_secs(1),
tcp_connect_timeout: Duration::from_secs(30),
Expand Down Expand Up @@ -141,7 +141,7 @@ impl ProxyFloatEscaperConfig {
}
"source" => {
self.source =
Some(ProxyFloatSource::parse(v).context(format!("invalid value for key {k}"))?);
ProxyFloatSource::parse(v).context(format!("invalid value for key {k}"))?;
Ok(())
}
"cache" => {
Expand Down Expand Up @@ -197,15 +197,11 @@ impl ProxyFloatEscaperConfig {
if self.name.is_empty() {
return Err(anyhow!("name is not set"));
}
if let Some(source) = &self.source {
if source.need_local_cache() && self.cache_file.is_none() {
warn!(
"It is very recommended to set local cache for escaper {}",
self.name
);
}
} else {
return Err(anyhow!("no source url set"));
if self.source.need_local_cache() && self.cache_file.is_none() {
warn!(
"It is very recommended to set local cache for escaper {}",
self.name
);
}

Ok(())
Expand Down
10 changes: 1 addition & 9 deletions g3proxy/src/escape/proxy_float/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,11 @@ pub(super) fn new_job(
peers_container: Arc<ArcSwap<Box<[ArcNextProxyPeer]>>>,
tls_config: Option<Arc<OpensslTlsClientConfig>>,
) -> anyhow::Result<AbortHandle> {
if config.source.is_none() {
return Err(anyhow!("no source set"));
}

let f = async move {
let source = match &config.source {
Some(source) => source,
None => unreachable!(),
};
let mut interval = tokio::time::interval(config.refresh_interval);
interval.tick().await; // will tick immediately
loop {
let result = match source {
let result = match &config.source {
ProxyFloatSource::Passive => {
// do nothing
interval.tick().await;
Expand Down

0 comments on commit bbf8459

Please sign in to comment.