[Java] Update auto-generated Java files
[ldk-java] / src / main / java / org / ldk / structs / OnionMessageHandler.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  * A trait to describe an object that can receive onion messages.
12  */
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class OnionMessageHandler extends CommonBase {
15         final bindings.LDKOnionMessageHandler bindings_instance;
16         OnionMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17         private OnionMessageHandler(bindings.LDKOnionMessageHandler arg, bindings.LDKOnionMessageProvider OnionMessageProvider) {
18                 super(bindings.LDKOnionMessageHandler_new(arg, OnionMessageProvider));
19                 this.ptrs_to.add(arg);
20                 this.ptrs_to.add(OnionMessageProvider);
21                 this.bindings_instance = arg;
22         }
23         @Override @SuppressWarnings("deprecation")
24         protected void finalize() throws Throwable {
25                 if (ptr != 0) { bindings.OnionMessageHandler_free(ptr); } super.finalize();
26         }
27
28         public static interface OnionMessageHandlerInterface {
29                 /**
30                  * Handle an incoming onion_message message from the given peer.
31                  */
32                 void handle_onion_message(byte[] peer_node_id, OnionMessage msg);
33                 /**
34                  * Called when a connection is established with a peer. Can be used to track which peers
35                  * advertise onion message support and are online.
36                  */
37                 void peer_connected(byte[] their_node_id, Init init);
38                 /**
39                  * Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to
40                  * drop and refuse to forward onion messages to this peer.
41                  */
42                 void peer_disconnected(byte[] their_node_id, boolean no_connection_possible);
43                 /**
44                  * Gets the node feature flags which this handler itself supports. All available handlers are
45                  * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
46                  * which are broadcasted in our [`NodeAnnouncement`] message.
47                  */
48                 NodeFeatures provided_node_features();
49                 /**
50                  * Gets the init feature flags which should be sent to the given peer. All available handlers
51                  * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
52                  * which are sent in our [`Init`] message.
53                  * 
54                  * Note that this method is called before [`Self::peer_connected`].
55                  */
56                 InitFeatures provided_init_features(byte[] their_node_id);
57         }
58         private static class LDKOnionMessageHandlerHolder { OnionMessageHandler held; }
59         public static OnionMessageHandler new_impl(OnionMessageHandlerInterface arg, OnionMessageProvider.OnionMessageProviderInterface OnionMessageProvider_impl) {
60                 final LDKOnionMessageHandlerHolder impl_holder = new LDKOnionMessageHandlerHolder();
61                 impl_holder.held = new OnionMessageHandler(new bindings.LDKOnionMessageHandler() {
62                         @Override public void handle_onion_message(byte[] peer_node_id, long msg) {
63                                 org.ldk.structs.OnionMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.OnionMessage(null, msg); }
64                                 arg.handle_onion_message(peer_node_id, msg_hu_conv);
65                                 Reference.reachabilityFence(arg);
66                         }
67                         @Override public void peer_connected(byte[] their_node_id, long init) {
68                                 org.ldk.structs.Init init_hu_conv = null; if (init < 0 || init > 4096) { init_hu_conv = new org.ldk.structs.Init(null, init); }
69                                 arg.peer_connected(their_node_id, init_hu_conv);
70                                 Reference.reachabilityFence(arg);
71                         }
72                         @Override public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
73                                 arg.peer_disconnected(their_node_id, no_connection_possible);
74                                 Reference.reachabilityFence(arg);
75                         }
76                         @Override public long provided_node_features() {
77                                 NodeFeatures ret = arg.provided_node_features();
78                                 Reference.reachabilityFence(arg);
79                                 long result = ret == null ? 0 : ret.clone_ptr();
80                                 return result;
81                         }
82                         @Override public long provided_init_features(byte[] their_node_id) {
83                                 InitFeatures ret = arg.provided_init_features(their_node_id);
84                                 Reference.reachabilityFence(arg);
85                                 long result = ret == null ? 0 : ret.clone_ptr();
86                                 return result;
87                         }
88                 }, OnionMessageProvider.new_impl(OnionMessageProvider_impl).bindings_instance);
89                 return impl_holder.held;
90         }
91
92         /**
93          * Gets the underlying OnionMessageProvider.
94          */
95         public OnionMessageProvider get_onion_message_provider() {
96                 OnionMessageProvider res = new OnionMessageProvider(null, bindings.LDKOnionMessageHandler_get_OnionMessageProvider(this.ptr));
97                 this.ptrs_to.add(res);
98                 return res;
99         }
100
101         /**
102          * Handle an incoming onion_message message from the given peer.
103          */
104         public void handle_onion_message(byte[] peer_node_id, OnionMessage msg) {
105                 bindings.OnionMessageHandler_handle_onion_message(this.ptr, InternalUtils.check_arr_len(peer_node_id, 33), msg == null ? 0 : msg.ptr);
106                 Reference.reachabilityFence(this);
107                 Reference.reachabilityFence(peer_node_id);
108                 Reference.reachabilityFence(msg);
109                 if (this != null) { this.ptrs_to.add(msg); };
110         }
111
112         /**
113          * Called when a connection is established with a peer. Can be used to track which peers
114          * advertise onion message support and are online.
115          */
116         public void peer_connected(byte[] their_node_id, Init init) {
117                 bindings.OnionMessageHandler_peer_connected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), init == null ? 0 : init.ptr);
118                 Reference.reachabilityFence(this);
119                 Reference.reachabilityFence(their_node_id);
120                 Reference.reachabilityFence(init);
121                 if (this != null) { this.ptrs_to.add(init); };
122         }
123
124         /**
125          * Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to
126          * drop and refuse to forward onion messages to this peer.
127          */
128         public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
129                 bindings.OnionMessageHandler_peer_disconnected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), no_connection_possible);
130                 Reference.reachabilityFence(this);
131                 Reference.reachabilityFence(their_node_id);
132                 Reference.reachabilityFence(no_connection_possible);
133         }
134
135         /**
136          * Gets the node feature flags which this handler itself supports. All available handlers are
137          * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
138          * which are broadcasted in our [`NodeAnnouncement`] message.
139          */
140         public NodeFeatures provided_node_features() {
141                 long ret = bindings.OnionMessageHandler_provided_node_features(this.ptr);
142                 Reference.reachabilityFence(this);
143                 if (ret >= 0 && ret <= 4096) { return null; }
144                 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
145                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
146                 return ret_hu_conv;
147         }
148
149         /**
150          * Gets the init feature flags which should be sent to the given peer. All available handlers
151          * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
152          * which are sent in our [`Init`] message.
153          * 
154          * Note that this method is called before [`Self::peer_connected`].
155          */
156         public InitFeatures provided_init_features(byte[] their_node_id) {
157                 long ret = bindings.OnionMessageHandler_provided_init_features(this.ptr, InternalUtils.check_arr_len(their_node_id, 33));
158                 Reference.reachabilityFence(this);
159                 Reference.reachabilityFence(their_node_id);
160                 if (ret >= 0 && ret <= 4096) { return null; }
161                 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
162                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
163                 return ret_hu_conv;
164         }
165
166 }