b7e592dd9d630c6628a6ab1e19f50b900f906e1c
[ldk-java] / src / main / java / org / ldk / structs / ErrorAction.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * Used to put an error message in a LightningError
13  */
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 {
19                 super.finalize();
20                 if (ptr != 0) { bindings.ErrorAction_free(ptr); }
21         }
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);
26                 }
27                 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreError.class) {
28                         return new IgnoreError(ptr, (bindings.LDKErrorAction.IgnoreError)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreAndLog.class) {
31                         return new IgnoreAndLog(ptr, (bindings.LDKErrorAction.IgnoreAndLog)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreDuplicateGossip.class) {
34                         return new IgnoreDuplicateGossip(ptr, (bindings.LDKErrorAction.IgnoreDuplicateGossip)raw_val);
35                 }
36                 if (raw_val.getClass() == bindings.LDKErrorAction.SendErrorMessage.class) {
37                         return new SendErrorMessage(ptr, (bindings.LDKErrorAction.SendErrorMessage)raw_val);
38                 }
39                 assert false; return null; // Unreachable without extending the (internal) bindings interface
40         }
41
42         /**
43          * The peer took some action which made us think they were useless. Disconnect them.
44          */
45         public final static class DisconnectPeer extends ErrorAction {
46                 /**
47                  * An error message which we should make an effort to send before we disconnect.
48                  * 
49                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
50                 */
51                 @Nullable public final ErrorMessage msg;
52                 private DisconnectPeer(long ptr, bindings.LDKErrorAction.DisconnectPeer obj) {
53                         super(null, ptr);
54                         long msg = obj.msg;
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;
58                 }
59         }
60         /**
61          * The peer did something harmless that we weren't able to process, just log and ignore
62          */
63         public final static class IgnoreError extends ErrorAction {
64                 private IgnoreError(long ptr, bindings.LDKErrorAction.IgnoreError obj) {
65                         super(null, ptr);
66                 }
67         }
68         /**
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.
71          */
72         public final static class IgnoreAndLog extends ErrorAction {
73                 public final Level ignore_and_log;
74                 private IgnoreAndLog(long ptr, bindings.LDKErrorAction.IgnoreAndLog obj) {
75                         super(null, ptr);
76                         this.ignore_and_log = obj.ignore_and_log;
77                 }
78         }
79         /**
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.
83          */
84         public final static class IgnoreDuplicateGossip extends ErrorAction {
85                 private IgnoreDuplicateGossip(long ptr, bindings.LDKErrorAction.IgnoreDuplicateGossip obj) {
86                         super(null, ptr);
87                 }
88         }
89         /**
90          * The peer did something incorrect. Tell them.
91          */
92         public final static class SendErrorMessage extends ErrorAction {
93                 /**
94                  * The message to send.
95                 */
96                 public final ErrorMessage msg;
97                 private SendErrorMessage(long ptr, bindings.LDKErrorAction.SendErrorMessage obj) {
98                         super(null, ptr);
99                         long msg = obj.msg;
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;
103                 }
104         }
105         long clone_ptr() {
106                 long ret = bindings.ErrorAction_clone_ptr(this.ptr);
107                 Reference.reachabilityFence(this);
108                 return ret;
109         }
110
111         /**
112          * Creates a copy of the ErrorAction
113          */
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);
120                 return ret_hu_conv;
121         }
122
123         /**
124          * Utility method to constructs a new DisconnectPeer-variant ErrorAction
125          */
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);
132                 return ret_hu_conv;
133         }
134
135         /**
136          * Utility method to constructs a new IgnoreError-variant ErrorAction
137          */
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);
143                 return ret_hu_conv;
144         }
145
146         /**
147          * Utility method to constructs a new IgnoreAndLog-variant ErrorAction
148          */
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);
155                 return ret_hu_conv;
156         }
157
158         /**
159          * Utility method to constructs a new IgnoreDuplicateGossip-variant ErrorAction
160          */
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);
166                 return ret_hu_conv;
167         }
168
169         /**
170          * Utility method to constructs a new SendErrorMessage-variant ErrorAction
171          */
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);
178                 return ret_hu_conv;
179         }
180
181 }