Skip to content

Commit

Permalink
chore: upgrade to [email protected]
Browse files Browse the repository at this point in the history

---------

Co-authored-by: “ramfox” <“[email protected]”>
  • Loading branch information
ramfox and “ramfox” authored Dec 17, 2024
1 parent 8ecc9c3 commit fc434f1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 36 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iroh-c-ffi"
version = "0.29.0"
version = "0.30.0"
edition = "2021"
license = "MIT OR Apache-2.0"

Expand All @@ -19,9 +19,11 @@ required-features = ["headers"] # Do not build unless generating headers.
[dependencies]
anyhow = "1.0.79"
bytes = "1.5.0"
iroh = { version = "0.29", features = ["discovery-local-network"] }
iroh = { version = "0.30", features = ["discovery-local-network"] }
iroh-base = { version = "0.30", features = ["ticket"] }
once_cell = "1.19.0"
quinn = { version = "0.12", package = "iroh-quinn" }
rand = "0.8.5"
safer-ffi = { version = "0.1.5" }
socket2 = "0.5.7"
tokio = { version = "1.36.0", features = ["rt-multi-thread"] }
Expand Down
23 changes: 10 additions & 13 deletions src/addr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use iroh::{relay::RelayUrl, ticket::NodeTicket};
use iroh::RelayUrl;
use iroh_base::ticket::NodeTicket;
use safer_ffi::{prelude::*, vec};

use crate::key::PublicKey;
Expand All @@ -24,25 +25,22 @@ impl PartialEq for NodeAddr {
}
}

