MessageRouter::find_path returns a path to use when sending an onion
message. If the first node on the path is not connected or does not
support onion messages, sending will fail with InvalidFirstHop. Instead
of failing outright, buffer the message for later sending once the first
node is a connected peer.
/// The message was buffered and will be sent once it is processed by
/// [`OnionMessageHandler::next_onion_message_for_peer`].
Buffered,
/// The message was buffered and will be sent once it is processed by
/// [`OnionMessageHandler::next_onion_message_for_peer`].
Buffered,
+ /// The message was buffered and will be sent once the node is connected as a peer and it is
+ /// processed by [`OnionMessageHandler::next_onion_message_for_peer`].
+ BufferedAwaitingConnection(PublicKey),
}
/// Errors that may occur when [sending an onion message].
}
/// Errors that may occur when [sending an onion message].
/// The provided [`Destination`] was an invalid [`BlindedPath`] due to not having any blinded
/// hops.
TooFewBlindedHops,
/// The provided [`Destination`] was an invalid [`BlindedPath`] due to not having any blinded
/// hops.
TooFewBlindedHops,
- /// Our next-hop peer was offline or does not support onion message forwarding.
- InvalidFirstHop,
/// A path from the sender to the destination could not be found by the [`MessageRouter`].
PathNotFound,
/// Onion message contents must have a TLV type >= 64.
/// A path from the sender to the destination could not be found by the [`MessageRouter`].
PathNotFound,
/// Onion message contents must have a TLV type >= 64.
Ok(SendSuccess::Buffered) => {
log_trace!(self.logger, "Buffered onion message {}", log_suffix);
},
Ok(SendSuccess::Buffered) => {
log_trace!(self.logger, "Buffered onion message {}", log_suffix);
},
+ Ok(SendSuccess::BufferedAwaitingConnection(node_id)) => {
+ log_trace!(
+ self.logger, "Buffered onion message waiting on peer connection {}: {:?}",
+ log_suffix, node_id
+ );
+ },
}
match message_buffers.entry(first_node_id) {
}
match message_buffers.entry(first_node_id) {
- hash_map::Entry::Vacant(_) => Err(SendError::InvalidFirstHop),
+ hash_map::Entry::Vacant(e) => {
+ e.insert(OnionMessageBuffer::PendingConnection(VecDeque::new()))
+ .enqueue_message(onion_message);
+ Ok(SendSuccess::BufferedAwaitingConnection(first_node_id))
+ },
hash_map::Entry::Occupied(mut e) => {
e.get_mut().enqueue_message(onion_message);
Ok(SendSuccess::Buffered)
hash_map::Entry::Occupied(mut e) => {
e.get_mut().enqueue_message(onion_message);
Ok(SendSuccess::Buffered)