/**
* Constructs a new peer handler, spawning a thread to monitor for socket events.
- * The background thread will call the PeerManager's timer_tick_occured() function for you on an appropriate schedule.
*
* @param manager The LDK PeerManager which connection data will be provided to.
* @throws IOException If an internal java.nio error occurs.
this.selector = Selector.open();
io_thread = new Thread(() -> {
ByteBuffer buf = ByteBuffer.allocate(8192);
- long lastTimerTick = System.currentTimeMillis();
while (true) {
try {
if (IS_ANDROID) {
// no need to do anything here with the PeerManager.
}
}
- if (lastTimerTick < System.currentTimeMillis() - 30 * 1000) {
- peer_manager.timer_tick_occurred();
- lastTimerTick = System.currentTimeMillis();
- }
peer_manager.process_events();
}
}, "NioPeerHandler NIO Thread");
}
}
+ /**
+ * Disconnects any connections currently open with the peer with the given node id.
+ *
+ * @param their_node_id must be a valid 33-byte public key
+ */
+ public void disconnect(byte[] their_node_id) {
+ this.peer_manager.disconnect_by_node_id(their_node_id, false);
+ }
+
/**
* Binds a listening socket to the given address, accepting incoming connections and handling them on the background
* thread.