impl From<NodeAddr> for iroh::endpoint::NodeAddr {
impl From<NodeAddr> for iroh::NodeAddr {
fn from(addr: NodeAddr) -> Self {
let direct_addresses = addr.direct_addresses.iter().map(|a| a.addr).collect();
iroh::endpoint::NodeAddr {
iroh::NodeAddr {
node_id: addr.node_id.into(),
info: iroh::endpoint::AddrInfo {
relay_url: addr
.relay_url
.map(|u| u.url.clone().expect("url not initialized")),
direct_addresses,
},
relay_url: addr
.relay_url
.map(|u| u.url.clone().expect("url not initialized")),
direct_addresses,
}
}
}

impl From<iroh::endpoint::NodeAddr> for NodeAddr {
fn from(addr: iroh::endpoint::NodeAddr) -> Self {
impl From<iroh::NodeAddr> for NodeAddr {
fn from(addr: iroh::NodeAddr) -> Self {
let direct_addresses = addr
.info
.direct_addresses
.into_iter()
.map(|addr| Box::new(SocketAddr { addr }).into())
Expand All @@ -51,7 +49,6 @@ impl From<iroh::endpoint::NodeAddr> for NodeAddr {
NodeAddr {
node_id: addr.node_id.into(),
relay_url: addr
.info
.relay_url
.map(|url| Box::new(Url { url: Some(url) }).into()),
direct_addresses,
Expand Down
4 changes: 2 additions & 2 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ pub fn endpoint_bind(
}

fn make_discovery_config(
secret_key: iroh::key::SecretKey,
secret_key: iroh::SecretKey,
discovery_config: DiscoveryConfig,
) -> Option<iroh::discovery::ConcurrentDiscovery> {
let services = match discovery_config {
Expand All @@ -303,7 +303,7 @@ fn make_discovery_config(
services.map(ConcurrentDiscovery::from_services)
}

fn make_dns_discovery(secret_key: &iroh::key::SecretKey) -> Vec<Box<dyn Discovery>> {
fn make_dns_discovery(secret_key: &iroh::SecretKey) -> Vec<Box<dyn Discovery>> {
vec![
Box::new(DnsDiscovery::n0_dns()),
Box::new(PkarrPublisher::n0_dns(secret_key.clone())),
Expand Down
35 changes: 16 additions & 19 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ pub fn public_key_free(_key: PublicKey) {
/// Result must be freed using `rust_free_string`
#[ffi_export]
pub fn public_key_as_base32(key: &PublicKey) -> char_p::Box {
iroh::key::PublicKey::from(key)
.to_string()
.try_into()
.unwrap()
iroh::PublicKey::from(key).to_string().try_into().unwrap()
}

/// Generate a default (invalid) public key.
Expand All @@ -49,7 +46,7 @@ pub fn public_key_default() -> PublicKey {
/// Parses the public key from a base32 string.
#[ffi_export]
pub fn public_key_from_base32(raw_key: char_p::Ref<'_>, out: &mut PublicKey) -> KeyResult {
let key: Result<iroh::key::PublicKey, _> = raw_key.to_str().parse();
let key: Result<iroh::PublicKey, _> = raw_key.to_str().parse();

match key {
Ok(key) => {
Expand All @@ -60,23 +57,23 @@ pub fn public_key_from_base32(raw_key: char_p::Ref<'_>, out: &mut PublicKey) ->
}
}

impl From<iroh::key::PublicKey> for PublicKey {
fn from(key: iroh::key::PublicKey) -> Self {
impl From<iroh::PublicKey> for PublicKey {
fn from(key: iroh::PublicKey) -> Self {
PublicKey {
key: *key.as_bytes(),
}
}
}

impl From<PublicKey> for iroh::key::PublicKey {
impl From<PublicKey> for iroh::PublicKey {
fn from(key: PublicKey) -> Self {
iroh::key::PublicKey::try_from(&key.key).unwrap()
iroh::PublicKey::try_from(&key.key).unwrap()
}
}

impl From<&PublicKey> for iroh::key::PublicKey {
impl From<&PublicKey> for iroh::PublicKey {
fn from(key: &PublicKey) -> Self {
iroh::key::PublicKey::try_from(&key.key).unwrap()
iroh::PublicKey::try_from(&key.key).unwrap()
}
}

Expand All @@ -85,7 +82,7 @@ impl From<&PublicKey> for iroh::key::PublicKey {
#[repr(opaque)]
#[derive(Debug, Clone)]
pub struct SecretKey {
key: iroh::key::SecretKey,
key: iroh::SecretKey,
}

/// Free the passed in key.
Expand All @@ -100,7 +97,7 @@ pub fn secret_key_free(key: repr_c::Box<SecretKey>) {
#[ffi_export]
pub fn secret_key_default() -> repr_c::Box<SecretKey> {
Box::new(SecretKey {
key: iroh::key::SecretKey::generate(),
key: iroh::SecretKey::generate(rand::rngs::OsRng),
})
.into()
}
Expand All @@ -111,7 +108,7 @@ pub fn secret_key_from_base32(
raw_key: char_p::Ref<'_>,
out: &mut repr_c::Box<SecretKey>,
) -> KeyResult {
let key: Result<iroh::key::SecretKey, _> = raw_key.to_str().parse();
let key: Result<iroh::SecretKey, _> = raw_key.to_str().parse();

match key {
Ok(key) => {
Expand All @@ -128,7 +125,7 @@ pub fn secret_key_from_base32(
#[ffi_export]
pub fn secret_key_generate() -> repr_c::Box<SecretKey> {
Box::new(SecretKey {
key: iroh::key::SecretKey::generate(),
key: iroh::SecretKey::generate(rand::rngs::OsRng),
})
.into()
}
Expand All @@ -149,19 +146,19 @@ pub fn secret_key_public(key: &SecretKey) -> PublicKey {
key.key.public().into()
}

impl From<iroh::key::SecretKey> for SecretKey {
fn from(key: iroh::key::SecretKey) -> Self {
impl From<iroh::SecretKey> for SecretKey {
fn from(key: iroh::SecretKey) -> Self {
SecretKey { key }
}
}

impl From<SecretKey> for iroh::key::SecretKey {
impl From<SecretKey> for iroh::SecretKey {
fn from(key: SecretKey) -> Self {
key.key
}
}

impl From<&SecretKey> for iroh::key::SecretKey {
impl From<&SecretKey> for iroh::SecretKey {
fn from(key: &SecretKey) -> Self {
key.key.clone()
}
Expand Down

0 comments on commit fc434f1

Please sign in to comment.