Skip to content
Permalink
Browse files

rust: infohash support == operator and from hex

  • Loading branch information...
AmarOk1412 authored and aberaud committed Oct 29, 2019
1 parent 429a5ad commit 42398a541d168f1cb3e168b4af6f85a9f55cf120
Showing with 12 additions and 1 deletion.
  1. +2 −0 rust/src/ffi.rs
  2. +9 −0 rust/src/infohash.rs
  3. +1 −1 rust/src/value.rs
@@ -44,6 +44,7 @@ pub struct Blob
}

#[repr(C)]
#[derive(PartialEq)]
pub struct InfoHash
{
pub d: [u8; HASH_LEN],
@@ -144,6 +145,7 @@ extern {
pub fn dht_infohash_print(h: *const InfoHash) -> *const c_char;
pub fn dht_infohash_random(h: *mut InfoHash);
pub fn dht_infohash_get(h: *mut InfoHash, dat: *mut u8, dat_size: size_t);
pub fn dht_infohash_from_hex(h: *mut InfoHash, dat: *const c_char);
pub fn dht_infohash_is_zero(j: *const InfoHash) -> bool;

// dht::PkId
@@ -55,6 +55,15 @@ impl InfoHash {
h
}

pub fn from_hex(data: &str) -> InfoHash {
let mut h = InfoHash::new();
unsafe {
let c_str = CString::new(data).unwrap();
dht_infohash_from_hex(&mut h, c_str.as_ptr());
}
h
}

pub fn is_zero(&self) -> bool {
unsafe {
dht_infohash_is_zero(self)
@@ -65,7 +65,7 @@ impl Value {
}
}

fn recipient(&self) -> InfoHash {
pub fn recipient(&self) -> InfoHash {
unsafe {
dht_value_get_recipient(self)
}

0 comments on commit 42398a5

Please sign in to comment.
You can’t perform that action at this time.