diff options
-rw-r--r-- | include/salticidae/network.h | 25 | ||||
-rw-r--r-- | src/conn.cpp | 8 |
2 files changed, 23 insertions, 10 deletions
diff --git a/include/salticidae/network.h b/include/salticidae/network.h index 27fc6d6..6a9b8cf 100644 --- a/include/salticidae/network.h +++ b/include/salticidae/network.h @@ -813,7 +813,6 @@ void PeerNetwork<O, _, __>::on_dispatcher_teardown(const ConnPool::conn_t &_conn p->inbound_conn = nullptr; p->outbound_conn = nullptr; p->ev_ping_timer.del(); - p->nonce = 0; SALTICIDAE_LOG_INFO("%sended %s%s%s <-/-> %s%s%s (via %s)%s", tty_tertiary_color, tty_secondary_color, @@ -831,9 +830,14 @@ void PeerNetwork<O, _, __>::on_dispatcher_teardown(const ConnPool::conn_t &_conn /* auto retry the connection */ if (p->cur_ntry > 0) p->cur_ntry--; if (p->cur_ntry) + { + p->nonce = 0; p->ev_retry_timer.add( p->state == Peer::State::RESET ? 0 : gen_rand_timeout(p->retry_delay)); + } + else + p->nonce = passive_nonce; } template<typename O, O _, O __> @@ -962,7 +966,12 @@ void PeerNetwork<O, _, __>::ping_handler(MsgPing &&msg, const conn_t &conn) { this->user_tcall->async_call([this, addr=msg.claimed_addr, conn](ThreadCall::Handle &) { if (unknown_peer_cb) unknown_peer_cb(addr, conn->get_peer_cert()); }); - throw PeerNetworkError(SALTI_ERROR_PEER_NOT_MATCH); + SALTICIDAE_LOG_WARN( + "%s%s%s: %s%s%s does not match the record", + tty_secondary_color, id_hex.c_str(), tty_reset_color, + tty_secondary_color, get_hex10(pid).c_str(), tty_reset_color); + this->disp_terminate(conn); + return; } auto &p = pit->second; if (p->state != Peer::State::DISCONNECTED || @@ -1028,9 +1037,11 @@ void PeerNetwork<O, _, __>::pong_handler(MsgPong &&msg, const conn_t &conn) { if (pit == known_peers.end()) { SALTICIDAE_LOG_WARN( - "%s%s%s: unexpected pong from an unknown peer", - tty_secondary_color, id_hex.c_str(), tty_reset_color); - throw PeerNetworkError(SALTI_ERROR_PEER_NOT_MATCH); + "%s%s%s: %s%s%s does not match the record", + tty_secondary_color, id_hex.c_str(), tty_reset_color, + tty_secondary_color, get_hex10(pid).c_str(), tty_reset_color); + this->disp_terminate(conn); + return; } auto &p = pit->second; assert(!p->addr.is_null() && p->addr == conn->get_addr()); @@ -1182,7 +1193,7 @@ int32_t PeerNetwork<O, _, __>::set_peer_addr(const PeerId &pid, const NetAddr &a throw PeerNetworkError(SALTI_ERROR_PEER_NOT_EXIST); auto &p = it->second; p->addr = addr; - p->nonce = addr.is_null() ? passive_nonce : 0; + //p->nonce = addr.is_null() ? passive_nonce : 0; } catch (const PeerNetworkError &) { this->recoverable_error(std::current_exception(), id); } catch (...) { this->disp_error_cb(std::current_exception()); } @@ -1203,6 +1214,8 @@ int32_t PeerNetwork<O, _, __>::del_peer(const PeerId &pid) { auto &p = it->second; p->conn->peer = nullptr; this->disp_terminate(p->conn); + if (p->inbound_conn) + this->disp_terminate(p->inbound_conn); if (p->outbound_conn) this->disp_terminate(p->outbound_conn); known_peers.erase(it); diff --git a/src/conn.cpp b/src/conn.cpp index 568edee..667cd4b 100644 --- a/src/conn.cpp +++ b/src/conn.cpp @@ -73,7 +73,7 @@ void ConnPool::Conn::_send_data(const conn_t &conn, int fd, int events) { ssize_t size = buff_seg.size(); if (!size) break; ret = send(fd, buff_seg.data(), size, 0); - SALTICIDAE_LOG_DEBUG("socket sent %zd bytes", ret); + SALTICIDAE_LOG_DEBUG("socket(%d) sent %zd bytes", fd, ret); size -= ret; if (size > 0) { @@ -125,7 +125,7 @@ void ConnPool::Conn::_recv_data(const conn_t &conn, int fd, int events) { bytearray_t buff_seg; buff_seg.resize(recv_chunk_size); ret = recv(fd, buff_seg.data(), recv_chunk_size, 0); - SALTICIDAE_LOG_DEBUG("socket read %zd bytes", ret); + SALTICIDAE_LOG_DEBUG("socket(%d) read %zd bytes", fd, ret); if (ret < 0) { if (errno == EWOULDBLOCK) break; @@ -163,7 +163,7 @@ void ConnPool::Conn::_send_data_tls(const conn_t &conn, int fd, int events) { ssize_t size = buff_seg.size(); if (!size) break; ret = tls->send(buff_seg.data(), size); - SALTICIDAE_LOG_DEBUG("ssl sent %zd bytes", ret); + SALTICIDAE_LOG_DEBUG("ssl(%d) sent %zd bytes", fd, ret); size -= ret; if (size > 0) { @@ -213,7 +213,7 @@ void ConnPool::Conn::_recv_data_tls(const conn_t &conn, int fd, int events) { bytearray_t buff_seg; buff_seg.resize(recv_chunk_size); ret = tls->recv(buff_seg.data(), recv_chunk_size); - SALTICIDAE_LOG_DEBUG("ssl read %zd bytes", ret); + SALTICIDAE_LOG_DEBUG("ssl(%d) read %zd bytes", fd, ret); if (ret < 0) { if (tls->get_error(ret) == SSL_ERROR_WANT_READ) break; |