Skip to content

Commit

Permalink
Prepare for verifiable variant of lamport mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
sgdxbc committed Apr 18, 2024
1 parent b6fa55a commit 895ad25
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/bin/boson_mutex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub async fn untrusted_session(
},
Once(dispatch_session.sender()),
)?));
let mut processor = Blanket(Unify(Processor::new(
let mut processor = Blanket(Unify(Processor::<_, _, _>::new(
id,
config.addrs.len(),
|id| (0u32, id),
Expand Down Expand Up @@ -176,7 +176,7 @@ pub async fn replicated_session(
num_faulty,
)));
let mut queue = Blanket(Unify(Queue::new(Sender::from(client_session.sender()))));
let mut processor = Blanket(Unify(Processor::new(
let mut processor = Blanket(Unify(Processor::<_, _, _>::new(
id,
num_replica,
|_| 0u32,
Expand Down Expand Up @@ -263,7 +263,7 @@ pub async fn quorum_session(
},
Once(dispatch_session.sender()),
)?));
let mut processor = Blanket(Unify(Processor::new(
let mut processor = Blanket(Unify(Processor::<_, _, _, true>::new(
id,
config.addrs.len(),
|_| QuorumClock::default(),
Expand Down
31 changes: 22 additions & 9 deletions src/lamport_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ pub enum Message {
Release(u8),
}

pub struct Processor<CN, U, C> {
// `V` for verifiable
pub struct Processor<CN, U, C, const V: bool = false> {
id: u8,
latests: Vec<C>,
requests: Vec<(C, u8)>,
Expand All @@ -251,7 +252,7 @@ pub struct Processor<CN, U, C> {
upcall: U,
}

impl<CN, U, C> Processor<CN, U, C> {
impl<CN, U, C, const V: bool> Processor<CN, U, C, V> {
pub fn new(
id: u8,
num_processor: usize,
Expand Down Expand Up @@ -281,7 +282,9 @@ pub mod events {
pub trait Net: SendMessage<u8, Message> + SendMessage<All, Message> {}
impl<T: SendMessage<u8, Message> + SendMessage<All, Message>> Net for T {}

impl<CN: SendMessage<All, Message>, U, C> OnEvent<events::Request> for Processor<CN, U, C> {
impl<CN: SendMessage<All, Message>, U, C, const V: bool> OnEvent<events::Request>
for Processor<CN, U, C, V>
{
fn on_event(
&mut self,
events::Request: events::Request,
Expand All @@ -295,8 +298,12 @@ impl<CN: SendMessage<All, Message>, U, C> OnEvent<events::Request> for Processor
}
}

impl<CN: SendMessage<u8, Message>, U: SendEvent<events::RequestOk>, C: Clock>
OnEvent<Recv<Clocked<Message, C>>> for Processor<CN, U, C>
impl<
CN: SendMessage<u8, Message> + SendMessage<All, Message>,
U: SendEvent<events::RequestOk>,
C: Clock,
const V: bool,
> OnEvent<Recv<Clocked<Message, C>>> for Processor<CN, U, C, V>
{
fn on_event(
&mut self,
Expand All @@ -320,7 +327,11 @@ impl<CN: SendMessage<u8, Message>, U: SendEvent<events::RequestOk>, C: Clock>
{
self.requests.insert(index, (message.clock, id))
};
self.causal_net.send(id, Message::RequestOk(self.id))?;
if V {
self.causal_net.send(All, Message::RequestOk(self.id))?;
} else {
self.causal_net.send(id, Message::RequestOk(self.id))?;
}
}
Message::RequestOk(_) => {}
Message::Release(_) => {
Expand All @@ -343,7 +354,7 @@ impl<CN: SendMessage<u8, Message>, U: SendEvent<events::RequestOk>, C: Clock>
}
}

impl<CN, U: SendEvent<events::RequestOk>, C: Clock> Processor<CN, U, C> {
impl<CN, U: SendEvent<events::RequestOk>, C: Clock, const V: bool> Processor<CN, U, C, V> {
fn check_requested(&mut self) -> anyhow::Result<()> {
// self Request, requesting == true
// all others Request are Release, while loopback Request still not received
Expand All @@ -366,7 +377,9 @@ impl<CN, U: SendEvent<events::RequestOk>, C: Clock> Processor<CN, U, C> {
}
}

impl<CN: SendMessage<All, Message>, U, C> OnEvent<events::Release> for Processor<CN, U, C> {
impl<CN: SendMessage<All, Message>, U, C, const V: bool> OnEvent<events::Release>
for Processor<CN, U, C, V>
{
fn on_event(
&mut self,
events::Release: events::Release,
Expand All @@ -380,7 +393,7 @@ impl<CN: SendMessage<All, Message>, U, C> OnEvent<events::Release> for Processor
}
}

impl<CN, U, C> OnTimer for Processor<CN, U, C> {
impl<CN, U, C, const V: bool> OnTimer for Processor<CN, U, C, V> {
fn on_timer(&mut self, _: crate::event::TimerId, _: &mut impl Timer) -> anyhow::Result<()> {
unreachable!()
}
Expand Down

0 comments on commit 895ad25

Please sign in to comment.