Proof of Concept
This commit is contained in:
commit
e4fe60c06e
26 changed files with 4604 additions and 0 deletions
51
src/comm/types.rs
Normal file
51
src/comm/types.rs
Normal file
|
@ -0,0 +1,51 @@
|
|||
use anyhow::bail;
|
||||
use i2p::net::I2pSocketAddr;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::state::types::PeerId;
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Peer {
|
||||
id: PeerId,
|
||||
name: String,
|
||||
family: Vec<PeerId>,
|
||||
}
|
||||
|
||||
impl Peer {
|
||||
pub fn new(id: PeerId, name: String) -> Self {
|
||||
Peer {id: id, name: name, family: vec![]}
|
||||
}
|
||||
|
||||
pub fn addr(&self) -> I2pSocketAddr {
|
||||
self.id.addr()
|
||||
}
|
||||
|
||||
pub fn id(&self) -> PeerId {
|
||||
self.id.clone()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for Peer {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
match serde_json::from_str(value) {
|
||||
Ok(p) => Ok(p),
|
||||
Err(e) => bail!(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for Peer {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> {
|
||||
Self::try_from(value.as_str())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue