1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * Used to put an error message in a LightningError
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class ErrorAction extends CommonBase {
15 private ErrorAction(Object _dummy, long ptr) { super(ptr); }
16 @Override @SuppressWarnings("deprecation")
17 protected void finalize() throws Throwable {
19 if (ptr != 0) { bindings.ErrorAction_free(ptr); }
21 static ErrorAction constr_from_ptr(long ptr) {
22 bindings.LDKErrorAction raw_val = bindings.LDKErrorAction_ref_from_ptr(ptr);
23 if (raw_val.getClass() == bindings.LDKErrorAction.DisconnectPeer.class) {
24 return new DisconnectPeer(ptr, (bindings.LDKErrorAction.DisconnectPeer)raw_val);
26 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreError.class) {
27 return new IgnoreError(ptr, (bindings.LDKErrorAction.IgnoreError)raw_val);
29 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreAndLog.class) {
30 return new IgnoreAndLog(ptr, (bindings.LDKErrorAction.IgnoreAndLog)raw_val);
32 if (raw_val.getClass() == bindings.LDKErrorAction.SendErrorMessage.class) {
33 return new SendErrorMessage(ptr, (bindings.LDKErrorAction.SendErrorMessage)raw_val);
35 assert false; return null; // Unreachable without extending the (internal) bindings interface
39 * The peer took some action which made us think they were useless. Disconnect them.
41 public final static class DisconnectPeer extends ErrorAction {
43 * An error message which we should make an effort to send before we disconnect.
45 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
47 @Nullable public final ErrorMessage msg;
48 private DisconnectPeer(long ptr, bindings.LDKErrorAction.DisconnectPeer obj) {
51 ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ErrorMessage(null, msg); }
52 msg_hu_conv.ptrs_to.add(this);
53 this.msg = msg_hu_conv;
57 * The peer did something harmless that we weren't able to process, just log and ignore
59 public final static class IgnoreError extends ErrorAction {
60 private IgnoreError(long ptr, bindings.LDKErrorAction.IgnoreError obj) {
65 * The peer did something harmless that we weren't able to meaningfully process.
66 * If the error is logged, log it at the given level.
68 public final static class IgnoreAndLog extends ErrorAction {
69 public final Level ignore_and_log;
70 private IgnoreAndLog(long ptr, bindings.LDKErrorAction.IgnoreAndLog obj) {
72 this.ignore_and_log = obj.ignore_and_log;
76 * The peer did something incorrect. Tell them.
78 public final static class SendErrorMessage extends ErrorAction {
80 * The message to send.
82 public final ErrorMessage msg;
83 private SendErrorMessage(long ptr, bindings.LDKErrorAction.SendErrorMessage obj) {
86 ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ErrorMessage(null, msg); }
87 msg_hu_conv.ptrs_to.add(this);
88 this.msg = msg_hu_conv;
92 long ret = bindings.ErrorAction_clone_ptr(this.ptr);
97 * Creates a copy of the ErrorAction
99 public ErrorAction clone() {
100 long ret = bindings.ErrorAction_clone(this.ptr);
101 if (ret >= 0 && ret <= 4096) { return null; }
102 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
103 ret_hu_conv.ptrs_to.add(this);
108 * Utility method to constructs a new DisconnectPeer-variant ErrorAction
110 public static ErrorAction disconnect_peer(ErrorMessage msg) {
111 long ret = bindings.ErrorAction_disconnect_peer(msg == null ? 0 : msg.ptr & ~1);
112 if (ret >= 0 && ret <= 4096) { return null; }
113 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
114 ret_hu_conv.ptrs_to.add(ret_hu_conv);
119 * Utility method to constructs a new IgnoreError-variant ErrorAction
121 public static ErrorAction ignore_error() {
122 long ret = bindings.ErrorAction_ignore_error();
123 if (ret >= 0 && ret <= 4096) { return null; }
124 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
125 ret_hu_conv.ptrs_to.add(ret_hu_conv);
130 * Utility method to constructs a new IgnoreAndLog-variant ErrorAction
132 public static ErrorAction ignore_and_log(org.ldk.enums.Level a) {
133 long ret = bindings.ErrorAction_ignore_and_log(a);
134 if (ret >= 0 && ret <= 4096) { return null; }
135 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
136 ret_hu_conv.ptrs_to.add(ret_hu_conv);
141 * Utility method to constructs a new SendErrorMessage-variant ErrorAction
143 public static ErrorAction send_error_message(ErrorMessage msg) {
144 long ret = bindings.ErrorAction_send_error_message(msg == null ? 0 : msg.ptr & ~1);
145 if (ret >= 0 && ret <= 4096) { return null; }
146 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
147 ret_hu_conv.ptrs_to.add(ret_hu_conv);