summaryrefslogtreecommitdiff
path: root/src/packet_storage.c
diff options
context:
space:
mode:
authorGravatar moon <moon@coffin.ir> 2025-09-16 11:45:09 +0330
committerGravatar moon <moon@coffin.ir> 2025-09-16 11:45:09 +0330
commit96bda3794a6a96021dce0f29c4860b4276954784 (patch)
tree7dc2b2b60d7ee3e5c789e6098220cc5a69163fa6 /src/packet_storage.c
parentcompressino + fixed logic (diff)
fix duplicate + better propagation
Diffstat (limited to 'src/packet_storage.c')
-rw-r--r--src/packet_storage.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/packet_storage.c b/src/packet_storage.c
index 5781661..922cc45 100644
--- a/src/packet_storage.c
+++ b/src/packet_storage.c
@@ -141,17 +141,31 @@ void save_author_packet_hash(const public_key author, const hash packet_hash) {
const char *dir = "packets_by_author";
mkdir(dir, 0755);
- char author_hex[ 65 ];
+ char author_hex[65];
sprintf(author_hex, hash_fmt, hash_ref(author));
- char filename[ 256 ];
+ char filename[256];
snprintf(filename, sizeof(filename), "%s/%s.list", dir, author_hex);
- FILE *f = fopen(filename, "ab");
- if (!f) return;
- fwrite(packet_hash, 32, 1, f);
- fputc('\n', f);
- fclose(f);
+ FILE *f = fopen(filename, "rb");
+ if (f) {
+ unsigned char buf[64];
+ while (fread(buf, 1, 64, f) >= 32) {
+ int c = fgetc(f);
+ (void)c;
+ if (memcmp(buf, packet_hash, 32) == 0) {
+ fclose(f);
+ return;
+ }
+ }
+ fclose(f);
+ }
+
+ FILE *fa = fopen(filename, "ab");
+ if (!fa) return;
+ fwrite(packet_hash, 32, 1, fa);
+ fputc('\n', fa);
+ fclose(fa);
}
void save_recipient_packet_hash(const recipient recipient, const hash packet_hash) {