Skip to content

Commit a61b189

Browse files
Various manager functions + Documentation + Roles
Interface and enums for MTP manager functions Queue access types for for the server
1 parent 836c011 commit a61b189

File tree

1 file changed

+84
-14
lines changed

1 file changed

+84
-14
lines changed

net/src/protocol/interface.rs

Lines changed: 84 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
use std::{fmt::Error, net::SocketAddr};
1+
use std::net::SocketAddr;
22
use std::time::SystemTime;
33

44
use super::{
55
MTPManagerActions,
66
MTPHeaders,
77
MTPStorage,
8-
MTPMessage
8+
MTPMessage,
9+
10+
error::ProtocolError
911
};
1012

13+
1114
/// [`MessageTransferProtocol`] defines the main interface for a message transfer protocol system.
1215
/// It includes methods for subscribing to queues, unsubscribing, publishing messages,
1316
/// pulling messages, pinging the server, and managing actions.
@@ -24,13 +27,13 @@ pub trait MessageTransferProtocol {
2427
///
2528
/// # Returns
2629
/// A result containing a response or an error.
27-
fn subscribe(&self, queue: String) -> Result<Self::Response, Error>;
30+
fn subscribe(&self, queue: String) -> Result<Self::Response, ProtocolError>;
2831

2932
/// Unsubscribes from the queue with the passed identifier.
3033
///
3134
/// # Returns
3235
/// A result containing a response or an error.
33-
fn unsubscribe(&self, queue: String) -> Result<Self::Response, Error>;
36+
fn unsubscribe(&self, queue: String) -> Result<Self::Response, ProtocolError>;
3437

3538
/// Publishes a message to the queue.
3639
///
@@ -39,19 +42,19 @@ pub trait MessageTransferProtocol {
3942
///
4043
/// # Returns
4144
/// A result containing a response or an error.
42-
fn publish(&self, message: Self::Message) -> Result<Self::Response, Error>;
45+
fn publish(&self, message: Self::Message) -> Result<Self::Response, ProtocolError>;
4346

4447
/// Pulls a message from the queue.
4548
///
4649
/// # Returns
4750
/// A result containing a response or an error.
48-
fn pull(&self) -> Result<Self::Response, Error>;
51+
fn pull(&self) -> Result<Self::Response, ProtocolError>;
4952

5053
/// Pings the server to check status
5154
///
5255
/// # Returns
5356
/// A result containing a response or an error.
54-
fn ping(&self) -> Result<Self::Response, Error>;
57+
fn ping(&self) -> Result<Self::Response, ProtocolError>;
5558

5659
/// Manages the protocol actions.
5760
///
@@ -60,7 +63,7 @@ pub trait MessageTransferProtocol {
6063
///
6164
/// # Returns
6265
/// A result containing a response or an error.
63-
fn manage(&self, actions: MTPManagerActions) -> Result<Self::Response, Error>;
66+
fn manage(&self, actions: MTPManagerActions) -> Result<Self::Response, ProtocolError>;
6467
}
6568

6669
/// [`MessageTransferProtocolResponse`] represents the response returned by methods of the [`MessageTransferProtocol`] trait.
@@ -283,7 +286,7 @@ pub enum MTPRequestType {
283286
/// `MTPStatusCode` represents the various status codes that can be returned in a protocol response.
284287
pub enum MTPStatusCode {
285288
Success0,
286-
Error1(Error)
289+
Error1(ProtocolError)
287290
}
288291

289292
/// `MTPHeaderUnit` represents individual units within the protocol's header.
@@ -389,7 +392,7 @@ pub enum MTPHeaderUnit {
389392
/// - Content format defined in the type [`ContentType`]
390393
Message {
391394
id: String,
392-
timestamp: SystemTime,
395+
timestamp: Option<SystemTime>,
393396
priority: MessagePriority,
394397
category: MessageCategory,
395398
content_type: ContentType,
@@ -402,6 +405,10 @@ pub enum MTPHeaderUnit {
402405
queue: String,
403406
to: MessagePublish,
404407
},
408+
409+
QueueCreation{
410+
411+
}
405412
}
406413

407414
/// `MTPAuth` represents different authentication methods that can be used within the protocol's header.
@@ -647,19 +654,47 @@ pub enum AuthSchemes {
647654
/// based on the `MTPManagerAction` variant, performing appropriate operations for each action.
648655
pub enum MTPManagerAction {
649656
/// Rename an existing resource specifically the queue in the which the moderator is operating
650-
Rename,
657+
Rename(String),
651658

652659
/// Authorize user requesting persmissions to the queue
653-
Authorize, // On user invites (private)
660+
Authorize(String), // On user invites (private)
654661

655662
/// Reject user requesting permissions to the queue
656663
Reject, // Access permission
657664

658665
/// Dispose an exising client from the queue
659-
Dispose, // Dispose of existing clients
666+
Dispose(String), // Dispose of existing clients
660667

661668
/// Modify the roles/permissions of existing client
662-
AccessorModify, // Change the permission of the access of the queue
669+
AccessorModify(QueueAccess), // Change the permission of the access of the queue
670+
}
671+
672+
/// [`QueueAccess`] defines an access of a client to a particular queue.
673+
///
674+
/// ## Variants
675+
///
676+
/// ### `Public`
677+
///
678+
/// A queue to be public. Anyone with the queue identifier can join the queue to receive messages
679+
/// This is the default queue accessor.
680+
///
681+
/// - **Usage**: A public queue to publish messages to all who join the queue wihtout needing to wait for authorization
682+
///
683+
/// /// ### `Private`
684+
///
685+
/// A queue to be private can only be joined if the admin authorizes the request.
686+
/// A client waits for admin aprroval and then joins the queue to receive published messages
687+
///
688+
/// - **Usage**: A private queue to restrict information acccess
689+
///
690+
/// ### `Protected`
691+
///
692+
/// A queue to be protected.
693+
///
694+
pub enum QueueAccess {
695+
Public,
696+
Private,
697+
Protected
663698
}
664699

665700
/// `MessagePriority` defines the priority levels of messages within the protocol.
@@ -901,6 +936,16 @@ pub enum ContentType {
901936
XML,
902937
}
903938

939+
/// [`QueueRoles`] for the queue
940+
/// Roles that are defined for each client in the queue
941+
pub enum QueueRoles {
942+
Moderator,
943+
Manager,
944+
Producer,
945+
Consumer,
946+
Couple
947+
}
948+
904949

905950

906951
/// `MessagePublish` defines the different ways a message can be published within the protocol.
@@ -1059,3 +1104,28 @@ impl Clone for MessagePublish{
10591104
}
10601105
}
10611106
}
1107+
1108+
/// Clone implementation for [MTPRequestType]
1109+
impl Clone for MTPRequestType{
1110+
fn clone(&self) -> Self {
1111+
match self {
1112+
Self::Subscribe => Self::Subscribe,
1113+
Self::Unsubscribe => Self::Unsubscribe,
1114+
Self::Publish => Self::Publish,
1115+
Self::Pull => Self::Pull,
1116+
Self::Ping => Self::Ping,
1117+
Self::Manage => Self::Manage,
1118+
}
1119+
}
1120+
}
1121+
1122+
/// Clone implementation for [QueueAccess]
1123+
impl Clone for QueueAccess{
1124+
fn clone(&self) -> Self {
1125+
match self {
1126+
Self::Public => Self::Public,
1127+
Self::Private => Self::Private,
1128+
Self::Protected => Self::Protected,
1129+
}
1130+
}
1131+
}

0 commit comments

Comments
 (0)