Skip to content

Commit 81e19a6

Browse files
authored
Merge pull request #313032 from microsoft/connor4312/cli-ahp-management
cli: implement client AHP control functionality
2 parents e78dfbd + ed85ff7 commit 81e19a6

39 files changed

Lines changed: 2672 additions & 1167 deletions

cli/Cargo.lock

Lines changed: 468 additions & 344 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,61 @@ name = "code"
1515
futures = "0.3.28"
1616
clap = { version = "4.3.0", features = ["derive", "env"] }
1717
open = "4.1.0"
18-
reqwest = { version = "0.11.22", default-features = false, features = ["json", "stream", "native-tls"] }
19-
tokio = { version = "1.38.2", features = ["full"] }
18+
reqwest = { version = "0.13", default-features = false, features = ["json", "stream", "native-tls"] }
19+
tokio = { version = "1.52", features = ["full"] }
2020
tokio-util = { version = "0.7.8", features = ["compat", "codec"] }
2121
flate2 = { version = "1.0.26", default-features = false, features = ["zlib"] }
2222
zip = { version = "0.6.6", default-features = false, features = ["time", "deflate-zlib"] }
2323
regex = "1.8.3"
24-
lazy_static = "1.4.0"
2524
sysinfo = { version = "0.29.0", default-features = false }
2625
serde = { version = "1.0.163", features = ["derive"] }
2726
serde_json = "1.0.96"
2827
rmp-serde = "1.1.1"
2928
uuid = { version = "1.4", features = ["serde", "v4"] }
3029
dirs = "5.0.1"
31-
rand = "0.9.3"
32-
opentelemetry = { version = "0.19.0", features = ["rt-tokio"] }
30+
rand = "0.10"
3331
serde_bytes = "0.11.9"
34-
chrono = { version = "0.4.26", features = ["serde", "std", "clock"], default-features = false }
32+
jiff = { version = "0.2", default-features = false, features = ["std", "serde"] }
33+
http = "1"
3534
gethostname = "0.4.3"
3635
libc = "0.2.144"
37-
tunnels = { git = "https://github.com/microsoft/dev-tunnels", rev = "8cae9b2a24c65c6c1958f5a0e77d72b23b5c6c30", default-features = false, features = ["connections"] }
36+
# temporary fork pending https://github.com/microsoft/dev-tunnels/pull/626
37+
tunnels = { git = "https://github.com/connor4312/dev-tunnels", rev = "4be50b3cc5ade8cb6beec4038c53ea4f2cdac5a2", default-features = false, features = ["connections"] }
3838
keyring = { version = "2.0.3", default-features = false, features = ["linux-secret-service-rt-tokio-crypto-openssl", "platform-windows", "platform-macos", "linux-keyutils"] }
3939
dialoguer = "0.10.4"
40-
hyper = { version = "0.14.26", features = ["server", "http1", "runtime"] }
40+
hyper = { version = "1", features = ["server", "http1", "client"] }
41+
hyper-util = { version = "0.1", features = ["tokio", "server-auto"] }
42+
http-body-util = "0.1"
43+
tokio-tungstenite = { version = "0.29", features = ["native-tls"] }
4144
indicatif = "0.17.4"
4245
tempfile = "3.5.0"
43-
clap_lex = "0.7.0"
46+
clap_lex = "1"
4447
url = "2.5.4"
45-
async-trait = "0.1.68"
4648
log = "0.4.18"
4749
const_format = "0.2.31"
4850
sha2 = "0.10.6"
49-
base64 = "0.21.2"
51+
base64 = "0.22"
5052
shell-escape = "0.1.5"
51-
thiserror = "1.0.40"
53+
thiserror = "2"
5254
cfg-if = "1.0.0"
5355
pin-project = "1.1.0"
5456
console = "0.15.7"
5557
bytes = "1.11.1"
5658
tar = "0.4.45"
59+
local-ip-address = "0.6"
60+
ahp = "0.1"
61+
ahp-types = "0.1"
62+
ahp-ws = "0.1"
5763

5864
[build-dependencies]
5965
serde = { version="1.0.163", features = ["derive"] }
6066
serde_json = "1.0.96"
6167
winresource = "0.1"
6268

6369
[target.'cfg(windows)'.dependencies]
64-
winreg = "0.50.0"
70+
winreg = "0.56"
6571
winapi = "0.3.9"
72+
windows-sys = { version = "0.61", features = ["Win32_System_Console", "Win32_UI_Input_KeyboardAndMouse"] }
6673

6774
[target.'cfg(target_os = "macos")'.dependencies]
6875
core-foundation = "0.9.3"

cli/src/async_pipe.rs

