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.IgnoreError.class) {
28 return new IgnoreError(ptr, (bindings.LDKErrorAction.IgnoreError)raw_val);
30 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreAndLog.class) {
31 return new IgnoreAndLog(ptr, (bindings.LDKErrorAction.IgnoreAndLog)raw_val);
33 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreDuplicateGossip.class) {
34 return new IgnoreDuplicateGossip(ptr, (bindings.LDKErrorAction.IgnoreDuplicateGossip)raw_val);
36 if (raw_val.getClass() == bindings.LDKErrorAction.SendErrorMessage.class) {
37 return new SendErrorMessage(ptr, (bindings.LDKErrorAction.SendErrorMessage)raw_val);
39 if (raw_val.getClass() == bindings.LDKErrorAction.SendWarningMessage.class) {
40 return new SendWarningMessage(ptr, (bindings.LDKErrorAction.SendWarningMessage)raw_val);
42 assert false; return null; // Unreachable without extending the (internal) bindings interface
46 * The peer took some action which made us think they were useless. Disconnect them.
48 public final static class DisconnectPeer extends ErrorAction {
50 * An error message which we should make an effort to send before we disconnect.
52 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
54 @Nullable public final org.ldk.structs.ErrorMessage msg;
55 private DisconnectPeer(long ptr, bindings.LDKErrorAction.DisconnectPeer obj) {
58 ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ErrorMessage(null, msg); }
59 msg_hu_conv.ptrs_to.add(this);
60 this.msg = msg_hu_conv;
64 * The peer did something harmless that we weren't able to process, just log and ignore
66 public final static class IgnoreError extends ErrorAction {
67 private IgnoreError(long ptr, bindings.LDKErrorAction.IgnoreError obj) {
72 * The peer did something harmless that we weren't able to meaningfully process.
73 * If the error is logged, log it at the given level.
75 public final static class IgnoreAndLog extends ErrorAction {
76 public final org.ldk.enums.Level ignore_and_log;
77 private IgnoreAndLog(long ptr, bindings.LDKErrorAction.IgnoreAndLog obj) {
79 this.ignore_and_log = obj.ignore_and_log;
83 * The peer provided us with a gossip message which we'd already seen. In most cases this
84 * should be ignored, but it may result in the message being forwarded if it is a duplicate of
85 * our own channel announcements.
87 public final static class IgnoreDuplicateGossip extends ErrorAction {
88 private IgnoreDuplicateGossip(long ptr, bindings.LDKErrorAction.IgnoreDuplicateGossip obj) {
93 * The peer did something incorrect. Tell them.
95 public final static class SendErrorMessage extends ErrorAction {
97 * The message to send.
99 public final org.ldk.structs.ErrorMessage msg;
100 private SendErrorMessage(long ptr, bindings.LDKErrorAction.SendErrorMessage obj) {
103 ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ErrorMessage(null, msg); }
104 msg_hu_conv.ptrs_to.add(this);
105 this.msg = msg_hu_conv;
109 * The peer did something incorrect. Tell them without closing any channels.
111 public final static class SendWarningMessage extends ErrorAction {
113 * The message to send.
115 public final org.ldk.structs.WarningMessage msg;
117 * The peer may have done something harmless that we weren't able to meaningfully process,
118 * though we should still tell them about it.
119 * If this event is logged, log it at the given level.
121 public final org.ldk.enums.Level log_level;
122 private SendWarningMessage(long ptr, bindings.LDKErrorAction.SendWarningMessage obj) {
125 WarningMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new WarningMessage(null, msg); }
126 msg_hu_conv.ptrs_to.add(this);
127 this.msg = msg_hu_conv;
128 this.log_level = obj.log_level;
132 long ret = bindings.ErrorAction_clone_ptr(this.ptr);
133 Reference.reachabilityFence(this);
138 * Creates a copy of the ErrorAction
140 public ErrorAction clone() {
141 long ret = bindings.ErrorAction_clone(this.ptr);
142 Reference.reachabilityFence(this);
143 if (ret >= 0 && ret <= 4096) { return null; }
144 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
145 ret_hu_conv.ptrs_to.add(this);
150 * Utility method to constructs a new DisconnectPeer-variant ErrorAction
152 public static ErrorAction disconnect_peer(ErrorMessage msg) {
153 long ret = bindings.ErrorAction_disconnect_peer(msg == null ? 0 : msg.ptr & ~1);
154 Reference.reachabilityFence(msg);
155 if (ret >= 0 && ret <= 4096) { return null; }
156 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
157 ret_hu_conv.ptrs_to.add(ret_hu_conv);
162 * Utility method to constructs a new IgnoreError-variant ErrorAction
164 public static ErrorAction ignore_error() {
165 long ret = bindings.ErrorAction_ignore_error();
166 if (ret >= 0 && ret <= 4096) { return null; }
167 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
168 ret_hu_conv.ptrs_to.add(ret_hu_conv);
173 * Utility method to constructs a new IgnoreAndLog-variant ErrorAction
175 public static ErrorAction ignore_and_log(org.ldk.enums.Level a) {
176 long ret = bindings.ErrorAction_ignore_and_log(a);
177 Reference.reachabilityFence(a);
178 if (ret >= 0 && ret <= 4096) { return null; }
179 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
180 ret_hu_conv.ptrs_to.add(ret_hu_conv);
185 * Utility method to constructs a new IgnoreDuplicateGossip-variant ErrorAction
187 public static ErrorAction ignore_duplicate_gossip() {
188 long ret = bindings.ErrorAction_ignore_duplicate_gossip();
189 if (ret >= 0 && ret <= 4096) { return null; }
190 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
191 ret_hu_conv.ptrs_to.add(ret_hu_conv);
196 * Utility method to constructs a new SendErrorMessage-variant ErrorAction
198 public static ErrorAction send_error_message(ErrorMessage msg) {
199 long ret = bindings.ErrorAction_send_error_message(msg == null ? 0 : msg.ptr & ~1);
200 Reference.reachabilityFence(msg);
201 if (ret >= 0 && ret <= 4096) { return null; }
202 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
203 ret_hu_conv.ptrs_to.add(ret_hu_conv);
208 * Utility method to constructs a new SendWarningMessage-variant ErrorAction
210 public static ErrorAction send_warning_message(WarningMessage msg, org.ldk.enums.Level log_level) {
211 long ret = bindings.ErrorAction_send_warning_message(msg == null ? 0 : msg.ptr & ~1, log_level);
212 Reference.reachabilityFence(msg);
213 Reference.reachabilityFence(log_level);
214 if (ret >= 0 && ret <= 4096) { return null; }
215 org.ldk.structs.ErrorAction ret_hu_conv = org.ldk.structs.ErrorAction.constr_from_ptr(ret);
216 ret_hu_conv.ptrs_to.add(ret_hu_conv);