mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 23:08:36 +01:00
Trampoline onion construction.
This commit is contained in:
parent
4baa8a770c
commit
e7e1afac29
2 changed files with 45 additions and 0 deletions
|
@ -1740,6 +1740,17 @@ mod fuzzy_internal_msgs {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) enum OutboundTrampolinePayload {
|
||||
#[allow(unused)]
|
||||
Forward {
|
||||
/// The value, in msat, of the payment after this hop's fee is deducted.
|
||||
amt_to_forward: u64,
|
||||
outgoing_cltv_value: u32,
|
||||
/// The node id to which the trampoline node must find a route
|
||||
outgoing_node_id: PublicKey,
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DecodedOnionErrorPacket {
|
||||
pub(crate) hmac: [u8; 32],
|
||||
pub(crate) failuremsg: Vec<u8>,
|
||||
|
@ -2597,6 +2608,22 @@ impl Writeable for OutboundOnionPayload {
|
|||
}
|
||||
}
|
||||
|
||||
impl Writeable for OutboundTrampolinePayload {
|
||||
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
|
||||
match self {
|
||||
Self::Forward { amt_to_forward, outgoing_cltv_value, outgoing_node_id } => {
|
||||
_encode_varint_length_prefixed_tlv!(w, {
|
||||
(2, HighZeroBytesDroppedBigSize(*amt_to_forward), required),
|
||||
(4, HighZeroBytesDroppedBigSize(*outgoing_cltv_value), required),
|
||||
(14, outgoing_node_id, required)
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<NS: Deref> ReadableArgs<(Option<PublicKey>, &NS)> for InboundOnionPayload where NS::Target: NodeSigner {
|
||||
fn read<R: Read>(r: &mut R, args: (Option<PublicKey>, &NS)) -> Result<Self, DecodeError> {
|
||||
let (update_add_blinding_point, node_signer) = args;
|
||||
|
|
|
@ -291,6 +291,24 @@ pub(super) fn construct_onion_packet(
|
|||
)
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub(super) fn construct_trampoline_onion_packet(
|
||||
payloads: Vec<msgs::OutboundTrampolinePayload>, onion_keys: Vec<OnionKeys>,
|
||||
prng_seed: [u8; 32], associated_data: &PaymentHash, length: u16,
|
||||
) -> Result<msgs::TrampolineOnionPacket, ()> {
|
||||
let mut packet_data = vec![0u8; length as usize];
|
||||
|
||||
let mut chacha = ChaCha20::new(&prng_seed, &[0; 8]);
|
||||
chacha.process(&vec![0u8; length as usize], &mut packet_data);
|
||||
|
||||
construct_onion_packet_with_init_noise::<_, _>(
|
||||
payloads,
|
||||
onion_keys,
|
||||
packet_data,
|
||||
Some(associated_data),
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
/// Used in testing to write bogus `BogusOnionHopData` as well as `RawOnionHopData`, which is
|
||||
/// otherwise not representable in `msgs::OnionHopData`.
|
||||
|
|
Loading…
Add table
Reference in a new issue