]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Fix connection race in C++ demo
authorMatt Corallo <git@bluematt.me>
Tue, 28 Feb 2023 06:54:29 +0000 (06:54 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 6 Mar 2023 22:48:29 +0000 (22:48 +0000)
lightning-c-bindings/demo.cpp

index a4281f56ca707e7c8f6ebd32ff7e463d9184acaf..b6a4c722f53aa3aefef8190abeea23cfbfe261ba 100644 (file)
@@ -242,6 +242,14 @@ public:
                PeerManager_disconnect_by_node_id(&net1, ChannelManager_get_our_node_id(&cm2));
                assert(!socket_connect(node1_handler, ChannelManager_get_our_node_id(&cm2), (sockaddr*)&listen_addr, sizeof(listen_addr)));
 
+               while (true) {
+                       // Wait for the new connection handshake...
+                       LDK::CVec_C2Tuple_PublicKeyCOption_NetAddressZZZ peers_1 = PeerManager_get_peer_node_ids(&net1);
+                       LDK::CVec_C2Tuple_PublicKeyCOption_NetAddressZZZ peers_2 = PeerManager_get_peer_node_ids(&net2);
+                       if (peers_1->datalen == 1 && peers_2->datalen == 1) { break; }
+                       std::this_thread::yield();
+               }
+
                // 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));