+ public static interface SocketDescriptorInterface {
+ /**
+ * Attempts to send some data from the given slice to the peer.
+ *
+ * Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
+ * Note that in the disconnected case, [`PeerManager::socket_disconnected`] must still be
+ * called and further write attempts may occur until that time.
+ *
+ * If the returned size is smaller than `data.len()`, a
+ * [`PeerManager::write_buffer_space_avail`] call must be made the next time more data can be
+ * written. Additionally, until a `send_data` event completes fully, no further
+ * [`PeerManager::read_event`] calls should be made for the same peer! Because this is to
+ * prevent denial-of-service issues, you should not read or buffer any data from the socket
+ * until then.
+ *
+ * If a [`PeerManager::read_event`] call on this descriptor had previously returned true
+ * (indicating that read events should be paused to prevent DoS in the send buffer),
+ * `resume_read` may be set indicating that read events on this descriptor should resume. A
+ * `resume_read` of false carries no meaning, and should not cause any action.
+ */
+ long send_data(byte[] data, boolean resume_read);
+ /**
+ * Disconnect the socket pointed to by this SocketDescriptor.
+ *
+ * You do *not* need to call [`PeerManager::socket_disconnected`] with this socket after this
+ * call (doing so is a noop).
+ */
+ void disconnect_socket();
+ /**
+ * Checks if two objects are equal given this object's this_arg pointer and another object.
+ */
+ boolean eq(SocketDescriptor other_arg);
+ /**
+ * Calculate a succinct non-cryptographic hash for an object given its this_arg pointer.
+ * This is used, for example, for inclusion of this object in a hash map.
+ */
+ long hash();
+ }
+ private static class LDKSocketDescriptorHolder { SocketDescriptor held; }
+ public static SocketDescriptor new_impl(SocketDescriptorInterface arg) {
+ final LDKSocketDescriptorHolder impl_holder = new LDKSocketDescriptorHolder();
+ impl_holder.held = new SocketDescriptor(new bindings.LDKSocketDescriptor() {
+ @Override public long send_data(byte[] data, boolean resume_read) {
+ long ret = arg.send_data(data, resume_read);
+ return ret;
+ }
+ @Override public void disconnect_socket() {
+ arg.disconnect_socket();
+ }
+ @Override public boolean eq(long other_arg) {
+ SocketDescriptor ret_hu_conv = new SocketDescriptor(null, other_arg);
+ ret_hu_conv.ptrs_to.add(this);
+ boolean ret = arg.eq(ret_hu_conv);
+ return ret;
+ }
+ @Override public long hash() {
+ long ret = arg.hash();
+ return ret;
+ }
+ });
+ return impl_holder.held;
+ }
+ /**
+ * Attempts to send some data from the given slice to the peer.
+ *
+ * Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
+ * Note that in the disconnected case, [`PeerManager::socket_disconnected`] must still be
+ * called and further write attempts may occur until that time.
+ *
+ * If the returned size is smaller than `data.len()`, a
+ * [`PeerManager::write_buffer_space_avail`] call must be made the next time more data can be
+ * written. Additionally, until a `send_data` event completes fully, no further
+ * [`PeerManager::read_event`] calls should be made for the same peer! Because this is to
+ * prevent denial-of-service issues, you should not read or buffer any data from the socket
+ * until then.
+ *
+ * If a [`PeerManager::read_event`] call on this descriptor had previously returned true
+ * (indicating that read events should be paused to prevent DoS in the send buffer),
+ * `resume_read` may be set indicating that read events on this descriptor should resume. A
+ * `resume_read` of false carries no meaning, and should not cause any action.
+ */
+ public long send_data(byte[] data, boolean resume_read) {
+ long ret = bindings.SocketDescriptor_send_data(this.ptr, data, resume_read);