[−][src]Function cjdns_core::splice::build_label
pub fn build_label<L: LabelBits>(
path_hops: &[PathHop<'_, L>]
) -> Result<(RoutingLabel<L>, Vec<RoutingLabel<L>>)>
This will construct a label using an array representation of a path (path_hops
).
If any label along the path needs to be re-encoded, it will be.
Each element in the array represents a hop (node) in the path and each of them has PathHop.label_p
and/or PathHop.label_n
depending on whether there is a previous and/or next hop.
PathHop.label_p
is necessary to know the width of the inverse path hop so that the label can be re-encoded if necessary.
let label = build_label(&[ PathHop::new(l("0000.0000.0000.0000"), l("0000.0000.0000.0015"), &schemes::V358), PathHop::new(l("0000.0000.0000.009e"), l("0000.0000.0000.008e"), &schemes::V358), PathHop::new(l("0000.0000.0000.0013"), l("0000.0000.0000.00a2"), &schemes::V358), PathHop::new(l("0000.0000.0000.001b"), l("0000.0000.0000.001d"), &schemes::V358), PathHop::new(l("0000.0000.0000.00ee"), l("0000.0000.0000.001b"), &schemes::V358), PathHop::new(l("0000.0000.0000.0019"), l("0000.0000.0000.001b"), &schemes::V358), PathHop::new(l("0000.0000.0000.0013"), l("0000.0000.0000.0000"), &schemes::V358), ]); let expected = ( l("0000.0003.64b5.10e5"), vec![ l("0000.0000.0000.0015"), l("0000.0000.0000.008e"), l("0000.0000.0000.00a2"), l("0000.0000.0000.001d"), l("0000.0000.0000.0092"), l("0000.0000.0000.001b"), ] ); assert_eq!(label, Ok(expected));
This function results in a tuple containing 2 elements, label
and path
. label
is the final label for this path
. And path
is the hops to get there.
Notice the second to last hop in the path
has been changed from 001b to 0092. This is a re-encoding to ensure that the label
remains the right length as the reverse path for this hop is 00ee which is longer than 001b.