From 697d554edbea4a248246453801d3485ca63b9fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= Date: Mon, 28 Oct 2019 17:58:04 -0400 Subject: [PATCH] dhtrunner: change put methods --- rust/src/dhtrunner.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/rust/src/dhtrunner.rs b/rust/src/dhtrunner.rs index 93dd0209..584d33b6 100644 --- a/rust/src/dhtrunner.rs +++ b/rust/src/dhtrunner.rs @@ -217,25 +217,37 @@ impl DhtRunner { } } - pub fn put<'a>(&mut self, h: &InfoHash, v: Box, - done_cb: &'a mut(dyn FnMut(bool))) { + pub fn put<'a, T: Into>>(&mut self, h: &InfoHash, v: Box, + done_cb: &'a mut(dyn FnMut(bool)), permanent: T) { let handler = Box::new(PutHandler { done_cb, }); let handler = Box::into_raw(handler) as *mut c_void; unsafe { - dht_runner_put(&mut *self, h, &*v, put_handler_done, handler, false) + dht_runner_put(&mut *self, h, &*v, put_handler_done, handler, permanent.into().unwrap_or(false)) } } - pub fn permanent_put<'a>(&mut self, h: &InfoHash, v: Box, - done_cb: &'a mut(dyn FnMut(bool))) { + pub fn put_signed<'a, T: Into>>(&mut self, h: &InfoHash, v: Box, + done_cb: &'a mut(dyn FnMut(bool)), permanent: T) { let handler = Box::new(PutHandler { done_cb, }); let handler = Box::into_raw(handler) as *mut c_void; unsafe { - dht_runner_put(&mut *self, h, &*v, put_handler_done, handler, true) + dht_runner_put_signed(&mut *self, h, &*v, put_handler_done, handler, permanent.into().unwrap_or(false)) + } + } + + pub fn put_encrypted<'a, T: Into>>(&mut self, h: &InfoHash, v: Box, + to: &InfoHash, + done_cb: &'a mut(dyn FnMut(bool)), permanent: T) { + let handler = Box::new(PutHandler { + done_cb, + }); + let handler = Box::into_raw(handler) as *mut c_void; + unsafe { + dht_runner_put_encrypted(&mut *self, h, &*v, to, put_handler_done, handler, permanent.into().unwrap_or(false)) } }