diff --git a/src/shared/config.h b/src/shared/config.h index e6a525d..213cb93 100644 --- a/src/shared/config.h +++ b/src/shared/config.h @@ -44,7 +44,7 @@ typedef struct Config { bool partial; } Config; -#define PROTOCOL_VERSION "1.3.0" +#define PROTOCOL_VERSION "2.0.0" #define DEFAULT_CHUNK_SIZE (10 * 1024 * 1024) Config* config_create(char* version, char* send_directory, char* receive_directory, diff --git a/src/shared/file.c b/src/shared/file.c index 5a412cd..8134a6c 100644 --- a/src/shared/file.c +++ b/src/shared/file.c @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/src/shared/metadata.c b/src/shared/metadata.c index b4de62e..4134c13 100644 --- a/src/shared/metadata.c +++ b/src/shared/metadata.c @@ -11,6 +11,19 @@ #include #include +/* + * Wire format serialization (protocol version 2.0.0+): + * All metadata fields are serialized as fixed-width integers (int32_t / int64_t) + * to ensure cross-platform binary compatiblity. See metadata.h for the + * exact wire layout. + * + * Compile-time assertions verify that the native platform types fit within + * the chosen fixed-width representations. + */ +typedef char static_assert_mode_t_fits[(sizeof(mode_t) <= sizeof(int32_t)) ? 1 : -1]; +typedef char static_assert_uid_t_fits[(sizeof(uid_t) <= sizeof(int32_t)) ? 1 : -1]; +typedef char static_assert_gid_t_fits[(sizeof(gid_t) <= sizeof(int32_t)) ? 1 : -1]; + void metadata_to_buf(char** buf, const FileMetadata* m) { int32_t present = (m != NULL) ? 1 : 0; memcpy(*buf, &present, sizeof(present)); diff --git a/src/shared/metadata.h b/src/shared/metadata.h index 518077b..f15570f 100644 --- a/src/shared/metadata.h +++ b/src/shared/metadata.h @@ -6,6 +6,20 @@ #include #include +/* + * Wire format (introduced in protocol version 2.0.0): + * int32_t present + * int32_t mode (was mode_t, platform-dependent) + * int32_t uid (was uid_t, platform-dependent) + * int32_t gid (was gid_t, platform-dependent) + * int64_t mtime_sec (was time_t, platform-dependent) + * int64_t mtime_nsec (was long, platform-dependent) + * + * Prior to 2.0.0 the wire format used the raw platform-dependent types, + * which broke compatiblity across different systems. All fields are now + * serialized as fixed-width integers. + */ + #define FILE_METADATA_WIRE_SIZE (sizeof(int32_t) * 3 + sizeof(int64_t) * 2) void metadata_to_buf(char** buf, const FileMetadata* m);