X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FClosureReason.java;h=cea9cc6bfb20f16667e65c9fab34851eaae02e6a;hb=4a36fa97d4eee96099c4a176ea845c52db27e64c;hp=800deb56e6b5b59bb7a9b15a8994064ee5c4b9a5;hpb=3c60e0fd0da579be9932801c1be2b32014c944a5;p=ldk-java diff --git a/src/main/java/org/ldk/structs/ClosureReason.java b/src/main/java/org/ldk/structs/ClosureReason.java index 800deb56..cea9cc6b 100644 --- a/src/main/java/org/ldk/structs/ClosureReason.java +++ b/src/main/java/org/ldk/structs/ClosureReason.java @@ -58,14 +58,19 @@ public class ClosureReason extends CommonBase { /** * The error which the peer sent us. * - * The string should be sanitized before it is used (e.g emitted to logs - * or printed to stdout). Otherwise, a well crafted error message may exploit + * Be careful about printing the peer_msg, a well-crafted message could exploit * a security vulnerability in the terminal emulator or the logging subsystem. + * To be safe, use `Display` on `UntrustedString` + * + * [`UntrustedString`]: crate::util::string::UntrustedString */ - public final java.lang.String peer_msg; + public final org.ldk.structs.UntrustedString peer_msg; private CounterpartyForceClosed(long ptr, bindings.LDKClosureReason.CounterpartyForceClosed obj) { super(null, ptr); - this.peer_msg = obj.peer_msg; + long peer_msg = obj.peer_msg; + org.ldk.structs.UntrustedString peer_msg_hu_conv = null; if (peer_msg < 0 || peer_msg > 4096) { peer_msg_hu_conv = new org.ldk.structs.UntrustedString(null, peer_msg); } + if (peer_msg_hu_conv != null) { peer_msg_hu_conv.ptrs_to.add(this); }; + this.peer_msg = peer_msg_hu_conv; } } /** @@ -122,8 +127,13 @@ public class ClosureReason extends CommonBase { * The peer disconnected prior to funding completing. In this case the spec mandates that we * forget the channel entirely - we can attempt again if the peer reconnects. * + * This includes cases where we restarted prior to funding completion, including prior to the + * initial [`ChannelMonitor`] persistence completing. + * * In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the * peer because of mutual incompatibility between us and our channel counterparty. + * + * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor */ public final static class DisconnectedPeer extends ClosureReason { private DisconnectedPeer(long ptr, bindings.LDKClosureReason.DisconnectedPeer obj) { @@ -131,8 +141,11 @@ public class ClosureReason extends CommonBase { } } /** - * Closure generated from `ChannelManager::read` if the ChannelMonitor is newer than - * the ChannelManager deserialized. + * Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than + * the [`ChannelManager`] deserialized. + * + * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor + * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager */ public final static class OutdatedChannelManager extends ClosureReason { private OutdatedChannelManager(long ptr, bindings.LDKClosureReason.OutdatedChannelManager obj) { @@ -160,12 +173,13 @@ public class ClosureReason extends CommonBase { /** * Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason */ - public static ClosureReason counterparty_force_closed(java.lang.String peer_msg) { - long ret = bindings.ClosureReason_counterparty_force_closed(peer_msg); + public static ClosureReason counterparty_force_closed(org.ldk.structs.UntrustedString peer_msg) { + long ret = bindings.ClosureReason_counterparty_force_closed(peer_msg == null ? 0 : peer_msg.ptr); Reference.reachabilityFence(peer_msg); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(peer_msg); }; return ret_hu_conv; } @@ -247,6 +261,21 @@ public class ClosureReason extends CommonBase { return ret_hu_conv; } + /** + * Checks if two ClosureReasons contain equal inner contents. + * This ignores pointers and is_owned flags and looks at the values in fields. + */ + public boolean eq(org.ldk.structs.ClosureReason b) { + boolean ret = bindings.ClosureReason_eq(this.ptr, b == null ? 0 : b.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(b); + return ret; + } + + @Override public boolean equals(Object o) { + if (!(o instanceof ClosureReason)) return false; + return this.eq((ClosureReason)o); + } /** * Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read */