Skip to content

Commit

Permalink
fixed the shutdown errors and other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed May 9, 2024
1 parent af2eb15 commit d13b26c
Show file tree
Hide file tree
Showing 13 changed files with 661 additions and 684 deletions.
302 changes: 144 additions & 158 deletions iroh-willow/src/net.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion iroh-willow/src/proto/grouping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl<T: Ord + PartialOrd> RangeEnd<T> {
}

/// A grouping of Entries that are among the newest in some store.
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Hash)]
pub struct AreaOfInterest {
/// To be included in this AreaOfInterest, an Entry must be included in the area.
pub area: Area,
Expand Down
12 changes: 12 additions & 0 deletions iroh-willow/src/proto/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,24 @@ pub struct NamespaceSignature(ed25519_dalek::Signature);

bytestring!(NamespaceSignature, SIGNATURE_LENGTH);

impl std::hash::Hash for NamespaceSignature {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.0.to_bytes().hash(state);
}
}

/// The signature obtained by signing a message with a [`UserSecretKey`].
#[derive(Serialize, Deserialize, Clone, From, PartialEq, Eq, Deref)]
pub struct UserSignature(ed25519_dalek::Signature);

bytestring!(UserSignature, SIGNATURE_LENGTH);

impl std::hash::Hash for UserSignature {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.0.to_bytes().hash(state);
}
}

/// [`UserPublicKey`] in bytes
#[derive(
Default,
Expand Down
8 changes: 4 additions & 4 deletions iroh-willow/src/proto/meadowcap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl From<(McCapability, UserSignature)> for MeadowcapAuthorisationToken {
}
}

#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, derive_more::From)]
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash, derive_more::From)]
pub enum McCapability {
Communal(CommunalCapability),
Owned(OwnedCapability),
Expand Down Expand Up @@ -158,14 +158,14 @@ impl McCapability {
}
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy, Eq, PartialEq)]
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Eq, PartialEq, Hash)]
pub enum AccessMode {
Read,
Write,
}

/// A capability that authorizes reads or writes in communal namespaces.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
pub struct CommunalCapability {
/// The kind of access this grants.
access_mode: AccessMode,
Expand Down Expand Up @@ -206,7 +206,7 @@ impl CommunalCapability {
}

/// A capability that authorizes reads or writes in owned namespaces.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
pub struct OwnedCapability {
/// The kind of access this grants.
access_mode: AccessMode,
Expand Down
4 changes: 2 additions & 2 deletions iroh-willow/src/proto/wgps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pub enum LogicalChannel {
impl LogicalChannel {
pub fn fmt_short(&self) -> &str {
match self {
LogicalChannel::Control => "C",
LogicalChannel::Reconciliation => "R",
LogicalChannel::Control => "Ctl",
LogicalChannel::Reconciliation => "Rec",
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions iroh-willow/src/proto/willow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub type NamespaceId = keys::NamespaceId;
/// A type for identifying subspaces.
pub type SubspaceId = keys::UserId;

/// The capability type needed to authorize writes.
pub type WriteCapability = McCapability;

/// A Timestamp is a 64-bit unsigned integer, that is, a natural number between zero (inclusive) and 2^64 - 1 (exclusive).
/// Timestamps are to be interpreted as a time in microseconds since the Unix epoch.
pub type Timestamp = u64;
Expand Down
31 changes: 26 additions & 5 deletions iroh-willow/src/session.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::{HashMap, HashSet};

use crate::proto::{grouping::AreaOfInterest, keys::UserSecretKey, wgps::ReadCapability};

pub mod coroutine;
Expand All @@ -9,23 +11,42 @@ mod util;
pub use self::error::Error;
pub use self::state::{SessionState, SharedSessionState};

/// To break symmetry, we refer to the peer that initiated the synchronisation session as Alfie,
/// and the other peer as Betty.
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum Role {
Betty,
/// The peer that initiated the synchronisation session.
Alfie,
/// The peer that accepted the synchronisation session.
Betty,
}

/// The bind scope for resources.
///
/// Resources are bound by either peer
#[derive(Copy, Clone, Debug)]
pub enum Scope {
/// Resources bound by ourselves.
Ours,
/// Resources bound by the other peer.
Theirs,
}

#[derive(Debug)]
pub struct SessionInit {
pub user_secret_key: UserSecretKey,
// TODO: allow multiple capabilities?
pub capability: ReadCapability,
// TODO: allow multiple areas of interest?
pub area_of_interest: AreaOfInterest,
pub interests: HashMap<ReadCapability, HashSet<AreaOfInterest>>,
}

impl SessionInit {
pub fn with_interest(
user_secret_key: UserSecretKey,
capability: ReadCapability,
area_of_interest: AreaOfInterest,
) -> Self {
Self {
user_secret_key,
interests: HashMap::from_iter([(capability, HashSet::from_iter([area_of_interest]))]),
}
}
}
Loading

0 comments on commit d13b26c

Please sign in to comment.