[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / SocketDescriptor.cs
1
2 using org.ldk.impl;
3 using org.ldk.enums;
4 using org.ldk.util;
5 using System;
6
7 namespace org { namespace ldk { namespace structs {
8
9
10
11 /** An implementation of SocketDescriptor */
12 public interface SocketDescriptorInterface {
13         /**Attempts to send some data from the given slice to the peer.
14          * 
15          * Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
16          * Note that in the disconnected case, [`PeerManager::socket_disconnected`] must still be
17          * called and further write attempts may occur until that time.
18          * 
19          * If the returned size is smaller than `data.len()`, a
20          * [`PeerManager::write_buffer_space_avail`] call must be made the next time more data can be
21          * written. Additionally, until a `send_data` event completes fully, no further
22          * [`PeerManager::read_event`] calls should be made for the same peer! Because this is to
23          * prevent denial-of-service issues, you should not read or buffer any data from the socket
24          * until then.
25          * 
26          * If a [`PeerManager::read_event`] call on this descriptor had previously returned true
27          * (indicating that read events should be paused to prevent DoS in the send buffer),
28          * `resume_read` may be set indicating that read events on this descriptor should resume. A
29          * `resume_read` of false carries no meaning, and should not cause any action.
30          */
31         long send_data(byte[] data, bool resume_read);
32         /**Disconnect the socket pointed to by this SocketDescriptor.
33          * 
34          * You do *not* need to call [`PeerManager::socket_disconnected`] with this socket after this
35          * call (doing so is a noop).
36          */
37         void disconnect_socket();
38         /**Checks if two objects are equal given this object's this_arg pointer and another object.
39          */
40         bool eq(SocketDescriptor other_arg);
41         /**Calculate a succinct non-cryptographic hash for an object given its this_arg pointer.
42          * This is used, for example, for inclusion of this object in a hash map.
43          */
44         long hash();
45 }
46
47 /**
48  * Provides an object which can be used to send data to and which uniquely identifies a connection
49  * to a remote host. You will need to be able to generate multiple of these which meet Eq and
50  * implement Hash to meet the PeerManager API.
51  * 
52  * For efficiency, [`Clone`] should be relatively cheap for this type.
53  * 
54  * Two descriptors may compare equal (by [`cmp::Eq`] and [`hash::Hash`]) as long as the original
55  * has been disconnected, the [`PeerManager`] has been informed of the disconnection (either by it
56  * having triggered the disconnection or a call to [`PeerManager::socket_disconnected`]), and no
57  * further calls to the [`PeerManager`] related to the original socket occur. This allows you to
58  * use a file descriptor for your SocketDescriptor directly, however for simplicity you may wish
59  * to simply use another value which is guaranteed to be globally unique instead.
60  */
61 public class SocketDescriptor : CommonBase {
62         internal bindings.LDKSocketDescriptor bindings_instance;
63         internal long instance_idx;
64
65         internal SocketDescriptor(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
66         ~SocketDescriptor() {
67                 if (ptr != 0) { bindings.SocketDescriptor_free(ptr); }
68         }
69
70         private class LDKSocketDescriptorHolder { internal SocketDescriptor held; }
71         private class LDKSocketDescriptorImpl : bindings.LDKSocketDescriptor {
72                 internal LDKSocketDescriptorImpl(SocketDescriptorInterface arg, LDKSocketDescriptorHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
73                 private SocketDescriptorInterface arg;
74                 private LDKSocketDescriptorHolder impl_holder;
75                 public long send_data(long _data, bool _resume_read) {
76                         byte[] _data_conv = InternalUtils.decodeUint8Array(_data);
77                         long ret = arg.send_data(_data_conv, _resume_read);
78                                 GC.KeepAlive(arg);
79                         return ret;
80                 }
81                 public void disconnect_socket() {
82                         arg.disconnect_socket();
83                                 GC.KeepAlive(arg);
84                 }
85                 public bool eq(long _other_arg) {
86                         SocketDescriptor ret_hu_conv = new SocketDescriptor(null, _other_arg);
87                         if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
88                         bool ret = arg.eq(ret_hu_conv);
89                                 GC.KeepAlive(arg);
90                         return ret;
91                 }
92                 public long hash() {
93                         long ret = arg.hash();
94                                 GC.KeepAlive(arg);
95                         return ret;
96                 }
97         }
98
99         /** Creates a new instance of SocketDescriptor from a given implementation */
100         public static SocketDescriptor new_impl(SocketDescriptorInterface arg) {
101                 LDKSocketDescriptorHolder impl_holder = new LDKSocketDescriptorHolder();
102                 LDKSocketDescriptorImpl impl = new LDKSocketDescriptorImpl(arg, impl_holder);
103                 long[] ptr_idx = bindings.LDKSocketDescriptor_new(impl);
104
105                 impl_holder.held = new SocketDescriptor(null, ptr_idx[0]);
106                 impl_holder.held.instance_idx = ptr_idx[1];
107                 impl_holder.held.bindings_instance = impl;
108                 return impl_holder.held;
109         }
110
111         /**
112          * Attempts to send some data from the given slice to the peer.
113          * 
114          * Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
115          * Note that in the disconnected case, [`PeerManager::socket_disconnected`] must still be
116          * called and further write attempts may occur until that time.
117          * 
118          * If the returned size is smaller than `data.len()`, a
119          * [`PeerManager::write_buffer_space_avail`] call must be made the next time more data can be
120          * written. Additionally, until a `send_data` event completes fully, no further
121          * [`PeerManager::read_event`] calls should be made for the same peer! Because this is to
122          * prevent denial-of-service issues, you should not read or buffer any data from the socket
123          * until then.
124          * 
125          * If a [`PeerManager::read_event`] call on this descriptor had previously returned true
126          * (indicating that read events should be paused to prevent DoS in the send buffer),
127          * `resume_read` may be set indicating that read events on this descriptor should resume. A
128          * `resume_read` of false carries no meaning, and should not cause any action.
129          */
130         public long send_data(byte[] data, bool resume_read) {
131                 long ret = bindings.SocketDescriptor_send_data(this.ptr, InternalUtils.encodeUint8Array(data), resume_read);
132                 GC.KeepAlive(this);
133                 GC.KeepAlive(data);
134                 GC.KeepAlive(resume_read);
135                 return ret;
136         }
137
138         /**
139          * Disconnect the socket pointed to by this SocketDescriptor.
140          * 
141          * You do *not* need to call [`PeerManager::socket_disconnected`] with this socket after this
142          * call (doing so is a noop).
143          */
144         public void disconnect_socket() {
145                 bindings.SocketDescriptor_disconnect_socket(this.ptr);
146                 GC.KeepAlive(this);
147         }
148
149         /**
150          * Calculate a succinct non-cryptographic hash for an object given its this_arg pointer.
151          * This is used, for example, for inclusion of this object in a hash map.
152          */
153         public long hash() {
154                 long ret = bindings.SocketDescriptor_hash(this.ptr);
155                 GC.KeepAlive(this);
156                 return ret;
157         }
158
159         public override int GetHashCode() {
160                 return (int)this.hash();
161         }
162         internal long clone_ptr() {
163                 long ret = bindings.SocketDescriptor_clone_ptr(this.ptr);
164                 GC.KeepAlive(this);
165                 return ret;
166         }
167
168         /**
169          * Creates a copy of a SocketDescriptor
170          */
171         public SocketDescriptor clone() {
172                 long ret = bindings.SocketDescriptor_clone(this.ptr);
173                 GC.KeepAlive(this);
174                 if (ret >= 0 && ret <= 4096) { return null; }
175                 SocketDescriptor ret_hu_conv = new SocketDescriptor(null, ret);
176                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
177                 return ret_hu_conv;
178         }
179
180 }
181 } } }