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