From 20669e2b5e956babf888bca577e39a71d83bae79 Mon Sep 17 00:00:00 2001 From: Determinant Date: Fri, 16 Nov 2018 21:40:53 -0500 Subject: add test_p2p_stress.cpp; fix bugs --- include/salticidae/network.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'include/salticidae/network.h') diff --git a/include/salticidae/network.h b/include/salticidae/network.h index 5e966fe..78449eb 100644 --- a/include/salticidae/network.h +++ b/include/salticidae/network.h @@ -140,7 +140,9 @@ class MsgNetwork: public ConnPool { size_t _burst_size; public: - Config(): _burst_size(1000) {} + Config(): Config(ConnPool::Config()) {} + Config(const ConnPool::Config &config): + ConnPool::Config(config), _burst_size(1000) {} Config &burst_size(size_t x) { _burst_size = x; @@ -380,12 +382,16 @@ class PeerNetwork: public MsgNetwork { IdentityMode _id_mode; public: - Config(): + Config(): Config(typename MsgNet::Config()) {} + + Config(const typename MsgNet::Config &config): + MsgNet::Config(config), _retry_conn_delay(2), _ping_period(30), _conn_timeout(180), _id_mode(IP_PORT_BASED) {} + Config &retry_conn_delay(double x) { _retry_conn_delay = x; return *this; @@ -518,9 +524,7 @@ void PeerNetwork::Conn::on_teardown() { p->ev_ping_timer.del(); p->connected = false; p->conn = nullptr; - SALTICIDAE_LOG_INFO("connection lost %s for %s", - std::string(*this).c_str(), - std::string(peer_id).c_str()); + SALTICIDAE_LOG_INFO("connection lost: %s", std::string(*this).c_str()); // try to reconnect p->ev_retry_timer = Event(pn->disp_ec, -1, [pn, peer_id = this->peer_id](int, int) { @@ -618,8 +622,9 @@ void PeerNetwork::start_active_conn(const NetAddr &addr) { /* begin: functions invoked by the user loop */ template void PeerNetwork::msg_ping(MsgPing &&msg, Conn &_conn) { + if (_conn.get_mode() == ConnPool::Conn::DEAD) return; auto conn = static_pointer_cast(_conn.self()); - if (!conn) return; + assert(conn); uint16_t port = msg.port; this->disp_tcall->async_call([this, conn, port](ThreadCall::Handle &msg) { SALTICIDAE_LOG_INFO("ping from %s, port %u", @@ -632,8 +637,9 @@ void PeerNetwork::msg_ping(MsgPing &&msg, Conn &_conn) { template void PeerNetwork::msg_pong(MsgPong &&msg, Conn &_conn) { + if (_conn.get_mode() == ConnPool::Conn::DEAD) return; auto conn = static_pointer_cast(_conn.self()); - if (!conn) return; + assert(conn); uint16_t port = msg.port; this->disp_tcall->async_call([this, conn, port](ThreadCall::Handle &msg) { auto it = id2peer.find(conn->peer_id); -- cgit v1.2.3