mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
misc patches
This commit is contained in:
@@ -151,103 +151,112 @@ where
|
|||||||
cx: &mut std::task::Context<'_>,
|
cx: &mut std::task::Context<'_>,
|
||||||
) -> Poll<Result<(Self::Metadata, AcceptStream), Error>> {
|
) -> Poll<Result<(Self::Metadata, AcceptStream), Error>> {
|
||||||
self.in_progress.mutate(|in_progress| {
|
self.in_progress.mutate(|in_progress| {
|
||||||
loop {
|
// First, check if any in-progress handshakes have completed
|
||||||
if !in_progress.is_empty() {
|
if !in_progress.is_empty() {
|
||||||
if let Poll::Ready(Some((handler, res))) = in_progress.poll_next_unpin(cx) {
|
if let Poll::Ready(Some((handler, res))) = in_progress.poll_next_unpin(cx) {
|
||||||
if let Some(res) = res.transpose() {
|
if let Some(res) = res.transpose() {
|
||||||
self.tls_handler = handler;
|
self.tls_handler = handler;
|
||||||
return Poll::Ready(res);
|
return Poll::Ready(res);
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
// Connection was rejected (preprocess returned None).
|
||||||
|
// Yield to the runtime to avoid busy-looping, but wake
|
||||||
|
// immediately to continue processing.
|
||||||
|
cx.waker().wake_by_ref();
|
||||||
|
return Poll::Pending;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let (metadata, stream) = ready!(self.accept.poll_accept(cx)?);
|
// Try to accept a new connection
|
||||||
let mut tls_handler = self.tls_handler.clone();
|
let (metadata, stream) = ready!(self.accept.poll_accept(cx)?);
|
||||||
let mut fut = async move {
|
let mut tls_handler = self.tls_handler.clone();
|
||||||
let res = async {
|
let mut fut = async move {
|
||||||
let mut acceptor = LazyConfigAcceptor::new(
|
let res = async {
|
||||||
Acceptor::default(),
|
let mut acceptor = LazyConfigAcceptor::new(
|
||||||
BackTrackingIO::new(stream),
|
Acceptor::default(),
|
||||||
);
|
BackTrackingIO::new(stream),
|
||||||
let mut mid: tokio_rustls::StartHandshake<BackTrackingIO<AcceptStream>> =
|
);
|
||||||
match (&mut acceptor).await {
|
let mut mid: tokio_rustls::StartHandshake<BackTrackingIO<AcceptStream>> =
|
||||||
Ok(a) => a,
|
match (&mut acceptor).await {
|
||||||
Err(e) => {
|
Ok(a) => a,
|
||||||
let mut stream =
|
Err(e) => {
|
||||||
acceptor.take_io().or_not_found("acceptor io")?;
|
let mut stream =
|
||||||
let (_, buf) = stream.rewind();
|
acceptor.take_io().or_not_found("acceptor io")?;
|
||||||
if std::str::from_utf8(buf)
|
let (_, buf) = stream.rewind();
|
||||||
.ok()
|
if std::str::from_utf8(buf)
|
||||||
.and_then(|buf| {
|
.ok()
|
||||||
buf.lines()
|
.and_then(|buf| {
|
||||||
.map(|l| l.trim())
|
buf.lines()
|
||||||
.filter(|l| !l.is_empty())
|
.map(|l| l.trim())
|
||||||
.next()
|
.filter(|l| !l.is_empty())
|
||||||
})
|
.next()
|
||||||
.map_or(false, |buf| {
|
})
|
||||||
regex::Regex::new("[A-Z]+ (.+) HTTP/1")
|
.map_or(false, |buf| {
|
||||||
.unwrap()
|
regex::Regex::new("[A-Z]+ (.+) HTTP/1")
|
||||||
.is_match(buf)
|
.unwrap()
|
||||||
})
|
.is_match(buf)
|
||||||
{
|
})
|
||||||
handle_http_on_https(stream).await.log_err();
|
{
|
||||||
|
handle_http_on_https(stream).await.log_err();
|
||||||
|
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
} else {
|
} else {
|
||||||
return Err(e).with_kind(ErrorKind::Network);
|
return Err(e).with_kind(ErrorKind::Network);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
let hello = mid.client_hello();
|
};
|
||||||
if let Some(cfg) = tls_handler.get_config(&hello, &metadata).await {
|
let hello = mid.client_hello();
|
||||||
let buffered = mid.io.stop_buffering();
|
if let Some(cfg) = tls_handler.get_config(&hello, &metadata).await {
|
||||||
mid.io
|
let buffered = mid.io.stop_buffering();
|
||||||
.write_all(&buffered)
|
mid.io
|
||||||
.await
|
.write_all(&buffered)
|
||||||
.with_kind(ErrorKind::Network)?;
|
.await
|
||||||
return Ok(match mid.into_stream(Arc::new(cfg)).await {
|
.with_kind(ErrorKind::Network)?;
|
||||||
Ok(stream) => {
|
return Ok(match mid.into_stream(Arc::new(cfg)).await {
|
||||||
let s = stream.get_ref().1;
|
Ok(stream) => {
|
||||||
Some((
|
let s = stream.get_ref().1;
|
||||||
TlsMetadata {
|
Some((
|
||||||
inner: metadata,
|
TlsMetadata {
|
||||||
tls_info: TlsHandshakeInfo {
|
inner: metadata,
|
||||||
sni: s.server_name().map(InternedString::intern),
|
tls_info: TlsHandshakeInfo {
|
||||||
alpn: s
|
sni: s.server_name().map(InternedString::intern),
|
||||||
.alpn_protocol()
|
alpn: s
|
||||||
.map(|a| MaybeUtf8String(a.to_vec())),
|
.alpn_protocol()
|
||||||
},
|
.map(|a| MaybeUtf8String(a.to_vec())),
|
||||||
},
|
},
|
||||||
Box::pin(stream) as AcceptStream,
|
},
|
||||||
))
|
Box::pin(stream) as AcceptStream,
|
||||||
}
|
))
|
||||||
Err(e) => {
|
}
|
||||||
tracing::trace!("Error completing TLS handshake: {e}");
|
Err(e) => {
|
||||||
tracing::trace!("{e:?}");
|
tracing::trace!("Error completing TLS handshake: {e}");
|
||||||
None
|
tracing::trace!("{e:?}");
|
||||||
}
|
None
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
|
||||||
.await;
|
|
||||||
(tls_handler, res)
|
|
||||||
}
|
}
|
||||||
.boxed();
|
.await;
|
||||||
match fut.poll_unpin(cx) {
|
(tls_handler, res)
|
||||||
Poll::Pending => {
|
}
|
||||||
in_progress.push(fut);
|
.boxed();
|
||||||
return Poll::Pending;
|
match fut.poll_unpin(cx) {
|
||||||
|
Poll::Pending => {
|
||||||
|
in_progress.push(fut);
|
||||||
|
Poll::Pending
|
||||||
|
}
|
||||||
|
Poll::Ready((handler, res)) => {
|
||||||
|
if let Some(res) = res.transpose() {
|
||||||
|
self.tls_handler = handler;
|
||||||
|
return Poll::Ready(res);
|
||||||
}
|
}
|
||||||
Poll::Ready((handler, res)) => {
|
// Connection was rejected (preprocess returned None).
|
||||||
if let Some(res) = res.transpose() {
|
// Yield to the runtime to avoid busy-looping, but wake
|
||||||
self.tls_handler = handler;
|
// immediately to continue processing.
|
||||||
return Poll::Ready(res);
|
cx.waker().wake_by_ref();
|
||||||
}
|
Poll::Pending
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -384,16 +384,12 @@ impl ImageSource {
|
|||||||
pub fn ingredients(&self) -> Vec<PathBuf> {
|
pub fn ingredients(&self) -> Vec<PathBuf> {
|
||||||
match self {
|
match self {
|
||||||
Self::Packed => Vec::new(),
|
Self::Packed => Vec::new(),
|
||||||
Self::DockerBuild {
|
Self::DockerBuild { dockerfile, .. } => {
|
||||||
dockerfile,
|
|
||||||
workdir,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
vec![
|
vec![
|
||||||
workdir
|
dockerfile
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.unwrap_or(Path::new("."))
|
.unwrap_or(Path::new("Dockerfile"))
|
||||||
.join(dockerfile.as_deref().unwrap_or(Path::new("Dockerfile"))),
|
.to_owned(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Self::DockerTag(_) => Vec::new(),
|
Self::DockerTag(_) => Vec::new(),
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::prelude::*;
|
|||||||
use crate::service::Service;
|
use crate::service::Service;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(in crate::service) struct EffectContext(Weak<Service>);
|
pub struct EffectContext(Weak<Service>);
|
||||||
impl EffectContext {
|
impl EffectContext {
|
||||||
pub fn new(service: Weak<Service>) -> Self {
|
pub fn new(service: Weak<Service>) -> Self {
|
||||||
Self(service)
|
Self(service)
|
||||||
|
|||||||
Reference in New Issue
Block a user