Skip to content

Commit

Permalink
broker: add signer_type field to channel_request
Browse files Browse the repository at this point in the history
make it optional just like the cid field.
  • Loading branch information
irriden committed Sep 2, 2023
1 parent 3026bf5 commit eb46131
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion broker/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub struct ChannelRequest {
pub message: Vec<u8>,
pub reply_tx: oneshot::Sender<ChannelReply>,
pub cid: Option<String>, // if it exists, only try the one client
pub signer_type: Option<SignerType>, // if it exists, only try clients of these types
}
impl ChannelRequest {
pub fn new(topic: &str, message: Vec<u8>) -> (Self, oneshot::Receiver<ChannelReply>) {
Expand All @@ -61,6 +62,7 @@ impl ChannelRequest {
message,
reply_tx,
cid: None,
signer_type: None,
};
(cr, reply_rx)
}
Expand All @@ -75,6 +77,7 @@ impl ChannelRequest {
message,
reply_tx,
cid: None,
signer_type: None,
};
let _ = sender.send(req).await;
let reply = reply_rx.await?;
Expand All @@ -92,13 +95,14 @@ impl ChannelRequest {
message,
reply_tx,
cid: Some(cid.to_string()),
signer_type: None,
};
let _ = sender.send(req).await;
let reply = reply_rx.await?;
Ok(reply.reply)
}
pub fn for_cid(&mut self, cid: &str) {
self.cid = Some(cid.to_string())
self.cid = Some(cid.to_string());
}
pub fn new_for(
cid: &str,
Expand All @@ -109,6 +113,18 @@ impl ChannelRequest {
cr.for_cid(cid);
(cr, reply_rx)
}
pub fn for_type(&mut self, signer_type: SignerType) {
self.signer_type = Some(signer_type);
}
pub fn new_for_type(
signer_type: SignerType,
topic: &str,
message: Vec<u8>,
) -> (Self, oneshot::Receiver<ChannelReply>) {
let (mut cr, reply_rx) = ChannelRequest::new(topic, message);
cr.for_type(signer_type);
(cr, reply_rx)
}
}

// mpsc reply
Expand Down

0 comments on commit eb46131

Please sign in to comment.