1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Used to put an error message in a [`LightningError`].
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ErrorAction extends CommonBase {
16 private ErrorAction(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.ErrorAction_free(ptr); }
22 static ErrorAction constr_from_ptr(long ptr) {
23 bindings.LDKErrorAction raw_val = bindings.LDKErrorAction_ref_from_ptr(ptr);
24 if (raw_val.getClass() == bindings.LDKErrorAction.DisconnectPeer.class) {
25 return new DisconnectPeer(ptr, (bindings.LDKErrorAction.DisconnectPeer)raw_val);
27 if (raw_val.getClass() == bindings.LDKErrorAction.DisconnectPeerWithWarning.class) {
28 return new DisconnectPeerWithWarning(ptr, (bindings.LDKErrorAction.DisconnectPeerWithWarning)raw_val);
30 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreError.class) {
31 return new IgnoreError(ptr, (bindings.LDKErrorAction.IgnoreError)raw_val);
33 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreAndLog.class) {
34 return new IgnoreAndLog(ptr, (bindings.LDKErrorAction.IgnoreAndLog)raw_val);
36 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreDuplicateGossip.class) {
37 return new IgnoreDuplicateGossip(ptr, (bindings.LDKErrorAction.IgnoreDuplicateGossip)raw_val);
39 if (raw_val.getClass() == bindings.LDKErrorAction.SendErrorMessage.class) {
40 return new SendErrorMessage(ptr, (bindings.LDKErrorAction.SendErrorMessage)raw_val);
42 if (raw_val.getClass() == bindings.LDKErrorAction.SendWarningMessage.class) {
43 return new SendWarningMessage(ptr, (bindings.LDKErrorAction.SendWarningMessage)raw_val);
45 assert false; return null; // Unreachable without extending the (internal) bindings interface
49 * The peer took some action which made us think they were useless. Disconnect them.
51 public final static class DisconnectPeer extends ErrorAction {
53 * An error message which we should make an effort to send before we disconnect.
55 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
57 @Nullable public final org.ldk.structs.ErrorMessage msg;
58 private DisconnectPeer(long ptr, bindings.LDKErrorAction.DisconnectPeer obj) {
61 org.ldk.structs.ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ErrorMessage(null, msg); }
62 if (msg_hu_conv != null) { msg_hu_conv.ptrs_to.add(this); };
63 this.msg = msg_hu_conv;
67 * The peer did something incorrect. Tell them without closing any channels and disconnect them.
69 public final static class DisconnectPeerWithWarning extends ErrorAction {
71 * A warning message which we should make an effort to send before we disconnect.
73 public final org.ldk.structs.WarningMessage msg;
74 private DisconnectPeerWithWarning(long ptr, bindings.LDKErrorAction.DisconnectPeerWithWarning obj) {
77 org.ldk.structs.WarningMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.WarningMessage(null, msg); }
78 if (msg_hu_conv != null) { msg_hu_conv.ptrs_to.add(this); };
79 this.msg = msg_hu_conv;
83 * The peer did something harmless that we weren't able to process, just log and ignore
85 public final static class IgnoreError extends ErrorAction {
86 private IgnoreError(long ptr, bindings.LDKErrorAction.IgnoreError obj) {
91 * The peer did something harmless that we weren't able to meaningfully process.
92 * If the error is logged, log it at the given level.
94 public final static class IgnoreAndLog extends ErrorAction {
95 public final org.ldk.enums.Level ignore_and_log;
96 private IgnoreAndLog(long ptr, bindings.LDKErrorAction.IgnoreAndLog obj) {
98 this.ignore_and_log = obj.ignore_and_log;
102 * The peer provided us with a gossip message which we'd already seen. In most cases this
103 * should be ignored, but it may result in the message being forwarded if it is a duplicate of
104 * our own channel announcements.
106 public final static class IgnoreDuplicateGossip extends ErrorAction {
107 private IgnoreDuplicateGossip(long ptr, bindings.LDKErrorAction.IgnoreDuplicateGossip obj) {
112 * The peer did something incorrect. Tell them.
114 public final static class SendErrorMessage extends ErrorAction {
116 * The message to send.
118 public final org.ldk.structs.ErrorMessage msg;
119 private SendErrorMessage(long ptr, bindings.LDKErrorAction.SendErrorMessage obj) {
122 org.ldk.structs.ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ErrorMessage(null, msg); }
123 if (msg_hu_conv != null) { msg_hu_conv.ptrs_to.add(this); };
124 this.msg = msg_hu_conv;
128 * The peer did something incorrect. Tell them without closing any channels.
130 public final static class SendWarningMessage extends ErrorAction {
132 * The message to send.
134 public final org.ldk.structs.WarningMessage msg;
136 * The peer may have done something harmless that we weren't able to meaningfully process,
137 * though we should still tell them about it.
138 * If this event is logged, log it at the given level.
140 public final org.ldk.enums.Level log_level;
141 private SendWarningMessage(long ptr, bindings.LDKErrorAction.SendWarningMessage obj) {
144 org.ldk.structs.WarningMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.WarningMessage(null, msg); }
145 if (msg_hu_conv != null) { msg_hu_conv.ptrs_to.add(this); };
146 this.msg = msg_hu_conv;
147 this.log_level = obj.log_level;
151 long ret = bindings.ErrorAction_clone_ptr(this.ptr);
152 Reference.reachabilityFence(this);
157 * Creates a copy of the ErrorAction
159 public ErrorAction clone() {
160 long ret = bindings.ErrorAction_clone(this.ptr);
161 Reference.reachabilityFence(this);
162 if (ret >= 0 && ret <= 4096) { return null; }
163 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
164 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
169 * Utility method to constructs a new DisconnectPeer-variant ErrorAction
171 public static ErrorAction disconnect_peer(org.ldk.structs.ErrorMessage msg) {
172 long ret = bindings.ErrorAction_disconnect_peer(msg == null ? 0 : msg.ptr);
173 Reference.reachabilityFence(msg);
174 if (ret >= 0 && ret <= 4096) { return null; }
175 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
176 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
177 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(msg); };
182 * Utility method to constructs a new DisconnectPeerWithWarning-variant ErrorAction
184 public static ErrorAction disconnect_peer_with_warning(org.ldk.structs.WarningMessage msg) {
185 long ret = bindings.ErrorAction_disconnect_peer_with_warning(msg == null ? 0 : msg.ptr);
186 Reference.reachabilityFence(msg);
187 if (ret >= 0 && ret <= 4096) { return null; }
188 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
189 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
190 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(msg); };
195 * Utility method to constructs a new IgnoreError-variant ErrorAction
197 public static ErrorAction ignore_error() {
198 long ret = bindings.ErrorAction_ignore_error();
199 if (ret >= 0 && ret <= 4096) { return null; }
200 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
201 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
206 * Utility method to constructs a new IgnoreAndLog-variant ErrorAction
208 public static ErrorAction ignore_and_log(org.ldk.enums.Level a) {
209 long ret = bindings.ErrorAction_ignore_and_log(a);
210 Reference.reachabilityFence(a);
211 if (ret >= 0 && ret <= 4096) { return null; }
212 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
213 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
218 * Utility method to constructs a new IgnoreDuplicateGossip-variant ErrorAction
220 public static ErrorAction ignore_duplicate_gossip() {
221 long ret = bindings.ErrorAction_ignore_duplicate_gossip();
222 if (ret >= 0 && ret <= 4096) { return null; }
223 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
224 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
229 * Utility method to constructs a new SendErrorMessage-variant ErrorAction
231 public static ErrorAction send_error_message(org.ldk.structs.ErrorMessage msg) {
232 long ret = bindings.ErrorAction_send_error_message(msg == null ? 0 : msg.ptr);
233 Reference.reachabilityFence(msg);
234 if (ret >= 0 && ret <= 4096) { return null; }
235 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
236 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
237 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(msg); };
242 * Utility method to constructs a new SendWarningMessage-variant ErrorAction
244 public static ErrorAction send_warning_message(org.ldk.structs.WarningMessage msg, org.ldk.enums.Level log_level) {
245 long ret = bindings.ErrorAction_send_warning_message(msg == null ? 0 : msg.ptr, log_level);
246 Reference.reachabilityFence(msg);
247 Reference.reachabilityFence(log_level);
248 if (ret >= 0 && ret <= 4096) { return null; }
249 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
250 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
251 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(msg); };