Add some additional writing hooks which C# needs
[ldk-java] / src / main / java / org / ldk / structs / ChannelMessageHandler.java
index 0e5c15bbfb43da4aef32de0d9574f5b70599328d..b8367adc84aa20464577ae03a856b9cc124779e9 100644 (file)
@@ -94,12 +94,19 @@ public class ChannelMessageHandler extends CommonBase {
                 * is believed to be possible in the future (eg they're sending us messages we don't
                 * understand or indicate they require unknown feature bits), no_connection_possible is set
                 * and any outstanding channels should be failed.
+                * 
+                * Note that in some rare cases this may be called without a corresponding
+                * [`Self::peer_connected`].
                 */
                void peer_disconnected(byte[] their_node_id, boolean no_connection_possible);
                /**
                 * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
+                * 
+                * May return an `Err(())` if the features the peer supports are not sufficient to communicate
+                * with us. Implementors should be somewhat conservative about doing so, however, as other
+                * message handlers may still wish to communicate with this peer.
                 */
-               void peer_connected(byte[] their_node_id, Init msg);
+               Result_NoneNoneZ peer_connected(byte[] their_node_id, Init msg);
                /**
                 * Handle an incoming channel_reestablish message from the given peer.
                 */
@@ -112,6 +119,20 @@ public class ChannelMessageHandler extends CommonBase {
                 * Handle an incoming error message from the given peer.
                 */
                void handle_error(byte[] their_node_id, ErrorMessage msg);
+               /**
+                * Gets the node feature flags which this handler itself supports. All available handlers are
+                * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
+                * which are broadcasted in our [`NodeAnnouncement`] message.
+                */
+               NodeFeatures provided_node_features();
+               /**
+                * Gets the init feature flags which should be sent to the given peer. All available handlers
+                * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
+                * which are sent in our [`Init`] message.
+                * 
+                * Note that this method is called before [`Self::peer_connected`].
+                */
+               InitFeatures provided_init_features(byte[] their_node_id);
        }
        private static class LDKChannelMessageHandlerHolder { ChannelMessageHandler held; }
        public static ChannelMessageHandler new_impl(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
@@ -119,14 +140,14 @@ public class ChannelMessageHandler extends CommonBase {
                impl_holder.held = new ChannelMessageHandler(new bindings.LDKChannelMessageHandler() {
                        @Override public void handle_open_channel(byte[] their_node_id, long their_features, long msg) {
                                org.ldk.structs.InitFeatures their_features_hu_conv = null; if (their_features < 0 || their_features > 4096) { their_features_hu_conv = new org.ldk.structs.InitFeatures(null, their_features); }
-                               their_features_hu_conv.ptrs_to.add(this);
+                               if (their_features_hu_conv != null) { their_features_hu_conv.ptrs_to.add(this); };
                                org.ldk.structs.OpenChannel msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.OpenChannel(null, msg); }
                                arg.handle_open_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
                                Reference.reachabilityFence(arg);
                        }
                        @Override public void handle_accept_channel(byte[] their_node_id, long their_features, long msg) {
                                org.ldk.structs.InitFeatures their_features_hu_conv = null; if (their_features < 0 || their_features > 4096) { their_features_hu_conv = new org.ldk.structs.InitFeatures(null, their_features); }
-                               their_features_hu_conv.ptrs_to.add(this);
+                               if (their_features_hu_conv != null) { their_features_hu_conv.ptrs_to.add(this); };
                                org.ldk.structs.AcceptChannel msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.AcceptChannel(null, msg); }
                                arg.handle_accept_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
                                Reference.reachabilityFence(arg);
@@ -201,10 +222,12 @@ public class ChannelMessageHandler extends CommonBase {
                                arg.peer_disconnected(their_node_id, no_connection_possible);
                                Reference.reachabilityFence(arg);
                        }
-                       @Override public void peer_connected(byte[] their_node_id, long msg) {
+                       @Override public long peer_connected(byte[] their_node_id, long msg) {
                                org.ldk.structs.Init msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.Init(null, msg); }
-                               arg.peer_connected(their_node_id, msg_hu_conv);
+                               Result_NoneNoneZ ret = arg.peer_connected(their_node_id, msg_hu_conv);
                                Reference.reachabilityFence(arg);
+                               long result = ret == null ? 0 : ret.clone_ptr();
+                               return result;
                        }
                        @Override public void handle_channel_reestablish(byte[] their_node_id, long msg) {
                                org.ldk.structs.ChannelReestablish msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ChannelReestablish(null, msg); }
@@ -221,6 +244,18 @@ public class ChannelMessageHandler extends CommonBase {
                                arg.handle_error(their_node_id, msg_hu_conv);
                                Reference.reachabilityFence(arg);
                        }
+                       @Override public long provided_node_features() {
+                               NodeFeatures ret = arg.provided_node_features();
+                               Reference.reachabilityFence(arg);
+                               long result = ret == null ? 0 : ret.clone_ptr();
+                               return result;
+                       }
+                       @Override public long provided_init_features(byte[] their_node_id) {
+                               InitFeatures ret = arg.provided_init_features(their_node_id);
+                               Reference.reachabilityFence(arg);
+                               long result = ret == null ? 0 : ret.clone_ptr();
+                               return result;
+                       }
                }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
                return impl_holder.held;
        }
@@ -243,8 +278,8 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(their_features);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(their_features);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(their_features); };
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -256,8 +291,8 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(their_features);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(their_features);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(their_features); };
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -268,7 +303,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -279,7 +314,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -290,7 +325,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -302,8 +337,8 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(their_features);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(their_features);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(their_features); };
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -314,7 +349,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -325,7 +360,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -336,7 +371,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -347,7 +382,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -358,7 +393,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -369,7 +404,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -380,7 +415,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -391,7 +426,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -402,7 +437,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -410,6 +445,9 @@ public class ChannelMessageHandler extends CommonBase {
         * is believed to be possible in the future (eg they're sending us messages we don't
         * understand or indicate they require unknown feature bits), no_connection_possible is set
         * and any outstanding channels should be failed.
+        * 
+        * Note that in some rare cases this may be called without a corresponding
+        * [`Self::peer_connected`].
         */
        public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
                bindings.ChannelMessageHandler_peer_disconnected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), no_connection_possible);
