+/// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
+/// return packet by a node along the route. See [BOLT #4] for details.
+///
+/// [BOLT #4]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md
+#[must_use]
+#[derive(Clone)]
+#[repr(C)]
+pub enum NetworkUpdate {
+ /// An error indicating a `channel_update` messages should be applied via
+ /// [`NetworkGraph::update_channel`].
+ ChannelUpdateMessage {
+ /// The update to apply via [`NetworkGraph::update_channel`].
+ msg: crate::lightning::ln::msgs::ChannelUpdate,
+ },
+ /// An error indicating only that a channel has been closed, which should be applied via
+ /// [`NetworkGraph::close_channel_from_update`].
+ ChannelClosed {
+ /// The short channel id of the closed channel.
+ short_channel_id: u64,
+ /// Whether the channel should be permanently removed or temporarily disabled until a new
+ /// `channel_update` message is received.
+ is_permanent: bool,
+ },
+ /// An error indicating only that a node has failed, which should be applied via
+ /// [`NetworkGraph::fail_node`].
+ NodeFailure {
+ /// The node id of the failed node.
+ node_id: crate::c_types::PublicKey,
+ /// Whether the node should be permanently removed from consideration or can be restored
+ /// when a new `channel_update` message is received.
+ is_permanent: bool,
+ },
+}
+use lightning::routing::network_graph::NetworkUpdate as nativeNetworkUpdate;
+impl NetworkUpdate {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeNetworkUpdate {
+ match self {
+ NetworkUpdate::ChannelUpdateMessage {ref msg, } => {
+ let mut msg_nonref = (*msg).clone();
+ nativeNetworkUpdate::ChannelUpdateMessage {
+ msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
+ }
+ },
+ NetworkUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => {
+ let mut short_channel_id_nonref = (*short_channel_id).clone();
+ let mut is_permanent_nonref = (*is_permanent).clone();
+ nativeNetworkUpdate::ChannelClosed {
+ short_channel_id: short_channel_id_nonref,
+ is_permanent: is_permanent_nonref,
+ }
+ },
+ NetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
+ let mut node_id_nonref = (*node_id).clone();
+ let mut is_permanent_nonref = (*is_permanent).clone();
+ nativeNetworkUpdate::NodeFailure {
+ node_id: node_id_nonref.into_rust(),
+ is_permanent: is_permanent_nonref,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeNetworkUpdate {
+ match self {
+ NetworkUpdate::ChannelUpdateMessage {mut msg, } => {
+ nativeNetworkUpdate::ChannelUpdateMessage {
+ msg: *unsafe { Box::from_raw(msg.take_inner()) },
+ }
+ },
+ NetworkUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => {
+ nativeNetworkUpdate::ChannelClosed {
+ short_channel_id: short_channel_id,
+ is_permanent: is_permanent,
+ }
+ },
+ NetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
+ nativeNetworkUpdate::NodeFailure {
+ node_id: node_id.into_rust(),
+ is_permanent: is_permanent,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativeNetworkUpdate) -> Self {
+ match native {
+ nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => {
+ let mut msg_nonref = (*msg).clone();
+ NetworkUpdate::ChannelUpdateMessage {
+ msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
+ }
+ },
+ nativeNetworkUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => {
+ let mut short_channel_id_nonref = (*short_channel_id).clone();
+ let mut is_permanent_nonref = (*is_permanent).clone();
+ NetworkUpdate::ChannelClosed {
+ short_channel_id: short_channel_id_nonref,
+ is_permanent: is_permanent_nonref,
+ }
+ },
+ nativeNetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
+ let mut node_id_nonref = (*node_id).clone();
+ let mut is_permanent_nonref = (*is_permanent).clone();
+ NetworkUpdate::NodeFailure {
+ node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
+ is_permanent: is_permanent_nonref,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeNetworkUpdate) -> Self {
+ match native {
+ nativeNetworkUpdate::ChannelUpdateMessage {mut msg, } => {
+ NetworkUpdate::ChannelUpdateMessage {
+ msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
+ }
+ },
+ nativeNetworkUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => {
+ NetworkUpdate::ChannelClosed {
+ short_channel_id: short_channel_id,
+ is_permanent: is_permanent,
+ }
+ },
+ nativeNetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
+ NetworkUpdate::NodeFailure {
+ node_id: crate::c_types::PublicKey::from_rust(&node_id),
+ is_permanent: is_permanent,
+ }
+ },
+ }
+ }
+}
+/// Frees any resources used by the NetworkUpdate
+#[no_mangle]
+pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { }
+/// Creates a copy of the NetworkUpdate
+#[no_mangle]
+pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate {
+ orig.clone()
+}
+#[no_mangle]
+/// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
+pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate {
+ NetworkUpdate::ChannelUpdateMessage {
+ msg,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new ChannelClosed-variant NetworkUpdate
+pub extern "C" fn NetworkUpdate_channel_closed(short_channel_id: u64, is_permanent: bool) -> NetworkUpdate {
+ NetworkUpdate::ChannelClosed {
+ short_channel_id,
+ is_permanent,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new NodeFailure-variant NetworkUpdate
+pub extern "C" fn NetworkUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent: bool) -> NetworkUpdate {
+ NetworkUpdate::NodeFailure {
+ node_id,
+ is_permanent,
+ }
+}
+#[no_mangle]
+/// Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
+pub extern "C" fn NetworkUpdate_write(obj: &NetworkUpdate) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
+}
+impl From<nativeNetGraphMsgHandler> for crate::lightning::util::events::EventHandler {
+ fn from(obj: nativeNetGraphMsgHandler) -> Self {
+ let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
+ let mut ret = NetGraphMsgHandler_as_EventHandler(&rust_obj);
+ // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
+ rust_obj.inner = std::ptr::null_mut();
+ ret.free = Some(NetGraphMsgHandler_free_void);
+ ret
+ }
+}
+/// Constructs a new EventHandler which calls the relevant methods on this_arg.
+/// This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is
+#[no_mangle]
+pub extern "C" fn NetGraphMsgHandler_as_EventHandler(this_arg: &NetGraphMsgHandler) -> crate::lightning::util::events::EventHandler {
+ crate::lightning::util::events::EventHandler {
+ this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
+ free: None,
+ handle_event: NetGraphMsgHandler_EventHandler_handle_event,
+ }
+}
+
+extern "C" fn NetGraphMsgHandler_EventHandler_handle_event(this_arg: *const c_void, event: &crate::lightning::util::events::Event) {
+ <nativeNetGraphMsgHandler as lightning::util::events::EventHandler<>>::handle_event(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &event.to_native())
+}
+