Skip to content

Commit

Permalink
g3proxy: always log for interception supported protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq-b committed Aug 28, 2024
1 parent 2972151 commit 68dc246
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 55 deletions.
26 changes: 15 additions & 11 deletions g3proxy/src/inspect/http/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,28 @@ where
SC: ServerConfig + Send + Sync + 'static,
{
pub(crate) async fn intercept(mut self) -> ServerTaskResult<()> {
match self.ctx.h2_inspect_policy() {
ProtocolInspectPolicy::Intercept => match self.do_intercept().await {
Ok(_) => {
intercept_log!(self, "finished");
Ok(())
}
Err(e) => {
intercept_log!(self, "{e}");
Err(InterceptionError::H2(e).into_server_task_error(Protocol::Http2))
}
},
let r = match self.ctx.h2_inspect_policy() {
ProtocolInspectPolicy::Intercept => self
.do_intercept()
.await
.map_err(|e| InterceptionError::H2(e).into_server_task_error(Protocol::Http2)),
#[cfg(feature = "quic")]
ProtocolInspectPolicy::Detour => self.do_detour().await,
ProtocolInspectPolicy::Bypass => self.do_bypass().await,
ProtocolInspectPolicy::Block => self
.do_block()
.await
.map_err(|e| InterceptionError::H2(e).into_server_task_error(Protocol::Http2)),
};
match r {
Ok(_) => {
intercept_log!(self, "finished");
Ok(())
}
Err(e) => {
intercept_log!(self, "{e}");
Err(e)
}
}
}

Expand Down
36 changes: 14 additions & 22 deletions g3proxy/src/inspect/imap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,29 +130,21 @@ where
}

pub(crate) async fn intercept(mut self) -> ServerTaskResult<Option<StreamInspection<SC>>> {
match self.ctx.imap_inspect_policy() {
ProtocolInspectPolicy::Intercept => match self.do_intercept().await {
Ok(obj) => {
intercept_log!(self, "finished");
Ok(obj)
}
Err(e) => {
intercept_log!(self, "{e}");
Err(e)
}
},
let r = match self.ctx.imap_inspect_policy() {
ProtocolInspectPolicy::Intercept => self.do_intercept().await,
#[cfg(feature = "quic")]
ProtocolInspectPolicy::Detour => {
self.do_detour().await?;
Ok(None)
}
ProtocolInspectPolicy::Bypass => {
self.do_bypass().await?;
Ok(None)
ProtocolInspectPolicy::Detour => self.do_detour().await.map(|_| None),
ProtocolInspectPolicy::Bypass => self.do_bypass().await.map(|_| None),
ProtocolInspectPolicy::Block => self.do_block().await.map(|_| None),
};
match r {
Ok(obj) => {
intercept_log!(self, "finished");
Ok(obj)
}
ProtocolInspectPolicy::Block => {
self.do_block().await?;
Ok(None)
Err(e) => {
intercept_log!(self, "{e}");
Err(e)
}
}
}
Expand Down Expand Up @@ -217,7 +209,7 @@ where
.await
.map_err(ServerTaskError::ClientTcpWriteFailed)?;
Err(ServerTaskError::InternalAdapterError(anyhow!(
"blocked by inspection policy"
"imap blocked by inspection policy"
)))
}

Expand Down
36 changes: 14 additions & 22 deletions g3proxy/src/inspect/smtp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,29 +121,21 @@ where
}

pub(crate) async fn intercept(mut self) -> ServerTaskResult<Option<StreamInspection<SC>>> {
match self.ctx.smtp_inspect_policy() {
ProtocolInspectPolicy::Intercept => match self.do_intercept().await {
Ok(obj) => {
intercept_log!(self, "finished");
Ok(obj)
}
Err(e) => {
intercept_log!(self, "{e}");
Err(e)
}
},
let r = match self.ctx.smtp_inspect_policy() {
ProtocolInspectPolicy::Intercept => self.do_intercept().await,
#[cfg(feature = "quic")]
ProtocolInspectPolicy::Detour => {
self.do_detour().await?;
Ok(None)
}
ProtocolInspectPolicy::Bypass => {
self.do_bypass().await?;
Ok(None)
ProtocolInspectPolicy::Detour => self.do_detour().await.map(|_| None),
ProtocolInspectPolicy::Bypass => self.do_bypass().await.map(|_| None),
ProtocolInspectPolicy::Block => self.do_block().await.map(|_| None),
};
match r {
Ok(obj) => {
intercept_log!(self, "finished");
Ok(obj)
}
ProtocolInspectPolicy::Block => {
self.do_block().await?;
Ok(None)
Err(e) => {
intercept_log!(self, "{e}");
Err(e)
}
}
}
Expand Down Expand Up @@ -218,7 +210,7 @@ where
)
.await?;
Err(ServerTaskError::InternalAdapterError(anyhow!(
"blocked by inspection policy"
"smtp blocked by inspection policy"
)))
}

Expand Down

0 comments on commit 68dc246

Please sign in to comment.