Upgrade Iroh integration to 1.0
This commit is contained in:
parent
b0768999db
commit
32580749d6
9 changed files with 912 additions and 930 deletions
|
|
@ -7,13 +7,11 @@ license.workspace = true
|
|||
|
||||
[dependencies]
|
||||
hex.workspace = true
|
||||
ed25519.workspace = true
|
||||
pkcs8.workspace = true
|
||||
iroh.workspace = true
|
||||
iroh-blobs.workspace = true
|
||||
iroh-docs.workspace = true
|
||||
iroh-gossip.workspace = true
|
||||
rand.workspace = true
|
||||
iroh-mdns-address-lookup.workspace = true
|
||||
serde.workspace = true
|
||||
thiserror.workspace = true
|
||||
tokio.workspace = true
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ pub const ALPN_DOCUMENT: &[u8] = b"/geth/document/1";
|
|||
pub const ALPN_SSH_PROXY: &[u8] = b"/geth/ssh-proxy/1";
|
||||
pub const ALPN_OVERLAY: &[u8] = b"/geth/overlay/1";
|
||||
|
||||
pub const IROH_VERSION: &str = "0.95.1";
|
||||
pub const IROH_BLOBS_VERSION: &str = "0.97.0";
|
||||
pub const IROH_DOCS_VERSION: &str = "0.95.0";
|
||||
pub const IROH_GOSSIP_VERSION: &str = "0.95.0";
|
||||
pub const IROH_VERSION: &str = "1.0.0";
|
||||
pub const IROH_BLOBS_VERSION: &str = "0.103.0";
|
||||
pub const IROH_DOCS_VERSION: &str = "0.101.0";
|
||||
pub const IROH_GOSSIP_VERSION: &str = "0.101.0";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct GethIrohConfig {
|
||||
|
|
@ -348,20 +348,20 @@ fn is_loopback_socket_addr(addr: &str) -> bool {
|
|||
|
||||
pub async fn start_endpoint(config: &GethIrohConfig) -> Result<GethIrohEndpoint, IrohError> {
|
||||
let secret_key = load_or_create_secret_key(&config.secret_key_path)?;
|
||||
let mut builder = iroh::Endpoint::builder()
|
||||
let mut builder = iroh::Endpoint::builder(iroh::endpoint::presets::N0)
|
||||
.secret_key(secret_key)
|
||||
.relay_mode(config.relay_mode.to_iroh()?)
|
||||
.alpns(config.alpns.clone());
|
||||
|
||||
if config.local_discovery {
|
||||
builder = builder.discovery(iroh::discovery::mdns::MdnsDiscovery::builder());
|
||||
builder = builder.address_lookup(iroh_mdns_address_lookup::MdnsAddressLookup::builder());
|
||||
}
|
||||
|
||||
if let Some(bind_ipv4) = config.bind_ipv4 {
|
||||
builder = builder.bind_addr_v4(bind_ipv4);
|
||||
builder = builder.bind_addr(bind_ipv4)?;
|
||||
}
|
||||
if let Some(bind_ipv6) = config.bind_ipv6 {
|
||||
builder = builder.bind_addr_v6(bind_ipv6);
|
||||
builder = builder.bind_addr(bind_ipv6)?;
|
||||
}
|
||||
|
||||
let endpoint = builder.bind().await.map_err(IrohError::from)?;
|
||||
|
|
@ -391,7 +391,7 @@ pub fn load_or_create_secret_key(path: &Path) -> Result<iroh::SecretKey, IrohErr
|
|||
if let Some(parent) = path.parent() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
let secret_key = iroh::SecretKey::generate(&mut rand::rng());
|
||||
let secret_key = iroh::SecretKey::generate();
|
||||
let tmp = path.with_extension("tmp");
|
||||
std::fs::write(&tmp, hex::encode(secret_key.to_bytes()))?;
|
||||
std::fs::rename(tmp, path)?;
|
||||
|
|
@ -444,6 +444,8 @@ pub enum IrohError {
|
|||
InvalidSecretKeyLength,
|
||||
#[error("invalid iroh relay URL `{url}`: {message}")]
|
||||
InvalidRelayUrl { url: String, message: String },
|
||||
#[error("invalid iroh bind address: {0}")]
|
||||
InvalidBindAddr(iroh::endpoint::InvalidSocketAddr),
|
||||
#[error("failed to bind iroh endpoint: {0}")]
|
||||
Bind(Box<iroh::endpoint::BindError>),
|
||||
#[error("timed out waiting for iroh node address")]
|
||||
|
|
@ -460,6 +462,12 @@ pub enum RouterError {
|
|||
UnknownAlpn { alpn: String },
|
||||
}
|
||||
|
||||
impl From<iroh::endpoint::InvalidSocketAddr> for IrohError {
|
||||
fn from(error: iroh::endpoint::InvalidSocketAddr) -> Self {
|
||||
Self::InvalidBindAddr(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<iroh::endpoint::BindError> for IrohError {
|
||||
fn from(error: iroh::endpoint::BindError) -> Self {
|
||||
Self::Bind(Box::new(error))
|
||||
|
|
|
|||
Loading…
Reference in a new issue