[TS] Update auto-generated TypeScript Bindings
[ldk-java] / ts / structs / RoutingMessageHandler.mts
index c15facf14cca4e88bed3392646102d09d1e24d28..7eb2c16a74da7e66947ca9d6ea851e7a9c5a79a6 100644 (file)
@@ -280,20 +280,59 @@ import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScor
 
 import CommonBase from './CommonBase.mjs';
 import * as bindings from '../bindings.mjs'
-import * as InternalUtils from '../InternalUtils.mjs'
 
 
 
+/** An implementation of RoutingMessageHandler */
 export interface RoutingMessageHandlerInterface {
+       /**Handle an incoming node_announcement message, returning true if it should be forwarded on,
+        * false or returning an Err otherwise.
+        */
        handle_node_announcement(msg: NodeAnnouncement): Result_boolLightningErrorZ;
+       /**Handle a channel_announcement message, returning true if it should be forwarded on, false
+        * or returning an Err otherwise.
+        */
        handle_channel_announcement(msg: ChannelAnnouncement): Result_boolLightningErrorZ;
+       /**Handle an incoming channel_update message, returning true if it should be forwarded on,
+        * false or returning an Err otherwise.
+        */
        handle_channel_update(msg: ChannelUpdate): Result_boolLightningErrorZ;
-       get_next_channel_announcements(starting_point: number, batch_amount: number): ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ[];
+       /**Gets a subset of the channel announcements and updates required to dump our routing table
+        * to a remote node, starting at the short_channel_id indicated by starting_point and
+        * including the batch_amount entries immediately higher in numerical value than starting_point.
+        */
+       get_next_channel_announcements(starting_point: bigint, batch_amount: number): ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ[];
+       /**Gets a subset of the node announcements required to dump our routing table to a remote node,
+        * starting at the node *after* the provided publickey and including batch_amount entries
+        * immediately higher (as defined by <PublicKey as Ord>::cmp) than starting_point.
+        * If None is provided for starting_point, we start at the first node.
+        * 
+        * Note that starting_point (or a relevant inner pointer) may be NULL or all-0s to represent None
+        */
        get_next_node_announcements(starting_point: Uint8Array, batch_amount: number): NodeAnnouncement[];
+       /**Called when a connection is established with a peer. This can be used to
+        * perform routing table synchronization using a strategy defined by the
+        * implementor.
+        */
        sync_routing_table(their_node_id: Uint8Array, init: Init): void;
+       /**Handles the reply of a query we initiated to learn about channels
+        * for a given range of blocks. We can expect to receive one or more
+        * replies to a single query.
+        */
        handle_reply_channel_range(their_node_id: Uint8Array, msg: ReplyChannelRange): Result_NoneLightningErrorZ;
+       /**Handles the reply of a query we initiated asking for routing gossip
+        * messages for a list of channels. We should receive this message when
+        * a node has completed its best effort to send us the pertaining routing
+        * gossip messages.
+        */
        handle_reply_short_channel_ids_end(their_node_id: Uint8Array, msg: ReplyShortChannelIdsEnd): Result_NoneLightningErrorZ;
+       /**Handles when a peer asks us to send a list of short_channel_ids
+        * for the requested range of blocks.
+        */
        handle_query_channel_range(their_node_id: Uint8Array, msg: QueryChannelRange): Result_NoneLightningErrorZ;
+       /**Handles when a peer asks us to send routing gossip messages for a
+        * list of short_channel_ids.
+        */
        handle_query_short_channel_ids(their_node_id: Uint8Array, msg: QueryShortChannelIds): Result_NoneLightningErrorZ;
 }
 
@@ -301,6 +340,15 @@ class LDKRoutingMessageHandlerHolder {
        held: RoutingMessageHandler;
 }
 
