X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FHTLCDestination.java;h=f3f56ff195259a470d1b80710d4548efd8775db1;hb=ffdd56c967087cba7548599934585b8a9a3102e2;hp=a5c58c1d6f7028d229b40cff8aa3ef30fdf0cc78;hpb=af6f9949b19c1e8d2daac5c7a94cf14d41175f2b;p=ldk-java diff --git a/src/main/java/org/ldk/structs/HTLCDestination.java b/src/main/java/org/ldk/structs/HTLCDestination.java index a5c58c1d..f3f56ff1 100644 --- a/src/main/java/org/ldk/structs/HTLCDestination.java +++ b/src/main/java/org/ldk/structs/HTLCDestination.java @@ -27,6 +27,12 @@ public class HTLCDestination extends CommonBase { if (raw_val.getClass() == bindings.LDKHTLCDestination.UnknownNextHop.class) { return new UnknownNextHop(ptr, (bindings.LDKHTLCDestination.UnknownNextHop)raw_val); } + if (raw_val.getClass() == bindings.LDKHTLCDestination.InvalidForward.class) { + return new InvalidForward(ptr, (bindings.LDKHTLCDestination.InvalidForward)raw_val); + } + if (raw_val.getClass() == bindings.LDKHTLCDestination.InvalidOnion.class) { + return new InvalidOnion(ptr, (bindings.LDKHTLCDestination.InvalidOnion)raw_val); + } if (raw_val.getClass() == bindings.LDKHTLCDestination.FailedPayment.class) { return new FailedPayment(ptr, (bindings.LDKHTLCDestination.FailedPayment)raw_val); } @@ -49,11 +55,14 @@ public class HTLCDestination extends CommonBase { /** * The outgoing `channel_id` between us and the next node. */ - public final byte[] channel_id; + public final org.ldk.structs.ChannelId channel_id; private NextHopChannel(long ptr, bindings.LDKHTLCDestination.NextHopChannel obj) { super(null, ptr); this.node_id = obj.node_id; - this.channel_id = obj.channel_id; + long channel_id = obj.channel_id; + org.ldk.structs.ChannelId channel_id_hu_conv = null; if (channel_id < 0 || channel_id > 4096) { channel_id_hu_conv = new org.ldk.structs.ChannelId(null, channel_id); } + if (channel_id_hu_conv != null) { channel_id_hu_conv.ptrs_to.add(this); }; + this.channel_id = channel_id_hu_conv; } } /** @@ -69,14 +78,39 @@ public class HTLCDestination extends CommonBase { this.requested_forward_scid = obj.requested_forward_scid; } } + /** + * We couldn't forward to the outgoing scid. An example would be attempting to send a duplicate + * intercept HTLC. + */ + public final static class InvalidForward extends HTLCDestination { + /** + * Short channel id we are requesting to forward an HTLC to. + */ + public final long requested_forward_scid; + private InvalidForward(long ptr, bindings.LDKHTLCDestination.InvalidForward obj) { + super(null, ptr); + this.requested_forward_scid = obj.requested_forward_scid; + } + } + /** + * We couldn't decode the incoming onion to obtain the forwarding details. + */ + public final static class InvalidOnion extends HTLCDestination { + private InvalidOnion(long ptr, bindings.LDKHTLCDestination.InvalidOnion obj) { + super(null, ptr); + } + } /** * Failure scenario where an HTLC may have been forwarded to be intended for us, * but is invalid for some reason, so we reject it. * * Some of the reasons may include: * HTLC Timeouts - * Expected MPP amount to claim does not equal HTLC total - * Claimable amount does not match expected amount + * Excess HTLCs for a payment that we have already fully received, over-paying for the + * payment, + * The counterparty node modified the HTLC in transit, + * A probing attack where an intermediary node is trying to detect if we are the ultimate + * recipient for a payment. */ public final static class FailedPayment extends HTLCDestination { /** @@ -102,20 +136,21 @@ public class HTLCDestination extends CommonBase { Reference.reachabilityFence(this); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(this); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } /** * Utility method to constructs a new NextHopChannel-variant HTLCDestination */ - public static HTLCDestination next_hop_channel(byte[] node_id, byte[] channel_id) { - long ret = bindings.HTLCDestination_next_hop_channel(InternalUtils.check_arr_len(node_id, 33), InternalUtils.check_arr_len(channel_id, 32)); + public static HTLCDestination next_hop_channel(byte[] node_id, org.ldk.structs.ChannelId channel_id) { + long ret = bindings.HTLCDestination_next_hop_channel(InternalUtils.check_arr_len(node_id, 33), channel_id.ptr); Reference.reachabilityFence(node_id); Reference.reachabilityFence(channel_id); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_id); }; return ret_hu_conv; } @@ -127,7 +162,30 @@ public class HTLCDestination extends CommonBase { Reference.reachabilityFence(requested_forward_scid); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + return ret_hu_conv; + } + + /** + * Utility method to constructs a new InvalidForward-variant HTLCDestination + */ + public static HTLCDestination invalid_forward(long requested_forward_scid) { + long ret = bindings.HTLCDestination_invalid_forward(requested_forward_scid); + Reference.reachabilityFence(requested_forward_scid); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + return ret_hu_conv; + } + + /** + * Utility method to constructs a new InvalidOnion-variant HTLCDestination + */ + public static HTLCDestination invalid_onion() { + long ret = bindings.HTLCDestination_invalid_onion(); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } @@ -139,10 +197,25 @@ public class HTLCDestination extends CommonBase { Reference.reachabilityFence(payment_hash); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } + /** + * Checks if two HTLCDestinations contain equal inner contents. + * This ignores pointers and is_owned flags and looks at the values in fields. + */ + public boolean eq(org.ldk.structs.HTLCDestination b) { + boolean ret = bindings.HTLCDestination_eq(this.ptr, b.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(b); + return ret; + } + + @Override public boolean equals(Object o) { + if (!(o instanceof HTLCDestination)) return false; + return this.eq((HTLCDestination)o); + } /** * Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read */