-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request_id
attribute for generic response
#42
base: master
Are you sure you want to change the base?
Changes from all commits
6dd0064
e9bd60d
4d6f489
16e6aaa
17c42f9
64d6065
d73b05b
64ef75e
a99321a
a08957b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,9 @@ pub struct RegisterFailure { | |
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct ServiceConnectionAccepted; | ||
pub struct ServiceConnectionAccepted { | ||
pub request_id: Option<Uuid>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct MessageSendSuccess { | ||
|
@@ -553,6 +555,7 @@ pub struct FileTransferRequestNotification { | |
pub cid: u64, | ||
pub peer_cid: u64, | ||
pub metadata: VirtualObjectMetadata, | ||
pub request_id: Option<Uuid>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
|
@@ -570,6 +573,11 @@ pub struct FileTransferTickNotification { | |
pub cid: u64, | ||
pub peer_cid: Option<u64>, | ||
pub status: ObjectTransferStatus, | ||
pub request_id: Option<Uuid>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potentially the same as with the other struct. Take a look at the clippy workflow to see the test it shows an error for. |
||
} | ||
|
||
pub trait ResponseId { | ||
fn response_id() -> String; | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, IsError, IsNotification)] | ||
|
@@ -653,6 +661,102 @@ pub enum InternalServiceResponse { | |
ListRegisteredPeersFailure(ListRegisteredPeersFailure), | ||
} | ||
|
||
/// Shortcut for getting `.request_id` attribute on all members | ||
macro_rules! match_request_id { | ||
($val:expr, $($variant:ident),+) => { | ||
match $val { | ||
$( | ||
InternalServiceResponse::$variant(x) => x.request_id, | ||
)+ | ||
} | ||
} | ||
} | ||
|
||
impl InternalServiceResponse { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could use a proc macro to simplify this. Take a look at the answer on this. |
||
pub fn request_id(&self) -> Option<Uuid> { | ||
match_request_id!( | ||
self, | ||
ConnectSuccess, | ||
ConnectFailure, | ||
RegisterSuccess, | ||
RegisterFailure, | ||
ServiceConnectionAccepted, | ||
MessageSendSuccess, | ||
MessageSendFailure, | ||
MessageNotification, | ||
DisconnectNotification, | ||
DisconnectFailure, | ||
SendFileRequestSuccess, | ||
SendFileRequestFailure, | ||
FileTransferRequestNotification, | ||
FileTransferStatusNotification, | ||
FileTransferTickNotification, | ||
DownloadFileSuccess, | ||
DownloadFileFailure, | ||
DeleteVirtualFileSuccess, | ||
DeleteVirtualFileFailure, | ||
PeerConnectSuccess, | ||
PeerConnectFailure, | ||
PeerConnectNotification, | ||
PeerRegisterNotification, | ||
PeerDisconnectSuccess, | ||
PeerDisconnectFailure, | ||
PeerRegisterSuccess, | ||
PeerRegisterFailure, | ||
GroupChannelCreateSuccess, | ||
GroupChannelCreateFailure, | ||
GroupBroadcastHandleFailure, | ||
GroupCreateSuccess, | ||
GroupCreateFailure, | ||
GroupLeaveSuccess, | ||
GroupLeaveFailure, | ||
GroupLeaveNotification, | ||
GroupEndSuccess, | ||
GroupEndFailure, | ||
GroupEndNotification, | ||
GroupMessageNotification, | ||
GroupMessageResponse, | ||
GroupMessageSuccess, | ||
GroupMessageFailure, | ||
GroupInviteNotification, | ||
GroupInviteSuccess, | ||
GroupInviteFailure, | ||
GroupRespondRequestSuccess, | ||
GroupRespondRequestFailure, | ||
GroupMembershipResponse, | ||
GroupRequestJoinPendingNotification, | ||
GroupDisconnectNotification, | ||
GroupKickSuccess, | ||
GroupKickFailure, | ||
GroupListGroupsSuccess, | ||
GroupListGroupsFailure, | ||
GroupListGroupsResponse, | ||
GroupJoinRequestNotification, | ||
GroupRequestJoinAcceptResponse, | ||
GroupRequestJoinDeclineResponse, | ||
GroupRequestJoinSuccess, | ||
GroupRequestJoinFailure, | ||
GroupMemberStateChangeNotification, | ||
LocalDBGetKVSuccess, | ||
LocalDBGetKVFailure, | ||
LocalDBSetKVSuccess, | ||
LocalDBSetKVFailure, | ||
LocalDBDeleteKVSuccess, | ||
LocalDBDeleteKVFailure, | ||
LocalDBGetAllKVSuccess, | ||
LocalDBGetAllKVFailure, | ||
LocalDBClearAllKVSuccess, | ||
LocalDBClearAllKVFailure, | ||
GetSessionsResponse, | ||
GetAccountInformationResponse, | ||
ListAllPeersResponse, | ||
ListAllPeersFailure, | ||
ListRegisteredPeersResponse, | ||
ListRegisteredPeersFailure | ||
) | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub enum InternalServiceRequest { | ||
Connect { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,9 @@ pub trait IOInterfaceExt: IOInterface { | |
tokio::task::spawn(async move { | ||
let write_task = async move { | ||
let response = | ||
InternalServiceResponse::ServiceConnectionAccepted(ServiceConnectionAccepted); | ||
InternalServiceResponse::ServiceConnectionAccepted(ServiceConnectionAccepted { | ||
request_id: None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, this request_id matches that of the initiated connection so we know which request this belongs to |
||
}); | ||
|
||
if let Err(err) = sink_send_payload::<Self>(response, &mut sink).await { | ||
error!(target: "citadel", "Failed to send to client: {err:?}"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,6 +368,7 @@ fn spawn_tick_updater( | |
cid: implicated_cid, | ||
peer_cid, | ||
status: status_message, | ||
request_id: None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We would ideally want to make this the same as the request_id as the initial file transfer request that initiated this. |
||
}, | ||
); | ||
match entry.send(message.clone()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ pub async fn handle<T: IOInterface>( | |
cid: implicated_cid, | ||
peer_cid, | ||
metadata, | ||
request_id: None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
}, | ||
); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there are a few occurrences in tests that didn't get updated to reflect the addition of request_id