+/**
+ * A trait to describe an object which can receive routing messages.
+ * 
+ * # Implementor DoS Warnings
+ * 
+ * For `gossip_queries` messages there are potential DoS vectors when handling
+ * inbound queries. Implementors using an on-disk network graph should be aware of
+ * repeated disk I/O for queries accessing different parts of the network graph.
+ */
 export class RoutingMessageHandler extends CommonBase {
        /* @internal */
        public bindings_instance?: bindings.LDKRoutingMessageHandler;
@@ -311,7 +359,8 @@ export class RoutingMessageHandler extends CommonBase {
                this.bindings_instance = null;
        }
 
-       static new_impl(arg: RoutingMessageHandlerInterface, messageSendEventsProvider_impl: MessageSendEventsProviderInterface): RoutingMessageHandler {
+       /** Creates a new instance of RoutingMessageHandler from a given implementation */
+       public static new_impl(arg: RoutingMessageHandlerInterface, messageSendEventsProvider_impl: MessageSendEventsProviderInterface): RoutingMessageHandler {
                const impl_holder: LDKRoutingMessageHandlerHolder = new LDKRoutingMessageHandlerHolder();
                let structImplementation = {
                        handle_node_announcement (msg: number): number {
@@ -332,45 +381,51 @@ export class RoutingMessageHandler extends CommonBase {
                                const result: number = ret == null ? 0 : ret.clone_ptr();
                                return result;
                        },
-                       get_next_channel_announcements (starting_point: number, batch_amount: number): number[] {
+                       get_next_channel_announcements (starting_point: bigint, batch_amount: number): number {
                                const ret: ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ[] = arg.get_next_channel_announcements(starting_point, batch_amount);
-                               const result: number[] = ret != null ? ret.map(ret_conv_59 => ret_conv_59 == null ? 0 : ret_conv_59.clone_ptr()) : null;
+                               const result: number = bindings.encodeUint32Array(ret != null ? ret.map(ret_conv_59 => ret_conv_59 == null ? 0 : ret_conv_59.clone_ptr()) : null);
                                return result;
                        },
-                       get_next_node_announcements (starting_point: Uint8Array, batch_amount: number): number[] {
-                               const ret: NodeAnnouncement[] = arg.get_next_node_announcements(starting_point, batch_amount);
-                               const result: number[] = ret != null ? ret.map(ret_conv_18 => ret_conv_18 == null ? 0 : ret_conv_18.clone_ptr()) : null;
+                       get_next_node_announcements (starting_point: number, batch_amount: number): number {
+                               const starting_point_conv: Uint8Array = bindings.decodeUint8Array(starting_point);
+                               const ret: NodeAnnouncement[] = arg.get_next_node_announcements(starting_point_conv, batch_amount);
+                               const result: number = bindings.encodeUint32Array(ret != null ? ret.map(ret_conv_18 => ret_conv_18 == null ? 0 : ret_conv_18.clone_ptr()) : null);
                                return result;
                        },
-                       sync_routing_table (their_node_id: Uint8Array, init: number): void {
+                       sync_routing_table (their_node_id: number, init: number): void {
+                               const their_node_id_conv: Uint8Array = bindings.decodeUint8Array(their_node_id);
                                const init_hu_conv: Init = new Init(null, init);
-                               arg.sync_routing_table(their_node_id, init_hu_conv);
+                               arg.sync_routing_table(their_node_id_conv, init_hu_conv);
                        },
-                       handle_reply_channel_range (their_node_id: Uint8Array, msg: number): number {
+                       handle_reply_channel_range (their_node_id: number, msg: number): number {
+                               const their_node_id_conv: Uint8Array = bindings.decodeUint8Array(their_node_id);
                                const msg_hu_conv: ReplyChannelRange = new ReplyChannelRange(null, msg);
                                CommonBase.add_ref_from(msg_hu_conv, this);
-                               const ret: Result_NoneLightningErrorZ = arg.handle_reply_channel_range(their_node_id, msg_hu_conv);
+                               const ret: Result_NoneLightningErrorZ = arg.handle_reply_channel_range(their_node_id_conv, msg_hu_conv);
                                const result: number = ret == null ? 0 : ret.clone_ptr();
                                return result;
                        },
-                       handle_reply_short_channel_ids_end (their_node_id: Uint8Array, msg: number): number {
+                       handle_reply_short_channel_ids_end (their_node_id: number, msg: number): number {
+                               const their_node_id_conv: Uint8Array = bindings.decodeUint8Array(their_node_id);
                                const msg_hu_conv: ReplyShortChannelIdsEnd = new ReplyShortChannelIdsEnd(null, msg);
                                CommonBase.add_ref_from(msg_hu_conv, this);
-                               const ret: Result_NoneLightningErrorZ = arg.handle_reply_short_channel_ids_end(their_node_id, msg_hu_conv);
+                               const ret: Result_NoneLightningErrorZ = arg.handle_reply_short_channel_ids_end(their_node_id_conv, msg_hu_conv);
                                const result: number = ret == null ? 0 : ret.clone_ptr();
                                return result;
                        },
-                       handle_query_channel_range (their_node_id: Uint8Array, msg: number): number {
+                       handle_query_channel_range (their_node_id: number, msg: number): number {
+                               const their_node_id_conv: Uint8Array = bindings.decodeUint8Array(their_node_id);
                                const msg_hu_conv: QueryChannelRange = new QueryChannelRange(null, msg);
                                CommonBase.add_ref_from(msg_hu_conv, this);
-                               const ret: Result_NoneLightningErrorZ = arg.handle_query_channel_range(their_node_id, msg_hu_conv);
+                               const ret: Result_NoneLightningErrorZ = arg.handle_query_channel_range(their_node_id_conv, msg_hu_conv);
                                const result: number = ret == null ? 0 : ret.clone_ptr();
                                return result;
                        },
-                       handle_query_short_channel_ids (their_node_id: Uint8Array, msg: number): number {
+                       handle_query_short_channel_ids (their_node_id: number, msg: number): number {
+                               const their_node_id_conv: Uint8Array = bindings.decodeUint8Array(their_node_id);
                                const msg_hu_conv: QueryShortChannelIds = new QueryShortChannelIds(null, msg);
                                CommonBase.add_ref_from(msg_hu_conv, this);
-                               const ret: Result_NoneLightningErrorZ = arg.handle_query_short_channel_ids(their_node_id, msg_hu_conv);
+                               const ret: Result_NoneLightningErrorZ = arg.handle_query_short_channel_ids(their_node_id_conv, msg_hu_conv);
                                const result: number = ret == null ? 0 : ret.clone_ptr();
                                return result;
                        },
@@ -383,6 +438,11 @@ export class RoutingMessageHandler extends CommonBase {
                impl_holder.held.ptrs_to.push(messageSendEventsProvider);
                return impl_holder.held;
        }
+
+       /**
+        * Handle an incoming node_announcement message, returning true if it should be forwarded on,
+        * false or returning an Err otherwise.
+        */
        public handle_node_announcement(msg: NodeAnnouncement): Result_boolLightningErrorZ {
                const ret: number = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
                const ret_hu_conv: Result_boolLightningErrorZ = Result_boolLightningErrorZ.constr_from_ptr(ret);
@@ -390,6 +450,10 @@ export class RoutingMessageHandler extends CommonBase {
                return ret_hu_conv;
        }
 
+       /**
+        * Handle a channel_announcement message, returning true if it should be forwarded on, false
+        * or returning an Err otherwise.
+        */
        public handle_channel_announcement(msg: ChannelAnnouncement): Result_boolLightningErrorZ {
                const ret: number = bindings.RoutingMessageHandler_handle_channel_announcement(this.ptr, msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
                const ret_hu_conv: Result_boolLightningErrorZ = Result_boolLightningErrorZ.constr_from_ptr(ret);
@@ -397,6 +461,10 @@ export class RoutingMessageHandler extends CommonBase {
                return ret_hu_conv;
        }
 
+       /**
+        * Handle an incoming channel_update message, returning true if it should be forwarded on,
+        * false or returning an Err otherwise.
+        */
        public handle_channel_update(msg: ChannelUpdate): Result_boolLightningErrorZ {
                const ret: number = bindings.RoutingMessageHandler_handle_channel_update(this.ptr, msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
                const ret_hu_conv: Result_boolLightningErrorZ = Result_boolLightningErrorZ.constr_from_ptr(ret);
@@ -404,55 +472,96 @@ export class RoutingMessageHandler extends CommonBase {
                return ret_hu_conv;
        }
 
-       public get_next_channel_announcements(starting_point: number, batch_amount: number): ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ[] {
-               const ret: number[] = bindings.RoutingMessageHandler_get_next_channel_announcements(this.ptr, starting_point, batch_amount);
-               const ret_conv_59_arr: ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ[] = new Array(ret.length).fill(null);
-               for (var h = 0; h < ret.length; h++) {
-                       const ret_conv_59: number = ret[h];
+       /**
+        * Gets a subset of the channel announcements and updates required to dump our routing table
+        * to a remote node, starting at the short_channel_id indicated by starting_point and
+        * including the batch_amount entries immediately higher in numerical value than starting_point.
+        */
+       public get_next_channel_announcements(starting_point: bigint, batch_amount: number): ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ[] {
+               const ret: number = bindings.RoutingMessageHandler_get_next_channel_announcements(this.ptr, starting_point, batch_amount);
+               const ret_conv_59_len: number = bindings.getArrayLength(ret);
+               const ret_conv_59_arr: ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ[] = new Array(ret_conv_59_len).fill(null);
+               for (var h = 0; h < ret_conv_59_len; h++) {
+                       const ret_conv_59: number = bindings.getU32ArrayElem(ret, h);
                        const ret_conv_59_hu_conv: ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ = new ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ(null, ret_conv_59);
                        CommonBase.add_ref_from(ret_conv_59_hu_conv, this);
                        ret_conv_59_arr[h] = ret_conv_59_hu_conv;
                }
+               bindings.freeWasmMemory(ret)
                return ret_conv_59_arr;
        }
 
+       /**
+        * Gets a subset of the node announcements required to dump our routing table to a remote node,
+        * starting at the node *after* the provided publickey and including batch_amount entries
+        * immediately higher (as defined by <PublicKey as Ord>::cmp) than starting_point.
+        * If None is provided for starting_point, we start at the first node.
+        * 
+        * Note that starting_point (or a relevant inner pointer) may be NULL or all-0s to represent None
+        */
        public get_next_node_announcements(starting_point: Uint8Array, batch_amount: number): NodeAnnouncement[] {
-               const ret: number[] = bindings.RoutingMessageHandler_get_next_node_announcements(this.ptr, InternalUtils.check_arr_len(starting_point, 33), batch_amount);
-               const ret_conv_18_arr: NodeAnnouncement[] = new Array(ret.length).fill(null);
-               for (var s = 0; s < ret.length; s++) {
-                       const ret_conv_18: number = ret[s];
+               const ret: number = bindings.RoutingMessageHandler_get_next_node_announcements(this.ptr, bindings.encodeUint8Array(bindings.check_arr_len(starting_point, 33)), batch_amount);
+               const ret_conv_18_len: number = bindings.getArrayLength(ret);
+               const ret_conv_18_arr: NodeAnnouncement[] = new Array(ret_conv_18_len).fill(null);
+               for (var s = 0; s < ret_conv_18_len; s++) {
+                       const ret_conv_18: number = bindings.getU32ArrayElem(ret, s);
                        const ret_conv_18_hu_conv: NodeAnnouncement = new NodeAnnouncement(null, ret_conv_18);
                        CommonBase.add_ref_from(ret_conv_18_hu_conv, this);
                        ret_conv_18_arr[s] = ret_conv_18_hu_conv;
                }
+               bindings.freeWasmMemory(ret)
                return ret_conv_18_arr;
        }
 
+       /**
+        * Called when a connection is established with a peer. This can be used to
+        * perform routing table synchronization using a strategy defined by the
+        * implementor.
+        */
        public sync_routing_table(their_node_id: Uint8Array, init: Init): void {
-               bindings.RoutingMessageHandler_sync_routing_table(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), init == null ? 0 : CommonBase.get_ptr_of(init) & ~1);
+               bindings.RoutingMessageHandler_sync_routing_table(this.ptr, bindings.encodeUint8Array(bindings.check_arr_len(their_node_id, 33)), init == null ? 0 : CommonBase.get_ptr_of(init) & ~1);
                CommonBase.add_ref_from(this, init);
        }
 
+       /**
+        * Handles the reply of a query we initiated to learn about channels
+        * for a given range of blocks. We can expect to receive one or more
+        * replies to a single query.
+        */
        public handle_reply_channel_range(their_node_id: Uint8Array, msg: ReplyChannelRange): Result_NoneLightningErrorZ {
-               const ret: number = bindings.RoutingMessageHandler_handle_reply_channel_range(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
+               const ret: number = bindings.RoutingMessageHandler_handle_reply_channel_range(this.ptr, bindings.encodeUint8Array(bindings.check_arr_len(their_node_id, 33)), msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
                const ret_hu_conv: Result_NoneLightningErrorZ = Result_NoneLightningErrorZ.constr_from_ptr(ret);
                return ret_hu_conv;
        }
 
+       /**
+        * Handles the reply of a query we initiated asking for routing gossip
+        * messages for a list of channels. We should receive this message when
+        * a node has completed its best effort to send us the pertaining routing
+        * gossip messages.
+        */
        public handle_reply_short_channel_ids_end(their_node_id: Uint8Array, msg: ReplyShortChannelIdsEnd): Result_NoneLightningErrorZ {
-               const ret: number = bindings.RoutingMessageHandler_handle_reply_short_channel_ids_end(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
+               const ret: number = bindings.RoutingMessageHandler_handle_reply_short_channel_ids_end(this.ptr, bindings.encodeUint8Array(bindings.check_arr_len(their_node_id, 33)), msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
                const ret_hu_conv: Result_NoneLightningErrorZ = Result_NoneLightningErrorZ.constr_from_ptr(ret);
                return ret_hu_conv;
        }
 
+       /**
+        * Handles when a peer asks us to send a list of short_channel_ids
+        * for the requested range of blocks.
+        */
        public handle_query_channel_range(their_node_id: Uint8Array, msg: QueryChannelRange): Result_NoneLightningErrorZ {
-               const ret: number = bindings.RoutingMessageHandler_handle_query_channel_range(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
+               const ret: number = bindings.RoutingMessageHandler_handle_query_channel_range(this.ptr, bindings.encodeUint8Array(bindings.check_arr_len(their_node_id, 33)), msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
                const ret_hu_conv: Result_NoneLightningErrorZ = Result_NoneLightningErrorZ.constr_from_ptr(ret);
                return ret_hu_conv;
        }
 
+       /**
+        * Handles when a peer asks us to send routing gossip messages for a
+        * list of short_channel_ids.
+        */
        public handle_query_short_channel_ids(their_node_id: Uint8Array, msg: QueryShortChannelIds): Result_NoneLightningErrorZ {
-               const ret: number = bindings.RoutingMessageHandler_handle_query_short_channel_ids(this.ptr, InternalUtils.check_arr_len(their_node_id, 33), msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
+               const ret: number = bindings.RoutingMessageHandler_handle_query_short_channel_ids(this.ptr, bindings.encodeUint8Array(bindings.check_arr_len(their_node_id, 33)), msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
                const ret_hu_conv: Result_NoneLightningErrorZ = Result_NoneLightningErrorZ.constr_from_ptr(ret);
                return ret_hu_conv;
        }