From ae62216bf457c81b686be9bbbea5d2ab6866cc9e Mon Sep 17 00:00:00 2001 From: Adrien Beraud <adrien.beraud@savoirfairelinux.com> Date: Fri, 7 Jun 2024 10:29:17 -0400 Subject: [PATCH] rust: update to 2021, fix memory issues --- rust/Cargo.toml | 10 +++++----- rust/src/dhtrunner.rs | 17 +++++++++-------- rust/src/ffi.rs | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 7227d0fa..47a6400f 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -2,10 +2,10 @@ name = "opendht" version = "0.1.0" authors = ["Sébastien Blin <sebastien.blin@savoirfairelinux.com>"] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +edition = "2021" [dependencies] -libc="0.2.0" -os_socketaddr="0.2.3" \ No newline at end of file +libc="0.2" +os_socketaddr="0.2.3" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/rust/src/dhtrunner.rs b/rust/src/dhtrunner.rs index 3ff9f212..1292fce5 100644 --- a/rust/src/dhtrunner.rs +++ b/rust/src/dhtrunner.rs @@ -56,6 +56,7 @@ impl DhtRunnerConfig { privatekey: ptr::null_mut(), certificate: ptr::null_mut(), }, + log: true, }); unsafe { dht_runner_config_default(&mut *config); @@ -64,23 +65,23 @@ impl DhtRunnerConfig { } pub fn set_proxy_server(&mut self, proxy_server: &str) { - self.proxy_server = CString::new(proxy_server).unwrap().as_ptr(); + self.proxy_server = CString::new(proxy_server).unwrap().into_raw(); } pub fn set_push_node_id(&mut self, push_node_id: &str) { - self.push_node_id = CString::new(push_node_id).unwrap().as_ptr(); + self.push_node_id = CString::new(push_node_id).unwrap().into_raw(); } pub fn set_push_token(&mut self, push_token: &str) { - self.push_token = CString::new(push_token).unwrap().as_ptr(); + self.push_token = CString::new(push_token).unwrap().into_raw(); } pub fn set_push_topic(&mut self, push_topic: &str) { - self.push_topic = CString::new(push_topic).unwrap().as_ptr(); + self.push_topic = CString::new(push_topic).unwrap().into_raw(); } pub fn set_push_platform(&mut self, push_platform: &str) { - self.push_platform = CString::new(push_platform).unwrap().as_ptr(); + self.push_platform = CString::new(push_platform).unwrap().into_raw(); } pub fn set_identity(&mut self, certificate: Box<DhtCertificate>, privatekey: Box<PrivateKey>) { @@ -93,7 +94,7 @@ impl DhtRunnerConfig { impl DhtNodeConfig { pub fn set_persist_path(&mut self, persist_path: &str) { - self.persist_path = CString::new(persist_path).unwrap().as_ptr(); + self.persist_path = CString::new(persist_path).unwrap().into_raw(); } } @@ -197,8 +198,8 @@ impl DhtRunner { pub fn bootstrap(&mut self, host: &str, service: u16) { unsafe { dht_runner_bootstrap(&mut *self, - CString::new(host).unwrap().as_ptr(), - CString::new(service.to_string()).unwrap().as_ptr()) + CString::new(host).unwrap().into_raw(), + CString::new(service.to_string()).unwrap().into_raw()) } } diff --git a/rust/src/ffi.rs b/rust/src/ffi.rs index f14ffaa8..3ae928c5 100644 --- a/rust/src/ffi.rs +++ b/rust/src/ffi.rs @@ -124,9 +124,9 @@ pub struct DhtRunnerConfig pub peer_publish: bool, pub server_ca: *mut DhtCertificate, pub client_identity: DhtIdentity, + pub log: bool, } - #[link(name = "opendht-c")] extern { // dht::Value -- GitLab