libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit 1b50f47306d56da32daab8bfa72cf994dece043b
parent 48a024bc9e146a8bc861f9c58de65a769fdcaa40
Author: Jacki <jacki@thejackimonster.de>
Date:   Fri,  2 Feb 2024 00:31:21 +0100

Implement rejection of an invitation

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Minclude/gnunet/gnunet_chat_lib.h | 19++++++++++++++++++-
Msrc/gnunet_chat_handle.c | 2+-
Msrc/gnunet_chat_handle_intern.c | 17++++++++++++++++-
Msrc/gnunet_chat_invitation.c | 7++++++-
Msrc/gnunet_chat_invitation.h | 4++++
Msrc/gnunet_chat_lib.c | 49+++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 94 insertions(+), 4 deletions(-)

diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h @@ -1381,7 +1381,15 @@ void GNUNET_CHAT_invitation_accept (struct GNUNET_CHAT_Invitation *invitation); /** - * Returns if a given <i>invitation</i> is accepted. + * Rejects a given chat <i>invitation</i> to enter another chat. + * + * @param[in,out] invitation Chat invitation + */ +void +GNUNET_CHAT_invitation_reject (struct GNUNET_CHAT_Invitation *invitation); + +/** + * Returns if a given <i>invitation</i> got accepted. * * @param[in] invitation Chat invitation * @return #GNUNET_YES if accepted, #GNUNET_NO otherwise @@ -1390,6 +1398,15 @@ enum GNUNET_GenericReturnValue GNUNET_CHAT_invitation_is_accepted (const struct GNUNET_CHAT_Invitation *invitation); /** + * Returns if a given <i>invitation</i> got rejected. + * + * @param[in] invitation Chat invitation + * @return #GNUNET_YES if rejected, #GNUNET_NO otherwise + */ +enum GNUNET_GenericReturnValue +GNUNET_CHAT_invitation_is_rejected (const struct GNUNET_CHAT_Invitation *invitation); + +/** * Returns the contact of the issuer from a given chat <i>ticket</i>. * * @param[in] invitation Chat invitation diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c @@ -775,7 +775,7 @@ handle_send_internal_message (struct GNUNET_CHAT_Handle *handle, void handle_send_room_name (struct GNUNET_CHAT_Handle *handle, - struct GNUNET_MESSENGER_Room *room) + struct GNUNET_MESSENGER_Room *room) { GNUNET_assert((handle) && (handle->messenger) && (room)); diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c @@ -896,7 +896,7 @@ on_handle_message (void *cls, case GNUNET_MESSENGER_KIND_INVITE: { struct GNUNET_CHAT_Invitation *invitation = invitation_create_from_message( - context, &(msg->body.invite) + context, hash, &(msg->body.invite) ); if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( @@ -971,6 +971,21 @@ on_handle_message (void *cls, ); break; } + case GNUNET_MESSENGER_KIND_TAG: + { + if (msg->body.tag.tag) + break; + + struct GNUNET_CHAT_Invitation *invitation = GNUNET_CONTAINER_multihashmap_get( + context->invites, &(msg->body.tag.hash) + ); + + if (invitation) + GNUNET_memcpy(&(invitation->rejection), hash, + sizeof(invitation->rejection)); + + break; + } default: break; } diff --git a/src/gnunet_chat_invitation.c b/src/gnunet_chat_invitation.c @@ -23,17 +23,22 @@ */ #include "gnunet_chat_invitation.h" +#include <gnunet/gnunet_common.h> struct GNUNET_CHAT_Invitation* invitation_create_from_message (struct GNUNET_CHAT_Context *context, + const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_MessageInvite *message) { - GNUNET_assert((context) && (message)); + GNUNET_assert((context) && (hash) && (message)); struct GNUNET_CHAT_Invitation *invitation = GNUNET_new(struct GNUNET_CHAT_Invitation); invitation->context = context; + GNUNET_memcpy(&(invitation->hash), hash, sizeof(invitation->hash)); + GNUNET_memcpy(&(invitation->rejection), hash, sizeof(invitation->rejection)); + GNUNET_memcpy(&(invitation->key), &(message->key), sizeof(invitation->key)); invitation->door = GNUNET_PEER_intern(&(message->door)); diff --git a/src/gnunet_chat_invitation.h b/src/gnunet_chat_invitation.h @@ -34,6 +34,9 @@ struct GNUNET_CHAT_Invitation { struct GNUNET_CHAT_Context *context; + struct GNUNET_HashCode hash; + struct GNUNET_HashCode rejection; + struct GNUNET_HashCode key; GNUNET_PEER_Id door; }; @@ -48,6 +51,7 @@ struct GNUNET_CHAT_Invitation */ struct GNUNET_CHAT_Invitation* invitation_create_from_message (struct GNUNET_CHAT_Context *context, + const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_MessageInvite *message); /** diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -2167,6 +2167,32 @@ GNUNET_CHAT_invitation_accept (struct GNUNET_CHAT_Invitation *invitation) } +void +GNUNET_CHAT_invitation_reject (struct GNUNET_CHAT_Invitation *invitation) +{ + GNUNET_CHAT_VERSION_ASSERT(); + + if (!invitation) + return; + + const struct GNUNET_MESSENGER_Contact *sender = GNUNET_MESSENGER_get_sender( + invitation->context->room, &(invitation->hash) + ); + + if (!sender) + return; + + struct GNUNET_MESSENGER_Message msg; + + msg.header.kind = GNUNET_MESSENGER_KIND_TAG; + GNUNET_memcpy(&(msg.body.tag.hash), &(invitation->hash), + sizeof(struct GNUNET_HashCode)); + msg.body.tag.tag = NULL; + + GNUNET_MESSENGER_send_message(invitation->context->room, &msg, sender); +} + + enum GNUNET_GenericReturnValue GNUNET_CHAT_invitation_is_accepted (const struct GNUNET_CHAT_Invitation *invitation) { @@ -2182,6 +2208,29 @@ GNUNET_CHAT_invitation_is_accepted (const struct GNUNET_CHAT_Invitation *invitat } +enum GNUNET_GenericReturnValue +GNUNET_CHAT_invitation_is_rejected (const struct GNUNET_CHAT_Invitation *invitation) +{ + GNUNET_CHAT_VERSION_ASSERT(); + + if (!invitation) + return GNUNET_NO; + + if (0 == GNUNET_CRYPTO_hash_cmp(&(invitation->hash), &(invitation->rejection))) + return GNUNET_NO; + + const struct GNUNET_CHAT_Message *message = GNUNET_CONTAINER_multihashmap_get( + invitation->context->messages, &(invitation->rejection) + ); + + if ((!message) || (!message->msg) || (message->msg->header.kind != GNUNET_MESSENGER_KIND_TAG) || + (message->msg->body.tag.tag)) + return GNUNET_NO; + else + return GNUNET_YES; +} + + const struct GNUNET_CHAT_Contact* GNUNET_CHAT_ticket_get_contact (const struct GNUNET_CHAT_Ticket *ticket) {