1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * A processed incoming onion message, containing either a Forward (another onion message)
13 * or a Receive payload with decrypted contents.
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class PeeledOnion extends CommonBase {
17 private PeeledOnion(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.PeeledOnion_free(ptr); }
23 static PeeledOnion constr_from_ptr(long ptr) {
24 bindings.LDKPeeledOnion raw_val = bindings.LDKPeeledOnion_ref_from_ptr(ptr);
25 if (raw_val.getClass() == bindings.LDKPeeledOnion.Forward.class) {
26 return new Forward(ptr, (bindings.LDKPeeledOnion.Forward)raw_val);
28 if (raw_val.getClass() == bindings.LDKPeeledOnion.Receive.class) {
29 return new Receive(ptr, (bindings.LDKPeeledOnion.Receive)raw_val);
31 assert false; return null; // Unreachable without extending the (internal) bindings interface
35 * Forwarded onion, with the next node id and a new onion
37 public final static class Forward extends PeeledOnion {
38 public final byte[] _0;
39 public final org.ldk.structs.OnionMessage _1;
40 private Forward(long ptr, bindings.LDKPeeledOnion.Forward obj) {
44 org.ldk.structs.OnionMessage _1_hu_conv = null; if (_1 < 0 || _1 > 4096) { _1_hu_conv = new org.ldk.structs.OnionMessage(null, _1); }
45 if (_1_hu_conv != null) { _1_hu_conv.ptrs_to.add(this); };
50 * Received onion message, with decrypted contents, path_id, and reply path
52 public final static class Receive extends PeeledOnion {
53 public final org.ldk.structs.ParsedOnionMessageContents _0;
55 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
57 @Nullable public final byte[] _1;
59 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
61 @Nullable public final org.ldk.structs.BlindedPath _2;
62 private Receive(long ptr, bindings.LDKPeeledOnion.Receive obj) {
65 org.ldk.structs.ParsedOnionMessageContents _0_hu_conv = org.ldk.structs.ParsedOnionMessageContents.constr_from_ptr(_0);
66 if (_0_hu_conv != null) { _0_hu_conv.ptrs_to.add(this); };
70 org.ldk.structs.BlindedPath _2_hu_conv = null; if (_2 < 0 || _2 > 4096) { _2_hu_conv = new org.ldk.structs.BlindedPath(null, _2); }
71 if (_2_hu_conv != null) { _2_hu_conv.ptrs_to.add(this); };
76 long ret = bindings.PeeledOnion_clone_ptr(this.ptr);
77 Reference.reachabilityFence(this);
82 * Creates a copy of the PeeledOnion
84 public PeeledOnion clone() {
85 long ret = bindings.PeeledOnion_clone(this.ptr);
86 Reference.reachabilityFence(this);
87 if (ret >= 0 && ret <= 4096) { return null; }
88 org.ldk.structs.PeeledOnion ret_hu_conv = org.ldk.structs.PeeledOnion.constr_from_ptr(ret);
89 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
94 * Utility method to constructs a new Forward-variant PeeledOnion
96 public static PeeledOnion forward(byte[] a, org.ldk.structs.OnionMessage b) {
97 long ret = bindings.PeeledOnion_forward(InternalUtils.check_arr_len(a, 33), b == null ? 0 : b.ptr);
98 Reference.reachabilityFence(a);
99 Reference.reachabilityFence(b);
100 if (ret >= 0 && ret <= 4096) { return null; }
101 org.ldk.structs.PeeledOnion ret_hu_conv = org.ldk.structs.PeeledOnion.constr_from_ptr(ret);
102 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
103 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(b); };
108 * Utility method to constructs a new Receive-variant PeeledOnion
110 public static PeeledOnion receive(org.ldk.structs.ParsedOnionMessageContents a, byte[] b, org.ldk.structs.BlindedPath c) {
111 long ret = bindings.PeeledOnion_receive(a.ptr, InternalUtils.check_arr_len(b, 32), c == null ? 0 : c.ptr);
112 Reference.reachabilityFence(a);
113 Reference.reachabilityFence(b);
114 Reference.reachabilityFence(c);
115 if (ret >= 0 && ret <= 4096) { return null; }
116 org.ldk.structs.PeeledOnion ret_hu_conv = org.ldk.structs.PeeledOnion.constr_from_ptr(ret);
117 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
118 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
119 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(c); };