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 assert false; return null; // Unreachable without extending the (internal) bindings interface
43 * The peer took some action which made us think they were useless. Disconnect them.
45 public final static class DisconnectPeer extends ErrorAction {
47 * An error message which we should make an effort to send before we disconnect.
49 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
51 @Nullable public final ErrorMessage msg;
52 private DisconnectPeer(long ptr, bindings.LDKErrorAction.DisconnectPeer obj) {
55 ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ErrorMessage(null, msg); }
56 msg_hu_conv.ptrs_to.add(this);
57 this.msg = msg_hu_conv;
61 * The peer did something harmless that we weren't able to process, just log and ignore
63 public final static class IgnoreError extends ErrorAction {
64 private IgnoreError(long ptr, bindings.LDKErrorAction.IgnoreError obj) {
69 * The peer did something harmless that we weren't able to meaningfully process.
70 * If the error is logged, log it at the given level.
72 public final static class IgnoreAndLog extends ErrorAction {
73 public final Level ignore_and_log;
74 private IgnoreAndLog(long ptr, bindings.LDKErrorAction.IgnoreAndLog obj) {
76 this.ignore_and_log = obj.ignore_and_log;
80 * The peer provided us with a gossip message which we'd already seen. In most cases this
81 * should be ignored, but it may result in the message being forwarded if it is a duplicate of
82 * our own channel announcements.
84 public final static class IgnoreDuplicateGossip extends ErrorAction {
85 private IgnoreDuplicateGossip(long ptr, bindings.LDKErrorAction.IgnoreDuplicateGossip obj) {
90 * The peer did something incorrect. Tell them.
92 public final static class SendErrorMessage extends ErrorAction {
94 * The message to send.
96 public final ErrorMessage msg;
97 private SendErrorMessage(long ptr, bindings.LDKErrorAction.SendErrorMessage obj) {
100 ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ErrorMessage(null, msg); }
101 msg_hu_conv.ptrs_to.add(this);
102 this.msg = msg_hu_conv;
106 long ret = bindings.ErrorAction_clone_ptr(this.ptr);
107 Reference.reachabilityFence(this);
112 * Creates a copy of the ErrorAction
114 public ErrorAction clone() {
115 long ret = bindings.ErrorAction_clone(this.ptr);
116 Reference.reachabilityFence(this);
117 if (ret >= 0 && ret <= 4096) { return null; }
118 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
119 ret_hu_conv.ptrs_to.add(this);
124 * Utility method to constructs a new DisconnectPeer-variant ErrorAction
126 public static ErrorAction disconnect_peer(ErrorMessage msg) {
127 long ret = bindings.ErrorAction_disconnect_peer(msg == null ? 0 : msg.ptr & ~1);
128 Reference.reachabilityFence(msg);
129 if (ret >= 0 && ret <= 4096) { return null; }
130 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
131 ret_hu_conv.ptrs_to.add(ret_hu_conv);
136 * Utility method to constructs a new IgnoreError-variant ErrorAction
138 public static ErrorAction ignore_error() {
139 long ret = bindings.ErrorAction_ignore_error();
140 if (ret >= 0 && ret <= 4096) { return null; }
141 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
142 ret_hu_conv.ptrs_to.add(ret_hu_conv);
147 * Utility method to constructs a new IgnoreAndLog-variant ErrorAction
149 public static ErrorAction ignore_and_log(org.ldk.enums.Level a) {
150 long ret = bindings.ErrorAction_ignore_and_log(a);
151 Reference.reachabilityFence(a);
152 if (ret >= 0 && ret <= 4096) { return null; }
153 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
154 ret_hu_conv.ptrs_to.add(ret_hu_conv);
159 * Utility method to constructs a new IgnoreDuplicateGossip-variant ErrorAction
161 public static ErrorAction ignore_duplicate_gossip() {
162 long ret = bindings.ErrorAction_ignore_duplicate_gossip();
163 if (ret >= 0 && ret <= 4096) { return null; }
164 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
165 ret_hu_conv.ptrs_to.add(ret_hu_conv);
170 * Utility method to constructs a new SendErrorMessage-variant ErrorAction
172 public static ErrorAction send_error_message(ErrorMessage msg) {
173 long ret = bindings.ErrorAction_send_error_message(msg == null ? 0 : msg.ptr & ~1);
174 Reference.reachabilityFence(msg);
175 if (ret >= 0 && ret <= 4096) { return null; }
176 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
177 ret_hu_conv.ptrs_to.add(ret_hu_conv);