diff options
| author | 2025-09-15 03:31:41 +0330 | |
|---|---|---|
| committer | 2025-09-15 03:31:41 +0330 | |
| commit | 53d387e60bbc69480737c84b6f09a9ca2b76aeea (patch) | |
| tree | eb75b700a8672037539c30cef254a4deedb6155f /src/server.c | |
| parent | logging (diff) | |
perf opt in set_data_packet
Diffstat (limited to 'src/server.c')
| -rw-r--r-- | src/server.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/server.c b/src/server.c index b3c5590..cc1f45d 100644 --- a/src/server.c +++ b/src/server.c @@ -637,6 +637,89 @@ void paste_server( return; } break; + case query_by_recipient: { + if (in_len < 1 + 32 + 32 + 64 + 2 + 8) { + log(_error, "query_by_recipient: input too short, got %zu bytes", in_len); + byte resp = error; + *out = malloc(1); + if (*out) { + (*out)[ 0 ] = resp; + *out_len = 1; + } else { + *out_len = 0; + } + break; + } + public_key author; + public_key signing_pub; + signature sig; + uint16_t count; + uint64_t offset; + size_t off = 1; + memcpy(author, in + off, 32); + off += 32; + memcpy(signing_pub, in + off, 32); + off += 32; + memcpy(sig, in + off, 64); + off += 64; + count = read_u16_le(in + off); + off += 2; + offset = read_u64_le(in + off); + + byte msg[ 32 + 32 + 2 + 8 ]; + memcpy(msg, author, 32); + memcpy(msg + 32, signing_pub, 32); + write_u16_le(msg + 64, count); + write_u64_le(msg + 66, offset); + + if (crypto_sign_verify_detached(sig, msg, sizeof(msg), signing_pub) != 0) { + log(_error, "query_by_recipient: signature verification failed for author"); + byte resp = error; + *out = malloc(1); + if (*out) { + (*out)[ 0 ] = resp; + *out_len = 1; + } else { + *out_len = 0; + } + break; + } + + log(_info, + "query_by_recipient: fetching %u packets for recipient, offset %lu", + count, + offset); + struct data_packet packets[ 256 ]; + uint64_t new_offset; + uint16_t collected + = get_packets_for_recipient(author, offset, count, packets, &new_offset); + + *out_len = 1 + 2 + 8 + collected * PACKET_SIZE; + *out = malloc(*out_len); + if (!*out) { + log(_error, + "query_by_recipient: failed to allocate %zu bytes for response", + *out_len); + *out_len = 0; + break; + } + off = 0; + (*out)[ off++ ] = queried_recipient_packets; + write_u16_le(*out + off, collected); + off += 2; + write_u64_le(*out + off, new_offset); + off += 8; + for (uint16_t i = 0; i < collected; i++) { + data_packet2s(packets[ i ], *out + off); + off += PACKET_SIZE; + } + log(_info, + "query_by_recipient: returned %u packets, new offset %lu", + collected, + new_offset); + break; + } + default: { log(_info, "<%.*s> request type: invalid method", (int) ip_size, ip_addr); |
