23078a60fecf41d72617f7aa4960676acc0f3935
[ldk-java] / src / main / java / org / ldk / structs / UserConfig.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 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
13  * 
14  * Default::default() provides sane defaults for most configurations
15  * (but currently with 0 relay fees!)
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class UserConfig extends CommonBase {
19         UserConfig(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.UserConfig_free(ptr); }
24         }
25
26         /**
27          * Channel config that we propose to our counterparty.
28          */
29         public ChannelHandshakeConfig get_own_channel_config() {
30                 long ret = bindings.UserConfig_get_own_channel_config(this.ptr);
31                 Reference.reachabilityFence(this);
32                 if (ret >= 0 && ret <= 4096) { return null; }
33                 ChannelHandshakeConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelHandshakeConfig(null, ret); }
34                 ret_hu_conv.ptrs_to.add(this);
35                 return ret_hu_conv;
36         }
37
38         /**
39          * Channel config that we propose to our counterparty.
40          */
41         public void set_own_channel_config(ChannelHandshakeConfig val) {
42                 bindings.UserConfig_set_own_channel_config(this.ptr, val == null ? 0 : val.ptr & ~1);
43                 Reference.reachabilityFence(this);
44                 Reference.reachabilityFence(val);
45         }
46
47         /**
48          * Limits applied to our counterparty's proposed channel config settings.
49          */
50         public ChannelHandshakeLimits get_peer_channel_config_limits() {
51                 long ret = bindings.UserConfig_get_peer_channel_config_limits(this.ptr);
52                 Reference.reachabilityFence(this);
53                 if (ret >= 0 && ret <= 4096) { return null; }
54                 ChannelHandshakeLimits ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelHandshakeLimits(null, ret); }
55                 ret_hu_conv.ptrs_to.add(this);
56                 return ret_hu_conv;
57         }
58
59         /**
60          * Limits applied to our counterparty's proposed channel config settings.
61          */
62         public void set_peer_channel_config_limits(ChannelHandshakeLimits val) {
63                 bindings.UserConfig_set_peer_channel_config_limits(this.ptr, val == null ? 0 : val.ptr & ~1);
64                 Reference.reachabilityFence(this);
65                 Reference.reachabilityFence(val);
66         }
67
68         /**
69          * Channel config which affects behavior during channel lifetime.
70          */
71         public ChannelConfig get_channel_options() {
72                 long ret = bindings.UserConfig_get_channel_options(this.ptr);
73                 Reference.reachabilityFence(this);
74                 if (ret >= 0 && ret <= 4096) { return null; }
75                 ChannelConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelConfig(null, ret); }
76                 ret_hu_conv.ptrs_to.add(this);
77                 return ret_hu_conv;
78         }
79
80         /**
81          * Channel config which affects behavior during channel lifetime.
82          */
83         public void set_channel_options(ChannelConfig val) {
84                 bindings.UserConfig_set_channel_options(this.ptr, val == null ? 0 : val.ptr & ~1);
85                 Reference.reachabilityFence(this);
86                 Reference.reachabilityFence(val);
87         }
88
89         /**
90          * If this is set to false, we will reject any HTLCs which were to be forwarded over private
91          * channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
92          * node which is not online reliably.
93          * 
94          * For nodes which are not online reliably, you should set all channels to *not* be announced
95          * (using [`ChannelConfig::announced_channel`] and
96          * [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
97          * ensure you are not exposed to any forwarding risk.
98          * 
99          * Note that because you cannot change a channel's announced state after creation, there is no
100          * way to disable forwarding on public channels retroactively. Thus, in order to change a node
101          * from a publicly-announced forwarding node to a private non-forwarding node you must close
102          * all your channels and open new ones. For privacy, you should also change your node_id
103          * (swapping all private and public key material for new ones) at that time.
104          * 
105          * Default value: false.
106          */
107         public boolean get_accept_forwards_to_priv_channels() {
108                 boolean ret = bindings.UserConfig_get_accept_forwards_to_priv_channels(this.ptr);
109                 Reference.reachabilityFence(this);
110                 return ret;
111         }
112
113         /**
114          * If this is set to false, we will reject any HTLCs which were to be forwarded over private
115          * channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a
116          * node which is not online reliably.
117          * 
118          * For nodes which are not online reliably, you should set all channels to *not* be announced
119          * (using [`ChannelConfig::announced_channel`] and
120          * [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
121          * ensure you are not exposed to any forwarding risk.
122          * 
123          * Note that because you cannot change a channel's announced state after creation, there is no
124          * way to disable forwarding on public channels retroactively. Thus, in order to change a node
125          * from a publicly-announced forwarding node to a private non-forwarding node you must close
126          * all your channels and open new ones. For privacy, you should also change your node_id
127          * (swapping all private and public key material for new ones) at that time.
128          * 
129          * Default value: false.
130          */
131         public void set_accept_forwards_to_priv_channels(boolean val) {
132                 bindings.UserConfig_set_accept_forwards_to_priv_channels(this.ptr, val);
133                 Reference.reachabilityFence(this);
134                 Reference.reachabilityFence(val);
135         }
136
137         /**
138          * If this is set to false, we do not accept inbound requests to open a new channel.
139          * Default value: true.
140          */
141         public boolean get_accept_inbound_channels() {
142                 boolean ret = bindings.UserConfig_get_accept_inbound_channels(this.ptr);
143                 Reference.reachabilityFence(this);
144                 return ret;
145         }
146
147         /**
148          * If this is set to false, we do not accept inbound requests to open a new channel.
149          * Default value: true.
150          */
151         public void set_accept_inbound_channels(boolean val) {
152                 bindings.UserConfig_set_accept_inbound_channels(this.ptr, val);
153                 Reference.reachabilityFence(this);
154                 Reference.reachabilityFence(val);
155         }
156
157         /**
158          * Constructs a new UserConfig given each field
159          */
160         public static UserConfig of(ChannelHandshakeConfig own_channel_config_arg, ChannelHandshakeLimits peer_channel_config_limits_arg, ChannelConfig channel_options_arg, boolean accept_forwards_to_priv_channels_arg, boolean accept_inbound_channels_arg) {
161                 long ret = bindings.UserConfig_new(own_channel_config_arg == null ? 0 : own_channel_config_arg.ptr & ~1, peer_channel_config_limits_arg == null ? 0 : peer_channel_config_limits_arg.ptr & ~1, channel_options_arg == null ? 0 : channel_options_arg.ptr & ~1, accept_forwards_to_priv_channels_arg, accept_inbound_channels_arg);
162                 Reference.reachabilityFence(own_channel_config_arg);
163                 Reference.reachabilityFence(peer_channel_config_limits_arg);
164                 Reference.reachabilityFence(channel_options_arg);
165                 Reference.reachabilityFence(accept_forwards_to_priv_channels_arg);
166                 Reference.reachabilityFence(accept_inbound_channels_arg);
167                 if (ret >= 0 && ret <= 4096) { return null; }
168                 UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new UserConfig(null, ret); }
169                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
170                 return ret_hu_conv;
171         }
172
173         long clone_ptr() {
174                 long ret = bindings.UserConfig_clone_ptr(this.ptr);
175                 Reference.reachabilityFence(this);
176                 return ret;
177         }
178
179         /**
180          * Creates a copy of the UserConfig
181          */
182         public UserConfig clone() {
183                 long ret = bindings.UserConfig_clone(this.ptr);
184                 Reference.reachabilityFence(this);
185                 if (ret >= 0 && ret <= 4096) { return null; }
186                 UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new UserConfig(null, ret); }
187                 ret_hu_conv.ptrs_to.add(this);
188                 return ret_hu_conv;
189         }
190
191         /**
192          * Creates a "default" UserConfig. See struct and individual field documentaiton for details on which values are used.
193          */
194         public static UserConfig with_default() {
195                 long ret = bindings.UserConfig_default();
196                 if (ret >= 0 && ret <= 4096) { return null; }
197                 UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new UserConfig(null, ret); }
198                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
199                 return ret_hu_conv;
200         }
201
202 }