+#ifdef REAL_NET
+class PeersConnection {
+ void* node1_handler;
+ void* node2_handler;
+
+public:
+ PeersConnection(LDK::ChannelManager& cm1, LDK::ChannelManager& cm2, LDK::PeerManager& net1, LDK::PeerManager& net2) {
+ node1_handler = init_socket_handling(&net1);
+ node2_handler = init_socket_handling(&net2);
+
+ struct sockaddr_in listen_addr;
+ listen_addr.sin_family = AF_INET;
+ listen_addr.sin_addr.s_addr = htonl((127 << 8*3) | 1);
+ listen_addr.sin_port = htons(10042);
+ assert(!socket_bind(node2_handler, (sockaddr*)&listen_addr, sizeof(listen_addr)));
+
+ assert(!socket_connect(node1_handler, ChannelManager_get_our_node_id(&cm2), (sockaddr*)&listen_addr, sizeof(listen_addr)));
+
+ while (true) {
+ // Wait for the initial handshakes to complete...
+ LDK::CVec_PublicKeyZ peers_1 = PeerManager_get_peer_node_ids(&net1);
+ LDK::CVec_PublicKeyZ peers_2 = PeerManager_get_peer_node_ids(&net2);
+ if (peers_1->datalen == 1 && peers_2->datalen == 1) { break; }
+ std::this_thread::yield();
+ }
+
+ // Connect twice, which should auto-disconnect, and is a good test of our disconnect pipeline
+ assert(!socket_connect(node1_handler, ChannelManager_get_our_node_id(&cm2), (sockaddr*)&listen_addr, sizeof(listen_addr)));
+ assert(!socket_connect(node1_handler, ChannelManager_get_our_node_id(&cm2), (sockaddr*)&listen_addr, sizeof(listen_addr)));
+
+ // Then disconnect the "main" connection, while another connection is being made.
+ PeerManager_disconnect_by_node_id(&net1, ChannelManager_get_our_node_id(&cm2), false);
+ assert(!socket_connect(node1_handler, ChannelManager_get_our_node_id(&cm2), (sockaddr*)&listen_addr, sizeof(listen_addr)));
+
+ // Wait for all our sockets to disconnect (making sure we disconnect any new connections)...
+ while (true) {
+ PeerManager_disconnect_by_node_id(&net1, ChannelManager_get_our_node_id(&cm2), false);
+ // Wait for the peers to disconnect...
+ LDK::CVec_PublicKeyZ peers_1 = PeerManager_get_peer_node_ids(&net1);
+ LDK::CVec_PublicKeyZ peers_2 = PeerManager_get_peer_node_ids(&net2);
+ if (peers_1->datalen == 0 && peers_2->datalen == 0) { break; }
+ std::this_thread::yield();
+ }
+
+ // Finally make an actual connection and keep it this time
+ assert(!socket_connect(node1_handler, ChannelManager_get_our_node_id(&cm2), (sockaddr*)&listen_addr, sizeof(listen_addr)));
+
+ while (true) {
+ // Wait for the initial handshakes to complete...
+ LDK::CVec_PublicKeyZ peers_1 = PeerManager_get_peer_node_ids(&net1);
+ LDK::CVec_PublicKeyZ peers_2 = PeerManager_get_peer_node_ids(&net2);
+ if (peers_1->datalen == 1 && peers_2->datalen == 1) { break; }
+ std::this_thread::yield();
+ }
+ }
+ void stop() {
+ interrupt_socket_handling(node1_handler);
+ interrupt_socket_handling(node2_handler);
+ }
+};
+
+#else // REAL_NET