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
26 changes: 19 additions & 7 deletions build/CommonCompilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(DEFINED SANITIZE_CODE AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${SANITIZE_CODE}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${SANITIZE_CODE}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${SANITIZE_CODE}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=${SANITIZE_CODE}")
add_compile_options("-fsanitize=${SANITIZE_CODE}")
add_link_options("-fsanitize=${SANITIZE_CODE}")
if (DEFINED SANITIZE_CODE)
message(STATUS "Building with sanitizer: ${SANITIZE_CODE}")
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${SANITIZE_CODE}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${SANITIZE_CODE}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${SANITIZE_CODE}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=${SANITIZE_CODE}")
add_compile_options("-fsanitize=${SANITIZE_CODE}")
add_link_options("-fsanitize=${SANITIZE_CODE}")
elseif (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=${SANITIZE_CODE}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fsanitize=${SANITIZE_CODE}")
add_compile_options("/fsanitize=${SANITIZE_CODE}")
endif()
endif()

include(GNUInstallDirs)
Expand All @@ -41,6 +48,11 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()

if(WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_WIN32_WINNT=0x0A00 -DNOMINMAX")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=0x0A00 -DNOMINMAX")
endif()

# Define zkllvm directory
if(NOT DEFINED ZKLLVM_BUILD_DIR)
get_filename_component(BUILD_PLATFORM_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
Expand Down
10 changes: 5 additions & 5 deletions example/account_handling/AccountHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file AccountHelper.cpp
* @brief
* @brief
* @date 2024-05-15
* @author Henrique A. Klein (hklein@gnus.ai)
*/
Expand Down Expand Up @@ -83,7 +83,7 @@ namespace sgns
crdt::KeyPairFileStorage( pubsubKeyPath ).GetKeyPair().value() );
pubsub_->Start( 40001, {} );

auto scheduler = std::make_shared<libp2p::protocol::AsioScheduler>( io_, libp2p::protocol::SchedulerConfig{} );
auto scheduler = std::make_shared<libp2p::basic::SchedulerImpl>( std::make_shared<libp2p::basic::AsioSchedulerBackend>( io_ ), libp2p::basic::Scheduler::Config{ std::chrono::milliseconds( 100 ) } );
auto graphsyncnetwork = std::make_shared<sgns::ipfs_lite::ipfs::graphsync::Network>( pubsub_->GetHost(),
scheduler );
auto generator = std::make_shared<sgns::ipfs_lite::ipfs::graphsync::RequestIdGenerator>();
Expand Down Expand Up @@ -141,14 +141,14 @@ namespace sgns
std::vector<unsigned char> hash( SHA256_DIGEST_LENGTH );
SHA256( inputBytes.data(), inputBytes.size(), hash.data() );
//Provide CID
libp2p::protocol::kademlia::ContentId key( hash );
auto key = libp2p::multi::ContentIdentifierCodec::encodeCIDV0( hash.data(), hash.size() );
pubsub_->GetDHT()->Start();
pubsub_->GetDHT()->ProvideCID( key, true );

auto cidtest = libp2p::multi::ContentIdentifierCodec::decode( key.data );
auto cidtest = libp2p::multi::ContentIdentifierCodec::decode( key );

auto cidstring = libp2p::multi::ContentIdentifierCodec::toString( cidtest.value() );
std::cout << "CID Test::" << cidstring.value() << std::endl;
std::cout << "CID Test::" << cidstring.value() << '\n';

//Also Find providers
pubsub_->StartFindingPeers( key );
Expand Down
8 changes: 5 additions & 3 deletions example/crdt_globaldb/globaldb_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

#include <libp2p/log/configurator.hpp>
#include <libp2p/log/logger.hpp>
#include <libp2p/basic/scheduler/asio_scheduler_backend.hpp>
#include <libp2p/basic/scheduler/scheduler_impl.hpp>
#include <ipfs_lite/ipfs/graphsync/impl/network/network.hpp>
#include <ipfs_lite/ipfs/graphsync/impl/local_requests.hpp>
#include <libp2p/protocol/common/asio/asio_scheduler.hpp>

using Buffer = sgns::base::Buffer;
using HierarchicalKey = sgns::crdt::HierarchicalKey;
Expand Down Expand Up @@ -119,13 +120,14 @@ int main( int argc, char **argv )
sgns::crdt::KeyPairFileStorage( strDatabasePath + "/pubsub" ).GetKeyPair().value() );
pubsub->Start( pubsubListeningPort, pubsubBootstrapPeers );

auto scheduler = std::make_shared<libp2p::protocol::AsioScheduler>( io, libp2p::protocol::SchedulerConfig{} );
auto scheduler = std::make_shared<libp2p::basic::SchedulerImpl>(
std::make_shared<libp2p::basic::AsioSchedulerBackend>( io ),
libp2p::basic::Scheduler::Config{ std::chrono::milliseconds( 100 ) } );
auto graphsyncnetwork = std::make_shared<sgns::ipfs_lite::ipfs::graphsync::Network>( pubsub->GetHost(), scheduler );
auto generator = std::make_shared<sgns::ipfs_lite::ipfs::graphsync::RequestIdGenerator>();
auto crdtOptions = sgns::crdt::CrdtOptions::DefaultOptions();
crdtOptions->logger = logger;


auto globaldb_ret =
sgns::crdt::GlobalDB::New( io, strDatabasePath, pubsub, crdtOptions, graphsyncnetwork, scheduler, generator );

Expand Down
1 change: 0 additions & 1 deletion example/graphsync_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ add_executable(graphsync_app
target_link_libraries(graphsync_app
ipfs-lite-cpp::graphsync
ipfs-lite-cpp::ipfs_merkledag_service
p2p::asio_scheduler
Boost::program_options
${WIN_CRYPT_LIBRARY}
)
14 changes: 7 additions & 7 deletions example/graphsync_app/graphsync_acceptance_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <boost/di/extension/scopes/shared.hpp>

#include <libp2p/injector/host_injector.hpp>
#include <libp2p/protocol/common/asio/asio_scheduler.hpp>
#include <libp2p/basic/scheduler/asio_scheduler_backend.hpp>

#include <ipfs_lite/ipfs/graphsync/impl/graphsync_impl.hpp>
#include <ipfs_lite/ipld/impl/ipld_node_impl.hpp>
Expand Down Expand Up @@ -32,16 +32,16 @@ createNodeObjects(std::shared_ptr<boost::asio::io_context> io)
{
// [boost::di::override] allows for creating multiple hosts for testing
// purposes
auto injector =
auto injector =
libp2p::injector::makeHostInjector<boost::di::extension::shared_config>(
boost::di::bind<boost::asio::io_context>.to(io)[boost::di::override]);


std::pair<std::shared_ptr<sgns::ipfs_lite::ipfs::graphsync::Graphsync>, std::shared_ptr<libp2p::Host>>
objects;
objects.second = injector.template create<std::shared_ptr<libp2p::Host>>();
auto scheduler = std::make_shared<libp2p::protocol::AsioScheduler>(
io, libp2p::protocol::SchedulerConfig{});
auto scheduler = std::make_shared<libp2p::basic::SchedulerImpl>(
std::make_shared<libp2p::basic::AsioSchedulerBackend>(io), libp2p::basic::Scheduler::Config{ std::chrono::milliseconds(100) });
auto graphsyncnetwork = std::make_shared<sgns::ipfs_lite::ipfs::graphsync::Network>( objects.second, scheduler );
auto generator = std::make_shared<sgns::ipfs_lite::ipfs::graphsync::RequestIdGenerator>();
objects.first =
Expand All @@ -54,7 +54,7 @@ createNodeObjects(std::shared_ptr<boost::asio::io_context> io, libp2p::crypto::K
{
// [boost::di::override] allows for creating multiple hosts for testing
// purposes
auto injector =
auto injector =
libp2p::injector::makeHostInjector<boost::di::extension::shared_config>(
boost::di::bind<boost::asio::io_context>.to(io)[boost::di::override],
boost::di::bind<libp2p::crypto::KeyPair>.to(std::move(keyPair))[boost::di::override]);
Expand All @@ -63,8 +63,8 @@ createNodeObjects(std::shared_ptr<boost::asio::io_context> io, libp2p::crypto::K
std::pair<std::shared_ptr<sgns::ipfs_lite::ipfs::graphsync::Graphsync>, std::shared_ptr<libp2p::Host>>
objects;
objects.second = injector.template create<std::shared_ptr<libp2p::Host>>();
auto scheduler = std::make_shared<libp2p::protocol::AsioScheduler>(
io, libp2p::protocol::SchedulerConfig{});
auto scheduler = std::make_shared<libp2p::basic::SchedulerImpl>(
std::make_shared<libp2p::basic::AsioSchedulerBackend>(io), libp2p::basic::Scheduler::Config{ std::chrono::milliseconds(100) });
auto graphsyncnetwork = std::make_shared<sgns::ipfs_lite::ipfs::graphsync::Network>( objects.second, scheduler );
auto generator = std::make_shared<sgns::ipfs_lite::ipfs::graphsync::RequestIdGenerator>();
objects.first = std::make_shared<sgns::ipfs_lite::ipfs::graphsync::GraphsyncImpl>( objects.second,
Expand Down
6 changes: 3 additions & 3 deletions example/ipfs_client/ipfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <libp2p/injector/host_injector.hpp>
#include <libp2p/injector/kademlia_injector.hpp>
#include <libp2p/host/host.hpp>
#include <libp2p/protocol/common/asio/asio_scheduler.hpp>
#include <libp2p/basic/scheduler/asio_scheduler_backend.hpp>
#include <libp2p/multi/content_identifier_codec.hpp>
#include <libp2p/protocol/identify/identify.hpp>
#include <libp2p/log/configurator.hpp>
Expand Down Expand Up @@ -207,7 +207,7 @@ int main(int argc, char* argv[])
//auto peer_id = libp2p::peer::PeerId::fromBase58("QmRXP6S7qwSH4vjSrZeJUGT68ww8rQVhoFWU5Kp7UkVkPN").value();
//auto peer_id = libp2p::peer::PeerId::fromBase58("QmTigmvYEhvcwEpZMuXHcC5HGQG4iKDCKaNeZuoy69QsJw").value();

// Peers addresses:
// Peers addresses:
// /ip4/127.0.0.1/udp/4001/quic;
// /ip4/54.89.142.24/udp/4001/quic;
// /ip4/54.89.142.24/tcp/1031;
Expand All @@ -219,7 +219,7 @@ int main(int argc, char* argv[])
// /ip4/10.0.65.121/tcp/4001;
// /ip4/127.0.0.1/tcp/4001;
// /ip4/54.89.142.24/tcp/1024;
auto peer_address =
auto peer_address =
libp2p::multi::Multiaddress::create(
//"/ip4/10.0.65.121/tcp/4001/p2p/QmRXP6S7qwSH4vjSrZeJUGT68ww8rQVhoFWU5Kp7UkVkPN"
//"/ip4/54.89.142.24/tcp/4001/p2p/QmRXP6S7qwSH4vjSrZeJUGT68ww8rQVhoFWU5Kp7UkVkPN"
Expand Down
16 changes: 3 additions & 13 deletions example/ipfs_client/ipfs_dht.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,10 @@ void IpfsDHT::FindProviders(
const libp2p::multi::ContentIdentifier& cid,
std::function<void(libp2p::outcome::result<std::vector<libp2p::peer::PeerInfo>> onProvidersFound)> onProvidersFound)
{
auto kadCID = libp2p::protocol::kademlia::ContentId::fromWire(
auto kadCID = libp2p::protocol::kademlia::ContentId(
libp2p::multi::ContentIdentifierCodec::encode(cid).value());
if (!kadCID)
{
logger_->error("Wrong CID {}",
libp2p::peer::PeerId::fromHash(cid.content_address).value().toBase58());
// TODO: pass an error to callback
//onProvidersFound(ERROR);
}
else
{
[[maybe_unused]] auto res = kademlia_->findProviders(
kadCID.value(), 0, onProvidersFound);
}

[[maybe_unused]] auto res = kademlia_->findProviders(kadCID, 0, std::move(onProvidersFound));
}

std::vector<libp2p::peer::PeerInfo> IpfsDHT::GetBootstrapNodes() const
Expand Down
5 changes: 3 additions & 2 deletions example/ipfs_client/ping_session.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ping_session.hpp"
#include <libp2p/connection/stream_and_protocol.hpp>
#include <libp2p/crypto/random_generator/boost_generator.hpp>

PingSession::PingSession(std::shared_ptr<boost::asio::io_context> io, std::shared_ptr<libp2p::Host> host)
Expand All @@ -19,8 +20,8 @@ void PingSession::Init()
});

host_->setProtocolHandler(
ping_->getProtocolId(),
[ctx = shared_from_this()](libp2p::protocol::BaseProtocol::StreamResult rstream) {
{ping_->getProtocolId()},
[ctx = shared_from_this()](libp2p::StreamAndProtocol rstream) {
ctx->ping_->handle(std::move(rstream));
});
}
Expand Down
8 changes: 4 additions & 4 deletions example/ipfs_client2/testipfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <libp2p/injector/host_injector.hpp>
#include <libp2p/injector/kademlia_injector.hpp>
#include <libp2p/host/host.hpp>
#include <libp2p/protocol/common/asio/asio_scheduler.hpp>
#include <libp2p/basic/scheduler/asio_scheduler_backend.hpp>
#include <libp2p/multi/content_identifier_codec.hpp>
#include <libp2p/protocol/identify/identify.hpp>
#include <libp2p/log/configurator.hpp>
Expand Down Expand Up @@ -336,15 +336,15 @@ int main(int argc, char *argv[]) {
auto cid = libp2p::multi::ContentIdentifierCodec::fromString("QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D").value();
auto content_id = libp2p::protocol::kademlia::ContentId::fromWire(
libp2p::multi::ContentIdentifierCodec::encode(cid).value());
auto &scheduler = injector.create<libp2p::protocol::Scheduler &>();
auto &scheduler = injector.create<libp2p::basic::Scheduler &>();

std::function<void()> find_providers = [&] {
[[maybe_unused]] auto res1 = kademlia->findProviders(
content_id.value(), 100,
[&](libp2p::outcome::result<std::vector<libp2p::peer::PeerInfo>>
res) {
scheduler
.schedule(libp2p::protocol::scheduler::toTicks(
.schedule(libp2p::basic::Scheduler::toTicks(
kademlia_config.randomWalk.interval),
find_providers)
.detach();
Expand All @@ -368,7 +368,7 @@ int main(int argc, char *argv[]) {
kademlia->provide(content_id.value(), !kademlia_config.passiveMode);

scheduler
.schedule(libp2p::protocol::scheduler::toTicks(
.schedule(libp2p::basic::Scheduler::toTicks(
kademlia_config.randomWalk.interval),
provide)
.detach();
Expand Down
5 changes: 3 additions & 2 deletions example/processing_dapp/processing_dapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "crdt/globaldb/globaldb.hpp"
#include "crdt/globaldb/keypair_file_storage.hpp"

#include <libp2p/basic/scheduler/scheduler_impl.hpp>
#include <libp2p/multi/multibase_codec/multibase_codec_impl.hpp>
#include <libp2p/log/configurator.hpp>
#include <libp2p/log/logger.hpp>
Expand All @@ -13,7 +14,7 @@
#include <iostream>
#include <ipfs_lite/ipfs/graphsync/impl/network/network.hpp>
#include <ipfs_lite/ipfs/graphsync/impl/local_requests.hpp>
#include <libp2p/protocol/common/asio/asio_scheduler.hpp>
#include <libp2p/basic/scheduler/asio_scheduler_backend.hpp>

using namespace sgns::processing;

Expand Down Expand Up @@ -235,7 +236,7 @@ int main( int argc, char *argv[] )

auto io = std::make_shared<boost::asio::io_context>();
auto crdtOptions = sgns::crdt::CrdtOptions::DefaultOptions();
auto scheduler = std::make_shared<libp2p::protocol::AsioScheduler>( io, libp2p::protocol::SchedulerConfig{} );
auto scheduler = std::make_shared<libp2p::basic::SchedulerImpl>( std::make_shared<libp2p::basic::AsioSchedulerBackend>( io ), libp2p::basic::Scheduler::Config{ std::chrono::milliseconds( 100 ) } );
auto graphsyncnetwork = std::make_shared<sgns::ipfs_lite::ipfs::graphsync::Network>( pubs->GetHost(), scheduler );
auto generator = std::make_shared<sgns::ipfs_lite::ipfs::graphsync::RequestIdGenerator>();

Expand Down
5 changes: 3 additions & 2 deletions example/processing_dapp/processing_dapp_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include "crdt/globaldb/globaldb.hpp"
#include <ipfs_lite/ipfs/graphsync/impl/network/network.hpp>
#include <ipfs_lite/ipfs/graphsync/impl/local_requests.hpp>
#include <libp2p/protocol/common/asio/asio_scheduler.hpp>
#include <libp2p/basic/scheduler/asio_scheduler_backend.hpp>
#include <libp2p/basic/scheduler/scheduler_impl.hpp>

using namespace sgns::processing;

Expand Down Expand Up @@ -286,7 +287,7 @@ int main( int argc, char *argv[] )

auto io = std::make_shared<boost::asio::io_context>();
auto crdtOptions = sgns::crdt::CrdtOptions::DefaultOptions();
auto scheduler = std::make_shared<libp2p::protocol::AsioScheduler>( io, libp2p::protocol::SchedulerConfig{} );
auto scheduler = std::make_shared<libp2p::basic::SchedulerImpl>( std::make_shared<libp2p::basic::AsioSchedulerBackend>( io ), libp2p::basic::Scheduler::Config{ std::chrono::milliseconds( 100 ) } );
auto graphsyncnetwork = std::make_shared<sgns::ipfs_lite::ipfs::graphsync::Network>( pubs->GetHost(), scheduler );
auto generator = std::make_shared<sgns::ipfs_lite::ipfs::graphsync::RequestIdGenerator>();
auto globaldb_ret = sgns::crdt::GlobalDB::New(
Expand Down
Loading
Loading