diff --git a/api/Dockerfile b/api/Dockerfile index 64cb004..5e74c77 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -15,4 +15,10 @@ COPY --from=builder /app/build/api/asio-grpc-server /app/asio-grpc-server # Run CMD ["/app/asio-grpc-server"] -EXPOSE 50051 \ No newline at end of file +EXPOSE 50051 + +# Metadata +LABEL project="eternity2" +LABEL description="Eternity II Asio gRPC server" +LABEL version="1.0" +LABEL repository="https://github.com/Apoorva64/eternity2" \ No newline at end of file diff --git a/api/main.cpp b/api/main.cpp index f95b36a..ccfb70b 100644 --- a/api/main.cpp +++ b/api/main.cpp @@ -32,7 +32,6 @@ #include #include #include -// Example showing some of the features of using asio-grpc with libunifex. template void run_grpc_context_for_sender(agrpc::GrpcContext &grpc_context, Sender &&sender) diff --git a/api/solver/solvera.cpp b/api/solver/solvera.cpp index bb22a1a..d9eb40c 100644 --- a/api/solver/solvera.cpp +++ b/api/solver/solvera.cpp @@ -181,21 +181,19 @@ auto handle_server_solver_request_step_by_step(agrpc::GrpcContext &grpc_context, while (!shared_data.stop) { co_await delay(std::chrono::milliseconds{request.wait_time()}); - mutex.lock(); + std::scoped_lock lock(mutex); for (auto &res : responses) { if (!co_await rpc.write(res)) { spdlog::info("Client cancelled request"); shared_data.stop = true; - mutex.unlock(); solver_thread.join(); co_await rpc.finish(grpc::Status::CANCELLED); co_return; } } responses.clear(); - mutex.unlock(); } co_await rpc.finish(grpc::Status::OK); }); diff --git a/solver/CMakeLists.txt b/solver/CMakeLists.txt index bceeadf..0b49991 100644 --- a/solver/CMakeLists.txt +++ b/solver/CMakeLists.txt @@ -49,7 +49,9 @@ add_library(solver_lib STATIC format/format.cpp format/format.h solver/solver.h - solver/solver.cpp board/scan_row.cpp board/scan_row.h board/spiral.cpp board/spiral.h) + solver/solver.cpp board/scan_row.cpp board/scan_row.h board/spiral.cpp board/spiral.h + hash_load_store/hash_store_load.cpp + hash_load_store/hash_store_load.h) target_include_directories(solver_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/solver/hash_load_store/hash_store_load.cpp b/solver/hash_load_store/hash_store_load.cpp new file mode 100644 index 0000000..05a2520 --- /dev/null +++ b/solver/hash_load_store/hash_store_load.cpp @@ -0,0 +1,26 @@ +// +// Created by appad on 03/03/2024. +// + +#include "hash_store_load.h" +void store_hash(std::unordered_set &hashes, const std::string &filename) +{ + std::ofstream file; + file.open(filename); + for (const auto &hash : hashes) + { + file << hash << '\n'; + } + file.close(); +} +void load_hash(std::unordered_set &hashes, const std::string &filename) +{ + std::ifstream file; + file.open(filename); + std::string line; + while (std::getline(file, line)) + { + hashes.insert(line); + } + file.close(); +} diff --git a/solver/hash_load_store/hash_store_load.h b/solver/hash_load_store/hash_store_load.h new file mode 100644 index 0000000..c7d87e6 --- /dev/null +++ b/solver/hash_load_store/hash_store_load.h @@ -0,0 +1,18 @@ +// +// Created by appad on 03/03/2024. +// + +#ifndef ETERNITY2_HASH_STORE_LOAD_H +#define ETERNITY2_HASH_STORE_LOAD_H + +#include "board/board.h" + +#include +#include +#include +#include + +void store_hash(std::unordered_set &hashes, const std::string &filename); + +void load_hash(std::unordered_set &hashes, const std::string &filename); +#endif //ETERNITY2_HASH_STORE_LOAD_H diff --git a/solver/solver/solver.h b/solver/solver/solver.h index b0b2446..ad8306a 100644 --- a/solver/solver/solver.h +++ b/solver/solver/solver.h @@ -17,8 +17,6 @@ struct SharedData unsigned int hash_length_threshold = 7; }; -SharedData create_shared_data(); - auto possible_pieces(const Board &board, const std::vector &pieces, Index index) -> std::vector;