X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=blobdiff_plain;f=ts%2Fstructs%2FNetworkGraph.mts;h=ecd06fc1da29d8704568bb16963d4f66544cc9a7;hp=c18f254ab3d62cee7e840d291fe7232fce1ea7bd;hb=c629a01650402c8e2f9b9db8ced9ed63ce687727;hpb=d1d0121c000b713c10fd0bedd249eb8dda2e4db7 diff --git a/ts/structs/NetworkGraph.mts b/ts/structs/NetworkGraph.mts index c18f254a..ecd06fc1 100644 --- a/ts/structs/NetworkGraph.mts +++ b/ts/structs/NetworkGraph.mts @@ -281,6 +281,9 @@ import CommonBase from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' +/** + * Represents the network as nodes and channels between them + */ export class NetworkGraph extends CommonBase { /* @internal */ public constructor(_dummy: object, ptr: number) { @@ -292,6 +295,9 @@ export class NetworkGraph extends CommonBase { return ret; } + /** + * Creates a copy of the NetworkGraph + */ public clone(): NetworkGraph { const ret: number = bindings.NetworkGraph_clone(this.ptr); const ret_hu_conv: NetworkGraph = new NetworkGraph(null, ret); @@ -299,18 +305,27 @@ export class NetworkGraph extends CommonBase { return ret_hu_conv; } + /** + * Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read + */ public write(): Uint8Array { const ret: number = bindings.NetworkGraph_write(this.ptr); const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); return ret_conv; } + /** + * Read a NetworkGraph from a byte array, created by NetworkGraph_write + */ public static constructor_read(ser: Uint8Array): Result_NetworkGraphDecodeErrorZ { const ret: number = bindings.NetworkGraph_read(bindings.encodeUint8Array(ser)); const ret_hu_conv: Result_NetworkGraphDecodeErrorZ = Result_NetworkGraphDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } + /** + * Creates a new, empty, network graph. + */ public static constructor_new(genesis_hash: Uint8Array): NetworkGraph { const ret: number = bindings.NetworkGraph_new(bindings.encodeUint8Array(bindings.check_arr_len(genesis_hash, 32))); const ret_hu_conv: NetworkGraph = new NetworkGraph(null, ret); @@ -318,6 +333,9 @@ export class NetworkGraph extends CommonBase { return ret_hu_conv; } + /** + * Returns a read-only view of the network graph. + */ public read_only(): ReadOnlyNetworkGraph { const ret: number = bindings.NetworkGraph_read_only(this.ptr); const ret_hu_conv: ReadOnlyNetworkGraph = new ReadOnlyNetworkGraph(null, ret); @@ -325,6 +343,14 @@ export class NetworkGraph extends CommonBase { return ret_hu_conv; } + /** + * For an already known node (from channel announcements), update its stored properties from a + * given node announcement. + * + * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's + * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept + * routing messages from a source using a protocol other than the lightning P2P protocol. + */ public update_node_from_announcement(msg: NodeAnnouncement): Result_NoneLightningErrorZ { const ret: number = bindings.NetworkGraph_update_node_from_announcement(this.ptr, msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1); const ret_hu_conv: Result_NoneLightningErrorZ = Result_NoneLightningErrorZ.constr_from_ptr(ret); @@ -332,6 +358,12 @@ export class NetworkGraph extends CommonBase { return ret_hu_conv; } + /** + * For an already known node (from channel announcements), update its stored properties from a + * given node announcement without verifying the associated signatures. Because we aren't + * given the associated signatures here we cannot relay the node announcement to any of our + * peers. + */ public update_node_from_unsigned_announcement(msg: UnsignedNodeAnnouncement): Result_NoneLightningErrorZ { const ret: number = bindings.NetworkGraph_update_node_from_unsigned_announcement(this.ptr, msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1); const ret_hu_conv: Result_NoneLightningErrorZ = Result_NoneLightningErrorZ.constr_from_ptr(ret); @@ -339,6 +371,16 @@ export class NetworkGraph extends CommonBase { return ret_hu_conv; } + /** + * Store or update channel info from a channel announcement. + * + * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's + * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept + * routing messages from a source using a protocol other than the lightning P2P protocol. + * + * If a `chain::Access` object is provided via `chain_access`, it will be called to verify + * the corresponding UTXO exists on chain and is correctly-formatted. + */ public update_channel_from_announcement(msg: ChannelAnnouncement, chain_access: Option_AccessZ): Result_NoneLightningErrorZ { const ret: number = bindings.NetworkGraph_update_channel_from_announcement(this.ptr, msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1, CommonBase.get_ptr_of(chain_access)); const ret_hu_conv: Result_NoneLightningErrorZ = Result_NoneLightningErrorZ.constr_from_ptr(ret); @@ -347,6 +389,14 @@ export class NetworkGraph extends CommonBase { return ret_hu_conv; } + /** + * Store or update channel info from a channel announcement without verifying the associated + * signatures. Because we aren't given the associated signatures here we cannot relay the + * channel announcement to any of our peers. + * + * If a `chain::Access` object is provided via `chain_access`, it will be called to verify + * the corresponding UTXO exists on chain and is correctly-formatted. + */ public update_channel_from_unsigned_announcement(msg: UnsignedChannelAnnouncement, chain_access: Option_AccessZ): Result_NoneLightningErrorZ { const ret: number = bindings.NetworkGraph_update_channel_from_unsigned_announcement(this.ptr, msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1, CommonBase.get_ptr_of(chain_access)); const ret_hu_conv: Result_NoneLightningErrorZ = Result_NoneLightningErrorZ.constr_from_ptr(ret); @@ -355,18 +405,50 @@ export class NetworkGraph extends CommonBase { return ret_hu_conv; } + /** + * Close a channel if a corresponding HTLC fail was sent. + * If permanent, removes a channel from the local storage. + * May cause the removal of nodes too, if this was their last channel. + * If not permanent, makes channels unavailable for routing. + */ public close_channel_from_update(short_channel_id: bigint, is_permanent: boolean): void { bindings.NetworkGraph_close_channel_from_update(this.ptr, short_channel_id, is_permanent); } + /** + * Marks a node in the graph as failed. + */ public fail_node(_node_id: Uint8Array, is_permanent: boolean): void { bindings.NetworkGraph_fail_node(this.ptr, bindings.encodeUint8Array(bindings.check_arr_len(_node_id, 33)), is_permanent); } + /** + * Removes information about channels that we haven't heard any updates about in some time. + * This can be used regularly to prune the network graph of channels that likely no longer + * exist. + * + * While there is no formal requirement that nodes regularly re-broadcast their channel + * updates every two weeks, the non-normative section of BOLT 7 currently suggests that + * pruning occur for updates which are at least two weeks old, which we implement here. + * + * This function takes the current unix time as an argument. For users with the `std` feature + * enabled, [`NetworkGraph::remove_stale_channels`] may be preferable. + */ public remove_stale_channels_with_time(current_time_unix: bigint): void { bindings.NetworkGraph_remove_stale_channels_with_time(this.ptr, current_time_unix); } + /** + * For an already known (from announcement) channel, update info about one of the directions + * of the channel. + * + * You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's + * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept + * routing messages from a source using a protocol other than the lightning P2P protocol. + * + * If built with `no-std`, any updates with a timestamp more than two weeks in the past or + * materially in the future will be rejected. + */ public update_channel(msg: ChannelUpdate): Result_NoneLightningErrorZ { const ret: number = bindings.NetworkGraph_update_channel(this.ptr, msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1); const ret_hu_conv: Result_NoneLightningErrorZ = Result_NoneLightningErrorZ.constr_from_ptr(ret); @@ -374,6 +456,14 @@ export class NetworkGraph extends CommonBase { return ret_hu_conv; } + /** + * For an already known (from announcement) channel, update info about one of the directions + * of the channel without verifying the associated signatures. Because we aren't given the + * associated signatures here we cannot relay the channel update to any of our peers. + * + * If built with `no-std`, any updates with a timestamp more than two weeks in the past or + * materially in the future will be rejected. + */ public update_channel_unsigned(msg: UnsignedChannelUpdate): Result_NoneLightningErrorZ { const ret: number = bindings.NetworkGraph_update_channel_unsigned(this.ptr, msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1); const ret_hu_conv: Result_NoneLightningErrorZ = Result_NoneLightningErrorZ.constr_from_ptr(ret);