Skip to content

Commit a784d24

Browse files
committed
update to use capnp 0.22
1 parent 582f26c commit a784d24

File tree

13 files changed

+412
-525
lines changed

13 files changed

+412
-525
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ c-ares-sys = { version = "10.0", default-features = false }
174174
hickory-proto = { version = "0.25", default-features = false }
175175
hickory-client = { version = "0.25", default-features = false }
176176
#
177-
capnp-rpc = "0.21"
178-
capnp = "0.21"
179-
capnpc = "0.21"
177+
capnp-rpc = "0.22"
178+
capnp = "0.22"
179+
capnpc = "0.22"
180180
#
181181
libc = "0.2.169"
182182
rustix = { version = "1.0", default-features = false }

g3keymess/src/control/capnp/proc.rs

Lines changed: 63 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use std::str::FromStr;
77

88
use anyhow::anyhow;
9-
use capnp::capability::Promise;
10-
use capnp_rpc::pry;
119

1210
use g3_types::metrics::{MetricTagName, MetricTagValue};
1311

@@ -20,131 +18,118 @@ use super::set_operation_result;
2018
pub(super) struct ProcControlImpl;
2119

2220
impl proc_control::Server for ProcControlImpl {
23-
fn version(
24-
&mut self,
21+
async fn version(
22+
&self,
2523
_params: proc_control::VersionParams,
2624
mut results: proc_control::VersionResults,
27-
) -> Promise<(), capnp::Error> {
25+
) -> capnp::Result<()> {
2826
results.get().set_version(crate::build::VERSION);
29-
Promise::ok(())
27+
Ok(())
3028
}
3129

32-
fn offline(
33-
&mut self,
30+
async fn offline(
31+
&self,
3432
_params: proc_control::OfflineParams,
3533
mut results: proc_control::OfflineResults,
36-
) -> Promise<(), capnp::Error> {
37-
Promise::from_future(async move {
38-
g3_daemon::control::quit::start_graceful_shutdown().await;
39-
set_operation_result(results.get().init_result(), Ok(()));
40-
Ok(())
41-
})
34+
) -> capnp::Result<()> {
35+
g3_daemon::control::quit::start_graceful_shutdown().await;
36+
set_operation_result(results.get().init_result(), Ok(()));
37+
Ok(())
4238
}
4339

44-
fn cancel_shutdown(
45-
&mut self,
40+
async fn cancel_shutdown(
41+
&self,
4642
_params: proc_control::CancelShutdownParams,
4743
mut results: proc_control::CancelShutdownResults,
48-
) -> Promise<(), capnp::Error> {
49-
Promise::from_future(async move {
50-
let r = g3_daemon::control::quit::cancel_graceful_shutdown().await;
51-
set_operation_result(results.get().init_result(), r);
52-
Ok(())
53-
})
44+
) -> capnp::Result<()> {
45+
let r = g3_daemon::control::quit::cancel_graceful_shutdown().await;
46+
set_operation_result(results.get().init_result(), r);
47+
Ok(())
5448
}
5549

56-
fn release_controller(
57-
&mut self,
50+
async fn release_controller(
51+
&self,
5852
_params: proc_control::ReleaseControllerParams,
5953
mut results: proc_control::ReleaseControllerResults,
60-
) -> Promise<(), capnp::Error> {
61-
Promise::from_future(async move {
62-
let r = g3_daemon::control::quit::release_controller().await;
63-
set_operation_result(results.get().init_result(), r);
64-
Ok(())
65-
})
54+
) -> capnp::Result<()> {
55+
let r = g3_daemon::control::quit::release_controller().await;
56+
set_operation_result(results.get().init_result(), r);
57+
Ok(())
6658
}
6759

68-
fn list_server(
69-
&mut self,
60+
async fn list_server(
61+
&self,
7062
_params: proc_control::ListServerParams,
7163
mut results: proc_control::ListServerResults,
72-
) -> Promise<(), capnp::Error> {
64+
) -> capnp::Result<()> {
7365
let set = crate::serve::get_names();
7466
let mut builder = results.get().init_result(set.len() as u32);
7567
for (i, name) in set.iter().enumerate() {
7668
builder.set(i as u32, name.as_str());
7769
}
78-
Promise::ok(())
70+
Ok(())
7971
}
8072

81-
fn get_server(
82-
&mut self,
73+
async fn get_server(
74+
&self,
8375
params: proc_control::GetServerParams,
8476
mut results: proc_control::GetServerResults,
85-
) -> Promise<(), capnp::Error> {
86-
let server = pry!(pry!(pry!(params.get()).get_name()).to_str());
87-
pry!(set_fetch_result::<server_control::Owned>(
77+
) -> capnp::Result<()> {
78+
let server = params.get()?.get_name()?.to_str()?;
79+
set_fetch_result::<server_control::Owned>(
8880
results.get().init_server(),
8981
super::server::ServerControlImpl::new_client(server),
90-
));
91-
Promise::ok(())
82+
)
9283
}
9384

94-
fn publish_key(
95-
&mut self,
85+
async fn publish_key(
86+
&self,
9687
params: proc_control::PublishKeyParams,
9788
mut results: proc_control::PublishKeyResults,
98-
) -> Promise<(), capnp::Error> {
99-
let pem = pry!(pry!(pry!(params.get()).get_pem()).to_string());
100-
Promise::from_future(async move {
101-
let r = crate::control::bridge::add_key(&pem).await;
102-
set_operation_result(results.get().init_result(), r);
103-
Ok(())
104-
})
89+
) -> capnp::Result<()> {
90+
let pem = params.get()?.get_pem()?.to_str()?;
91+
let r = crate::control::bridge::add_key(pem).await;
92+
set_operation_result(results.get().init_result(), r);
93+
Ok(())
10594
}
10695

107-
fn list_keys(
108-
&mut self,
96+
async fn list_keys(
97+
&self,
10998
_params: proc_control::ListKeysParams,
11099
mut results: proc_control::ListKeysResults,
111-
) -> Promise<(), capnp::Error> {
112-
Promise::from_future(async move {
113-
let r = crate::control::bridge::list_keys()
114-
.await
115-
.unwrap_or_default();
116-
let mut builder = results.get().init_result(r.len() as u32);
117-
for (i, ski) in r.iter().enumerate() {
118-
builder.set(i as u32, ski.as_slice());
119-
}
120-
Ok(())
121-
})
100+
) -> capnp::Result<()> {
101+
let r = crate::control::bridge::list_keys()
102+
.await
103+
.unwrap_or_default();
104+
let mut builder = results.get().init_result(r.len() as u32);
105+
for (i, ski) in r.iter().enumerate() {
106+
builder.set(i as u32, ski.as_slice());
107+
}
108+
Ok(())
122109
}
123110

124-
fn check_key(
125-
&mut self,
111+
async fn check_key(
112+
&self,
126113
params: proc_control::CheckKeyParams,
127114
mut results: proc_control::CheckKeyResults,
128-
) -> Promise<(), capnp::Error> {
129-
let ski = pry!(pry!(params.get()).get_ski()).to_vec();
130-
Promise::from_future(async move {
131-
let r = crate::control::bridge::check_key(ski).await;
132-
set_operation_result(results.get().init_result(), r);
133-
Ok(())
134-
})
115+
) -> capnp::Result<()> {
116+
let ski = params.get()?.get_ski()?.to_vec();
117+
let r = crate::control::bridge::check_key(ski).await;
118+
set_operation_result(results.get().init_result(), r);
119+
Ok(())
135120
}
136121

137-
fn add_metrics_tag(
138-
&mut self,
122+
async fn add_metrics_tag(
123+
&self,
139124
params: proc_control::AddMetricsTagParams,
140125
mut results: proc_control::AddMetricsTagResults,
141-
) -> Promise<(), capnp::Error> {
142-
let name = pry!(pry!(pry!(params.get()).get_name()).to_str());
143-
let value = pry!(pry!(pry!(params.get()).get_value()).to_str());
126+
) -> capnp::Result<()> {
127+
let name = params.get()?.get_name()?.to_str()?;
128+
let value = params.get()?.get_value()?.to_str()?;
144129

145130
let r = do_add_metrics_tag(name, value);
146131
set_operation_result(results.get().init_result(), r);
147-
Promise::ok(())
132+
Ok(())
148133
}
149134
}
150135

0 commit comments

Comments
 (0)