From bab8558511317d79495fac0aa8f43362c974402c Mon Sep 17 00:00:00 2001 From: Francesco Cozzuto Date: Sun, 9 Nov 2025 20:36:08 +0100 Subject: [PATCH] Progress --- src/chunk_server.c | 2 +- src/client.c | 18 ++++++++++-------- src/main_test.c | 2 +- src/message.c | 10 +++++----- src/metadata_server.c | 5 ++++- src/simulation_client.c | 2 -- src/system.c | 4 ++++ 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/chunk_server.c b/src/chunk_server.c index 2a880a0..8a8f248 100644 --- a/src/chunk_server.c +++ b/src/chunk_server.c @@ -644,7 +644,7 @@ process_client_create_chunk(ChunkServer *state, int conn_idx, ByteView msg) if (mem == NULL) return send_error(&state->tcp, conn_idx, false, MESSAGE_TYPE_CREATE_CHUNK_ERROR, S("Out of memory")); - assert(data.len <= chunk_size); + assert((uint32_t) data.len <= chunk_size); assert(target_off + data.len <= chunk_size); memset(mem, 0, chunk_size); diff --git a/src/client.c b/src/client.c index bd8f030..76f9d69 100644 --- a/src/client.c +++ b/src/client.c @@ -1211,11 +1211,11 @@ static void process_event_for_write(TinyDFS *tdfs, char *src = full_ptr + relative_off; - int off = 0; + uint32_t off = 0; if (i == 0) off = full_off % chunk_size; - int len = full_len - relative_off; + uint32_t len = full_len - relative_off; if (len > chunk_size - off) len = chunk_size - off; @@ -1355,15 +1355,15 @@ static void process_event_for_write(TinyDFS *tdfs, #endif int old_relative_off = relative_off; - for (int w = 0; w < num_new_hashes; w++) { + for (uint32_t w = 0; w < num_new_hashes; w++) { char *src = full_ptr + relative_off; - int off = 0; + uint32_t off = 0; if (num_hashes == 0 && w == 0) off = full_off % chunk_size; - int len = full_len - relative_off; + uint32_t len = full_len - relative_off; if (len > chunk_size - off) len = chunk_size - off; @@ -1422,13 +1422,13 @@ static void process_event_for_write(TinyDFS *tdfs, #endif int old_relative_off = relative_off; - for (int w = 0; w < num_new_hashes; w++) { + for (uint32_t w = 0; w < num_new_hashes; w++) { - int off = 0; + uint32_t off = 0; if (num_hashes == 0 && w == 0) off = full_off % chunk_size; - int len = full_len - relative_off; + uint32_t len = full_len - relative_off; if (len > chunk_size - off) len = chunk_size - off; @@ -1917,6 +1917,8 @@ int tinydfs_process_events(TinyDFS *tdfs, void **contexts, struct pollfd *polled void tinydfs_wait(TinyDFS *tdfs, int opidx, TinyDFS_Result *result, int timeout) { + // TODO: use the timeout parameter + void *contexts[MAX_CONNS+1]; struct pollfd polled[MAX_CONNS+1]; int num_polled; diff --git a/src/main_test.c b/src/main_test.c index a2d69bb..294a0e7 100644 --- a/src/main_test.c +++ b/src/main_test.c @@ -15,7 +15,7 @@ int main(int argc, char **argv) // TODO: set simulation_should_stop=true on ctrl+C - startup_simulation(3); + startup_simulation(2); // Spawn metadata server (leader) spawn_simulated_process("--addr 127.0.0.1 --port 8080 --leader"); diff --git a/src/message.c b/src/message.c index 87e934d..00cf4ce 100644 --- a/src/message.c +++ b/src/message.c @@ -155,7 +155,7 @@ void message_dump(FILE *stream, ByteView msg) } fprintf(stream, " path_len: %d\n", path_len); - char *path = reader.src + reader.cur; + char *path = (char*) reader.src + reader.cur; if (!binary_read(&reader, NULL, path_len)) { fprintf(stream, " (incomplete)\n"); return; @@ -189,7 +189,7 @@ void message_dump(FILE *stream, ByteView msg) } fprintf(stream, " path_len: %d\n", path_len); - char *path = reader.src + reader.cur; + char *path = (char*) reader.src + reader.cur; if (!binary_read(&reader, NULL, path_len)) { fprintf(stream, " (incomplete)\n"); return; @@ -207,7 +207,7 @@ void message_dump(FILE *stream, ByteView msg) } fprintf(stream, " path_len: %d\n", path_len); - char *path = reader.src + reader.cur; + char *path = (char*) reader.src + reader.cur; if (!binary_read(&reader, NULL, path_len)) { fprintf(stream, " (incomplete)\n"); return; @@ -225,7 +225,7 @@ void message_dump(FILE *stream, ByteView msg) } fprintf(stream, " path_len: %d\n", path_len); - char *path = reader.src + reader.cur; + char *path = (char*) reader.src + reader.cur; if (!binary_read(&reader, NULL, path_len)) { fprintf(stream, " (incomplete)\n"); return; @@ -257,7 +257,7 @@ void message_dump(FILE *stream, ByteView msg) } fprintf(stream, " path_len: %d\n", path_len); - char *path = reader.src + reader.cur; + char *path = (char*) reader.src + reader.cur; if (!binary_read(&reader, NULL, path_len)) { fprintf(stream, " (incomplete)\n"); return; diff --git a/src/metadata_server.c b/src/metadata_server.c index 3f69aa7..4496911 100644 --- a/src/metadata_server.c +++ b/src/metadata_server.c @@ -573,6 +573,9 @@ process_client_write(MetadataServer *state, int conn_idx, ByteView msg) ChunkWriteResult results[MAX_CHUNKS_PER_WRITE]; + if (num_chunks > MAX_CHUNKS_PER_WRITE) + return -1; // TODO + for (uint32_t i = 0; i < num_chunks; i++) { SHA256 old_hash; @@ -626,7 +629,7 @@ process_client_write(MetadataServer *state, int conn_idx, ByteView msg) SHA256 old_hashes[MAX_CHUNKS_PER_WRITE]; SHA256 new_hashes[MAX_CHUNKS_PER_WRITE]; - for (int i = 0; i < num_chunks; i++) { + for (uint32_t i = 0; i < num_chunks; i++) { old_hashes[i] = results[i].old_hash; new_hashes[i] = results[i].new_hash; } diff --git a/src/simulation_client.c b/src/simulation_client.c index 81d60fe..af729c8 100644 --- a/src/simulation_client.c +++ b/src/simulation_client.c @@ -55,8 +55,6 @@ static int random_in_range(int min, int max) int simulation_client_step(SimulationClient *client, void **contexts, struct pollfd *polled, int num_polled, int *timeout) { - TinyDFS_Result result; - // Process any pending events from the network and get new poll descriptors num_polled = tinydfs_process_events(client->tdfs, contexts, polled, num_polled); diff --git a/src/system.c b/src/system.c index a40ddf2..a278b16 100644 --- a/src/system.c +++ b/src/system.c @@ -982,6 +982,10 @@ int mock_getsockopt(SOCKET fd, int level, int optname, void *optval, socklen_t * int val; switch (desc->type) { + case DESC_EMPTY: + assert(0); + break; + case DESC_FILE: SET_SOCKET_ERROR(SOCKET_ERROR_NOTSOCK); return -1;