Skip to content

Commit

Permalink
Refactor away the return val of setConfiguration
Browse files Browse the repository at this point in the history
Signed-off-by: Mr-Kanister <[email protected]>
  • Loading branch information
Mr-Kanister committed Dec 6, 2024
1 parent 3b10e69 commit a496c53
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ interface Client {

suspend fun getConfiguration(): Configuration

suspend fun setConfiguration(configuration: Configuration): UInt
suspend fun setConfiguration(configuration: Configuration)

suspend fun getOdexFiles(pid: UInt): Flow<String>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ object RustClient : Client {
return configuration
}

override suspend fun setConfiguration(configuration: Configuration): UInt {
override suspend fun setConfiguration(configuration: Configuration) {
this.configuration = configuration

return 0u
}

override suspend fun initStream(): Flow<Event> = flow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class RustClient(private val inner: uniffi.client.Client) : Client {

override suspend fun getConfiguration(): Configuration = inner.getConfiguration().into()

override suspend fun setConfiguration(configuration: Configuration): UInt =
override suspend fun setConfiguration(configuration: Configuration) =
inner.setConfiguration(configuration.into())

override suspend fun getOdexFiles(pid: UInt): Flow<String> =
Expand Down
6 changes: 3 additions & 3 deletions rust/backend/daemon/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use shared::{
counter::counter_server::CounterServer,
ziofa::{
ziofa_server::{Ziofa, ZiofaServer},
CheckServerResponse, ProcessList, SetConfigurationResponse,
CheckServerResponse, ProcessList,
},
};
use std::path::PathBuf;
Expand Down Expand Up @@ -93,7 +93,7 @@ impl Ziofa for ZiofaImpl {
async fn set_configuration(
&self,
request: Request<Configuration>,
) -> Result<Response<SetConfigurationResponse>, Status> {
) -> Result<Response<()>, Status> {
let config = request.into_inner();

// TODO: Implement function 'validate'
Expand All @@ -109,7 +109,7 @@ impl Ziofa for ZiofaImpl {
.update_from_config(ebpf_guard.deref_mut(), &config)
.map_err(EbpfErrorWrapper::from)?;

Ok(Response::new(SetConfigurationResponse { response_type: 0 }))
Ok(Response::new(()))
}

type InitStreamStream = Receiver<Result<Event, Status>>;
Expand Down
26 changes: 11 additions & 15 deletions rust/backend/daemon/tests/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,23 @@ async fn set_get_configuration() {
let mut client = setup().await;
let default_config = Configuration {
uprobes: vec![],
vfs_write: Some(VfsWriteConfig { entries: std::collections::HashMap::new() }),
sys_sendmsg: Some(SysSendmsgConfig { entries: std::collections::HashMap::new() }),
vfs_write: Some(VfsWriteConfig {
entries: std::collections::HashMap::new(),
}),
sys_sendmsg: Some(SysSendmsgConfig {
entries: std::collections::HashMap::new(),
}),
};
assert_eq!(
client
.set_configuration(default_config.clone())
.await
.expect("should work")
.into_inner()
.response_type,
0
);
client
.set_configuration(default_config.clone())
.await
.expect("should work");

let res_config = client
.get_configuration(())
.await
.expect("should work")
.into_inner();

assert_eq!(
res_config,
default_config
);
assert_eq!(res_config, default_config);
}
29 changes: 13 additions & 16 deletions rust/client/src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,18 @@ async fn sendmsg(client: &mut Client, pid: u32) -> Result<()> {
}

async fn set_config(client: &mut Client) -> Result<()> {
println!(
"response_type: {}",
client
.set_configuration(Configuration {
uprobes: vec![],
vfs_write: Some(VfsWriteConfig {
entries: std::collections::HashMap::new(),
}),
sys_sendmsg: Some(SysSendmsgConfig {
entries: std::collections::HashMap::new(),
}),
})
.await?
);

client
.set_configuration(Configuration {
uprobes: vec![],
vfs_write: Some(VfsWriteConfig {
entries: std::collections::HashMap::new(),
}),
sys_sendmsg: Some(SysSendmsgConfig {
entries: std::collections::HashMap::new(),
}),
})
.await?;
println!("Success");
Ok(())
}

Expand Down Expand Up @@ -187,7 +184,7 @@ pub async fn main() -> anyhow::Result<()> {
}
Commands::Odex { pid, silent } => {
get_odex_files(&mut client, pid, silent).await?;
},
}
Commands::Symbols { odex_file, silent } => {
get_symbols(&mut client, odex_file, silent).await?;
}
Expand Down
2 changes: 1 addition & 1 deletion rust/client/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Client {
Ok(self.0.lock().await.get_configuration().await?)
}

pub async fn set_configuration(&self, configuration: Configuration) -> Result<u32> {
pub async fn set_configuration(&self, configuration: Configuration) -> Result<()> {
Ok(self.0.lock().await.set_configuration(configuration).await?)
}

Expand Down
10 changes: 3 additions & 7 deletions rust/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,9 @@ impl Client {
Ok(self.ziofa.get_configuration(()).await?.into_inner())
}

pub async fn set_configuration(&mut self, configuration: Configuration) -> Result<u32> {
Ok(self
.ziofa
.set_configuration(configuration)
.await?
.into_inner()
.response_type)
pub async fn set_configuration(&mut self, configuration: Configuration) -> Result<()> {
self.ziofa.set_configuration(configuration).await?;
Ok(())
}

pub async fn init_stream(&mut self) -> Result<impl Stream<Item = Result<Event>>> {
Expand Down
8 changes: 2 additions & 6 deletions rust/shared/proto/ziofa.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ service Ziofa {
rpc CheckServer(google.protobuf.Empty) returns (CheckServerResponse) {}
rpc ListProcesses(google.protobuf.Empty) returns (ProcessList) {}

rpc GetConfiguration(google.protobuf.Empty) returns (config.Configuration){}
rpc SetConfiguration(config.Configuration) returns (SetConfigurationResponse){}
rpc GetConfiguration(google.protobuf.Empty) returns (config.Configuration) {}
rpc SetConfiguration(config.Configuration) returns (google.protobuf.Empty) {}

rpc InitStream(google.protobuf.Empty) returns (stream Event) {} // all Responses genereated by the ebpf-programms are send via this stream

Expand Down Expand Up @@ -64,10 +64,6 @@ message CmdlineData {
repeated string args = 1;
}

message SetConfigurationResponse{
uint32 response_type = 1;
}

message Event {
oneof event_data {
VfsWriteEvent vfs_write = 1;
Expand Down

0 comments on commit a496c53

Please sign in to comment.