-
Notifications
You must be signed in to change notification settings - Fork 5
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
refactor: changes done while porting iroh-willow #45
Conversation
data-model/src/entry.rs
Outdated
@@ -13,7 +13,7 @@ pub type Timestamp = u64; | |||
|
|||
/// The metadata associated with each Payload. | |||
/// [Definition](https://willowprotocol.org/specs/data-model/index.html#Entry). | |||
#[derive(Debug, PartialEq, Eq, Clone)] | |||
#[derive(Debug, PartialEq, Eq, Clone, Ord, PartialOrd)] |
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.
I think the derived Ord
should work as expected, as the derive will sort fields in definition order, which is the same order I deemed logical in my impl before.
I mostly need this to stick entries into a BTreeSet or such, to have predictable ordering.
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.
I feel like the impl of PartialOrd and Ord should have a doc comment stating that the order is not according to the spec but simply an arbitrary choice.
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.
Added a comment that details the sort order, and swapped the field ordering on the struct so that payload_digest comes before payload_length, so that the derived Ord
matches the "is newer" relation from the willow spec (for entries where namespace, subspace and path are equal).
@@ -16,11 +16,16 @@ pub struct AreaOfInterest<const MCL: usize, const MCC: usize, const MPL: usize, | |||
impl<const MCL: usize, const MCC: usize, const MPL: usize, S: SubspaceId> | |||
AreaOfInterest<MCL, MCC, MPL, S> | |||
{ | |||
/// Creates a new [`AreaOfInterest`]. | |||
pub fn new(area: Area<MCL, MCC, MPL, S>, max_count: u64, max_size: u64) -> Self { |
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's just easier to type than initializing with let aoi = AreaOfInterest { area, max_count, max_size }
and leads to less line breaks.
/// Return the intersection of this [`AreaOfInterest`] with another. | ||
/// [Definition](https://willowprotocol.org/specs/grouping-entries/index.html#aoi_intersection). | ||
pub fn intersection( | ||
&self, | ||
other: AreaOfInterest<MCL, MCC, MPL, S>, | ||
other: &AreaOfInterest<MCL, MCC, MPL, S>, |
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.
Doesn't consume other
so should take by ref to not need cloning at call site
@@ -6,7 +6,7 @@ use arbitrary::{Arbitrary, Error as ArbitraryError}; | |||
|
|||
use crate::path::Path; | |||
|
|||
#[derive(Debug, Hash, PartialEq, Eq)] | |||
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] |
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.
Those can easily be copy
@@ -164,6 +152,11 @@ impl<T> Range<T> | |||
where | |||
T: Ord + Clone, | |||
{ | |||
/// Construct a range. | |||
pub fn new(start: T, end: RangeEnd<T>) -> Self { |
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.
Again, a constructor for when you have a RangeEnd
available (eg from another range) saves line breaks at callsite
@@ -157,8 +157,8 @@ where | |||
/// The kind of access this capability grants. | |||
/// | |||
/// [Definition](https://willowprotocol.org/specs/meadowcap/index.html#communal_cap_mode) | |||
pub fn access_mode(&self) -> &AccessMode { | |||
&self.access_mode | |||
pub fn access_mode(&self) -> AccessMode { |
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.
Copy types should be returned by value
namespace_key: NamespacePublicKey, | ||
namespace_secret: NamespaceSecret, | ||
namespace_secret: &NamespaceSecret, |
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.
- No need for this to be async.
NamespaceSecret
isn't consumed, so take by ref to not have to clone at call site
@@ -251,7 +251,7 @@ where | |||
/// Return a new [`McAuthorisationToken`], or an error if the resulting signature was not for the capability's receiver. | |||
pub fn authorisation_token<UserSecret, PD>( | |||
&self, | |||
entry: Entry<MCL, MCC, MPL, NamespacePublicKey, UserPublicKey, PD>, | |||
entry: &Entry<MCL, MCC, MPL, NamespacePublicKey, UserPublicKey, PD>, |
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.
Entry isn't consumed so take ref to avoid clone at call site
@@ -69,9 +69,9 @@ where | |||
UserSignature: Encodable + Clone, | |||
{ | |||
/// Generate a new [`McSubspaceCapability`] for a given user, or return an error if the given namespace secret is incorrect. | |||
pub fn new<const MCL: usize, const MCC: usize, const MPL: usize, NamespaceSecret>( | |||
pub fn new<NamespaceSecret>( |
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.
the const generics weren't used
pub Entry<MCL, MCC, MPL, N, S, PD>, | ||
pub AT, | ||
Entry<MCL, MCC, MPL, N, S, PD>, | ||
AT, |
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.
I think the fields should not be pub: If this type is intended to symbolize an entry+token pair where the authorisation was checked (which the new
function indicates, and which is also how the term is used in the willow spec) then I think the fields should be private, otherwise AuthorisedEntry(some_entry, some_token)
is a too-easy-to-get-wrong constructor for an unchecked AuthorisedEntry.
Thank you. I agree with |
…gth to newer relation from spec
@AljoschaMeyer wrote here:
Right! I changed towards a manual impl of |
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.
Thank you for this roundup!
This PR contains changes I made to willow-rs while porting iroh-willow to use willow-rs.
The changes are mostly small and not all related to each other. They were mostly done by doing jump to definition from iroh-willow when touching willow-rs parts that didn't fit in well yet.
I will add review comments in the diff to explain the motivation.
My idea was to submit this here, let you review it, and if anything warrants further discussion, I will separate it out into its own PR, to keep only uncontroversial things in here that can easily be merged.
If you prefer to split this up right away, let me know.