]> git.bitcoin.ninja Git - ldk-java/blob - src/main/java/org/ldk/structs/NetAddress.java
Fix race in tests
[ldk-java] / src / main / java / org / ldk / structs / NetAddress.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7
8 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
9 public class NetAddress extends CommonBase {
10         private NetAddress(Object _dummy, long ptr) { super(ptr); }
11         @Override @SuppressWarnings("deprecation")
12         protected void finalize() throws Throwable {
13                 super.finalize();
14                 if (ptr != 0) { bindings.NetAddress_free(ptr); }
15         }
16         static NetAddress constr_from_ptr(long ptr) {
17                 bindings.LDKNetAddress raw_val = bindings.LDKNetAddress_ref_from_ptr(ptr);
18                 if (raw_val.getClass() == bindings.LDKNetAddress.IPv4.class) {
19                         return new IPv4(ptr, (bindings.LDKNetAddress.IPv4)raw_val);
20                 }
21                 if (raw_val.getClass() == bindings.LDKNetAddress.IPv6.class) {
22                         return new IPv6(ptr, (bindings.LDKNetAddress.IPv6)raw_val);
23                 }
24                 if (raw_val.getClass() == bindings.LDKNetAddress.OnionV2.class) {
25                         return new OnionV2(ptr, (bindings.LDKNetAddress.OnionV2)raw_val);
26                 }
27                 if (raw_val.getClass() == bindings.LDKNetAddress.OnionV3.class) {
28                         return new OnionV3(ptr, (bindings.LDKNetAddress.OnionV3)raw_val);
29                 }
30                 assert false; return null; // Unreachable without extending the (internal) bindings interface
31         }
32
33         public final static class IPv4 extends NetAddress {
34                 public final byte[] addr;
35                 public final short port;
36                 private IPv4(long ptr, bindings.LDKNetAddress.IPv4 obj) {
37                         super(null, ptr);
38                         this.addr = obj.addr;
39                         this.port = obj.port;
40                 }
41         }
42         public final static class IPv6 extends NetAddress {
43                 public final byte[] addr;
44                 public final short port;
45                 private IPv6(long ptr, bindings.LDKNetAddress.IPv6 obj) {
46                         super(null, ptr);
47                         this.addr = obj.addr;
48                         this.port = obj.port;
49                 }
50         }
51         public final static class OnionV2 extends NetAddress {
52                 public final byte[] addr;
53                 public final short port;
54                 private OnionV2(long ptr, bindings.LDKNetAddress.OnionV2 obj) {
55                         super(null, ptr);
56                         this.addr = obj.addr;
57                         this.port = obj.port;
58                 }
59         }
60         public final static class OnionV3 extends NetAddress {
61                 public final byte[] ed25519_pubkey;
62                 public final short checksum;
63                 public final byte version;
64                 public final short port;
65                 private OnionV3(long ptr, bindings.LDKNetAddress.OnionV3 obj) {
66                         super(null, ptr);
67                         this.ed25519_pubkey = obj.ed25519_pubkey;
68                         this.checksum = obj.checksum;
69                         this.version = obj.version;
70                         this.port = obj.port;
71                 }
72         }
73 }