Hashes match now.

This commit is contained in:
Your Name 2025-04-29 23:07:33 +12:00
parent 38b3f33689
commit b770558c68
5 changed files with 3768 additions and 61 deletions

View File

@ -32,9 +32,6 @@ configure_file(
# Set CMAKE_MODULE_PATH to include our custom find modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Find required packages
find_package(TBB REQUIRED)
# Auto-detect source files
file(GLOB_RECURSE SOURCES "src/*.cpp")
file(GLOB_RECURSE HEADERS "src/*.hpp")
@ -50,7 +47,6 @@ target_include_directories(dropshell PRIVATE
# Link libraries
target_link_libraries(dropshell PRIVATE
TBB::tbb
)
# Install targets

View File

@ -1,38 +0,0 @@
# Find xxHash library
#
# This sets the following variables:
# xxHash_FOUND - True if xxHash was found
# xxHash_INCLUDE_DIRS - xxHash include directories
# xxHash_LIBRARIES - xxHash libraries
find_path(xxHash_INCLUDE_DIR
NAMES xxhash.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
${CMAKE_INSTALL_PREFIX}/include
PATH_SUFFIXES xxhash
)
find_library(xxHash_LIBRARY
NAMES xxhash libxxhash
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
${CMAKE_INSTALL_PREFIX}/lib
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(xxHash
FOUND_VAR xxHash_FOUND
REQUIRED_VARS xxHash_LIBRARY xxHash_INCLUDE_DIR
)
if(xxHash_FOUND)
set(xxHash_LIBRARIES ${xxHash_LIBRARY})
set(xxHash_INCLUDE_DIRS ${xxHash_INCLUDE_DIR})
endif()
mark_as_advanced(xxHash_INCLUDE_DIR xxHash_LIBRARY)

3744
src/contrib/transwarp.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -7,10 +7,11 @@
#include "services.hpp"
#include "config.hpp"
#include "templates.hpp"
#include "contrib/transwarp.hpp"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <execution>
#include <filesystem>
namespace dropshell {
@ -49,14 +50,15 @@ std::vector<ServerInfo> get_configured_servers() {
return servers;
}
// https://github.com/bloomen/transwarp?tab=readme-ov-file#range-functions
void list_servers() {
auto servers = get_configured_servers();
tableprint tp("All DropShell Servers");
tp.add_row({"Name", "Address", "Health", "Ports"});
std::for_each(std::execution::par, servers.begin(), servers.end(), [&](const ServerInfo& server) {
transwarp::parallel exec{servers.size()};
auto task = transwarp::for_each(exec, servers.begin(), servers.end(), [&](const ServerInfo& server) {
std::map<std::string, ServiceStatus> status = service_runner::get_all_services_status(server.name);
std::set<int> ports_used;
@ -71,6 +73,7 @@ void list_servers() {
tp.add_row({server.name, server.ssh_host, serviceticks, ports_used_str});
});
task->wait();
tp.print();
}

View File

@ -11,20 +11,21 @@ namespace dropshell {
uint64_t hash_file(const std::string &path) {
// Create hash state
XXH3_state_t* const state = XXH3_createState();
XXH64_state_t* const state = XXH64_createState();
if (state == nullptr) {
std::cerr << "Failed to create hash state" << std::endl;
return 0;
}
// Initialize state with seed 0
XXH3_64bits_reset(state);
XXH64_hash_t const seed = 0; /* or any other value */
if (XXH64_reset(state, seed) == XXH_ERROR) return 0;
// Open file
std::ifstream file(path, std::ios::binary);
if (!file.is_open()) {
std::cerr << "Failed to open file: " << path << std::endl;
XXH3_freeState(state);
XXH64_freeState(state);
return 0;
}
@ -32,40 +33,41 @@ uint64_t hash_file(const std::string &path) {
const size_t buffer_size = 4096;
char buffer[buffer_size];
while (file.read(buffer, buffer_size)) {
if (XXH3_64bits_update(state, buffer, file.gcount()) == XXH_ERROR) {
if (XXH64_update(state, buffer, file.gcount()) == XXH_ERROR) {
std::cerr << "Failed to update hash" << std::endl;
XXH3_freeState(state);
XXH64_freeState(state);
return 0;
}
}
// Handle any remaining bytes
if (file.gcount() > 0) {
if (XXH3_64bits_update(state, buffer, file.gcount()) == XXH_ERROR) {
if (XXH64_update(state, buffer, file.gcount()) == XXH_ERROR) {
std::cerr << "Failed to update hash" << std::endl;
XXH3_freeState(state);
XXH64_freeState(state);
return 0;
}
}
// Get final hash
XXH64_hash_t hash = XXH3_64bits_digest(state);
XXH3_freeState(state);
XXH64_hash_t hash = XXH64_digest(state);
XXH64_freeState(state);
return hash;
}
uint64_t hash_directory_recursive(const std::string &path) {
// Create hash state
XXH3_state_t* const state = XXH3_createState();
XXH64_state_t* const state = XXH64_createState();
if (state == nullptr) {
std::cerr << "Failed to create hash state" << std::endl;
return 0;
}
// Initialize state with seed 0
if (XXH3_64bits_reset(state) == XXH_ERROR) {
XXH64_hash_t const seed = 0; /* or any other value */
if (XXH64_reset(state, seed) == XXH_ERROR) {
std::cerr << "Failed to reset hash state" << std::endl;
XXH3_freeState(state);
XXH64_freeState(state);
return 0;
}
@ -75,18 +77,18 @@ uint64_t hash_directory_recursive(const std::string &path) {
if (entry.is_regular_file()) {
// Get file hash
XXH64_hash_t file_hash = hash_file(entry.path().string());
XXH3_64bits_update(state, &file_hash, sizeof(file_hash));
XXH64_update(state, &file_hash, sizeof(file_hash));
}
}
} catch (const std::filesystem::filesystem_error& e) {
std::cerr << "Filesystem error: " << e.what() << std::endl;
XXH3_freeState(state);
XXH64_freeState(state);
return 0;
}
// Get final hash
XXH64_hash_t hash = XXH3_64bits_digest(state);
XXH3_freeState(state);
XXH64_hash_t hash = XXH64_digest(state);
XXH64_freeState(state);
return hash;
}