Skip to content

Commit

Permalink
Merge pull request #352 from nervosnetwork/readd-multi-to-target-session
Browse files Browse the repository at this point in the history
feat: re-add multi to target session
  • Loading branch information
driftluo authored May 6, 2022
2 parents a62d8e9 + 1ee45ff commit fa50edc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 17 additions & 1 deletion tentacle/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,24 @@ where
.await;
}
}
TargetSession::Multi(iter) => {
for id in iter {
if let Some(control) = self.sessions.get_mut(&id) {
control.inner.incr_pending_data_size(data.len());
let _ignore = control
.send(
priority,
SessionEvent::ProtocolMessage {
proto_id,
data: data.clone(),
},
)
.await;
}
}
}
// Send data to the specified protocol for the specified sessions.
TargetSession::Filter(filter) => {
TargetSession::Filter(mut filter) => {
for (id, control) in self.sessions.iter_mut().filter(|(id, _)| filter(id)) {
debug!(
"send message to session [{}], proto [{}], data len: {}",
Expand Down
4 changes: 3 additions & 1 deletion tentacle/src/service/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,10 @@ pub enum TargetSession {
All,
/// Try send to only one
Single(SessionId),
/// Try send to some determined session
Multi(Box<dyn Iterator<Item = SessionId> + Send + 'static>),
/// Try send to some session, if return true, send to it
Filter(Box<dyn Fn(&SessionId) -> bool + Sync + Send + 'static>),
Filter(Box<dyn FnMut(&SessionId) -> bool + Send + 'static>),
}

impl From<SessionId> for TargetSession {
Expand Down

0 comments on commit fa50edc

Please sign in to comment.