Basic family join/leave implementation, tests not fully working
This commit is contained in:
parent
ec0a55b286
commit
636aff64b9
14 changed files with 429 additions and 151 deletions
|
@ -1,6 +1,6 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::{ElementContent, ElementId, MessageId, PotId};
|
||||
use crate::types::{ElementContent, ElementId, Family, FamilyId, MessageId, PotId};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Message {
|
||||
|
@ -19,6 +19,11 @@ pub enum MessageContent {
|
|||
Hello {
|
||||
peer_name: String,
|
||||
},
|
||||
JoinFamily,
|
||||
AddedToFamily {
|
||||
family: Family,
|
||||
},
|
||||
LeaveFamily,
|
||||
CreateElement {
|
||||
id: ElementId,
|
||||
content: ElementContent,
|
||||
|
@ -34,7 +39,7 @@ pub enum MessageContent {
|
|||
AddPot {
|
||||
id: PotId,
|
||||
app_type: String,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
use std::hash::Hash;
|
||||
|
||||
use anyhow::{anyhow, bail};
|
||||
use i2p::net::{I2pAddr, I2pSocketAddr, ToI2pSocketAddrs};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct PeerId {
|
||||
i2p_dest: I2pSocketAddr,
|
||||
i2p_b32: Option<I2pAddr>,
|
||||
|
@ -27,6 +29,14 @@ impl PeerId {
|
|||
}
|
||||
}
|
||||
|
||||
// The identity of the PeerId only depends on the i2p_dest (which is unique),
|
||||
// and not on whether the b32 address has been computed before
|
||||
impl Hash for PeerId {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.i2p_dest.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for PeerId {
|
||||
fn to_string(&self) -> String {
|
||||
self.i2p_dest.to_string()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue