From: Matt Corallo Date: Tue, 28 Feb 2023 06:54:29 +0000 (+0000) Subject: Fix connection race in C++ demo X-Git-Tag: v0.0.114.0^2~5 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=commitdiff_plain;h=658e107370630688b53c663adc566fd814c6e974 Fix connection race in C++ demo --- diff --git a/lightning-c-bindings/demo.cpp b/lightning-c-bindings/demo.cpp index a4281f5..b6a4c72 100644 --- a/lightning-c-bindings/demo.cpp +++ b/lightning-c-bindings/demo.cpp @@ -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));