parent
4bf897278a
commit
ce7519225e
33 changed files with 2709 additions and 1084 deletions
|
@ -5,15 +5,15 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
use crate::types::PeerId;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
pub struct Peer {
|
||||
id: PeerId,
|
||||
name: String,
|
||||
name: Option<String>,
|
||||
family: Vec<PeerId>,
|
||||
}
|
||||
|
||||
impl Peer {
|
||||
pub fn new(id: PeerId, name: String) -> Self {
|
||||
pub fn new(id: PeerId, name: Option<String>) -> Self {
|
||||
Peer {
|
||||
id: id,
|
||||
name: name,
|
||||
|
@ -29,7 +29,7 @@ impl Peer {
|
|||
self.id.clone()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> String {
|
||||
pub fn name(&self) -> Option<String> {
|
||||
self.name.clone()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default, Ord, PartialOrd, PartialEq, Eq, Hash)]
|
||||
pub struct AppId(Uuid);
|
||||
|
||||
impl AppId {
|
||||
|
|
|
@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
use super::{ElementContent, ElementId, MessageId, PotId};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub struct Element {
|
||||
// Uuid identifying the element itself
|
||||
id: ElementId,
|
||||
|
@ -46,4 +46,10 @@ impl Element {
|
|||
pub fn pot(&self) -> &Option<PotId> {
|
||||
&self.pot
|
||||
}
|
||||
pub fn latest_message(&self) -> &Option<MessageId> {
|
||||
&self.latest_message
|
||||
}
|
||||
pub fn local_changes(&self) -> bool {
|
||||
self.local_changes
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||
pub struct ElementId(Uuid);
|
||||
impl ElementId {
|
||||
pub fn new() -> Self {
|
||||
ElementId(Uuid::new_v4())
|
||||
}
|
||||
|
||||
pub fn bytes(&self) -> &[u8; 16] {
|
||||
self.0.as_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for ElementId {
|
||||
|
@ -27,3 +31,15 @@ impl TryFrom<&str> for ElementId {
|
|||
serde_json::from_str(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Uuid> for ElementId {
|
||||
fn from(value: Uuid) -> Self {
|
||||
ElementId {0: value}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[u8; 16]> for ElementId {
|
||||
fn from(value: [u8; 16]) -> Self {
|
||||
ElementId {0: Uuid::from_bytes(value)}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub struct MessageId(Uuid);
|
||||
|
||||
impl MessageId {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use anyhow::bail;
|
||||
use i2p::net::{I2pSocketAddr, ToI2pSocketAddrs};
|
||||
use i2p::net::{I2pAddr, I2pSocketAddr, ToI2pSocketAddrs};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct PeerId {
|
||||
i2p_addr: I2pSocketAddr,
|
||||
}
|
||||
|
@ -54,3 +54,11 @@ impl From<PeerId> for I2pSocketAddr {
|
|||
value.i2p_addr
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PeerId {
|
||||
fn default() -> Self {
|
||||
PeerId {
|
||||
i2p_addr: I2pSocketAddr::new(I2pAddr::new(""), 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
use super::PotId;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub struct Pot {
|
||||
pub id: PotId,
|
||||
pub app_type: String,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct PotId(Uuid);
|
||||
impl PotId {
|
||||
pub fn new() -> Self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue