diff options
author | Determinant <[email protected]> | 2019-06-30 13:49:59 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2019-06-30 13:49:59 -0400 |
commit | a53ae6b6ff2faa7fa1d54b3eb662dcfb3591d8ef (patch) | |
tree | 0c984757e1f312cb69dc3ed49d914e2bda3099c9 | |
parent | b06eef583fb9084f29e416a1af7555de4a73f764 (diff) |
try to fix get_peer_addr bug
-rw-r--r-- | include/salticidae/network.h | 3 | ||||
-rw-r--r-- | test/test_p2p_stress.cpp | 10 |
2 files changed, 11 insertions, 2 deletions
diff --git a/include/salticidae/network.h b/include/salticidae/network.h index 1f21c92..d83e7f1 100644 --- a/include/salticidae/network.h +++ b/include/salticidae/network.h @@ -284,7 +284,7 @@ class PeerNetwork: public MsgNetwork<OpcodeType> { NetAddr get_peer_addr() { auto ret = *(static_cast<NetAddr *>( get_net()->disp_tcall->call([this](ThreadCall::Handle &h) { - h.set_result(peer ? peer->peer_addr : NetAddr()); + h.set_result(peer ? NetAddr(peer->peer_addr) : NetAddr()); }).get())); return ret; } @@ -650,6 +650,7 @@ void PeerNetwork<O, _, __>::on_teardown(const ConnPool::conn_t &_conn) { known_peers[p->peer_addr] = std::make_pair(uint256_t(), TimerEvent()); { pinfo_ulock_t __g(pid2peer_lock); + p->conn->peer = nullptr; pid2peer.erase(p->peer_id); } this->user_tcall->async_call([this, conn](ThreadCall::Handle &) { diff --git a/test/test_p2p_stress.cpp b/test/test_p2p_stress.cpp index b8ef017..cb6595c 100644 --- a/test/test_p2p_stress.cpp +++ b/test/test_p2p_stress.cpp @@ -118,6 +118,9 @@ void install_proto(AppContext &app, const size_t &seg_buff_size) { tc.hash = msg.hash; net.send_msg(std::move(msg), conn); }; + net.reg_conn_handler([](const ConnPool::conn_t &conn, bool connected) { + return true; + }); net.reg_peer_handler([&, send_rand](const MyNet::conn_t &conn, bool connected) { if (connected) { @@ -143,7 +146,12 @@ void install_proto(AppContext &app, const size_t &seg_buff_size) { }); net.reg_handler([&, send_rand](MsgAck &&msg, const MyNet::conn_t &conn) { auto addr = conn->get_peer_addr(); - assert(!addr.is_null()); + if (addr.is_null()) return; + if (app.tc.find(addr) == app.tc.end()) + { + SALTICIDAE_LOG_WARN("%s\n", std::string(addr).c_str()); + throw std::runtime_error("violation"); + } auto &tc = app.tc[addr]; if (msg.view != tc.view) { |