Browse Source

Hotfix/identify (#88)

* hotfix to prevent unexpected exception from identify msg processor

* secio connection read buffer as member (performance)
pull/89/head
art-gor 4 years ago
committed by GitHub
parent
commit
7314b5d10c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      include/libp2p/security/secio/secio_connection.hpp
  2. 21
      src/protocol/identify/identify_msg_processor.cpp
  3. 8
      src/security/secio/secio_connection.cpp

3
include/libp2p/security/secio/secio_connection.hpp

@ -162,6 +162,9 @@ namespace libp2p::connection {
boost::optional<std::unique_ptr<crypto::aes::AesCtr>> remote_decryptor_; boost::optional<std::unique_ptr<crypto::aes::AesCtr>> remote_decryptor_;
std::queue<uint8_t> user_data_buffer_; std::queue<uint8_t> user_data_buffer_;
std::shared_ptr<common::ByteArray> read_buffer_;
common::Logger log_ = common::createLogger("SECCONN"); common::Logger log_ = common::createLogger("SECCONN");
}; };
} // namespace libp2p::connection } // namespace libp2p::connection

21
src/protocol/identify/identify_msg_processor.cpp

@ -7,12 +7,12 @@
#include <tuple> #include <tuple>
#include <generated/protocol/identify/protobuf/identify.pb.h>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <libp2p/basic/protobuf_message_read_writer.hpp> #include <libp2p/basic/protobuf_message_read_writer.hpp>
#include <libp2p/network/network.hpp> #include <libp2p/network/network.hpp>
#include <libp2p/peer/address_repository.hpp> #include <libp2p/peer/address_repository.hpp>
#include <libp2p/protocol/identify/utils.hpp> #include <libp2p/protocol/identify/utils.hpp>
#include <generated/protocol/identify/protobuf/identify.pb.h>
namespace { namespace {
inline std::string fromMultiaddrToString(const libp2p::multi::Multiaddress &ma) { inline std::string fromMultiaddrToString(const libp2p::multi::Multiaddress &ma) {
@ -354,16 +354,15 @@ namespace libp2p::protocol {
log_->debug("can not get addresses for peer {}", peer_id.toBase58()); log_->debug("can not get addresses for peer {}", peer_id.toBase58());
} }
switch (conn_manager_.connectedness({peer_id, addresses.value()})) { bool permanent_ttl =
case network::ConnectionManager::Connectedness::CONNECTED: (addresses
add_res = addr_repo.upsertAddresses(peer_id, listen_addresses, && (conn_manager_.connectedness({peer_id, addresses.value()})
peer::ttl::kPermanent); == network::ConnectionManager::Connectedness::CONNECTED));
break;
default: add_res = addr_repo.upsertAddresses(
add_res = addr_repo.upsertAddresses(peer_id, listen_addresses, peer_id, listen_addresses,
peer::ttl::kRecentlyConnected); permanent_ttl ? peer::ttl::kPermanent : peer::ttl::kRecentlyConnected);
break;
}
if (!add_res) { if (!add_res) {
log_->error("cannot add addresses to peer {}: {}", peer_id.toBase58(), log_->error("cannot add addresses to peer {}: {}", peer_id.toBase58(),
add_res.error().message()); add_res.error().message());

8
src/security/secio/secio_connection.cpp

@ -138,6 +138,9 @@ namespace libp2p::connection {
} else { } else {
return Error::UNSUPPORTED_CIPHER; return Error::UNSUPPORTED_CIPHER;
} }
read_buffer_ = std::make_shared<common::ByteArray>(kMaxFrameSize);
return outcome::success(); return outcome::success();
} }
@ -260,10 +263,9 @@ namespace libp2p::connection {
} }
void SecioConnection::readNextMessage(ReadCallbackFunc cb) { void SecioConnection::readNextMessage(ReadCallbackFunc cb) {
auto buffer{std::make_shared<common::ByteArray>(kMaxFrameSize)};
raw_connection_->read( raw_connection_->read(
*buffer, kLenMarkerSize, *read_buffer_, kLenMarkerSize,
[self{shared_from_this()}, buffer, [self{shared_from_this()}, buffer=read_buffer_,
cb{std::move(cb)}](outcome::result<size_t> read_bytes_res) mutable { cb{std::move(cb)}](outcome::result<size_t> read_bytes_res) mutable {
IO_OUTCOME_TRY(len_marker_size, read_bytes_res, cb) IO_OUTCOME_TRY(len_marker_size, read_bytes_res, cb)
if (len_marker_size != kLenMarkerSize) { if (len_marker_size != kLenMarkerSize) {

Loading…
Cancel
Save