diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2024-01-02 19:04:40 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2024-01-02 19:04:40 +0100 |
commit | a118acdd652d35fc2445370ef7b7b86c510367d5 (patch) | |
tree | 93cc936544eba882a274f4cff088ceebe7c1158b | |
parent | 85ee00ef023f5435c2429deecc8a4a0f7953fa11 (diff) | |
download | gnunet-a118acdd652d35fc2445370ef7b7b86c510367d5.tar.gz gnunet-a118acdd652d35fc2445370ef7b7b86c510367d5.zip |
MESSENGER: encode/decode connection message
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/service/messenger/messenger_api_message.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/service/messenger/messenger_api_message.c b/src/service/messenger/messenger_api_message.c index 0b6f6253e..51213bce5 100644 --- a/src/service/messenger/messenger_api_message.c +++ b/src/service/messenger/messenger_api_message.c | |||
@@ -240,6 +240,10 @@ get_message_body_kind_size (enum GNUNET_MESSENGER_MessageKind kind) | |||
240 | length += member_size (struct GNUNET_MESSENGER_Message, | 240 | length += member_size (struct GNUNET_MESSENGER_Message, |
241 | body.deletion.delay); | 241 | body.deletion.delay); |
242 | break; | 242 | break; |
243 | case GNUNET_MESSENGER_KIND_CONNECTION: | ||
244 | length += member_size (struct GNUNET_MESSENGER_Message, body.connection.amount); | ||
245 | length += member_size (struct GNUNET_MESSENGER_Message, body.connection.flags); | ||
246 | break; | ||
243 | default: | 247 | default: |
244 | break; | 248 | break; |
245 | } | 249 | } |
@@ -424,13 +428,13 @@ encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, | |||
424 | char *buffer, | 428 | char *buffer, |
425 | uint16_t offset) | 429 | uint16_t offset) |
426 | { | 430 | { |
427 | uint32_t version; | 431 | uint32_t value0, value1; |
428 | switch (kind) | 432 | switch (kind) |
429 | { | 433 | { |
430 | case GNUNET_MESSENGER_KIND_INFO: | 434 | case GNUNET_MESSENGER_KIND_INFO: |
431 | version = GNUNET_htobe32 (body->info.messenger_version); | 435 | value0 = GNUNET_htobe32 (body->info.messenger_version); |
432 | 436 | ||
433 | encode_step (buffer, offset, &version); | 437 | encode_step (buffer, offset, &value0); |
434 | break; | 438 | break; |
435 | case GNUNET_MESSENGER_KIND_JOIN: | 439 | case GNUNET_MESSENGER_KIND_JOIN: |
436 | encode_step_key (buffer, offset, &(body->join.key), length); | 440 | encode_step_key (buffer, offset, &(body->join.key), length); |
@@ -486,6 +490,13 @@ encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, | |||
486 | encode_step (buffer, offset, &(body->deletion.hash)); | 490 | encode_step (buffer, offset, &(body->deletion.hash)); |
487 | encode_step (buffer, offset, &(body->deletion.delay)); | 491 | encode_step (buffer, offset, &(body->deletion.delay)); |
488 | break; | 492 | break; |
493 | case GNUNET_MESSENGER_KIND_CONNECTION: | ||
494 | value0 = GNUNET_htobe32 (body->connection.amount); | ||
495 | value1 = GNUNET_htobe32 (body->connection.flags); | ||
496 | |||
497 | encode_step (buffer, offset, &value0); | ||
498 | encode_step (buffer, offset, &value1); | ||
499 | break; | ||
489 | default: | 500 | default: |
490 | break; | 501 | break; |
491 | } | 502 | } |
@@ -610,13 +621,13 @@ decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, | |||
610 | 621 | ||
611 | length -= padding; | 622 | length -= padding; |
612 | 623 | ||
613 | uint32_t version; | 624 | uint32_t value0, value1; |
614 | switch (*kind) | 625 | switch (*kind) |
615 | { | 626 | { |
616 | case GNUNET_MESSENGER_KIND_INFO: { | 627 | case GNUNET_MESSENGER_KIND_INFO: { |
617 | decode_step (buffer, offset, &version); | 628 | decode_step (buffer, offset, &value0); |
618 | 629 | ||
619 | body->info.messenger_version = GNUNET_be32toh (version); | 630 | body->info.messenger_version = GNUNET_be32toh (value0); |
620 | break; | 631 | break; |
621 | } case GNUNET_MESSENGER_KIND_JOIN: { | 632 | } case GNUNET_MESSENGER_KIND_JOIN: { |
622 | decode_step_key (buffer, offset, &(body->join.key), length); | 633 | decode_step_key (buffer, offset, &(body->join.key), length); |
@@ -668,6 +679,13 @@ decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, | |||
668 | decode_step (buffer, offset, &(body->deletion.hash)); | 679 | decode_step (buffer, offset, &(body->deletion.hash)); |
669 | decode_step (buffer, offset, &(body->deletion.delay)); | 680 | decode_step (buffer, offset, &(body->deletion.delay)); |
670 | break; | 681 | break; |
682 | case GNUNET_MESSENGER_KIND_CONNECTION: | ||
683 | decode_step (buffer, offset, &value0); | ||
684 | decode_step (buffer, offset, &value1); | ||
685 | |||
686 | body->connection.amount = GNUNET_be32toh (value0); | ||
687 | body->connection.flags = GNUNET_be32toh (value1); | ||
688 | break; | ||
671 | default: | 689 | default: |
672 | *kind = GNUNET_MESSENGER_KIND_UNKNOWN; | 690 | *kind = GNUNET_MESSENGER_KIND_UNKNOWN; |
673 | break; | 691 | break; |
@@ -1053,6 +1071,7 @@ is_peer_message (const struct GNUNET_MESSENGER_Message *message) | |||
1053 | case GNUNET_MESSENGER_KIND_PEER: | 1071 | case GNUNET_MESSENGER_KIND_PEER: |
1054 | case GNUNET_MESSENGER_KIND_MISS: | 1072 | case GNUNET_MESSENGER_KIND_MISS: |
1055 | case GNUNET_MESSENGER_KIND_MERGE: | 1073 | case GNUNET_MESSENGER_KIND_MERGE: |
1074 | case GNUNET_MESSENGER_KIND_CONNECTION: | ||
1056 | return GNUNET_YES; | 1075 | return GNUNET_YES; |
1057 | default: | 1076 | default: |
1058 | return GNUNET_NO; | 1077 | return GNUNET_NO; |
@@ -1098,6 +1117,8 @@ is_service_message (const struct GNUNET_MESSENGER_Message *message) | |||
1098 | return GNUNET_YES; // Prevent duplicate encryption breaking all access! | 1117 | return GNUNET_YES; // Prevent duplicate encryption breaking all access! |
1099 | case GNUNET_MESSENGER_KIND_DELETE: | 1118 | case GNUNET_MESSENGER_KIND_DELETE: |
1100 | return GNUNET_YES; // Deletion should not apply individually! (inefficieny) | 1119 | return GNUNET_YES; // Deletion should not apply individually! (inefficieny) |
1120 | case GNUNET_MESSENGER_KIND_CONNECTION: | ||
1121 | return GNUNET_YES; // Reserved for connection handling only! | ||
1101 | default: | 1122 | default: |
1102 | return GNUNET_SYSERR; | 1123 | return GNUNET_SYSERR; |
1103 | } | 1124 | } |
@@ -1142,6 +1163,8 @@ filter_message_sending (const struct GNUNET_MESSENGER_Message *message) | |||
1142 | return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead! | 1163 | return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead! |
1143 | case GNUNET_MESSENGER_KIND_DELETE: | 1164 | case GNUNET_MESSENGER_KIND_DELETE: |
1144 | return GNUNET_YES; | 1165 | return GNUNET_YES; |
1166 | case GNUNET_MESSENGER_KIND_CONNECTION: | ||
1167 | return GNUNET_SYSERR; // Reserved for connection handling only! | ||
1145 | default: | 1168 | default: |
1146 | return GNUNET_SYSERR; | 1169 | return GNUNET_SYSERR; |
1147 | } | 1170 | } |