From bb1c884a2f466cccbc4e719f8ec021e627f2dda3 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 20 Feb 2020 11:56:48 -0500 Subject: fix the potential data race in known_peers --- test/test_p2p_min.cpp | 9 ++++++++- test/test_p2p_stress.cpp | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test_p2p_min.cpp b/test/test_p2p_min.cpp index a221d79..bc62eda 100644 --- a/test/test_p2p_min.cpp +++ b/test/test_p2p_min.cpp @@ -43,7 +43,14 @@ int main() { for (size_t i = 0; i < nodes.size(); i++) for (size_t j = 0; j < nodes.size(); j++) if (i != j) - nodes[i].second->add_peer(nodes[j].first); + { + auto &node = nodes[i].second; + auto &peer_addr = nodes[j].first; + salticidae::PeerId pid{peer_addr}; + node->add_peer(pid); + node->set_peer_addr(pid, peer_addr); + node->conn_peer(pid); + } ec.dispatch(); return 0; } diff --git a/test/test_p2p_stress.cpp b/test/test_p2p_stress.cpp index dca9cf4..f5a0b5d 100644 --- a/test/test_p2p_stress.cpp +++ b/test/test_p2p_stress.cpp @@ -238,7 +238,13 @@ int main(int argc, char **argv) { masksigs(); a.net->listen(a.addr); for (auto &paddr: addrs) - if (paddr != a.addr) a.net->add_peer(paddr); + if (paddr != a.addr) + { + salticidae::PeerId pid{paddr}; + a.net->add_peer(pid); + a.net->set_peer_addr(pid, paddr); + a.net->conn_peer(pid); + } a.ec.dispatch();})); EventContext ec; -- cgit v1.2.3-70-g09d2