@@ -420,13 +458,20 @@ public class ChannelMessageHandler extends CommonBase {
 
        /**
         * Handle a peer reconnecting, possibly generating channel_reestablish message(s).
+        * 
+        * May return an `Err(())` if the features the peer supports are not sufficient to communicate
+        * with us. Implementors should be somewhat conservative about doing so, however, as other
+        * message handlers may still wish to communicate with this peer.
         */
-       public void peer_connected(byte[] their_node_id, Init msg) {
-               bindings.ChannelMessageHandler_peer_connected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
+       public Result_NoneNoneZ peer_connected(byte[] their_node_id, Init msg) {
+               long ret = bindings.ChannelMessageHandler_peer_connected(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : msg.ptr);
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (ret >= 0 && ret <= 4096) { return null; }
+               Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
+               if (this != null) { this.ptrs_to.add(msg); };
+               return ret_hu_conv;
        }
 
        /**
@@ -437,7 +482,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -448,7 +493,7 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
        }
 
        /**
@@ -459,7 +504,38 @@ public class ChannelMessageHandler extends CommonBase {
                Reference.reachabilityFence(this);
                Reference.reachabilityFence(their_node_id);
                Reference.reachabilityFence(msg);
-               this.ptrs_to.add(msg);
+               if (this != null) { this.ptrs_to.add(msg); };
+       }
+
+       /**
+        * Gets the node feature flags which this handler itself supports. All available handlers are
+        * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
+        * which are broadcasted in our [`NodeAnnouncement`] message.
+        */
+       public NodeFeatures provided_node_features() {
+               long ret = bindings.ChannelMessageHandler_provided_node_features(this.ptr);
+               Reference.reachabilityFence(this);
+               if (ret >= 0 && ret <= 4096) { return null; }
+               org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
+               return ret_hu_conv;
+       }
+
+       /**
+        * Gets the init feature flags which should be sent to the given peer. All available handlers
+        * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
+        * which are sent in our [`Init`] message.
+        * 
+        * Note that this method is called before [`Self::peer_connected`].
+        */
+       public InitFeatures provided_init_features(byte[] their_node_id) {
+               long ret = bindings.ChannelMessageHandler_provided_init_features(this.ptr, InternalUtils.check_arr_len(their_node_id, 33));
+               Reference.reachabilityFence(this);
+               Reference.reachabilityFence(their_node_id);
+               if (ret >= 0 && ret <= 4096) { return null; }
+               org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
+               return ret_hu_conv;
        }
 
 }