Skip to content

Commit

Permalink
Two way op flow (#41)
Browse files Browse the repository at this point in the history
* chore(api): Split `MetaOp` to remove timestamp and add `StoredOp` type

* chore(memory): Implement storage of `Kitsune2MemoryOp` which can be converted to a `StoredOp`

* Integrate changed op types into tests

* Update crates/memory/src/op_store.rs

Co-authored-by: David Braden <[email protected]>

* Don't need ordering

* Simplify test

* Fixup after rebase

---------

Co-authored-by: David Braden <[email protected]>
  • Loading branch information
ThetaSinner and neonphog authored Dec 4, 2024
1 parent e0e44ff commit 0548a4c
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 135 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 18 additions & 7 deletions crates/api/src/op_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,36 @@ pub struct MetaOp {
/// The id of the op.
pub op_id: OpId,

/// The actual op data.
pub op_data: Vec<u8>,
}

/// An op that has been stored by the Kitsune host.
///
/// This is the basic unit of data that the host is expected to store. Whether that storage is
/// persistent may depend on the use-case. While Kitsune is holding references by hash, the host
/// is expected to store the actual data.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct StoredOp {
/// The id of the op.
pub op_id: OpId,

/// The creation timestamp of the op.
///
/// This must be the same for everyone who sees this op.
///
/// The host must reject the op if the timestamp does not agree with any timestamps inside the
/// op data.
/// Note that this means any op implementation must include a consistent timestamp in the op
/// data so that it can be provided back to Kitsune.
pub timestamp: Timestamp,

/// The actual op data.
pub op_data: Vec<u8>,
}

impl Ord for MetaOp {
impl Ord for StoredOp {
fn cmp(&self, other: &Self) -> Ordering {
(&self.timestamp, &self.op_id).cmp(&(&other.timestamp, &other.op_id))
}
}

impl PartialOrd for MetaOp {
impl PartialOrd for StoredOp {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
Expand Down
Loading

0 comments on commit 0548a4c

Please sign in to comment.