diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2024-01-19 22:57:32 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2024-01-19 22:57:32 +0100 |
commit | 63cf392a58f9e18e659df727a4fa052d38f62bf5 (patch) | |
tree | aaabcbb147e7d32a0806cbc781f23ed1d5895d24 | |
parent | f239edd23faf14a23ad36e9770b364eed544a463 (diff) | |
download | gnunet-63cf392a58f9e18e659df727a4fa052d38f62bf5.tar.gz gnunet-63cf392a58f9e18e659df727a4fa052d38f62bf5.zip |
MESSENGER: Add transcript and tag message kinds
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/include/gnunet_messenger_service.h | 60 | ||||
-rw-r--r-- | src/service/messenger/messenger_api.c | 12 | ||||
-rw-r--r-- | src/service/messenger/messenger_api_message.c | 93 |
3 files changed, 152 insertions, 13 deletions
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h index 5457e8ddb..497a430c2 100644 --- a/src/include/gnunet_messenger_service.h +++ b/src/include/gnunet_messenger_service.h | |||
@@ -208,6 +208,16 @@ enum GNUNET_MESSENGER_MessageKind | |||
208 | GNUNET_MESSENGER_KIND_TICKET = 17, | 208 | GNUNET_MESSENGER_KIND_TICKET = 17, |
209 | 209 | ||
210 | /** | 210 | /** |
211 | * The transcript kind. The message contains a #GNUNET_MESSENGER_MessageTranscript body. | ||
212 | */ | ||
213 | GNUNET_MESSENGER_KIND_TRANSCRIPT = 18, | ||
214 | |||
215 | /** | ||
216 | * The tag kind. The message contains a #GNUNET_MESSENGER_MessageTag body. | ||
217 | */ | ||
218 | GNUNET_MESSENGER_KIND_TAG = 19, | ||
219 | |||
220 | /** | ||
211 | * The unknown kind. The message contains an unknown body. | 221 | * The unknown kind. The message contains an unknown body. |
212 | */ | 222 | */ |
213 | GNUNET_MESSENGER_KIND_UNKNOWN = 0 | 223 | GNUNET_MESSENGER_KIND_UNKNOWN = 0 |
@@ -537,6 +547,54 @@ struct GNUNET_MESSENGER_MessageTicket | |||
537 | }; | 547 | }; |
538 | 548 | ||
539 | /** | 549 | /** |
550 | * A transcript message body | ||
551 | * This allows reading the content of a sent private message. | ||
552 | * | ||
553 | * Message-body-size: 68+ | ||
554 | */ | ||
555 | struct GNUNET_MESSENGER_MessageTranscript | ||
556 | { | ||
557 | /** | ||
558 | * The hash of the original message. | ||
559 | */ | ||
560 | struct GNUNET_HashCode hash; | ||
561 | |||
562 | /** | ||
563 | * The key from the recipient of the original message. | ||
564 | */ | ||
565 | struct GNUNET_CRYPTO_PublicKey key; | ||
566 | |||
567 | /** | ||
568 | * The length of the transcribed message. | ||
569 | */ | ||
570 | uint16_t length; | ||
571 | |||
572 | /** | ||
573 | * The data of the transcribed message. | ||
574 | */ | ||
575 | char *data; | ||
576 | }; | ||
577 | |||
578 | /** | ||
579 | * A tag message body | ||
580 | * This allows tagging a message with a custom tag. | ||
581 | * | ||
582 | * Message-body-size: 32+ | ||
583 | */ | ||
584 | struct GNUNET_MESSENGER_MessageTag | ||
585 | { | ||
586 | /** | ||
587 | * The hash of the message to tag. | ||
588 | */ | ||
589 | struct GNUNET_HashCode hash; | ||
590 | |||
591 | /** | ||
592 | * The custom tag. | ||
593 | */ | ||
594 | char *tag; | ||
595 | }; | ||
596 | |||
597 | /** | ||
540 | * The unified body of a #GNUNET_MESSENGER_Message. | 598 | * The unified body of a #GNUNET_MESSENGER_Message. |
541 | */ | 599 | */ |
542 | struct GNUNET_MESSENGER_MessageBody | 600 | struct GNUNET_MESSENGER_MessageBody |
@@ -560,6 +618,8 @@ struct GNUNET_MESSENGER_MessageBody | |||
560 | struct GNUNET_MESSENGER_MessageDelete deletion; | 618 | struct GNUNET_MESSENGER_MessageDelete deletion; |
561 | struct GNUNET_MESSENGER_MessageConnection connection; | 619 | struct GNUNET_MESSENGER_MessageConnection connection; |
562 | struct GNUNET_MESSENGER_MessageTicket ticket; | 620 | struct GNUNET_MESSENGER_MessageTicket ticket; |
621 | struct GNUNET_MESSENGER_MessageTranscript transcript; | ||
622 | struct GNUNET_MESSENGER_MessageTag tag; | ||
563 | }; | 623 | }; |
564 | }; | 624 | }; |
565 | 625 | ||
diff --git a/src/service/messenger/messenger_api.c b/src/service/messenger/messenger_api.c index 7fd873211..9f31ebb00 100644 --- a/src/service/messenger/messenger_api.c +++ b/src/service/messenger/messenger_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020--2023 GNUnet e.V. | 3 | Copyright (C) 2020--2024 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -24,7 +24,7 @@ | |||
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include "gnunet_common.h" | 26 | #include "gnunet_common.h" |
27 | #include "gnunet_identity_service.h" | 27 | #include "gnunet_core_service.h" |
28 | #include "gnunet_messenger_service.h" | 28 | #include "gnunet_messenger_service.h" |
29 | 29 | ||
30 | #include "gnunet-service-messenger.h" | 30 | #include "gnunet-service-messenger.h" |
@@ -72,6 +72,14 @@ GNUNET_MESSENGER_name_of_kind (enum GNUNET_MESSENGER_MessageKind kind) | |||
72 | return "PRIVATE"; | 72 | return "PRIVATE"; |
73 | case GNUNET_MESSENGER_KIND_DELETE: | 73 | case GNUNET_MESSENGER_KIND_DELETE: |
74 | return "DELETE"; | 74 | return "DELETE"; |
75 | case GNUNET_MESSENGER_KIND_CONNECTION: | ||
76 | return "CONNECTION"; | ||
77 | case GNUNET_MESSENGER_KIND_TICKET: | ||
78 | return "TICKET"; | ||
79 | case GNUNET_MESSENGER_KIND_TRANSCRIPT: | ||
80 | return "TRANSCRIPT"; | ||
81 | case GNUNET_MESSENGER_KIND_TAG: | ||
82 | return "TAG"; | ||
75 | default: | 83 | default: |
76 | return "UNKNOWN"; | 84 | return "UNKNOWN"; |
77 | } | 85 | } |
diff --git a/src/service/messenger/messenger_api_message.c b/src/service/messenger/messenger_api_message.c index bfab00c02..c7762d925 100644 --- a/src/service/messenger/messenger_api_message.c +++ b/src/service/messenger/messenger_api_message.c | |||
@@ -63,6 +63,13 @@ create_message (enum GNUNET_MESSENGER_MessageKind kind) | |||
63 | message->body.privacy.length = 0; | 63 | message->body.privacy.length = 0; |
64 | message->body.privacy.data = NULL; | 64 | message->body.privacy.data = NULL; |
65 | break; | 65 | break; |
66 | case GNUNET_MESSENGER_KIND_TRANSCRIPT: | ||
67 | message->body.transcript.length = 0; | ||
68 | message->body.transcript.data = NULL; | ||
69 | break; | ||
70 | case GNUNET_MESSENGER_KIND_TAG: | ||
71 | message->body.tag.tag = NULL; | ||
72 | break; | ||
66 | default: | 73 | default: |
67 | break; | 74 | break; |
68 | } | 75 | } |
@@ -97,12 +104,22 @@ copy_message (const struct GNUNET_MESSENGER_Message *message) | |||
97 | copy->body.privacy.length) : NULL; | 104 | copy->body.privacy.length) : NULL; |
98 | 105 | ||
99 | if (copy->body.privacy.data) | 106 | if (copy->body.privacy.data) |
100 | { | ||
101 | GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data, | 107 | GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data, |
102 | copy->body.privacy.length); | 108 | copy->body.privacy.length); |
103 | } | ||
104 | 109 | ||
105 | break; | 110 | break; |
111 | case GNUNET_MESSENGER_KIND_TRANSCRIPT: | ||
112 | copy->body.transcript.data = copy->body.transcript.length ? GNUNET_malloc ( | ||
113 | copy->body.transcript.length) : NULL; | ||
114 | |||
115 | if (copy->body.transcript.data) | ||
116 | GNUNET_memcpy (copy->body.transcript.data, message->body.transcript.data, | ||
117 | copy->body.transcript.length); | ||
118 | |||
119 | break; | ||
120 | case GNUNET_MESSENGER_KIND_TAG: | ||
121 | copy->body.tag.tag = GNUNET_strdup (message->body.tag.tag); | ||
122 | break; | ||
106 | default: | 123 | default: |
107 | break; | 124 | break; |
108 | } | 125 | } |
@@ -118,10 +135,12 @@ destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, | |||
118 | switch (kind) | 135 | switch (kind) |
119 | { | 136 | { |
120 | case GNUNET_MESSENGER_KIND_NAME: | 137 | case GNUNET_MESSENGER_KIND_NAME: |
121 | GNUNET_free (body->name.name); | 138 | if (body->name.name) |
139 | GNUNET_free (body->name.name); | ||
122 | break; | 140 | break; |
123 | case GNUNET_MESSENGER_KIND_TEXT: | 141 | case GNUNET_MESSENGER_KIND_TEXT: |
124 | GNUNET_free (body->text.text); | 142 | if (body->text.text) |
143 | GNUNET_free (body->text.text); | ||
125 | break; | 144 | break; |
126 | case GNUNET_MESSENGER_KIND_FILE: | 145 | case GNUNET_MESSENGER_KIND_FILE: |
127 | GNUNET_free (body->file.uri); | 146 | GNUNET_free (body->file.uri); |
@@ -129,6 +148,13 @@ destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, | |||
129 | case GNUNET_MESSENGER_KIND_PRIVATE: | 148 | case GNUNET_MESSENGER_KIND_PRIVATE: |
130 | GNUNET_free (body->privacy.data); | 149 | GNUNET_free (body->privacy.data); |
131 | break; | 150 | break; |
151 | case GNUNET_MESSENGER_KIND_TRANSCRIPT: | ||
152 | GNUNET_free (body->transcript.data); | ||
153 | break; | ||
154 | case GNUNET_MESSENGER_KIND_TAG: | ||
155 | if (body->tag.tag) | ||
156 | GNUNET_free (body->tag.tag); | ||
157 | break; | ||
132 | default: | 158 | default: |
133 | break; | 159 | break; |
134 | } | 160 | } |
@@ -228,8 +254,6 @@ get_message_body_kind_size (enum GNUNET_MESSENGER_MessageKind kind) | |||
228 | length += member_size (struct GNUNET_MESSENGER_Message, body.invite.door); | 254 | length += member_size (struct GNUNET_MESSENGER_Message, body.invite.door); |
229 | length += member_size (struct GNUNET_MESSENGER_Message, body.invite.key); | 255 | length += member_size (struct GNUNET_MESSENGER_Message, body.invite.key); |
230 | break; | 256 | break; |
231 | case GNUNET_MESSENGER_KIND_TEXT: | ||
232 | break; | ||
233 | case GNUNET_MESSENGER_KIND_FILE: | 257 | case GNUNET_MESSENGER_KIND_FILE: |
234 | length += member_size (struct GNUNET_MESSENGER_Message, body.file.key); | 258 | length += member_size (struct GNUNET_MESSENGER_Message, body.file.key); |
235 | length += member_size (struct GNUNET_MESSENGER_Message, body.file.hash); | 259 | length += member_size (struct GNUNET_MESSENGER_Message, body.file.hash); |
@@ -250,6 +274,12 @@ get_message_body_kind_size (enum GNUNET_MESSENGER_MessageKind kind) | |||
250 | case GNUNET_MESSENGER_KIND_TICKET: | 274 | case GNUNET_MESSENGER_KIND_TICKET: |
251 | length += member_size (struct GNUNET_MESSENGER_Message, body.ticket.identifier); | 275 | length += member_size (struct GNUNET_MESSENGER_Message, body.ticket.identifier); |
252 | break; | 276 | break; |
277 | case GNUNET_MESSENGER_KIND_TRANSCRIPT: | ||
278 | length += member_size (struct GNUNET_MESSENGER_Message, body.transcript.hash); | ||
279 | break; | ||
280 | case GNUNET_MESSENGER_KIND_TAG: | ||
281 | length += member_size (struct GNUNET_MESSENGER_Message, body.tag.hash); | ||
282 | break; | ||
253 | default: | 283 | default: |
254 | break; | 284 | break; |
255 | } | 285 | } |
@@ -297,7 +327,7 @@ get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, | |||
297 | length += GNUNET_CRYPTO_public_key_get_length (&(body->key.key)); | 327 | length += GNUNET_CRYPTO_public_key_get_length (&(body->key.key)); |
298 | break; | 328 | break; |
299 | case GNUNET_MESSENGER_KIND_TEXT: | 329 | case GNUNET_MESSENGER_KIND_TEXT: |
300 | length += strlen (body->text.text); | 330 | length += (body->text.text ? strlen (body->text.text) : 0); |
301 | break; | 331 | break; |
302 | case GNUNET_MESSENGER_KIND_FILE: | 332 | case GNUNET_MESSENGER_KIND_FILE: |
303 | length += strlen (body->file.uri); | 333 | length += strlen (body->file.uri); |
@@ -305,6 +335,13 @@ get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, | |||
305 | case GNUNET_MESSENGER_KIND_PRIVATE: | 335 | case GNUNET_MESSENGER_KIND_PRIVATE: |
306 | length += body->privacy.length; | 336 | length += body->privacy.length; |
307 | break; | 337 | break; |
338 | case GNUNET_MESSENGER_KIND_TRANSCRIPT: | ||
339 | length += GNUNET_CRYPTO_public_key_get_length (&(body->transcript.key)); | ||
340 | length += body->transcript.length; | ||
341 | break; | ||
342 | case GNUNET_MESSENGER_KIND_TAG: | ||
343 | length += (body->tag.tag ? strlen (body->tag.tag) : 0); | ||
344 | break; | ||
308 | default: | 345 | default: |
309 | break; | 346 | break; |
310 | } | 347 | } |
@@ -449,7 +486,7 @@ encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, | |||
449 | if (body->name.name) | 486 | if (body->name.name) |
450 | encode_step_ext (buffer, offset, body->name.name, min (length - offset, | 487 | encode_step_ext (buffer, offset, body->name.name, min (length - offset, |
451 | strlen ( | 488 | strlen ( |
452 | body->name.name))); | 489 | body->name.name))); |
453 | break; | 490 | break; |
454 | case GNUNET_MESSENGER_KIND_KEY: | 491 | case GNUNET_MESSENGER_KIND_KEY: |
455 | encode_step_key (buffer, offset, &(body->key.key), length); | 492 | encode_step_key (buffer, offset, &(body->key.key), length); |
@@ -474,9 +511,10 @@ encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, | |||
474 | encode_step (buffer, offset, &(body->invite.key)); | 511 | encode_step (buffer, offset, &(body->invite.key)); |
475 | break; | 512 | break; |
476 | case GNUNET_MESSENGER_KIND_TEXT: | 513 | case GNUNET_MESSENGER_KIND_TEXT: |
477 | encode_step_ext (buffer, offset, body->text.text, min (length - offset, | 514 | if (body->text.text) |
478 | strlen ( | 515 | encode_step_ext (buffer, offset, body->text.text, min (length - offset, |
479 | body->text.text))); | 516 | strlen ( |
517 | body->text.text))); | ||
480 | break; | 518 | break; |
481 | case GNUNET_MESSENGER_KIND_FILE: | 519 | case GNUNET_MESSENGER_KIND_FILE: |
482 | encode_step (buffer, offset, &(body->file.key)); | 520 | encode_step (buffer, offset, &(body->file.key)); |
@@ -506,6 +544,20 @@ encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, | |||
506 | case GNUNET_MESSENGER_KIND_TICKET: | 544 | case GNUNET_MESSENGER_KIND_TICKET: |
507 | encode_step (buffer, offset, &(body->ticket.identifier)); | 545 | encode_step (buffer, offset, &(body->ticket.identifier)); |
508 | break; | 546 | break; |
547 | case GNUNET_MESSENGER_KIND_TRANSCRIPT: | ||
548 | encode_step (buffer, offset, &(body->transcript.hash)); | ||
549 | encode_step_key (buffer, offset, &(body->transcript.key), length); | ||
550 | encode_step_ext (buffer, offset, body->transcript.data, min (length - offset, | ||
551 | body->transcript. | ||
552 | length)); | ||
553 | break; | ||
554 | case GNUNET_MESSENGER_KIND_TAG: | ||
555 | encode_step (buffer, offset, &(body->tag.hash)); | ||
556 | if (body->tag.tag) | ||
557 | encode_step_ext (buffer, offset, body->tag.tag, min (length - offset, | ||
558 | strlen ( | ||
559 | body->tag.tag))); | ||
560 | break; | ||
509 | default: | 561 | default: |
510 | break; | 562 | break; |
511 | } | 563 | } |
@@ -698,6 +750,17 @@ decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, | |||
698 | case GNUNET_MESSENGER_KIND_TICKET: | 750 | case GNUNET_MESSENGER_KIND_TICKET: |
699 | decode_step (buffer, offset, &(body->ticket.identifier)); | 751 | decode_step (buffer, offset, &(body->ticket.identifier)); |
700 | break; | 752 | break; |
753 | case GNUNET_MESSENGER_KIND_TRANSCRIPT: | ||
754 | decode_step (buffer, offset, &(body->transcript.hash)); | ||
755 | decode_step_key (buffer, offset, &(body->transcript.key), length); | ||
756 | |||
757 | body->transcript.length = (length - offset); | ||
758 | decode_step_malloc (buffer, offset, body->transcript.data, length - offset, 0); | ||
759 | break; | ||
760 | case GNUNET_MESSENGER_KIND_TAG: | ||
761 | decode_step (buffer, offset, &(body->tag.hash)); | ||
762 | decode_step_malloc (buffer, offset, body->tag.tag, length - offset, 1); | ||
763 | break; | ||
701 | default: | 764 | default: |
702 | *kind = GNUNET_MESSENGER_KIND_UNKNOWN; | 765 | *kind = GNUNET_MESSENGER_KIND_UNKNOWN; |
703 | break; | 766 | break; |
@@ -1133,6 +1196,10 @@ is_service_message (const struct GNUNET_MESSENGER_Message *message) | |||
1133 | return GNUNET_YES; // Reserved for connection handling only! | 1196 | return GNUNET_YES; // Reserved for connection handling only! |
1134 | case GNUNET_MESSENGER_KIND_TICKET: | 1197 | case GNUNET_MESSENGER_KIND_TICKET: |
1135 | return GNUNET_NO; | 1198 | return GNUNET_NO; |
1199 | case GNUNET_MESSENGER_KIND_TRANSCRIPT: | ||
1200 | return GNUNET_YES; // Allow access to self encrypted messages! | ||
1201 | case GNUNET_MESSENGER_KIND_TAG: | ||
1202 | return GNUNET_NO; | ||
1136 | default: | 1203 | default: |
1137 | return GNUNET_SYSERR; | 1204 | return GNUNET_SYSERR; |
1138 | } | 1205 | } |
@@ -1180,6 +1247,10 @@ filter_message_sending (const struct GNUNET_MESSENGER_Message *message) | |||
1180 | case GNUNET_MESSENGER_KIND_CONNECTION: | 1247 | case GNUNET_MESSENGER_KIND_CONNECTION: |
1181 | return GNUNET_SYSERR; // Reserved for connection handling only! | 1248 | return GNUNET_SYSERR; // Reserved for connection handling only! |
1182 | case GNUNET_MESSENGER_KIND_TICKET: | 1249 | case GNUNET_MESSENGER_KIND_TICKET: |
1250 | return GNUNET_NO; // Use #GNUNET_MESSENGER_send_ticket(...) instead! | ||
1251 | case GNUNET_MESSENGER_KIND_TRANSCRIPT: | ||
1252 | return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead! | ||
1253 | case GNUNET_MESSENGER_KIND_TAG: | ||
1183 | return GNUNET_YES; | 1254 | return GNUNET_YES; |
1184 | default: | 1255 | default: |
1185 | return GNUNET_SYSERR; | 1256 | return GNUNET_SYSERR; |