GNUnet 0.22.2
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--2024 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
29
30static void
32 const struct GNUNET_MESSENGER_Message *message,
33 const struct GNUNET_HashCode *hash)
34{
36
37 GNUNET_assert ((session) && (message) && (hash));
38
39 next = switch_member_session (session, message, hash);
40
41 if (next != session)
43}
44
45
46void
48 struct GNUNET_MESSENGER_SenderSession *session,
49 const struct GNUNET_MESSENGER_Message *message,
50 const struct GNUNET_HashCode *hash)
51{
52 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Member (%s) joins room (%s).\n",
53 GNUNET_sh2s (&(message->header.sender_id)), GNUNET_h2s (
54 get_srv_room_key (room)));
55
56 if (GNUNET_OK != reset_member_session (session->member, hash))
57 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Resetting member session failed!\n");
58
60 room,
61 &(message->body.join.key),
62 &(message->header.sender_id),
64 );
65}
66
67
68void
70 struct GNUNET_MESSENGER_SenderSession *session,
71 const struct GNUNET_MESSENGER_Message *message,
72 const struct GNUNET_HashCode *hash)
73{
74 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Member (%s) leaves room (%s).\n",
75 GNUNET_sh2s (&(message->header.sender_id)), GNUNET_h2s (
76 get_srv_room_key (room)));
77
79}
80
81
82void
84 struct GNUNET_MESSENGER_SenderSession *session,
85 const struct GNUNET_MESSENGER_Message *message,
86 const struct GNUNET_HashCode *hash)
87{
88 handle_member_session_switch (session->member, message, hash);
89}
90
91
92void
94 struct GNUNET_MESSENGER_SenderSession *session,
95 const struct GNUNET_MESSENGER_Message *message,
96 const struct GNUNET_HashCode *hash)
97{
98 struct GNUNET_MESSENGER_PeerStore *store;
99
100 store = get_srv_room_peer_store (room);
101
102 if (0 == GNUNET_memcmp (session->peer, &(message->body.peer.peer)))
103 update_store_peer (store, &(message->body.peer.peer), GNUNET_YES);
104
106 &(message->body.peer.peer)))
107 add_to_list_tunnels (&(room->basement), &(message->body.peer.peer), hash);
108
109 if (room->peer_message)
111}
112
113
114void
116 struct GNUNET_MESSENGER_SenderSession *session,
117 const struct GNUNET_MESSENGER_Message *message,
118 const struct GNUNET_HashCode *hash)
119{
120 handle_member_session_switch (session->member, message, hash);
121
123 room,
125 &(message->body.id.id),
127 );
128}
129
130
131void
133 struct GNUNET_MESSENGER_SenderSession *session,
134 const struct GNUNET_MESSENGER_Message *message,
135 const struct GNUNET_HashCode *hash)
136{
137 struct GNUNET_MESSENGER_PeerStore *store;
138 struct GNUNET_MESSENGER_ListTunnel *element;
139
140 store = get_srv_room_peer_store (room);
141
142 if (0 == GNUNET_memcmp (session->peer, &(message->body.miss.peer)))
143 update_store_peer (store, &(message->body.miss.peer), GNUNET_NO);
144
145 element = find_list_tunnels (&(room->basement),
146 &(message->body.miss.peer), NULL);
147
148 if (! element)
149 return;
150
151 remove_from_list_tunnels (&(room->basement), element);
152
153 if (room->peer_message)
155}
156
157
158void
160 struct GNUNET_MESSENGER_SenderSession *session,
161 const struct GNUNET_MESSENGER_Message *message,
162 const struct GNUNET_HashCode *hash)
163{
164 struct GNUNET_TIME_Relative delay;
166
167 delay = GNUNET_TIME_relative_ntoh (message->body.deletion.delay);
169
172 action);
173
174 delete_srv_room_message (room, session->member,
175 &(message->body.deletion.hash), delay);
176}
177
178
179void
181 struct GNUNET_MESSENGER_SenderSession *session,
182 const struct GNUNET_MESSENGER_Message *message,
183 const struct GNUNET_HashCode *hash)
184{
185 struct GNUNET_MESSENGER_ListTunnel *element;
186
187 element = find_list_tunnels (&(room->basement), session->peer, NULL);
188
189 if (! element)
190 return;
191
192 memcpy (&(element->connection), &(message->body.connection),
193 sizeof (struct GNUNET_MESSENGER_MessageConnection));
194}
195
196
197void
199 struct GNUNET_MESSENGER_SenderSession *session,
200 const struct GNUNET_MESSENGER_Message *message,
201 const struct GNUNET_HashCode *hash)
202{
203 struct GNUNET_MESSENGER_Member *member;
204 const struct GNUNET_ShortHashCode *discourse;
205 struct GNUNET_MESSENGER_Subscription *subscription;
206
207 member = session->member->member;
208
209 discourse = &(message->body.subscribe.discourse);
210 subscription = get_member_subscription (member, discourse);
211
212 {
215
218
219 if (subscription)
220 update_subscription (subscription,
221 timestamp,
222 duration);
223 else
224 {
225 subscription =
226 create_subscription (room, member, discourse,
227 timestamp,
228 duration);
229
230 if (! subscription)
231 return;
232
233 add_member_subscription (member, subscription);
234 }
235 }
236
237 update_subscription_timing (subscription);
238 cleanup_srv_room_discourse_messages (room, discourse);
239}
static uint64_t timestamp(void)
Get current timestamp.
void add_member_subscription(struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_Subscription *subscription)
Adds a given subscription to a member.
struct GNUNET_MESSENGER_Subscription * get_member_subscription(struct GNUNET_MESSENGER_Member *member, const struct GNUNET_ShortHashCode *discourse)
Returns the active subscription of a given member to a selected discourse.
void add_member_session(struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_MemberSession *session)
Adds a given member session to its member.
const struct GNUNET_CRYPTO_PublicKey * get_member_session_public_key(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the public key of a given member session.
void close_member_session(struct GNUNET_MESSENGER_MemberSession *session)
Closes a given member session which opens the request for completion of the given member session.
enum GNUNET_GenericReturnValue reset_member_session(struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash)
Resets a given member session which re-opens a member session for new usage.
struct GNUNET_MESSENGER_MemberSession * switch_member_session(struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Creates and allocates a new member session closing and replacing a given other session of the same me...
void handle_message_id(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const 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_delete(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent delete message to delete a specific message from the store.
void handle_message_peer(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const 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.
void handle_message_join(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent join message to make changes of current member information.
void handle_message_key(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const 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...
void handle_message_leave(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent leave message to make changes of current member information.
void handle_message_subscribe(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent subscribe message to subscribe a member to a discourse.
void handle_message_connection(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent connection message to update connection information about a peer.
void handle_message_miss(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const 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.
static void handle_member_session_switch(struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
void update_store_peer(struct GNUNET_MESSENGER_PeerStore *store, const struct GNUNET_PeerIdentity *peer, enum GNUNET_GenericReturnValue active)
Adds a peer identity to the store if necessary.
void rebuild_srv_room_basement_structure(struct GNUNET_MESSENGER_SrvRoom *room)
Rebuilds the decentralized structure for a room by ensuring all required connections are made dependi...
struct GNUNET_MESSENGER_PeerStore * get_srv_room_peer_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used peer store of a given room.
void cleanup_srv_room_discourse_messages(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *discourse)
Cleanup discourse messages outside of current subscriptions from a specific discourse of all the memb...
void solve_srv_room_member_collisions(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_CRYPTO_PublicKey *public_key, const struct GNUNET_ShortHashCode *member_id, struct GNUNET_TIME_Absolute timestamp)
Checks for potential collisions with member ids and solves them changing active handles ids if they u...
enum GNUNET_GenericReturnValue delete_srv_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay)
Deletes a message from the room with a given hash in a specific delay if the provided member by its s...
const struct GNUNET_HashCode * get_srv_room_key(const struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.
void update_subscription(struct GNUNET_MESSENGER_Subscription *subscribtion, struct GNUNET_TIME_Absolute timestamp, struct GNUNET_TIME_Relative duration)
void update_subscription_timing(struct GNUNET_MESSENGER_Subscription *subscribtion)
struct GNUNET_MESSENGER_Subscription * create_subscription(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Member *member, const struct GNUNET_ShortHashCode *discourse, struct GNUNET_TIME_Absolute timestamp, struct GNUNET_TIME_Relative duration)
static struct GNUNET_TIME_Relative duration
Option '-d': duration of the mapping.
Definition: gnunet-vpn.c:90
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:630
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:741
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:452
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:423
void add_to_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HashCode *hash)
Adds a specific peer from a tunnel to the end of the list.
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...
enum GNUNET_GenericReturnValue 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_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...
A 512-bit hashcode.
struct GNUNET_MESSENGER_MessageConnection connection
struct GNUNET_MESSENGER_MemberSession * next
struct GNUNET_MESSENGER_MessageConnection connection
struct GNUNET_MESSENGER_MessageSubscribe subscribe
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_MessageMiss miss
struct GNUNET_MESSENGER_MessagePeer peer
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_MESSENGER_MessageDelete deletion
A connection message body This allows to tell others about connection information about a peer.
struct GNUNET_HashCode hash
The hash of the message to delete.
struct GNUNET_TIME_RelativeNBO delay
The delay of the delete operation to get processed.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
struct GNUNET_CRYPTO_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_PeerIdentity peer
The peer identity of a disconnected door to a room.
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
struct GNUNET_TIME_RelativeNBO time
The time window of the subscription.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to subscribe.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MemberSession * member
struct GNUNET_HashCode * peer_message
struct GNUNET_MESSENGER_ListTunnels basement
A 256-bit hashcode.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.