GNUnet  0.11.x
gnunet-service-messenger_message_handle.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2020 GNUnet e.V.
4 
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
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
27 
28 void
30  struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
31 {
32  struct GNUNET_MESSENGER_SrvContact *contact = get_room_contact (room, &(message->header.sender_id));
33 
34  if (!contact)
35  add_room_contact (room, &(message->header.sender_id), &(message->body.join.key));
36 
37  struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id));
38 
39  if (!info)
40  {
42 
45  }
46  else
48 
51  add_to_list_messages (&(info->session_messages), hash);
52 }
53 
54 void
56  struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
57 {
58  struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id));
59 
60  if (info)
62 }
63 
64 void
66  struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
67 {
68  struct GNUNET_MESSENGER_SrvContact *contact = get_room_contact (room, &(message->header.sender_id));
69 
70  if (contact)
71  set_contact_name (contact, message->body.name.name);
72 
73  struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id));
74 
75  if (info)
76  add_to_list_messages (&(info->session_messages), hash);
77 }
78 
79 void
81  struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
82 {
83  struct GNUNET_MESSENGER_SrvContact *contact = get_room_contact (room, &(message->header.sender_id));
84 
85  if (contact)
86  swap_service_contact_by_pubkey (room->service, contact, &(message->body.key.key));
87 
88  struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id));
89 
90  if (info)
91  add_to_list_messages (&(info->session_messages), hash);
92 }
93 
94 void
96  struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
97 {
98  if (GNUNET_NO == contains_list_tunnels (&(room->basement), &(message->body.peer.peer)))
99  add_to_list_tunnels (&(room->basement), &(message->body.peer.peer));
100 
101  if (room->peer_message)
103 }
104 
105 void
107  struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
108 {
109  struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id));
110 
111  if (info)
112  add_to_list_messages (&(info->session_messages), hash);
113 
114  switch_room_member_id (room, &(message->header.sender_id), &(message->body.id.id), hash);
115 }
116 
117 void
119  struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
120 {
121  struct GNUNET_MESSENGER_ListTunnel *element = find_list_tunnels (&(room->basement), &(message->body.peer.peer), NULL);
122 
123  if (!element)
124  return;
125 
126  remove_from_list_tunnels (&(room->basement), element);
127 
128  if (room->peer_message)
130 }
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
struct GNUNET_MESSENGER_MessageHeader header
Header.
int contains_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer)
Tests linearly if the list of tunnels peer identities contains a specific peer identity and returns G...
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
void handle_message_id(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent id message to change a members id.
void handle_message_miss(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent miss message to drop a peer from the basement in the room.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
struct GNUNET_MESSENGER_MessageKey key
void handle_message_name(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent name message to rename a current member.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void add_to_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer)
Adds a specific peer from a tunnel to the end of the list.
void swap_service_contact_by_pubkey(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvContact *contact, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Changes the public key for a contact known to a service to a specific public key and updates local ma...
void handle_message_peer(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent peer message to make changes of the basement in the room.
struct GNUNET_CONTAINER_MultiShortmap * member_infos
struct GNUNET_MESSENGER_MemberInfo * get_room_member_info(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id)
Returns the member information of a member in a room identified by a given id.
struct GNUNET_MESSENGER_SrvContact * get_room_contact(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id)
Returns the contact of a member in a room identified by a given id.
void init_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Initializes list of message hashes as empty list.
struct GNUNET_MESSENGER_Service * service
, &#39; bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_IDENTITY_PublicKey key
The senders public key to verify its signatures.
void set_contact_name(struct GNUNET_MESSENGER_SrvContact *contact, const char *name)
Changes the current name of a given contact by copying it from the parameter name.
struct GNUNET_HashCode * peer_message
struct GNUNET_IDENTITY_PublicKey key
The new public key which replaces the current senders public key.
void add_to_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
Adds a specific hash from a message to the end of the list.
struct GNUNET_MESSENGER_MessageBody body
Body.
int GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void handle_message_key(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent key message to change the key of a member and rearrange the contacts accor...
A 512-bit hashcode.
void switch_room_member_id(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *old_id, const struct GNUNET_ShortHashCode *new_id, const struct GNUNET_HashCode *hash)
Changes an id of a current member from an old id to a new one and adds optionally the hash of an id m...
struct GNUNET_MESSENGER_MessageName name
void add_room_contact(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Adds a contact from the service to a room under a specific id with a given public key...
struct GNUNET_MESSENGER_MessagePeer peer
void rebuild_room_basement_structure(struct GNUNET_MESSENGER_SrvRoom *room)
Rebuilds the decentralized structure for a room by ensuring all required connections are made dependi...
void clear_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Clears the list of message hashes.
void handle_message_join(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent join message to make changes of current member information.
struct GNUNET_MESSENGER_ListTunnels basement
struct GNUNET_MESSENGER_ListMessages session_messages
char * name
The new name which replaces the current senders name.
void handle_message_leave(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent leave message to make changes of current member information.
enum GNUNET_MESSENGER_MemberAccess access
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_MESSENGER_ListTunnel * find_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, size_t *index)
Searches linearly through the list of tunnels peer identities for matching a specific peer identity a...
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_ListTunnel * remove_from_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, struct GNUNET_MESSENGER_ListTunnel *element)
Removes a specific element from the list of tunnels peer identities and returns the next element in t...