Got gemini proxy working, via a custom tokio_rustls branch
This commit is contained in:
parent
c8176c819f
commit
c1659fab2a
@ -23,7 +23,7 @@ service:
|
|||||||
value: ""
|
value: ""
|
||||||
gemini:
|
gemini:
|
||||||
proxied_domains:
|
proxied_domains:
|
||||||
localhost:
|
mediocregopher.com:
|
||||||
url: gemini://127.0.0.1:1965
|
url: gemini://127.0.0.1:1965
|
||||||
passphrase: foobar
|
passphrase: foobar
|
||||||
dns_records:
|
dns_records:
|
||||||
|
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -2964,8 +2964,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-rustls"
|
name = "tokio-rustls"
|
||||||
version = "0.24.1"
|
version = "0.24.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://code.betamike.com/micropelago/tokio-rustls.git?branch=transparent-acceptor#18fd688b335430e17e054e15ff7d6ce073db2419"
|
||||||
checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rustls",
|
"rustls",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
@ -45,3 +45,6 @@ serde_yaml = "0.9.22"
|
|||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
reqwest = "0.11.18"
|
reqwest = "0.11.18"
|
||||||
hyper-reverse-proxy = "0.5.1"
|
hyper-reverse-proxy = "0.5.1"
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
tokio-rustls = { git = "https://code.betamike.com/micropelago/tokio-rustls.git", branch = "transparent-acceptor" }
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
pkgs.openssl
|
pkgs.openssl
|
||||||
toolchain
|
toolchain
|
||||||
|
|
||||||
pkgs.gmni
|
pkgs.nmap # ncat
|
||||||
];
|
];
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
source $(pwd)/.env.dev
|
source $(pwd)/.env.dev
|
||||||
|
@ -36,11 +36,14 @@ impl Service {
|
|||||||
service
|
service
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn proxy_conn(
|
async fn proxy_conn<IO>(
|
||||||
&self,
|
&self,
|
||||||
proxied_domain: &ConfigProxiedDomain,
|
proxied_domain: &ConfigProxiedDomain,
|
||||||
mut conn: tokio::net::TcpStream,
|
mut conn: IO,
|
||||||
) -> unexpected::Result<()> {
|
) -> unexpected::Result<()>
|
||||||
|
where
|
||||||
|
IO: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin,
|
||||||
|
{
|
||||||
let mut proxy_conn = tokio::net::TcpStream::connect(&proxied_domain.url.addr)
|
let mut proxy_conn = tokio::net::TcpStream::connect(&proxied_domain.url.addr)
|
||||||
.await
|
.await
|
||||||
.map_unexpected_while(|| {
|
.map_unexpected_while(|| {
|
||||||
@ -55,10 +58,10 @@ impl Service {
|
|||||||
async fn handle_conn(
|
async fn handle_conn(
|
||||||
&self,
|
&self,
|
||||||
conn: tokio::net::TcpStream,
|
conn: tokio::net::TcpStream,
|
||||||
tls_conn: rustls::ServerConnection,
|
_tls_config: sync::Arc<rustls::ServerConfig>,
|
||||||
) -> Result<(), HandleConnError> {
|
) -> Result<(), HandleConnError> {
|
||||||
let acceptor =
|
let acceptor =
|
||||||
tokio_rustls::LazyConfigAcceptor::new(rustls::server::Acceptor::default(), conn);
|
tokio_rustls::TransparentConfigAcceptor::new(rustls::server::Acceptor::default(), conn);
|
||||||
futures::pin_mut!(acceptor);
|
futures::pin_mut!(acceptor);
|
||||||
|
|
||||||
match acceptor.as_mut().await {
|
match acceptor.as_mut().await {
|
||||||
@ -77,10 +80,7 @@ impl Service {
|
|||||||
|
|
||||||
// If the domain should be proxied, then proxy it
|
// If the domain should be proxied, then proxy it
|
||||||
if let Some(proxied_domain) = self.config.gemini.proxied_domains.get(&domain) {
|
if let Some(proxied_domain) = self.config.gemini.proxied_domains.get(&domain) {
|
||||||
let conn = acceptor
|
let conn = start.into_original_stream();
|
||||||
.take_io()
|
|
||||||
.expect("failed to take back underlying TCP connection");
|
|
||||||
|
|
||||||
self.proxy_conn(proxied_domain, conn).await?;
|
self.proxy_conn(proxied_domain, conn).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -130,10 +130,7 @@ async fn listen(
|
|||||||
let tls_config = tls_config.clone();
|
let tls_config = tls_config.clone();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let tls_conn = rustls::ServerConnection::new(tls_config)
|
match service.handle_conn(conn, tls_config).await {
|
||||||
.expect("failed to initialize TLS connection state");
|
|
||||||
|
|
||||||
match service.handle_conn(conn, tls_conn).await {
|
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(HandleConnError::ClientError(e)) => {
|
Err(HandleConnError::ClientError(e)) => {
|
||||||
log::warn!("Bad request from connection {addr}: {e}")
|
log::warn!("Bad request from connection {addr}: {e}")
|
||||||
|
Loading…
Reference in New Issue
Block a user