From d465b0a4be3a5903ef0d91be790e2eaae583dd4a Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 21 Jul 2019 15:10:06 +0200 Subject: [PATCH] Some changes --- server/src/Configuration.cpp | 13 ++++++++-- server/src/manager/ConversationManager.cpp | 28 ++++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/server/src/Configuration.cpp b/server/src/Configuration.cpp index d63c9dd..99e771f 100644 --- a/server/src/Configuration.cpp +++ b/server/src/Configuration.cpp @@ -325,7 +325,7 @@ void read_bindings(YAML::Node& root, const std::deque>& comments); std::deque> create_local_bindings(int& version, std::string& license); -#define CURRENT_CONFIG_VERSION 13 +#define CURRENT_CONFIG_VERSION 14 vector config::parseConfig(const std::string& path) { //FIXME test for premium! vector errors; @@ -406,7 +406,16 @@ vector config::parseConfig(const std::string& path) { nodes_key = YAML::Node(YAML::NodeType::Undefined); } - default: + case 13: + { + auto nodes_key = resolveNode(config, "binding.query.host").back(); + if(nodes_key.IsDefined() && nodes_key.as() == "0.0.0.0") + nodes_key = nodes_key.as() + ",[::]"; + auto node_ft = resolveNode(config, "binding.file.host").back(); + if(node_ft.IsDefined() && node_ft.as() == "0.0.0.0") + node_ft = node_ft.as() + ",[::]"; + } + default: break; } config["version"] = CURRENT_CONFIG_VERSION; diff --git a/server/src/manager/ConversationManager.cpp b/server/src/manager/ConversationManager.cpp index fe4f8b0..275bee0 100644 --- a/server/src/manager/ConversationManager.cpp +++ b/server/src/manager/ConversationManager.cpp @@ -297,6 +297,29 @@ bool Conversation::initialize(std::string& error) { }); LOG_SQL_CMD(result); + /* find duplicates and remove them */ + { + map> blocks; + for(auto& block : this->message_blocks) { + auto& entry = blocks[block->block_offset]; + if(entry) { + debugMessage(ref_server->getServerId(), "[Conversations][{}] Found duplicated block at index {}. Using newest block and dropping old one.", this->_channel_id, block->block_offset); + if(entry->begin_timestamp < block->begin_timestamp) { + entry->flag_invalid = true; + this->db_save_block(entry); + entry = block; + } else { + block->flag_invalid = true; + this->db_save_block(block); + } + } else + entry = block; + } + + /* lets remove the invalid blocks */ + this->message_blocks.erase(std::find_if(this->message_blocks.begin(), this->message_blocks.end(), [](const shared_ptr& block) { return block->flag_invalid; }), this->message_blocks.end()); + } + /* lets find the last block */ if(!this->message_blocks.empty()) { debugMessage(ref_server->getServerId(), "[Conversations][{}] Loaded {} blocks. Trying to find last block.", this->_channel_id, this->message_blocks.size()); @@ -518,8 +541,9 @@ bool Conversation::load_message_block_header(const std::shared_ptr(); - if(this->fread(&*block_header, sizeof(*block_header), block->block_offset, true) != sizeof(*block_header)) { - error = "failed to read block header"; + auto read = this->fread(&*block_header, sizeof(*block_header), block->block_offset, true); + if(read != sizeof(*block_header)) { + error = "failed to read block header (read " + to_string(read) + " out of " + to_string(sizeof(*block_header)) + ": " + to_string(errno) + ")"; return false; } if(block_header->version != 1) {