/// Stores the `signal` inside the internal timed-queue for `implicated_cid`, and then sends `packet` to `target_cid`.
/// After `timeout`, the closure `on_timeout` is executed
#[inline]
pub fn route_primary<'a, 'b: 'a, 'c: 'b>(&'c mut self, implicated_cid: u64, target_cid: u64, ticket: Ticket, signal: PeerSignal, packet: impl Fn(&'b Rc<PostQuantumContainer>, &'b Drill) -> Bytes + 'a, timeout: Duration, on_timeout: impl Fn(PeerSignal) + 'static) -> Result<(), String> {
if self.account_manager.hyperlan_cid_is_registered(target_cid) {
// get the target cid's session
if let Some(sess) = self.sessions.get(&target_cid) {
if self.hypernode_peer_layer.insert_tracked_posting(implicated_cid, timeout, ticket, signal, on_timeout) {
let sess_ref = sess.inner.borrow();
let target_pqc = sess_ref.post_quantum.as_ref().unwrap();
let peer_sender = sess_ref.to_primary_stream.as_ref().unwrap();
let peer_cnac = sess_ref.cnac.as_ref().unwrap();
if let Some(ref peer_latest_drill) = peer_cnac.get_drill_blocking(None) {
log::info!("Routing packet through primary stream ({} -> {})", implicated_cid, target_cid);
let packet = packet(target_pqc, peer_latest_drill );
let _drill = peer_latest_drill;
peer_sender.unbounded_send(packet).map_err(|err| err.to_string());
} else {
return Err(format!("Unable to acquire peer drill for {}", target_cid))
}
return Ok(())
} else {
Err(format!("Unable to insert tracked posting for {}", implicated_cid))
}
} else {
// session is not active, but user is registered (thus offline). Deliver to mailbox
if self.hypernode_peer_layer.try_add_mailbox(true, target_cid, signal) {
Ok(())
} else {
Err(format!("Peer {} is offline. Furthermore, that peer's mailbox is not accepting signals at this time", target_cid))
}
}
} else {
Err(format!("CID {} is not registered locally", target_cid))
}
}
Error:
error[E0597]: `sess_ref` does not live long enough
--> hyxe_net/src/hdp/hdp_session_manager.rs:449:38
|
443 | pub fn route_primary<'a, 'b: 'a, 'c: 'b>(&'c mut self, implicated_cid: u64, target_cid: u64, ticket: Ticket, signal: PeerSignal, packet: impl Fn(&'b Rc<PostQuantumContainer>, &'b Drill) -> Bytes + 'a, timeout: Duration, on_timeout: impl Fn(PeerSignal) + 'static) -> Result<(), String> {
| -- lifetime `'b` defined here
...
449 | let target_pqc = sess_ref.post_quantum.as_ref().unwrap();
| ^^^^^^^^ borrowed value does not live long enough
...
455 | let packet = packet(target_pqc, peer_latest_drill );
| -------------------------------------- argument requires that `sess_ref` is borrowed for `'b`
...
463 | } else {
| - `sess_ref` dropped here while still borrowed
error[E0716]: temporary value dropped while borrowed
--> hyxe_net/src/hdp/hdp_session_manager.rs:453:58
|
443 | pub fn route_primary<'a, 'b: 'a, 'c: 'b>(&'c mut self, implicated_cid: u64, target_cid: u64, ticket: Ticket, signal: PeerSignal, packet: impl Fn(&'b Rc<PostQuantumContainer>, &'b Drill) -> Bytes + 'a, timeout: Duration, on_timeout: impl Fn(PeerSignal) + 'static) -> Result<(), String> {
| -- lifetime `'b` defined here
...
453 | if let Some(ref peer_latest_drill) = peer_cnac.get_drill_blocking(None) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
454 | log::info!("Routing packet through primary stream ({} -> {})", implicated_cid, target_cid);
455 | let packet = packet(target_pqc, peer_latest_drill );
| -------------------------------------- argument requires that borrow lasts for `'b`
...
460 | }
| - temporary value is freed at the end of this statement
I want the closure packet
to be called in order to obtain a Bytes
object, and from there, send it through the unbounded sender. However, when I try this I get the lifetime error shown above