Improved PeerId::from(I2pSocketAddr) function
This commit is contained in:
parent
9bc2db2b24
commit
51682c04b1
1 changed files with 7 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Error};
|
use anyhow::{anyhow, Error};
|
||||||
use i2p::net::{I2pAddr, I2pSocketAddr, ToI2pSocketAddrs};
|
use i2p::net::{I2pAddr, I2pSocketAddr};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -52,7 +52,11 @@ impl From<PeerId> for I2pSocketAddr {
|
||||||
|
|
||||||
impl From<I2pSocketAddr> for PeerId {
|
impl From<I2pSocketAddr> for PeerId {
|
||||||
fn from(value: I2pSocketAddr) -> Self {
|
fn from(value: I2pSocketAddr) -> Self {
|
||||||
PeerId { addr: value }
|
Self::try_from_b32(&value.dest().string(), Some(value.port())).unwrap_or(
|
||||||
|
Self::try_from_dest(&value.dest().string(), Some(value.port())).expect(&format!(
|
||||||
|
"I2pSocketAddr was neither in b32 nor in b64 format: {value:?}"
|
||||||
|
)),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue