Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial revision of Database Server #11

Merged
merged 30 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
17 changes: 12 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Output binaries to bin/
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

# Include libuv.
add_subdirectory(libs/libuv)
Expand All @@ -24,11 +25,13 @@ include_directories(libs/yaml-cpp/include)
set(ARDOS_WANT_DB_SERVER ON CACHE BOOL "If on, Ardos will be built with the Database Server component.")
if (ARDOS_WANT_DB_SERVER)
# Include MongoDB driver.
find_package(libmongocxx REQUIRED)
find_package(libbsoncxx REQUIRED)
find_package(mongocxx CONFIG REQUIRED)
find_package(bsoncxx CONFIG REQUIRED)

include_directories(${LIBMONGOCXX_INCLUE_DIR})
include_directories(${LIBBSONCXX_INCLUDE_DIR})
include_directories(${LIBMONGOCXX_INCLUDE_DIRS})
include_directories(${LIBBSONCXX_INCLUDE_DIRS})

add_definitions(-DARDOS_WANT_DB_SERVER)
endif ()

# Include AMQP-CPP (RabbitMQ).
Expand Down Expand Up @@ -60,4 +63,8 @@ add_executable(ardos ${ARDOS_SOURCES} ${ARDOS_HEADERS})
add_subdirectory(libs/dclass)
include_directories(libs/dclass)

target_link_libraries(ardos PRIVATE uv yaml-cpp ${LIBMONGOCXX_LIBRARIES} ${LIBBSONCXX_LIBRARIES} amqpcpp prometheus-cpp::pull)
target_link_libraries(ardos PRIVATE uv yaml-cpp amqpcpp prometheus-cpp::pull)

if (ARDOS_WANT_DB_SERVER)
target_link_libraries(ardos PRIVATE mongo::mongocxx_shared mongo::bsoncxx_shared)
endif ()
10 changes: 10 additions & 0 deletions config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,13 @@ client-agent:
max: 1009999999

# Database configuration.
database-server:
channel: 4003

# MongoDB configuration.
mongodb-uri: mongodb://localhost:27017/ardos

# The range of DoId's this database server can allocate.
generate:
min: 100000000
max: 399999999
28 changes: 12 additions & 16 deletions src/clientagent/client_participant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,16 @@ ClientParticipant::ClientParticipant(
_clientAgent->ParticipantJoined();
}

/**
* Manually disconnect and delete this client participant.
*/
void ClientParticipant::Shutdown() {
ChannelSubscriber::Shutdown();
ClientParticipant::~ClientParticipant() {
NetworkClient::Shutdown();

_clientAgent->ParticipantLeft();

delete this;
}

void ClientParticipant::Annihilate() {
/**
* Manually disconnect and delete this client participant.
*/
void ClientParticipant::Shutdown() {
// Stop the heartbeat timer (if we have one.)
if (_heartbeatTimer) {
_heartbeatTimer->stop();
Expand Down Expand Up @@ -101,8 +98,6 @@ void ClientParticipant::Annihilate() {
for (auto it = _pendingInterests.begin(); it != _pendingInterests.end();) {
(it++)->second->Finish();
}

Shutdown();
}

/**
Expand All @@ -118,7 +113,7 @@ void ClientParticipant::HandleDisconnect(uv_errno_t code) {
address.ip, address.port, errorEvent.what()));
}

Annihilate();
Shutdown();
}

/**
Expand Down Expand Up @@ -635,9 +630,9 @@ void ClientParticipant::SendDisconnect(const uint16_t &reason,
dg->AddString(message);
SendDatagram(dg);

// This will call Annihilate from HandleDisconnect.
// This will call Shutdown from HandleDisconnect.
_cleanDisconnect = true;
NetworkClient::Shutdown();
Shutdown();
}

/**
Expand Down Expand Up @@ -989,15 +984,17 @@ void ClientParticipant::HandleClientAddInterest(DatagramIterator &dgi,
return;
}

Interest i;

#ifdef ARDOS_USE_LEGACY_CLIENT
uint16_t handleId = dgi.GetUint16();
uint32_t context = dgi.GetUint32();
BuildInterest(dgi, multiple, i, handleId);
#else
uint32_t context = dgi.GetUint32();
BuildInterest(dgi, multiple, i);
#endif

Interest i;
BuildInterest(dgi, multiple, i);
if (_clientAgent->GetInterestsPermission() == INTERESTS_VISIBLE &&
!LookupObject(i.parent)) {
SendDisconnect(CLIENT_DISCONNECT_FORBIDDEN_INTEREST,
Expand Down Expand Up @@ -1050,7 +1047,6 @@ void ClientParticipant::BuildInterest(DatagramIterator &dgi,
#else
uint16_t interestId = dgi.GetUint16();
#endif

uint32_t parent = dgi.GetUint32();

out.id = interestId;
Expand Down
2 changes: 1 addition & 1 deletion src/clientagent/client_participant.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class ClientParticipant : public NetworkClient, public ChannelSubscriber {
public:
ClientParticipant(ClientAgent *clientAgent,
const std::shared_ptr<uvw::tcp_handle> &socket);
~ClientParticipant();

friend class InterestOperation;

private:
void Shutdown() override;
void Annihilate();

void HandleDisconnect(uv_errno_t code) override;

Expand Down
11 changes: 0 additions & 11 deletions src/database/database.cpp

This file was deleted.

13 changes: 0 additions & 13 deletions src/database/database.h

This file was deleted.

Loading
Loading