projects
/
rust-lightning
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Implement `Debug`/`PartialEq`/`Eq` for `Destination`
[rust-lightning]
/
lightning
/
src
/
onion_message
/
messenger.rs
diff --git
a/lightning/src/onion_message/messenger.rs
b/lightning/src/onion_message/messenger.rs
index 1c37fc3d71e7c4e309e043b27e5fe0dd51138f27..0a38022dbb5883cdcf06a5e3340a68079ae9f23c 100644
(file)
--- a/
lightning/src/onion_message/messenger.rs
+++ b/
lightning/src/onion_message/messenger.rs
@@
-96,8
+96,8
@@
pub(super) const MAX_TIMER_TICKS: usize = 2;
/// # first_node_addresses: None,
/// # })
/// # }
/// # first_node_addresses: None,
/// # })
/// # }
-/// # fn create_blinded_paths<
ES: EntropySource + ?Sized,
T: secp256k1::Signing + secp256k1::Verification>(
-/// # &self, _recipient: PublicKey, _peers: Vec<PublicKey>, _
entropy_source: &ES, _
secp_ctx: &Secp256k1<T>
+/// # fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
+/// # &self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>
/// # ) -> Result<Vec<BlindedPath>, ()> {
/// # unreachable!()
/// # }
/// # ) -> Result<Vec<BlindedPath>, ()> {
/// # unreachable!()
/// # }
@@
-285,34
+285,37
@@
pub trait MessageRouter {
/// Creates [`BlindedPath`]s to the `recipient` node. The nodes in `peers` are assumed to be
/// direct peers with the `recipient`.
fn create_blinded_paths<
/// Creates [`BlindedPath`]s to the `recipient` node. The nodes in `peers` are assumed to be
/// direct peers with the `recipient`.
fn create_blinded_paths<
-
ES: EntropySource + ?Sized,
T: secp256k1::Signing + secp256k1::Verification
+ T: secp256k1::Signing + secp256k1::Verification
>(
>(
- &self, recipient: PublicKey, peers: Vec<PublicKey>, entropy_source: &ES,
- secp_ctx: &Secp256k1<T>
+ &self, recipient: PublicKey, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedPath>, ()>;
}
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
) -> Result<Vec<BlindedPath>, ()>;
}
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
-pub struct DefaultMessageRouter<G: Deref<Target=NetworkGraph<L>>, L: Deref>
+pub struct DefaultMessageRouter<G: Deref<Target=NetworkGraph<L>>, L: Deref
, ES: Deref
>
where
L::Target: Logger,
where
L::Target: Logger,
+ ES::Target: EntropySource,
{
network_graph: G,
{
network_graph: G,
+ entropy_source: ES,
}
}
-impl<G: Deref<Target=NetworkGraph<L>>, L: Deref
> DefaultMessageRouter<G, L
>
+impl<G: Deref<Target=NetworkGraph<L>>, L: Deref
, ES: Deref> DefaultMessageRouter<G, L, ES
>
where
L::Target: Logger,
where
L::Target: Logger,
+ ES::Target: EntropySource,
{
/// Creates a [`DefaultMessageRouter`] using the given [`NetworkGraph`].
{
/// Creates a [`DefaultMessageRouter`] using the given [`NetworkGraph`].
- pub fn new(network_graph: G) -> Self {
- Self { network_graph }
+ pub fn new(network_graph: G
, entropy_source: ES
) -> Self {
+ Self { network_graph
, entropy_source
}
}
}
}
}
-impl<G: Deref<Target=NetworkGraph<L>>, L: Deref
> MessageRouter for DefaultMessageRouter<G, L
>
+impl<G: Deref<Target=NetworkGraph<L>>, L: Deref
, ES: Deref> MessageRouter for DefaultMessageRouter<G, L, ES
>
where
L::Target: Logger,
where
L::Target: Logger,
+ ES::Target: EntropySource,
{
fn find_path(
&self, _sender: PublicKey, peers: Vec<PublicKey>, destination: Destination
{
fn find_path(
&self, _sender: PublicKey, peers: Vec<PublicKey>, destination: Destination
@@
-343,10
+346,9
@@
where
}
fn create_blinded_paths<
}
fn create_blinded_paths<
-
ES: EntropySource + ?Sized,
T: secp256k1::Signing + secp256k1::Verification
+ T: secp256k1::Signing + secp256k1::Verification
>(
>(
- &self, recipient: PublicKey, peers: Vec<PublicKey>, entropy_source: &ES,
- secp_ctx: &Secp256k1<T>
+ &self, recipient: PublicKey, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedPath>, ()> {
// Limit the number of blinded paths that are computed.
const MAX_PATHS: usize = 3;
) -> Result<Vec<BlindedPath>, ()> {
// Limit the number of blinded paths that are computed.
const MAX_PATHS: usize = 3;
@@
-366,7
+368,7
@@
where
.unwrap_or(false)
)
.map(|pubkey| vec![*pubkey, recipient])
.unwrap_or(false)
)
.map(|pubkey| vec![*pubkey, recipient])
- .map(|node_pks| BlindedPath::new_for_message(&node_pks, entropy_source, secp_ctx))
+ .map(|node_pks| BlindedPath::new_for_message(&node_pks,
&*self.
entropy_source, secp_ctx))
.take(MAX_PATHS)
.collect::<Result<Vec<_>, _>>();
.take(MAX_PATHS)
.collect::<Result<Vec<_>, _>>();
@@
-374,7
+376,7
@@
where
Ok(paths) if !paths.is_empty() => Ok(paths),
_ => {
if network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient)) {
Ok(paths) if !paths.is_empty() => Ok(paths),
_ => {
if network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient)) {
- BlindedPath::one_hop_for_message(recipient, entropy_source, secp_ctx)
+ BlindedPath::one_hop_for_message(recipient,
&*self.
entropy_source, secp_ctx)
.map(|path| vec![path])
} else {
Err(())
.map(|path| vec![path])
} else {
Err(())
@@
-411,7
+413,7
@@
impl OnionMessagePath {
}
/// The destination of an onion message.
}
/// The destination of an onion message.
-#[derive(Clone)]
+#[derive(Clone
, Debug, PartialEq, Eq
)]
pub enum Destination {
/// We're sending this onion message to a node.
Node(PublicKey),
pub enum Destination {
/// We're sending this onion message to a node.
Node(PublicKey),
@@
-704,7
+706,7
@@
where
OnionMessenger {
entropy_source,
node_signer,
OnionMessenger {
entropy_source,
node_signer,
- message_recipients: Mutex::new(
HashMap::new
()),
+ message_recipients: Mutex::new(
new_hash_map
()),
secp_ctx,
logger,
message_router,
secp_ctx,
logger,
message_router,
@@
-846,7
+848,7
@@
where
#[cfg(test)]
pub(super) fn release_pending_msgs(&self) -> HashMap<PublicKey, VecDeque<OnionMessage>> {
let mut message_recipients = self.message_recipients.lock().unwrap();
#[cfg(test)]
pub(super) fn release_pending_msgs(&self) -> HashMap<PublicKey, VecDeque<OnionMessage>> {
let mut message_recipients = self.message_recipients.lock().unwrap();
- let mut msgs =
HashMap::new
();
+ let mut msgs =
new_hash_map
();
// We don't want to disconnect the peers by removing them entirely from the original map, so we
// release the pending message buffers individually.
for (node_id, recipient) in &mut *message_recipients {
// We don't want to disconnect the peers by removing them entirely from the original map, so we
// release the pending message buffers individually.
for (node_id, recipient) in &mut *message_recipients {
@@
-1069,7
+1071,7
@@
pub type SimpleArcOnionMessenger<M, T, F, L> = OnionMessenger<
Arc<KeysManager>,
Arc<KeysManager>,
Arc<L>,
Arc<KeysManager>,
Arc<KeysManager>,
Arc<L>,
- Arc<DefaultMessageRouter<Arc<NetworkGraph<Arc<L>>>, Arc<L>>>,
+ Arc<DefaultMessageRouter<Arc<NetworkGraph<Arc<L>>>, Arc<L>
, Arc<KeysManager>
>>,
Arc<SimpleArcChannelManager<M, T, F, L>>,
IgnoringMessageHandler
>;
Arc<SimpleArcChannelManager<M, T, F, L>>,
IgnoringMessageHandler
>;
@@
-1088,7
+1090,7
@@
pub type SimpleRefOnionMessenger<
&'a KeysManager,
&'a KeysManager,
&'b L,
&'a KeysManager,
&'a KeysManager,
&'b L,
- &'i DefaultMessageRouter<&'g NetworkGraph<&'b L>, &'b L>,
+ &'i DefaultMessageRouter<&'g NetworkGraph<&'b L>, &'b L
, &'a KeysManager
>,
&'j SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, M, T, F, L>,
IgnoringMessageHandler
>;
&'j SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, M, T, F, L>,
IgnoringMessageHandler
>;