Sync against taskchampion-sync-server (#3118)
This removes use of gnutls and the TLS implementation, which is no longer needed (task synchronization is handled via Taskchampion, which uses `reqwest`, which handles TLS via other Rust dependencies). This incidentally removes the following config options: * `debug.tls` * `taskd.ca` * `taskd.certificate` * `taskd.ciphers` * `taskd.credentials` * `taskd.key` * `taskd.server` * `taskd.trust`
This commit is contained in:
committed by
GitHub
parent
771977aa69
commit
31105c2ba3
@@ -10,6 +10,7 @@ set (tc_SRCS
|
||||
ffi.h
|
||||
util.cpp util.h
|
||||
Replica.cpp Replica.h
|
||||
Server.cpp Server.h
|
||||
WorkingSet.cpp WorkingSet.h
|
||||
Task.cpp Task.h)
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <format.h>
|
||||
#include "tc/Replica.h"
|
||||
#include "tc/Task.h"
|
||||
#include "tc/Server.h"
|
||||
#include "tc/WorkingSet.h"
|
||||
#include "tc/util.h"
|
||||
|
||||
@@ -142,6 +143,16 @@ tc::Task tc::Replica::import_task_with_uuid (const std::string &uuid)
|
||||
return Task (tctask);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void tc::Replica::sync (Server server, bool avoid_snapshots)
|
||||
{
|
||||
// The server remains owned by this function, per tc_replica_sync docs.
|
||||
auto res = tc_replica_sync (&*inner, server.inner.get(), avoid_snapshots);
|
||||
if (res != TC_RESULT_OK) {
|
||||
throw replica_error ();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void tc::Replica::undo (int32_t *undone_out)
|
||||
{
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
namespace tc {
|
||||
class Task;
|
||||
class WorkingSet;
|
||||
class Server;
|
||||
|
||||
// a unique_ptr to a TCReplica which will automatically free the value when
|
||||
// it goes out of scope.
|
||||
@@ -91,7 +92,7 @@ namespace tc {
|
||||
tc::Task new_task (Status status, const std::string &description);
|
||||
tc::Task import_task_with_uuid (const std::string &uuid);
|
||||
// TODO: struct TCTask *tc_replica_import_task_with_uuid(struct TCReplica *rep, struct TCUuid tcuuid);
|
||||
// TODO: TCResult tc_replica_sync(struct TCReplica *rep, struct TCServer *server, bool avoid_snapshots);
|
||||
void sync(Server server, bool avoid_snapshots);
|
||||
void undo (int32_t *undone_out);
|
||||
int64_t num_local_operations ();
|
||||
int64_t num_undo_points ();
|
||||
|
||||
101
src/tc/Server.cpp
Normal file
101
src/tc/Server.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2022, Dustin J. Mitchell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// https://www.opensource.org/licenses/mit-license.php
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmake.h>
|
||||
#include <format.h>
|
||||
#include "tc/Server.h"
|
||||
#include "tc/util.h"
|
||||
|
||||
using namespace tc::ffi;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
tc::Server::Server (const std::string &server_dir)
|
||||
{
|
||||
TCString tc_server_dir = tc_string_borrow (server_dir.c_str ());
|
||||
TCString error;
|
||||
auto tcserver = tc_server_new_local (tc_server_dir, &error);
|
||||
if (!tcserver) {
|
||||
auto errmsg = format ("Could not configure local server at {1}: {2}",
|
||||
server_dir, tc_string_content (&error));
|
||||
tc_string_free (&error);
|
||||
throw errmsg;
|
||||
}
|
||||
inner = unique_tcserver_ptr (
|
||||
tcserver,
|
||||
[](TCServer* rep) { tc_server_free (rep); });
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
tc::Server::Server (const std::string &origin, const std::string &client_key, const std::string &encryption_secret)
|
||||
{
|
||||
TCString tc_origin = tc_string_borrow (origin.c_str ());
|
||||
|
||||
TCString tc_client_key_str = tc_string_borrow (client_key.c_str ());
|
||||
|
||||
TCString tc_encryption_secret = tc_string_borrow (encryption_secret.c_str ());
|
||||
|
||||
TCUuid tc_client_key;
|
||||
if (tc_uuid_from_str(tc_client_key_str, &tc_client_key) != TC_RESULT_OK) {
|
||||
tc_string_free(&tc_origin);
|
||||
tc_string_free(&tc_encryption_secret);
|
||||
throw "client_key must be a valid UUID";
|
||||
}
|
||||
|
||||
TCString error;
|
||||
auto tcserver = tc_server_new_remote (tc_origin, tc_client_key, tc_encryption_secret, &error);
|
||||
if (!tcserver) {
|
||||
auto errmsg = format ("Could not configure connection to server at {1}: {2}",
|
||||
origin, tc_string_content (&error));
|
||||
tc_string_free (&error);
|
||||
throw errmsg;
|
||||
}
|
||||
inner = unique_tcserver_ptr (
|
||||
tcserver,
|
||||
[](TCServer* rep) { tc_server_free (rep); });
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
tc::Server::Server (tc::Server &&other) noexcept
|
||||
{
|
||||
// move inner from other
|
||||
inner = unique_tcserver_ptr (
|
||||
other.inner.release (),
|
||||
[](TCServer* rep) { tc_server_free (rep); });
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
tc::Server& tc::Server::operator= (tc::Server &&other) noexcept
|
||||
{
|
||||
if (this != &other) {
|
||||
// move inner from other
|
||||
inner = unique_tcserver_ptr (
|
||||
other.inner.release (),
|
||||
[](TCServer* rep) { tc_server_free (rep); });
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
80
src/tc/Server.h
Normal file
80
src/tc/Server.h
Normal file
@@ -0,0 +1,80 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2022, Dustin J. Mitchell
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// https://www.opensource.org/licenses/mit-license.php
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDED_TC_SERVER
|
||||
#define INCLUDED_TC_SERVER
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include "tc/ffi.h"
|
||||
|
||||
namespace tc {
|
||||
// a unique_ptr to a TCServer which will automatically free the value when
|
||||
// it goes out of scope.
|
||||
using unique_tcserver_ptr = std::unique_ptr<
|
||||
tc::ffi::TCServer,
|
||||
std::function<void(tc::ffi::TCServer*)>>;
|
||||
|
||||
// Server wraps the TCServer type, managing its memory, errors, and so on.
|
||||
//
|
||||
// Except as noted, method names match the suffix to `tc_replica_..`.
|
||||
class Server
|
||||
{
|
||||
public:
|
||||
// Construct a null server
|
||||
Server () = default;
|
||||
|
||||
// Construct a local server (tc_server_new_local).
|
||||
Server (const std::string& server_dir);
|
||||
|
||||
// Construct a remote server (tc_server_new_remote).
|
||||
Server (const std::string &origin, const std::string &client_key, const std::string &encryption_secret);
|
||||
|
||||
// This object "owns" inner, so copy is not allowed.
|
||||
Server (const Server &) = delete;
|
||||
Server &operator=(const Server &) = delete;
|
||||
|
||||
// Explicit move constructor and assignment
|
||||
Server (Server &&) noexcept;
|
||||
Server &operator=(Server &&) noexcept;
|
||||
|
||||
protected:
|
||||
unique_tcserver_ptr inner;
|
||||
|
||||
// Replica accesses the inner pointer to call tc_replica_sync
|
||||
friend class Replica;
|
||||
|
||||
// construct an error message from the given string.
|
||||
std::string server_error (tc::ffi::TCString string);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
4
src/tc/rust/Cargo.lock
generated
4
src/tc/rust/Cargo.lock
generated
@@ -767,9 +767,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.3.4"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fa2982af2eec27de306107c027578ff7f423d65f7250e40ce0fea8f45248b81"
|
||||
checksum = "d023da39d1fde5a8a3fe1f3e01ca9632ada0a63e9797de55a879d6e2236277be"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"serde",
|
||||
|
||||
Reference in New Issue
Block a user