Skip to content

Commit cf415ee

Browse files
committed
fix: fixed ack sending, fixed TextFiles declaration
1 parent 9d2e0f7 commit cf415ee

2 files changed

Lines changed: 43 additions & 17 deletions

File tree

src/packet_processor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ pub trait Processor {
2121
match pkt.pack_type {
2222
PacketType::MsgFragment(fragment) => {
2323
let idx = fragment.fragment_index;
24+
let mut shr = pkt.routing_header.clone();
25+
shr.reverse();
26+
self.routing_handler().send_ack(shr, pkt.session_id, idx)?;
2427
if let Some(msg) = self.assembler().add_fragment(
2528
fragment,
2629
pkt.session_id,
2730
pkt.routing_header.hops[0],
2831
) {
29-
let mut shr = pkt.routing_header.clone();
30-
shr.reverse();
31-
self.routing_handler().send_ack(shr, pkt.session_id, idx)?;
3232
self.handle_msg(msg, pkt.routing_header.hops[0], pkt.session_id);
3333
}
3434
}

src/types.rs

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use uuid::Uuid;
1111

1212
pub type Bytes = Vec<u8>;
1313

14-
#[derive(Debug, Clone, Serialize, Deserialize)]
14+
#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq)]
1515
pub struct MediaReference {
1616
location: NodeId,
1717
pub id: Uuid
@@ -32,11 +32,19 @@ impl MediaReference {
3232
}
3333

3434
impl Display for MediaReference {
35-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3636
write!(f, "{}/{}", self.location, self.id.to_string())
3737
}
3838
}
3939

40+
impl PartialEq for MediaReference {
41+
fn eq(&self, other: &Self) -> bool {
42+
self.id == other.id
43+
}
44+
}
45+
46+
47+
4048
impl FromStr for MediaReference {
4149
type Err = anyhow::Error;
4250

@@ -52,16 +60,22 @@ impl FromStr for MediaReference {
5260
}
5361
}
5462

55-
#[derive(Debug, Clone, Serialize, Deserialize)]
56-
pub struct TextFile<'a>{
63+
#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq)]
64+
pub struct TextFile{
5765
id: Uuid,
5866
title: String,
59-
content: &'a str,
67+
content: String,
6068
media_refs: Option<Vec<MediaReference>>
6169
}
6270

63-
impl<'a> TextFile<'a> {
64-
pub fn new(title: String, content: &'a str, media_refs: Option<Vec<MediaReference>>) -> Self {
71+
impl PartialEq for TextFile {
72+
fn eq(&self, other: &Self) -> bool {
73+
self.id == other.id
74+
}
75+
}
76+
77+
impl TextFile {
78+
pub fn new(title: String, content: String, media_refs: Option<Vec<MediaReference>>) -> Self {
6579
Self {
6680
title,
6781
id: Uuid::new_v4(),
@@ -70,18 +84,29 @@ impl<'a> TextFile<'a> {
7084
}
7185
}
7286

73-
pub fn get_refs(&self) -> Option<Vec<MediaReference>> {
74-
self.media_refs.clone()
87+
pub fn get_refs(&self) -> Vec<MediaReference> {
88+
if let Some(vec) = &self.media_refs {
89+
return vec.to_vec()
90+
} else {
91+
vec![]
92+
}
7593
}
7694
}
7795

96+
7897
#[derive(Debug, Clone, Serialize, Deserialize)]
7998
pub struct MediaFile {
8099
id: Uuid,
81100
title: String,
82101
content: Vec<Bytes>,
83102
}
84103

104+
impl PartialEq for MediaFile {
105+
fn eq(&self, other: &Self) -> bool {
106+
self.id == other.id
107+
}
108+
}
109+
85110

86111
#[derive(Serialize, Deserialize, Debug)]
87112
#[serde(tag = "request_type")]
@@ -103,16 +128,16 @@ pub enum WebRequest {
103128
#[serde(tag = "response_type")]
104129
pub enum WebResponse {
105130
#[serde(rename = "server_type!")]
106-
ServerTypeResponse { server_type: String },
131+
ServerType { server_type: ServerType },
107132

108133
#[serde(rename = "files_list!")]
109-
TextFilesListResponse { files: Vec<String> },
134+
TextFilesList { files: Vec<String> },
110135

111136
#[serde(rename = "file!")]
112-
FileResponse { file_size: usize, file_data: Vec<u8> },
137+
TextFile { file_data: Vec<u8> },
113138

114139
#[serde(rename = "media!")]
115-
MediaResponse { media_data: Vec<u8> },
140+
MediaFile { media_data: Vec<u8> },
116141

117142
#[serde(rename = "error_requested_not_found!")]
118143
ErrorNotFound,
@@ -141,7 +166,7 @@ pub enum ChatRequest {
141166
#[serde(tag = "response_type")]
142167
pub enum ChatResponse {
143168
#[serde(rename = "server_type!")]
144-
ServerType { server_id: NodeId, server_type: ServerType },
169+
ServerType { server_type: ServerType },
145170

146171
#[serde(rename = "client_list!")]
147172
ClientList { list_of_client_ids: Vec<NodeId> },
@@ -226,5 +251,6 @@ pub enum ClientType {
226251
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
227252
pub enum ServerType {
228253
ChatServer,
254+
TextServer,
229255
MediaServer,
230256
}

0 commit comments

Comments
 (0)