[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / OnionMessageHandler.cs
1
2 using org.ldk.impl;
3 using org.ldk.enums;
4 using org.ldk.util;
5 using System;
6
7 namespace org { namespace ldk { namespace structs {
8
9
10
11 /** An implementation of OnionMessageHandler */
12 public interface OnionMessageHandlerInterface {
13         /**Handle an incoming `onion_message` message from the given peer.
14          */
15         void handle_onion_message(byte[] peer_node_id, OnionMessage msg);
16         /**Returns the next pending onion message for the peer with the given node id.
17          * 
18          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
19          */
20         OnionMessage next_onion_message_for_peer(byte[] peer_node_id);
21         /**Called when a connection is established with a peer. Can be used to track which peers
22          * advertise onion message support and are online.
23          * 
24          * May return an `Err(())` if the features the peer supports are not sufficient to communicate
25          * with us. Implementors should be somewhat conservative about doing so, however, as other
26          * message handlers may still wish to communicate with this peer.
27          */
28         Result_NoneNoneZ peer_connected(byte[] their_node_id, Init init, bool inbound);
29         /**Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to
30          * drop and refuse to forward onion messages to this peer.
31          */
32         void peer_disconnected(byte[] their_node_id);
33         /**Gets the node feature flags which this handler itself supports. All available handlers are
34          * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
35          * which are broadcasted in our [`NodeAnnouncement`] message.
36          */
37         NodeFeatures provided_node_features();
38         /**Gets the init feature flags which should be sent to the given peer. All available handlers
39          * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
40          * which are sent in our [`Init`] message.
41          * 
42          * Note that this method is called before [`Self::peer_connected`].
43          */
44         InitFeatures provided_init_features(byte[] their_node_id);
45 }
46
47 /**
48  * A handler for received [`OnionMessage`]s and for providing generated ones to send.
49  */
50 public class OnionMessageHandler : CommonBase {
51         internal bindings.LDKOnionMessageHandler bindings_instance;
52         internal long instance_idx;
53
54         internal OnionMessageHandler(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
55         ~OnionMessageHandler() {
56                 if (ptr != 0) { bindings.OnionMessageHandler_free(ptr); }
57         }
58
59         private class LDKOnionMessageHandlerHolder { internal OnionMessageHandler held; }
60         private class LDKOnionMessageHandlerImpl : bindings.LDKOnionMessageHandler {
61                 internal LDKOnionMessageHandlerImpl(OnionMessageHandlerInterface arg, LDKOnionMessageHandlerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
62                 private OnionMessageHandlerInterface arg;
63                 private LDKOnionMessageHandlerHolder impl_holder;
64                 public void handle_onion_message(long _peer_node_id, long _msg) {
65                         byte[] _peer_node_id_conv = InternalUtils.decodeUint8Array(_peer_node_id);
66                         org.ldk.structs.OnionMessage _msg_hu_conv = null; if (_msg < 0 || _msg > 4096) { _msg_hu_conv = new org.ldk.structs.OnionMessage(null, _msg); }
67                         arg.handle_onion_message(_peer_node_id_conv, _msg_hu_conv);
68                                 GC.KeepAlive(arg);
69                 }
70                 public long next_onion_message_for_peer(long _peer_node_id) {
71                         byte[] _peer_node_id_conv = InternalUtils.decodeUint8Array(_peer_node_id);
72                         OnionMessage ret = arg.next_onion_message_for_peer(_peer_node_id_conv);
73                                 GC.KeepAlive(arg);
74                         long result = ret == null ? 0 : ret.clone_ptr();
75                         return result;
76                 }
77                 public long peer_connected(long _their_node_id, long _init, bool _inbound) {
78                         byte[] _their_node_id_conv = InternalUtils.decodeUint8Array(_their_node_id);
79                         org.ldk.structs.Init _init_hu_conv = null; if (_init < 0 || _init > 4096) { _init_hu_conv = new org.ldk.structs.Init(null, _init); }
80                         Result_NoneNoneZ ret = arg.peer_connected(_their_node_id_conv, _init_hu_conv, _inbound);
81                                 GC.KeepAlive(arg);
82                         long result = ret == null ? 0 : ret.clone_ptr();
83                         return result;
84                 }
85                 public void peer_disconnected(long _their_node_id) {
86                         byte[] _their_node_id_conv = InternalUtils.decodeUint8Array(_their_node_id);
87                         arg.peer_disconnected(_their_node_id_conv);
88                                 GC.KeepAlive(arg);
89                 }
90                 public long provided_node_features() {
91                         NodeFeatures ret = arg.provided_node_features();
92                                 GC.KeepAlive(arg);
93                         long result = ret == null ? 0 : ret.clone_ptr();
94                         return result;
95                 }
96                 public long provided_init_features(long _their_node_id) {
97                         byte[] _their_node_id_conv = InternalUtils.decodeUint8Array(_their_node_id);
98                         InitFeatures ret = arg.provided_init_features(_their_node_id_conv);
99                                 GC.KeepAlive(arg);
100                         long result = ret == null ? 0 : ret.clone_ptr();
101                         return result;
102                 }
103         }
104
105         /** Creates a new instance of OnionMessageHandler from a given implementation */
106         public static OnionMessageHandler new_impl(OnionMessageHandlerInterface arg) {
107                 LDKOnionMessageHandlerHolder impl_holder = new LDKOnionMessageHandlerHolder();
108                 LDKOnionMessageHandlerImpl impl = new LDKOnionMessageHandlerImpl(arg, impl_holder);
109                 long[] ptr_idx = bindings.LDKOnionMessageHandler_new(impl);
110
111                 impl_holder.held = new OnionMessageHandler(null, ptr_idx[0]);
112                 impl_holder.held.instance_idx = ptr_idx[1];
113                 impl_holder.held.bindings_instance = impl;
114                 return impl_holder.held;
115         }
116
117         /**
118          * Handle an incoming `onion_message` message from the given peer.
119          */
120         public void handle_onion_message(byte[] peer_node_id, org.ldk.structs.OnionMessage msg) {
121                 bindings.OnionMessageHandler_handle_onion_message(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(peer_node_id, 33)), msg == null ? 0 : msg.ptr);
122                 GC.KeepAlive(this);
123                 GC.KeepAlive(peer_node_id);
124                 GC.KeepAlive(msg);
125                 if (this != null) { this.ptrs_to.AddLast(msg); };
126         }
127
128         /**
129          * Returns the next pending onion message for the peer with the given node id.
130          * 
131          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
132          */
133         public OnionMessage next_onion_message_for_peer(byte[] peer_node_id) {
134                 long ret = bindings.OnionMessageHandler_next_onion_message_for_peer(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(peer_node_id, 33)));
135                 GC.KeepAlive(this);
136                 GC.KeepAlive(peer_node_id);
137                 if (ret >= 0 && ret <= 4096) { return null; }
138                 org.ldk.structs.OnionMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OnionMessage(null, ret); }
139                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
140                 return ret_hu_conv;
141         }
142
143         /**
144          * Called when a connection is established with a peer. Can be used to track which peers
145          * advertise onion message support and are online.
146          * 
147          * May return an `Err(())` if the features the peer supports are not sufficient to communicate
148          * with us. Implementors should be somewhat conservative about doing so, however, as other
149          * message handlers may still wish to communicate with this peer.
150          */
151         public Result_NoneNoneZ peer_connected(byte[] their_node_id, org.ldk.structs.Init init, bool inbound) {
152                 long ret = bindings.OnionMessageHandler_peer_connected(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(their_node_id, 33)), init == null ? 0 : init.ptr, inbound);
153                 GC.KeepAlive(this);
154                 GC.KeepAlive(their_node_id);
155                 GC.KeepAlive(init);
156                 GC.KeepAlive(inbound);
157                 if (ret >= 0 && ret <= 4096) { return null; }
158                 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
159                 if (this != null) { this.ptrs_to.AddLast(init); };
160                 return ret_hu_conv;
161         }
162
163         /**
164          * Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to
165          * drop and refuse to forward onion messages to this peer.
166          */
167         public void peer_disconnected(byte[] their_node_id) {
168                 bindings.OnionMessageHandler_peer_disconnected(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(their_node_id, 33)));
169                 GC.KeepAlive(this);
170                 GC.KeepAlive(their_node_id);
171         }
172
173         /**
174          * Gets the node feature flags which this handler itself supports. All available handlers are
175          * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
176          * which are broadcasted in our [`NodeAnnouncement`] message.
177          */
178         public NodeFeatures provided_node_features() {
179                 long ret = bindings.OnionMessageHandler_provided_node_features(this.ptr);
180                 GC.KeepAlive(this);
181                 if (ret >= 0 && ret <= 4096) { return null; }
182                 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
183                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
184                 return ret_hu_conv;
185         }
186
187         /**
188          * Gets the init feature flags which should be sent to the given peer. All available handlers
189          * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
190          * which are sent in our [`Init`] message.
191          * 
192          * Note that this method is called before [`Self::peer_connected`].
193          */
194         public InitFeatures provided_init_features(byte[] their_node_id) {
195                 long ret = bindings.OnionMessageHandler_provided_init_features(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(their_node_id, 33)));
196                 GC.KeepAlive(this);
197                 GC.KeepAlive(their_node_id);
198                 if (ret >= 0 && ret <= 4096) { return null; }
199                 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
200                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
201                 return ret_hu_conv;
202         }
203
204 }
205 } } }