Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0021ca3fcd |
+54
-65
@@ -105,27 +105,71 @@ static int read_patterns_from_file(const char* filepath, char*** patterns, int*
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool validate_config(Config* config) {
|
||||||
|
if (!config->send_directory || !config->receive_root_directory) {
|
||||||
|
fprintf(stderr, "Error: source and destination directories are required\n");
|
||||||
|
print_usage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (config->use_sendfile && (config->use_chunk_serialization || config->use_compression)) {
|
||||||
|
fprintf(stderr, "Error: -f/--sendfile cannot be combined with -c (compression) or -s "
|
||||||
|
"(chunk serialization)\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (config->transport == TRANSPORT_SSH && config->use_sendfile) {
|
||||||
|
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (config->use_incremental && config->use_chunk_serialization) {
|
||||||
|
fprintf(stderr, "Error: --incremental is not supported with -s (chunk serialization)\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (config->use_incremental && !config->use_metadata) {
|
||||||
|
log_message(LOG_LEVEL_INFO, "Enabling metadata preservation for --incremental");
|
||||||
|
config->use_metadata = true;
|
||||||
|
}
|
||||||
|
if (config->use_delta && !config->use_incremental) {
|
||||||
|
fprintf(stderr, "Error: --delta requires --incremental\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (config->use_delta && config->use_chunk_serialization) {
|
||||||
|
fprintf(stderr, "Error: --delta cannot be combined with -s (chunk serialization)\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (config->use_delta && config->use_sendfile) {
|
||||||
|
fprintf(stderr, "Error: --delta cannot be combined with -f (sendfile)\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (config->use_delta && !config->use_metadata) {
|
||||||
|
log_message(LOG_LEVEL_INFO, "Enabling metadata preservation for --delta");
|
||||||
|
config->use_metadata = true;
|
||||||
|
}
|
||||||
|
if (config->use_tls) {
|
||||||
|
if (!config->tls_cert || !config->tls_key) {
|
||||||
|
fprintf(stderr, "Error: --tls requires --cert and --key\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
tls_global_init();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
const char* env_source = getenv("FASTSYNC_SOURCE_DIR");
|
const char* env_source = getenv("FASTSYNC_SOURCE_DIR");
|
||||||
const char* env_dest = getenv("FASTSYNC_DEST_DIR");
|
const char* env_dest = getenv("FASTSYNC_DEST_DIR");
|
||||||
const char* env_save = getenv("FASTSYNC_SAVE_TO_DISK");
|
const char* env_save = getenv("FASTSYNC_SAVE_TO_DISK");
|
||||||
|
|
||||||
bool save_to_disk = false;
|
|
||||||
if (env_save && (strcmp(env_save, "true") == 0 || strcmp(env_save, "1") == 0)) {
|
|
||||||
save_to_disk = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
Config* config = NULL;
|
Config* config = NULL;
|
||||||
bool config_owned_by_pipeline = false;
|
bool config_owned_by_pipeline = false;
|
||||||
|
|
||||||
char* config_version = str_dup(PROTOCOL_VERSION);
|
config = config_create();
|
||||||
if (!config_version) {
|
if (!config) {
|
||||||
exit_code = 1;
|
exit_code = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
config = config_create(config_version, NULL, NULL, save_to_disk, false, false, false, false, 5,
|
if (env_save && (strcmp(env_save, "true") == 0 || strcmp(env_save, "1") == 0))
|
||||||
false, 0);
|
config->save_to_disk = true;
|
||||||
|
|
||||||
int positional_args[2];
|
int positional_args[2];
|
||||||
int positional_count = 0;
|
int positional_count = 0;
|
||||||
@@ -341,7 +385,6 @@ int main(int argc, char* argv[]) {
|
|||||||
config->send_directory = str_dup(argv[positional_args[0]]);
|
config->send_directory = str_dup(argv[positional_args[0]]);
|
||||||
config->receive_root_directory = str_dup(argv[positional_args[1]]);
|
config->receive_root_directory = str_dup(argv[positional_args[1]]);
|
||||||
config->save_to_disk = true;
|
config->save_to_disk = true;
|
||||||
|
|
||||||
config_parse_ssh_dest(config);
|
config_parse_ssh_dest(config);
|
||||||
} else if (positional_count == 1) {
|
} else if (positional_count == 1) {
|
||||||
fprintf(stderr, "Error: missing destination argument\n");
|
fprintf(stderr, "Error: missing destination argument\n");
|
||||||
@@ -355,64 +398,10 @@ int main(int argc, char* argv[]) {
|
|||||||
config->receive_root_directory = str_dup((char*)env_dest);
|
config->receive_root_directory = str_dup((char*)env_dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config->send_directory || !config->receive_root_directory) {
|
if (!validate_config(config)) {
|
||||||
fprintf(stderr, "Error: source and destination directories are required\n");
|
|
||||||
print_usage();
|
|
||||||
exit_code = 1;
|
exit_code = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (config->use_sendfile && (config->use_chunk_serialization || config->use_compression)) {
|
|
||||||
fprintf(stderr, "Error: -f/--sendfile cannot be combined with -c (compression) or -s (chunk "
|
|
||||||
"serialization)\n");
|
|
||||||
exit_code = 1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->transport == TRANSPORT_SSH && config->use_sendfile) {
|
|
||||||
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
|
|
||||||
exit_code = 1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->use_incremental && config->use_chunk_serialization) {
|
|
||||||
fprintf(stderr, "Error: --incremental is not supported with -s (chunk serialization)\n");
|
|
||||||
exit_code = 1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->use_incremental && !config->use_metadata) {
|
|
||||||
log_message(LOG_LEVEL_INFO, "Enabling metadata preservation for --incremental");
|
|
||||||
config->use_metadata = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->use_delta && !config->use_incremental) {
|
|
||||||
fprintf(stderr, "Error: --delta requires --incremental\n");
|
|
||||||
exit_code = 1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (config->use_delta && config->use_chunk_serialization) {
|
|
||||||
fprintf(stderr, "Error: --delta cannot be combined with -s (chunk serialization)\n");
|
|
||||||
exit_code = 1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (config->use_delta && config->use_sendfile) {
|
|
||||||
fprintf(stderr, "Error: --delta cannot be combined with -f (sendfile)\n");
|
|
||||||
exit_code = 1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (config->use_delta && !config->use_metadata) {
|
|
||||||
log_message(LOG_LEVEL_INFO, "Enabling metadata preservation for --delta");
|
|
||||||
config->use_metadata = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->use_tls) {
|
|
||||||
if (!config->tls_cert || !config->tls_key) {
|
|
||||||
fprintf(stderr, "Error: --tls requires --cert and --key\n");
|
|
||||||
exit_code = 1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
tls_global_init();
|
|
||||||
}
|
|
||||||
|
|
||||||
tcp_set_timeouts(config->timeout, config->contimeout);
|
tcp_set_timeouts(config->timeout, config->contimeout);
|
||||||
|
|
||||||
|
|||||||
+77
-86
@@ -364,62 +364,86 @@ static int load_files_multithreaded(void* pipeline_context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int send_files(Config* config) {
|
static int run_dry_run(Config* config) {
|
||||||
if (config->dry_run) {
|
DirectoryScanner* scanner = directory_scanner_create(
|
||||||
DirectoryScanner* scanner = directory_scanner_create(
|
config->send_directory, config->use_metadata, config->chunk_size, config->exclude_patterns,
|
||||||
config->send_directory, config->use_metadata, config->chunk_size, config->exclude_patterns,
|
config->exclude_count, config->include_patterns, config->include_count, config->max_size,
|
||||||
config->exclude_count, config->include_patterns, config->include_count, config->max_size,
|
config->min_size, config->max_depth);
|
||||||
config->min_size, config->max_depth);
|
if (!scanner)
|
||||||
Chunk* chunk;
|
return -1;
|
||||||
int file_count = 0;
|
Chunk* chunk;
|
||||||
unsigned long long total_bytes = 0;
|
int file_count = 0;
|
||||||
printf("Dry run: files to be transferred\n");
|
unsigned long long total_bytes = 0;
|
||||||
while ((chunk = directory_scanner_next(scanner)) != NULL) {
|
printf("Dry run: files to be transferred\n");
|
||||||
for (int i = 0; i < chunk->element_count; i++) {
|
while ((chunk = directory_scanner_next(scanner)) != NULL) {
|
||||||
printf(" %s (%zu bytes)\n", chunk->items[i]->path, chunk->items[i]->data->size);
|
for (int i = 0; i < chunk->element_count; i++) {
|
||||||
total_bytes += chunk->items[i]->data->size;
|
printf(" %s (%zu bytes)\n", chunk->items[i]->path, chunk->items[i]->data->size);
|
||||||
file_count++;
|
total_bytes += chunk->items[i]->data->size;
|
||||||
}
|
file_count++;
|
||||||
chunk_destroy(chunk);
|
|
||||||
}
|
}
|
||||||
directory_scanner_destroy(scanner);
|
chunk_destroy(chunk);
|
||||||
printf("Total: %d files, %.1f MB\n", file_count, total_bytes / 1048576.0);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
directory_scanner_destroy(scanner);
|
||||||
|
printf("Total: %d files, %.1f MB\n", file_count, total_bytes / 1048576.0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Client* client;
|
static Client* connect_to_server(Config* config) {
|
||||||
if (config->transport == TRANSPORT_SSH) {
|
if (config->transport == TRANSPORT_SSH) {
|
||||||
if (config->use_sendfile) {
|
if (config->use_sendfile) {
|
||||||
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
|
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
|
||||||
return 1;
|
return NULL;
|
||||||
}
|
|
||||||
client =
|
|
||||||
client_connect_ssh(config->ssh_destination, config->ssh_port, config->fastsync_server_path);
|
|
||||||
if (!client)
|
|
||||||
return 1;
|
|
||||||
} else if (config->use_tls) {
|
|
||||||
client = client_create();
|
|
||||||
if (!client || !client_connect_tls(client, config->server_host, config->server_port,
|
|
||||||
config->tls_cert, config->tls_key, config->tls_ca)) {
|
|
||||||
if (client)
|
|
||||||
client_delete(client);
|
|
||||||
fprintf(stderr, "Error: could not connect to server via TLS\n");
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
return client_connect_ssh(config->ssh_destination, config->ssh_port,
|
||||||
|
config->fastsync_server_path);
|
||||||
|
}
|
||||||
|
Client* client = client_create();
|
||||||
|
if (!client)
|
||||||
|
return NULL;
|
||||||
|
bool ok;
|
||||||
|
if (config->use_tls) {
|
||||||
|
ok = client_connect_tls(client, config->server_host, config->server_port, config->tls_cert,
|
||||||
|
config->tls_key, config->tls_ca);
|
||||||
} else {
|
} else {
|
||||||
client = client_create();
|
ok = client_connect(client, config->server_host, config->server_port);
|
||||||
if (!client || !client_connect(client, config->server_host, config->server_port)) {
|
|
||||||
if (client)
|
|
||||||
client_delete(client);
|
|
||||||
fprintf(stderr, "Error: could not connect to server\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!config_send(client->file_descriptor, config)) {
|
if (!ok) {
|
||||||
client_disconnect(client);
|
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
return 1;
|
fprintf(stderr, "Error: could not connect to server\n");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool send_manifest(int fd, ArrayList* manifest) {
|
||||||
|
if (!send_status(fd, STATUS_MANIFEST))
|
||||||
|
return false;
|
||||||
|
if (!send_int(fd, manifest->size))
|
||||||
|
return false;
|
||||||
|
for (int i = 0; i < manifest->size; i++) {
|
||||||
|
if (!send_str(fd, (char*)manifest->items[i]))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_progress(unsigned long long total_bytes, time_t start) {
|
||||||
|
double elapsed = difftime(time(NULL), start);
|
||||||
|
double rate = elapsed > 0 ? total_bytes / (1048576.0 * elapsed) : 0;
|
||||||
|
fprintf(stderr, "\rSent %.1f MB (%.1f MB/s) ", total_bytes / 1048576.0, rate);
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
int send_files(Config* config) {
|
||||||
|
if (config->dry_run)
|
||||||
|
return run_dry_run(config);
|
||||||
|
|
||||||
|
Client* client = connect_to_server(config);
|
||||||
|
if (!client)
|
||||||
|
return 1;
|
||||||
|
if (!config_send(client->file_descriptor, config))
|
||||||
|
goto send_fail;
|
||||||
|
|
||||||
DirectoryScanner* scanner = directory_scanner_create(
|
DirectoryScanner* scanner = directory_scanner_create(
|
||||||
config->send_directory, config->use_metadata, config->chunk_size, config->exclude_patterns,
|
config->send_directory, config->use_metadata, config->chunk_size, config->exclude_patterns,
|
||||||
config->exclude_count, config->include_patterns, config->include_count, config->max_size,
|
config->exclude_count, config->include_patterns, config->include_count, config->max_size,
|
||||||
@@ -461,40 +485,26 @@ int send_files(Config* config) {
|
|||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
if (now - last_progress >= 1) {
|
if (now - last_progress >= 1) {
|
||||||
last_progress = now;
|
last_progress = now;
|
||||||
double elapsed = difftime(now, start);
|
print_progress(total_bytes, start);
|
||||||
double rate = elapsed > 0 ? total_bytes / (1048576.0 * elapsed) : 0;
|
|
||||||
fprintf(stderr, "\rSent %.1f MB (%.1f MB/s) ", total_bytes / 1048576.0, rate);
|
|
||||||
fflush(stderr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chunk_destroy(current_chunk);
|
chunk_destroy(current_chunk);
|
||||||
}
|
}
|
||||||
if (config->use_delete) {
|
if (config->use_delete) {
|
||||||
if (!send_status(client->file_descriptor, STATUS_MANIFEST)) {
|
if (!send_manifest(client->file_descriptor, manifest)) {
|
||||||
array_list_delete(manifest);
|
array_list_delete(manifest);
|
||||||
goto send_fail;
|
goto send_fail;
|
||||||
}
|
}
|
||||||
if (!send_int(client->file_descriptor, manifest->size)) {
|
|
||||||
array_list_delete(manifest);
|
|
||||||
goto send_fail;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < manifest->size; i++) {
|
|
||||||
if (!send_str(client->file_descriptor, (char*)manifest->items[i])) {
|
|
||||||
array_list_delete(manifest);
|
|
||||||
goto send_fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
array_list_delete(manifest);
|
array_list_delete(manifest);
|
||||||
}
|
}
|
||||||
if (!send_status(client->file_descriptor, STATUS_FINISHED))
|
if (!send_status(client->file_descriptor, STATUS_FINISHED))
|
||||||
goto send_fail;
|
goto send_fail;
|
||||||
Status s;
|
Status s;
|
||||||
int ok = receive_status(client->file_descriptor, &s) && s == STATUS_OK;
|
int ok = receive_status(client->file_descriptor, &s) && s == STATUS_OK;
|
||||||
if (config->show_progress) {
|
if (config->show_progress)
|
||||||
double elapsed = difftime(time(NULL), start);
|
print_progress(total_bytes, start);
|
||||||
double rate = elapsed > 0 ? total_bytes / (1048576.0 * elapsed) : 0;
|
if (config->show_progress)
|
||||||
fprintf(stderr, "\rSent %.1f MB (%.1f MB/s) Done.\n", total_bytes / 1048576.0, rate);
|
fprintf(stderr, "Done.\n");
|
||||||
}
|
|
||||||
directory_scanner_destroy(scanner);
|
directory_scanner_destroy(scanner);
|
||||||
client_disconnect(client);
|
client_disconnect(client);
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
@@ -508,27 +518,8 @@ send_fail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int send_files_multithreaded(Config* config) {
|
int send_files_multithreaded(Config* config) {
|
||||||
if (config->dry_run) {
|
if (config->dry_run)
|
||||||
DirectoryScanner* scanner = directory_scanner_create(
|
return run_dry_run(config);
|
||||||
config->send_directory, config->use_metadata, config->chunk_size, config->exclude_patterns,
|
|
||||||
config->exclude_count, config->include_patterns, config->include_count, config->max_size,
|
|
||||||
config->min_size, config->max_depth);
|
|
||||||
Chunk* chunk;
|
|
||||||
int file_count = 0;
|
|
||||||
unsigned long long total_bytes = 0;
|
|
||||||
printf("Dry run: files to be transferred\n");
|
|
||||||
while ((chunk = directory_scanner_next(scanner)) != NULL) {
|
|
||||||
for (int i = 0; i < chunk->element_count; i++) {
|
|
||||||
printf(" %s (%zu bytes)\n", chunk->items[i]->path, chunk->items[i]->data->size);
|
|
||||||
total_bytes += chunk->items[i]->data->size;
|
|
||||||
file_count++;
|
|
||||||
}
|
|
||||||
chunk_destroy(chunk);
|
|
||||||
}
|
|
||||||
directory_scanner_destroy(scanner);
|
|
||||||
printf("Total: %d files, %.1f MB\n", file_count, total_bytes / 1048576.0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
long pages = sysconf(_SC_AVPHYS_PAGES);
|
long pages = sysconf(_SC_AVPHYS_PAGES);
|
||||||
long page_size = sysconf(_SC_PAGE_SIZE);
|
long page_size = sysconf(_SC_PAGE_SIZE);
|
||||||
|
|||||||
+8
-44
@@ -8,57 +8,21 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
Config* config_create(char* version, char* send_directory, char* receive_directory,
|
Config* config_create(void) {
|
||||||
bool save_to_disk, bool use_multithreading, bool use_chunk_serialization,
|
Config* config = calloc(1, sizeof(Config));
|
||||||
bool use_compression, bool use_metadata, int compression_level,
|
|
||||||
bool use_sendfile, unsigned long long chunk_size) {
|
|
||||||
|
|
||||||
Config* config = malloc(sizeof(Config));
|
|
||||||
if (!config)
|
if (!config)
|
||||||
return NULL;
|
return NULL;
|
||||||
config->version = version;
|
config->version = str_dup(PROTOCOL_VERSION);
|
||||||
config->send_directory = send_directory;
|
config->compression_level = 5;
|
||||||
config->receive_root_directory = receive_directory;
|
config->chunk_size = DEFAULT_CHUNK_SIZE;
|
||||||
config->save_to_disk = save_to_disk;
|
|
||||||
config->use_multithreading = use_multithreading;
|
|
||||||
config->use_chunk_serialization = use_chunk_serialization;
|
|
||||||
config->use_compression = use_compression;
|
|
||||||
config->use_metadata = use_metadata;
|
|
||||||
config->show_progress = false;
|
|
||||||
config->dry_run = false;
|
|
||||||
config->use_delete = false;
|
|
||||||
config->compression_level = compression_level;
|
|
||||||
config->use_sendfile = use_sendfile;
|
|
||||||
config->chunk_size = chunk_size > 0 ? chunk_size : DEFAULT_CHUNK_SIZE;
|
|
||||||
config->ssh_port = 22;
|
config->ssh_port = 22;
|
||||||
config->transport = TRANSPORT_TCP;
|
|
||||||
config->ssh_destination = NULL;
|
|
||||||
config->fastsync_server_path = NULL;
|
|
||||||
config->exclude_patterns = NULL;
|
|
||||||
config->exclude_count = 0;
|
|
||||||
config->include_patterns = NULL;
|
|
||||||
config->include_count = 0;
|
|
||||||
config->max_size = 0;
|
|
||||||
config->min_size = 0;
|
|
||||||
config->use_incremental = false;
|
|
||||||
config->use_delta = false;
|
|
||||||
config->delta_block_size = DELTA_BLOCK_SIZE_DEFAULT;
|
|
||||||
config->delta_max_file_size = DELTA_MAX_FILE_SIZE;
|
|
||||||
config->use_tls = false;
|
|
||||||
config->tls_cert = NULL;
|
|
||||||
config->tls_key = NULL;
|
|
||||||
config->tls_ca = NULL;
|
|
||||||
config->server_host = str_dup("127.0.0.1");
|
|
||||||
config->server_port = 8080;
|
config->server_port = 8080;
|
||||||
|
config->server_host = str_dup("127.0.0.1");
|
||||||
config->timeout = 30;
|
config->timeout = 30;
|
||||||
config->contimeout = 10;
|
config->contimeout = 10;
|
||||||
config->quiet = false;
|
|
||||||
config->backup = false;
|
|
||||||
config->backup_dir = NULL;
|
|
||||||
config->stats = false;
|
|
||||||
config->max_depth = 0;
|
|
||||||
config->log_file = NULL;
|
|
||||||
config->queue_size = 100;
|
config->queue_size = 100;
|
||||||
|
config->delta_block_size = DELTA_BLOCK_SIZE_DEFAULT;
|
||||||
|
config->delta_max_file_size = DELTA_MAX_FILE_SIZE;
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-4
@@ -58,10 +58,7 @@ typedef struct Config {
|
|||||||
#define PROTOCOL_VERSION "1.3.0"
|
#define PROTOCOL_VERSION "1.3.0"
|
||||||
#define DEFAULT_CHUNK_SIZE (10 * 1024 * 1024)
|
#define DEFAULT_CHUNK_SIZE (10 * 1024 * 1024)
|
||||||
|
|
||||||
Config* config_create(char* version, char* send_directory, char* receive_directory,
|
Config* config_create(void);
|
||||||
bool save_to_disk, bool use_multithreading, bool use_chunk_serialization,
|
|
||||||
bool use_compression, bool use_metadata, int compression_level,
|
|
||||||
bool use_sendfile, unsigned long long chunk_size);
|
|
||||||
void config_delete(Config* config);
|
void config_delete(Config* config);
|
||||||
bool config_send(int file_descriptor, const Config* config);
|
bool config_send(int file_descriptor, const Config* config);
|
||||||
Config* config_receive(int file_descriptor);
|
Config* config_receive(int file_descriptor);
|
||||||
|
|||||||
+51
-12
@@ -7,9 +7,17 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static void test_config_lifecycle() {
|
static void test_config_lifecycle() {
|
||||||
Config* cfg = config_create(str_dup("1.0"), str_dup("/src"), str_dup("/dst"), true, true, false,
|
Config* cfg = config_create();
|
||||||
false, false, 1, false, 0);
|
|
||||||
EXPECT_NOT_NULL(cfg);
|
EXPECT_NOT_NULL(cfg);
|
||||||
|
free(cfg->version);
|
||||||
|
cfg->version = str_dup("1.0");
|
||||||
|
cfg->send_directory = str_dup("/src");
|
||||||
|
cfg->receive_root_directory = str_dup("/dst");
|
||||||
|
cfg->save_to_disk = true;
|
||||||
|
cfg->use_multithreading = true;
|
||||||
|
cfg->use_chunk_serialization = false;
|
||||||
|
cfg->use_compression = false;
|
||||||
|
cfg->compression_level = 1;
|
||||||
EXPECT_EQ_STR(cfg->version, "1.0");
|
EXPECT_EQ_STR(cfg->version, "1.0");
|
||||||
EXPECT_EQ_STR(cfg->send_directory, "/src");
|
EXPECT_EQ_STR(cfg->send_directory, "/src");
|
||||||
EXPECT_EQ_STR(cfg->receive_root_directory, "/dst");
|
EXPECT_EQ_STR(cfg->receive_root_directory, "/dst");
|
||||||
@@ -23,9 +31,14 @@ static void test_config_lifecycle() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_config_ssh_dest() {
|
static void test_config_ssh_dest() {
|
||||||
Config* cfg = config_create(str_dup("1.0"), str_dup("/src"), str_dup("user@host:/dst"), true,
|
Config* cfg = config_create();
|
||||||
false, false, false, false, 1, false, 0);
|
|
||||||
EXPECT_NOT_NULL(cfg);
|
EXPECT_NOT_NULL(cfg);
|
||||||
|
free(cfg->version);
|
||||||
|
cfg->version = str_dup("1.0");
|
||||||
|
cfg->send_directory = str_dup("/src");
|
||||||
|
cfg->receive_root_directory = str_dup("user@host:/dst");
|
||||||
|
cfg->save_to_disk = true;
|
||||||
|
cfg->compression_level = 1;
|
||||||
EXPECT_EQ_INT(cfg->transport, TRANSPORT_TCP);
|
EXPECT_EQ_INT(cfg->transport, TRANSPORT_TCP);
|
||||||
EXPECT_NULL(cfg->ssh_destination);
|
EXPECT_NULL(cfg->ssh_destination);
|
||||||
EXPECT_EQ_STR(cfg->receive_root_directory, "user@host:/dst");
|
EXPECT_EQ_STR(cfg->receive_root_directory, "user@host:/dst");
|
||||||
@@ -38,8 +51,14 @@ static void test_config_ssh_dest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_config_ssh_dest_local_path() {
|
static void test_config_ssh_dest_local_path() {
|
||||||
Config* cfg = config_create(str_dup("1.0"), str_dup("/src"), str_dup("/local/path"), true, false,
|
Config* cfg = config_create();
|
||||||
false, false, false, 1, false, 0);
|
EXPECT_NOT_NULL(cfg);
|
||||||
|
free(cfg->version);
|
||||||
|
cfg->version = str_dup("1.0");
|
||||||
|
cfg->send_directory = str_dup("/src");
|
||||||
|
cfg->receive_root_directory = str_dup("/local/path");
|
||||||
|
cfg->save_to_disk = true;
|
||||||
|
cfg->compression_level = 1;
|
||||||
config_parse_ssh_dest(cfg);
|
config_parse_ssh_dest(cfg);
|
||||||
EXPECT_EQ_INT(cfg->transport, TRANSPORT_TCP);
|
EXPECT_EQ_INT(cfg->transport, TRANSPORT_TCP);
|
||||||
EXPECT_NULL(cfg->ssh_destination);
|
EXPECT_NULL(cfg->ssh_destination);
|
||||||
@@ -48,8 +67,14 @@ static void test_config_ssh_dest_local_path() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_config_ssh_dest_no_user() {
|
static void test_config_ssh_dest_no_user() {
|
||||||
Config* cfg = config_create(str_dup("1.0"), str_dup("/src"), str_dup("host:/remote"), true, false,
|
Config* cfg = config_create();
|
||||||
false, false, false, 1, false, 0);
|
EXPECT_NOT_NULL(cfg);
|
||||||
|
free(cfg->version);
|
||||||
|
cfg->version = str_dup("1.0");
|
||||||
|
cfg->send_directory = str_dup("/src");
|
||||||
|
cfg->receive_root_directory = str_dup("host:/remote");
|
||||||
|
cfg->save_to_disk = true;
|
||||||
|
cfg->compression_level = 1;
|
||||||
config_parse_ssh_dest(cfg);
|
config_parse_ssh_dest(cfg);
|
||||||
EXPECT_EQ_INT(cfg->transport, TRANSPORT_SSH);
|
EXPECT_EQ_INT(cfg->transport, TRANSPORT_SSH);
|
||||||
EXPECT_EQ_STR(cfg->ssh_destination, "host:/remote");
|
EXPECT_EQ_STR(cfg->ssh_destination, "host:/remote");
|
||||||
@@ -58,8 +83,14 @@ static void test_config_ssh_dest_no_user() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_pipeline_sender_lifecycle() {
|
static void test_pipeline_sender_lifecycle() {
|
||||||
Config* cfg = config_create(str_dup("2.0"), str_dup("/src2"), str_dup("/dst2"), false, false,
|
Config* cfg = config_create();
|
||||||
true, true, false, 1, false, 0);
|
free(cfg->version);
|
||||||
|
cfg->version = str_dup("2.0");
|
||||||
|
cfg->send_directory = str_dup("/src2");
|
||||||
|
cfg->receive_root_directory = str_dup("/dst2");
|
||||||
|
cfg->use_chunk_serialization = true;
|
||||||
|
cfg->use_compression = true;
|
||||||
|
cfg->compression_level = 1;
|
||||||
Queue* q1 = queue_create(5, NULL);
|
Queue* q1 = queue_create(5, NULL);
|
||||||
Queue* q2 = queue_create(15, NULL);
|
Queue* q2 = queue_create(15, NULL);
|
||||||
|
|
||||||
@@ -75,8 +106,16 @@ static void test_pipeline_sender_lifecycle() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_pipeline_receiver_lifecycle() {
|
static void test_pipeline_receiver_lifecycle() {
|
||||||
Config* cfg = config_create(str_dup("3.0"), str_dup("/src3"), str_dup("/dst3"), true, true, true,
|
Config* cfg = config_create();
|
||||||
true, false, 1, false, 0);
|
free(cfg->version);
|
||||||
|
cfg->version = str_dup("3.0");
|
||||||
|
cfg->send_directory = str_dup("/src3");
|
||||||
|
cfg->receive_root_directory = str_dup("/dst3");
|
||||||
|
cfg->save_to_disk = true;
|
||||||
|
cfg->use_multithreading = true;
|
||||||
|
cfg->use_chunk_serialization = true;
|
||||||
|
cfg->use_compression = true;
|
||||||
|
cfg->compression_level = 1;
|
||||||
Queue* q = queue_create(20, NULL);
|
Queue* q = queue_create(20, NULL);
|
||||||
|
|
||||||
PipelineContextReceiver* pcr = pipeline_context_receiver_create(cfg, q, 42);
|
PipelineContextReceiver* pcr = pipeline_context_receiver_create(cfg, q, 42);
|
||||||
|
|||||||
+3
-2
@@ -154,8 +154,9 @@ static void test_file_send_receive() {
|
|||||||
memcpy(file->data->data, content, len);
|
memcpy(file->data->data, content, len);
|
||||||
file->data->size = len;
|
file->data->size = len;
|
||||||
|
|
||||||
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), false,
|
Config* cfg = config_create();
|
||||||
false, false, false, false, 0, false, 0);
|
cfg->send_directory = str_dup("/tmp");
|
||||||
|
cfg->receive_root_directory = str_dup("/tmp");
|
||||||
|
|
||||||
int p[2];
|
int p[2];
|
||||||
EXPECT_EQ_INT(pipe(p), 0);
|
EXPECT_EQ_INT(pipe(p), 0);
|
||||||
|
|||||||
@@ -22,9 +22,10 @@ static void test_sendfile_basic() {
|
|||||||
/* Set the size so file_send_sendfile can report it */
|
/* Set the size so file_send_sendfile can report it */
|
||||||
file->data->size = len;
|
file->data->size = len;
|
||||||
|
|
||||||
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), false,
|
Config* cfg = config_create();
|
||||||
false, false, false, false, 0, false, 0);
|
|
||||||
EXPECT_NOT_NULL(cfg);
|
EXPECT_NOT_NULL(cfg);
|
||||||
|
cfg->send_directory = str_dup("/tmp");
|
||||||
|
cfg->receive_root_directory = str_dup("/tmp");
|
||||||
|
|
||||||
int p[2];
|
int p[2];
|
||||||
EXPECT_EQ_INT(pipe(p), 0);
|
EXPECT_EQ_INT(pipe(p), 0);
|
||||||
@@ -80,9 +81,10 @@ static void test_sendfile_empty_file() {
|
|||||||
EXPECT_NOT_NULL(file);
|
EXPECT_NOT_NULL(file);
|
||||||
file->data->size = 0;
|
file->data->size = 0;
|
||||||
|
|
||||||
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), false,
|
Config* cfg = config_create();
|
||||||
false, false, false, false, 0, false, 0);
|
|
||||||
EXPECT_NOT_NULL(cfg);
|
EXPECT_NOT_NULL(cfg);
|
||||||
|
cfg->send_directory = str_dup("/tmp");
|
||||||
|
cfg->receive_root_directory = str_dup("/tmp");
|
||||||
|
|
||||||
int p[2];
|
int p[2];
|
||||||
EXPECT_EQ_INT(pipe(p), 0);
|
EXPECT_EQ_INT(pipe(p), 0);
|
||||||
@@ -91,6 +93,7 @@ static void test_sendfile_empty_file() {
|
|||||||
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
|
/* Child: receive */
|
||||||
close(p[1]);
|
close(p[1]);
|
||||||
File* received = file_receive(cfg, p[0]);
|
File* received = file_receive(cfg, p[0]);
|
||||||
close(p[0]);
|
close(p[0]);
|
||||||
@@ -161,9 +164,12 @@ static void test_sendfile_compression_fallback() {
|
|||||||
file->data->size = (size_t)st.st_size;
|
file->data->size = (size_t)st.st_size;
|
||||||
EXPECT_TRUE(file_load_data(file));
|
EXPECT_TRUE(file_load_data(file));
|
||||||
|
|
||||||
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), false,
|
Config* cfg = config_create();
|
||||||
false, false, true, false, 3, false, 0);
|
|
||||||
EXPECT_NOT_NULL(cfg);
|
EXPECT_NOT_NULL(cfg);
|
||||||
|
cfg->send_directory = str_dup("/tmp");
|
||||||
|
cfg->receive_root_directory = str_dup("/tmp");
|
||||||
|
cfg->use_compression = true;
|
||||||
|
cfg->compression_level = 3;
|
||||||
|
|
||||||
int p[2];
|
int p[2];
|
||||||
EXPECT_EQ_INT(pipe(p), 0);
|
EXPECT_EQ_INT(pipe(p), 0);
|
||||||
@@ -172,6 +178,7 @@ static void test_sendfile_compression_fallback() {
|
|||||||
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
|
/* Child: receive */
|
||||||
close(p[1]);
|
close(p[1]);
|
||||||
File* received = file_receive(cfg, p[0]);
|
File* received = file_receive(cfg, p[0]);
|
||||||
close(p[0]);
|
close(p[0]);
|
||||||
|
|||||||
@@ -8,9 +8,12 @@
|
|||||||
|
|
||||||
/* Test pipeline_context_sender_create/destroy with valid arguments */
|
/* Test pipeline_context_sender_create/destroy with valid arguments */
|
||||||
static void test_sender_create_destroy() {
|
static void test_sender_create_destroy() {
|
||||||
Config* cfg = config_create(str_dup("1.0"), str_dup("/src"), str_dup("/dst"), false, false, false,
|
Config* cfg = config_create();
|
||||||
false, false, 0, false, 0);
|
|
||||||
EXPECT_NOT_NULL(cfg);
|
EXPECT_NOT_NULL(cfg);
|
||||||
|
free(cfg->version);
|
||||||
|
cfg->version = str_dup("1.0");
|
||||||
|
cfg->send_directory = str_dup("/src");
|
||||||
|
cfg->receive_root_directory = str_dup("/dst");
|
||||||
|
|
||||||
Queue* q_scanner = queue_create(5, NULL);
|
Queue* q_scanner = queue_create(5, NULL);
|
||||||
EXPECT_NOT_NULL(q_scanner);
|
EXPECT_NOT_NULL(q_scanner);
|
||||||
@@ -32,9 +35,14 @@ static void test_sender_create_destroy() {
|
|||||||
|
|
||||||
/* Test pipeline_context_receiver_create/destroy with valid arguments */
|
/* Test pipeline_context_receiver_create/destroy with valid arguments */
|
||||||
static void test_receiver_create_destroy() {
|
static void test_receiver_create_destroy() {
|
||||||
Config* cfg = config_create(str_dup("2.0"), str_dup("/src"), str_dup("/dst"), true, true, false,
|
Config* cfg = config_create();
|
||||||
false, false, 0, false, 0);
|
|
||||||
EXPECT_NOT_NULL(cfg);
|
EXPECT_NOT_NULL(cfg);
|
||||||
|
free(cfg->version);
|
||||||
|
cfg->version = str_dup("2.0");
|
||||||
|
cfg->send_directory = str_dup("/src");
|
||||||
|
cfg->receive_root_directory = str_dup("/dst");
|
||||||
|
cfg->save_to_disk = true;
|
||||||
|
cfg->use_multithreading = true;
|
||||||
|
|
||||||
Queue* q = queue_create(20, NULL);
|
Queue* q = queue_create(20, NULL);
|
||||||
EXPECT_NOT_NULL(q);
|
EXPECT_NOT_NULL(q);
|
||||||
@@ -51,9 +59,12 @@ static void test_receiver_create_destroy() {
|
|||||||
|
|
||||||
/* Test that create handles various queue capacities */
|
/* Test that create handles various queue capacities */
|
||||||
static void test_sender_queue_capacities() {
|
static void test_sender_queue_capacities() {
|
||||||
Config* cfg = config_create(str_dup("3.0"), str_dup("/src"), str_dup("/dst"), false, false, false,
|
Config* cfg = config_create();
|
||||||
false, false, 0, false, 0);
|
|
||||||
EXPECT_NOT_NULL(cfg);
|
EXPECT_NOT_NULL(cfg);
|
||||||
|
free(cfg->version);
|
||||||
|
cfg->version = str_dup("3.0");
|
||||||
|
cfg->send_directory = str_dup("/src");
|
||||||
|
cfg->receive_root_directory = str_dup("/dst");
|
||||||
|
|
||||||
/* Single-element queues */
|
/* Single-element queues */
|
||||||
Queue* q1 = queue_create(1, NULL);
|
Queue* q1 = queue_create(1, NULL);
|
||||||
@@ -67,9 +78,12 @@ static void test_sender_queue_capacities() {
|
|||||||
|
|
||||||
/* Test that create handles zero-capacity queues */
|
/* Test that create handles zero-capacity queues */
|
||||||
static void test_sender_zero_capacity() {
|
static void test_sender_zero_capacity() {
|
||||||
Config* cfg = config_create(str_dup("4.0"), str_dup("/src"), str_dup("/dst"), false, false, false,
|
Config* cfg = config_create();
|
||||||
false, false, 0, false, 0);
|
|
||||||
EXPECT_NOT_NULL(cfg);
|
EXPECT_NOT_NULL(cfg);
|
||||||
|
free(cfg->version);
|
||||||
|
cfg->version = str_dup("4.0");
|
||||||
|
cfg->send_directory = str_dup("/src");
|
||||||
|
cfg->receive_root_directory = str_dup("/dst");
|
||||||
|
|
||||||
Queue* q1 = queue_create(0, NULL);
|
Queue* q1 = queue_create(0, NULL);
|
||||||
Queue* q2 = queue_create(0, NULL);
|
Queue* q2 = queue_create(0, NULL);
|
||||||
@@ -82,8 +96,11 @@ static void test_sender_zero_capacity() {
|
|||||||
|
|
||||||
/* Test receiver with zero file_descriptor */
|
/* Test receiver with zero file_descriptor */
|
||||||
static void test_receiver_fd_zero() {
|
static void test_receiver_fd_zero() {
|
||||||
Config* cfg = config_create(str_dup("5.0"), str_dup("/src"), str_dup("/dst"), false, false, false,
|
Config* cfg = config_create();
|
||||||
false, false, 0, false, 0);
|
free(cfg->version);
|
||||||
|
cfg->version = str_dup("5.0");
|
||||||
|
cfg->send_directory = str_dup("/src");
|
||||||
|
cfg->receive_root_directory = str_dup("/dst");
|
||||||
Queue* q = queue_create(5, NULL);
|
Queue* q = queue_create(5, NULL);
|
||||||
PipelineContextReceiver* ctx = pipeline_context_receiver_create(cfg, q, 0);
|
PipelineContextReceiver* ctx = pipeline_context_receiver_create(cfg, q, 0);
|
||||||
EXPECT_NOT_NULL(ctx);
|
EXPECT_NOT_NULL(ctx);
|
||||||
|
|||||||
Reference in New Issue
Block a user