globaldb/GlobalDbNetworkComposition.hpp
Namespaces
Classes
Functions
Functions Documentation
function OUTCOME_HPP_DECLARE_ERROR_2
OUTCOME_HPP_DECLARE_ERROR_2(
sgns::crdt ,
GlobalDbNetworkComposition::Error
)
Source code
#ifndef SUPERGENIUS_CRDT_GLOBALDB_NETWORK_COMPOSITION_HPP
#define SUPERGENIUS_CRDT_GLOBALDB_NETWORK_COMPOSITION_HPP
#include <cstdint>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include "base/logger.hpp"
#include "outcome/outcome.hpp"
namespace libp2p::basic
{
class Scheduler;
}
namespace sgns::ipfs_lite::ipfs::graphsync
{
class Network;
class RequestIdGenerator;
}
namespace sgns::ipfs_pubsub
{
class GossipPubSub;
}
namespace sgns::crdt
{
class GlobalDB;
class GlobalDbNetworkComposition
{
public:
struct Config
{
std::string network_config_path;
std::string database_path;
std::string listen_topic;
std::string broadcast_topic;
base::Logger logger;
};
enum class Error : uint8_t
{
INVALID_CONFIG = 0,
NETWORK_CONFIG_IO,
NETWORK_CONFIG_PARSE,
KEYPAIR_LOAD_FAILED,
PUBSUB_START_FAILED,
GLOBALDB_CREATE_FAILED,
TOPIC_CONFIGURATION_FAILED,
};
static outcome::result<std::shared_ptr<GlobalDbNetworkComposition>> Create( Config config );
GlobalDbNetworkComposition( const GlobalDbNetworkComposition & ) = delete;
GlobalDbNetworkComposition &operator=( const GlobalDbNetworkComposition & ) = delete;
~GlobalDbNetworkComposition();
outcome::result<void> Start();
void Stop();
std::shared_ptr<GlobalDB> db() const;
std::string interface_address() const;
private:
struct NetworkConfig
{
uint16_t pubsub_port{ 0 };
std::string pubsub_bind_address{ "0.0.0.0" };
std::vector<std::string> bootstrap_addresses;
int high_water{ 300 };
int low_water{ 150 };
};
GlobalDbNetworkComposition( Config config, NetworkConfig network_config );
static outcome::result<NetworkConfig> LoadNetworkConfig( const std::string &path, const base::Logger &logger );
Config config_;
NetworkConfig network_config_;
mutable std::mutex mutex_;
bool started_{ false };
std::shared_ptr<ipfs_pubsub::GossipPubSub> pubsub_;
std::shared_ptr<libp2p::basic::Scheduler> scheduler_;
std::shared_ptr<ipfs_lite::ipfs::graphsync::Network> graphsync_network_;
std::shared_ptr<ipfs_lite::ipfs::graphsync::RequestIdGenerator> request_id_generator_;
std::shared_ptr<GlobalDB> db_;
};
} // namespace sgns::crdt
OUTCOME_HPP_DECLARE_ERROR_2( sgns::crdt, GlobalDbNetworkComposition::Error );
#endif // SUPERGENIUS_CRDT_GLOBALDB_NETWORK_COMPOSITION_HPP
Updated on 2026-09-25 at 15:46:11 +0000