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

Rewrite casync-http to use curl multi #208

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9af7c5f
Copy TAKE_PTR from systemd
elboulangero Apr 10, 2019
74e294a
casync-http: Rename ARG_PROTOCOL_* to PROTOCOL_*, add a typedef
elboulangero Jun 17, 2019
10c158c
casync-http: Add protocol helpers to factorize code
elboulangero Jun 17, 2019
d7b7bb2
casync-http: Use automatic pointer in acquire_file()
elboulangero Jun 25, 2019
ed01920
casync-http: Fix handling of ca_remote_has_unwritten() return value
elboulangero Jun 17, 2019
b88e115
casync-http: Dont forget to call PROCESS_UNTIL_WRITTEN
elboulangero Jun 17, 2019
669ab87
casync-http: Factorize curl handle work
elboulangero Jun 25, 2019
db25594
casync-http: Introduce macros to set curl options
elboulangero Jun 25, 2019
1a29cdc
casync-http: Use an automatic pointer for the chunks curl handle
elboulangero Jun 25, 2019
6057748
casync-http: Log curl error code in acquire_file()
elboulangero Jun 25, 2019
77652a8
casync-http: Use log_error_errno to report casync error code
elboulangero Jun 25, 2019
e6bfd49
casync-http: Move chunks download in a separate function for clarity
elboulangero Jun 17, 2019
7b5ab17
casync-http: use a constant for long option --rate-limit-bps
gportay Jun 13, 2019
bc85e26
casync-http: Add cmdline option to trust ssl peers
elboulangero Jun 17, 2019
e9901db
Revert "casync-http: retry when curl fails to connect"
gportay Jul 3, 2019
48f37dd
Import list.h from systemd
gportay Jun 21, 2019
c1c025c
casync-http: add support for cURL multi interface
elboulangero Jun 17, 2019
f1f6b11
casync: propagate --log-level option to helpers
gportay Jun 20, 2019
1d05b93
casync-http: set curl verbosity
gportay Jun 20, 2019
d07cfc0
casync-http: add max-active-chunks option
gportay Jul 3, 2019
3907d67
casync-http: add max-host-connections option
gportay Jul 3, 2019
edb7225
casync: propagate --trust-peer option to helpers
gportay Jul 3, 2019
d8748c9
casync-http: add some traces to debug
gportay Jul 3, 2019
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
3 changes: 3 additions & 0 deletions doc/casync.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ General options:
--cache=<PATH> Directory to use as encoder cache
--cache-auto, -c Pick encoder cache directory automatically
--rate-limit-bps=<LIMIT> Maximum bandwidth in bytes/s for remote communication
--max-active-chunks=<MAX> Maximum number of simultaneously active chunks for remote communication
--max-host-connections=<MAX> Maximum number of connections to a single host for remote communication
--ssl-trust-peer Trust the peer's SSL certificate
--exclude-nodump=no Don't exclude files with chattr(1)'s +d **nodump** flag when creating archive
--exclude-submounts=yes Exclude submounts when creating archive
--exclude-file=no Don't respect .caexclude files in the file tree
Expand Down
80 changes: 80 additions & 0 deletions src/caremote.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ struct CaRemote {
int input_fd;
int output_fd;

int log_level;
uint64_t rate_limit_bps;
unsigned max_active_chunks;
unsigned max_host_connections;
bool ssl_trust_peer;

ReallocBuffer input_buffer;
ReallocBuffer output_buffer;
Expand Down Expand Up @@ -112,6 +116,7 @@ CaRemote* ca_remote_new(void) {
rr->local_feature_flags = UINT64_MAX;
rr->remote_feature_flags = UINT64_MAX;

rr->log_level = -1;
rr->rate_limit_bps = UINT64_MAX;

rr->digest_type = _CA_DIGEST_TYPE_INVALID;
Expand Down Expand Up @@ -228,6 +233,15 @@ CaRemote* ca_remote_unref(CaRemote *rr) {
return mfree(rr);
}

int ca_remote_set_log_level(CaRemote *rr, int log_level) {
if (!rr)
return -EINVAL;

rr->log_level = log_level;

return 0;
}

int ca_remote_set_rate_limit_bps(CaRemote *rr, uint64_t rate_limit_bps) {
if (!rr)
return -EINVAL;
Expand All @@ -237,6 +251,33 @@ int ca_remote_set_rate_limit_bps(CaRemote *rr, uint64_t rate_limit_bps) {
return 0;
}

int ca_remote_set_max_active_chunks(CaRemote *rr, unsigned max_active_chunks) {
if (!rr)
return -EINVAL;

rr->max_active_chunks = max_active_chunks;

return 0;
}

int ca_remote_set_max_host_connections(CaRemote *rr, unsigned max_host_connections) {
if (!rr)
return -EINVAL;

rr->max_host_connections = max_host_connections;

return 0;
}

int ca_remote_set_ssl_trust_peer(CaRemote *rr, bool ssl_trust_peer) {
if (!rr)
return -EINVAL;

rr->ssl_trust_peer = ssl_trust_peer;

return 0;
}

int ca_remote_set_local_feature_flags(CaRemote *rr, uint64_t flags) {
if (!rr)
return -EINVAL;
Expand Down Expand Up @@ -984,9 +1025,21 @@ static int ca_remote_start(CaRemote *rr) {

argc = (rr->callout ? 1 : 3) + 5 + strv_length(rr->rstore_urls);

if (rr->log_level != -1)
argc++;

if (rr->rate_limit_bps != UINT64_MAX)
argc++;

if (rr->max_active_chunks)
argc++;

if (rr->max_host_connections)
argc++;

if (rr->ssl_trust_peer)
argc++;

args = newa(char*, argc + 1);

if (rr->callout) {
Expand Down Expand Up @@ -1016,6 +1069,14 @@ static int ca_remote_start(CaRemote *rr) {
args[i++] = (char*) remote_casync;
}

if (rr->log_level != -1) {
r = asprintf(args + i, "--log-level=%i", rr->log_level);
if (r < 0)
return log_oom();

i++;
}

if (rr->rate_limit_bps != UINT64_MAX) {
r = asprintf(args + i, "--rate-limit-bps=%" PRIu64, rr->rate_limit_bps);
if (r < 0)
Expand All @@ -1024,6 +1085,25 @@ static int ca_remote_start(CaRemote *rr) {
i++;
}

if (rr->max_active_chunks) {
r = asprintf(args + i, "--max-active-chunks=%u", rr->max_active_chunks);
if (r < 0)
return log_oom();

i++;
}

if (rr->max_host_connections) {
r = asprintf(args + i, "--max-host-connections=%u", rr->max_host_connections);
if (r < 0)
return log_oom();

i++;
}

if (rr->ssl_trust_peer)
args[i++] = (char*) "--ssl-trust-peer";

args[i + CA_REMOTE_ARG_OPERATION] = (char*) ((rr->local_feature_flags & (CA_PROTOCOL_PUSH_CHUNKS|CA_PROTOCOL_PUSH_INDEX|CA_PROTOCOL_PUSH_ARCHIVE)) ? "push" : "pull");
args[i + CA_REMOTE_ARG_BASE_URL] = /* rr->base_url ? rr->base_url + skip :*/ (char*) "-";
args[i + CA_REMOTE_ARG_ARCHIVE_URL] = rr->archive_url ? rr->archive_url + skip : (char*) "-";
Expand Down
4 changes: 4 additions & 0 deletions src/caremote.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ int ca_remote_get_remote_feature_flags(CaRemote *rr, uint64_t* flags);
int ca_remote_set_digest_type(CaRemote *rr, CaDigestType type);
int ca_remote_get_digest_type(CaRemote *rr, CaDigestType *ret);

int ca_remote_set_log_level(CaRemote *rr, int log_level);
int ca_remote_set_rate_limit_bps(CaRemote *rr, uint64_t rate_limit_bps);
int ca_remote_set_max_active_chunks(CaRemote *rr, unsigned max_active_chunks);
int ca_remote_set_max_host_connections(CaRemote *rr, unsigned max_max_connections);
int ca_remote_set_ssl_trust_peer(CaRemote *rr, bool ssl_trust_peer);

int ca_remote_set_io_fds(CaRemote *rr, int input_fd, int output_fd);
int ca_remote_get_io_fds(CaRemote *rr, int *ret_input_fd, int *ret_output_fd);
Expand Down
Loading