Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/00-vcpkg-install/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
int main() {
auto ma_res = libp2p::multi::Multiaddress::create("/ip4/127.0.0.1/tcp/8080");
if (ma_res.has_value()) {
std::cout << "Created multiaddress: "
<< ma_res.value().getStringAddress() << std::endl;
std::cout << "Created multiaddress: " << ma_res.value().getStringAddress()
<< std::endl;
}
return 0;
}
8 changes: 6 additions & 2 deletions include/libp2p/common/metrics/instance_count.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
})(); \
return count; \
} \
Libp2pMetricsInstanceCount(const type *) { ++count(); } \
Libp2pMetricsInstanceCount(const type *) { \
++count(); \
} \
Libp2pMetricsInstanceCount(const Libp2pMetricsInstanceCount &) { \
++count(); \
} \
~Libp2pMetricsInstanceCount() { --count(); } \
~Libp2pMetricsInstanceCount() { \
--count(); \
} \
} libp2p_metrics_instance_count { \
this \
}
Expand Down
58 changes: 29 additions & 29 deletions include/libp2p/common/metrics/instance_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@
#include <list>
#include <mutex>

#define _LIBP2P_METRICS_INSTANCE_LIST(type) \
struct Libp2pMetricsInstanceList { \
using List = std::list<const type *>; \
struct State { \
std::mutex mutex; \
List list; \
static auto &get() { \
static State state; \
return state; \
} \
}; \
List::const_iterator it; \
Libp2pMetricsInstanceList(const type *ptr) { \
auto &state{State::get()}; \
std::lock_guard lock{state.mutex}; \
state.list.emplace_front(ptr); \
it = state.list.begin(); \
} \
Libp2pMetricsInstanceList(const Libp2pMetricsInstanceList &list) \
: Libp2pMetricsInstanceList{ \
(const type *)((uintptr_t)*list.it + (this - &list))} {} \
~Libp2pMetricsInstanceList() { \
auto &state{State::get()}; \
std::lock_guard lock{state.mutex}; \
state.list.erase(it); \
} \
void operator=(const Libp2pMetricsInstanceList &hook) {} \
} libp2p_metrics_instance_list { \
this \
#define _LIBP2P_METRICS_INSTANCE_LIST(type) \
struct Libp2pMetricsInstanceList { \
using List = std::list<const type *>; \
struct State { \
std::mutex mutex; \
List list; \
static auto &get() { \
static State state; \
return state; \
} \
}; \
List::const_iterator it; \
Libp2pMetricsInstanceList(const type *ptr) { \
auto &state{State::get()}; \
std::lock_guard lock{state.mutex}; \
state.list.emplace_front(ptr); \
it = state.list.begin(); \
} \
Libp2pMetricsInstanceList(const Libp2pMetricsInstanceList &list) \
: Libp2pMetricsInstanceList{ \
(const type *)((uintptr_t)*list.it + (this - &list))} {} \
~Libp2pMetricsInstanceList() { \
auto &state{State::get()}; \
std::lock_guard lock{state.mutex}; \
state.list.erase(it); \
} \
void operator=(const Libp2pMetricsInstanceList &hook) {} \
} libp2p_metrics_instance_list { \
this \
}

#define LIBP2P_METRICS_INSTANCE_LIST(type) \
Expand Down
8 changes: 4 additions & 4 deletions include/libp2p/event/emitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ namespace libp2p::event {
template <typename ExpectedEvent>
std::enable_if_t<
std::is_same_v<std::decay_t<ThisEvent>, std::decay_t<ExpectedEvent>>,
Signal<ExpectedEvent>>
&getSignal() {
Signal<ExpectedEvent>> &
getSignal() {
return signal_;
}

Expand All @@ -61,8 +61,8 @@ namespace libp2p::event {
template <typename ExpectedEvent>
std::enable_if_t<
!std::is_same_v<std::decay_t<ThisEvent>, std::decay_t<ExpectedEvent>>,
Signal<ExpectedEvent>>
&getSignal() {
Signal<ExpectedEvent>> &
getSignal() {
return Base::template getSignal<ExpectedEvent>();
}

Expand Down
8 changes: 4 additions & 4 deletions include/libp2p/multi/multiaddress_protocol_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

#pragma once

#include <unistd.h>
#include <array>
#include <functional>
#include <map>
#include <string_view>
#include <unistd.h>

namespace libp2p::multi {

Expand Down Expand Up @@ -58,8 +58,8 @@ namespace libp2p::multi {
// https://github.com/multiformats/rust-multiaddr/blob/3c7e813c3b1fdd4187a9ca9ff67e10af0e79231d/src/protocol.rs#L50-L53
X_PARITY_WS = 4770,
X_PARITY_WSS = 4780,
// Range for private use: 0x300000 – 0x3FFFFF
// Debug section
// Range for private use: 0x300000 – 0x3FFFFF
// Debug section
_DUMMY_PROTO_1 = 0x3DEAD1,
_DUMMY_PROTO_2 = 0x3DEAD2,
_DUMMY_PROTO_3 = 0x3DEAD3,
Expand Down Expand Up @@ -161,7 +161,7 @@ namespace libp2p::multi {
{Protocol::Code::P2P_CIRCUIT, 0, "p2p-circuit"},
{Protocol::Code::X_PARITY_WS, Protocol::kVarLen, "x-parity-ws"},
{Protocol::Code::X_PARITY_WSS, Protocol::kVarLen, "x-parity-wss"},
// Debug section
// Debug section
{Protocol::Code::_DUMMY_PROTO_1, 0, "_dummy_proto_1"},
{Protocol::Code::_DUMMY_PROTO_2, 0, "_dummy_proto_2"},
{Protocol::Code::_DUMMY_PROTO_3, Protocol::kVarLen, "_dummy_proto_3"},
Expand Down
6 changes: 4 additions & 2 deletions include/libp2p/protocol/kademlia/impl/kademlia_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ namespace libp2p::protocol::kademlia {
void performRepublishing();

// Helper methods for periodic operations
std::vector<PeerId> getClosestPeers(const Key& key, size_t count);
void replicateRecord(const Key& key, const Value& value, bool extend_expiration);
std::vector<PeerId> getClosestPeers(const Key &key, size_t count);
void replicateRecord(const Key &key,
const Value &value,
bool extend_expiration);

log::SubLogger log_;
};
Expand Down
2 changes: 1 addition & 1 deletion src/basic/protobuf_message_read_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace libp2p::basic {
std::shared_ptr<ReadWriter>
conn) // NOLINT(performance-unnecessary-value-param)
: read_writer_{
std::make_shared<MessageReadWriterUvarint>(std::move(conn))} {
std::make_shared<MessageReadWriterUvarint>(std::move(conn))} {
BOOST_ASSERT(read_writer_);
}
} // namespace libp2p::basic
2 changes: 1 addition & 1 deletion src/multi/multibase_codec/codecs/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace {
};

/// Returns max bytes needed to decode a base64 string
inline std::size_t constexpr decodedSize(std::size_t n) {
inline constexpr std::size_t decodedSize(std::size_t n) {
return n / 4 * 3; // requires n&3==0, smaller
}

Expand Down
2 changes: 1 addition & 1 deletion src/peer/key_repository/inmem_key_repository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace libp2p::peer {

InmemKeyRepository::InmemKeyRepository()
: kp_(std::make_shared<std::unordered_set<crypto::KeyPair>>()){};
: kp_(std::make_shared<std::unordered_set<crypto::KeyPair>>()) {};

void InmemKeyRepository::clear(const PeerId &p) {
auto it1 = pub_.find(p);
Expand Down
2 changes: 1 addition & 1 deletion src/security/tls/tls_adaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#include <libp2p/peer/peer_id.hpp>
#include <libp2p/security/tls/ssl_context.hpp>
#include <libp2p/security/tls/tls_connection.hpp>
#include <libp2p/security/tls/tls_details.hpp>
#include <libp2p/security/tls/tls_errors.hpp>
#include <libp2p/security/tls/tls_connection.hpp>

namespace libp2p::security {

Expand Down
3 changes: 1 addition & 2 deletions test/acceptance/p2p/host/peer/tick_counter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ struct TickCounter {
auto actual_count = ticks_count.load();
ASSERT_EQ(actual_count, required_count) // NOLINT
<< "sending messages from <" << ci << "> client to <" << si
<< "> server "
<< "required messages count <" << required_count
<< "> server " << "required messages count <" << required_count
<< ">count doesn't match actual count <" << actual_count << ">";
}

Expand Down
4 changes: 3 additions & 1 deletion test/libp2p/common/metrics_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ TEST(MetricsInstance, AddOne) {
* @then Foo removed from metrics
*/
TEST(MetricsInstance, RemoveOne) {
{ Foo foo; }
{
Foo foo;
}
expectFoo({});
}

Expand Down
5 changes: 2 additions & 3 deletions test/libp2p/multi/utils/protocol_list_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ TEST(ProtocolList, getByCode) {
TEST(ProtocolList, getProtocols) {
auto &protocols = ProtocolList::getProtocols();
static_assert(protocols.size() == ProtocolList::kProtocolsNum);
auto it = std::ranges::find_if(protocols, [](auto &p) {
return p.name == "ip4";
});
auto it =
std::ranges::find_if(protocols, [](auto &p) { return p.name == "ip4"; });
ASSERT_NE(it, protocols.end());
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ struct InmemAddressRepository_Test : public ::testing::Test {

TEST_F(InmemAddressRepository_Test, GarbageCollection) {
// @given address repository that has 2 peers, and some addresses
ASSERT_OUTCOME_SUCCESS(db->addAddresses(p1, std::vector<Multiaddress>{ma1, ma2}, 10ms));
ASSERT_OUTCOME_SUCCESS(db->addAddresses(p1, std::vector<Multiaddress>{ma3, ma4}, 1000ms));
ASSERT_OUTCOME_SUCCESS(db->upsertAddresses(p2, std::vector<Multiaddress>{ma4}, 10ms));
ASSERT_OUTCOME_SUCCESS(
db->addAddresses(p1, std::vector<Multiaddress>{ma1, ma2}, 10ms));
ASSERT_OUTCOME_SUCCESS(
db->addAddresses(p1, std::vector<Multiaddress>{ma3, ma4}, 1000ms));
ASSERT_OUTCOME_SUCCESS(
db->upsertAddresses(p2, std::vector<Multiaddress>{ma4}, 10ms));

// @when no collectGarbage is called
{
Expand Down Expand Up @@ -135,8 +138,10 @@ TEST_F(InmemAddressRepository_Test, GarbageCollection) {
* @then ttl is updated, ma1 is not evicted
*/
TEST_F(InmemAddressRepository_Test, UpdateAddress) {
ASSERT_OUTCOME_SUCCESS(db->addAddresses(p1, std::vector<Multiaddress>{ma1}, 10ms));
ASSERT_OUTCOME_SUCCESS(db->upsertAddresses(p1, std::vector<Multiaddress>{ma1}, 1000ms));
ASSERT_OUTCOME_SUCCESS(
db->addAddresses(p1, std::vector<Multiaddress>{ma1}, 10ms));
ASSERT_OUTCOME_SUCCESS(
db->upsertAddresses(p1, std::vector<Multiaddress>{ma1}, 1000ms));

{
ASSERT_OUTCOME_SUCCESS(v, db->getAddresses(p1));
Expand All @@ -157,8 +162,10 @@ TEST_F(InmemAddressRepository_Test, UpdateAddress) {
* @then ttl of ma1 is not updated, ma1 is evicted. ma2 is inserted.
*/
TEST_F(InmemAddressRepository_Test, InsertAddress) {
ASSERT_OUTCOME_SUCCESS(db->addAddresses(p1, std::vector<Multiaddress>{ma1}, 10ms));
ASSERT_OUTCOME_SUCCESS(db->upsertAddresses(p1, std::vector<Multiaddress>{ma2}, 1000ms));
ASSERT_OUTCOME_SUCCESS(
db->addAddresses(p1, std::vector<Multiaddress>{ma1}, 10ms));
ASSERT_OUTCOME_SUCCESS(
db->upsertAddresses(p1, std::vector<Multiaddress>{ma2}, 1000ms));

{
ASSERT_OUTCOME_SUCCESS(v, db->getAddresses(p1));
Expand Down
20 changes: 13 additions & 7 deletions test/libp2p/peer/peer_id_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ TEST_F(PeerIdTest, FromPubkeySuccess) {
pubkey.data = kBuffer;

auto hash = libp2p::crypto::sha256(pubkey.data).value();
ASSERT_OUTCOME_SUCCESS(multihash, Multihash::create(
libp2p::multi::sha256, Buffer{hash.begin(), hash.end()}));
ASSERT_OUTCOME_SUCCESS(multihash,
Multihash::create(libp2p::multi::sha256,
Buffer{hash.begin(), hash.end()}));

ASSERT_OUTCOME_SUCCESS(peer_id, PeerId::fromPublicKey(ProtobufKey{pubkey.data}));
ASSERT_OUTCOME_SUCCESS(peer_id,
PeerId::fromPublicKey(ProtobufKey{pubkey.data}));
EXPECT_EQ(peer_id.toBase58(), encodeBase58(multihash.toBuffer()));
EXPECT_EQ(peer_id.toMultihash(), multihash);
}
Expand All @@ -47,7 +49,8 @@ TEST_F(PeerIdTest, FromPubkeySuccess) {
* @then creation is successful
*/
TEST_F(PeerIdTest, FromBase58Success) {
ASSERT_OUTCOME_SUCCESS(hash, Multihash::create(libp2p::multi::sha256, kBuffer));
ASSERT_OUTCOME_SUCCESS(hash,
Multihash::create(libp2p::multi::sha256, kBuffer));
auto hash_b58 = encodeBase58(hash.toBuffer());

ASSERT_OUTCOME_SUCCESS(peer_id, PeerId::fromBase58(hash_b58));
Expand Down Expand Up @@ -81,7 +84,8 @@ TEST_F(PeerIdTest, FromBase58IcorrectHash) {
* @then creation fails
*/
TEST_F(PeerIdTest, FromBase58NotSha256) {
ASSERT_OUTCOME_SUCCESS(hash, Multihash::create(libp2p::multi::sha512, kBuffer));
ASSERT_OUTCOME_SUCCESS(hash,
Multihash::create(libp2p::multi::sha512, kBuffer));
auto hash_b58 = encodeBase58(hash.toBuffer());

EXPECT_FALSE(PeerId::fromBase58(hash_b58));
Expand All @@ -93,7 +97,8 @@ TEST_F(PeerIdTest, FromBase58NotSha256) {
* @then creation is successful
*/
TEST_F(PeerIdTest, FromHashSuccess) {
ASSERT_OUTCOME_SUCCESS(hash, Multihash::create(libp2p::multi::sha256, kBuffer));
ASSERT_OUTCOME_SUCCESS(hash,
Multihash::create(libp2p::multi::sha256, kBuffer));
auto hash_b58 = encodeBase58(hash.toBuffer());

ASSERT_OUTCOME_SUCCESS(peer_id, PeerId::fromHash(hash));
Expand All @@ -107,7 +112,8 @@ TEST_F(PeerIdTest, FromHashSuccess) {
* @then creation fails
*/
TEST_F(PeerIdTest, FromHashNotSha256) {
ASSERT_OUTCOME_SUCCESS(hash, Multihash::create(libp2p::multi::sha512, kBuffer));
ASSERT_OUTCOME_SUCCESS(hash,
Multihash::create(libp2p::multi::sha512, kBuffer));

EXPECT_FALSE(PeerId::fromHash(hash));
}
3 changes: 2 additions & 1 deletion test/libp2p/transport/tcp/tcp_listener_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ TEST_F(TcpListenerTest, DoubleClose) {
EXPECT_CALL(cb, Call(_)).WillOnce(Invoke([](CapConnResult c) {
if (!c) {
if (!c) {
ASSERT_EQ(c.error().value(), (int)boost::asio::error::operation_aborted);
ASSERT_EQ(c.error().value(),
(int)boost::asio::error::operation_aborted);
} else {
ADD_FAILURE();
}
Expand Down
16 changes: 10 additions & 6 deletions test/libp2p/transport/upgrader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ class UpgraderTest : public testing::Test {
TEST_F(UpgraderTest, UpgradeLayersInitiator) {
setAllOutbound();

ASSERT_OUTCOME_SUCCESS(address, libp2p::multi::Multiaddress::create(
"/ip4/127.0.0.1/tcp/1234/_dummy_proto_1/_dummy_proto_2"
"/p2p/12D3KooWEgUjBV5FJAuBSoNMRYFRHjV7PjZwRQ7b43EKX9g7D6xV"));
ASSERT_OUTCOME_SUCCESS(
address,
libp2p::multi::Multiaddress::create(
"/ip4/127.0.0.1/tcp/1234/_dummy_proto_1/_dummy_proto_2"
"/p2p/12D3KooWEgUjBV5FJAuBSoNMRYFRHjV7PjZwRQ7b43EKX9g7D6xV"));
auto layers = detail::asTcp(address).value().second;

EXPECT_CALL(*std::static_pointer_cast<LayerAdaptorMock>(layer_adaptors_[0]),
Expand All @@ -148,9 +150,11 @@ TEST_F(UpgraderTest, UpgradeLayersInitiator) {
TEST_F(UpgraderTest, UpgradeLayersNotInitiator) {
setAllInbound();

ASSERT_OUTCOME_SUCCESS(address, libp2p::multi::Multiaddress::create(
"/ip4/127.0.0.1/tcp/1234/_dummy_proto_1/_dummy_proto_2"
"/p2p/12D3KooWEgUjBV5FJAuBSoNMRYFRHjV7PjZwRQ7b43EKX9g7D6xV"));
ASSERT_OUTCOME_SUCCESS(
address,
libp2p::multi::Multiaddress::create(
"/ip4/127.0.0.1/tcp/1234/_dummy_proto_1/_dummy_proto_2"
"/p2p/12D3KooWEgUjBV5FJAuBSoNMRYFRHjV7PjZwRQ7b43EKX9g7D6xV"));
auto layers = detail::asTcp(address).value().second;

EXPECT_CALL(
Expand Down
Loading