-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#78) Network viewer - New API JSON-RPC getStatus
- Loading branch information
1 parent
22c715f
commit cd75919
Showing
21 changed files
with
1,135 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
How to modify the API? | ||
|
||
(1) def_methods.rs : defines all the API methods and responses. | ||
|
||
(2) Implement in one of these files: | ||
- impl_general_api.rs : General interface to Suibase. | ||
- impl_proxy_api.rs : Specific to the proxy/multi-link feature. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_with::serde_as; | ||
|
||
use crate::shared_types::UuidST; | ||
|
||
#[serde_as] | ||
#[derive(Clone, Default, Debug, JsonSchema, Serialize, Deserialize, PartialEq, Eq)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Header { | ||
// Header fields | ||
// ============= | ||
// - method: | ||
// A string echoing the method of the request. | ||
// | ||
// - key: | ||
// A string echoing one of the "key" parameter of the request (e.g. the workdir requested). | ||
// This field is optional and its interpretation depends on the method. | ||
// | ||
// - data_uuid: | ||
// A sortable hex 64 bytes (UUID v7). Increments with every data modification. | ||
// | ||
// - method_uuid: | ||
// A hex 64 bytes (UUID v4) that changes every time a new generated data_uuid is unexpectedly | ||
// lower than the previous one for this method (e.g. system time went backward) or the PID of | ||
// the process changes. Complements data_uuid for added reliability on various edge cases. | ||
// | ||
pub method: String, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub method_uuid: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub data_uuid: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub key: Option<String>, | ||
} | ||
|
||
// Class to conveniently add UUID versioning to any data structure. | ||
// | ||
// That versioning can be used to initialize the method_uuid and data_uuid fields of a Header | ||
|
||
// TODO Implement PartialEq and PartialOrd to use only the uuid field for comparison. | ||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)] | ||
pub struct Versioned<T> { | ||
uuid: UuidST, | ||
data: T, | ||
} | ||
|
||
impl<T: Clone + PartialEq> Versioned<T> { | ||
pub fn new(data: T) -> Self { | ||
Self { | ||
uuid: UuidST::new(), | ||
data, | ||
} | ||
} | ||
|
||
// if data is different, then increment version, else no-op. | ||
pub fn set(&mut self, new_data: &T) -> UuidST { | ||
if new_data != &self.data { | ||
self.data = new_data.clone(); | ||
self.uuid.increment(); | ||
} | ||
self.uuid.clone() | ||
} | ||
|
||
// readonly access | ||
pub fn get_data(&self) -> &T { | ||
&self.data | ||
} | ||
|
||
pub fn get_uuid(&self) -> &UuidST { | ||
&self.uuid | ||
} | ||
|
||
// Write version into a Header structure. | ||
pub fn init_header_uuids(&self, header: &mut Header) { | ||
let (method_uuid, data_uuid) = self.uuid.get(); | ||
header.method_uuid = Some(method_uuid.to_string()); | ||
header.data_uuid = Some(data_uuid.to_string()); | ||
} | ||
} |
Oops, something went wrong.