Lines changed: 30 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
use crate::{constants::APPLICATION_NAME, util::errors::CodeError};
7-
use async_trait::async_trait;
7+
use std::future::Future;
88
use std::path::{Path, PathBuf};
99
use std::pin::Pin;
10-
use std::task::{Context, Poll};
1110
use tokio::io::{AsyncRead, AsyncWrite};
1211
use tokio::net::TcpListener;
1312
use uuid::Uuid;
@@ -46,6 +45,7 @@ cfg_if::cfg_if! {
4645
} else {
4746
use tokio::{time::sleep, io::ReadBuf};
4847
use tokio::net::windows::named_pipe::{ClientOptions, ServerOptions, NamedPipeClient, NamedPipeServer};
48+
use std::task::{Context, Poll};
4949
use std::{time::Duration, io};
5050
use pin_project::pin_project;
5151

@@ -176,57 +176,6 @@ cfg_if::cfg_if! {
176176
}
177177
}
178178

179-
impl AsyncPipeListener {
180-
pub fn into_pollable(self) -> PollableAsyncListener {
181-
PollableAsyncListener {
182-
listener: Some(self),
183-
write_fut: tokio_util::sync::ReusableBoxFuture::new(make_accept_fut(None)),
184-
}
185-
}
186-
}
187-
188-
pub struct PollableAsyncListener {
189-
listener: Option<AsyncPipeListener>,
190-
write_fut: tokio_util::sync::ReusableBoxFuture<
191-
'static,
192-
(AsyncPipeListener, Result<AsyncPipe, CodeError>),
193-
>,
194-
}
195-
196-
async fn make_accept_fut(
197-
data: Option<AsyncPipeListener>,
198-
) -> (AsyncPipeListener, Result<AsyncPipe, CodeError>) {
199-
match data {
200-
Some(mut l) => {
201-
let c = l.accept().await;
202-
(l, c)
203-
}
204-
None => unreachable!("this future should not be pollable in this state"),
205-
}
206-
}
207-
208-
impl hyper::server::accept::Accept for PollableAsyncListener {
209-
type Conn = AsyncPipe;
210-
type Error = CodeError;
211-
212-
fn poll_accept(
213-
mut self: Pin<&mut Self>,
214-
cx: &mut Context<'_>,
215-
) -> Poll<Option<Result<Self::Conn, Self::Error>>> {
216-
if let Some(l) = self.listener.take() {
217-
self.write_fut.set(make_accept_fut(Some(l)))
218-
}
219-
220-
match self.write_fut.poll(cx) {
221-
Poll::Ready((l, cnx)) => {
222-
self.listener = Some(l);
223-
Poll::Ready(Some(cnx))
224-
}
225-
Poll::Pending => Poll::Pending,
226-
}
227-
}
228-
}
229-
230179
/// Gets a random name for a pipe/socket on the platform
231180
pub fn get_socket_name() -> PathBuf {
232181
cfg_if::cfg_if! {
@@ -243,28 +192,41 @@ pub type AcceptedRW = (
243192
Box<dyn AsyncWrite + Send + Unpin>,
244193
);
245194

246-
#[async_trait]
247195
pub trait AsyncRWAccepter {
248-
async fn accept_rw(&mut self) -> Result<AcceptedRW, CodeError>;
196+
fn accept_rw(
197+
&mut self,
198+
) -> Pin<Box<dyn Future<Output = Result<AcceptedRW, CodeError>> + Send + '_>>;
249199
}
250200

251-
#[async_trait]
252201
impl AsyncRWAccepter for AsyncPipeListener {
253-
async fn accept_rw(&mut self) -> Result<AcceptedRW, CodeError> {
254-
let pipe = self.accept().await?;
255-
let (read, write) = socket_stream_split(pipe);
256-
Ok((Box::new(read), Box::new(write)))
202+
fn accept_rw(
203+
&mut self,
204+
) -> Pin<Box<dyn Future<Output = Result<AcceptedRW, CodeError>> + Send + '_>> {
205+
Box::pin(async move {
206+
let pipe = self.accept().await?;
207+
let (read, write) = socket_stream_split(pipe);
208+
Ok((
209+
Box::new(read) as Box<dyn AsyncRead + Send + Unpin>,
210+
Box::new(write) as Box<dyn AsyncWrite + Send + Unpin>,
211+
))
212+
})
257213
}
258214
}
259215

260-
#[async_trait]
261216
impl AsyncRWAccepter for TcpListener {
262-
async fn accept_rw(&mut self) -> Result<AcceptedRW, CodeError> {
263-
let (stream, _) = self
264-
.accept()
265-
.await
266-
.map_err(CodeError::AsyncPipeListenerFailed)?;
267-
let (read, write) = tokio::io::split(stream);
268-
Ok((Box::new(read), Box::new(write)))
217+
fn accept_rw(
218+
&mut self,
219+
) -> Pin<Box<dyn Future<Output = Result<AcceptedRW, CodeError>> + Send + '_>> {
220+
Box::pin(async move {
221+
let (stream, _) = self
222+
.accept()
223+
.await
224+
.map_err(CodeError::AsyncPipeListenerFailed)?;
225+
let (read, write) = tokio::io::split(stream);
226+
Ok((
227+
Box::new(read) as Box<dyn AsyncRead + Send + Unpin>,
228+
Box::new(write) as Box<dyn AsyncWrite + Send + Unpin>,
229+
))
230+
})
269231
}
270232
}

0 commit comments

Comments
 (0)